From 09a0c3f863d6471532ecc8c868f95850e97ad1dc Mon Sep 17 00:00:00 2001 From: Anton Kochkov Date: Wed, 1 Mar 2023 12:37:01 +0800 Subject: [PATCH 1/4] Remove use of rz_malloc() --- src/CodeXMLParse.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CodeXMLParse.cpp b/src/CodeXMLParse.cpp index 3623c84f..1452e8c1 100644 --- a/src/CodeXMLParse.cpp +++ b/src/CodeXMLParse.cpp @@ -48,7 +48,7 @@ struct ParseCodeXMLContext static char *strdup_rz(const char *s) { size_t sz = strlen(s); - char *r = reinterpret_cast(rz_malloc(sz + 1)); + char *r = reinterpret_cast(rz_mem_alloc(sz + 1)); if(!r) return NULL; memcpy(r, s, sz + 1); @@ -350,7 +350,7 @@ RZ_API RzAnnotatedCode *ParseCodeXML(Funcdata *func, const char *xml) ParseNode(doc.child("function"), &ctx, ss, code); std::string str = ss.str(); - code->code = reinterpret_cast(rz_malloc(str.length() + 1)); + code->code = reinterpret_cast(rz_mem_alloc(str.length() + 1)); if(!code->code) { rz_annotated_code_free(code); From 301f5e86fdc4646cf33ec500cc18b758f99a3a3d Mon Sep 17 00:00:00 2001 From: Anton Kochkov Date: Thu, 2 Mar 2023 00:09:31 +0800 Subject: [PATCH 2/4] Remove use of rz_mem_swapendian() --- src/analysis_ghidra.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/analysis_ghidra.cpp b/src/analysis_ghidra.cpp index 6adeec69..59b21b09 100644 --- a/src/analysis_ghidra.cpp +++ b/src/analysis_ghidra.cpp @@ -2937,9 +2937,7 @@ static bool esil_peek_n(RzAnalysisEsil *esil, int bits) ut64 bitmask = genmask(bits - 1); ut8 a[sizeof(ut64)] = {0}; ret = !!rz_analysis_esil_mem_read(esil, addr, a, bytes); - ut64 b = rz_read_ble64(a, 0); // esil->analysis->big_endian); - if(esil->analysis->big_endian) - rz_mem_swapendian((ut8 *)&b, (const ut8 *)&b, bytes); + ut64 b = rz_read_ble64(a, esil->analysis->big_endian); snprintf(res, sizeof(res), "0x%" PFMT64x, b & bitmask); rz_analysis_esil_push(esil, res); From 9e07face23c0389a335fde6bed15ca4edf332f81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Sun, 2 Jul 2023 10:25:44 +0200 Subject: [PATCH 3/4] Update tests for latest rizin --- .gitignore | 1 + test/db/extras/analysis_ghidra | 46 +++++++++++++++++----------------- test/db/extras/ghidra | 32 +++++++++++------------ 3 files changed, 40 insertions(+), 39 deletions(-) diff --git a/.gitignore b/.gitignore index 9b0dca58..cf2ca2a4 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ ghidra/flex/ .ccls-cache .gdb_history .cache/ +.DS_Store diff --git a/test/db/extras/analysis_ghidra b/test/db/extras/analysis_ghidra index a5011e6b..1a28e6cc 100644 --- a/test/db/extras/analysis_ghidra +++ b/test/db/extras/analysis_ghidra @@ -83,91 +83,91 @@ e asm.bits wx 89e1 pdq 1 ao | grep type -?e ---- +echo ---- wx a168a00408 pdq 1 ao | grep type -?e ---- +echo ---- wx a368a00408 pdq 1 ao | grep type -?e ---- +echo ---- wx 8945f0 pdq 1 ao | grep type -?e ---- +echo ---- wx 8b4510 pdq 1 ao | grep type -?e ---- +echo ---- wx 0f4c0d03000000 pdq 1 ao | grep type -?e ---- +echo ---- wx cd80 pdq 1 ao | grep type -?e ---- +echo ---- wx 55 pdq 1 ao | grep type -?e ---- +echo ---- wx 6a00 pdq 1 ao | grep type -?e ---- +echo ---- wx 5d pdq 1 ao | grep type -?e ---- +echo ---- wx 83f853 pdq 1 ao | grep type -?e ---- +echo ---- wx 85c0 pdq 1 ao | grep type -?e ---- +echo ---- wx 83c410 pdq 1 ao | grep type -?e ---- +echo ---- wx 81ec88100000 pdq 1 ao | grep type -?e ---- +echo ---- wx f7ea pdq 1 ao | grep type -?e ---- +echo ---- wx f7f2 pdq 1 ao | grep type -?e ---- +echo ---- wx d1e8 pdq 1 ao | grep type -?e ---- +echo ---- wx d1e0 pdq 1 ao | grep type -?e ---- +echo ---- wx d1f8 pdq 1 ao | grep type -?e ---- +echo ---- wx 0b25f0ff0000 pdq 1 ao | grep type -?e ---- +echo ---- wx 2325f0ff0000 pdq 1 ao | grep type -?e ---- +echo ---- wx 3325f0ff0000 pdq 1 ao | grep type -?e ---- +echo ---- wx 8703 pdq 1 ao | grep type @@ -189,7 +189,7 @@ e asm.arch=ghidra wx 298947f9 pdq 1 ao | grep type -?e ---- +echo ---- wx 690200f9 @ 0x200 pdq 1 @ 0x200 ao @ 0x200| grep type diff --git a/test/db/extras/ghidra b/test/db/extras/ghidra index d75a90d5..8f64edf5 100644 --- a/test/db/extras/ghidra +++ b/test/db/extras/ghidra @@ -247,7 +247,7 @@ s sym.get_global_array_entry af e ghidra.rawptr=1 pdg -?e -- +echo -- e ghidra.rawptr=0 pdg EOF @@ -275,7 +275,7 @@ s sym.get_global_var af e ghidra.rawptr=1 pdg -?e -- +echo -- e ghidra.rawptr=0 pdg EOF @@ -315,15 +315,15 @@ s sym.get_global_var af e ghidra.rawptr=1 pdg -?e -- +echo -- e ghidra.rawptr=0 pdg -?e -- +echo -- s sym.get_global_array_entry af e ghidra.rawptr=1 pdg -?e -- +echo -- e ghidra.rawptr=0 pdg EOF @@ -2277,12 +2277,12 @@ afvs 4 bright BrightPtr afvs 8 argc "Bright *" afvs 12 argv "const char **" pdg -?e -- +echo -- afvs 4 bright "BrightTypedefd *" afvs 8 argc int32_t afvs 12 argv "const char **" pdg -?e -- +echo -- afvs 4 bright BrightTypedefdPtr pdg EOF @@ -2740,18 +2740,18 @@ s main af e scr.color=0 pdg -?e -- +echo -- pdgo -?e -- +echo -- pdg* -?e -- +echo -- pdgx~!id=, Date: Sun, 2 Jul 2023 10:27:10 +0200 Subject: [PATCH 4/4] Fix function name for realname enabled and multiple flags --- src/RizinScope.cpp | 3 ++- test/db/extras/ghidra | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/RizinScope.cpp b/src/RizinScope.cpp index 695e1dda..cf5882d6 100644 --- a/src/RizinScope.cpp +++ b/src/RizinScope.cpp @@ -122,7 +122,8 @@ FunctionSymbol *RizinScope::registerFunction(RzAnalysisFunction *fcn) const auto flag = reinterpret_cast(pos); if(flag->space && flag->space->name && !strcmp(flag->space->name, RZ_FLAGS_FS_SECTIONS)) continue; - if (flag->realname && *flag->realname) { + if(!strcmp(flag->name, fcn->name) && flag->realname && *flag->realname) + { fcn_name = flag->realname; break; } diff --git a/test/db/extras/ghidra b/test/db/extras/ghidra index 8f64edf5..8802cec2 100644 --- a/test/db/extras/ghidra +++ b/test/db/extras/ghidra @@ -3350,3 +3350,34 @@ undefined4 sym.ko_example_init(void) } EOF RUN + +NAME=realname and multiple flags at function +FILE=rizin-testbins/mach0/hello-macos-arm64-objc-stubs-stripped +CMDS=<