def get_data(segs, cpp_in): '''[str] -> str -> [c_ast]''' def gen(((ti, ea, declstr), node)): '''(tinfo_t, ea_t) -> c_ast''' # NOTE mutates node has_data = ida.seg_name(ea) != '.bss' ptr = ida.can_be_off32(ea) if ptr not in [ida.BADADDR, 0]: ptr_ti = ida.get_or_guess_tinfo(ptr) ti_node = cdecl.get_decls(declstr).decls[utils.cpp_decomp_tag][0] return gen(((ptr_ti, ptr, ''), ti_node)) # XXX our data segment has no strings, but that's probably specific to # the one binary we're dealing with elif ti.is_array(): ai = ida.array_type_data_t() ti.get_array_details(ai) item_size = ai.elem_type.get_size() typename = get_type_for_c_ast_constant(ai.elem_type) length = (ida.item_end(ea) - ida.item_head(ea)) / item_size if has_data is True: if ai.elem_type.is_char(): node.init = ep_ct.constant(typename, c_stringify( ida.get_string(ea))) else: items = list(get_item(ea + j * item_size, ti) for j in xrange(0, length)) node.init = ep_ct.initlist( [ep_ct.constant(typename, str(x)) for x in items]) else: if has_data is True: typename = get_type_for_c_ast_constant(ti) node.init = ep_ct.constant(typename, str(get_item(ea, ti))) return node
def get_num(ea): ti = ida.get_or_guess_tinfo(ea) return get_item(ea, ti)
def get_tinfo_and_declstr(ea): ti = ida.get_or_guess_tinfo(ea) return (ti, ea, ida.print_tinfo(ida.name(ea), ti))