MCPcopy Create free account
hub / github.com/fabioz/PyDev.Debugger / __restore_mbi

Method __restore_mbi

pydevd_attach_to_process/winappdbg/process.py:3355–3443  ·  view source on GitHub ↗

Used internally by L{restore_memory_snapshot}.

(self, hProcess, new_mbi, old_mbi, bSkipMappedFiles, bSkipOnError)

Source from the content-addressed store, hash-verified

3353 self.resume()
3354
3355 def __restore_mbi(self, hProcess, new_mbi, old_mbi, bSkipMappedFiles, bSkipOnError):
3356 """
3357 Used internally by L{restore_memory_snapshot}.
3358 """
3359
3360 ## print "Restoring %s-%s" % (
3361 ## HexDump.address(old_mbi.BaseAddress, self.get_bits()),
3362 ## HexDump.address(old_mbi.BaseAddress + old_mbi.RegionSize,
3363 ## self.get_bits()))
3364
3365 try:
3366 # Restore the region state.
3367 if new_mbi.State != old_mbi.State:
3368 if new_mbi.is_free():
3369 if old_mbi.is_reserved():
3370 # Free -> Reserved
3371 address = win32.VirtualAllocEx(
3372 hProcess, old_mbi.BaseAddress, old_mbi.RegionSize, win32.MEM_RESERVE, old_mbi.Protect
3373 )
3374 if address != old_mbi.BaseAddress:
3375 self.free(address)
3376 msg = "Error restoring region at address %s"
3377 msg = msg % HexDump(old_mbi.BaseAddress, self.get_bits())
3378 raise RuntimeError(msg)
3379 # permissions already restored
3380 new_mbi.Protect = old_mbi.Protect
3381
3382 else: # elif old_mbi.is_commited():
3383 # Free -> Commited
3384 address = win32.VirtualAllocEx(
3385 hProcess, old_mbi.BaseAddress, old_mbi.RegionSize, win32.MEM_RESERVE | win32.MEM_COMMIT, old_mbi.Protect
3386 )
3387 if address != old_mbi.BaseAddress:
3388 self.free(address)
3389 msg = "Error restoring region at address %s"
3390 msg = msg % HexDump(old_mbi.BaseAddress, self.get_bits())
3391 raise RuntimeError(msg)
3392 # permissions already restored
3393 new_mbi.Protect = old_mbi.Protect
3394
3395 elif new_mbi.is_reserved():
3396 if old_mbi.is_commited():
3397 # Reserved -> Commited
3398 address = win32.VirtualAllocEx(hProcess, old_mbi.BaseAddress, old_mbi.RegionSize, win32.MEM_COMMIT, old_mbi.Protect)
3399 if address != old_mbi.BaseAddress:
3400 self.free(address)
3401 msg = "Error restoring region at address %s"
3402 msg = msg % HexDump(old_mbi.BaseAddress, self.get_bits())
3403 raise RuntimeError(msg)
3404 # permissions already restored
3405 new_mbi.Protect = old_mbi.Protect
3406
3407 else: # elif old_mbi.is_free():
3408 # Reserved -> Free
3409 win32.VirtualFreeEx(hProcess, old_mbi.BaseAddress, old_mbi.RegionSize, win32.MEM_RELEASE)
3410
3411 else: # elif new_mbi.is_commited():
3412 if old_mbi.is_reserved():

Callers 1

Calls 9

freeMethod · 0.95
get_bitsMethod · 0.95
pokeMethod · 0.95
writeMethod · 0.95
HexDumpClass · 0.90
is_freeMethod · 0.80
is_reservedMethod · 0.80
is_commitedMethod · 0.80
has_contentMethod · 0.80

Tested by

no test coverage detected