Jump to content
rootx

[SOLVED] Extract .png inside a .bin file

Recommended Posts

Posted (edited)

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

Share this post


Link to post
Share on other sites
Posted (edited)

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

Share this post


Link to post
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 :)


A cross-platform implementation of the AutoIt language

My contributions to the AutoIt Community ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

Share this post


Link to post
Share on other sites
Posted (edited)

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)

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites
Posted (edited)

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)

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Posted (edited)
13 hours ago, Nine said:

@rootx Could you provide your code, someone else could find it helpful. Thanks.

I read this discussion as jchd advised me.

Edited by rootx

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...