def get_header_data(self): self.imports = [] #: Types we have already inspected self.seen = set() #: List of structures, to patch .h later self.structs = set() # add missing #defines self.imports.append("#define __cdecl") nimps = idaapi.get_import_module_qty() for ordinal in range(0, nimps): idaapi.enum_import_names(ordinal, self.imp_cb) # Fix local types by iterating until all types are defined while self.add_types() > 0: pass class str_sink(idaapi.text_sink_t): """ Sink to get .h in a string """ def __init__(self): idaapi.text_sink_t.__init__(self) self.text = "" def _print(self, defstr): self.text += defstr return 0 def res(self): return self.text sink = str_sink() idaapi.print_decls( sink, idaapi.cvar.idati, [], idaapi.PDF_INCL_DEPS | idaapi.PDF_DEF_FWD | idaapi.PDF_DEF_BASE) # Generate fixed .h res = sink.res() for s in self.structs: if "struct " not in s: search = r"(^\s*(?:typedef )?)\b%s\b" % re.escape(s) res = re.sub(search, r"\1struct %s" % s, res, flags=re.MULTILINE) res += "\n\n" + "\n".join(self.imports) res = re.sub(r"__attribute__.*? ", " ", res) res = res.replace("$", "D_") res = res.replace("::", "__") return res
def format_local_type(ordinal=None, name=None, til=None): til, tif = get_local_type(ordinal, name, til) printer = Printer() idaapi.print_decls(printer, til, [tif.get_ordinal()], 0) #idaapi.PDF_INCL_DEPS | idaapi.PDF_DEF_FWD) lines = "".join(printer.lines[1:]).split('\n') lines = "\n".join(lines[1:]).rstrip( ) # This removes the prepended comment on all structs return lines
def local_type_info(): class my_sink(idaapi.text_sink_t): def __init__(self): try: idaapi.text_sink_t.__init__(self) except AttributeError: pass # Older IDA versions keep the text_sink_t abstract self.text = [] def _print(self, thing): self.text.append(thing) return 0 sink = my_sink() idaapi.print_decls(sink, idaapi.cvar.idati, [], idaapi.PDF_INCL_DEPS | idaapi.PDF_DEF_FWD) return sink.text
def local_type_info(): class my_sink(idaapi.text_sink_t): def __init__(self): try: idaapi.text_sink_t.__init__(self) except AttributeError: pass # Older IDA versions keep the text_sink_t abstract self.text = [] def _print(self, thing): self.text.append(thing) return 0 sink = my_sink() idaapi.print_decls(sink, idaapi.cvar.idati, [], idaapi.PDF_INCL_DEPS | idaapi.PDF_DEF_FWD) return sink.text
def PrintLocalTypes(ordinals, flags): # from lastest idapython """ Print types in a format suitable for use in a header file @param ordinals: comma-separated list of type ordinals @param flags: combination of PDF_... constants or 0 @return: string containing the type definitions """ class def_sink(idaapi.text_sink_t): def __init__(self): idaapi.text_sink_t.__init__(self) self.text = "" def _print(self, defstr): self.text += defstr return 0 sink = def_sink() py_ordinals = map(lambda l: int(l), ordinals.split(",")) idaapi.print_decls(sink, idaapi.cvar.idati, py_ordinals, flags) return sink.text
def PrintLocalTypes(ordinals, flags): # from lastest idapython """ Print types in a format suitable for use in a header file @param ordinals: comma-separated list of type ordinals @param flags: combination of PDF_... constants or 0 @return: string containing the type definitions """ class def_sink(idaapi.text_sink_t): def __init__(self): idaapi.text_sink_t.__init__(self) self.text = "" def _print(self, defstr): self.text += defstr return 0 sink = def_sink() py_ordinals = map(lambda l : int(l), ordinals.split(",")) idaapi.print_decls(sink, idaapi.cvar.idati, py_ordinals, flags) return sink.text
def local_types(): printer = Printer() idaapi.print_decls(printer, idaapi.cvar.idati, [], idaapi.PDF_INCL_DEPS | idaapi.PDF_DEF_FWD) return printer.lines
def local_types(): printer = Printer() idaapi.print_decls(printer, idaapi.cvar.idati, [], idaapi.PDF_INCL_DEPS | idaapi.PDF_DEF_FWD) return printer.lines