mardi 24 mars 2015

Read hidden zip file

I have a jpeg, and on the end of it I wrote a zip file.


Inside this zip file is a single txt file called hidden.txt. I can change the extension to zip and read the file just fine on my laptop (debian) but when I try to read it using either a ZipInputStream or using ZipFile I get an error telling me it's not a zip file.


I tried separating the jpg part out first by reading the whole thing to a Bitmap then writing that to a byte[], however the byte[] encompassed more than just the image.


My method to combine the bitmap and the zipFile (a byte[])



private byte[] combineFiles(Bitmap drawn, byte[] zip) throws
IOException {
InputStream in;
ByteArrayOutputStream out = new ByteArrayOutputStream();

/*write the first file*/
byte[] img;
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
drawn.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
img = byteArrayOutputStream.toByteArray();
in = new ByteArrayInputStream(img);
IOUtils.copy(in, out);
in.close();

/*add the second (hidden) file*/
in = new ByteArrayInputStream(zip);

IOUtils.copy(in, out);
out.flush();
in.close();
return out.toByteArray();
}


So really I have two questions,



  1. How do I separate the jpg and zip portions of the file?

  2. How do I unzip hidden.txt (preferably into a byte[])

    • fairly certain I know this one, but what I am doing currently does not work, probably because I am doing #1 wrong




Aucun commentaire:

Enregistrer un commentaire