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?
Reverse Engineering Stack Exchange is a question and answer site for researchers and developers who explore the principles of a system through analysis of its structure, function, and operation. It only takes a minute to sign up.
Sign up to join this communityI 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?
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
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
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.
sudo apt-get install radare2
and then translate with rasm2 -a arm -b 32 add R0, R1, R2
??
Apr 15, 2018 at 16:12