def handleReplaceFuncEdit(self, screenEA = None):
if screenEA is not None:
func = get_func(screenEA)
else:
func = get_func(ScreenEA())
if func is None:
return
repl_id = func.startEA;
if repl_id not in self.funcReplaceMap:
return
entry = self.funcReplaceMap[repl_id]
replaceDlg = FunctionReplaceDialog(entry.module, "%X" % entry.id, entry.symbol, entry.recentSrcFile)
replaceDlg.Compile()
replaceDlg.ret_type.value = entry.ret_type[1:-1]
replaceDlg.args.value = entry.args_str
replaceDlg.script.value = entry.script
ok = replaceDlg.Execute()
if ok != 1:
return
flags = FuncReplace.UDP_NONE
entry.recentSrcFile = replaceDlg.recentScriptFile
if entry.script != replaceDlg.script.value:
entry.script = replaceDlg.script.value
flags |= FuncReplace.UPD_SCRIPT
outJSON = json.dumps({
"req_id": kFridaLink_UpdReplaceRequest,
"data": entry.genUpdRequest(flags)
})
self.clientSocket.sendto(outJSON, self.clientAddress)
python类ScreenEA()的实例源码
def handleReplaceFuncDel(self, screenEA = None):
if screenEA is not None:
func = get_func(screenEA)
else:
func = get_func(ScreenEA())
if func is None:
return
repl_id = func.startEA;
if repl_id not in self.funcReplaceMap:
return
entry = self.funcReplaceMap[repl_id]
outJSON = json.dumps({
"req_id": kFridaLink_DelReplaceRequest,
"data": entry.genDelRequest()
})
del self.funcReplaceMap[repl_id]
self.clientSocket.sendto(outJSON, self.clientAddress)
if entry.moduleImport == False:
SetColor(repl_id, CIC_FUNC, kIDAViewColor_Reset)
refresh_idaview_anyway()
self.funcReplaceView.setContent(self.funcReplaceMap)
def replacedFunction(self, screenEA = None):
if screenEA is not None:
func = get_func(screenEA)
else:
func = get_func(ScreenEA())
if func is None:
return False;
address = func.startEA;
if address in self.funcReplaceMap:
return True
else:
return False
def GlobalorLocal(self):
origlobal= self._global
views = ['1','2','3']
if self._global == 1:
tmpglobal = 0
else:
tmpglobal = 1
c_ea = idc.ScreenEA()
(c_startEA,c_endEA) = self._GetFuncRange(c_ea)
indexs = [i for i,item in enumerate(self._tablelist) if item[2] in views]
for index in indexs:
ea = int(self._tablelist[index][0],16)
DEBUG_PRINT( ea)
(startEA,endEA) = self._GetFuncRange(ea)
if startEA == c_startEA:
c_index = index
continue
self._delComms(startEA,endEA)
self._tablelist[index][2] = '0'
for ea in range(c_startEA,c_endEA+1):
if ea in self._dbDict.keys():
if self._dbDict[ea]._shown == True:
idx = self.GetIDX(ea)
id = self.GetID(ea, idx)
oldComm = str(idc.GetCommentEx(ea, 0))
startIdx = oldComm.find(self._commMarker)
if(startIdx != -1):
comm = oldComm[0:startIdx]
idc.MakeComm(ea, str(comm).strip())
self._global = tmpglobal
self._ApdComm(ea,id)
self._global = origlobal
self._global = tmpglobal
return
def _showFunctions(self):
DEBUG_PRINT('IN _showFunctions')
try:
ea = idc.ScreenEA()
deflt_ea = idaapi.get_func(ea).startEA
except:
deflt_ea = int(self._tablelist[0][0],16)
deflt_id = 1
views = ['0','1','2','3']
for view in views:
if [hex(deflt_ea),idc.GetFunctionName(deflt_ea),view] in self._tablelist:
deflt_id = self._tablelist.index([hex(deflt_ea),idc.GetFunctionName(deflt_ea),view]) + 1
# if [hex(deflt_ea),idc.GetFunctionName(deflt_ea),'0'] in self._tablelist:
# deflt_id = self._tablelist.index([hex(deflt_ea),idc.GetFunctionName(deflt_ea),'0']) + 1
# if [hex(deflt_ea),idc.GetFunctionName(deflt_ea),'1'] in self._tablelist:
# deflt_id = self._tablelist.index([hex(deflt_ea),idc.GetFunctionName(deflt_ea),'1']) + 1
title = "Functions with Comments"
cols = [['Address',10],['Function Name',15],['Show',4]]
chooser = IdxChoose2(title, cols, self._tablelist, deflt = deflt_id)
id = chooser.show()
if -1==id:
return 0
else:
ea = int(self._tablelist[id][0],16)
return ea
#hex(int(self._tablelist[id][0],16))
def IdxChooser(self): #'i' #THE ONLY place can change the index manually
DEBUG_PRINT('in IdxChooser')
ea = idc.ScreenEA()
deflt_id = 1
try:
deflt_id = self.GetID(ea, self.GetIDX(ea)) + 1
except:
pass
DEBUG_PRINT(ea)
if ea not in self._dbDict.keys():
DEBUG_PRINT( '\n0x%x has no comments'%(ea))
return
title = 'IndexChooser'
cols = [['ID',4],['Index',10],['Comment',40]]
items = []
count = 1
for item in self._dbDict[ea]._idx_list:
temp = [str(count),str(item[0]),item[1]]
items.append(temp)
count = count + 1
chooser = IdxChoose2(title, cols, items,deflt = deflt_id)
id = chooser.show()
if -1==id:
idc.Message('\n Index no change\n')
else:
self._choose_id = id
self._choose_ea = ea
print '0x%x %dth index is chosen'%(ea,self._choose_id)
self.ForwardView(ea,self._choose_id,innermode = 1)
def handleHookInstCust(self, screenEA = None):
if screenEA is not None:
address = screenEA
else:
address = ScreenEA()
# safety checks, can be start of the function
if address in self.idbHookMap and self.idbHookMap[address].hook.type == "func":
dlg = AskYN(0, "Address contains function hook!\nDo you want to remove it?")
if dlg != 1:
return
# remove function hook
self.handleUnhookFunc(address)
offset, moduleName = self.getAddressDetails(address)
hookDlg = InstructionHookDialog(moduleName, "%X" % address, GetDisasm(address), None)
hookDlg.Compile()
hookDlg.script.value = ""
ok = hookDlg.Execute()
if ok != 1:
return
hook = InstHook()
hook.id = address
hook.mnemonic = GetDisasm(address)
hook.address = offset
hook.module = moduleName
hook.once = True if hookDlg.trigger.value == 0 else False
hook.recentScriptFile = hookDlg.recentScriptFile
hook.script = hookDlg.script.value
entry = HookEntry(hook)
outJSON = json.dumps({
"req_id": kFridaLink_SetHookRequest,
"data": entry.genSetRequest()
})
SetColor(address, CIC_ITEM, kIDAViewColor_HookedInst)
refresh_idaview_anyway()
self.clientSocket.sendto(outJSON, self.clientAddress)
self.idbHookMap[address] = entry
self.idbHooksView.setContent(self.idbHookMap)
def handleHookFuncCust(self, screenEA = None):
if screenEA is not None:
func = get_func(screenEA)
else:
func = get_func(ScreenEA())
if func is None:
return
address = func.startEA;
# safety checks, can be start of the function
if address in self.idbHookMap and self.idbHookMap[address].hook.type == "inst":
dlg = AskYN(0, "Address contains instruction hook!\nDo you want to remove it?")
if dlg != 1:
return
# remove instruction hook
self.handleUnhookInst(address)
offset, moduleName = self.getAddressDetails(address)
hookDlg = FunctionHookDialog(moduleName, "%X" % address, get_func_name(address), None, None)
hookDlg.Compile()
hookDlg.script_enter.value = ""
hookDlg.script_leave.value = ""
ok = hookDlg.Execute()
if ok != 1:
return
hook = FuncHook()
hook.id = address
hook.symbol = get_func_name(address)
hook.address = offset
hook.module = moduleName
hook.once = True if hookDlg.trigger.value == 0 else False
hook.enterRecentSrcFile = hookDlg.recentScriptFileEnter
hook.enterScript = hookDlg.script_enter.value
hook.leaveRecentSrcFile = hookDlg.recentScriptFileLeave
hook.leaveScript = hookDlg.script_leave.value
entry = HookEntry(hook)
outJSON = json.dumps({
"req_id": kFridaLink_SetHookRequest,
"data": entry.genSetRequest()
})
SetColor(address, CIC_FUNC, kIDAViewColor_HookedFunc)
refresh_idaview_anyway()
self.clientSocket.sendto(outJSON, self.clientAddress)
self.idbHookMap[address] = entry
self.idbHooksView.setContent(self.idbHookMap)
def handleHookFuncEdit(self, screenEA = None):
if self.hookedFunction() == False:
return
if screenEA is not None:
func = get_func(screenEA)
else:
func = get_func(ScreenEA())
if func is None:
return
address = func.startEA;
entry = self.idbHookMap[address]
entry.hook.symbol = get_func_name(address)
hookDlg = FunctionHookDialog(entry.hook.module, "%X" % entry.hook.id, entry.hook.symbol, entry.hook.enterRecentSrcFile, entry.hook.leaveRecentSrcFile)
hookDlg.Compile()
hookDlg.script_enter.value = entry.hook.enterScript
hookDlg.script_leave.value = entry.hook.leaveScript
hookDlg.trigger.value = 0 if entry.hook.once == True else 1
ok = hookDlg.Execute()
if ok != 1:
return
flags = HookEntry.UDP_NONE
once = True if hookDlg.trigger.value == 0 else False
if entry.hook.once != once:
entry.hook.once = once
flags |= HookEntry.UPD_TRIGGER
entry.hook.enterRecentSrcFile = hookDlg.recentScriptFileEnter
if entry.hook.enterScript != hookDlg.script_enter.value:
entry.hook.enterScript = hookDlg.script_enter.value
flags |= HookEntry.UPD_SCRIPT
entry.hook.leaveRecentSrcFile = hookDlg.recentScriptFileLeave
if entry.hook.leaveScript != hookDlg.script_leave.value:
entry.hook.leaveScript = hookDlg.script_leave.value
flags |= HookEntry.UPD_SCRIPT
outJSON = json.dumps({
"req_id": kFridaLink_UpdHookRequest,
"data": entry.genUpdRequest(flags)
})
self.clientSocket.sendto(outJSON, self.clientAddress)
def ForwardView(self,ea,id, innermode = 0): # '>'.
DEBUG_PRINT( 'Forward ')
if innermode == 0:
ea = idc.ScreenEA()
id = self.GetID(ea, self.GetIDX(ea))
self._choose_ea = ea
self.max_ea = ea
self.min_ea = ea
self.max_idx = 0
self.min_idx = 0
color = 1
(startEA,endEA) = self._GetFuncRange(ea)
self.ColorCompare()
self._delComms(startEA,endEA)
# endEA = decode_prev_insn(endEA)
(down_ea, up_ea) = (ea,ea)
(down_id, up_id) = (id,id)
# print 'max 0x%x end 0x%x'%(self.max_ea,endEA)
# print 'min 0x%x start 0x%x'%(self.min_ea,startEA)
while(self.max_ea <= endEA and self.min_ea >= startEA and color <4):
DEBUG_PRINT( 'in while')
self.LookDOWN(endEA,down_ea,down_id,color)
self.LookUP(startEA,up_ea,up_id,color)
if [] == self._dbDict[self.max_ea]._xref_from and [] == self._dbDict[self.min_ea]._xref_to:
print 'max_ea and min_ea have no xref'
break
if [] != self._dbDict[self.max_ea]._xref_from:
(down_ea, down_id) = self.Get_Down()
if -1 == down_ea:
(down_ea, down_id) = (ea,id)
if [] != self._dbDict[self.min_ea]._xref_to:
(up_ea, up_id) = self.Get_Up()
if -1 == up_ea:
(up_ea, up_id) = (ea,id)
DEBUG_PRINT(color)
color = color+1
print 'Forward View is finished'
idc.Refresh()
cid = [i for i,item in enumerate(self._tablelist) if item[0]==hex(startEA)]
if cid != []:
cindex = cid[0]
self._tablelist[cindex][2] = '2'
else:
print 'ea not in range'
return
def BackwardView(self,ea,id, innermode = 0): #'<', DEFAULT VIEW
DEBUG_PRINT('Backward')
if innermode == 0:
ea = idc.ScreenEA()
self._choose_ea = ea
id = self.GetID(ea, self.GetIDX(ea))
self.max_ea = ea
self.min_ea = ea
self.max_idx = 0
self.min_idx = 0
color = 1
(startEA,endEA) = self._GetFuncRange(ea)
self.ColorCompare()
self._delComms(startEA,endEA)
# endEA = decode_prev_insn(endEA)
(down_ea, up_ea) = (ea,ea)
(down_id, up_id) = (id,id)
# print 'max 0x%x end 0x%x'%(self.max_ea,endEA)
# print 'min 0x%x start 0x%x'%(self.min_ea,startEA)
while(self.max_ea <= endEA and self.min_ea >= startEA and color <4):
DEBUG_PRINT( 'in while')
DEBUG_PRINT( 'max 0x%x'%self.max_ea)
DEBUG_PRINT( 'min 0x%x'%self.min_ea)
self.LookUP(startEA,up_ea,up_id,color)
self.LookDOWN(endEA,down_ea,down_id,color)
if [] == self._dbDict[self.max_ea]._xref_from and [] == self._dbDict[self.min_ea]._xref_to:
break
if [] != self._dbDict[self.max_ea]._xref_from:
(down_ea, down_id) = self.Get_Down()
if -1 == down_ea:
(down_ea, down_id) = (ea,id)
if [] != self._dbDict[self.min_ea]._xref_to:
(up_ea, up_id) = self.Get_Up()
if -1 == up_ea:
(up_ea, up_id) = (ea,id)
DEBUG_PRINT(color)
color = color+1
print 'Backward View finished'
cid = [i for i,item in enumerate(self._tablelist) if item[0]==hex(startEA)]
if cid != []:
cindex = cid[0]
self._tablelist[cindex][2] = '3'
else:
print 'ea not in range'
idc.Refresh()
return