From aea22bcd6d85d862fb2db889fcb13beb2cecd5e9 Mon Sep 17 00:00:00 2001 From: Jonas Zaddach Date: Mon, 2 Mar 2020 19:36:51 +0100 Subject: [PATCH] Update to Python3 --- GO_Utils/Firstmoduledata.py | 4 ++-- GO_Utils/GoStrings.py | 4 ++-- GO_Utils/Gopclntab.py | 4 ++-- GO_Utils/Types.py | 20 ++++++++++---------- GO_Utils/Utils.py | 12 ++++++------ GO_Utils/__init__.py | 16 ++++++++-------- go_entry.py | 6 +++--- 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/GO_Utils/Firstmoduledata.py b/GO_Utils/Firstmoduledata.py index 3c2603e..02cbe5e 100644 --- a/GO_Utils/Firstmoduledata.py +++ b/GO_Utils/Firstmoduledata.py @@ -1,4 +1,4 @@ -import Utils +from . import Utils import idautils import struct @@ -155,4 +155,4 @@ def getTypeinfo(addr, bt): next *moduledata } -""" \ No newline at end of file +""" diff --git a/GO_Utils/GoStrings.py b/GO_Utils/GoStrings.py index 655a24e..659940a 100644 --- a/GO_Utils/GoStrings.py +++ b/GO_Utils/GoStrings.py @@ -41,7 +41,7 @@ def is_this_a_real_string(next_pos, instr, size_data): return False, 0 def make_string(addr, siz): - print "Creating string at %x %d size" % (addr, siz) + print("Creating string at %x %d size" % (addr, siz)) idc.MakeUnknown(addr, siz, idc.DOUNK_SIMPLE) ida_bytes.create_strlit(addr, siz, -1) @@ -60,7 +60,7 @@ def stringify(): while position < f.endEA: instr = idautils.DecodeInstruction(position) if instr is None: - print "%x: Not and instruction found" % position + print("%x: Not and instruction found" % position) break mnem = instr.get_canon_mnem() if mnem == "mov": diff --git a/GO_Utils/Gopclntab.py b/GO_Utils/Gopclntab.py index daf723f..adb88b2 100644 --- a/GO_Utils/Gopclntab.py +++ b/GO_Utils/Gopclntab.py @@ -5,7 +5,7 @@ import ida_funcs import ida_search import ida_segment -import Utils +from . import Utils info = idaapi.get_inf_structure() try: @@ -43,7 +43,7 @@ def rename(beg, ptr, make_funcs = True): size = ptr.ptr(pos) pos += ptr.size end = pos + (size * ptr.size * 2) - print "%x" % end + print("%x" % end) while pos < end: offset = ptr.ptr(pos + ptr.size) ptr.maker(pos) #in order to get xrefs diff --git a/GO_Utils/Types.py b/GO_Utils/Types.py index 3b99ee0..13ea4e5 100644 --- a/GO_Utils/Types.py +++ b/GO_Utils/Types.py @@ -1,4 +1,4 @@ -import Utils +from . import Utils import ida_bytes import ida_struct import idc @@ -315,7 +315,7 @@ def handle_offset(self, offset): #Check if we already parse this if offset in self.type_addr: return - print "Processing: %x" % offset + print("Processing: %x" % offset) self.type_addr.append(offset) #Set type and get name @@ -325,7 +325,7 @@ def handle_offset(self, offset): #get kind name kind_name = self.getKindEnumName(offset) - print kind_name + print(kind_name) if name[0] == "*" and kind_name != "PTR": name = name[1:] name = Utils.relaxName(name) @@ -427,7 +427,7 @@ def createUserTypeStruct(self, addr, name, size, self_size): fieldname = "unused_"+Utils.id_generator() offset = self.getStructFieldOffset(sid, addr+i*sz) if offset != curr_offset: - print "Offset missmatch.Got %d expected %d. Adding padding..." % (curr_offset, offset) + print("Offset missmatch.Got %d expected %d. Adding padding..." % (curr_offset, offset)) if offset < curr_offset: raise("Too many bytes already") while offset != curr_offset: @@ -437,14 +437,14 @@ def createUserTypeStruct(self, addr, name, size, self_size): if size != 0: offset_kind = idc.get_member_offset(sid_type, "kind") kind_of_type = self.getKindEnumName(type_addr) - print kind_of_type + print(kind_of_type) if kind_of_type == "STRUCT_": #Disabled for now name_type = self.getName(type_addr) while name_type[0] == "*": name_type = name_type[1:] name_type = Utils.relaxName(name_type) name_type = "ut_" + name_type - #print "setting type %s" % name_type + #print("setting type %s" % name_type) fields.append((fieldname, name_type)) elif kind_of_type == "STRING": fields.append((fieldname, "string")) @@ -455,7 +455,7 @@ def createUserTypeStruct(self, addr, name, size, self_size): else: fields.append((fieldname, "char [%d]" % size)) if curr_offset != self_size: - print "%x: Structure size mismatch: %x" % (addr, curr_offset) + print("%x: Structure size mismatch: %x" % (addr, curr_offset)) if self_size < curr_offset: raise("Too many bytes already") while self_size != curr_offset: @@ -466,11 +466,11 @@ def createUserTypeStruct(self, addr, name, size, self_size): new_type_sid = ida_struct.get_struc_id(name) sz = ida_struct.get_struc_size(new_type_sid) if sz != self_size: - print "%x" % addr + print("%x" % addr ) raise("Error at creating structure") def getType(self, addr): - print "%x" % addr + print("%x" % addr) sid = ida_struct.get_struc_id("type") name = self.getName(addr) if self.getKindEnumName(addr) != "PTR": @@ -627,4 +627,4 @@ def __init__(self, pos, endpos, step, settings, base_type): self.robase = base_type def getStructFieldOffset(self, sid, addr): - return (self.getPtr(sid, addr, "offset") >> 1) \ No newline at end of file + return (self.getPtr(sid, addr, "offset") >> 1) diff --git a/GO_Utils/Utils.py b/GO_Utils/Utils.py index aca6ab3..6a6d890 100644 --- a/GO_Utils/Utils.py +++ b/GO_Utils/Utils.py @@ -27,9 +27,9 @@ def rename(offset, name): def relaxName(name): - name = name.replace('.', '_').replace("<-", '_chan_left_').replace('*', '_ptr_').replace('-', '_').replace(';','').replace('"', '').replace('\\', '') - name = name.replace('(', '').replace(')', '').replace('/', '_').replace(' ', '_').replace(',', 'comma').replace('{','').replace('}', '').replace('[', '').replace(']', '') - return name + name = name.replace(b'.', b'_').replace(b"<-", b'_chan_left_').replace(b'*', b'_ptr_').replace(b'-', b'_').replace(b';', b'').replace(b'"', b'').replace(b'\\', b'') + name = name.replace(b'(', b'').replace(b')', b'').replace(b'/', b'_').replace(b' ', b'_').replace(b',', b'comma').replace(b'{', b'').replace(b'}', b'').replace(b'[', b'').replace(b']', b'') + return name.decode(encoding = "ISO-8859-1") def get_bitness(addr): @@ -86,16 +86,16 @@ def fillStruct(self, sid, data): res = idc.add_struc_member(sid, i[0], -1, i1, i2, i3) use_name = i[0] if res == -1: #Bad name - #print "Bad name %s for struct member" % i[0] + #print("Bad name %s for struct member" % i[0]) use_name = i[0] + "_autogen_"+id_generator() idc.add_struc_member(sid, use_name, -1, i1, i2, i3) if new_type is not None: offset = idc.get_member_offset(sid, use_name) - #print "Setting %s as %s" % (i[0], new_type) + #print("Setting %s as %s" % (i[0], new_type)) idc.SetType(idc.get_member_id(sid, offset), new_type) def makeStruct(self, i): - print "Creating structure %s" % (i[0]) + print("Creating structure %s" % (i[0])) sid = self.createStruct(i[0]) self.fillStruct(sid, i[1]) diff --git a/GO_Utils/__init__.py b/GO_Utils/__init__.py index f4121d7..a621c30 100644 --- a/GO_Utils/__init__.py +++ b/GO_Utils/__init__.py @@ -1,8 +1,8 @@ import idaapi -import Gopclntab -import Utils -import Firstmoduledata -import Types +from . import Gopclntab +from . import Utils +from . import Firstmoduledata +from . import Types import idc import idautils import ida_ida @@ -125,7 +125,7 @@ def typesModuleData(self, typ): else: beg, end = Firstmoduledata.getTypeinfo(fmd, self.bt_obj) self.processor = Types.TypeProcessing(beg, end, self.bt_obj, self) - print "%x %x %x" % (beg, end, robase) - for i in self.processor: - pass - return \ No newline at end of file + print("%x %x %x" % (beg, end, robase)) +# for i in self.processor: +# pass + return diff --git a/go_entry.py b/go_entry.py index eec79c0..c08313f 100644 --- a/go_entry.py +++ b/go_entry.py @@ -50,14 +50,14 @@ def __init__(self): def OnButton1(self, code=0): GO_SETTINGS.findModuleData() - print GO_SETTINGS.tryFindGoVersion() + print(GO_SETTINGS.tryFindGoVersion()) def OnButton3(self, code=0): GO_SETTINGS.renameFunctions() def OnButton2(self, code=0): - print GO_SETTINGS.getVersionByString() + print(GO_SETTINGS.getVersionByString()) def OnButton4(self, code=0): typ = self.GetControlValue(self.cGoVers) @@ -97,4 +97,4 @@ def ida_main(): # -------------------------------------------------------------------------- -ida_main() \ No newline at end of file +ida_main()