Skip to content
Advertisement

How to I find out the size of a GZIP section embedded in firmware?

I am currently analyzing firmware images which contain many different sections, one of which is a GZIP section.

I am able to know the location of the start of the GZIP section using magic number and the GZIPInputStream in Java.

However, I need to know the compressed size of the gzip section. GZIPInputStream would return me the uncompressed file size.

Is there anybody who has an idea?

Advertisement

Answer

You can count the number of byte read using a custom InputStream. You would need to force the stream to read one byte at a time to ensure you don’t read more than you need.


You can wrap your current InputStream in this

JavaScript

and then wrap it in a GZIPInputStream. The field counter will hold the number of bytes read.

To use this with BufferedInputStream you can do

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement