1

I have combined two files in android, using this Linux command

cat file1.png file2.zip > file3.png

How can I split two files again?I just want the zip file to be retrieved separately.

Is there any specific command?I've tried these codes:

unzip file3.png

Replaced png with zip:

unzip file3.zip

but none of them work. The only application with which I can open the combination, is winrar on windows

And also I tried several unzipping and unraring apps on android but none of them work except RAR app by rarlab

Is there any source for those apps I mentioned to unrar/unzip the file?

2
  • 1
    cat doesn't zip the files, it appends them together. Winrar on Windows probably works because it recognizes the file boundaries Commented Dec 27, 2015 at 15:47
  • @cricket_007 I konw , my file 2 is a zip file and winrar can open it I hoped the unzip command would open it too.
    – pooyathr
    Commented Jan 3, 2016 at 10:33

3 Answers 3

0

Strictly speaking : there's no way.

You might look for the PK 0x04 0x03 as a separator in the answer above, but you don't have any guaranty that this char sequence does not show up in the image data of the file1.png as well.

All together it's a funny question. If you want to split files like this on a regular basis rethink your strategy. If you need it to correct a one time mistake or something, you can split finding the seperator and be ok in over 99% of the cases.

1
  • What about opening with winrar? How does winrar opens the zip file?
    – pooyathr
    Commented Jan 3, 2016 at 10:32
0

What you need to know is that PNG files start with the hex value 0x89 followed by the text PNG. Zip files start with PK 0x04 0x03. You could write a utility which reads a file and outputs the bytes read in to a new file, using a new output file when a certain file signature is detected.

For a one-of solution, you can use vim, though you have to be careful to stop vim from adding a newline character to the end of the line.

Copy your input file for safety

cp file3.png f1
cp file3.png f2

vim -b f1

and in vim type

:set noeol

search for the start of the zip file

/PK

checking that the sequence found is PK^C^D. If not, look for the next match.

Delete the end of the line from PK with

d$

Move down a line, delete the remainder of the file and save

j
:.,$ d
ZZ

Similarly, delete the top of the file in f2 to get the zip file.

Note: don't name f2 as f2.zip because vim is smart enough to open this as as a zip file, which is not what you want here.

0

I'm not sure what you trying to accomplish by "hiding" a zip file into a PNG, but if you are trying to make a single file Winrar can open, then that's an odd way to do it.

You do not make a .zip (or any other type of archive) file when you cat a file to the either the start or end of a zip file. That simply appends two binary files together.

The reason winrar can open your "combined" binary file is that it most likely recognizes the file headers and can decipher you have 2 files.

I suggest you look into the usage of the zip command, for how to add files to an archive. I quick search shows, for example

zip -rv zipfile.zip newfile.txt

Will add newfile.txt to zipfile.zip.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.