[0.3.x] added : writeCStr, writeWStr ( write 0 terminated string to the target memory )

git-svn-id: https://pykd.svn.codeplex.com/svn@91045 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2016-09-16 08:11:38 +00:00 committed by Mikhail I. Izmestev
parent 7b3710b487
commit 584eb08fa7
5 changed files with 69 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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" );

49
samples/um/createfile.py Normal file
View File

@ -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()

View File

@ -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()