One of the main programs distributed with radare and radare2 is 'rasm' (and 'rasm2).
This tool permits to assemble and disassemble stream of bytes or opcodes from pipes or files.
The way to disassemble some bytes is easy:
$ rasm2 'nop'
$ rasm2 -d '90'
Appending more than one opcode is done by the ';' character:
$ rasm2 'nop;mov eax,33;int3'
By default rasm2 uses the configuration of bits and cpu of the running system.
$ rasm2 -h
rasm2 [-e] [-o off] [-a arch] [-s stx] -d "op"|"hex"|- [-f file ..]
-d Disassemble from hexpair bytes
-f Read data from file
-o [offset] Offset where this opcode is suposed to be
-a [arch] Set architecture plugin
-b [bits] Set architecture bits
-s [syntax] Select syntax (intel, att)
-B Binary input/output (-l is mandatory for binary input)
-l [int] Input/Output length
-C Output in C format
-L List supported asm plugins
-e Use big endian
-V Show version information
If '-l' value is greater than output length, pad with nops
If the last argument is '-' reads from stdin
If we want to assemble one opcode for java we will do:
$ rasm -a java 'bipush 32'
Or maybe to assemble an opcode in 16bit for x86 to patch a bios?
$ rasm -a x86 -b 16 'mov ax,32'
Simple, huh? :)
One of the main uses of the generated code of rasm2 is to be injected
or used to patch a binary in order to fix a vulnerability or optimize
the startup process.
So, we will have to specify an offset where this code will be assembled with the '-o' flag