2

I looking for simple tool(not site) to translate arm instruction to hex like http://armconverter.com/.

Without linker , I want put 1 instruction , and want get the hex .

Do you know one please?

2 Answers 2

5

as i commented to Elians post rasm2 works in windows as is

rasm2 -a arm -b 32 "add r0, r1, r2" will return 020081e0

you can use keystone / capstone to assemble and disassemble

:\>python
>>> from keystone import *
>>> for i in (Ks(KS_ARCH_ARM,KS_MODE_ARM).asm ("add R0,R1,R2" , 0x400000) )[0]:
...     print "%02x " % i
...
02
00
81
e0
>>>

or if you have visual studio you can compile and dumpbin a single instruction

:\>cat foo.asm
    AREA .text, CODE, ARM
test PROC
    add R0,R1,R2
    ENDP
    END

:\>armasm /nologo foo.asm

:\>dumpbin /disasm foo.obj | grep add
  00000000: EB01 0002 add         r0,r1,r2

with keystone you use KS_MODE_THUMB with rasm you should be using -b 16 but it seems there is a bug where rasm2 can disassemble hex pairs correctly but not assemble it back again

so may be you follow it up in github issues for radare2

>>> from keystone import *
>>> for i in (Ks(KS_ARCH_ARM , KS_MODE_THUMB).asm("add r0,r1,r2" , 0 ))[0]:
...     print "%02x " %i ,
...
01  eb  02  00
>>> ^Z


C:\>rasm2 -a arm -b 16 -d "01 eb 02 00"
add.w r0, r1, r2

C:\>rasm2 -a arm -b 16 add.w r0, r1, r2
Cannot assemble 'add.w' at line 3
invalid
2
  • I have little misunderstanding, and will happy if you can help me , . I want the simple way to get each time the hex for 1 arm instruction . 1)how can I install rasm2 n windows that I can run rasm2 -a arm -b 32 "add r0, r1, r2"` 2) what is the different between keystone and keypatch? thank you Apr 15, 2018 at 20:19
  • what is the problem with installing double click the installer is all that is needed :( radare.mikelloc.com/get/2.3.0/… i dont know what keypatch is it is for ida and i havent used it keystone can be installed with pip install keystone
    – blabb
    Apr 15, 2018 at 20:26
2

For this exact purpose I highly suggest using a command line tool such as rasm2.

It is a tool that comes with the radare2 suite. One of it's basic capabilities is translating assembly instructions in various architectures to opcodes and vice versa. The usage is fairly simple:

# rasm2 -a arm -b 32 "add R0, R1, R2"
020081e0

Here:

-a specifies the architecture.

-b specifies the bits (where 16 is Thumb-1)

For more information there is plenty, such as the radare2 blog and official book.

7
  • how can I do it on windows please? Apr 15, 2018 at 16:02
  • @ivn23744sawoe.com it technically can be done but it is experimental (refer to radare.gitbooks.io/radare2book/content/introduction/…) however, I highly suggest using cygwin or something similar to get the best out of it (I believe also listed in the link above. Also, this question may be too broad or subjective I'd suggest limiting the scope for "offline windows command line tool' or something similar to improve it's quality. Apr 15, 2018 at 16:03
  • so you not recommend use radare2 on wondows? I once download from rada.re/r ... do you only recommend use on Linux and install with sudo apt-get install radare2 and then translate with rasm2 -a arm -b 32 add R0, R1, R2 ?? Apr 15, 2018 at 16:12
  • 2
    @ivn23744sawoe.com Yes it works on Ubuntu as you said. It can also work on windows as stated in the documentation earlier. Please try the methods yourself and see what works for you instead of positing it as a comment here. Still this is a Q&A site, not a technical support forum :) Apr 15, 2018 at 16:25
  • 1
    @ op rasm2 works on windows @ElianKamal you need to add quotes iirc 80e0 corresponds to add r0, r0 , r0 not what you want you need to get back 02008e01
    – blabb
    Apr 15, 2018 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.