LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to get hex offset of string (https://www.linuxquestions.org/questions/linux-software-2/how-to-get-hex-offset-of-string-926343/)

otaku2k2 01-29-2012 02:01 PM

How to get hex offset of string
 
Hi.

I got a file, that I want to patch. I know the hex code I want to patch, but not the offset. How can I do that? Now I am looking for terminal software, that allows me to get the offset of the string, so I can pipe it to xxd.

Thanks.

kbp 01-29-2012 04:12 PM

Not sure why you need xxd, you can just do an inplace edit with sed

otaku2k2 01-30-2012 01:41 AM

Because sed cannot replace by offset, just by hex code. Or can it?

sed and xxd are not my problem. The problem is to get the offset.

kbp 01-30-2012 02:41 AM

Usually to patch binaries you can just match a longer set of hex chars to make it more unique, try 'grep -c <pattern>' with longer patterns until you only get one match then feed it into sed for the search and replace.

Sorry, in answer to your actual question try diff and patch, I can't say I've tried but they're probably a good bet.

otaku2k2 01-30-2012 03:20 AM

Thanks for the ideas. One problem is that I also have to patch single bytes, which can only be done by offset or I would patch any matching byte of the whole file.

H_TeXMeX_H 01-30-2012 03:55 AM

I know of bgrep:
https://github.com/tmbinc/bgrep

In the past I have made patches in C that search for and patch intelligently.

otaku2k2 01-30-2012 06:06 AM

I also found the program called strings.

Thanks. Linux mates are the best.


All times are GMT -5. The time now is 01:48 AM.