rizinorg / rizin

UNIX-like reverse engineering framework and command-line toolset.
https://rizin.re
GNU Lesser General Public License v3.0
2.59k stars 346 forks source link

Remove static variables from RzAnalysis plugins #3721

Closed XVilka closed 5 months ago

XVilka commented 1 year ago
$ rg --pcre2 "\tstatic (?\!const)" librz/analysis/p/
librz/analysis/p/analysis_sparc_cs.c
74: static RzRegItem reg;
100:    static csh handle = 0;
101:    static int omode;

librz/analysis/p/analysis_pic.c
32: static void _inst__##OPCODE_NAME(RzAnalysis *analysis, RzAnalysisOp *op, \
663:    static bool init_done = false;

librz/analysis/p/analysis_xtensa.c
16: static int length_table[16] = { 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 8, 8 };
1969:   static xtensa_insnbuf insn_buffer = NULL;
1970:   static xtensa_insnbuf slot_buffer = NULL;

librz/analysis/p/analysis_ppc_cs.c
43: static char cmask[32];
57: static char cmask[32];
73: static char words[8][64];
141:    static char cspr[16];
925:    static csh handle = 0;
926:    static int omode = -1, obits = -1;

librz/analysis/p/analysis_x86_cs.c
230:    static char buf[AR_DIM][BUF_SZ];

librz/analysis/p/analysis_m680x_cs.c
50: static csh handle = 0;
51: static int omode = -1;
52: static int obits = 32;

librz/analysis/p/analysis_m68k_cs.c
131:    static RzRegItem reg;
164:    static csh handle = 0;
165:    static int omode = -1;
166:    static int obits = 32;

librz/analysis/p/analysis_xcore_cs.c
54: static csh handle = 0;
55: static int omode = 0;

librz/analysis/p/analysis_mips_cs.c
619:    static RzRegItem reg;

librz/analysis/p/analysis_tms320c64x.c
63: static csh handle = 0;
64: static int omode;

librz/analysis/p/analysis_riscv_cs.c
221:    static RzRegItem reg;
320:    static csh hndl = 0;
321:    static int omode = -1;
322:    static int obits = 32;

See https://github.com/rizinorg/rizin/commit/2c9a7008e9e30a10ff42c0422b1ef7d6579b8dab as an example how to handle this.

khardikk commented 1 year ago

Hey @XVilka I would like to work on this issue! it will be my first time contributing

XVilka commented 1 year ago

Sure, @hady68, go ahead.

khardikk commented 1 year ago

Sure, @hady68, go ahead.

Can you please list down the steps that are needed to solve this one?

XVilka commented 1 year ago

See the commit mentioned in the issue, just do similarly.

khardikk commented 1 year ago

See the commit mentioned in the issue, just do similarly.

Sure okay, can you please assign this to me

XVilka commented 1 year ago

See the commit mentioned in the issue, just do similarly.

Sure okay, can you please assign this to me

GitHub doesn't allow assigning people who aren't part of the organization. Just send a PR and link to this issue, that should be enough. Don't forget to check https://github.com/rizinorg/rizin/blob/dev/CONTRIBUTING.md and https://github.com/rizinorg/rizin/blob/dev/DEVELOPERS.md

khardikk commented 1 year ago

See the commit mentioned in the issue, just do similarly.

Sure okay, can you please assign this to me

GitHub doesn't allow assigning people who aren't part of the organization. Just send a PR and link to this issue, that should be enough. Don't forget to check https://github.com/rizinorg/rizin/blob/dev/CONTRIBUTING.md and https://github.com/rizinorg/rizin/blob/dev/DEVELOPERS.md

Got it thanks will do so

XVilka commented 1 year ago

@hady68 sorry, there is actually a better example - see how the state is saved into the context in librz/analysis/p/analysis_asm_cs.c

khardikk commented 1 year ago

Hi @XVilka, I have worked on one of the files, and wanted to cross-check if this is what you're looking for, then I can go forward for other files as well, attaching the link to a PR in my forked repo, please have a look and let me know.
https://github.com/hady68/rizin/pull/1

XVilka commented 1 year ago

@hady68 no, you need to introduce a context structure since the omode of that code is cached between different disassemble() function calls.

khardikk commented 1 year ago

of that code is cached between different disassemble() function calls.

Added the above here -> https://github.com/hady68/rizin/pull/1/commits/af37dc33a3ecc9772274d805fea6d9ba796b17e5 please check

XVilka commented 1 year ago

@hady68 yes, the crux of it is right. Please fix the indentation though (use sys/clang-format.py)

khardikk commented 1 year ago

@hady68 yes, the crux of it is right. Please fix the indentation though (use sys/clang-format.py)

Alright will fix it, working on the other files now

HN026 commented 7 months ago

Removed static Variables from RzAsm #4100

XVilka commented 6 months ago

@imbillow could you please remove the one static var left in RzAsm tricore plugin?