mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-27 07:00:30 +00:00
Include callconv information in pdc output ##decompiler
* Make afc/afci work without depending on function
This commit is contained in:
parent
2e1e27f485
commit
f5578dacdd
@ -620,7 +620,7 @@ static RCoreHelpMessage help_msg_afb = {
|
||||
static RCoreHelpMessage help_msg_afc = {
|
||||
"Usage:", "afc[agl?]", "# see also tcc command to manage all calling conventions",
|
||||
"afc", " ccname", "manually set calling convention for current function",
|
||||
"afc", "", "show calling convention for the Current function (same as tcc)",
|
||||
"afc", "", "show default function calling convention (same as tcc)",
|
||||
"afcr", "[j]", "show register usage for the current function",
|
||||
"afcf", "[j] [name]", "prints return type function(arg1, arg2...), see afij",
|
||||
"afci", "", "information about the current calling convention",
|
||||
@ -5707,6 +5707,15 @@ static int cmd_af(RCore *core, const char *input) {
|
||||
if (!input[2] || input[2] == ' ' || input[2] == 'i' || input[2] == 'r' || input[2] == 'a') {
|
||||
fcn = r_anal_get_fcn_in (core->anal, core->offset, 0);
|
||||
if (!fcn) {
|
||||
if (!input[2]) {
|
||||
r_cons_println (r_config_get (core->config, "anal.cc"));
|
||||
break;
|
||||
}
|
||||
if (input[2] == 'i') {
|
||||
r_core_cmdf (core, "afcl %s",
|
||||
r_config_get (core->config, "anal.cc"));
|
||||
break;
|
||||
}
|
||||
R_LOG_ERROR ("afc: Cannot find function here");
|
||||
break;
|
||||
}
|
||||
|
@ -381,17 +381,30 @@ R_API int r_core_pseudo_code(RCore *core, const char *input) {
|
||||
n_bb, (int)r_anal_function_realsize (fcn));
|
||||
NEWLINE (fcn->addr, indent);
|
||||
const char *S0 = "esp";
|
||||
PRINTF ("static inline void push (int reg) {%s -= %d; stack[%s] = reg; }\n", S0, (int)sizeof (int), S0);
|
||||
PRINTF ("static inline void push(int reg) {%s -= %d; stack[%s] = reg; }\n", S0, (int)sizeof (int), S0);
|
||||
PRINTF ("static inline int pop() {int r = stack[%s]; %s += %d; return r; }\n", S0, S0, (int)sizeof (int));
|
||||
PRINTF ("\n");
|
||||
}
|
||||
|
||||
char *fs = r_core_cmd_strf (core, "afs@0x%08"PFMT64x, fcn->addr);
|
||||
{
|
||||
char *cc = r_core_cmd_strf (core, "afci@0x%08"PFMT64x, fcn->addr);
|
||||
r_str_trim (cc);
|
||||
if (R_STR_ISNOTEMPTY (cc)) {
|
||||
PRINTF ("// callconv: %s\n", cc);
|
||||
}
|
||||
free (cc);
|
||||
}
|
||||
if (R_STR_ISEMPTY (fs) || (r_str_startswith (fs, "void") && strstr (fs, "()"))) {
|
||||
PRINTF ("int %s (int %s, int %s) {", fcn->name, a0, a1);
|
||||
if (!strcmp (a0, a1)) {
|
||||
PRINTF ("int %s (int %s) {", fcn->name, a0);
|
||||
} else {
|
||||
PRINTF ("int %s (int %s, int %s) {", fcn->name, a0, a1);
|
||||
}
|
||||
} else {
|
||||
r_str_replace_char (fs, ';', '{');
|
||||
PRINTF ("%s", fs);
|
||||
r_str_replace_char (fs, ';', ' ');
|
||||
r_str_trim (fs);
|
||||
PRINTF ("%s {", fs);
|
||||
}
|
||||
free (fs);
|
||||
indent++;
|
||||
|
@ -100,7 +100,8 @@ EXPECT=<<EOF
|
||||
| 0x0040206e ff15b8304000 call dword [MessageBoxA] ; 0x4030b8 ; int MessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType)
|
||||
| 0x00402074 6a00 push 0
|
||||
\ 0x00402076 ff1584304000 call dword [ExitProcess] ; 0x403084 ; VOID ExitProcess(UINT uExitCode)
|
||||
int entry0 (int stack, int stack) {
|
||||
// callconv: eax cdecl (stack);
|
||||
int entry0 (int stack) {
|
||||
loc_0x0040200f:
|
||||
si = 3
|
||||
fcn.00402000 ()
|
||||
@ -150,7 +151,8 @@ af
|
||||
pdc
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
int sym.func.100003a54 (int x0, int x1) {
|
||||
// callconv: x0 arm64 (x0, x1, x2, x3, x4, x5, x6, x7, stack);
|
||||
void sym.func.100003a54 (int64_t arg1, int64_t arg2) {
|
||||
loc_0x100003a54:
|
||||
x8 = [x0 + 0x60] // arg1
|
||||
x8 = [x8 + 0x60]
|
||||
|
Loading…
Reference in New Issue
Block a user