From bd687bb226acb43e727fa40a4b17cf64e5a1a2c0 Mon Sep 17 00:00:00 2001 From: Anton Kochkov Date: Wed, 31 Mar 2021 17:16:21 +0800 Subject: [PATCH] Fix endianess for RzTypes --- librz/analysis/analysis.c | 1 + librz/core/cconfig.c | 2 ++ librz/include/rz_type.h | 1 + librz/type/type.c | 4 ++++ 4 files changed, 8 insertions(+) diff --git a/librz/analysis/analysis.c b/librz/analysis/analysis.c index 1cea1b75ea2..ba87ed171d7 100644 --- a/librz/analysis/analysis.c +++ b/librz/analysis/analysis.c @@ -304,6 +304,7 @@ RZ_API int rz_analysis_set_big_endian(RzAnalysis *analysis, int bigend) { if (analysis->reg) { analysis->reg->big_endian = bigend; } + rz_type_db_set_endian(analysis->typedb, bigend); return true; } diff --git a/librz/core/cconfig.c b/librz/core/cconfig.c index 023fc43dd6e..5137863d0aa 100644 --- a/librz/core/cconfig.c +++ b/librz/core/cconfig.c @@ -695,6 +695,8 @@ static bool cb_asmarch(void *user, void *data) { if (!core->analysis || !core->analysis->typedb) { rz_core_analysis_type_init(core); } + // set endian of RzAnalysis to match binary + rz_analysis_set_big_endian(core->analysis, bigbin); rz_core_analysis_cc_init(core); return true; diff --git a/librz/include/rz_type.h b/librz/include/rz_type.h index b92b9f09cf8..a06427fcde1 100644 --- a/librz/include/rz_type.h +++ b/librz/include/rz_type.h @@ -97,6 +97,7 @@ RZ_API void rz_type_db_purge(RzTypeDB *typedb); RZ_API void rz_type_db_set_bits(RzTypeDB *typedb, int bits); RZ_API void rz_type_db_set_os(RzTypeDB *typedb, const char *os); RZ_API void rz_type_db_set_cpu(RzTypeDB *typedb, const char *cpu); +RZ_API void rz_type_db_set_endian(RzTypeDB *typedb, bool big_endian); RZ_API char *rz_type_db_kuery(RzTypeDB *typedb, const char *query); RZ_API const char *rz_type_db_get(RzTypeDB *typedb, const char *name); diff --git a/librz/type/type.c b/librz/type/type.c index 6a6e0f5b762..a1e14393246 100644 --- a/librz/type/type.c +++ b/librz/type/type.c @@ -63,6 +63,10 @@ RZ_API void rz_type_db_set_cpu(RzTypeDB *typedb, const char *cpu) { typedb->target->cpu = cpu; } +RZ_API void rz_type_db_set_endian(RzTypeDB *typedb, bool big_endian) { + typedb->target->big_endian = big_endian; +} + RZ_API char *rz_type_db_kuery(RzTypeDB *typedb, const char *query) { char *output = NULL; if (query) {