From 63b22d00d50c31f47d5dfe127ffc46b00bad077a Mon Sep 17 00:00:00 2001 From: "elias.bachaalany" Date: Fri, 17 Dec 2010 16:50:35 +0000 Subject: [PATCH] - Fixed issue 59 - Fixed idaapi.msg() / error() and warning() so they don't accept vararg - Fixed processor_t.id constants - idaapi.BasicBlock and FlowChart are now new-style classes --- python/idc.py | 2 +- swig/gdl.i | 47 ++++++++++++------- swig/kernwin.i | 25 +++++++++++ swig/typeinf.i | 2 +- swig/ua.i | 119 +++++++++++++++++++++++++------------------------ 5 files changed, 118 insertions(+), 77 deletions(-) diff --git a/python/idc.py b/python/idc.py index 58b6546..d00d86f 100644 --- a/python/idc.py +++ b/python/idc.py @@ -4113,7 +4113,7 @@ def ChooseFunction(title): @return: -1 - user refused to select a function otherwise returns the selected function start address """ - return idaapi.choose_func(title) + return idaapi.choose_func(title, idaapi.BADADDR) def GetFuncOffset(ea): diff --git a/swig/gdl.i b/swig/gdl.i index 9c0e10f..239b2c3 100644 --- a/swig/gdl.i +++ b/swig/gdl.i @@ -25,37 +25,43 @@ %pythoncode %{ # # ----------------------------------------------------------------------- -class BasicBlock: +class BasicBlock(object): """Basic block class. It is returned by the Flowchart class""" - def __init__(self, id, bb, f): - self._f = f + def __init__(self, id, bb, fc): + self._fc = fc + self.id = id """Basic block ID""" + self.startEA = bb.startEA """startEA of basic block""" + self.endEA = bb.endEA """endEA of basic block""" - self.type = self._f._q.calc_block_type(self.id) + + self.type = self._fc._q.calc_block_type(self.id) """Block type (check fc_block_type_t enum)""" + def preds(self): """ Iterates the predecessors list """ - q = self._f._q - for i in xrange(0, self._f._q.npred(self.id)): - yield self._f[q.pred(self.id, i)] + q = self._fc._q + for i in xrange(0, self._fc._q.npred(self.id)): + yield self._fc[q.pred(self.id, i)] + def succs(self): """ Iterates the successors list """ - q = self._f._q + q = self._fc._q for i in xrange(0, q.nsucc(self.id)): - yield self._f[q.succ(self.id, i)] + yield self._fc[q.succ(self.id, i)] # ----------------------------------------------------------------------- -class FlowChart: +class FlowChart(object): """ Flowchart class used to determine basic blocks. Check ex_gdl_qflow_chart.py for sample usage. @@ -67,25 +73,34 @@ class FlowChart: @param bounds: A tuple of the form (start, end). Used if "f" is None @param flags: one of the FC_xxxx flags. One interesting flag is FC_PREDS """ - if (not f) and (not bounds or type(bounds) != types.TupleType): + if (f is None) and (bounds is None or type(bounds) != types.TupleType): raise Exception("Please specifiy either a function or start/end pair") - if not bounds: + + if bounds is None: bounds = (BADADDR, BADADDR) - # create the flowchart + + # Create the flowchart self._q = qflow_chart_t("", f, bounds[0], bounds[1], flags) - self.size = self._q.size() + + size = property(lambda self: self._q.size()) + """Number of blocks in the flow chart""" + def refresh(): + """Refreshes the flow chart""" self._q.refresh() - self.size = self._q.size() + def __getitem__(self, index): """ Returns a basic block + @return: BasicBlock """ if index >= self.size: raise StopIteration - return BasicBlock(index, self._q[index], self) + else: + return BasicBlock(index, self._q[index], self) + # %} diff --git a/swig/kernwin.i b/swig/kernwin.i index e19672f..106cc0b 100644 --- a/swig/kernwin.i +++ b/swig/kernwin.i @@ -8,6 +8,16 @@ %ignore del_menu_item; %rename (del_menu_item) py_del_menu_item; %ignore vwarning; + +%ignore msg; +%rename (msg) py_msg; + +%ignore warning; +%rename (warning) py_warning; + +%ignore error; +%rename (error) py_error; + %ignore vinfo; %ignore vnomem; %ignore vmsg; @@ -61,6 +71,21 @@ %rename (_askseg) askseg; %inline %{ +int py_msg(const char *format) +{ + return msg("%s", format); +} + +void py_warning(const char *format) +{ + warning("%s", format); +} + +void py_error(const char *format) +{ + error("%s", format); +} + void refresh_lists(void) { callui(ui_list); diff --git a/swig/typeinf.i b/swig/typeinf.i index 10b6da3..027b04c 100644 --- a/swig/typeinf.i +++ b/swig/typeinf.i @@ -388,7 +388,7 @@ def pack_object_to_bv(obj, ti, tp, fields, base_ea, pio_flags = 0): @param fields: type fields @param base_ea: base ea used to relocate the pointers in the packed object @param pio_flags: flags used while unpacking - @return: + @return: tuple(0, err_code) on failure tuple(1, packed_buf) on success """ diff --git a/swig/ua.i b/swig/ua.i index b27b7ca..36e1fe9 100644 --- a/swig/ua.i +++ b/swig/ua.i @@ -1101,65 +1101,66 @@ OP_SP_ADD = 0x00000000 # operand value is added to the pointer OP_SP_SUB = 0x00000002 # operand value is substracted from the pointer # processor_t.id -PLFM_386 = 0x0 # Intel 80x86 -PLFM_Z80 = 0x1 # 8085, Z80 -PLFM_I860 = 0x2 # Intel 860 -PLFM_8051 = 0x3 # 8051 -PLFM_TMS = 0x4 # Texas Instruments TMS320C5x -PLFM_6502 = 0x5 # 6502 -PLFM_PDP = 0x6 # PDP11 -PLFM_68K = 0x7 # Motoroal 680x0 -PLFM_JAVA = 0x8 # Java -PLFM_6800 = 0x9 # Motorola 68xx -PLFM_ST7 = 0x10 # SGS-Thomson ST7 -PLFM_MC6812 = 0x11 # Motorola 68HC12 -PLFM_MIPS = 0x12 # MIPS -PLFM_ARM = 0x13 # Advanced RISC Machines -PLFM_TMSC6 = 0x14 # Texas Instruments TMS320C6x -PLFM_PPC = 0x15 # PowerPC -PLFM_80196 = 0x16 # Intel 80196 -PLFM_Z8 = 0x17 # Z8 -PLFM_SH = 0x18 # Renesas (formerly Hitachi) SuperH -PLFM_NET = 0x19 # Microsoft Visual Studio.Net -PLFM_AVR = 0x20 # Atmel 8-bit RISC processor(s) -PLFM_H8 = 0x21 # Hitachi H8/300, H8/2000 -PLFM_PIC = 0x22 # Microchip's PIC -PLFM_SPARC = 0x23 # SPARC -PLFM_ALPHA = 0x24 # DEC Alpha -PLFM_HPPA = 0x25 # Hewlett-Packard PA-RISC -PLFM_H8500 = 0x26 # Hitachi H8/500 -PLFM_TRICORE = 0x27 # Tasking Tricore -PLFM_DSP56K = 0x28 # Motorola DSP5600x -PLFM_C166 = 0x29 # Siemens C166 family -PLFM_ST20 = 0x30 # SGS-Thomson ST20 -PLFM_IA64 = 0x31 # Intel Itanium IA64 -PLFM_I960 = 0x32 # Intel 960 -PLFM_F2MC = 0x33 # Fujistu F2MC-16 -PLFM_TMS320C54 = 0x34 # Texas Instruments TMS320C54xx -PLFM_TMS320C55 = 0x35 # Texas Instruments TMS320C55xx -PLFM_TRIMEDIA = 0x36 # Trimedia -PLFM_M32R = 0x37 # Mitsubishi 32bit RISC -PLFM_NEC_78K0 = 0x38 # NEC 78K0 -PLFM_NEC_78K0S = 0x39 # NEC 78K0S -PLFM_M740 = 0x40 # Mitsubishi 8bit -PLFM_M7700 = 0x41 # Mitsubishi 16bit -PLFM_ST9 = 0x42 # ST9+ -PLFM_FR = 0x43 # Fujitsu FR Family -PLFM_MC6816 = 0x44 # Motorola 68HC16 -PLFM_M7900 = 0x45 # Mitsubishi 7900 -PLFM_TMS320C3 = 0x46 # Texas Instruments TMS320C3 -PLFM_KR1878 = 0x47 # Angstrem KR1878 -PLFM_AD218X = 0x48 # Analog Devices ADSP 218X -PLFM_OAKDSP = 0x49 # Atmel OAK DSP -PLFM_TLCS900 = 0x50 # Toshiba TLCS-900 -PLFM_C39 = 0x51 # Rockwell C39 -PLFM_CR16 = 0x52 # NSC CR16 -PLFM_MN102L00 = 0x53 # Panasonic MN10200 -PLFM_TMS320C1X = 0x54 # Texas Instruments TMS320C1x -PLFM_NEC_V850X = 0x55 # NEC V850 and V850ES/E1/E2 -PLFM_SCR_ADPT = 0x56 # Processor module adapter for processor modules written in scripting languages -PLFM_EBC = 0x57 # EFI Bytecode -PLFM_MSP430 = 0x58 # Texas Instruments MSP430 +PLFM_386 = 0 # Intel 80x86 +PLFM_Z80 = 1 # 8085, Z80 +PLFM_I860 = 2 # Intel 860 +PLFM_8051 = 3 # 8051 +PLFM_TMS = 4 # Texas Instruments TMS320C5x +PLFM_6502 = 5 # 6502 +PLFM_PDP = 6 # PDP11 +PLFM_68K = 7 # Motoroal 680x0 +PLFM_JAVA = 8 # Java +PLFM_6800 = 9 # Motorola 68xx +PLFM_ST7 = 10 # SGS-Thomson ST7 +PLFM_MC6812 = 11 # Motorola 68HC12 +PLFM_MIPS = 12 # MIPS +PLFM_ARM = 13 # Advanced RISC Machines +PLFM_TMSC6 = 14 # Texas Instruments TMS320C6x +PLFM_PPC = 15 # PowerPC +PLFM_80196 = 16 # Intel 80196 +PLFM_Z8 = 17 # Z8 +PLFM_SH = 18 # Renesas (formerly Hitachi) SuperH +PLFM_NET = 19 # Microsoft Visual Studio.Net +PLFM_AVR = 20 # Atmel 8-bit RISC processor(s) +PLFM_H8 = 21 # Hitachi H8/300, H8/2000 +PLFM_PIC = 22 # Microchip's PIC +PLFM_SPARC = 23 # SPARC +PLFM_ALPHA = 24 # DEC Alpha +PLFM_HPPA = 25 # Hewlett-Packard PA-RISC +PLFM_H8500 = 26 # Hitachi H8/500 +PLFM_TRICORE = 27 # Tasking Tricore +PLFM_DSP56K = 28 # Motorola DSP5600x +PLFM_C166 = 29 # Siemens C166 family +PLFM_ST20 = 30 # SGS-Thomson ST20 +PLFM_IA64 = 31 # Intel Itanium IA64 +PLFM_I960 = 32 # Intel 960 +PLFM_F2MC = 33 # Fujistu F2MC-16 +PLFM_TMS320C54 = 34 # Texas Instruments TMS320C54xx +PLFM_TMS320C55 = 35 # Texas Instruments TMS320C55xx +PLFM_TRIMEDIA = 36 # Trimedia +PLFM_M32R = 37 # Mitsubishi 32bit RISC +PLFM_NEC_78K0 = 38 # NEC 78K0 +PLFM_NEC_78K0S = 39 # NEC 78K0S +PLFM_M740 = 40 # Mitsubishi 8bit +PLFM_M7700 = 41 # Mitsubishi 16bit +PLFM_ST9 = 42 # ST9+ +PLFM_FR = 43 # Fujitsu FR Family +PLFM_MC6816 = 44 # Motorola 68HC16 +PLFM_M7900 = 45 # Mitsubishi 7900 +PLFM_TMS320C3 = 46 # Texas Instruments TMS320C3 +PLFM_KR1878 = 47 # Angstrem KR1878 +PLFM_AD218X = 48 # Analog Devices ADSP 218X +PLFM_OAKDSP = 49 # Atmel OAK DSP +PLFM_TLCS900 = 50 # Toshiba TLCS-900 +PLFM_C39 = 51 # Rockwell C39 +PLFM_CR16 = 52 # NSC CR16 +PLFM_MN102L00 = 53 # Panasonic MN10200 +PLFM_TMS320C1X = 54 # Texas Instruments TMS320C1x +PLFM_NEC_V850X = 55 # NEC V850 and V850ES/E1/E2 +PLFM_SCR_ADPT = 56 # Processor module adapter for processor modules written in scripting languages +PLFM_EBC = 57 # EFI Bytecode +PLFM_MSP430 = 58 # Texas Instruments MSP430 +PLFM_SPU = 59 # Cell Broadband Engine Synergistic Processor Unit # # processor_t.flag