This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

reformatting user command argument


Hello, I've written a macro to assemble instructions directly to memory
using the nasm assembler to make patching binaries using `set write`
easier, it works great, but as a final touch I'd like to be able to tell
the assembler the address where the code will be inserted.

This works fine if I call my macro as `assemble 0x12345`, or `assemble
$pc` but if I use `assemble _start` i cant convert that to an address. I
thought `set $arg0 = (unsigned) $arg0` might work, but no such luck.

For example, this will work:

$ gdb --write -q testcase
(gdb) assemble 0x80489a4
Instructions will be written to 0x80489a4.
Type instructions, one per line.
End with a line saying just "end".
>jmp $+18
>msg: db "This is a test.",0xa
>mov eax, 4
>mov ebx, 1
>mov ecx, msg
>mov edx, 16
>int 0x80
>xor eax, eax
>xor ebx, ebx
>inc eax
>int 0x80
>end
(gdb) q
$ ./testcase 
This is a test.

(I could have used call/pop but this is just an example)

But this wont, as the assembler doesnt know what main is:

$ gdb --write -q testcase
(gdb) assemble main
Instructions will be written to 0x80489a4.
Type instructions, one per line.
End with a line saying just "end".
>msg: db "foobar"
>mov eax, msg
>end
error: symbol `main' not defined before use
error: No or invalid offset specified in ORG directive.

My macro is here <http://dev.gentoo.org/~taviso/assemble.txt>

Am I out of luck? I could just document that the user should enter `org
ADDR` (the pseudo-op nasm uses for this), but I'd rather automate it if
possible.

Thanks for any advice.

-- 
-------------------------------------
taviso@sdf.lonestar.org | finger me for my pgp key.
-------------------------------------------------------

Attachment: pgp00000.pgp
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]