radareorg / radare2

UNIX-like reverse engineering framework and command-line toolset
https://www.radare.org/
GNU Lesser General Public License v3.0
20.69k stars 3.01k forks source link

The x86 handmade assembler (x86.nz) can not handle SIB addressing #3644

Closed sghctoma closed 8 years ago

sghctoma commented 9 years ago

Currently the x86.nz assembler plugin can not assemble instructions where scale-index-base addressing is used. Example:

[0x00 radare2]$ echo 'mov eax, dword [eax*4+0x1337]' | rasm2 -a x86.nz -
8b4037

The same with x86.nasm:

[0x00 radare2]$ echo 'mov eax, dword [eax*4+0x1337]' | rasm2 -a x86.nasm -
8b048537130000
radare commented 9 years ago

For 32 bits use asm.olly unless you are alergic to gpl.

Can you add some tests?

On 31 Oct 2015, at 21:27, sghctoma notifications@github.com wrote:

Currently the x86.nz assembler plugin can not assemble instructions where scale-index-base addressing is used. Example:

[0x00 radare2]$ echo 'mov eax, dword [eax*4+0x1337]' | rasm2 -a x86.nz - 8b4037 The same with x86.nasm:

[0x00 radare2]$ echo 'mov eax, dword [eax*4+0x1337]' | rasm2 -a x86.nasm - 8b048537130000 — Reply to this email directly or view it on GitHub.

sghctoma commented 9 years ago

I'm allergic to GPL, but I can live with it :) But for the moment I've just changed the default fallback assembler to x86.nasm. Which got me thinking: what if the fallback assembler would not be hardcoded, but there was an option to set it? Would you be OK with such an option?

About the tests: I've started to look around, and got a little confused. There are some tests in libr/asm/t that seems to be used by make quality but all the docs point to radare2-regressions in regards of tests. Am I right in assuming that tests should be written in radare2-regressions?

radare commented 9 years ago

Yes it will be good to have an asm.asm option. Its just filling a pointer, because its not hardcoded at all. I can do it quickly, but we need a better name for it, because asm.asm looks retarded to me.

The asm/t thing is there because of practicity. All tedtsuites started i libr/*/t but have been moved to r2r to avoid the bloatness of the bins and be able to work in there without interfering the core dev.

Those tests should be moved into r2r, but as long as they are handy for testing new assemblers and such they are still there.

Right now those tests can be pushed dirextly into r2r because they need some rework, but you get the idea of how assemblers should be tested.

On 01 Nov 2015, at 12:18, sghctoma notifications@github.com wrote:

I'm allergic to GPL, but I can live with it :) But for the moment I've just changed the default fallback assembler to x86.nasm. Which got me thinking: what if the fallback assembler would not be hardcoded, but there was an option to set it? Would you be OK with such an option?

About the tests: I've started to look around, and got a little confused. There are some tests in libr/asm/t that seems to be used by make quality but all the docs point to radare2-regressions in regards of tests. Am I right in assuming that tests should be written in radare2-regressions?

— Reply to this email directly or view it on GitHub.

sghctoma commented 9 years ago

By hardcoded I meant that if the current plugin is not able to assemble, r2 always chooses the .nz as assembler provided it exists (libr/asm/asm.c@375). As for the name: asm.asm looks silly indeed, maybe asm.assembler is a bit better.

Thanks for the clarification on the tests, I'll start writing them!