LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-29-2012, 02:01 PM   #1
otaku2k2
LQ Newbie
 
Registered: Mar 2009
Posts: 5

Rep: Reputation: 0
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.
 
Old 01-29-2012, 04:12 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Not sure why you need xxd, you can just do an inplace edit with sed
 
Old 01-30-2012, 01:41 AM   #3
otaku2k2
LQ Newbie
 
Registered: Mar 2009
Posts: 5

Original Poster
Rep: Reputation: 0
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.
 
Old 01-30-2012, 02:41 AM   #4
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
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.
 
Old 01-30-2012, 03:20 AM   #5
otaku2k2
LQ Newbie
 
Registered: Mar 2009
Posts: 5

Original Poster
Rep: Reputation: 0
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.
 
Old 01-30-2012, 03:55 AM   #6
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
I know of bgrep:
https://github.com/tmbinc/bgrep

In the past I have made patches in C that search for and patch intelligently.
 
Old 01-30-2012, 06:06 AM   #7
otaku2k2
LQ Newbie
 
Registered: Mar 2009
Posts: 5

Original Poster
Rep: Reputation: 0
I also found the program called strings.

Thanks. Linux mates are the best.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] string to hex parser avee137 Programming 5 09-10-2011 04:41 PM
Looking for tcpdump syntax to start hex output at a given byte offset in the packet silentquasar Linux - Networking 1 08-06-2011 06:03 AM
Notice: Uninitialized string offset: 1 in [PHP] Aquarius_Girl Programming 8 11-10-2010 10:09 PM
Hex String to ttysX digmeupnow Linux - Newbie 1 11-25-2008 03:33 AM
Hex output of a hex/ascii input string mlewis Programming 35 04-10-2008 12:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration