Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
fix exception that occurs when attempting to read non-existent stack …
Browse files Browse the repository at this point in the history
…memory in getArgv
  • Loading branch information
jtbennett-fe committed Jul 22, 2022
1 parent 4d773f6 commit 2c23fa8
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion flare_emu.py
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,13 @@ def getArgv(self):
if self.arch == unicorn.UC_ARCH_X86:
if self.mode == unicorn.UC_MODE_64:
sp = self.getRegVal("rsp")
# ensure there is mem mapped at the stack pointer
try:
self.uc.mem_read(sp, 4)
except:
sp = self.allocEmuMem(0x2000) + 0x1000
self.uc.reg_write(self.regs["sp"], sp)

if self.filetype == "MACHO" or self.filetype == "ELF":
argv = [
self.getRegVal("rdi"),
Expand Down Expand Up @@ -1929,7 +1936,7 @@ def _guidedHook(self, uc, address, size, userData):
self.analysisHelper.getNameAddr(self.analysisHelper.getOperand(address, 0)) ==
self.analysisHelper.getFuncStart(
self.analysisHelper.getNameAddr(self.analysisHelper.getOperand(address, 0))))):

funcName = self.getCallTargetName(address)
if userData["callHook"]:
userData["callHook"](address, self.getArgv(), funcName, userData)
Expand Down

0 comments on commit 2c23fa8

Please sign in to comment.