I'm using Mac OS 10.2.2 and I need to find a command line hex editor. I figure there's already one built-in, but I just don't know enough about Unix, yet. Basically, what I want to do is tell the hexeditor to open a file, replace a specific offset with a new value, then put the resulting file somewhere. For example:
hexeditor inputfile offset newvalue > outputfile
It would also be nice to be able to specify the block size, since I am used to looking at the code in byte-sized chunks (pun not intended). Can anyone tell me which command(s) would get this done?
As for a command, take a look at the od command. od is octal dump. There are more than likely other utilities, but not having much use for these sorts of commands on a daily basis, I do not know of them. Sorry I cannot help further.
Thanks for taking the time to reply. Unfortunately, od won't help here because 1) it's deprecated in favor of hexdump (at least in Darwin), and 2) it only displays the file in hex, not let you edit it. For instance:
hexdump -C myfile // prints myfile in blocks of 1 byte to the standard output
hexdump -C myfile > outputfile // creates a text file with the results
It's the perfect viewer, and I could check my work quickly with hexdump, but first I need to actually edit the file. At first look, dd looked like it might provide a solution for me, but now I'm not so sure. Here's what I tried:
The results are that 0x03 through 0x05 were changed to 31 32 33, respectively. I'm not sure, but I believe that's the ASCII version of what I wanted to do. I really don't know enough about this to know what to try. I know enough to delete my hard drive or otherwise get myself into a terrible mess! Any more ideas?
@Perderabo
I don't think I have ksh. The default shell when opening the Terminal app is tcsh, but I'm most familiar with sh (which is bash in Darwin, I think). Anyways, I couldn't get echo \\0123 to work for me. The man pages in Darwin are a bit on the sketchy side. The man page for echo, for instance, tells me the format to use, describes the -n option briefly, and that it writes to the standard output. Not very informative, which might not matter for echo, but that's not the point. That's why all my learning has happened here and in Google groups. I also don't have adb. They might have it in a later release (I'm using Mac OS 10.2.2).
@Driver
That tip on how to write the hexadecimal values with printf is exactly what I needed. I used printf to pipe to dd and the patch worked perfectly.
@Anyone looking for a command line hex editor for Mac OS X
Here's the code I used if anyone's interested:
Explanation for newbies like me:
1) print 0x01 0x02 0x03
2) pipe to dd (block size = 1 byte, replace 3 blocks, skip to offset 0x03, do not truncate the file, apply output to myfile)
Viewing hexdump-myfile shows that myfile was patched:
Thanks for helping the newbie, guys!
Hi, it's me again. Now that I have the basics down for this, I am trying to make a versatile patching script that can dynamically patch at different offsets.
This script works as long as blah is true. If blah is not true, however, I'm obviously going to have a problem since what I want printf to output is \x00\x01\x02\x03, not \x00 01 02 03. I thought that perhaps using sed would work, but it appears that sed likes to output the ascii character as opposed to the hexadecimal output I'm trying to achieve. To expand on this example, for instance:
...produces...
...which is the ascii character version of the first byte of my input (\x00). Anyone got any ideas on how I can splice the \x into the bytes I'm trying to input?
Ouch. Now I feel really sub-newby-ish. I was working out an elaborate solution with arrays and all sorts of junk when it dawned on me that the answer was easier than I could have imagined...
Apparently all I have to do to get the \x in there is this:
I think I'm going to go hide now...
Assume I have a file \usr\home\\somedir\myfile123.txt
and I want to replace all occurencies of the two (concatenated) hex values x'AD' x'A0' bytwo other (concatenated) hex values x'20' x'6E'
How can I achieve this with the gnu sed tool?
Additional question: Is there a way to let sed show... (1 Reply)
Hi,
Is there really a difference between these two, std::hex and ios::hex??
I stumbled upon reading a line, "std::ios::hex is a bitmask (8 on gcc) and works with setf(). std::hex is the operator". Is this true?
Thanks (0 Replies)
Is there any command or VARIABLE in unix to display only bash builtin commands?. Some days back I worked on that, but now I do not remember.
Can anyone please reply for this?... (4 Replies)
Hi All,
My main intension of is to convert the Hexstring stored in a char* into hex and then prefixing it with "0x" and suffix it with ','
This has to be done for all the hexstring char* is NULL.
Store the result prefixed with "0x" and suffixed with ',' in another char* and pass it to... (1 Reply)
Hi All,
I am running a script , working very fine on cmd prompt. The problem is that when I open do crontab -e even after setting editor to vi by
set EDITOR=vi it does not open a vi editor , rather it do as below.....
/////////////////////////////////////////////////////
$ set... (6 Replies)
Hi,
I knw its a silly question, but am a newbie to 'vi' editor. I'm forced to use this, hence kindly help me with this question.
How can i paste a chunk 'copied from' a different editor(gedit) in 'vi editor'?
As i see, p & P options does work only within 'vi'. (10 Replies)
I am new to Unix scripting. I would like to know if someone can point me to a site which lists any built-in commands in there scripted form. I thought to start with the basics and learn from example.
Thanks
JSP (2 Replies)
Dear experts
I am learning awk command through some books on Solaris 8.
I have tested the folloing command
awk 'BEGIN { print match ("And" , /d/)}'
then the result is as following
awk: syntax error near line 1
awk: illegal statement near line 1
Could you please help on this and just... (4 Replies)