6 #define GO_MAX_STRING_SIZE 0x4000
12 #define IS_GOPCLNTAB_1_2_LE(x) (x[0] == 0xfb && x[1] == 0xff && x[2] == 0xff && x[3] == 0xff)
13 #define IS_GOPCLNTAB_1_2_BE(x) (x[3] == 0xfb && x[2] == 0xff && x[1] == 0xff && x[0] == 0xff)
14 #define IS_GOPCLNTAB_1_16_LE(x) (x[0] == 0xfa && x[1] == 0xff && x[2] == 0xff && x[3] == 0xff)
15 #define IS_GOPCLNTAB_1_16_BE(x) (x[3] == 0xfa && x[2] == 0xff && x[1] == 0xff && x[0] == 0xff)
16 #define IS_GOPCLNTAB_1_18_LE(x) (x[0] == 0xf0 && x[1] == 0xff && x[2] == 0xff && x[3] == 0xff)
17 #define IS_GOPCLNTAB_1_18_BE(x) (x[3] == 0xf0 && x[2] == 0xff && x[1] == 0xff && x[0] == 0xff)
103 #define is_addr_outside(x) ((x) <= begin || (x) >= end)
134 #undef is_addr_outside
151 RZ_LOG_ERROR(
"Failed append new go symbol to symbols list\n");
155 if (!strcmp(
name,
"main.main")) {
166 ut64 func_ptr = 0, func_off = 0, name_ptr = 0, name_off = 0;
230 rz_flag_space_pop(core->
flags);
241 ut64 func_ptr = 0, func_off = 0, name_ptr = 0, name_off = 0;
306 rz_flag_space_pop(core->
flags);
318 ut64 func_ptr = 0, func_off = 0, name_ptr = 0, name_off = 0;
363 name_ptr = pclntab->
vaddr + func_off + pclntab->
ptrsize;
393 rz_flag_space_pop(core->
flags);
422 (!strcmp(
section->name,
".text") || strstr(
section->name,
"__text"))) {
427 if (!pclntab.
vaddr) {
429 rz_list_foreach (symbols_list,
iter, symbol) {
431 if (symbol->
size >= 16 && !strcmp(symbol->
name,
"gopclntab")) {
439 if (!pclntab.
vaddr) {
452 pclntab.
io = core->
io;
520 RZ_LOG_ERROR(
"Failed append new go string to strings database\n");
539 const size_t n_prefix = strlen(
"str.");
541 char *flag =
malloc(str_size + n_prefix + 1);
542 char *raw =
malloc(str_size + 1);
555 flag[str_size + 4] = 0;
568 memcpy(flag + n_prefix, raw, str_size);
592 rz_flag_space_pop(
ctx->core->flags);
604 for (
size_t i = 0;
i < n_sigs; ++
i) {
605 if (nlen >=
ctx->size) {
621 copy[j] = copy[j] & sig->
pasm->
mask[j];
657 #define go_is_sign_match_autosize(ctx, info, sigs) go_is_sign_match(ctx, info, sigs, RZ_ARRAY_SIZE(sigs))
658 #define go_asm_pattern_name(arch, bits, mnemonic) go_##arch##_##bits##_##mnemonic
659 #define go_asm_pattern_define(arch, bits, mnemonic, pattern, mask, set_xref) \
660 static GoAsmPattern go_asm_pattern_name(arch, bits, mnemonic) = { (const ut8 *)pattern, (const ut8 *)mask, (sizeof(pattern) - 1), set_xref }
1615 rz_core_notify_begin(core,
"Analyze all instructions to recover all strings used in sym.go.*");
1628 if (!strcmp(asm_arch,
"x86")) {
1639 }
else if (!strcmp(asm_arch,
"arm")) {
1650 }
else if (!strcmp(asm_arch,
"mips")) {
1661 }
else if (!strcmp(asm_arch,
"riscv")) {
1669 }
else if (!strcmp(asm_arch,
"ppc")) {
1677 }
else if (!strcmp(asm_arch,
"sysz")) {
1681 rz_core_notify_done(core,
"Analyze all instructions to recover all strings used in sym.go.*");
1686 rz_core_notify_error(core,
"Cannot resolve go strings because arch '%s:%u' is not supported.", asm_arch, asm_bits);
1694 rz_list_foreach (func->
bbs, it2, block) {
1697 RZ_LOG_ERROR(
"Failed allocate basic block bytes buffer\n");
1711 i +=
RZ_MAX(nlen, min_op_size);
1717 rz_core_notify_done(core,
"Analyze all instructions to recover all strings used in sym.go.*");
RZ_API int rz_analysis_archinfo(RzAnalysis *analysis, int query)
static RzILOpEffect * ldr(cs_insn *insn, bool is_thumb)
static RzILOpEffect * mov(cs_insn *insn, bool is_thumb)
static ut32 adrp(ArmOp *op, ut64 addr, ut32 k)
RZ_API RzBinObject * rz_bin_cur_object(RzBin *bin)
RZ_API RzBinSymbol * rz_bin_symbol_new(const char *name, ut64 paddr, ut64 vaddr)
RZ_API void rz_bin_symbol_free(RzBinSymbol *sym)
RZ_API void rz_bin_string_free(void *_str)
RZ_DEPRECATE RZ_API RZ_BORROW RzList * rz_bin_get_symbols(RZ_NONNULL RzBin *bin)
RZ_API RZ_BORROW RzBinSection * rz_bin_get_section_at(RzBinObject *o, ut64 off, int va)
Find the binary section at offset off.
RZ_API RzBinFile * rz_bin_cur(RzBin *bin)
RZ_DEPRECATE RZ_API RZ_BORROW RzList * rz_bin_get_sections(RZ_NONNULL RzBin *bin)
RzBinInfo * info(RzBinFile *bf)
RZ_API RZ_BORROW RzBinString * rz_bin_object_get_string_at(RZ_NONNULL RzBinObject *obj, ut64 address, bool is_va)
Return RzBinString if at address there is an entry in the RzBinObject string database.
RZ_API const RzList * rz_bin_object_get_strings(RZ_NONNULL RzBinObject *obj)
Get list of RzBinString representing the strings identified in the binary object.
RZ_API bool rz_bin_string_database_add(RZ_NONNULL RzBinStrDb *db, RZ_NONNULL RzBinString *bstr)
{ function_description }
RZ_API int rz_core_cmd0(RzCore *core, const char *cmd)
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
RZ_API RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
RZ_API bool rz_cons_is_breaked(void)
static GoSignature go_ppcle64_li_std_lis_addi_signature[]
static bool decode_from_table(RzCore *core, GoStrInfo *info, ut64 pc, const ut8 *buffer, const ut32 size)
#define IS_GOPCLNTAB_1_2_LE(x)
static bool decode_val_set_size(RzCore *core, GoStrInfo *info, ut64 pc, const ut8 *buffer, const ut32 size)
static GoSignature go_x64_mov3_lea_signature[]
static GoSignature go_x64_lea_mov2_signature[]
static GoSignature go_ppcbe64_lis_addi_std_li_signature[]
#define IS_GOPCLNTAB_1_16_BE(x)
#define go_asm_pattern_name(arch, bits, mnemonic)
static GoSignature go_ppcle64_lis_addi_li_signature[]
static GoSignature go_arm64_adrp_add_str_movz_signature[]
static GoSignature go_riscv64_li_sd_auipc_add_signature[]
ut64 go_data(GoPcLnTab *pclntab, ut32 n_word)
struct go_pc_line_table_t GoPcLnTab
static bool recover_string_at(GoStrRecover *ctx, ut64 str_addr, ut64 str_size)
static ut32 decode_one_opcode_size(GoStrRecover *ctx)
static ut32 core_recover_golang_functions_go_1_2(RzCore *core, GoPcLnTab *pclntab)
#define IS_GOPCLNTAB_1_18_BE(x)
static GoSignature go_mipsbe32_table_signature[]
static GoSignature go_ppcbe64_li_std_lis_addi_signature[]
#define GO_MAX_STRING_SIZE
RZ_API bool rz_core_analysis_recover_golang_functions(RzCore *core)
reads pclntab table in go binaries and recovers functions. Follows the code https://github....
static bool go_is_sign_match(GoStrRecover *ctx, GoStrInfo *info, GoSignature *sigs, const size_t n_sigs)
static GoSignature go_mipsle64_daddiu_sd_lui_daddu_daddiu_signature[]
static GoSignature go_mipsle32_table_signature[]
static GoSignature go_mipsle64_table_signature[]
static GoSignature go_arm64_movz_str_adrp_add_signature[]
static GoSignature go_ppcbe64_table_signature[]
static GoSignature go_mipsbe64_lui_daddu_daddiu_daddiu_signature[]
static GoSignature go_mipsle64_lui_daddu_daddiu_sd_daddiu_signature[]
static GoSignature go_arm32_ldr_mov_signature[]
static GoSignature go_x86_table_signature[]
static GoSignature go_arm64_adrp_add_movz_signature[]
static GoSignature go_x64_lea_mov1_mov_signature[]
ut64 go_uintptr(GoPcLnTab *pclntab, ut8 *bytes)
RZ_API void rz_core_analysis_resolve_golang_strings(RzCore *core)
Attempts to recover all golang string.
static GoSignature go_mipsle32_lui_addiu_sw_addiu_signature[]
static ut32 golang_recover_string_arm64(GoStrRecover *ctx)
static GoSignature go_mipsbe32_addiu_sw_lui_addiu_signature[]
static ut32 golang_recover_string_arm32(GoStrRecover *ctx)
struct go_asm_pattern_t GoAsmPattern
static GoSignature go_x64_table1_signature[]
static GoSignature go_mipsle32_addiu_sw_lui_addiu_signature[]
ut64 go_offset(GoPcLnTab *pclntab, ut32 n_word)
static ut32 golang_recover_string_ppc64(GoStrRecover *ctx)
static GoSignature go_mipsle32_lui_addiu_addiu_signature[]
static GoSignature go_x64_table0_signature[]
static GoSignature go_x64_lea_mov3_signature[]
static GoSignature go_x64_mov1_lea_signature[]
struct go_string_info_t GoStrInfo
#define is_addr_outside(x)
static GoSignature go_mipsle64_lui_daddu_daddiu_daddiu_signature[]
static ut32 core_recover_golang_functions_go_1_18(RzCore *core, GoPcLnTab *pclntab)
#define go_is_sign_match_autosize(ctx, info, sigs)
static GoSignature go_riscv64_table_signature[]
static ut32 golang_recover_string_mips64(GoStrRecover *ctx)
ut32 go_func_tab_field_size(GoPcLnTab *pclntab)
static GoSignature go_riscv64_auipc_add_addiw_signature[]
static GoSignature go_arm64_table_signature[]
static GoSignature go_mipsbe32_lui_addiu_sw_addiu_signature[]
static GoSignature go_mipsbe32_lui_addiu_addiu_signature[]
static GoSignature go_mipsbe64_lui_daddu_daddiu_sd_daddiu_signature[]
static GoSignature go_x86_lea_mov0_mov_signature[]
static bool decode_disp_set_addr(RzCore *core, GoStrInfo *info, ut64 pc, const ut8 *buffer, const ut32 size)
static GoSignature go_x64_lea_mov0_mov_signature[]
static bool decode_lui_set_addr(RzCore *core, GoStrInfo *info, ut64 pc, const ut8 *buffer, const ut32 size)
static ut32 core_recover_golang_functions_go_1_16(RzCore *core, GoPcLnTab *pclntab)
static GoSignature go_ppcle64_lis_addi_std_li_signature[]
#define go_asm_pattern_define(arch, bits, mnemonic, pattern, mask, set_xref)
static GoSignature go_ppcbe64_lis_addi_li_signature[]
static bool add_new_bin_string(RzCore *core, char *string, ut64 vaddr, ut32 size)
static GoSignature go_x86_lea_mov1_signature[]
static bool decode_auipc_set_addr(RzCore *core, GoStrInfo *info, ut64 pc, const ut8 *buffer, const ut32 size)
static GoSignature go_arm32_mov_str_ldr_signature[]
static GoSignature go_x64_lea_mov0_signature[]
ut32(* GoStrRecoverCb)(GoStrRecover *ctx)
static GoSignature go_x86_lea_mov1_mov_signature[]
static bool decode_ldr_set_addr(RzCore *core, GoStrInfo *info, ut64 pc, const ut8 *buffer, const ut32 size)
static GoSignature go_mipsbe64_daddiu_sd_lui_daddu_daddiu_signature[]
static GoSignature go_riscv64_addiw_sd_auipc_add_signature[]
bool(* GoDecodeCb)(RzCore *core, GoStrInfo *info, ut64 pc, const ut8 *buffer, const ut32 size)
static GoSignature go_riscv64_auipc_add_li_signature[]
static GoSignature go_x64_mov2_lea_signature[]
static GoSignature go_arm64_orr_str_adrp_add_signature[]
struct go_string_recover_t GoStrRecover
static bool decode_val_add_addr(RzCore *core, GoStrInfo *info, ut64 pc, const ut8 *buffer, const ut32 size)
static GoSignature go_arm64_adrp_add_orr_signature[]
static GoSignature go_x64_mov0_lea_signature[]
struct go_signature_t GoSignature
static void add_new_func_symbol(RzCore *core, const char *name, ut64 vaddr)
static GoSignature go_arm64_adrp_add_str_orr_signature[]
#define IS_GOPCLNTAB_1_2_BE(x)
static ut32 golang_recover_string_riscv64(GoStrRecover *ctx)
static bool decode_val_set_addr(RzCore *core, GoStrInfo *info, ut64 pc, const ut8 *buffer, const ut32 size)
static GoSignature go_arm32_table_signature[]
static ut32 golang_recover_string_mips32(GoStrRecover *ctx)
static GoSignature go_ppcle64_table_signature[]
static GoSignature go_x64_lea_mov1_signature[]
static GoSignature go_riscv64_auipc_add_sd_addiw_signature[]
static bool is_pclntab_valid(GoPcLnTab *pclntab)
#define IS_GOPCLNTAB_1_18_LE(x)
#define IS_GOPCLNTAB_1_16_LE(x)
static ut32 golang_recover_string_x86(GoStrRecover *ctx)
static GoSignature go_mipsbe64_table_signature[]
static GoSignature go_x86_mov_lea_signature[]
static bool decode_ptr_set_addr(RzCore *core, GoStrInfo *info, ut64 pc, const ut8 *buffer, const ut32 size)
static GoSignature go_riscv64_auipc_add_sd_li_signature[]
static GoSignature go_arm32_ldr_str_mov_signature[]
static GoSignature go_x86_lea_mov0_signature[]
static ut32 golang_recover_string_x64(GoStrRecover *ctx)
checking print the parsed form of the magic use in n conjunction with m to debug a new magic file n before installing it n output MIME type strings(--mime-type and\n"
" --mime-encoding)\n") OPT('s'
RZ_API bool rz_flag_unset_all_off(RzFlag *f, ut64 off)
RZ_API RzFlagItem * rz_flag_set(RzFlag *f, const char *name, ut64 off, ut32 size)
RZ_API void Ht_() free(HtName_(Ht) *ht)
return memset(p, 0, total)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
RZ_API void rz_core_notify_begin(RZ_NONNULL RzCore *core, RZ_NONNULL const char *format,...)
Prints a message definining the beginning of a task.
RZ_API void rz_core_notify_done(RZ_NONNULL RzCore *core, RZ_NONNULL const char *format,...)
Prints a message definining the end of a task which succeeded.
RZ_API void rz_core_notify_error(RZ_NONNULL RzCore *core, RZ_NONNULL const char *format,...)
Prints a message definining the end of a task which errored.
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
void * malloc(size_t size)
#define header(is_bt, len_min, ret_op)
RZ_API bool rz_analysis_op_fini(RzAnalysisOp *op)
RZ_API void rz_analysis_op_init(RzAnalysisOp *op)
RZ_API int rz_analysis_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *data, int len, RzAnalysisOpMask mask)
@ RZ_ANALYSIS_XREF_TYPE_STRING
@ RZ_ANALYSIS_OP_MASK_DISASM
#define RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE
#define rz_return_if_fail(expr)
#define rz_return_val_if_fail(expr, val)
#define RZ_BIN_BIND_GLOBAL_STR
#define RZ_BIN_TYPE_FUNC_STR
#define RZ_FLAGS_FS_STRINGS
#define RZ_FLAGS_FS_SYMBOLS
static ut64 rz_read_ble64(const void *src, bool big_endian)
static ut32 rz_read_ble32(const void *src, bool big_endian)
static ut64 rz_read_ble(const void *src, bool big_endian, int size)
static ut32 rz_read_be32(const void *src)
RZ_API ut64 rz_io_v2p(RzIO *io, ut64 va)
RZ_API int rz_io_nread_at(RzIO *io, ut64 addr, ut8 *buf, int len)
#define RZ_LOG_INFO(fmtstr,...)
#define RZ_LOG_ERROR(fmtstr,...)
RZ_API bool rz_name_filter(char *name, int len, bool strict)
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API size_t rz_str_len_utf8_ansi(const char *str)
#define rz_strf(buf,...)
Convenience macro for local temporary strings.
XX curplugin == o->plugin.
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
RZ_API bool rz_analysis_xrefs_set(RzAnalysis *analysis, ut64 from, ut64 to, RzAnalysisXRefType type)