Author Topic: Find hex string in hex editor window  (Read 324 times)


  • New member
  • *
  • Posts: 6
Find hex string in hex editor window
« on: April 20, 2021, 11:30:06 pm »
Hi guys!
I'm a noob... I can load a bin file and show it in hex editor window on my program and modify it no problem. I need to search from address $2000 upwards until I find the first instance of "00000A" (which changes address randomly) and display 6 bytes on the line right under it. So if "00000A" is found at line  $500 I need to display the first 6 bytes of line $510. Why from $2000 up? Because there are other instances but the very last instance is the one that is followed by the string that I need. I can display it if it is at a fixed address but I'm having a hard time coming up with the code to do this search. Hope somebody can help me out with this.

I can do it with if's but it would be too many repetitions (over 500) of the same exact if. Maybe somebody could point me in the right direction to a loop?
« Last Edit: April 21, 2021, 07:31:26 am by JCDes »


  • New member
  • *
  • Posts: 6
Re: Find hex string in hex editor window
« Reply #1 on: April 21, 2021, 09:47:04 pm »
This works but the script can't handle this repeated the amount of times I need it to be executed. I've gone to endless loop land a million times and still can't get it right.

All variables are declared this is what I got and can't think of a way to make a loop work for me.

a33 := $2000;
a34 := $3000;
a32 := inttohex(GetDwordHexEdit(a33,8),8);
a35 := inttohex(GetDwordHexEdit(a34,8),8);

if a32 <> '00000003' then a33 := a33 - 16;
if a32 <> '00000003' then a34 := a34 - 16;
if a32 = '00000003' then Code := a35;
a32 := inttohex(GetDwordHexEdit(a33,8),8);
a35 := inttohex(GetDwordHexEdit(a34,8),8);

How can I make this repeat itself until I get the result? Like I said I'm a noob...


  • Hero Member
  • *****
  • Posts: 4457
Re: Find hex string in hex editor window
« Reply #2 on: April 21, 2021, 11:12:56 pm »
Trying to follow your code and your projections is a little straining on this old man!  :-\

 Anyways, I assume you have a ASCII /Text list of a HEX string dump of some memory or file so this is what I would do...

First simply search for the desired value in a binary path...

 Set a Pointer to the start of where you want to be.. , in this case $2000, you can use INDEXes from an array too if you wish..., what ever the method you would like.

 It looks like you are looking for a 32 bit field so use a PDWORD type and set it to the start of your memory search and use it to find your value
While MyPDWord < Max_Range  do
 If MYPDWORD^ = $00000A Then 
    //We found it.
  End else Inc(UintPtr(MyPDWORd));

 check here to the Max_Range and ensure it didn't abort to the end of the buffer..

  Now you have the exact place in memory but now you would like to know how to determine the first HEX line it would be shown..
 MyFirstHexLineAddress  := UintPtr(MyPWord) and (N0t $0A);

and of course the next line would be $0A added to it..

Of course you can do all of this using integers as an index too...
« Last Edit: April 21, 2021, 11:15:18 pm by jamie »
The only true wisdom is knowing you know nothing


  • New member
  • *
  • Posts: 6
Re: Find hex string in hex editor window
« Reply #3 on: April 21, 2021, 11:48:01 pm »
It's a bin file loaded on to a hex edit window.


  • Full Member
  • ***
  • Posts: 247
Re: Find hex string in hex editor window
« Reply #4 on: April 22, 2021, 09:15:09 am »
What component do you use for hex editor?
Can you make a small test/demo project? I don't think it would be too hard to help you then.


TinyPortal © 2005-2018