Jump to content

[SOLVED] Extract .png inside a .bin file


 Share

Recommended Posts

how can I extract all the png images contained in a file? 

I would like to save each range in a .png file, as I do with the hex editor manually.

start = 89 50 4E 47 0D 0A 1A 0A

End = 49 45 4E 44 AE 42 60 82

 

Thx

 

 

Edited by rootx
Link to comment
Share on other sites

It depends on where and how the images are stored in the executable.  If the images are store in the executable's resource area, then you could use functions in the WinAPIRes UDF file to access them.  If they are stored somewhere else in the executable, then you would need some other method(s).  If they are stored compressed or encoded, then you need to take that into consideration also.  In other words, who knows because you haven't provided enough information.

Edit:

I just recognized that you specifically said a .bin file, not an executable.  Not sure what your .bin file is and how it was created, other than it's a binary file.  Assuming that the images are not stored compressed or encoded in the .bin file, you could open file the file as binary and extract file the binary image data using the starting and ending tags, with a regular expression.  You could then save that extracted binary data as a binary file.

Edit:

Actually a StringRegexp function probably wouldn't work because it would stop when a null byte (0x00) was encountered.  Since you are familiar with extracting the .png files with your hex editor, maybe you can automate using it to extract the files.  Or, you could open and read through the binary file byte by byte looking for your starting and ending tags.

Edited by TheXman
Link to comment
Share on other sites

@rootx You have to go through each byte and compare the values with known values. Remember that a byte is just nothing but an 8 digit binary number ;)

My apologies for the lack of an example, I am a bit busy at the moment. Hopefully someone will take out the time to show you :)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

Yo can use the code provided in this thread to perform regex search in binary:

 

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

1 minute ago, jchd said:

Yo can use the code provided in this thread to perform regex search in binary:

Since StringRegexp is a function that returns strings, would the result, if it had embedded null bytes (0x00), be the whole result or would it be truncated at the first null byte?

Link to comment
Share on other sites

It will work. The binary is converted to a string of UCS2 encoding units with exact same data: only the encoding is changed. PCRE (the underlying regex processing code is imune to embedded NULLs.

In AutoIt 0x00 is only a string termination on I/O (AFAICT).

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

On 8/3/2020 at 10:01 PM, TheDcoder said:

@rootx You have to go through each byte and compare the values with known values. Remember that a byte is just nothing but an 8 digit binary number ;)

My apologies for the lack of an example, I am a bit busy at the moment. Hopefully someone will take out the time to show you :)

Thanks for the tip, I found my solution, FileSetPos and then loop the entire file.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...