Replace in all files - HEX mode

Help with writing and playing macros

Replace in all files - HEX mode

Postby phelan » Mon Jan 07, 2008 11:36 pm

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.
User avatar
phelan
Newbie
 
Posts: 9
Joined: Mon Jul 02, 2007 11:00 pm

Re: Replace in all files - HEX mode

Postby Mofi » Tue Jan 08, 2008 8:22 am

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.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4055
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Replace in all files - HEX mode

Postby phelan » Tue Jan 08, 2008 8:47 pm

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
User avatar
phelan
Newbie
 
Posts: 9
Joined: Mon Jul 02, 2007 11:00 pm


Return to Macros