Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove hidden static variables & globals #4073

Merged
merged 12 commits into from
Jan 6, 2024
2 changes: 2 additions & 0 deletions librz/analysis/analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ RZ_API RzAnalysis *rz_analysis_new(void) {
analysis->il_vm = NULL;
analysis->hash = rz_hash_new();
analysis->debug_info = rz_analysis_debug_info_new();
analysis->cmpval = UT64_MAX;
analysis->lea_jmptbl_ip = UT64_MAX;
return analysis;
}

Expand Down
33 changes: 15 additions & 18 deletions librz/analysis/cc.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ RZ_API void rz_analysis_cc_del(RzAnalysis *analysis, const char *name) {
rz_return_if_fail(analysis && name);
sdb_unset(DB, name, 0);
cc_sdb_unsetf(DB, "cc.%s.ret", name);
cc_sdb_unsetf(DB, "cc.%s.maxargs", name);
cc_sdb_unsetf(DB, "cc.%s.argn", name);
for (int i = 0; i < RZ_ANALYSIS_CC_MAXARG; i++) {
cc_sdb_unsetf(DB, "cc.%s.arg%d", name, i);
Expand Down Expand Up @@ -77,6 +78,11 @@ RZ_API bool rz_analysis_cc_set(RzAnalysis *analysis, const char *expr) {
n++;
}
}
if (n > rz_analysis_cc_max_arg(analysis, ccname)) {
char maxargs[256];
rz_strf(maxargs, "%d", n);
cc_sdb_setf(DB, maxargs, "cc.%s.maxargs", ccname);
}
rz_list_free(ccArgs);
free(e);
free(args);
Expand Down Expand Up @@ -197,27 +203,18 @@ RZ_API void rz_analysis_cc_set_error(RzAnalysis *analysis, const char *conventio
}

RZ_API int rz_analysis_cc_max_arg(RzAnalysis *analysis, const char *cc) {
int i = 0;
rz_return_val_if_fail(analysis && DB && cc, 0);
static void *oldDB = NULL;
static char *oldCC = NULL;
static int oldArg = 0;
if (oldDB == DB && !strcmp(cc, oldCC)) {
return oldArg;
char *query = rz_str_newf("cc.%s.maxargs", cc);
if (!query) {
return 0;
}
oldDB = DB;
free(oldCC);
oldCC = strdup(cc);
for (i = 0; i < RZ_ANALYSIS_CC_MAXARG; i++) {
char *query = rz_str_newf("cc.%s.arg%d", cc, i);
const char *res = query ? sdb_const_get(DB, query, 0) : NULL;
free(query);
if (!res) {
break;
}
const char *res = sdb_const_get(DB, query, 0);
free(query);
int maxargs = res ? atoi(res) : 0;
if (maxargs < 0 || maxargs > RZ_ANALYSIS_CC_MAXARG) {
return 0;
}
oldArg = i;
return i;
return maxargs;
}

RZ_API const char *rz_analysis_cc_ret(RzAnalysis *analysis, const char *convention) {
Expand Down
2 changes: 2 additions & 0 deletions librz/analysis/d/cc-arm-16.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ cc.arm16.arg1=r1
cc.arm16.arg2=r2
cc.arm16.arg3=r3
cc.arm16.argn=stack
cc.arm16.maxargs=4
cc.arm16.ret=r0

arm32=cc
cc.arm32.arg0=r0
cc.arm32.arg1=r1
cc.arm32.arg2=r2
cc.arm32.argn=stack
cc.arm16.maxargs=3
cc.arm32.ret=r0
3 changes: 3 additions & 0 deletions librz/analysis/d/cc-arm-32.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ default.cc=arm32
arm32=cc
cc.arm32.arg0=r0
cc.arm32.arg1=r1
cc.arm32.maxargs=2
cc.arm32.ret=r0

arm16=cc
Expand All @@ -11,6 +12,7 @@ cc.arm16.arg1=r1
cc.arm16.arg2=r2
cc.arm16.arg3=r3
cc.arm16.argn=stack
cc.arm16.maxargs=4
cc.arm16.ret=r0

swift=cc
Expand All @@ -19,6 +21,7 @@ cc.swift.arg1=r1
cc.swift.arg2=r2
cc.swift.arg3=r3
cc.swift.argn=stack
cc.swift.maxargs=4
cc.swift.self=r10
cc.swift.self=r8
cc.swift.ret=r0
2 changes: 2 additions & 0 deletions librz/analysis/d/cc-arm-64.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ cc.arm64.arg5=x5
cc.arm64.arg6=x6
cc.arm64.arg7=x7
cc.arm64.argn=stack
cc.arm64.maxargs=8
cc.arm64.ret=x0

swift=cc
Expand All @@ -22,6 +23,7 @@ cc.swift.arg5=x5
cc.swift.arg6=x6
cc.swift.arg7=x7
cc.swift.argn=stack
cc.swift.maxargs=8
cc.swift.self=x20
cc.swift.error=x21
cc.swift.ret=x0
1 change: 1 addition & 0 deletions librz/analysis/d/cc-avr-8.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ cc.avr.arg4=r22
cc.avr.arg5=r21
cc.avr.arg6=r18
cc.avr.argn=stack
cc.avr.maxargs=7
cc.avr.ret=r24
2 changes: 2 additions & 0 deletions librz/analysis/d/cc-hexagon-32.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cc.hexagon.arg3=r3
cc.hexagon.arg4=r4
cc.hexagon.arg5=r5
cc.hexagon.argn=stack_rev
cc.hexagon.maxargs=6
cc.hexagon.ret=r0

hvx=cc
Expand All @@ -28,4 +29,5 @@ cc.hvx.arg12=v12
cc.hvx.arg13=v13
cc.hvx.arg14=v14
cc.hvx.arg15=v15
cc.hvx.maxargs=16
cc.hvx.ret=v0
1 change: 1 addition & 0 deletions librz/analysis/d/cc-m68k-32.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ default.cc=m68k

m68k=cc
cc.m68k.arg0=stack_rev
cc.m68k.maxargs=1
cc.m68k.ret=d0
2 changes: 2 additions & 0 deletions librz/analysis/d/cc-mips-32.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cc.o32.arg1=a1
cc.o32.arg2=a2
cc.o32.arg3=a3
cc.o32.argn=stack
cc.o32.maxargs=4
cc.o32.ret=v0

n32=cc
Expand All @@ -18,5 +19,6 @@ cc.n32.arg5=a5
cc.n32.arg6=a6
cc.n32.arg7=a7
cc.n32.argn=stack
cc.n32.maxargs=8
cc.n32.ret=v0

2 changes: 2 additions & 0 deletions librz/analysis/d/cc-mips-64.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cc.o32.arg1=a1
cc.o32.arg2=a2
cc.o32.arg3=a3
cc.o32.argn=stack
cc.o32.maxargs=4
cc.o32.ret=v0

n32=cc
Expand All @@ -18,5 +19,6 @@ cc.n32.arg5=a5
cc.n32.arg6=a6
cc.n32.arg7=a7
cc.n32.argn=stack
cc.n32.maxargs=8
cc.n32.ret=v0

1 change: 1 addition & 0 deletions librz/analysis/d/cc-ppc-32.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ cc.ppc-32.arg5=r8
cc.ppc-32.arg6=r9
cc.ppc-32.arg7=r10
cc.ppc-32.argn=stack_rev
cc.ppc-32.maxargs=8
cc.ppc-32.ret=r3

1 change: 1 addition & 0 deletions librz/analysis/d/cc-ppc-64.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ cc.ppc-64.arg5=r8
cc.ppc-64.arg6=r9
cc.ppc-64.arg7=r10
cc.ppc-64.argn=stack_rev
cc.ppc-64.maxargs=8
cc.ppc-64.ret=r3

1 change: 1 addition & 0 deletions librz/analysis/d/cc-riscv-64.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ cc.rvg.arg4=a4
cc.rvg.arg5=a5
cc.rvg.arg6=a6
cc.rvg.arg7=a7
cc.rvg.maxargs=8
cc.rvg.ret=a0
1 change: 1 addition & 0 deletions librz/analysis/d/cc-sh-32.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ cc.sh4.arg0=r4
cc.sh4.arg1=r5
cc.sh4.arg2=r6
cc.sh4.arg3=r7
cc.sh4.maxargs=4
cc.sh4.ret=r0
1 change: 1 addition & 0 deletions librz/analysis/d/cc-sparc-32.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ cc.sparc.arg3=i3
cc.sparc.arg4=i4
cc.sparc.arg5=i5
cc.sparc.argn=stack
cc.sparc.maxargs=6
cc.sparc.ret=o0
1 change: 1 addition & 0 deletions librz/analysis/d/cc-spc700-16.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ spc700=cc
cc.spc700.arg0=a
cc.spc700.arg1=x
cc.spc700.arg2=y
cc.spc700.maxargs=3
cc.spc700.ret=a
1 change: 1 addition & 0 deletions librz/analysis/d/cc-sysz-64.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ cc.sysz.arg1=r3
cc.sysz.arg2=r4
cc.sysz.arg3=r5
cc.sysz.arg4=r6
cc.sysz.maxargs=5
cc.sysz.ret=r2
2 changes: 2 additions & 0 deletions librz/analysis/d/cc-tricore-32.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ cc.reg.arg5=a5
cc.reg.arg6=a6
cc.reg.arg7=a7
cc.reg.argn=stack
cc.reg.maxargs=8
cc.reg.ret=d2

stack=cc
cc.stack.argn=stack
cc.stack.maxargs=0
cc.stack.ret=d2
5 changes: 5 additions & 0 deletions librz/analysis/d/cc-x86-16.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cc.fastcall.arg1=dx
cc.fastcall.arg2=bx
cc.fastcall.arg3=cx
cc.fastcall.argn=stack
cc.fastcall.maxargs=4
cc.fastcall.ret=ax

watcom=cc
Expand All @@ -14,24 +15,28 @@ cc.watcom.arg1=dx
cc.watcom.arg2=bx
cc.watcom.arg3=cx
cc.watcom.argn=stack
cc.watcom.maxargs=4
cc.watcom.ret=si

turboc=cc
cc.turboc.arg0=ax
cc.turboc.arg1=dx
cc.turboc.arg2=bx
cc.turboc.argn=stack
cc.turboc.maxargs=3
cc.turboc.ret=ax

ms=cc
cc.ms.arg0=ax
cc.ms.arg1=dx
cc.ms.argn=stack
cc.ms.maxargs=2
cc.ms.ret=ax

msm=cc
cc.msm.arg0=ax
cc.msm.arg1=dx
cc.msm.arg2=bx
cc.msm.argn=stack
cc.msm.maxargs=3
cc.msm.ret=bx
8 changes: 8 additions & 0 deletions librz/analysis/d/cc-x86-32.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,40 @@ default.cc=cdecl

cdecl=cc
cc.cdecl.argn=stack
cc.cdecl.maxargs=0
cc.cdecl.ret=eax

cdecl-thiscall-ms=cc
cc.cdecl-thiscall-ms.arg0=ecx
cc.cdecl-fastcall-ms.argn=stack
cc.cdecl-fastcall-ms.maxargs=1
cc.cdecl-fastcall-ms.ret=eax

optlink=cc
cc.optlink.arg0=eax
cc.optlink.arg1=edx
cc.optlink.arg2=ecx
cc.optlink.argn=stack
cc.optlink.maxargs=3
cc.optlink.ret=eax

stdcall=cc
cc.stdcall.argn=stack
cc.stdcall.maxargs=0
cc.stdcall.ret=eax

fastcall=cc
cc.fastcall.arg0=ecx
cc.fastcall.arg1=edx
cc.fastcall.argn=stack
cc.fastcall.maxargs=2
cc.fastcall.ret=eax

borland=cc
cc.borland.arg0=eax
cc.borland.arg1=edx
cc.borland.arg2=ecx
cc.borland.maxargs=3
cc.borland.argn=stack_rev

watcom=cc
Expand All @@ -38,6 +44,8 @@ cc.watcom.arg1=edx
cc.watcom.arg2=ebx
cc.watcom.arg3=ecx
cc.watcom.argn=stack
cc.watcom.maxargs=4

pascal=cc
cc.pascal.argn=stack_rev
cc.pascal.maxargs=0
4 changes: 4 additions & 0 deletions librz/analysis/d/cc-x86-64.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cc.ms.arg1=rdx
cc.ms.arg2=r8
cc.ms.arg3=r9
cc.ms.argn=stack
cc.ms.maxargs=4
cc.ms.ret=rax

amd64=cc
Expand All @@ -20,6 +21,7 @@ cc.amd64.arg7=xmm1
cc.amd64.arg8=xmm2
cc.amd64.arg9=xmm3
cc.amd64.arg10=xmm4
cc.amd64.maxargs=11
cc.amd64.ret=rax

swift=cc
Expand All @@ -34,6 +36,7 @@ cc.swift.arg7=xmm1
cc.swift.arg8=xmm2
cc.swift.arg9=xmm3
cc.swift.arg10=xmm4
cc.swift.maxargs=11
cc.swift.self=r13
cc.swift.error=r12
cc.swift.ret=rax
Expand All @@ -45,4 +48,5 @@ cc.amd64syscall.arg2=rdx
cc.amd64syscall.arg3=r10
cc.amd64syscall.arg4=r8
cc.amd64syscall.arg5=r9
cc.amd64syscall.maxargs=6
cc.amd64syscall.ret=rax
1 change: 1 addition & 0 deletions librz/analysis/d/cc-xtensa-32.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ cc.call0.arg3=a5
cc.call0.arg4=a6
cc.call0.arg5=a7
cc.call0.argn=stack
cc.call0.maxargs=6
cc.call0.ret=a2
17 changes: 7 additions & 10 deletions librz/analysis/esil/esil.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ RZ_API RzAnalysisEsil *rz_analysis_esil_new(int stacksize, int iotrap, unsigned
esil->parse_goto_count = RZ_ANALYSIS_ESIL_GOTO_LIMIT;
esil->ops = ht_pp_new(NULL, esil_ops_free, NULL);
esil->iotrap = iotrap;
esil->in_cmd_step = false;
rz_analysis_esil_sources_init(esil);
rz_analysis_esil_interrupts_init(esil);
esil->addrmask = genmask(addrsize - 1);
Expand Down Expand Up @@ -2953,17 +2954,13 @@ static int evalWord(RzAnalysisEsil *esil, const char *ostr, const char **str) {
}

static bool __stepOut(RzAnalysisEsil *esil, const char *cmd) {
static bool inCmdStep = false;
if (cmd && esil && esil->cmd && !inCmdStep) {
inCmdStep = true;
if (esil->cmd(esil, cmd, esil->address, 0)) {
inCmdStep = false;
// if returns 1 we skip the impl
return true;
}
inCmdStep = false;
bool ret = false;
if (cmd && esil && esil->cmd && !esil->in_cmd_step) {
esil->in_cmd_step = true;
ret = esil->cmd(esil, cmd, esil->address, 0);
esil->in_cmd_step = false;
}
return false;
return ret;
}

RZ_API bool rz_analysis_esil_parse(RzAnalysisEsil *esil, const char *str) {
Expand Down
Loading
Loading