Replace in all files - HEX mode

Replace in all files - HEX mode

9
NewbieNewbie
9

    Jan 08, 2008#1

    Time to give something back.

    I saw some posts a while ago asking about this so here is my solution

    I have had a need for a while to be able to run a macro on all files but in hex mode as i needed to replace with "00" which has no ascii character.

    I have finally come up with this macro.

    Notes:
    1. all files needing to be edited must be in the same location
    2. all need the same extension. I've used *.txt but edit the macro to suit your own needs

    Code: Select all

    Open "D:\Data\*.txt"
    InsertMode
    ColumnModeOff
    HexOff
    UnixReOff
    Loop 
    Top
    HexOn
    Find Select "01"
    Replace All "00"
    Top
    Find Select "0c"
    Replace All "00"
    Top
    Find Select "03"
    Replace All "00"
    Top
    Find Select "02"
    Replace All "00"
    Top
    Find Select "05"
    Replace All "00"
    Top
    Find Select "1d"
    Replace All "00"
    Top
    Find Select "1c"
    Replace All "00"
    Top
    Find Select "18"
    Replace All "00"
    Top
    Find Select "10"
    Replace All "00"
    Top
    Find Select "2a"
    Replace All "00"
    NextDocument
    EndLoop
    
    A few commands maybe out of order but it works for me.

    The NextDocument command simply makes the next tab active.

    Not an elegant solution but seems to work.

    6,624550
    Grand MasterGrand Master
    6,624550

      Jan 08, 2008#2

      What about this version?

      InsertMode
      ColumnModeOff
      HexOn
      UnixReOff
      Open "D:\Data\*.txt"
      Loop
      IfNameIs ""
      ExitLoop
      EndIf

      Top
      HexOn
      Find "01"
      Replace All "00"
      Top
      Find "0c"
      Replace All "00"
      Top
      Find "03"
      Replace All "00"
      Top
      Find "02"
      Replace All "00"
      Top
      Find "05"
      Replace All "00"
      Top
      Find "1d"
      Replace All "00"
      Top
      Find "1c"
      Replace All "00"
      Top
      Find "18"
      Replace All "00"
      Top
      Find "10"
      Replace All "00"
      Top
      Find "2a"
      Replace All "00"
      CloseFile Save
      NextDocument /*! Must be deleted when using the red code lines. !*/
      EndLoop

      It is a known (for IDM and me) bug of the macro recorder that a find/replace in hex edit mode is always recorded with option Select although this option is not needed.

      And you should mention that macro property Continue if a Find with Replace not found or Continue if search string not found must be UNCHECKED for this macro to exit the endless loop if in any file one of the found binary values is not found.

      With the red code lines I have added and with macro property Continue if a Find with Replace not found or Continue if search string not found CHECKED the macro will run all replaces in all files until all files are saved and closed.

      9
      NewbieNewbie
      9

        Jan 09, 2008#3

        Thanks Mofi,

        yes yours is a much more elegant way of exiting the macro.

        so basically your version just checks to see if the file name is Null and if so exits.

        cheers