Tapatalk

Binary file search with RegExp

Binary file search with RegExp

2
NewbieNewbie
2

    Jun 16, 2006#1

    Hello!

    As I could read trough the Forum, searching in binaries is very limited, so I hope there is a solution for my problem.

    I have a BIN file with many merged bitmaps of PNG format. I want to make Macro to split it to standalone files. All PNG files start with "‰PNG"

    Code: Select all

    00000000h: 89 50 4E 47 0D 0A 1A 0A 00 00 00 0D 49 48 44 52 ; ‰PNG........IHDR
    and ends with "IEND®B`"

    Code: Select all

    00000640h: 49 45 4E 44 AE 42 60 00 00 00 00 00 00 00 00 00 ; IEND®B`.........
    I've tried to use Find with RegExp by Perl synthax ‰PNG.*IEND®B` to select the whole PNG file, but I can't get it to work. Has someone clue where do I go wrong?? :cry: I have vers. 12.10.

    Thanks !

    6,685587
    Grand MasterGrand Master
    6,685587

      Jun 17, 2006#2

      Regular expressions are not possible in hex mode. But it is not needed for splitting your merged PNGs. The following macro will do it. You should enable the macro property Continue if a Find with Replace not found or the clearing of clipboard 9 and switch back to windows clipboard will not be executed.

      InsertMode
      ColumnModeOff
      HexOn
      UnixReOff
      Clipboard 9
      Loop
      Find "49454E44AE426082"
      IfNotFound
      ExitLoop
      EndIf
      Key LEFT ARROW
      Key RIGHT ARROW
      SelectToTop
      Cut
      NewFile
      UnicodeToASCII
      " "
      HexOn
      Key LEFT ARROW
      Key LEFT ARROW
      HexDelete 1
      Paste
      NextWindow
      EndLoop
      ClearClipboard
      Clipboard 0


      How it works:

      It searches for the end marker of PNG in hex. If found (and selected), the selection is removed (key left/right) and every byte from current position to top of the file (= start of the PNG image) is selected and CUT to the clipboard.

      Then a new ASCII file is created with a space to be able to switch to hex mode. The space is deleted and the PNG image content is pasted from the clipboard. With the last command in the loop the source file gets the focus and the loop continues until the source file is empty.

      After macro execution you will have an empty source file. Use File - Revert to Saved to restore the content or close it without save. And you will have new files in the order of the PNGs inside the source file which you have to save now manually with an appropriate name.
      Best regards from an UC/UE/UES for Windows user from Austria

      2
      NewbieNewbie
      2

        Jun 18, 2006#3

        Mofi, thanks alot for this comprehensive answer and hints. It's so simple but didn't cross my mind ...

        I had to make some additional modifications to remove the trash content between 2 files that was left on the top of data after the cut-paste process, and some minor additional editing... I can post the final macro if it's interesting to someone...

        Also I would suggest to developers of UE, The Ultimate Editor, to expand the RegEx support to hex mode, I'm sure many of us would use it alot!