diff --git a/pykd-0.3-2013.sln b/pykd-0.3-2013.sln index 2c4713e..d7bd3d8 100644 --- a/pykd-0.3-2013.sln +++ b/pykd-0.3-2013.sln @@ -14,6 +14,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "snippets", "snippets", "{AA EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "um", "um", "{EEFC9510-DFA7-439E-801E-48FCE72766AD}" ProjectSection(SolutionItems) = preProject + samples\um\createfile.py = samples\um\createfile.py samples\um\critlist.py = samples\um\critlist.py samples\um\ldr.py = samples\um\ldr.py EndProjectSection diff --git a/pykd/pymemaccess.h b/pykd/pymemaccess.h index a9a58ed..4dd50eb 100644 --- a/pykd/pymemaccess.h +++ b/pykd/pymemaccess.h @@ -185,6 +185,17 @@ void writeSignQWords( kdlib::MEMOFFSET_64 offset, const python::list &list, bool void writeFloats( kdlib::MEMOFFSET_64 offset, const python::list &list, bool phyAddr = false ); void writeDoubles( kdlib::MEMOFFSET_64 offset, const python::list &list, bool phyAddr = false ); +inline void writeCStr( kdlib::MEMOFFSET_64 offset, const std::string& str) +{ + AutoRestorePyState pystate; + kdlib::writeCStr(offset, str); +} + +inline void writeWStr( kdlib::MEMOFFSET_64 offset, const std::wstring& str) +{ + AutoRestorePyState pystate; + kdlib::writeWStr(offset, str); +} inline std::string loadChars( kdlib::MEMOFFSET_64 offset, unsigned long number, bool phyAddr = false ) { @@ -256,5 +267,7 @@ inline kdlib::MemoryProtect getVaProtect( kdlib::MEMOFFSET_64 offset ) } + + } // end namespace pykd diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp index f1e4d15..a7eb1df 100644 --- a/pykd/pymod.cpp +++ b/pykd/pymod.cpp @@ -361,6 +361,11 @@ BOOST_PYTHON_MODULE( pykd ) "Writing a list of floats to the target's memory" ) ); python::def( "writeDoubles", pykd::writeDoubles, writeDoubles_( python::args( "offset", "values", "phyAddr" ), "Writing a list of doubles to the target's memory" ) ); + python::def( "writeCStr", pykd::writeCStr, + "Write string as a 0 terminated ansi string to the buffer"); + python::def( "writeWStr", pykd::writeWStr, + "Write string as a 0 terminated unicode string to the buffer"); + python::def( "ptrPtr", pykd::ptrPtr, "Read an pointer value from the target memory" ); diff --git a/samples/um/createfile.py b/samples/um/createfile.py new file mode 100644 index 0000000..b4e6f5a --- /dev/null +++ b/samples/um/createfile.py @@ -0,0 +1,49 @@ + +import pykd + +GENERIC_READ = 0x80000000 +GENERIC_WRITE = 0x40000000 +NULL = 0 + +CREATE_ALWAYS = 2 + +FILE_ATTRIBUTE_NORMAL = 0x80 + +def main(): + + kernel32 = pykd.module("kernel32") + + HANDLE = pykd.typeInfo("Void*") + LPCWSTR = pykd.typeInfo("WChar*") + DWORD = pykd.typeInfo("UInt4B") + LPSECURITY_ATTRIBUTES = pykd.typeInfo("Void*") + + CreateFileW_Type = pykd.defineFunction(HANDLE, pykd.callingConvention.NearStd) + CreateFileW_Type.append("lpFileName", LPCWSTR ) + CreateFileW_Type.append("dwDesiredAccess", DWORD ) + CreateFileW_Type.append("dwShareMode", DWORD ) + CreateFileW_Type.append("lpSecurityAttributes", LPSECURITY_ATTRIBUTES ) + CreateFileW_Type.append("dwCreationDisposition", DWORD ) + CreateFileW_Type.append("dwFlagsAndAttributes", DWORD ) + CreateFileW_Type.append("hTemplateFile", HANDLE ) + + fileNameBuf = pykd.stackAlloc(100) + pykd.writeWStr(fileNameBuf, "C:\\temp\\testfile.txt") + + CreateFileW = pykd.typedVar( CreateFileW_Type, kernel32.CreateFileW ) + + fileHandle = CreateFileW( + fileNameBuf, + GENERIC_READ | GENERIC_WRITE, + 0, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL ) + + print "File Handle", hex(fileHandle) + + pykd.stackFree(100) + +if __name__ == "__main__": + main() diff --git a/test/scripts/moduletest.py b/test/scripts/moduletest.py index 57b828b..738ad74 100644 --- a/test/scripts/moduletest.py +++ b/test/scripts/moduletest.py @@ -86,7 +86,7 @@ class ModuleTest( unittest.TestCase ): fileName = pykd.getSourceFile(target.module.CdeclFunc ) self.assertTrue( re.search('testfunc\\.cpp', fileName ) ) fileName, lineNo, displacement = pykd.getSourceLine( target.module.CdeclFunc + 2) - self.assertEqual( 17, lineNo ) + self.assertEqual( 18, lineNo ) self.assertTrue( re.search('testfunc\\.cpp', fileName ) ) self.assertEqual( 2, displacement ) #fileName, lineNo, displacement = pykd.getSourceLine()