mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-23 13:19:54 +00:00
* r_asm
- Fixed asm_bea - More refactoring on rasm2
This commit is contained in:
parent
2cc6fcd1e4
commit
d8f56c56e9
@ -1,26 +0,0 @@
|
||||
@echo off
|
||||
|
||||
set INCLUDE=C:\PellesC\Include\;C:\PellesC\Include\Win\;
|
||||
set LIB=C:\PellesC\Lib\;C:\PellesC\Lib\Win\;
|
||||
set name=BeaEngine
|
||||
|
||||
echo ____________________________________
|
||||
echo *
|
||||
echo * COMPILATION with POCC.EXE (Pelles C)
|
||||
echo *
|
||||
echo ____________________________________
|
||||
\PellesC\bin\Pocc /Ze /W0 %name%.c
|
||||
|
||||
|
||||
echo ____________________________________
|
||||
echo *
|
||||
echo * CREATE LIB with POLIB.EXE (Pelles C)
|
||||
echo *
|
||||
echo ____________________________________
|
||||
\PellesC\bin\Polib /out:%name%.lib %name%.obj
|
||||
pause
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,28 +0,0 @@
|
||||
@echo off
|
||||
|
||||
set INCLUDE=C:\Program Files\PellesC\Include\;C:\Program Files\PellesC\Include\Win\;
|
||||
set LIB=C:\Program Files\PellesC\Lib\;C:\Program Files\PellesC\Lib\Win64\;
|
||||
set name=BeaEngine
|
||||
|
||||
echo ____________________________________
|
||||
echo *
|
||||
echo * COMPILATION with POCC.EXE (Pelles C)
|
||||
echo *
|
||||
echo ____________________________________
|
||||
|
||||
"\Program Files\PellesC\bin\pocc" /Tamd64-coff /Ze /W2 %name%.c
|
||||
|
||||
|
||||
echo ____________________________________
|
||||
echo *
|
||||
echo * CREATE LIB with POLIB.EXE (Pelles C)
|
||||
echo *
|
||||
echo ____________________________________
|
||||
|
||||
"\Program Files\PellesC\bin\PoLib" /MACHINE:X64 /out:%name%64.lib %name%.obj
|
||||
pause
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,26 +0,0 @@
|
||||
@echo off
|
||||
|
||||
set INCLUDE=C:\PellesC\Include\;C:\PellesC\Include\Win\;
|
||||
set LIB=C:\PellesC\Lib\;C:\PellesC\Lib\Win\;
|
||||
set name=BeaEngine
|
||||
|
||||
echo ____________________________________
|
||||
echo *
|
||||
echo * COMPILATION with POCC.EXE (Pelles C)
|
||||
echo *
|
||||
echo ____________________________________
|
||||
\PellesC\bin\Pocc /Ze /W0 %name%.c
|
||||
|
||||
|
||||
echo ____________________________________
|
||||
echo *
|
||||
echo * CREATE DLL with POLINK.EXE (Pelles C)
|
||||
echo *
|
||||
echo ____________________________________
|
||||
\PellesC\bin\PoLink /DLL /EXPORT:_Disasm@4 %name%.obj kernel32.lib
|
||||
pause
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,27 +0,0 @@
|
||||
@echo off
|
||||
|
||||
set INCLUDE=C:\Program Files\PellesC\Include\;C:\Program Files\PellesC\Include\Win\;
|
||||
set LIB=C:\Program Files\PellesC\Lib\;C:\Program Files\PellesC\Lib\Win64\;
|
||||
set name=BeaEngine
|
||||
|
||||
echo ____________________________________
|
||||
echo *
|
||||
echo * COMPILATION with POCC.EXE (Pelles C)
|
||||
echo *
|
||||
echo ____________________________________
|
||||
"\Program Files\PellesC\bin\pocc" /Tamd64-coff /Ze /W0 %name%.c
|
||||
|
||||
|
||||
echo ____________________________________
|
||||
echo *
|
||||
echo * CREATE DLL with POLINK.EXE (Pelles C)
|
||||
echo *
|
||||
echo ____________________________________
|
||||
|
||||
"\Program Files\PellesC\bin\PoLink" /MACHINE:X64 /DLL /EXPORT:Disasm /out:%name%64.dll %name%.obj
|
||||
pause
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -18,6 +18,9 @@
|
||||
|
||||
#ifndef _INCLUDE_OLLY_
|
||||
#define _INCLUDE_OLLY_
|
||||
|
||||
#define Disasm Disasm_olly
|
||||
|
||||
//#define strupr str
|
||||
//#define strlwr //
|
||||
#define pow10l //
|
||||
|
@ -1,4 +1,4 @@
|
||||
CFLAGS=-I../../include -I../arch/ -I../arch/include -w
|
||||
CFLAGS=-I../../include -I../arch/ -I../arch/include -w -fPIC -shared -Wl,-R..
|
||||
# XXX
|
||||
# -Wall
|
||||
CFLAGS+=-DLIL_ENDIAN=1 -D__UNIX__
|
||||
@ -58,47 +58,47 @@ all: asm_dummy.so asm_x86.so asm_olly.so \
|
||||
@true
|
||||
|
||||
asm_dummy.so: asm_dummy.o
|
||||
${CC} ${CFLAGS} -fPIC -shared -o asm_dummy.so asm_dummy.o -Wl,-R..
|
||||
${CC} ${CFLAGS} -o asm_dummy.so asm_dummy.o
|
||||
@#strip -s asm_dummy.so
|
||||
|
||||
asm_x86.so: ${OBJ_X86}
|
||||
${CC} ${CFLAGS} -fPIC -shared -o asm_x86.so ${OBJ_X86} -Wl,-R..
|
||||
${CC} ${CFLAGS} -o asm_x86.so ${OBJ_X86}
|
||||
@#strip -s asm_x86.so
|
||||
|
||||
asm_olly.so: ${OBJ_X86_OLLY}
|
||||
${CC} ${CFLAGS} -fPIC -shared -o asm_olly.so ${OBJ_X86_OLLY} -w,-R..
|
||||
${CC} ${CFLAGS} -o asm_olly.so ${OBJ_X86_OLLY}
|
||||
@#strip -s asm_x86_olly.so
|
||||
|
||||
asm_bea.so: ${OBJ_X86_BEA}
|
||||
${CC} ${CFLAGS} -fPIC -shared -o asm_bea.so ${OBJ_X86_BEA} -Wl,-R..
|
||||
${CC} ${CFLAGS} -o asm_bea.so ${OBJ_X86_BEA}
|
||||
@#strip -s asm_x86_bea.so
|
||||
|
||||
asm_arm.so: ${OBJ_ARM}
|
||||
${CC} ${CFLAGS} -fPIC -shared -o asm_arm.so ${OBJ_ARM} -Wl,-R..
|
||||
${CC} ${CFLAGS} -o asm_arm.so ${OBJ_ARM}
|
||||
@#strip -s asm_x86.so
|
||||
|
||||
asm_mips.so: ${OBJ_MIPS}
|
||||
${CC} ${CFLAGS} -fPIC -shared -o asm_mips.so ${OBJ_MIPS} -Wl,-R..
|
||||
${CC} ${CFLAGS} -o asm_mips.so ${OBJ_MIPS}
|
||||
@#strip -s asm_x86.so
|
||||
|
||||
asm_sparc.so: ${OBJ_SPARC}
|
||||
${CC} ${CFLAGS} -fPIC -shared -o asm_sparc.so ${OBJ_SPARC} -Wl,-R..
|
||||
${CC} ${CFLAGS} -o asm_sparc.so ${OBJ_SPARC}
|
||||
@#strip -s asm_x86.so
|
||||
|
||||
asm_ppc.so: ${OBJ_PPC}
|
||||
${CC} ${CFLAGS} -fPIC -shared -o asm_ppc.so ${OBJ_PPC} -Wl,-R..
|
||||
${CC} ${CFLAGS} -o asm_ppc.so ${OBJ_PPC}
|
||||
@#strip -s asm_x86.so
|
||||
|
||||
asm_bf.so: ${OBJ_BF}
|
||||
${CC} ${CFLAGS} -fPIC -shared -o asm_bf.so ${OBJ_BF} -Wl,-R..
|
||||
${CC} ${CFLAGS} -o asm_bf.so ${OBJ_BF}
|
||||
@#strip -s asm_x86.so
|
||||
|
||||
asm_csr.so: ${OBJ_CSR}
|
||||
${CC} ${CFLAGS} -fPIC -shared -o asm_csr.so ${OBJ_CSR} -Wl,-R..
|
||||
${CC} ${CFLAGS} -o asm_csr.so ${OBJ_CSR}
|
||||
@#strip -s asm_x86.so
|
||||
|
||||
asm_m68k.so: ${OBJ_M68K}
|
||||
${CC} ${CFLAGS} -fPIC -shared -o asm_m68k.so ${OBJ_M68K} -Wl,-R..
|
||||
${CC} ${CFLAGS} -o asm_m68k.so ${OBJ_M68K}
|
||||
@#strip -s asm_x86.so
|
||||
|
||||
clean:
|
||||
|
@ -16,15 +16,17 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64
|
||||
DISASM disasm_obj;
|
||||
|
||||
memset(&disasm_obj, '\0', sizeof(DISASM));
|
||||
disasm_obj.EIP = (int)buf;
|
||||
//disasm_obj.VirtualAddr = a->pc;
|
||||
//disasm_obj.Archi = ((a->bits == 64) ? 64 : 0);
|
||||
//disasm_obj.SecurityBlock = len;
|
||||
//if (a->syntax == R_ASM_SYN_ATT)
|
||||
// disasm_obj.Options = 0x400;
|
||||
//else
|
||||
// disasm_obj.Options = 0;
|
||||
Disasm(&disasm_obj);
|
||||
disasm_obj.EIP = (long long)buf;
|
||||
disasm_obj.VirtualAddr = a->pc;
|
||||
disasm_obj.Archi = ((a->bits == 64) ? 64 : 0);
|
||||
disasm_obj.SecurityBlock = len;
|
||||
if (a->syntax == R_ASM_SYN_ATT)
|
||||
disasm_obj.Options = 0x400;
|
||||
else
|
||||
disasm_obj.Options = 0;
|
||||
|
||||
aop->inst_len = Disasm(&disasm_obj);
|
||||
|
||||
snprintf(aop->buf_asm, 256, &disasm_obj.CompleteInstr);
|
||||
|
||||
if (aop->inst_len > 0) {
|
||||
|
@ -15,7 +15,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64
|
||||
t_disasm disasm_obj;
|
||||
|
||||
lowercase=1;
|
||||
aop->inst_len = Disasm(buf, len, a->pc, &disasm_obj, DISASM_FILE);
|
||||
aop->inst_len = Disasm_olly(buf, len, a->pc, &disasm_obj, DISASM_FILE);
|
||||
snprintf(aop->buf_asm, 256, "%s", disasm_obj.result);
|
||||
snprintf(aop->buf_hex, 256, "%s", disasm_obj.dump);
|
||||
|
||||
|
@ -18,7 +18,8 @@ static int rasm_show_help()
|
||||
printf( "rasm2 [-e] [-o offset] [-a arch] [-s syntax] -d \"opcode\"|\"hexpairs\"|-\n"
|
||||
" -d Disassemble from hexpair bytes\n"
|
||||
" -o [offset] Offset where this opcode is suposed to be\n"
|
||||
" -a [arch] Select architecture plugin\n"
|
||||
" -a [arch] Set architecture plugin\n"
|
||||
" -b [bits] Set architecture bits\n"
|
||||
" -s [syntax] Select syntax (intel, att, olly)\n"
|
||||
" -e Use big endian\n"
|
||||
" If the last argument is '-' reads from stdin\n\n"
|
||||
@ -28,7 +29,7 @@ static int rasm_show_help()
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
static int rasm_disasm(char *buf, u64 offset, char *arch, char *syntax, int big_endian)
|
||||
static int rasm_disasm(char *buf, u64 offset, int str)
|
||||
{
|
||||
struct r_asm_aop_t aop;
|
||||
u8 *data;
|
||||
@ -36,7 +37,7 @@ static int rasm_disasm(char *buf, u64 offset, char *arch, char *syntax, int big_
|
||||
int ret = 0;
|
||||
u64 idx = 0, word = 0, len = 0;
|
||||
|
||||
if (arch != NULL && strcmp(arch, "asm_bf")) {
|
||||
if (!str) {
|
||||
while(ptr[0]) {
|
||||
if (ptr[0]!= ' ')
|
||||
if (0==(++word%2))len++;
|
||||
@ -49,20 +50,8 @@ static int rasm_disasm(char *buf, u64 offset, char *arch, char *syntax, int big_
|
||||
data = (u8*)buf;
|
||||
}
|
||||
|
||||
if (arch == NULL || !r_asm_set(&a, arch))
|
||||
r_asm_set(&a, "asm_x86");
|
||||
|
||||
if (syntax != NULL) {
|
||||
if (!strcmp(syntax, "att"))
|
||||
r_asm_set_syntax(&a, R_ASM_SYN_ATT);
|
||||
else r_asm_set_syntax(&a, R_ASM_SYN_INTEL);
|
||||
} else r_asm_set_syntax(&a, R_ASM_SYN_INTEL);
|
||||
|
||||
r_asm_set_big_endian(&a, big_endian);
|
||||
r_asm_set_pc(&a, offset);
|
||||
|
||||
while (idx < len) {
|
||||
r_asm_set_pc(&a, a.pc + ret);
|
||||
r_asm_set_pc(&a, offset + idx);
|
||||
ret = r_asm_disassemble(&a, &aop, data+idx, len-idx);
|
||||
idx += ret;
|
||||
printf("%s\n", aop.buf_asm);
|
||||
@ -71,16 +60,14 @@ static int rasm_disasm(char *buf, u64 offset, char *arch, char *syntax, int big_
|
||||
return (int)idx;
|
||||
}
|
||||
|
||||
static int rasm_asm(char *buf, u64 offset, char *arch, char *syntax, int big_endian)
|
||||
static int rasm_asm(char *buf, u64 offset)
|
||||
{
|
||||
struct r_asm_aop_t aop;
|
||||
int ret;
|
||||
|
||||
|
||||
/* TODO: Arch, syntax... */
|
||||
r_asm_set(&a, "asm_x86_olly");
|
||||
|
||||
r_asm_set_big_endian(&a, big_endian);
|
||||
r_asm_set(&a, "asm_olly");
|
||||
r_asm_set_pc(&a, offset);
|
||||
|
||||
ret = r_asm_assemble(&a, &aop, buf);
|
||||
@ -103,9 +90,8 @@ static int __lib_asm_dt(struct r_lib_plugin_t *pl, void *p, void *u) { return R_
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char *arch, *syntax;
|
||||
u64 offset = 0;
|
||||
int big_endian = 0, dis = 0, c;
|
||||
u64 offset = 0x8048000;
|
||||
int dis = 0, str = 0, c;
|
||||
|
||||
r_asm_init(&a);
|
||||
r_lib_init(&l, "radare_plugin");
|
||||
@ -116,14 +102,21 @@ int main(int argc, char *argv[])
|
||||
if (argc<2)
|
||||
return rasm_show_help();
|
||||
|
||||
while ((c = getopt(argc, argv, "da:s:o:h")) != -1)
|
||||
while ((c = getopt(argc, argv, "da:b:s:o:h")) != -1)
|
||||
{
|
||||
switch( c ) {
|
||||
case 'a':
|
||||
arch = optarg;
|
||||
r_asm_set(&a, optarg);
|
||||
if (!strcmp(optarg, "asm_bf"))
|
||||
str = 1;
|
||||
break;
|
||||
case 'b':
|
||||
r_asm_set_bits(&a, r_num_math(NULL, optarg));
|
||||
break;
|
||||
case 's':
|
||||
syntax = optarg;
|
||||
if (!strcmp(optarg, "att"))
|
||||
r_asm_set_syntax(&a, R_ASM_SYN_ATT);
|
||||
else r_asm_set_syntax(&a, R_ASM_SYN_INTEL);
|
||||
break;
|
||||
case 'd':
|
||||
dis = 1;
|
||||
@ -132,7 +125,7 @@ int main(int argc, char *argv[])
|
||||
offset = r_num_math(NULL, optarg);
|
||||
break;
|
||||
case 'e':
|
||||
big_endian = 1;
|
||||
r_asm_set_big_endian(&a, R_TRUE);
|
||||
break;
|
||||
case 'h':
|
||||
return rasm_show_help();
|
||||
@ -148,14 +141,14 @@ int main(int argc, char *argv[])
|
||||
break;
|
||||
buf[strlen(buf)-1]='\0';
|
||||
if (dis)
|
||||
offset += rasm_disasm(buf, offset, arch, syntax, big_endian);
|
||||
else offset += rasm_asm(buf, offset, arch, syntax, big_endian);
|
||||
offset += rasm_disasm(buf, offset, str);
|
||||
else offset += rasm_asm(buf, offset);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (dis)
|
||||
return rasm_disasm(argv[optind], offset, arch, syntax, big_endian);
|
||||
else return rasm_asm(argv[optind], offset, arch, syntax, big_endian);
|
||||
return rasm_disasm(argv[optind], offset, str);
|
||||
else return rasm_asm(argv[optind], offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user