Search and replace over command line

Help on how to use HxD.
Post Reply
offom
Posts: 3
Joined: 26 May 2012 15:54

Search and replace over command line

Post by offom » 29 May 2012 19:38

Mael, just an another question,

How can I create a .bat for HxD to automate like

open etc.exe
change 0004AE 00 00 80 3F
to
00 00 40 3F

??

Maël
Site Admin
Posts: 1137
Joined: 12 Mar 2005 14:15

Re: Search and replace over command line

Post by Maël » 30 May 2012 00:25

HxD has no command line interface so it's not possible to automate this.

DVV
Posts: 12
Joined: 17 Jan 2008 11:24

Re: Search and replace over command line

Post by DVV » 20 Jun 2012 00:10

There's a tiny command-line tool which can do this: bincmp 2.2 (http://sourceforge.net/projects/bincmp/files/bincmp2/)
For your example, create a text file named "patch.txt" with the following lines:

Code: Select all

0004AE: 00 00 
0004AF: 00 00
0004B0: 80 40
0004B1: 3F 3F
and execute "bincmp -patch patch.txt etc.exe". (Actually, just one byte at offset 0004B0 needs to be patched, so other lines are not necessary and will be ignored during patching.)

Maël
Site Admin
Posts: 1137
Joined: 12 Mar 2005 14:15

Re: Search and replace over command line

Post by Maël » 20 Jun 2012 20:56

Thanks for helping out :)

DVV
Posts: 12
Joined: 17 Jan 2008 11:24

Re: Search and replace over command line

Post by DVV » 22 Jun 2012 11:51

There is even more powerful solution :) I think I've already mentioned the XVI32 hex-editor with its amazing XVI-script ability (and we all expect for similar ability in HxD ;)). This is very helpful when you need extra abilities to find, replace, insert, remove and so on. As the documnetation says,
XVI32U.chm wrote:

Code: Select all

XVI32.exe readme.txt /S=win2unix.xsc
This will start XVI32, open readme.txt and then execute the script win2unix.xsc automatically.
Unlike HxD, the XVI32 hex-editor loads a whole file into memory. Therefore you can not use it with a very big file (with size more than 1-2 GB).

Maël
Site Admin
Posts: 1137
Joined: 12 Mar 2005 14:15

Re: Search and replace over command line

Post by Maël » 22 Jun 2012 17:25

Thanks for your contribution. I removed the link to the competing hex editor though, I hope you understand :). Using a search engine still works though.

dremuler
Posts: 1
Joined: 29 Apr 2019 01:22

Re: Search and replace over command line

Post by dremuler » 29 Apr 2019 01:35

DVV wrote:
20 Jun 2012 00:10
There's a tiny command-line tool which can do this: bincmp 2.2 (http://sourceforge.net/projects/bincmp/files/bincmp2/)
For your example, create a text file named "patch.txt" with the following lines:

Code: Select all

0004AE: 00 00 
0004AF: 00 00
0004B0: 80 40
0004B1: 3F 3F
and execute "bincmp -patch patch.txt etc.exe". (Actually, just one byte at offset 0004B0 needs to be patched, so other lines are not necessary and will be ignored during patching.)
Probably im about 7 years late! but i just register to say thanks! this post, and the tool was very useful.
In order to demostrate my grateful im gonna explain (more clearly) about this process and i hope this help anyone else, like me, and dont have to spent a couple of hours testing and resereaching about this.
sorry if my english is not very good, im not american or british!

0.-For test this process create a folder called TEST in C:\ and paste the contents of bincmp zip inside.
after that open command line and type CD C:\TEST after that CD:\TEST\bincmp to open it.

this an example of how to insert bytes without patch file, probably in 2012, bincmp will not support that feature but now, actually does.

remember to follow the syntax order of the demo below

bincmp "file.exe" -patchstr "FA6238A: 8B 31; FA6238B: 87 C0; FA6238C: 3C 90; FA6238D: 01 90; FA6238E: 00 90; FA6238F: 00 90"

"file.exe" = the file that u want to insert bytes or replace hex values.
FA6238A: = is the offset, in HxD could appear like this: 0FA62380 just remove the 1st 0 and last 0, the A is talking about the block, 0,1,2,3,4,5,6,A,B,C,D,E,F in other words FA6238 its the row, and A its the column (represented with 0A in HxD)
8B= its the value that u want to change (old value) and the program will looking for.
31=its the value that u want to insert (new value) and the program will insert it.
Other values are examples.


i hope this help anyone else and become useful

Post Reply