* Add missing cc.c
This commit is contained in:
parent
af7cfafc0d
commit
2c3edbbbf5
3 changed files with 173 additions and 24 deletions
157
libr/anal/cc.c
Normal file
157
libr/anal/cc.c
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
/* radare - LGPL - Copyright 2011 -- pancake@nopcode.org */
|
||||
|
||||
// moved from core/cmd.c // the loop that does the funny trick ..
|
||||
|
||||
#include <r_anal.h>
|
||||
|
||||
R_API RAnalCC* r_anal_cc_new () {
|
||||
RAnalCC *cc = R_NEW (RAnalCC);
|
||||
//
|
||||
return cc;
|
||||
}
|
||||
|
||||
R_API RAnalCC* r_anal_cc_new_from_string (const char *str, int type) {
|
||||
// str = 0x804899 (123, 930, 0x804800)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
R_API char *r_anal_cc_to_string (RAnalCC* cc) {
|
||||
char str[1024];
|
||||
str[0] = 0;
|
||||
return strdup (str);
|
||||
}
|
||||
|
||||
R_API void r_anal_cc_free (RAnalCC* cc) {
|
||||
free (cc);
|
||||
}
|
||||
|
||||
R_API void r_anal_reset (RAnalCC *cc) {
|
||||
}
|
||||
|
||||
R_API boolt r_anal_cc_update (RAnal *anal, RAnalCC *cc, RAnalOp *op) {
|
||||
switch (op->type) {
|
||||
case R_ANAL_OP_TYPE_CALL:
|
||||
case R_ANAL_OP_TYPE_UCALL:
|
||||
cc->off = 0;
|
||||
// TODO: check if next instruction after call is restoring stack
|
||||
return R_FALSE;
|
||||
//case R_ANAL_OP_TYPE_MOV:
|
||||
case R_ANAL_OP_TYPE_PUSH:
|
||||
case R_ANAL_OP_TYPE_UPUSH:
|
||||
// add argument
|
||||
return R_TRUE;
|
||||
}
|
||||
// must update internal stuff to recognize parm
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
// Mixed up with XRefs
|
||||
R_API int r_anal_cc_register (RAnal *anal, RAnalCC *cc) {
|
||||
// register this calling convention to the destination call address
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
R_API int r_anal_cc_unregister (RAnal *anal, RAnalCC *cc) {
|
||||
// register this calling convention to the destination call address
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
#if 0
|
||||
////
|
||||
| - left-to-right, right-to-left
|
||||
| - stack aligned by caller or callee?
|
||||
| - list of regs used for args
|
||||
| - register args, stack args (int, ptr, fpu)
|
||||
\\\\
|
||||
|
||||
Calling conventions:
|
||||
====================
|
||||
x86: cdecl, fastcall, stdcall
|
||||
cdecl: push args in the stack (right-to-left order)
|
||||
- return value in eax
|
||||
|
||||
push eax
|
||||
push 123
|
||||
push byte[ebp+30]
|
||||
call eax
|
||||
add esp, 12
|
||||
|
||||
syscall: (args right to left)
|
||||
- eax, ecx, edx : not preserved, used as args
|
||||
- size of parameter list in dwords is passed in AL ??? (OS/2) ???
|
||||
|
||||
optlink:
|
||||
- first 3 parameters: eax, edx, ecx
|
||||
- up to 4 floating point args: ST(0)-ST(3)
|
||||
|
||||
pascal:
|
||||
like cdecl, but inverse order, the callee is responsible to clean the code
|
||||
push eax
|
||||
push 123
|
||||
push byte[ebp+30]
|
||||
call eax
|
||||
-- in eax: ... add esp, 12, ret
|
||||
|
||||
fastcall: (borland)
|
||||
|
||||
stdcall:
|
||||
like cdecl, but the callee is responsible to realign the stack
|
||||
- the one ised by microsoft and watcom
|
||||
- return value in EAX
|
||||
|
||||
fastcall:
|
||||
- not standarized.. see following
|
||||
|
||||
microsoft fastcall:
|
||||
- first two args in ECX, EDX, the rest in stack right-to-left
|
||||
|
||||
borland fastcall:
|
||||
- left-to-right
|
||||
- args: eax, edx, ecx, the rest in the stack (also left-to-right)
|
||||
|
||||
watcom fastcall:
|
||||
- eax, edx, ebx, ecx: left-to-right
|
||||
- in stack are right-to-left
|
||||
|
||||
topspeed/clarion:
|
||||
- eax, ebx, ecx, edx,
|
||||
- fpu: st0, st1, st2, st3, st4, st6
|
||||
- struct params are in the stack
|
||||
- return value:
|
||||
- integer: eax
|
||||
- pointer: edx
|
||||
- floatin: st0
|
||||
|
||||
Intel ABI
|
||||
- eax, edx, ecx: to not be preserved
|
||||
|
||||
x86-64:
|
||||
rcx, rdx, r8, r9: integer/pointer arguments
|
||||
additional args are pushed into stack
|
||||
xmm6, 8-15: floating point args (must preserve xmm6,xmm7)
|
||||
return value in rax
|
||||
|
||||
* System V AMD64 ABI convention (osx, linux, ...)
|
||||
- rdi, rsi, rdx, rcx, r8, r9: integer arguments
|
||||
- for syscalls, s/rcx/r10/
|
||||
- xmm0-xmm7 : floating point arguments
|
||||
- return value in RAX
|
||||
* Windows x64 calling conventions works in this way:
|
||||
- everything is pushed into the stack
|
||||
- return value in RAX
|
||||
|
||||
arm:
|
||||
r13 : stack pointer
|
||||
r0-r3 : arguments
|
||||
r4-r11 : local vars
|
||||
r0 : return value
|
||||
|
||||
mips:
|
||||
first 4 arguments as registers $a0-$a3
|
||||
next args in stack.
|
||||
return value in $v0 and $v1
|
||||
|
||||
sparc:
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
/* radare - LGPL - Copyright 2008-2010 pancake<nopcode.org> */
|
||||
/* radare - LGPL - Copyright 2008-2011 pancake<nopcode.org> */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "r_cmd.h"
|
||||
|
|
@ -12,7 +12,7 @@ int macro_counter = 0;
|
|||
static struct list_head macros;
|
||||
#endif
|
||||
|
||||
void r_cmd_macro_init(RCmdMacro *mac) {
|
||||
R_API void r_cmd_macro_init(RCmdMacro *mac) {
|
||||
mac->counter = 0;
|
||||
mac->_brk_value = 0;
|
||||
mac->brk_value = &mac->_brk_value;
|
||||
|
|
@ -25,7 +25,7 @@ void r_cmd_macro_init(RCmdMacro *mac) {
|
|||
|
||||
// XXX add support single line function definitions
|
||||
// XXX add support for single name multiple nargs macros
|
||||
int r_cmd_macro_add(RCmdMacro *mac, const char *oname) {
|
||||
R_API int r_cmd_macro_add(RCmdMacro *mac, const char *oname) {
|
||||
struct list_head *pos;
|
||||
struct r_cmd_macro_item_t *macro;
|
||||
char buf[1024];
|
||||
|
|
@ -36,8 +36,10 @@ int r_cmd_macro_add(RCmdMacro *mac, const char *oname) {
|
|||
int macro_update;
|
||||
char *name, *args = NULL;
|
||||
|
||||
if (oname[0]=='\0')
|
||||
return r_cmd_macro_list(mac);
|
||||
if (oname[0]=='\0') {
|
||||
r_cmd_macro_list(mac);
|
||||
return 0;
|
||||
}
|
||||
|
||||
name = alloca (strlen(oname)+1);
|
||||
strcpy (name, oname);
|
||||
|
|
@ -126,7 +128,7 @@ int r_cmd_macro_add(RCmdMacro *mac, const char *oname) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int r_cmd_macro_rm(struct r_cmd_macro_t *mac, const char *_name) {
|
||||
R_API int r_cmd_macro_rm(struct r_cmd_macro_t *mac, const char *_name) {
|
||||
char *name = alloca (strlen(_name));
|
||||
struct list_head *pos;
|
||||
char *ptr = strchr (name, ')');
|
||||
|
|
@ -139,14 +141,14 @@ int r_cmd_macro_rm(struct r_cmd_macro_t *mac, const char *_name) {
|
|||
list_del (&(mac->list));
|
||||
free (mac);
|
||||
eprintf ("Macro '%s' removed.\n", name);
|
||||
return 1;
|
||||
return R_TRUE;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
// TODO: use mac->printf which is r_cons_printf at the end
|
||||
int r_cmd_macro_list(RCmdMacro *mac) {
|
||||
R_API void r_cmd_macro_list(RCmdMacro *mac) {
|
||||
int j, idx = 0;
|
||||
struct list_head *pos;
|
||||
list_for_each_prev (pos, &mac->macros) {
|
||||
|
|
@ -160,7 +162,6 @@ int r_cmd_macro_list(RCmdMacro *mac) {
|
|||
/* mac->*/ printf (")\n");
|
||||
idx++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#if 0
|
||||
(define name value
|
||||
|
|
@ -176,7 +177,7 @@ int r_cmd_macro_list(RCmdMacro *mac) {
|
|||
.(define patata 3)
|
||||
#endif
|
||||
|
||||
int r_cmd_macro_cmd_args(RCmdMacro *mac, const char *ptr, const char *args, int nargs) {
|
||||
R_API int r_cmd_macro_cmd_args(RCmdMacro *mac, const char *ptr, const char *args, int nargs) {
|
||||
int i,j;
|
||||
char *cmd = alloca(strlen(ptr)+1024);
|
||||
char *arg = args?strdup(args):strdup("");
|
||||
|
|
@ -213,7 +214,7 @@ int r_cmd_macro_cmd_args(RCmdMacro *mac, const char *ptr, const char *args, int
|
|||
return (*cmd==')')?0:mac->cmd(mac->user, cmd);
|
||||
}
|
||||
|
||||
char *r_cmd_macro_label_process(RCmdMacro *mac, RCmdMacroLabel *labels, int *labels_n, char *ptr) {
|
||||
R_API char *r_cmd_macro_label_process(RCmdMacro *mac, RCmdMacroLabel *labels, int *labels_n, char *ptr) {
|
||||
int i;
|
||||
for (;ptr[0]==' ';ptr=ptr+1);
|
||||
if (ptr[strlen(ptr)-1]==':') {
|
||||
|
|
@ -278,7 +279,7 @@ char *r_cmd_macro_label_process(RCmdMacro *mac, RCmdMacroLabel *labels, int *lab
|
|||
}
|
||||
|
||||
/* TODO: add support for spaced arguments */
|
||||
int r_cmd_macro_call(RCmdMacro *mac, const char *name) {
|
||||
R_API int r_cmd_macro_call(RCmdMacro *mac, const char *name) {
|
||||
char *args;
|
||||
int nargs = 0;
|
||||
char *str, *ptr, *ptr2;
|
||||
|
|
@ -366,7 +367,7 @@ int r_cmd_macro_call(RCmdMacro *mac, const char *name) {
|
|||
return R_TRUE;
|
||||
}
|
||||
|
||||
int r_cmd_macro_break(RCmdMacro *mac, const char *value) {
|
||||
R_API int r_cmd_macro_break(RCmdMacro *mac, const char *value) {
|
||||
mac->brk = 1;
|
||||
mac->brk_value= NULL;
|
||||
mac->_brk_value = (ut64)r_num_math (mac->num, value);
|
||||
|
|
|
|||
|
|
@ -70,14 +70,6 @@ typedef struct r_cmd_plugin_t {
|
|||
} RCmdPlugin;
|
||||
|
||||
#ifdef R_API
|
||||
|
||||
R_API void r_cmd_macro_init(struct r_cmd_macro_t *mac);
|
||||
R_API int r_cmd_macro_add(struct r_cmd_macro_t *mac, const char *name);
|
||||
R_API int r_cmd_macro_rm(struct r_cmd_macro_t *mac, const char *_name);
|
||||
R_API int r_cmd_macro_list(struct r_cmd_macro_t *mac);
|
||||
R_API int r_cmd_macro_call(struct r_cmd_macro_t *mac, const char *name);
|
||||
R_API int r_cmd_macro_break(struct r_cmd_macro_t *mac, const char *value);
|
||||
|
||||
R_API RCmd *r_cmd_new();
|
||||
R_API RCmd *r_cmd_free(RCmd *cmd);
|
||||
R_API int r_cmd_set_data(struct r_cmd_t *cmd, void *data);
|
||||
|
|
@ -99,9 +91,8 @@ extern struct r_cmd_plugin_t r_cmd_plugin_dummy;
|
|||
R_API void r_cmd_macro_init(struct r_cmd_macro_t *mac);
|
||||
R_API int r_cmd_macro_add(struct r_cmd_macro_t *mac, const char *name);
|
||||
R_API int r_cmd_macro_rm(struct r_cmd_macro_t *mac, const char *_name);
|
||||
R_API int r_cmd_macro_list(struct r_cmd_macro_t *mac);
|
||||
R_API void r_cmd_macro_list(struct r_cmd_macro_t *mac);
|
||||
R_API int r_cmd_macro_call(struct r_cmd_macro_t *mac, const char *name);
|
||||
R_API int r_cmd_macro_break(struct r_cmd_macro_t *mac, const char *value);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in a new issue