Fix asm/arch/cpu initialization issues

This commit is contained in:
pancake 2022-05-01 21:49:24 +02:00 committed by pancake
parent bb545503ba
commit b405e54f3f
11 changed files with 40 additions and 47 deletions

View File

@ -327,18 +327,6 @@ R_API bool r_anal_set_bits(RAnal *anal, int bits) {
return false;
}
// XXX this is only used to set the arch, not the cpu
// R2_570
#if 0
R_API void r_anal_set_cpu(RAnal *anal, const char *cpu) {
r_arch_use (anal->config, cpu); // XXX cpu is arch, so it needs to be
int v = r_anal_archinfo (anal, R_ANAL_ARCHINFO_ALIGN);
if (v != -1) {
anal->config->pcalign = v;
}
}
#endif
R_API void r_anal_set_big_endian(RAnal *anal, int bigend) {
r_return_if_fail (anal);
anal->config->big_endian = bigend;

View File

@ -1040,12 +1040,12 @@ static const char *map_dwarf_reg_to_ppc64_reg(ut64 reg_num, VariableLocationKind
TODO add more arches */
static const char *get_dwarf_reg_name(const char *arch, int reg_num, VariableLocationKind *kind, int bits) {
R_LOG_DEBUG ("get_dwarf_reg_name %s %d\n", arch, bits);
if (R_STR_ISEMPTY (arch) || !strcmp (arch, "x86")) {
if (arch && !strcmp (arch, "x86")) {
if (bits == 64) {
return map_dwarf_reg_to_x86_64_reg (reg_num, kind);
}
return map_dwarf_reg_to_x86_reg (reg_num, kind);
} else if (!strcmp (arch, "ppc")) {
} else if (arch && !strcmp (arch, "ppc")) {
if (bits == 64) {
return map_dwarf_reg_to_ppc64_reg (reg_num, kind);
}

View File

@ -377,7 +377,6 @@ R_API bool r_asm_use(RAsm *a, const char *name) {
a->cur = h;
#if 0
r_arch_use (a->config, h->arch);
#else
r_arch_use (a->config, h->name);
#endif
return true;
@ -402,7 +401,6 @@ R_API bool r_asm_use(RAsm *a, const char *name) {
} else {
if (!strcmp (name, h->name)) {
#if 0
// r_arch_use (a->config, h->arch);
r_arch_set_cpu (a->config, NULL);
#else
h->arch = name;

View File

@ -502,6 +502,9 @@ static bool cb_analcpu(void *user, void *data) {
r_arch_set_cpu (core->anal->config, node->value);
/* set pcalign */
int v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_ALIGN);
if (v != -1) {
core->anal->config->pcalign = v;
}
r_config_set_i (core->config, "asm.pcalign", (v != -1)? v: 0);
return true;
}

View File

@ -1392,9 +1392,7 @@ static int cmd_type(void *data, const char *input) {
// TODO #7967 help refactor: move to detail
r_core_cmd_help (core, help_msg_td);
r_cons_printf ("Note: The td command should be put between double quotes\n"
"Example: \"td struct foo {int bar;int cow;};\""
"\nt");
"Example: \"td struct foo {int bar;int cow;};\"\n");
} else if (input[1] == ' ') {
char *tmp = r_str_newf ("%s;", input + 2);
if (!tmp) {
@ -1408,11 +1406,11 @@ static int cmd_type(void *data, const char *input) {
free (out);
}
if (error_msg) {
eprintf ("%s", error_msg);
R_LOG_ERROR ("%s", error_msg);
free (error_msg);
}
} else {
eprintf ("Invalid use of td. See td? for help\n");
R_LOG_ERROR ("Invalid use of td. See td? for help\n");
}
break;
case 'x': {

View File

@ -1579,7 +1579,6 @@ R_API char *r_anal_get_reg_profile(RAnal *anal);
R_API ut64 r_anal_get_bbaddr(RAnal *anal, ut64 addr);
R_API bool r_anal_set_bits(RAnal *anal, int bits);
R_API bool r_anal_set_os(RAnal *anal, const char *os);
R_API void r_anal_set_cpu(RAnal *anal, const char *cpu);
R_API void r_anal_set_big_endian(RAnal *anal, int boolean);
R_API ut8 *r_anal_mask(RAnal *anal, int size, const ut8 *data, ut64 at);
R_API void r_anal_trace_bb(RAnal *anal, ut64 addr);

View File

@ -215,7 +215,6 @@ asm_plugins += [
'sh',
'snes',
'sparc_cs',
's390_cs',
'tms320',
'tms320c64x',
'tricore',
@ -244,7 +243,6 @@ if no_user_plugins
'mips_gnu',
'ppc_gnu',
'sparc_gnu',
's390_gnu',
'v850_gnu',
]
anal_plugins += [
@ -252,6 +250,7 @@ if no_user_plugins
'arm_gnu',
'mips_gnu',
'loongarch_gnu',
's390_gnu',
'ppc_gnu',
'sparc_gnu',
]

View File

@ -60,6 +60,12 @@ static char *predotname(const char *name) {
R_API bool r_parse_use(RParse *p, const char *name) {
r_return_val_if_fail (p && name, false);
// TODO: remove the alias workarounds because of missing pseudo plugins
// TODO: maybe we want to have a generic pseudo parser?
if (r_str_startswith (name, "s390.")) {
name = "x86.pseudo";
}
RListIter *iter;
RParsePlugin *h;
r_list_foreach (p->parsers, iter, h) {

View File

@ -135,7 +135,7 @@ EXPECT=<<EOF
{
"opcode": "la %r4, 8(%r15)",
"disasm": "la %r4, 8(%r15)",
"pseudo": "la %r4,8(%r15) ",
"pseudo": "la %r4, 8 (%r15) ",
"description": "Load Address",
"mnemonic": "la",
"mask": "ffffffff",

View File

@ -3546,6 +3546,8 @@ RUN
NAME=tiny1 aae non-start-bb first
FILE=bins/elf/analysis/tiny1
CMDS=<<EOF
e asm.arch=x86
e asm.bits=32
e io.cache=true
$orig_end=?e `omt va_end/cols~[0]:3`
omr 1 `omt size/cols~[0]:3`+2

View File

@ -299,26 +299,26 @@ pdr.
EOF
EXPECT=<<EOF
/ 30: fcn.00560e67 ();
| : 0x00560e67 56 push esi
| ,==< 0x00560e68 e904000000 jmp 0x560e71
| 0x00560e67 56 push esi
| ,=< 0x00560e68 e904000000 jmp 0x560e71
..
| |: ; CODE XREF from fcn.00560e67 @ 0x560e68(x)
| `--> 0x00560e71 90 nop
| : 0x00560e72 eb09 jmp 0x560e7d
| | ; CODE XREF from fcn.00560e67 @ 0x560e68(x)
| `-> 0x00560e71 90 nop
| 0x00560e72 eb09 jmp 0x560e7d
..
| : ; CODE XREF from fcn.00560e67 @ 0x560e72(x)
| : 0x00560e7d 5e pop esi
| : 0x00560e7e 50 push eax
| : 0x00560e7f 52 push edx
| ,==< 0x00560e80 e911000000 jmp 0x560e96
| ; CODE XREF from fcn.00560e67 @ 0x560e72(x)
| 0x00560e7d 5e pop esi
| 0x00560e7e 50 push eax
| 0x00560e7f 52 push edx
| ,=< 0x00560e80 e911000000 jmp 0x560e96
..
| ||: ; CODE XREF from fcn.00560e67 @ 0x560e80(x)
| |`--> 0x00560e96 0f31 rdtsc
| | : 0x00560e98 e914000000 jmp 0x560eb1
| || ; CODE XREF from fcn.00560e67 @ 0x560e80(x)
| |`-> 0x00560e96 0f31 rdtsc
| | 0x00560e98 e914000000 jmp 0x560eb1
..
| ||: ; CODE XREF from fcn.00560e67 @ 0x560e98(x)
| ||: 0x00560eb1 5a pop edx
\ ||`=< 0x00560eb2 e940c5edff jmp 0x43d3f7
| || ; CODE XREF from fcn.00560e67 @ 0x560e98(x)
| || 0x00560eb1 5a pop edx
\ || 0x00560eb2 e940c5edff jmp 0x43d3f7
/ 30: fcn.00560e67 ();
| 0x00560e67 56 push esi
@ -413,7 +413,7 @@ EXPECT=<<EOF
,=< 0x00005b02 7d0a jge 0x5b0e ; rip=0x5b0e -> 0x8d4890f4 ; likely
,==< 0x00005b04 7f08 jg 0x5b0e ; rip=0x5b0e -> 0x8d4890f4 ; likely
,===< 0x00005b06 eb00 jmp 0x5b08 ; rip=0x5b08 -> 0xc30a15ff
`---> 0x00005b08 ff150ac30100 call qword [reloc.__libc_start_main] ; [0x21e18:8]=0 ; rsp=0xfffffffffffffff8 ; rip=0x0
`---> 0x00005b08 ff150ac30100 call qword [reloc.__libc_start_main] ; [0x21e18:8]=0 ; rsp=0xfffffffffffffff8 -> 0x4c457fff ; rip=0x0
|| ; int __libc_start_main(func: unk_size_format, -1, char **: unk_size-1, func: unk_size_format, func: unk_size_format, func: unk_size_format, -1)
EOF
RUN
@ -504,11 +504,11 @@ EXPECT=<<EOF
| 0x080485a0 mov dword [esp], str.Wrong_
| 0x080485a7 call sym.imp.puts
| 0x080485ac mov eax, 1
,=.-> 0x080485b1 jmp 0x80485f9
|`--> 0x080485b3 add dword [esp + 0x20], 1
| : 0x080485b8 mov ebx, dword [esp + 0x20]
| `=< 0x080485bc jne 0x80485b1
| 0x080485be nop
|,=< 0x080485b1 jmp 0x80485f9
`--> 0x080485b3 add dword [esp + 0x20], 1
| 0x080485b8 mov ebx, dword [esp + 0x20]
| 0x080485bc jne 0x80485b1
| 0x080485be nop
EOF
RUN