def rename(self): if not self.new_name_ok() or not self.old_name: return False found = False for i, a in enumerate(self.vars): item = self.occurences_lit.item(i) if item.checkState() == QtCore.Qt.Checked: clname = a["classname"] filename = self.structname_to_file_table[clname] hfile = hparser.HFile(filename) struct = hfile.get(clname) struct.rename_var(self.old_name, self.new_name) hfile.update(struct) hfile.save() idc.ParseTypes(filename, idc.PT_FILE | idc.PT_PAKDEF) found = True for i, a in enumerate(self.functions): item = self.occurences_lit.item(i + len(self.vars)) if item.checkState() == QtCore.Qt.Checked: ea = a["ea"] func_name = a["func_name"] if func_name.demangled: if not gui.ask( "Function %s is mangled. If you wish to rename it, mangling will dissapear. Continue?" % func_name.signature()): continue old_name = func_name.fullname() func_name.set_base_name(self.new_name) print ea, func_name.fullname(), idc.SN_NOCHECK idc.MakeNameEx(ea, str(func_name.fullname()), idc.SN_NOCHECK) print "FunctionName %s is replaced to %s" % ( old_name, func_name.fullname()) found = True return found
def create_binary_table(ea, tables, name_tables): print("Creating %s from at 0x%08X..." % (name_tables, ea)) for xname, xhex_mask, xbyte_size, xelement_type in tables: list_addr = find_binary_strings(ea, xhex_mask, xbyte_size) if list_addr and list_addr[0] == ea: # make name addr_name = xname nm = [b for a, b in idautils.Names()] iname = 2 while addr_name in nm: addr_name = "%s_%d" % (xname, iname) iname += 1 if not gui.ask("Found %s. Create %s?" % (xname, addr_name)): return # rename in IDA rename_public(ea, addr_name) # make array in IDA make_array(ea, xbyte_size, xelement_type) return print "No known %s found at 0x%08X" % name_tables, ea
def main(): while True: for d in fscomm.devices(): if d.type != "RemoteControlClient": continue if d.publicKeys.sign not in knownClientDevices: answer = gui.ask( "A new device was found:\n\n" + d.user_string() + "\nDo you want to allow full access on your computer?\n" + "(You can always disable the access again.)") devInfo = {} knownClientDevices[d.publicKeys.sign] = devInfo devInfo["devId"] = d.devId devInfo["publicKeys"] = d.publicKeys devInfo["allowAccess"] = answer for c in localDev.awaitingConnections(): print "new conn:", c if c.srcDev.publicKeys.sign not in knownClientDevices: c.refuse("not accepted client " + c.srcDev.devId) continue if c.connData.intent == "PythonExec.1": c.accept() else: c.refuse("unknown intend '%s'" % c.intent) for c in localDev.connections(): if c.hasCloseRequest(): c.close() continue #if time.time() - c.firstTime > 60: # old enough to cleanup # c.close("timeout") # continue if not c.isAccepted(): continue if c.srcDev.publicKeys.sign not in knownClientDevices: print "unknown client issued connection" c.close("unknown client") continue if not knownClientDevices[c.srcDev.publicKeys.sign]["allowAccess"]: print "no access for", c.srcDev c.close("no access") continue for p in c.readPackages(): print "got", repr(p), "from", c.srcDev response = {} response["seqnr"] = p.seqnr evalScope = evalScopes.setdefault(c.srcDev, { "srcDev":c.srcDev, "dstDev":c.dstDev}) try: ret = eval(p.data, evalScope, evalScope) response["ret"] = ret except Exception as exc: response["exception"] = repr(exc) c.sendPackage(response) easycfg.save() fscomm.wait()
def rename(self): if not self.new_name: return False item_num = 0 found = False #rename class members for a in self.text_items: item = self.occurences_lit.item(item_num) item_num += 1 if item.checkState() == QtCore.Qt.Checked: f = open(a['filename']) lines = f.readlines() f.close() lines[a['line']] = re.sub(self.regex(), self.new_name, lines[a['line']]) f = open(a['filename'], "w") f.write("".join(lines)) f.close() found = True #files for header in self.header_files: item = self.occurences_lit.item(item_num) item_num += 1 if item.checkState() == QtCore.Qt.Checked: newname = os.path.join(os.path.dirname(header), self.new_name + ".h") os.rename(header, newname) print "File %s was renamed to %s" % (header, newname) found = True #functions for a in self.functions: item = self.occurences_lit.item(item_num) item_num += 1 if item.checkState() == QtCore.Qt.Checked: ea = a["ea"] func_name = a["func_name"] if func_name.demangled: if not gui.ask( "Function %s is mangled. If you wish to rename it, mangling will dissapear. Continue?" % func_name.signature()): continue old_name = func_name.fullname() func_name.set_namespace(self.new_name) print ea, func_name.fullname() idc.MakeNameEx(ea, str(func_name.fullname()), idc.SN_NOCHECK) print "FunctionName %s is replaced to %s" % ( old_name, func_name.fullname()) found = True return found
def save_file(self): fn = os.path.join(decompiled.headers_folder, self.filename_edit.text()) if os.path.exists(fn) and not gui.ask( u"File %s already exists. Do you want to overwrite it?" % self.filename_edit.text(), u"File already exists"): return False if not os.path.exists(decompiled.headers_folder): if not gui.ask( u"Headers directory %s doesnt exist. Do you want to create it?" % decompiled.headers_folder, u"Headers directory doesnt exist", True): return False os.makedirs(decompiled.headers_folder) f = open(fn, 'w') f.write(self.textEdit.toPlainText()) f.close() idc.ParseTypes(str(fn), idc.PT_FILE | idc.PT_PAKDEF) print("File %s with virtual table %s created and loaded into Ida" % (self.filename_edit.text(), self.name_edit.text())) return True
def save_binary_dump(filename, addr, length): if os.path.exists(filename) and not gui.ask("File exists. Overwrite?"): return f = open(filename, "wb") end = addr + length for ea in range(addr, end, 0x1000): min_len = min(end - ea, 0x1000) bts = idaapi.get_many_bytes(ea, min_len) f.write(bts) f.close() print "Saved binary data addr = %s length =%s to %s" % ( hex(addr), hex(length), filename)
def parse_flt_module_file(self,filename): """ Program that opens a macro file and parses it, runs the move commands on each line of the file Added ability to defined either altitude in feet or meters, or the length in km or nm """ from gui import ask import os # set up predefined values predef = ['azi','AZI','PP','pp'] azi = self.ex.azi[-1] pp, AZI, PP = azi,azi,azi # load flt_module name = os.path.basename(filename).split('.')[0] f = open(filename,'r') s = f.readlines() # get variables in flt_module for l in s: if l.startswith('%'): names = [u.strip() for u in l.strip().strip('%').split(',')] choice = ['feet','meters'] choice2 = ['km','nm'] # remove values predefined for p in predef: try: names.remove(p) except: pass # ask the user supply the variables vals = ask(names,choice=choice,choice_title='Altitude:',choice2=choice2,choice2_title='Distance:',title='Enter values for {}'.format(name)) v = vals.names_val if vals.choice_val == 'feet': use_feet = True else: use_feet = False if vals.choice2_val == 'km': use_km = True else: use_km = False # make the values variables for i,n in enumerate(names): try: exec('{}={}'.format(n,vals.names_val[i])) except: print 'problem for {}={}'.format(n,vals.names_val[i]) for l in s[1:-1]: if not (l.startswith('#') or l.startswith('%')): try: self.newpoint(*eval(l),last=False,feet=use_feet,km=use_km) except: print 'problem with {}'.format(l) if not s[-1].startswith('#') or not s[-1].startswith('%'): try: self.newpoint(*eval(s[-1]),feet=use_feet,km=use_km) except: print 'problem with last {}'.format(s[-1]) f.close()
def parse_flt_module_file(self, filename): """ Program that opens a macro file and parses it, runs the move commands on each line of the file Added ability to defined either altitude in feet or meters, or the length in km or nm """ from gui import ask import os # set up predefined values predef = ['azi', 'AZI', 'PP', 'pp'] azi = self.ex.azi[-1] pp, AZI, PP = azi, azi, azi # load flt_module name = os.path.basename(filename).split('.')[0] f = open(filename, 'r') s = f.readlines() # get variables in flt_module for l in s: if l.startswith('%'): names = [u.strip() for u in l.strip().strip('%').split(',')] choice = ['feet', 'meters'] choice2 = ['km', 'nm'] # remove values predefined for p in predef: try: names.remove(p) except: pass # ask the user supply the variables vals = ask(names, choice=choice, choice_title='Altitude:', choice2=choice2, choice2_title='Distance:', title='Enter values for {}'.format(name)) v = vals.names_val if vals.choice_val == 'feet': use_feet = True else: use_feet = False if vals.choice2_val == 'km': use_km = True else: use_km = False # make the values variables for i, n in enumerate(names): try: exec('{}={}'.format(n, vals.names_val[i])) except: print 'problem for {}={}'.format(n, vals.names_val[i]) for l in s[1:-1]: if not (l.startswith('#') or l.startswith('%')): try: self.newpoint(*eval(l), last=False, feet=use_feet, km=use_km) except: print 'problem with {}'.format(l) if not s[-1].startswith('#') or not s[-1].startswith('%'): try: self.newpoint(*eval(s[-1]), feet=use_feet, km=use_km) except: print 'problem with last {}'.format(s[-1]) f.close()