mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-19 02:53:22 +08:00
[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:
parent
7b3710b487
commit
584eb08fa7
@ -14,6 +14,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "snippets", "snippets", "{AA
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "um", "um", "{EEFC9510-DFA7-439E-801E-48FCE72766AD}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "um", "um", "{EEFC9510-DFA7-439E-801E-48FCE72766AD}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
samples\um\createfile.py = samples\um\createfile.py
|
||||||
samples\um\critlist.py = samples\um\critlist.py
|
samples\um\critlist.py = samples\um\critlist.py
|
||||||
samples\um\ldr.py = samples\um\ldr.py
|
samples\um\ldr.py = samples\um\ldr.py
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
|
@ -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 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 );
|
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 )
|
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
|
} // end namespace pykd
|
||||||
|
|
||||||
|
@ -361,6 +361,11 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
"Writing a list of floats to the target's memory" ) );
|
"Writing a list of floats to the target's memory" ) );
|
||||||
python::def( "writeDoubles", pykd::writeDoubles, writeDoubles_( python::args( "offset", "values", "phyAddr" ),
|
python::def( "writeDoubles", pykd::writeDoubles, writeDoubles_( python::args( "offset", "values", "phyAddr" ),
|
||||||
"Writing a list of doubles to the target's memory" ) );
|
"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,
|
python::def( "ptrPtr", pykd::ptrPtr,
|
||||||
"Read an pointer value from the target memory" );
|
"Read an pointer value from the target memory" );
|
||||||
|
49
samples/um/createfile.py
Normal file
49
samples/um/createfile.py
Normal 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()
|
@ -86,7 +86,7 @@ class ModuleTest( unittest.TestCase ):
|
|||||||
fileName = pykd.getSourceFile(target.module.CdeclFunc )
|
fileName = pykd.getSourceFile(target.module.CdeclFunc )
|
||||||
self.assertTrue( re.search('testfunc\\.cpp', fileName ) )
|
self.assertTrue( re.search('testfunc\\.cpp', fileName ) )
|
||||||
fileName, lineNo, displacement = pykd.getSourceLine( target.module.CdeclFunc + 2)
|
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.assertTrue( re.search('testfunc\\.cpp', fileName ) )
|
||||||
self.assertEqual( 2, displacement )
|
self.assertEqual( 2, displacement )
|
||||||
#fileName, lineNo, displacement = pykd.getSourceLine()
|
#fileName, lineNo, displacement = pykd.getSourceLine()
|
||||||
|
Loading…
Reference in New Issue
Block a user