Merge asm.8051 into anal.8051 ##refactor
* Respect R_ANAL_ARCHINFO_INV_OP_SIZE during disasm
This commit is contained in:
parent
863bdbcf5f
commit
6ab659698e
|
@ -75,7 +75,6 @@ io.ptrace
|
||||||
io.procpid
|
io.procpid
|
||||||
io.shm
|
io.shm
|
||||||
io.zip
|
io.zip
|
||||||
asm.8051
|
|
||||||
asm.tms320
|
asm.tms320
|
||||||
asm.sh
|
asm.sh
|
||||||
asm.arm_winedbg
|
asm.arm_winedbg
|
||||||
|
|
|
@ -65,7 +65,6 @@ anal.rsp
|
||||||
anal.wasm
|
anal.wasm
|
||||||
anal.pyc
|
anal.pyc
|
||||||
esil.dummy
|
esil.dummy
|
||||||
asm.8051
|
|
||||||
asm.arc
|
asm.arc
|
||||||
asm.arm_cs
|
asm.arm_cs
|
||||||
asm.arm_gnu
|
asm.arm_gnu
|
||||||
|
|
|
@ -64,7 +64,6 @@ io.ptrace
|
||||||
io.procpid
|
io.procpid
|
||||||
io.shm
|
io.shm
|
||||||
io.zip
|
io.zip
|
||||||
asm.8051
|
|
||||||
asm.tms320
|
asm.tms320
|
||||||
asm.sh
|
asm.sh
|
||||||
asm.arm_winedbg
|
asm.arm_winedbg
|
||||||
|
|
|
@ -57,7 +57,6 @@ anal.rsp
|
||||||
anal.wasm
|
anal.wasm
|
||||||
anal.pyc
|
anal.pyc
|
||||||
esil.dummy
|
esil.dummy
|
||||||
asm.8051
|
|
||||||
asm.arc
|
asm.arc
|
||||||
asm.arm_cs
|
asm.arm_cs
|
||||||
asm.arm_gnu
|
asm.arm_gnu
|
||||||
|
|
|
@ -46,7 +46,6 @@ anal.rsp
|
||||||
anal.wasm
|
anal.wasm
|
||||||
anal.pyc
|
anal.pyc
|
||||||
esil.dummy
|
esil.dummy
|
||||||
asm.8051
|
|
||||||
asm.arc
|
asm.arc
|
||||||
asm.arm_gnu
|
asm.arm_gnu
|
||||||
asm.arm_winedbg
|
asm.arm_winedbg
|
||||||
|
|
|
@ -26,7 +26,6 @@ anal.x86_cs
|
||||||
anal.xcore_cs
|
anal.xcore_cs
|
||||||
anal.i4004
|
anal.i4004
|
||||||
esil.dummy
|
esil.dummy
|
||||||
asm.8051
|
|
||||||
asm.arm_cs
|
asm.arm_cs
|
||||||
asm.arm_winedbg
|
asm.arm_winedbg
|
||||||
asm.dalvik
|
asm.dalvik
|
||||||
|
|
|
@ -39,7 +39,6 @@ anal.6502
|
||||||
anal.snes
|
anal.snes
|
||||||
anal.riscv
|
anal.riscv
|
||||||
esil.dummy
|
esil.dummy
|
||||||
asm.8051
|
|
||||||
asm.arc
|
asm.arc
|
||||||
asm.arm_cs
|
asm.arm_cs
|
||||||
asm.arm_gnu
|
asm.arm_gnu
|
||||||
|
|
|
@ -27,7 +27,6 @@ anal.6502
|
||||||
anal.snes
|
anal.snes
|
||||||
anal.riscv
|
anal.riscv
|
||||||
esil.dummy
|
esil.dummy
|
||||||
asm.8051
|
|
||||||
asm.arc
|
asm.arc
|
||||||
asm.arm_cs
|
asm.arm_cs
|
||||||
asm.dalvik
|
asm.dalvik
|
||||||
|
|
|
@ -35,7 +35,6 @@ anal.wasm
|
||||||
anal.pyc
|
anal.pyc
|
||||||
anal.i4004
|
anal.i4004
|
||||||
esil.dummy
|
esil.dummy
|
||||||
asm.8051
|
|
||||||
asm.arc
|
asm.arc
|
||||||
asm.arm_cs
|
asm.arm_cs
|
||||||
asm.arm_gnu
|
asm.arm_gnu
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
/* radare - LGPL - Copyright 2009-2019 - hmht */
|
/* radare - LGPL - Copyright 2009-2019 - hmht */
|
||||||
#include"8051_ass.h"
|
|
||||||
|
|
||||||
/*****************************************************************************\
|
/*****************************************************************************\
|
||||||
* Architecture
|
* Architecture
|
||||||
|
@ -1360,11 +1359,10 @@ static parse_mnem_args mnemonic(char const *user_asm, int*nargs) {
|
||||||
* ## Section 7: radare2 glue and mnemonic tokenization
|
* ## Section 7: radare2 glue and mnemonic tokenization
|
||||||
--------------------------------------*/
|
--------------------------------------*/
|
||||||
|
|
||||||
int assemble_8051(RAsm *a, RAsmOp *op, char const *user_asm) {
|
int assemble_8051(RAnal *a, ut64 pc, char const *user_asm, ut8 *outbuf, int outlen) {
|
||||||
if (!a || !op || !user_asm) {
|
if (!a || !outbuf || !user_asm) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
r_strbuf_set (&op->buf_asm, user_asm);
|
|
||||||
while (!terminates_asm_line (*user_asm)
|
while (!terminates_asm_line (*user_asm)
|
||||||
&& (*user_asm == ' ' || *user_asm == '\t')) {
|
&& (*user_asm == ' ' || *user_asm == '\t')) {
|
||||||
user_asm += 1;
|
user_asm += 1;
|
||||||
|
@ -1396,7 +1394,7 @@ int assemble_8051(RAsm *a, RAsmOp *op, char const *user_asm) {
|
||||||
|
|
||||||
ut8 instr[4] = {0};
|
ut8 instr[4] = {0};
|
||||||
ut8 *binp = instr;
|
ut8 *binp = instr;
|
||||||
if (!mnem (carg, a->pc, &binp)) {
|
if (!mnem (carg, pc, &binp)) {
|
||||||
R_FREE (arg[0]);
|
R_FREE (arg[0]);
|
||||||
R_FREE (arg[1]);
|
R_FREE (arg[1]);
|
||||||
R_FREE (arg[2]);
|
R_FREE (arg[2]);
|
||||||
|
@ -1407,7 +1405,7 @@ int assemble_8051(RAsm *a, RAsmOp *op, char const *user_asm) {
|
||||||
R_FREE (arg[1]);
|
R_FREE (arg[1]);
|
||||||
R_FREE (arg[2]);
|
R_FREE (arg[2]);
|
||||||
size_t len = binp - instr;
|
size_t len = binp - instr;
|
||||||
r_strbuf_setbin (&op->buf, instr, len);
|
memcpy (outbuf, instr, len);
|
||||||
|
|
||||||
return binp - instr;
|
return binp - instr;
|
||||||
}
|
}
|
|
@ -121,6 +121,10 @@ R_API int r_anal_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le
|
||||||
ret = anal->cur->op (anal, op, addr, data, len, mask);
|
ret = anal->cur->op (anal, op, addr, data, len, mask);
|
||||||
if (ret < 1) {
|
if (ret < 1) {
|
||||||
op->type = R_ANAL_OP_TYPE_ILL;
|
op->type = R_ANAL_OP_TYPE_ILL;
|
||||||
|
op->size = r_anal_archinfo (anal, R_ANAL_ARCHINFO_INV_OP_SIZE);
|
||||||
|
if (op->size < 0) {
|
||||||
|
op->size = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
op->addr = addr;
|
op->addr = addr;
|
||||||
/* consider at least 1 byte to be part of the opcode */
|
/* consider at least 1 byte to be part of the opcode */
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
OBJ_8051=anal_8051.o
|
OBJ_8051=anal_8051.o
|
||||||
CFLAGS+=-I../asm/arch/8051
|
|
||||||
|
|
||||||
STATIC_OBJ+=${OBJ_8051}
|
STATIC_OBJ+=${OBJ_8051}
|
||||||
#OBJ_8051+=../../../../../../../../../../../../../../../../../../../../${LTOP}/asm/arch/8051/8051.o
|
#OBJ_8051+=../../../../../../../../../../../../../../../../../../../../${LTOP}/asm/arch/8051/8051.o
|
||||||
|
|
|
@ -6,8 +6,9 @@
|
||||||
#include <r_asm.h>
|
#include <r_asm.h>
|
||||||
#include <r_anal.h>
|
#include <r_anal.h>
|
||||||
|
|
||||||
#include <8051_ops.h>
|
#include "../arch/8051/8051_ops.h"
|
||||||
#include "../asm/arch/8051/8051_disas.c"
|
#include "../arch/8051/8051_ass.c"
|
||||||
|
#include "../arch/8051/8051_disas.c"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *name;
|
const char *name;
|
||||||
|
@ -1058,6 +1059,22 @@ static int i8051_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len
|
||||||
return op->size;
|
return op->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int archinfo(RAnal *anal, int q) {
|
||||||
|
switch (q) {
|
||||||
|
case R_ANAL_ARCHINFO_MIN_OP_SIZE:
|
||||||
|
return 1;
|
||||||
|
case R_ANAL_ARCHINFO_MAX_OP_SIZE:
|
||||||
|
return 3;
|
||||||
|
case R_ANAL_ARCHINFO_INV_OP_SIZE:
|
||||||
|
return 1;
|
||||||
|
case R_ANAL_ARCHINFO_ALIGN:
|
||||||
|
return 1;
|
||||||
|
case R_ANAL_ARCHINFO_DATA_ALIGN:
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
RAnalPlugin r_anal_plugin_8051 = {
|
RAnalPlugin r_anal_plugin_8051 = {
|
||||||
.name = "8051",
|
.name = "8051",
|
||||||
.arch = "8051",
|
.arch = "8051",
|
||||||
|
@ -1066,9 +1083,11 @@ RAnalPlugin r_anal_plugin_8051 = {
|
||||||
.desc = "8051 CPU code analysis plugin",
|
.desc = "8051 CPU code analysis plugin",
|
||||||
.license = "LGPL3",
|
.license = "LGPL3",
|
||||||
.op = &i8051_op,
|
.op = &i8051_op,
|
||||||
|
.opasm = &assemble_8051,
|
||||||
.set_reg_profile = &set_reg_profile,
|
.set_reg_profile = &set_reg_profile,
|
||||||
.esil_init = esil_i8051_init,
|
.esil_init = esil_i8051_init,
|
||||||
.esil_fini = esil_i8051_fini
|
.esil_fini = esil_i8051_fini,
|
||||||
|
.archinfo = archinfo
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef R2_PLUGIN_INCORE
|
#ifndef R2_PLUGIN_INCORE
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
#ifndef _8051_ASS_H
|
|
||||||
#define _8051_ASS_H
|
|
||||||
|
|
||||||
#include<r_asm.h>
|
|
||||||
int assemble_8051(RAsm *a, RAsmOp *op, char const *user_asm);
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -7,7 +7,6 @@ r_asm_sources = [
|
||||||
'aplugs.c',
|
'aplugs.c',
|
||||||
'binutils_as.c',
|
'binutils_as.c',
|
||||||
join_paths('p','asm_null.c'),
|
join_paths('p','asm_null.c'),
|
||||||
join_paths('p','asm_8051.c'),
|
|
||||||
# join_paths('p','asm_arc.c'),
|
# join_paths('p','asm_arc.c'),
|
||||||
join_paths('p','asm_arm_as.c'),
|
join_paths('p','asm_arm_as.c'),
|
||||||
join_paths('p','asm_arm_cs.c'),
|
join_paths('p','asm_arm_cs.c'),
|
||||||
|
@ -41,8 +40,6 @@ r_asm_sources = [
|
||||||
join_paths('p','asm_x86_nz.c'),
|
join_paths('p','asm_x86_nz.c'),
|
||||||
#join_paths('p','asm_x86_vm.c'),
|
#join_paths('p','asm_x86_vm.c'),
|
||||||
# join_paths('p','asm_z80.c'),
|
# join_paths('p','asm_z80.c'),
|
||||||
#join_paths('arch','8051','8051_disas.c'),
|
|
||||||
join_paths('arch','8051','8051_ass.c'),
|
|
||||||
join_paths('arch','ppc','libvle','vle.c'),
|
join_paths('arch','ppc','libvle','vle.c'),
|
||||||
join_paths('arch','ppc','libps','libps.c'),
|
join_paths('arch','ppc','libps','libps.c'),
|
||||||
#join_paths('arch','arc','gnu','arc-dis.c'),
|
#join_paths('arch','arc','gnu','arc-dis.c'),
|
||||||
|
@ -118,7 +115,6 @@ r_asm_inc = [
|
||||||
join_paths('arch','rsp'),
|
join_paths('arch','rsp'),
|
||||||
join_paths('arch','v850'),
|
join_paths('arch','v850'),
|
||||||
join_paths('arch','propeller'),
|
join_paths('arch','propeller'),
|
||||||
join_paths('arch','8051'),
|
|
||||||
join_paths('arch','v810'),
|
join_paths('arch','v810'),
|
||||||
join_paths('arch','or1k')
|
join_paths('arch','or1k')
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
OBJ_8051=asm_8051.o
|
|
||||||
OBJ_8051+=../arch/8051/8051_ass.o
|
|
||||||
CFLAGS+=-I./arch/8051/
|
|
||||||
|
|
||||||
STATIC_OBJ+=${OBJ_8051}
|
|
||||||
TARGET_8051=asm_8051.${EXT_SO}
|
|
||||||
|
|
||||||
ifeq ($(WITHPIC),1)
|
|
||||||
ALL_TARGETS+=${TARGET_8051}
|
|
||||||
|
|
||||||
${TARGET_8051}: ${OBJ_8051}
|
|
||||||
${CC} $(call libname,asm_8051) ${LDFLAGS} ${CFLAGS} \
|
|
||||||
-o ${TARGET_8051} ${OBJ_8051}
|
|
||||||
endif
|
|
|
@ -1,33 +0,0 @@
|
||||||
/* radare2 - LGPL - Copyright 2013-2019 - pancake, astuder */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <r_types.h>
|
|
||||||
#include <r_util.h>
|
|
||||||
#include <r_lib.h>
|
|
||||||
#include <r_asm.h>
|
|
||||||
|
|
||||||
#include <8051_ass.h>
|
|
||||||
|
|
||||||
RAsmPlugin r_asm_plugin_8051 = {
|
|
||||||
.name = "8051",
|
|
||||||
.arch = "8051",
|
|
||||||
.bits = 8,
|
|
||||||
.endian = R_SYS_ENDIAN_NONE,
|
|
||||||
.desc = "8051 Intel CPU",
|
|
||||||
// .disassemble = &disassemble,
|
|
||||||
.assemble = &assemble_8051,
|
|
||||||
.license = "PD",
|
|
||||||
.cpus =
|
|
||||||
"8051-generic," // First one is default
|
|
||||||
"8051-shared-code-xdata"
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifndef R2_PLUGIN_INCORE
|
|
||||||
R_API RLibStruct radare_plugin = {
|
|
||||||
.type = R_LIB_TYPE_ASM,
|
|
||||||
.data = &r_asm_plugin_8051,
|
|
||||||
.version = R2_VERSION
|
|
||||||
};
|
|
||||||
#endif
|
|
|
@ -186,7 +186,6 @@ R_API void r_asm_op_set_buf(RAsmOp *op, const ut8 *str, int len);
|
||||||
R_API ut8 *r_asm_op_get_buf(RAsmOp *op);
|
R_API ut8 *r_asm_op_get_buf(RAsmOp *op);
|
||||||
|
|
||||||
/* plugin pointers */
|
/* plugin pointers */
|
||||||
extern RAsmPlugin r_asm_plugin_8051;
|
|
||||||
extern RAsmPlugin r_asm_plugin_arc;
|
extern RAsmPlugin r_asm_plugin_arc;
|
||||||
extern RAsmPlugin r_asm_plugin_arm_as;
|
extern RAsmPlugin r_asm_plugin_arm_as;
|
||||||
extern RAsmPlugin r_asm_plugin_arm_cs;
|
extern RAsmPlugin r_asm_plugin_arm_cs;
|
||||||
|
|
|
@ -126,7 +126,6 @@ endif
|
||||||
if no_user_plugins
|
if no_user_plugins
|
||||||
|
|
||||||
asm_plugins += [
|
asm_plugins += [
|
||||||
'8051',
|
|
||||||
'arm_as',
|
'arm_as',
|
||||||
'arm_cs',
|
'arm_cs',
|
||||||
'arm_winedbg',
|
'arm_winedbg',
|
||||||
|
|
Loading…
Reference in New Issue