From 64f8a5ae57796a16fd9a6515ff10e8884cfdaf5d Mon Sep 17 00:00:00 2001 From: Giovanni <561184+wargio@users.noreply.github.com> Date: Thu, 7 Mar 2024 23:50:22 +0800 Subject: [PATCH] Move parse into arch. (#4342) --- binrz/rizin/meson.build | 1 - librz/arch/arch.c | 7 + librz/arch/deprecated_arch_helper.h | 15 +- librz/{parse => arch}/filter.c | 6 +- librz/arch/meson.build | 5 +- librz/arch/p/arch_6502.c | 3 +- librz/arch/p/arch_arm_cs.c | 3 +- librz/arch/p/arch_avr.c | 3 +- librz/arch/p/arch_chip8.c | 3 +- librz/arch/p/arch_dalvik.c | 3 +- librz/arch/p/arch_m68k_cs.c | 3 +- librz/arch/p/arch_mips_cs.c | 3 +- librz/arch/p/arch_ppc_cs.c | 3 +- librz/arch/p/arch_sh.c | 3 +- librz/arch/p/arch_tms320.c | 3 +- librz/arch/p/arch_v850.c | 3 +- librz/arch/p/arch_wasm.c | 3 +- librz/arch/p/arch_x86_cs.c | 3 +- .../p => arch/p/parse}/parse_6502_pseudo.c | 10 +- .../p => arch/p/parse}/parse_arm_pseudo.c | 12 +- .../p => arch/p/parse}/parse_avr_pseudo.c | 10 +- .../p => arch/p/parse}/parse_chip8_pseudo.c | 8 - .../p => arch/p/parse}/parse_dalvik_pseudo.c | 10 +- .../p => arch/p/parse}/parse_m68k_pseudo.c | 12 +- .../p => arch/p/parse}/parse_mips_pseudo.c | 14 +- .../p => arch/p/parse}/parse_ppc_pseudo.c | 26 +-- .../p => arch/p/parse}/parse_sh_pseudo.c | 10 +- .../p => arch/p/parse}/parse_tms320_pseudo.c | 10 +- .../p => arch/p/parse}/parse_v850_pseudo.c | 10 +- .../p => arch/p/parse}/parse_wasm_pseudo.c | 8 - .../p => arch/p/parse}/parse_x86_pseudo.c | 10 +- librz/arch/p_gnu/arch_riscv.c | 3 +- librz/arch/p_gnu/arch_z80.c | 4 +- .../p_gnu/parse/parse_riscv_gnu.c} | 10 +- .../p_gnu/parse/parse_z80_gnu.c} | 12 +- librz/{parse => arch}/parse.c | 18 +- .../p/parse_common.c => arch/parse_helper.c} | 81 +------- librz/arch/parse_helper.h | 84 ++++++++ librz/core/libs.c | 11 +- librz/core/meson.build | 2 - librz/include/rz_arch.h | 3 + librz/include/rz_parse.h | 2 - librz/main/meson.build | 1 - librz/main/rizin.c | 1 - librz/meson.build | 1 - librz/parse/README.md | 0 librz/parse/meson.build | 81 -------- librz/parse/p/parse_att2intel.c | 189 ------------------ meson.build | 1 - test/db/cmd/cmd_list | 3 +- test/integration/meson.build | 1 - test/unit/meson.build | 1 - 52 files changed, 186 insertions(+), 546 deletions(-) rename librz/{parse => arch}/filter.c (99%) rename librz/{parse/p => arch/p/parse}/parse_6502_pseudo.c (95%) rename librz/{parse/p => arch/p/parse}/parse_arm_pseudo.c (98%) rename librz/{parse/p => arch/p/parse}/parse_avr_pseudo.c (96%) rename librz/{parse/p => arch/p/parse}/parse_chip8_pseudo.c (95%) rename librz/{parse/p => arch/p/parse}/parse_dalvik_pseudo.c (98%) rename librz/{parse/p => arch/p/parse}/parse_m68k_pseudo.c (93%) rename librz/{parse/p => arch/p/parse}/parse_mips_pseudo.c (97%) rename librz/{parse/p => arch/p/parse}/parse_ppc_pseudo.c (99%) rename librz/{parse/p => arch/p/parse}/parse_sh_pseudo.c (97%) rename librz/{parse/p => arch/p/parse}/parse_tms320_pseudo.c (96%) rename librz/{parse/p => arch/p/parse}/parse_v850_pseudo.c (96%) rename librz/{parse/p => arch/p/parse}/parse_wasm_pseudo.c (86%) rename librz/{parse/p => arch/p/parse}/parse_x86_pseudo.c (98%) rename librz/{parse/p/parse_riscv_pseudo.c => arch/p_gnu/parse/parse_riscv_gnu.c} (96%) rename librz/{parse/p/parse_z80_pseudo.c => arch/p_gnu/parse/parse_z80_gnu.c} (95%) rename librz/{parse => arch}/parse.c (94%) rename librz/{parse/p/parse_common.c => arch/parse_helper.c} (61%) create mode 100644 librz/arch/parse_helper.h delete mode 100644 librz/parse/README.md delete mode 100644 librz/parse/meson.build delete mode 100644 librz/parse/p/parse_att2intel.c diff --git a/binrz/rizin/meson.build b/binrz/rizin/meson.build index a773375b8f..a0af0d1cde 100644 --- a/binrz/rizin/meson.build +++ b/binrz/rizin/meson.build @@ -15,7 +15,6 @@ rizin_exe = executable('rizin', 'rizin.c', rz_bp_dep, rz_reg_dep, rz_syscall_dep, - rz_parse_dep, rz_egg_dep, rz_search_dep, rz_hash_dep, diff --git a/librz/arch/arch.c b/librz/arch/arch.c index fd5b398d04..3699fe0c2b 100644 --- a/librz/arch/arch.c +++ b/librz/arch/arch.c @@ -28,3 +28,10 @@ RZ_DEPRECATE RZ_API RZ_BORROW RzAnalysisPlugin *rz_arch_get_analysis_plugin(size } return arch_static_plugins[index]->p_analysis; } + +RZ_DEPRECATE RZ_API RZ_BORROW RzParsePlugin *rz_arch_get_parse_plugin(size_t index) { + if (index >= RZ_ARRAY_SIZE(arch_static_plugins)) { + return NULL; + } + return arch_static_plugins[index]->p_parse; +} diff --git a/librz/arch/deprecated_arch_helper.h b/librz/arch/deprecated_arch_helper.h index aaebd18918..01a76ad70f 100644 --- a/librz/arch/deprecated_arch_helper.h +++ b/librz/arch/deprecated_arch_helper.h @@ -11,12 +11,21 @@ RzArchPlugin rz_arch_plugin_##name = { \ .p_asm = &rz_asm_plugin_##name, \ .p_analysis = &rz_analysis_plugin_##name, \ + .p_parse = &rz_parse_plugin_##name##_pseudo, \ + } + +#define DEPRECATED_OLD_ARCH_NO_PARSE_PLUGIN(name) \ + RzArchPlugin rz_arch_plugin_##name = { \ + .p_asm = &rz_asm_plugin_##name, \ + .p_analysis = &rz_analysis_plugin_##name, \ + .p_parse = NULL, \ } #define DEPRECATED_OLD_ARCH_ASM_ONLY_PLUGIN(name) \ RzArchPlugin rz_arch_plugin_##name = { \ .p_asm = &rz_asm_plugin_##name, \ .p_analysis = NULL, \ + .p_parse = NULL, \ } #ifndef RZ_PLUGIN_INCORE @@ -30,10 +39,14 @@ #define ARCH_PLUGIN_LIB_STRUCT(name) #endif -#define RZ_ARCH_PLUGIN_DEFINE_DEPRECATED(name) \ +#define RZ_ARCH_WITH_PARSE_PLUGIN_DEFINE_DEPRECATED(name) \ DEPRECATED_OLD_ARCH_PLUGIN(name); \ ARCH_PLUGIN_LIB_STRUCT(name) +#define RZ_ARCH_PLUGIN_DEFINE_DEPRECATED(name) \ + DEPRECATED_OLD_ARCH_NO_PARSE_PLUGIN(name); \ + ARCH_PLUGIN_LIB_STRUCT(name) + #define RZ_ARCH_ASM_ONLY_PLUGIN_DEFINE_DEPRECATED(name) \ DEPRECATED_OLD_ARCH_ASM_ONLY_PLUGIN(name); \ ARCH_PLUGIN_LIB_STRUCT(name) diff --git a/librz/parse/filter.c b/librz/arch/filter.c similarity index 99% rename from librz/parse/filter.c rename to librz/arch/filter.c index 6df5224bd5..a392df6c28 100644 --- a/librz/parse/filter.c +++ b/librz/arch/filter.c @@ -3,12 +3,12 @@ // SPDX-FileCopyrightText: 2009-2019 maijin // SPDX-License-Identifier: LGPL-3.0-only -#include "rz_util/rz_str.h" -#include #include +#include +#include #include -#include +#include #define isx86separator(x) ( \ (x) == ' ' || (x) == '\t' || (x) == '\n' || (x) == '\r' || (x) == ' ' || \ diff --git a/librz/arch/meson.build b/librz/arch/meson.build index 40c3c08849..44e7f4a2fe 100644 --- a/librz/arch/meson.build +++ b/librz/arch/meson.build @@ -360,6 +360,7 @@ arch_common_sources = [ 'data.c', 'dwarf_process.c', 'fcn.c', + 'filter.c', 'function.c', 'hint.c', 'il_trace.c', @@ -367,6 +368,8 @@ arch_common_sources = [ 'labels.c', 'meta.c', 'op.c', + 'parse.c', + 'parse_helper.c', 'pdb_process.c', 'platform_profile.c', 'platform_target_index.c', @@ -415,7 +418,6 @@ rz_arch = library('rz_arch', rz_arch_sources, rz_flag_dep, rz_hash_dep, rz_diff_dep, - rz_parse_dep, rz_bin_dep, rz_type_dep, rz_il_dep, @@ -445,7 +447,6 @@ modules += { 'rz_arch': { 'rz_flag', 'rz_hash', 'rz_il', - 'rz_parse', 'rz_reg', 'rz_search', 'rz_syscall', diff --git a/librz/arch/p/arch_6502.c b/librz/arch/p/arch_6502.c index f1735446de..4b9bc11a95 100644 --- a/librz/arch/p/arch_6502.c +++ b/librz/arch/p/arch_6502.c @@ -6,5 +6,6 @@ #include "analysis/analysis_6502.c" #include "asm/asm_6502.c" +#include "parse/parse_6502_pseudo.c" -RZ_ARCH_PLUGIN_DEFINE_DEPRECATED(6502); +RZ_ARCH_WITH_PARSE_PLUGIN_DEFINE_DEPRECATED(6502); diff --git a/librz/arch/p/arch_arm_cs.c b/librz/arch/p/arch_arm_cs.c index 63f1fa6b5e..0cbe824174 100644 --- a/librz/arch/p/arch_arm_cs.c +++ b/librz/arch/p/arch_arm_cs.c @@ -6,5 +6,6 @@ #include "analysis/analysis_arm_cs.c" #include "asm/asm_arm_cs.c" +#include "parse/parse_arm_pseudo.c" -RZ_ARCH_PLUGIN_DEFINE_DEPRECATED(arm_cs); +RZ_ARCH_WITH_PARSE_PLUGIN_DEFINE_DEPRECATED(arm_cs); diff --git a/librz/arch/p/arch_avr.c b/librz/arch/p/arch_avr.c index 376085e4f8..1f09a4d043 100644 --- a/librz/arch/p/arch_avr.c +++ b/librz/arch/p/arch_avr.c @@ -6,5 +6,6 @@ #include "analysis/analysis_avr.c" #include "asm/asm_avr.c" +#include "parse/parse_avr_pseudo.c" -RZ_ARCH_PLUGIN_DEFINE_DEPRECATED(avr); +RZ_ARCH_WITH_PARSE_PLUGIN_DEFINE_DEPRECATED(avr); diff --git a/librz/arch/p/arch_chip8.c b/librz/arch/p/arch_chip8.c index c699325659..b51bdbb855 100644 --- a/librz/arch/p/arch_chip8.c +++ b/librz/arch/p/arch_chip8.c @@ -6,5 +6,6 @@ #include "analysis/analysis_chip8.c" #include "asm/asm_chip8.c" +#include "parse/parse_chip8_pseudo.c" -RZ_ARCH_PLUGIN_DEFINE_DEPRECATED(chip8); +RZ_ARCH_WITH_PARSE_PLUGIN_DEFINE_DEPRECATED(chip8); diff --git a/librz/arch/p/arch_dalvik.c b/librz/arch/p/arch_dalvik.c index 4dbd782c9c..ad426c55c2 100644 --- a/librz/arch/p/arch_dalvik.c +++ b/librz/arch/p/arch_dalvik.c @@ -6,5 +6,6 @@ #include "analysis/analysis_dalvik.c" #include "asm/asm_dalvik.c" +#include "parse/parse_dalvik_pseudo.c" -RZ_ARCH_PLUGIN_DEFINE_DEPRECATED(dalvik); +RZ_ARCH_WITH_PARSE_PLUGIN_DEFINE_DEPRECATED(dalvik); diff --git a/librz/arch/p/arch_m68k_cs.c b/librz/arch/p/arch_m68k_cs.c index 1bc93bf31f..9f1d71b7ce 100644 --- a/librz/arch/p/arch_m68k_cs.c +++ b/librz/arch/p/arch_m68k_cs.c @@ -6,5 +6,6 @@ #include "analysis/analysis_m68k_cs.c" #include "asm/asm_m68k_cs.c" +#include "parse/parse_m68k_pseudo.c" -RZ_ARCH_PLUGIN_DEFINE_DEPRECATED(m68k_cs); +RZ_ARCH_WITH_PARSE_PLUGIN_DEFINE_DEPRECATED(m68k_cs); diff --git a/librz/arch/p/arch_mips_cs.c b/librz/arch/p/arch_mips_cs.c index 431647d49d..17e9614c4d 100644 --- a/librz/arch/p/arch_mips_cs.c +++ b/librz/arch/p/arch_mips_cs.c @@ -6,5 +6,6 @@ #include "analysis/analysis_mips_cs.c" #include "asm/asm_mips_cs.c" +#include "parse/parse_mips_pseudo.c" -RZ_ARCH_PLUGIN_DEFINE_DEPRECATED(mips_cs); +RZ_ARCH_WITH_PARSE_PLUGIN_DEFINE_DEPRECATED(mips_cs); diff --git a/librz/arch/p/arch_ppc_cs.c b/librz/arch/p/arch_ppc_cs.c index b103ad1a5e..da5d4df90a 100644 --- a/librz/arch/p/arch_ppc_cs.c +++ b/librz/arch/p/arch_ppc_cs.c @@ -6,5 +6,6 @@ #include "analysis/analysis_ppc_cs.c" #include "asm/asm_ppc_cs.c" +#include "parse/parse_ppc_pseudo.c" -RZ_ARCH_PLUGIN_DEFINE_DEPRECATED(ppc_cs); +RZ_ARCH_WITH_PARSE_PLUGIN_DEFINE_DEPRECATED(ppc_cs); diff --git a/librz/arch/p/arch_sh.c b/librz/arch/p/arch_sh.c index 840f255392..ca251e3e7f 100644 --- a/librz/arch/p/arch_sh.c +++ b/librz/arch/p/arch_sh.c @@ -6,5 +6,6 @@ #include "analysis/analysis_sh.c" #include "asm/asm_sh.c" +#include "parse/parse_sh_pseudo.c" -RZ_ARCH_PLUGIN_DEFINE_DEPRECATED(sh); +RZ_ARCH_WITH_PARSE_PLUGIN_DEFINE_DEPRECATED(sh); diff --git a/librz/arch/p/arch_tms320.c b/librz/arch/p/arch_tms320.c index c65864f0d1..2d83947e62 100644 --- a/librz/arch/p/arch_tms320.c +++ b/librz/arch/p/arch_tms320.c @@ -6,5 +6,6 @@ #include "analysis/analysis_tms320.c" #include "asm/asm_tms320.c" +#include "parse/parse_tms320_pseudo.c" -RZ_ARCH_PLUGIN_DEFINE_DEPRECATED(tms320); +RZ_ARCH_WITH_PARSE_PLUGIN_DEFINE_DEPRECATED(tms320); diff --git a/librz/arch/p/arch_v850.c b/librz/arch/p/arch_v850.c index 4256ed9d2c..1ad09f9207 100644 --- a/librz/arch/p/arch_v850.c +++ b/librz/arch/p/arch_v850.c @@ -6,5 +6,6 @@ #include "analysis/analysis_v850.c" #include "asm/asm_v850.c" +#include "parse/parse_v850_pseudo.c" -RZ_ARCH_PLUGIN_DEFINE_DEPRECATED(v850); +RZ_ARCH_WITH_PARSE_PLUGIN_DEFINE_DEPRECATED(v850); diff --git a/librz/arch/p/arch_wasm.c b/librz/arch/p/arch_wasm.c index 0b82df22a0..0fc733b8dc 100644 --- a/librz/arch/p/arch_wasm.c +++ b/librz/arch/p/arch_wasm.c @@ -6,5 +6,6 @@ #include "analysis/analysis_wasm.c" #include "asm/asm_wasm.c" +#include "parse/parse_wasm_pseudo.c" -RZ_ARCH_PLUGIN_DEFINE_DEPRECATED(wasm); +RZ_ARCH_WITH_PARSE_PLUGIN_DEFINE_DEPRECATED(wasm); diff --git a/librz/arch/p/arch_x86_cs.c b/librz/arch/p/arch_x86_cs.c index 830f1b813a..6efb67e652 100644 --- a/librz/arch/p/arch_x86_cs.c +++ b/librz/arch/p/arch_x86_cs.c @@ -6,5 +6,6 @@ #include "analysis/analysis_x86_cs.c" #include "asm/asm_x86_cs.c" +#include "parse/parse_x86_pseudo.c" -RZ_ARCH_PLUGIN_DEFINE_DEPRECATED(x86_cs); +RZ_ARCH_WITH_PARSE_PLUGIN_DEFINE_DEPRECATED(x86_cs); diff --git a/librz/parse/p/parse_6502_pseudo.c b/librz/arch/p/parse/parse_6502_pseudo.c similarity index 95% rename from librz/parse/p/parse_6502_pseudo.c rename to librz/arch/p/parse/parse_6502_pseudo.c index daf0861935..b5b4c99b50 100644 --- a/librz/parse/p/parse_6502_pseudo.c +++ b/librz/arch/p/parse/parse_6502_pseudo.c @@ -11,7 +11,7 @@ #include #include -#include "parse_common.c" +#include "parse_helper.h" static RzList /**/ *_6502_tokenize(const char *assembly, size_t length); @@ -123,11 +123,3 @@ RzParsePlugin rz_parse_plugin_6502_pseudo = { .desc = "6502 pseudo syntax", .parse = parse, }; - -#ifndef RZ_PLUGIN_INCORE -RZ_API RzLibStruct rizin_plugin = { - .type = RZ_LIB_TYPE_PARSE, - .data = &rz_parse_plugin_6502_pseudo, - .version = RZ_VERSION -}; -#endif diff --git a/librz/parse/p/parse_arm_pseudo.c b/librz/arch/p/parse/parse_arm_pseudo.c similarity index 98% rename from librz/parse/p/parse_arm_pseudo.c rename to librz/arch/p/parse/parse_arm_pseudo.c index 9c54178cc7..b43d958e7e 100644 --- a/librz/parse/p/parse_arm_pseudo.c +++ b/librz/arch/p/parse/parse_arm_pseudo.c @@ -13,7 +13,7 @@ #include #include -#include "parse_common.c" +#include "parse_helper.h" static RzList /**/ *arm_tokenize(const char *assembly, size_t length); @@ -392,17 +392,9 @@ static bool subvar(RzParse *p, RzAnalysisFunction *f, RzAnalysisOp *op, char *da return true; } -RzParsePlugin rz_parse_plugin_arm_pseudo = { +RzParsePlugin rz_parse_plugin_arm_cs_pseudo = { .name = "arm.pseudo", .desc = "ARM/ARM64 pseudo syntax", .parse = parse, .subvar = &subvar, }; - -#ifndef RZ_PLUGIN_INCORE -RZ_API RzLibStruct rizin_plugin = { - .type = RZ_LIB_TYPE_PARSE, - .data = &rz_parse_plugin_arm_pseudo, - .version = RZ_VERSION -}; -#endif diff --git a/librz/parse/p/parse_avr_pseudo.c b/librz/arch/p/parse/parse_avr_pseudo.c similarity index 96% rename from librz/parse/p/parse_avr_pseudo.c rename to librz/arch/p/parse/parse_avr_pseudo.c index 24d4d1d692..a420cc09c4 100644 --- a/librz/parse/p/parse_avr_pseudo.c +++ b/librz/arch/p/parse/parse_avr_pseudo.c @@ -11,7 +11,7 @@ #include #include -#include "parse_common.c" +#include "parse_helper.h" static RzList /**/ *avr_tokenize(const char *assembly, size_t length); @@ -155,11 +155,3 @@ RzParsePlugin rz_parse_plugin_avr_pseudo = { .desc = "AVR pseudo syntax", .parse = parse }; - -#ifndef RZ_PLUGIN_INCORE -RZ_API RzLibStruct rizin_plugin = { - .type = RZ_LIB_TYPE_PARSE, - .data = &rz_parse_plugin_avr_pseudo, - .version = RZ_VERSION -}; -#endif diff --git a/librz/parse/p/parse_chip8_pseudo.c b/librz/arch/p/parse/parse_chip8_pseudo.c similarity index 95% rename from librz/parse/p/parse_chip8_pseudo.c rename to librz/arch/p/parse/parse_chip8_pseudo.c index b137b6cf8d..18627f06c8 100644 --- a/librz/parse/p/parse_chip8_pseudo.c +++ b/librz/arch/p/parse/parse_chip8_pseudo.c @@ -112,11 +112,3 @@ RzParsePlugin rz_parse_plugin_chip8_pseudo = { .desc = "chip8 pseudo syntax", .parse = parse, }; - -#ifndef RZ_PLUGIN_INCORE -RZ_API RzLibStruct rizin_plugin = { - .type = RZ_LIB_TYPE_PARSE, - .data = &rz_parse_plugin_chip8_pseudo, - .version = RZ_VERSION -}; -#endif diff --git a/librz/parse/p/parse_dalvik_pseudo.c b/librz/arch/p/parse/parse_dalvik_pseudo.c similarity index 98% rename from librz/parse/p/parse_dalvik_pseudo.c rename to librz/arch/p/parse/parse_dalvik_pseudo.c index d0656c7fe1..64bdfd0ec4 100644 --- a/librz/parse/p/parse_dalvik_pseudo.c +++ b/librz/arch/p/parse/parse_dalvik_pseudo.c @@ -11,7 +11,7 @@ #include #include -#include "parse_common.c" +#include "parse_helper.h" static RzList /**/ *dalvik_tokenize(const char *assembly, size_t length); @@ -264,11 +264,3 @@ RzParsePlugin rz_parse_plugin_dalvik_pseudo = { .fini = NULL, .parse = parse, }; - -#ifndef RZ_PLUGIN_INCORE -RZ_API RzLibStruct rizin_plugin = { - .type = RZ_LIB_TYPE_PARSE, - .data = &rz_parse_plugin_dalvik_pseudo, - .version = RZ_VERSION -}; -#endif diff --git a/librz/parse/p/parse_m68k_pseudo.c b/librz/arch/p/parse/parse_m68k_pseudo.c similarity index 93% rename from librz/parse/p/parse_m68k_pseudo.c rename to librz/arch/p/parse/parse_m68k_pseudo.c index 3c485558bb..a31ff704cb 100644 --- a/librz/parse/p/parse_m68k_pseudo.c +++ b/librz/arch/p/parse/parse_m68k_pseudo.c @@ -11,7 +11,7 @@ #include #include -#include "parse_common.c" +#include "parse_helper.h" static RzList /**/ *m68k_tokenize(const char *assembly, size_t length); @@ -99,16 +99,8 @@ static bool parse(RzParse *parse, const char *assembly, RzStrBuf *sb) { return res; } -RzParsePlugin rz_parse_plugin_m68k_pseudo = { +RzParsePlugin rz_parse_plugin_m68k_cs_pseudo = { .name = "m68k.pseudo", .desc = "M68K pseudo syntax", .parse = parse, }; - -#ifndef RZ_PLUGIN_INCORE -RZ_API RzLibStruct rizin_plugin = { - .type = RZ_LIB_TYPE_PARSE, - .data = &rz_parse_plugin_m68k_pseudo, - .version = RZ_VERSION -}; -#endif diff --git a/librz/parse/p/parse_mips_pseudo.c b/librz/arch/p/parse/parse_mips_pseudo.c similarity index 97% rename from librz/parse/p/parse_mips_pseudo.c rename to librz/arch/p/parse/parse_mips_pseudo.c index 633bd0e16b..96540c5c25 100644 --- a/librz/parse/p/parse_mips_pseudo.c +++ b/librz/arch/p/parse/parse_mips_pseudo.c @@ -11,10 +11,10 @@ #include #include #include - -#include "parse_common.c" #include +#include "parse_helper.h" + static RzList /**/ *mips_tokenize(const char *assembly, size_t length); static const RzPseudoGrammar mips_lexicon[] = { @@ -253,7 +253,7 @@ static bool subvar(RzParse *p, RzAnalysisFunction *f, RzAnalysisOp *op, char *da return ret; } -RzParsePlugin rz_parse_plugin_mips_pseudo = { +RzParsePlugin rz_parse_plugin_mips_cs_pseudo = { .name = "mips.pseudo", .desc = "MIPS pseudo syntax", .init = NULL, @@ -261,11 +261,3 @@ RzParsePlugin rz_parse_plugin_mips_pseudo = { .parse = parse, .subvar = subvar, }; - -#ifndef RZ_PLUGIN_INCORE -RZ_API RzLibStruct rizin_plugin = { - .type = RZ_LIB_TYPE_PARSE, - .data = &rz_parse_plugin_mips_pseudo, - .version = RZ_VERSION -}; -#endif diff --git a/librz/parse/p/parse_ppc_pseudo.c b/librz/arch/p/parse/parse_ppc_pseudo.c similarity index 99% rename from librz/parse/p/parse_ppc_pseudo.c rename to librz/arch/p/parse/parse_ppc_pseudo.c index 2b1113ea37..77e3fb47e5 100644 --- a/librz/parse/p/parse_ppc_pseudo.c +++ b/librz/arch/p/parse/parse_ppc_pseudo.c @@ -96,18 +96,6 @@ #define PPC_UT64(x) (strtol(x, NULL, 16)) #define PPC_UT32(x) ((ut32)PPC_UT64(x)) -static ut64 mask64(ut64 mb, ut64 me) { - ut64 maskmb = UT64_MAX >> mb; - ut64 maskme = UT64_MAX << (63 - me); - return (mb <= me) ? maskmb & maskme : maskmb | maskme; -} - -static ut32 mask32(ut32 mb, ut32 me) { - ut32 maskmb = UT32_MAX >> mb; - ut32 maskme = UT32_MAX << (31 - me); - return (mb <= me) ? maskmb & maskme : maskmb | maskme; -} - static int can_replace(const char *str, int idx, int max_operands) { if (str[idx] < 'A' || str[idx] > 'J') { return false; @@ -121,7 +109,7 @@ static int can_replace(const char *str, int idx, int max_operands) { return true; } -static const char *getspr(const char *reg) { +static const char *getspr_pseudo(const char *reg) { static char cspr[16]; ut32 spr = 0; if (!reg) { @@ -1587,7 +1575,7 @@ static int replace(int argc, const char *argv[], char *newstr) { break; } } else if ((i == 44 && letter == 2) || (i == 45 && letter == 1)) { // spr - w = getspr(w); + w = getspr_pseudo(w); } if (w != NULL) { strcpy(newstr + k, w); @@ -1754,16 +1742,8 @@ static bool parse(RzParse *p, const char *data, RzStrBuf *sb) { return true; } -RzParsePlugin rz_parse_plugin_ppc_pseudo = { +RzParsePlugin rz_parse_plugin_ppc_cs_pseudo = { .name = "ppc.pseudo", .desc = "PowerPC pseudo syntax", .parse = parse, }; - -#ifndef RZ_PLUGIN_INCORE -RZ_API RzLibStruct rizin_plugin = { - .type = RZ_LIB_TYPE_PARSE, - .data = &rz_parse_plugin_ppc_pseudo, - .version = RZ_VERSION -}; -#endif diff --git a/librz/parse/p/parse_sh_pseudo.c b/librz/arch/p/parse/parse_sh_pseudo.c similarity index 97% rename from librz/parse/p/parse_sh_pseudo.c rename to librz/arch/p/parse/parse_sh_pseudo.c index c509c82c63..89e5b13cec 100644 --- a/librz/parse/p/parse_sh_pseudo.c +++ b/librz/arch/p/parse/parse_sh_pseudo.c @@ -11,7 +11,7 @@ #include #include -#include "parse_common.c" +#include "parse_helper.h" static RzList /**/ *sh_tokenize(const char *assembly, size_t length); @@ -178,11 +178,3 @@ RzParsePlugin rz_parse_plugin_sh_pseudo = { .desc = "SH-4 pseudo syntax", .parse = parse }; - -#ifndef RZ_PLUGIN_INCORE -RZ_API RzLibStruct rizin_plugin = { - .type = RZ_LIB_TYPE_PARSE, - .data = &rz_parse_plugin_sh_pseudo, - .version = RZ_VERSION -}; -#endif diff --git a/librz/parse/p/parse_tms320_pseudo.c b/librz/arch/p/parse/parse_tms320_pseudo.c similarity index 96% rename from librz/parse/p/parse_tms320_pseudo.c rename to librz/arch/p/parse/parse_tms320_pseudo.c index 5912d4bb48..61ac938b51 100644 --- a/librz/parse/p/parse_tms320_pseudo.c +++ b/librz/arch/p/parse/parse_tms320_pseudo.c @@ -7,7 +7,7 @@ #include // https://www.ti.com/lit/ug/spru732j/spru732j.pdf -#include "parse_common.c" +#include "parse_helper.h" static RzList /**/ *tms320_tokenize(const char *assembly, size_t length); @@ -122,11 +122,3 @@ RzParsePlugin rz_parse_plugin_tms320_pseudo = { .desc = "tms320 pseudo syntax", .parse = parse, }; - -#ifndef RZ_PLUGIN_INCORE -RZ_API RzLibStruct rizin_plugin = { - .type = RZ_LIB_TYPE_PARSE, - .data = &rz_parse_plugin_tms320_pseudo, - .version = RZ_VERSION -}; -#endif diff --git a/librz/parse/p/parse_v850_pseudo.c b/librz/arch/p/parse/parse_v850_pseudo.c similarity index 96% rename from librz/parse/p/parse_v850_pseudo.c rename to librz/arch/p/parse/parse_v850_pseudo.c index 7c9465fc0f..f4cdf59c08 100644 --- a/librz/parse/p/parse_v850_pseudo.c +++ b/librz/arch/p/parse/parse_v850_pseudo.c @@ -8,7 +8,7 @@ // https://www.renesas.com/us/en/doc/products/mpumcu/doc/v850/r01us0037ej0100_v850e2.pdf -#include "parse_common.c" +#include "parse_helper.h" static RzList /**/ *v850_tokenize(const char *assembly, size_t length); @@ -141,11 +141,3 @@ RzParsePlugin rz_parse_plugin_v850_pseudo = { .desc = "v850 pseudo syntax", .parse = parse, }; - -#ifndef RZ_PLUGIN_INCORE -RZ_API RzLibStruct rizin_plugin = { - .type = RZ_LIB_TYPE_PARSE, - .data = &rz_parse_plugin_v850_pseudo, - .version = RZ_VERSION -}; -#endif diff --git a/librz/parse/p/parse_wasm_pseudo.c b/librz/arch/p/parse/parse_wasm_pseudo.c similarity index 86% rename from librz/parse/p/parse_wasm_pseudo.c rename to librz/arch/p/parse/parse_wasm_pseudo.c index 3befb230f6..d57c01affe 100644 --- a/librz/parse/p/parse_wasm_pseudo.c +++ b/librz/arch/p/parse/parse_wasm_pseudo.c @@ -41,11 +41,3 @@ RzParsePlugin rz_parse_plugin_wasm_pseudo = { .desc = "WASM pseudo syntax", .subvar = &subvar, }; - -#ifndef RZ_PLUGIN_INCORE -RZ_API RzLibStruct rizin_plugin = { - .type = RZ_LIB_TYPE_PARSE, - .data = &rz_parse_plugin_wasm_pseudo, - .version = RZ_VERSION -}; -#endif diff --git a/librz/parse/p/parse_x86_pseudo.c b/librz/arch/p/parse/parse_x86_pseudo.c similarity index 98% rename from librz/parse/p/parse_x86_pseudo.c rename to librz/arch/p/parse/parse_x86_pseudo.c index e4d316931b..45fe83c90c 100644 --- a/librz/parse/p/parse_x86_pseudo.c +++ b/librz/arch/p/parse/parse_x86_pseudo.c @@ -461,17 +461,9 @@ static bool subvar(RzParse *p, RzAnalysisFunction *f, RzAnalysisOp *op, char *da return ret; } -RzParsePlugin rz_parse_plugin_x86_pseudo = { +RzParsePlugin rz_parse_plugin_x86_cs_pseudo = { .name = "x86.pseudo", .desc = "X86 pseudo syntax", .parse = &parse, .subvar = &subvar, }; - -#ifndef RZ_PLUGIN_INCORE -RZ_API RzLibStruct rizin_plugin = { - .type = RZ_LIB_TYPE_PARSE, - .data = &rz_parse_plugin_x86_pseudo, - .version = RZ_VERSION -}; -#endif diff --git a/librz/arch/p_gnu/arch_riscv.c b/librz/arch/p_gnu/arch_riscv.c index abec147789..8e464619ea 100644 --- a/librz/arch/p_gnu/arch_riscv.c +++ b/librz/arch/p_gnu/arch_riscv.c @@ -10,5 +10,6 @@ #include "analysis/analysis_riscv_gnu.c" #include "asm/asm_riscv_gnu.c" +#include "parse/parse_riscv_gnu.c" -RZ_ARCH_PLUGIN_DEFINE_DEPRECATED(riscv_gnu); +RZ_ARCH_WITH_PARSE_PLUGIN_DEFINE_DEPRECATED(riscv_gnu); diff --git a/librz/arch/p_gnu/arch_z80.c b/librz/arch/p_gnu/arch_z80.c index 759b826e62..05f0cc5662 100644 --- a/librz/arch/p_gnu/arch_z80.c +++ b/librz/arch/p_gnu/arch_z80.c @@ -6,7 +6,9 @@ #include "../isa_gnu/z80/z80.c" #include "../isa_gnu/z80/z80asm.c" + #include "analysis/analysis_z80_gnu.c" #include "asm/asm_z80_gnu.c" +#include "parse/parse_z80_gnu.c" -RZ_ARCH_PLUGIN_DEFINE_DEPRECATED(z80_gnu); +RZ_ARCH_WITH_PARSE_PLUGIN_DEFINE_DEPRECATED(z80_gnu); diff --git a/librz/parse/p/parse_riscv_pseudo.c b/librz/arch/p_gnu/parse/parse_riscv_gnu.c similarity index 96% rename from librz/parse/p/parse_riscv_pseudo.c rename to librz/arch/p_gnu/parse/parse_riscv_gnu.c index 383da471e4..2fe5584adf 100644 --- a/librz/parse/p/parse_riscv_pseudo.c +++ b/librz/arch/p_gnu/parse/parse_riscv_gnu.c @@ -219,16 +219,8 @@ static bool parse(RzParse *p, const char *data, RzStrBuf *sb) { return true; } -RzParsePlugin rz_parse_plugin_riscv_pseudo = { +RzParsePlugin rz_parse_plugin_riscv_gnu_pseudo = { .name = "riscv.pseudo", .desc = "riscv pseudo syntax", .parse = parse, }; - -#ifndef RZ_PLUGIN_INCORE -RZ_API RzLibStruct rizin_plugin = { - .type = RZ_LIB_TYPE_PARSE, - .data = &rz_parse_plugin_riscv_pseudo, - .version = RZ_VERSION -}; -#endif diff --git a/librz/parse/p/parse_z80_pseudo.c b/librz/arch/p_gnu/parse/parse_z80_gnu.c similarity index 95% rename from librz/parse/p/parse_z80_pseudo.c rename to librz/arch/p_gnu/parse/parse_z80_gnu.c index e5b27487f3..bc2323e1e1 100644 --- a/librz/parse/p/parse_z80_pseudo.c +++ b/librz/arch/p_gnu/parse/parse_z80_gnu.c @@ -11,7 +11,7 @@ #include #include -#include "parse_common.c" +#include "parse_helper.h" static RzList /**/ *z80_tokenize(const char *assembly, size_t length); @@ -153,18 +153,10 @@ static bool parse(RzParse *parse, const char *assembly, RzStrBuf *sb) { return rz_pseudo_convert(&z80_config, assembly, sb); } -RzParsePlugin rz_parse_plugin_z80_pseudo = { +RzParsePlugin rz_parse_plugin_z80_gnu_pseudo = { .name = "z80.pseudo", .desc = "z80 pseudo syntax", .init = NULL, .fini = NULL, .parse = parse, }; - -#ifndef RZ_PLUGIN_INCORE -RZ_API RzLibStruct rizin_plugin = { - .type = RZ_LIB_TYPE_PARSE, - .data = &rz_parse_plugin_z80_pseudo, - .version = RZ_VERSION -}; -#endif diff --git a/librz/parse/parse.c b/librz/arch/parse.c similarity index 94% rename from librz/parse/parse.c rename to librz/arch/parse.c index 892e154530..808bf7bec7 100644 --- a/librz/parse/parse.c +++ b/librz/arch/parse.c @@ -6,16 +6,10 @@ #include #include -#include +#include #include -#include "rz_parse_plugins.h" - -RZ_LIB_VERSION(rz_parse); - -static RzParsePlugin *parse_static_plugins[] = { RZ_PARSE_STATIC_PLUGINS }; RZ_API RzParse *rz_parse_new(void) { - int i; RzParse *p = RZ_NEW0(RzParse); if (!p) { return NULL; @@ -32,8 +26,14 @@ RZ_API RzParse *rz_parse_new(void) { p->subtail = false; p->minval = 0x100; p->localvar_only = false; - for (i = 0; i < RZ_ARRAY_SIZE(parse_static_plugins); i++) { - rz_parse_plugin_add(p, parse_static_plugins[i]); + + const size_t n_plugins = rz_arch_get_n_plugins(); + for (size_t i = 0; i < n_plugins; i++) { + RzParsePlugin *plugin = rz_arch_get_parse_plugin(i); + if (!plugin) { + continue; + } + rz_parse_plugin_add(p, plugin); } return p; } diff --git a/librz/parse/p/parse_common.c b/librz/arch/parse_helper.c similarity index 61% rename from librz/parse/p/parse_common.c rename to librz/arch/parse_helper.c index 5bb7897ff7..94fb7180cb 100644 --- a/librz/parse/p/parse_common.c +++ b/librz/arch/parse_helper.c @@ -1,7 +1,9 @@ -// SPDX-FileCopyrightText: 2018-2021 deroad +// SPDX-FileCopyrightText: 2018-2024 deroad // SPDX-License-Identifier: LGPL-3.0-only -/** \file parse_common.c +#include "parse_helper.h" + +/** \file parse_helper.c * This file contains a common code that can be used to convert any asm code * into a pseudo code, via a generic grammar. * @@ -27,80 +29,7 @@ * and */ -typedef struct { - const char *mnemonic; - size_t mnemonic_length; - const char *grammar; -} RzPseudoGrammar; - -typedef struct { - const char *expected; - const char *pseudo; -} RzPseudoDirect; - -typedef struct { - const char *expected; - const char *replace; - int flag; // 0 for first match, 1 for all matches -} RzPseudoReplace; - -typedef struct { - const RzPseudoDirect *direct; - size_t direct_length; - const RzPseudoReplace *replace; - size_t replace_length; - const RzPseudoGrammar *lexicon; - size_t lexicon_length; - int max_args; - RzList /**/ *(*tokenize)(const char *assembly, size_t length); -} RzPseudoConfig; - -#define RZ_PSEUDO_DEFINE_GRAMMAR(x, y) \ - { .mnemonic = x, .mnemonic_length = sizeof(x) - 1, .grammar = y } - -#define RZ_PSEUDO_DEFINE_DIRECT(x, y) \ - { .expected = x, .pseudo = y } - -#define RZ_PSEUDO_DEFINE_REPLACE(x, y, f) \ - { .expected = x, .replace = y, .flag = f } - -#define RZ_PSEUDO_DEFINE_CONFIG(d, l, r, m, t) \ - { \ - .direct = d, \ - .direct_length = RZ_ARRAY_SIZE(d), \ - .replace = r, \ - .replace_length = RZ_ARRAY_SIZE(r), \ - .lexicon = l, \ - .lexicon_length = RZ_ARRAY_SIZE(l), \ - .max_args = m, \ - .tokenize = t, \ - } - -#define RZ_PSEUDO_DEFINE_CONFIG_NO_DIRECT(l, r, m, t) \ - { \ - .direct = NULL, \ - .direct_length = 0, \ - .replace = r, \ - .replace_length = RZ_ARRAY_SIZE(r), \ - .lexicon = l, \ - .lexicon_length = RZ_ARRAY_SIZE(l), \ - .max_args = m, \ - .tokenize = t, \ - } - -#define RZ_PSEUDO_DEFINE_CONFIG_ONLY_LEXICON(l, m, t) \ - { \ - .direct = NULL, \ - .direct_length = 0, \ - .replace = NULL, \ - .replace_length = 0, \ - .lexicon = l, \ - .lexicon_length = RZ_ARRAY_SIZE(l), \ - .max_args = m, \ - .tokenize = t, \ - } - -static bool rz_pseudo_convert(const RzPseudoConfig *config, const char *assembly, RzStrBuf *sb) { +RZ_IPI bool rz_pseudo_convert(const RzPseudoConfig *config, const char *assembly, RzStrBuf *sb) { rz_return_val_if_fail(config && config->tokenize && config->lexicon, false); size_t i, p; diff --git a/librz/arch/parse_helper.h b/librz/arch/parse_helper.h new file mode 100644 index 0000000000..bdc2334b6f --- /dev/null +++ b/librz/arch/parse_helper.h @@ -0,0 +1,84 @@ +// SPDX-FileCopyrightText: 2024 deroad +// SPDX-License-Identifier: LGPL-3.0-only + +#ifndef PARSE_HELPER_H +#define PARSE_HELPER_H + +#include + +typedef struct { + const char *mnemonic; + size_t mnemonic_length; + const char *grammar; +} RzPseudoGrammar; + +typedef struct { + const char *expected; + const char *pseudo; +} RzPseudoDirect; + +typedef struct { + const char *expected; + const char *replace; + int flag; // 0 for first match, 1 for all matches +} RzPseudoReplace; + +typedef struct { + const RzPseudoDirect *direct; + size_t direct_length; + const RzPseudoReplace *replace; + size_t replace_length; + const RzPseudoGrammar *lexicon; + size_t lexicon_length; + int max_args; + RzList /**/ *(*tokenize)(const char *assembly, size_t length); +} RzPseudoConfig; + +#define RZ_PSEUDO_DEFINE_GRAMMAR(x, y) \ + { .mnemonic = x, .mnemonic_length = sizeof(x) - 1, .grammar = y } + +#define RZ_PSEUDO_DEFINE_DIRECT(x, y) \ + { .expected = x, .pseudo = y } + +#define RZ_PSEUDO_DEFINE_REPLACE(x, y, f) \ + { .expected = x, .replace = y, .flag = f } + +#define RZ_PSEUDO_DEFINE_CONFIG(d, l, r, m, t) \ + { \ + .direct = d, \ + .direct_length = RZ_ARRAY_SIZE(d), \ + .replace = r, \ + .replace_length = RZ_ARRAY_SIZE(r), \ + .lexicon = l, \ + .lexicon_length = RZ_ARRAY_SIZE(l), \ + .max_args = m, \ + .tokenize = t, \ + } + +#define RZ_PSEUDO_DEFINE_CONFIG_NO_DIRECT(l, r, m, t) \ + { \ + .direct = NULL, \ + .direct_length = 0, \ + .replace = r, \ + .replace_length = RZ_ARRAY_SIZE(r), \ + .lexicon = l, \ + .lexicon_length = RZ_ARRAY_SIZE(l), \ + .max_args = m, \ + .tokenize = t, \ + } + +#define RZ_PSEUDO_DEFINE_CONFIG_ONLY_LEXICON(l, m, t) \ + { \ + .direct = NULL, \ + .direct_length = 0, \ + .replace = NULL, \ + .replace_length = 0, \ + .lexicon = l, \ + .lexicon_length = RZ_ARRAY_SIZE(l), \ + .max_args = m, \ + .tokenize = t, \ + } + +RZ_IPI bool rz_pseudo_convert(const RzPseudoConfig *config, const char *assembly, RzStrBuf *sb); + +#endif /* PARSE_HELPER_H */ diff --git a/librz/core/libs.c b/librz/core/libs.c index 078aef1ff7..74ff419ce9 100644 --- a/librz/core/libs.c +++ b/librz/core/libs.c @@ -42,11 +42,8 @@ CB(hash, hash) static bool lib_arch_cb(RzLibPlugin *pl, void *user, void *data) { RzArchPlugin *hand = (RzArchPlugin *)data; RzCore *core = (RzCore *)user; - if (!hand->p_asm && !hand->p_analysis) { - // TODO: add new structure. - // return rz_arch_plugin_add(core->arch, hand); - return false; - } + // TODO: add new structure. + // return rz_arch_plugin_add(core->arch, hand); if (hand->p_asm && !rz_asm_plugin_add(core->rasm, hand->p_asm)) { // deprecated structure return false; @@ -55,6 +52,10 @@ static bool lib_arch_cb(RzLibPlugin *pl, void *user, void *data) { // deprecated structure return false; } + if (hand->p_parse && !rz_parse_plugin_add(core->parser, hand->p_parse)) { + // deprecated structure + return false; + } return true; } diff --git a/librz/core/meson.build b/librz/core/meson.build index 1019be246e..44f17752f4 100644 --- a/librz/core/meson.build +++ b/librz/core/meson.build @@ -148,7 +148,6 @@ rz_core_deps = [ rz_reg_dep, rz_bp_dep, rz_syscall_dep, - rz_parse_dep, rz_egg_dep, rz_search_dep, rz_sign_dep, @@ -199,7 +198,6 @@ modules += { 'rz_core': { 'rz_lang', 'rz_hash', 'rz_flag', - 'rz_parse', 'rz_egg', 'rz_debug', 'rz_crypto', diff --git a/librz/include/rz_arch.h b/librz/include/rz_arch.h index 5e3ee72a14..bf628fe5ec 100644 --- a/librz/include/rz_arch.h +++ b/librz/include/rz_arch.h @@ -8,6 +8,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -18,11 +19,13 @@ RZ_LIB_VERSION_HEADER(rz_arch); typedef struct rz_arch_plugin_t { RZ_DEPRECATE RzAsmPlugin *p_asm; ///< Assembly Plugin RZ_DEPRECATE RzAnalysisPlugin *p_analysis; ///< Analysis Plugin + RZ_DEPRECATE RzParsePlugin *p_parse; ///< Parse Plugin } RzArchPlugin; RZ_DEPRECATE RZ_API const size_t rz_arch_get_n_plugins(); RZ_DEPRECATE RZ_API RZ_BORROW RzAsmPlugin *rz_arch_get_asm_plugin(size_t index); RZ_DEPRECATE RZ_API RZ_BORROW RzAnalysisPlugin *rz_arch_get_analysis_plugin(size_t index); +RZ_DEPRECATE RZ_API RZ_BORROW RzParsePlugin *rz_arch_get_parse_plugin(size_t index); #ifdef __cplusplus } diff --git a/librz/include/rz_parse.h b/librz/include/rz_parse.h index 5120cba172..34d4b9c0e0 100644 --- a/librz/include/rz_parse.h +++ b/librz/include/rz_parse.h @@ -13,8 +13,6 @@ extern "C" { #endif -RZ_LIB_VERSION_HEADER(rz_parse); - typedef struct rz_parse_t { void *user; RzSpace *flagspace; diff --git a/librz/main/meson.build b/librz/main/meson.build index 66371ed298..b7e04ec166 100644 --- a/librz/main/meson.build +++ b/librz/main/meson.build @@ -26,7 +26,6 @@ rz_main_deps = [ rz_reg_dep, rz_bp_dep, rz_syscall_dep, - rz_parse_dep, rz_arch_dep, rz_egg_dep, rz_search_dep, diff --git a/librz/main/rizin.c b/librz/main/rizin.c index 37bc78b073..e6e1490448 100644 --- a/librz/main/rizin.c +++ b/librz/main/rizin.c @@ -53,7 +53,6 @@ static int rz_main_version_verify(int show) { #if !USE_LIB_MAGIC { "rz_magic", rz_magic_version }, #endif - { "rz_parse", rz_parse_version }, { "rz_reg", rz_reg_version }, { "rz_sign", rz_sign_version }, { "rz_search", rz_search_version }, diff --git a/librz/meson.build b/librz/meson.build index 164d598fd4..bc57eb27e5 100644 --- a/librz/meson.build +++ b/librz/meson.build @@ -21,7 +21,6 @@ subdir('reg') subdir('type') subdir('bin') subdir('config') -subdir('parse') subdir('lang') subdir('il') subdir('arch') diff --git a/librz/parse/README.md b/librz/parse/README.md deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/librz/parse/meson.build b/librz/parse/meson.build deleted file mode 100644 index 9b102d3b60..0000000000 --- a/librz/parse/meson.build +++ /dev/null @@ -1,81 +0,0 @@ -parse_plugins_list = [ - '6502_pseudo', - 'arm_pseudo', - 'att2intel', - 'avr_pseudo', - 'chip8_pseudo', - 'dalvik_pseudo', - 'm68k_pseudo', - 'mips_pseudo', - 'ppc_pseudo', - 'sh_pseudo', - 'tms320_pseudo', - 'v850_pseudo', - 'wasm_pseudo', - 'x86_pseudo', -] - -rz_parse_sources = [ - 'filter.c', - 'parse.c', - 'p/parse_6502_pseudo.c', - 'p/parse_arm_pseudo.c', - 'p/parse_att2intel.c', - 'p/parse_avr_pseudo.c', - 'p/parse_chip8_pseudo.c', - 'p/parse_dalvik_pseudo.c', - 'p/parse_m68k_pseudo.c', - 'p/parse_mips_pseudo.c', - 'p/parse_ppc_pseudo.c', - 'p/parse_sh_pseudo.c', - 'p/parse_tms320_pseudo.c', - 'p/parse_v850_pseudo.c', - 'p/parse_wasm_pseudo.c', - 'p/parse_x86_pseudo.c', -] - -if get_option('use_gpl') - parse_plugins_list += [ - 'riscv_pseudo', - 'z80_pseudo', - ] - - rz_parse_sources += [ - 'p/parse_riscv_pseudo.c', - 'p/parse_z80_pseudo.c', - ] -endif - -parse_plugins = { - 'base_name': 'rz_parse', - 'base_struct': 'RzParsePlugin', - 'list': parse_plugins_list, -} - -rz_parse = library('rz_parse', rz_parse_sources, - include_directories: platform_inc, - dependencies: [ - rz_util_dep, - rz_flag_dep, - rz_syscall_dep, - rz_reg_dep, - rz_cons_dep, - ], - install: true, - implicit_include_directories: false, - install_rpath: rpath_lib, - soversion: rizin_libversion, - version: rizin_version, - name_suffix: lib_name_suffix, - name_prefix: lib_name_prefix, -) - -rz_parse_dep = declare_dependency(link_with: rz_parse, - include_directories: platform_inc) -meson.override_dependency('rz_parse', rz_parse_dep) - -modules += { 'rz_parse': { - 'target': rz_parse, - 'dependencies': ['rz_util', 'rz_flag', 'rz_syscall', 'rz_reg', 'rz_cons'], - 'plugins': [parse_plugins] -}} diff --git a/librz/parse/p/parse_att2intel.c b/librz/parse/p/parse_att2intel.c deleted file mode 100644 index 30a3391ad7..0000000000 --- a/librz/parse/p/parse_att2intel.c +++ /dev/null @@ -1,189 +0,0 @@ -// SPDX-FileCopyrightText: 2011 pancake -// SPDX-License-Identifier: LGPL-3.0-only - -#include -#include -#include - -#include -#include -#include -#include -#include - -static int replace(int argc, const char *argv[], char *newstr) { - int i, j, k; - struct { - char *op; - char *str; - } ops[] = { - { "cmpl", "cmp 2, 1" }, - { "testl", "test 2, 1" }, - { "leal", "lea 2, 1" }, - { "movl", "mov 2, 1" }, - { "xorl", "xor 2, 1" }, - { "andl", "and 2, 1" }, - { "orl", "or 2, 1" }, - { "addl", "add 2, 1" }, - { "incl", "inc 1" }, - { "decl", "dec 1" }, - { "subl", "sub 2, 1" }, - { "mull", "mul 2, 1" }, - { "divl", "div 2, 1" }, - { "pushl", "push 1" }, - { "popl", "pop 1" }, - { "ret", "ret" }, - { NULL } - }; - - for (i = 0; ops[i].op != NULL; i++) { - if (!strcmp(ops[i].op, argv[0])) { - if (newstr != NULL) { - for (j = k = 0; ops[i].str[j] != '\0'; j++, k++) { - if (ops[i].str[j] >= '0' && ops[i].str[j] <= '9') { - const char *w = argv[ops[i].str[j] - '0']; - if (w != NULL) { - strcpy(newstr + k, w); - k += strlen(w) - 1; - } - } else { - newstr[k] = ops[i].str[j]; - } - } - newstr[k] = '\0'; - } - return true; - } - } - - /* TODO: this is slow */ - if (newstr != NULL) { - newstr[0] = '\0'; - for (i = 0; i < argc; i++) { - strcat(newstr, argv[i]); - strcat(newstr, (i == 0 || i == argc - 1) ? " " : ","); - } - } - - return false; -} - -static bool parse(RzParse *p, const char *data, RzStrBuf *sb) { - int i, n; - char w0[32]; - char w1[32]; - char w2[32]; - char w3[32]; - char str[1024] = { 0 }; - char *buf, *ptr, *optr, *num; - - // malloc can be slow here :? - buf = strdup(data); - if (!buf) { - return false; - } - rz_str_trim_head(buf); - - ptr = strchr(buf, '#'); - if (ptr) { - *ptr = 0; - rz_str_trim(buf); - } - if (*buf == '.' || buf[strlen(buf) - 1] == ':') { - free(buf); - strcpy(str, data); - return true; - } - rz_str_replace_char(buf, '$', 0); - rz_str_replace_char(buf, '%', 0); - rz_str_replace_char(buf, '\t', ' '); - rz_str_replace_char(buf, '(', '['); - rz_str_replace_char(buf, ')', ']'); - ptr = strchr(buf, '['); - if (ptr) { - *ptr = 0; - num = (char *)rz_str_lchr(buf, ' '); - if (!num) { - num = (char *)rz_str_lchr(buf, ','); - } - if (num) { - n = atoi(num + 1); - *ptr = '['; - rz_str_cpy(num + 1, ptr); - ptr = (char *)rz_str_lchr(buf, ']'); - if (n && ptr) { - char *rest = strdup(ptr + 1); - size_t dist = strlen(data) + 1 - (ptr - buf); - snprintf(ptr, dist, "%+d]%s", n, rest); - free(rest); - } - } else { - *ptr = '['; - } - } - - if (*buf) { - *w0 = *w1 = *w2 = *w3 = 0; - ptr = strchr(buf, ' '); - if (!ptr) { - ptr = strchr(buf, '\t'); - } - if (ptr) { - *ptr = '\0'; - for (++ptr; *ptr == ' '; ptr++) { - ; - } - strncpy(w0, buf, sizeof(w0) - 1); - strncpy(w1, ptr, sizeof(w1) - 1); - - optr = ptr; - ptr = strchr(ptr, ','); - if (ptr) { - *ptr = '\0'; - for (++ptr; *ptr == ' '; ptr++) { - ; - } - strncpy(w1, optr, sizeof(w1) - 1); - strncpy(w2, ptr, sizeof(w2) - 1); - ptr = strchr(ptr, ','); - if (ptr) { - *ptr = '\0'; - for (++ptr; *ptr == ' '; ptr++) { - ; - } - strncpy(w2, optr, sizeof(w2) - 1); - strncpy(w3, ptr, sizeof(w3) - 1); - } - } - } - { - const char *wa[] = { w0, w1, w2, w3 }; - int nw = 0; - for (i = 0; i < 4; i++) { - if (wa[i][0] != '\0') { - nw++; - } - } - replace(nw, wa, str); - } - } - free(buf); - rz_strbuf_set(sb, str); - return true; -} - -RzParsePlugin rz_parse_plugin_att2intel = { - .name = "att2intel", - .desc = "X86 att 2 intel plugin", - .init = NULL, - .fini = NULL, - .parse = &parse, -}; - -#ifndef RZ_PLUGIN_INCORE -RZ_API RzLibStruct rizin_plugin = { - .type = RZ_LIB_TYPE_PARSE, - .data = &rz_parse_plugin_att2intel, - .version = RZ_VERSION -}; -#endif diff --git a/meson.build b/meson.build index 1197487a0b..a8153a2ee5 100644 --- a/meson.build +++ b/meson.build @@ -827,6 +827,5 @@ summary({ 'IO Plugins': io_plugins.get('list'), 'Lang Plugins': lang_plugins.get('list'), 'Hash Plugins': comb_hash_plugins, - 'Parse Plugins': parse_plugins.get('list'), 'Demangler Plugins': demangler_plugins.get('list'), }, section: 'Plugins', list_sep: ', ') diff --git a/test/db/cmd/cmd_list b/test/db/cmd/cmd_list index 7f2adae88e..91f2065161 100644 --- a/test/db/cmd/cmd_list +++ b/test/db/cmd/cmd_list @@ -4,7 +4,6 @@ CMDS=Lp EXPECT=<