java - How to I find out the size of a GZIP section embedded in firmware? -
i analyzing firmware images contain many different sections, 1 of gzip section.
i able know location of start of gzip section using magic number , gzipinputstream
in java.
however, need know compressed size of gzip section. gzipinputstream
return me uncompressed file size.
is there has idea?
you can count number of byte read using custom inputstream. need force stream read 1 byte @ time ensure don't read more need.
you can wrap current inputstream in this
class countinginputstream extends inputstream { final inputstream is; int counter = 0; public countinginputstream(inputstream is) { this.is = is; } public int read() throws ioexception { int read = is.read(); if (read >= 0) counter++; return read; } }
and wrap in gzipinputstream. field counter hold number of bytes read.
to use bufferedinputstream can do
inputstream = new bufferedinputstream(new fileinputstream(filename)); // read data or skip want start. countinginputstream cis = new countinginputstream(is); gzipinputstream gzis = new gzipinputstream(cis); // read compressed data dis.read(...); int dataread = cis.counter;
Comments
Post a Comment