Commit 7fc08bca authored by SND\ussrhero_cp's avatar SND\ussrhero_cp Committed by Mikhail I. Izmestev
Browse files

[0.3.x] added : getTypeInfoProviderFromPdb ( create typeInfo provider from pdb file )

[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
parent d3b5f99a
......@@ -17,6 +17,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "um", "um", "{EEFC9510-DFA7-
samples\um\createfile.py = samples\um\createfile.py
samples\um\critlist.py = samples\um\critlist.py
samples\um\ldr.py = samples\um\ldr.py
samples\um\virtalloc.py = samples\um\virtalloc.py
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{D1F1222A-A12B-4FD7-91A0-0AB6393A3169}"
......
......@@ -204,6 +204,19 @@ inline kdlib::MEMOFFSET_64 stackFree(unsigned short byteCount) {
return kdlib::stackFree(byteCount);
}
inline void pushStack( const kdlib::NumVariant& value )
{
AutoRestorePyState pystate;
return kdlib::pushInStack(value);
}
inline kdlib::NumVariant popStack() {
AutoRestorePyState pystate;
kdlib::NumVariant value;
kdlib::popFromStack(value);
return value;
}
class CPUContextAdapter
{
......
......@@ -2,7 +2,7 @@
#define PYKD_VERSION_MAJOR 0
#define PYKD_VERSION_MINOR 3
#define PYKD_VERSION_SUBVERSION 2
#define PYKD_VERSION_BUILDNO 5
#define PYKD_VERSION_BUILDNO 6
#define __VER_STR2__(x) #x
#define __VER_STR1__(x) __VER_STR2__(x)
......
......@@ -101,7 +101,8 @@ BOOST_PYTHON_FUNCTION_OVERLOADS( Module_enumTypes, ModuleAdapter::enumTypes, 1,
BOOST_PYTHON_FUNCTION_OVERLOADS( TypeInfo_ptrTo, TypeInfoAdapter::ptrTo, 1, 2 );
BOOST_PYTHON_FUNCTION_OVERLOADS( getTypeFromSource_, pykd::getTypeFromSource, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( getTypeInfoProviderFromPdb_, pykd::getTypeInfoProviderFromPdb, 1, 2 );
BOOST_PYTHON_FUNCTION_OVERLOADS( getTypeInfoProviderFromSource_, pykd::getTypeInfoProviderFromSource, 1, 2);
namespace pykd {
......@@ -420,8 +421,10 @@ BOOST_PYTHON_MODULE( pykd )
python::def( "getTypeFromSource", &pykd::getTypeFromSource, getTypeFromSource_( python::args("sourceCode", "typeName", "compileOptions"),
"Create typeInfo class from C/C++ source code") );
python::def( "getTypeInfoProviderFromSource", &pykd::getTypeInfoProviderFromSource,
"Create typeInfo provider from C/C++ source code");
python::def( "getTypeInfoProviderFromSource", &pykd::getTypeInfoProviderFromSource, getTypeInfoProviderFromSource_( python::args("sourceCode", "compileOptions"),
"Create typeInfo provider from C/C++ source code") );
python::def( "getTypeInfoProviderFromPdb", &pykd::getTypeInfoProviderFromPdb, getTypeInfoProviderFromPdb_( python::args("filePath", "baseOffset"),
"Create typeInfo provider from pdb file") );
// CPU registers
python::def( "reg", pykd::getRegisterByName,
......@@ -486,6 +489,10 @@ BOOST_PYTHON_MODULE( pykd )
"Allocate bytes of space in the stack in the target process" );
python::def( "stackFree", pykd::stackFree,
"Free space in the stack previously allocated by stackAlloc" );
python::def( "pushStack", pykd::pushStack,
"Push a value into a stack" );
python::def( "popStack", pykd::popStack,
"Pop a value from a stack" );
// breakpoints
python::def( "setBp", &Breakpoint::setSoftwareBreakpoint,
......
......@@ -67,6 +67,12 @@ inline kdlib::TypeInfoProviderPtr getTypeInfoProviderFromSource(const std::wstri
return kdlib::getTypeInfoProviderFromSource(sourceCode, compileOptions);
}
inline kdlib::TypeInfoProviderPtr getTypeInfoProviderFromPdb(const std::wstring& fileName, kdlib::MEMOFFSET_64 offset = 0UL)
{
AutoRestorePyState pystate;
return kdlib::getTypeInfoProviderFromPdb(fileName, offset);
}
struct TypeInfoAdapter : public kdlib::TypeInfo {
static std::wstring getName( kdlib::TypeInfo &typeInfo )
......
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() )
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment