mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-17 01:13:24 +08:00

[0.3.x] added : pushStack ( push a value into a stack ) [0.3.x] added : popStack( popStack ) git-svn-id: https://pykd.svn.codeplex.com/svn@91232 9b283d60-5439-405e-af05-b73fd8c4d996
60 lines
1.2 KiB
Python
60 lines
1.2 KiB
Python
|
|
|
|
import pykd
|
|
|
|
|
|
win_src = '''
|
|
|
|
typedef void* LPVOID;
|
|
typedef size_t SIZE_T;
|
|
typedef unsigned long DWORD;
|
|
typedef bool BOOL;
|
|
|
|
LPVOID
|
|
__stdcall
|
|
VirtualAlloc(
|
|
LPVOID lpAddress,
|
|
SIZE_T dwSize,
|
|
DWORD flAllocationType,
|
|
DWORD flProtect
|
|
);
|
|
|
|
BOOL
|
|
__stdcall
|
|
VirtualFree(
|
|
LPVOID lpAddress,
|
|
SIZE_T dwSize,
|
|
DWORD dwFreeType
|
|
);
|
|
|
|
|
|
DWORD
|
|
__stdcall
|
|
GetLastError(void);l
|
|
|
|
'''
|
|
|
|
MEM_COMMIT = 0x1000
|
|
MEM_RELEASE = 0x8000
|
|
PAGE_READWRITE = 0x4
|
|
|
|
winTypeProvider = pykd.getTypeInfoProviderFromSource(win_src, "-w")
|
|
|
|
kernel = pykd.module('KERNELBASE')
|
|
|
|
VirtualAlloc = pykd.typedVar(winTypeProvider.getTypeByName('VirtualAlloc'), kernel.VirtualAlloc )
|
|
VirtualFree = pykd.typedVar(winTypeProvider.getTypeByName('VirtualFree'), kernel.VirtualFree )
|
|
GetLastError = pykd.typedVar(winTypeProvider.getTypeByName('GetLastError'), kernel.GetLastError )
|
|
|
|
addr = VirtualAlloc(0, 0x1000, MEM_COMMIT, PAGE_READWRITE)
|
|
|
|
if addr:
|
|
print("Allocated memory: %x" % addr )
|
|
|
|
if VirtualFree(addr, 0, MEM_RELEASE):
|
|
print("Successfully free memory")
|
|
else:
|
|
print("Failed VirtualFree with error %x" % GetLastError() )
|
|
else:
|
|
print("Failed VirtualAlloc with error %x" % GetLastError() )
|