Skip to content

Commit

Permalink
Replace UcError with IndexError when checking for invalid memory
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexodia committed Mar 5, 2023
1 parent 6a75429 commit b57acc0
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/dumpulator/dumpulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ def _all_exports(self):
def _parse_module_exports(self, module):
try:
module_data = self.read(module.baseaddress, module.size)
except UcError:
except IndexError:
self.error(f"Failed to read module data")
return []
pe = PE(data=module_data, fast_load=True)
Expand Down Expand Up @@ -757,7 +757,7 @@ def _setup_modules(self):
try:
data = self.read(va, size)
mapped_data[rva:size] = data
except UcError:
except IndexError:
self.error(f"Failed to read section {name} from module {path}")
# Load the PE dumped from memory
pe = PE(data=mapped_data, fast_load=True)
Expand Down Expand Up @@ -1325,9 +1325,9 @@ def _hook_code(uc: Uc, address, size, dp: Dumpulator):
instr = next(dp.cs.disasm(code, address, 1))
except StopIteration:
instr = None # Unsupported instruction
except UcError:
instr = None # Likely invalid memory
code = []
except IndexError:
instr = None # Likely invalid memory
code = b""
address_name = dp.exports.get(address, "")

module = ""
Expand Down Expand Up @@ -1361,13 +1361,13 @@ def _hook_code(uc: Uc, address, size, dp: Dumpulator):
def _unicode_string_to_string(dp: Dumpulator, arg: P(UNICODE_STRING)):
try:
return arg[0].read_str()
except UcError:
except IndexError:
return None

def _object_attributes_to_string(dp: Dumpulator, arg: P(OBJECT_ATTRIBUTES)):
try:
return arg[0].ObjectName[0].read_str()
except UcError:
except IndexError:
pass
return None

Expand Down Expand Up @@ -1555,6 +1555,6 @@ def _hook_invalid(uc: Uc, dp: Dumpulator):
return False # NOTE: returning True would stop emulation
except StopIteration:
pass # Unsupported instruction
except UcError:
except IndexError:
pass # Invalid memory access (NOTE: this should not be possible actually)
raise NotImplementedError("TODO: throw invalid instruction exception")

0 comments on commit b57acc0

Please sign in to comment.