reformatting user command argument

Tavis Ormandy
2006-05-11T12:46:59Z

[-- Attachment #1: Type: text/plain, Size: 1736 bytes --]

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 #2: Type: application/pgp-signature, Size: 238 bytes --]