mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-13 23:03:24 +08:00
[0.3.x] added : callFunctionRaw ( call function without prototype )
git-svn-id: https://pykd.svn.codeplex.com/svn@91241 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
61bf1b83d0
commit
3fab992efd
@ -2,7 +2,7 @@
|
|||||||
#define PYKD_VERSION_MAJOR 0
|
#define PYKD_VERSION_MAJOR 0
|
||||||
#define PYKD_VERSION_MINOR 3
|
#define PYKD_VERSION_MINOR 3
|
||||||
#define PYKD_VERSION_SUBVERSION 2
|
#define PYKD_VERSION_SUBVERSION 2
|
||||||
#define PYKD_VERSION_BUILDNO 6
|
#define PYKD_VERSION_BUILDNO 7
|
||||||
|
|
||||||
#define __VER_STR2__(x) #x
|
#define __VER_STR2__(x) #x
|
||||||
#define __VER_STR1__(x) __VER_STR2__(x)
|
#define __VER_STR1__(x) __VER_STR2__(x)
|
||||||
|
@ -418,6 +418,7 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
"Define custom function prototype" ) );
|
"Define custom function prototype" ) );
|
||||||
python::def( "callFunctionByPtr", python::raw_function(pykd::callFunctionByVar, 1) );
|
python::def( "callFunctionByPtr", python::raw_function(pykd::callFunctionByVar, 1) );
|
||||||
python::def( "callFunctionByAddr", python::raw_function(pykd::callFunctionByOffset, 2) );
|
python::def( "callFunctionByAddr", python::raw_function(pykd::callFunctionByOffset, 2) );
|
||||||
|
python::def( "callFunctionRaw", python::raw_function(pykd::callFunctionRaw, 1) );
|
||||||
|
|
||||||
python::def( "getTypeFromSource", &pykd::getTypeFromSource, getTypeFromSource_( python::args("sourceCode", "typeName", "compileOptions"),
|
python::def( "getTypeFromSource", &pykd::getTypeFromSource, getTypeFromSource_( python::args("sourceCode", "typeName", "compileOptions"),
|
||||||
"Create typeInfo class from C/C++ source code") );
|
"Create typeInfo class from C/C++ source code") );
|
||||||
|
@ -159,6 +159,7 @@ python::list TypeInfoAdapter::getElementDir(kdlib::TypeInfo &typeInfo)
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
python::object callTypedVar(kdlib::TypedVarPtr& funcobj, python::tuple& args)
|
python::object callTypedVar(kdlib::TypedVarPtr& funcobj, python::tuple& args)
|
||||||
{
|
{
|
||||||
kdlib::TypedValue retVal;
|
kdlib::TypedValue retVal;
|
||||||
@ -176,6 +177,30 @@ python::object callTypedVar(kdlib::TypedVarPtr& funcobj, python::tuple& args)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
python::extract<std::wstring> getStrVar(args[i]);
|
||||||
|
if ( getStrVar.check() )
|
||||||
|
{
|
||||||
|
std::wstringstream sstr;
|
||||||
|
|
||||||
|
if ( funcobj->getType()->getElement(i)->getName() == L"Char*" )
|
||||||
|
{
|
||||||
|
std::string strArg = _bstr_t( getStrVar().c_str() );
|
||||||
|
sstr << "Char[" << std::dec << strArg.size() + 1 << ']';
|
||||||
|
argLst.push_back( kdlib::loadTypedVar(sstr.str(), kdlib::getCacheAccessor( strArg.c_str(), strArg.size() + 1 ) ) );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( funcobj->getType()->getElement(i)->getName() == L"WChar*" )
|
||||||
|
{
|
||||||
|
std::wstring strArg = getStrVar();
|
||||||
|
sstr << "WChar[" << std::dec << strArg.size() + 1 << ']';
|
||||||
|
argLst.push_back( kdlib::loadTypedVar(sstr.str(), kdlib::getCacheAccessor( strArg.c_str(), 2*(strArg.size() + 1) ) ) );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw kdlib::TypeException(L"failed convert string argument");
|
||||||
|
}
|
||||||
|
|
||||||
python::extract<kdlib::NumBehavior> getNumVar(args[i]);
|
python::extract<kdlib::NumBehavior> getNumVar(args[i]);
|
||||||
if ( getNumVar.check() )
|
if ( getNumVar.check() )
|
||||||
{
|
{
|
||||||
@ -184,8 +209,15 @@ python::object callTypedVar(kdlib::TypedVarPtr& funcobj, python::tuple& args)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
kdlib::NumVariant var= NumVariantAdaptor::convertToVariant(args[i]);
|
|
||||||
argLst.push_back( var );
|
if ( python::extract<int>(args[i]).check() )
|
||||||
|
{
|
||||||
|
kdlib::NumVariant var= NumVariantAdaptor::convertToVariant(args[i]);
|
||||||
|
argLst.push_back( var );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw kdlib::TypeException(L"failed convert argument");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -227,4 +259,77 @@ python::object callFunctionByOffset( python::tuple& args, python::dict& kwargs)
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
python::object callFunctionRaw( python::tuple& args, python::dict& kwargs)
|
||||||
|
{
|
||||||
|
kdlib::MEMOFFSET_64 funcaddr = python::extract<kdlib::MEMOFFSET_64>(args[0]);
|
||||||
|
|
||||||
|
kdlib::CallingConventionType callingConvention = kdlib::CallingConventionType::CallConv_NearC;
|
||||||
|
|
||||||
|
if ( kwargs.has_key("callingConvention") )
|
||||||
|
callingConvention = python::extract<kdlib::CallingConventionType>(kwargs["callingConvention"]);
|
||||||
|
|
||||||
|
size_t argCount = python::len(args);
|
||||||
|
|
||||||
|
kdlib::TypedValueList argLst;
|
||||||
|
|
||||||
|
for ( size_t i = 0; i < argCount; ++i )
|
||||||
|
{
|
||||||
|
python::extract<kdlib::TypedVarPtr> getTypedVar(args[i]);
|
||||||
|
if ( getTypedVar.check() )
|
||||||
|
{
|
||||||
|
argLst.push_back( getTypedVar() );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
python::extract<std::string> getStrVar(args[i]);
|
||||||
|
if ( getStrVar.check() )
|
||||||
|
{
|
||||||
|
std::string strArg = getStrVar();
|
||||||
|
std::wstringstream sstr;
|
||||||
|
sstr << L"Char[" << std::dec << strArg.size() + 1 << L']';
|
||||||
|
argLst.push_back( kdlib::loadTypedVar(sstr.str(), kdlib::getCacheAccessor( strArg.c_str(), strArg.size() + 1 ) ) );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
python::extract<std::wstring> getWStrVar(args[i]);
|
||||||
|
if ( getWStrVar.check() )
|
||||||
|
{
|
||||||
|
std::wstring strArg = getWStrVar();
|
||||||
|
std::wstringstream sstr;
|
||||||
|
sstr << L"WChar[" << std::dec << strArg.size() + 1 << L']';
|
||||||
|
argLst.push_back( kdlib::loadTypedVar(sstr.str(), kdlib::getCacheAccessor( strArg.c_str(), 2*(strArg.size() + 1) ) ) );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
python::extract<kdlib::NumBehavior> getNumVar(args[i]);
|
||||||
|
if ( getNumVar.check() )
|
||||||
|
{
|
||||||
|
kdlib::NumVariant var = getNumVar();
|
||||||
|
argLst.push_back( var );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( python::extract<int>(args[i]).check() )
|
||||||
|
{
|
||||||
|
kdlib::NumVariant var= NumVariantAdaptor::convertToVariant(args[i]);
|
||||||
|
argLst.push_back( var );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw kdlib::TypeException(L"failed convert argument");
|
||||||
|
}
|
||||||
|
|
||||||
|
kdlib::NumVariant retVal;
|
||||||
|
|
||||||
|
{
|
||||||
|
AutoRestorePyState pystate;
|
||||||
|
retVal = kdlib::callRaw(funcaddr, callingConvention, argLst);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NumVariantAdaptor::convertToPython(retVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
} // pykd namespace
|
} // pykd namespace
|
||||||
|
@ -48,6 +48,8 @@ python::object callFunctionByVar( python::tuple& args, python::dict& kwargs );
|
|||||||
|
|
||||||
python::object callFunctionByOffset( python::tuple& args, python::dict& kwargs);
|
python::object callFunctionByOffset( python::tuple& args, python::dict& kwargs);
|
||||||
|
|
||||||
|
python::object callFunctionRaw( python::tuple& args, python::dict& kwargs);
|
||||||
|
|
||||||
|
|
||||||
inline kdlib::TypeInfoPtr getTypeInfoByName( const std::wstring &name )
|
inline kdlib::TypeInfoPtr getTypeInfoByName( const std::wstring &name )
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
|
|
||||||
import pykd
|
import pykd
|
||||||
|
|
||||||
GENERIC_READ = 0x80000000
|
GENERIC_READ = 0x80000000
|
||||||
@ -27,13 +27,10 @@ def main():
|
|||||||
CreateFileW_Type.append("dwFlagsAndAttributes", DWORD )
|
CreateFileW_Type.append("dwFlagsAndAttributes", DWORD )
|
||||||
CreateFileW_Type.append("hTemplateFile", HANDLE )
|
CreateFileW_Type.append("hTemplateFile", HANDLE )
|
||||||
|
|
||||||
fileNameBuf = pykd.stackAlloc(100)
|
|
||||||
pykd.writeWStr(fileNameBuf, "C:\\temp\\testfile.txt")
|
|
||||||
|
|
||||||
CreateFileW = pykd.typedVar( CreateFileW_Type, kernel32.CreateFileW )
|
CreateFileW = pykd.typedVar( CreateFileW_Type, kernel32.CreateFileW )
|
||||||
|
|
||||||
fileHandle = CreateFileW(
|
fileHandle = CreateFileW(
|
||||||
fileNameBuf,
|
"C:\\temp\\testfile.txt",
|
||||||
GENERIC_READ | GENERIC_WRITE,
|
GENERIC_READ | GENERIC_WRITE,
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
@ -43,7 +40,5 @@ def main():
|
|||||||
|
|
||||||
print "File Handle", hex(fileHandle)
|
print "File Handle", hex(fileHandle)
|
||||||
|
|
||||||
pykd.stackFree(100)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user