Commit 8b380051 authored by wanli's avatar wanli

更新测试用例

parent 5907af94
Pipeline #585 canceled with stages
__pycache__ __pycache__
*.pro.* *.pro.*
\ No newline at end of file *.xlsx
\ No newline at end of file
...@@ -125,4 +125,7 @@ static PyObject* PyInit_emb(void) # 模块初始化函数 ...@@ -125,4 +125,7 @@ static PyObject* PyInit_emb(void) # 模块初始化函数
# 增加模块: # 增加模块:
PyImport_AppendInittab("emb", &PyInit_emb); # 增加一个模块 PyImport_AppendInittab("emb", &PyInit_emb); # 增加一个模块
``` ```
\ No newline at end of file
## 参考链接
+ https://docs.python.org/zh-cn/3.8/c-api/index.html
\ No newline at end of file
...@@ -31,12 +31,7 @@ class dedecms_get_webshell: ...@@ -31,12 +31,7 @@ class dedecms_get_webshell:
def check(self, site, port): def check(self, site, port):
print("Exploiting Host:%s, Port:(%d)......" % (site, port)) print("Exploiting Host:%s, Port:(%d)......" % (site, port))
flag = 1 flag = 1
if flag: content = {"flag": flag, "content": "POST http://www.baidu.com/shell.php (cmd)"}
content = {"flag": 1,
"content": "POST http://www.baidu.com/shell.php (cmd)"}
else:
content = {"flag": 0,
"content": "POST http://www.baidu.com/shell.php (cmd)"}
return content return content
......
...@@ -5,13 +5,14 @@ void getCurrentEnv() ...@@ -5,13 +5,14 @@ void getCurrentEnv()
{ {
PyRun_SimpleString("import sys"); PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append('./')"); PyRun_SimpleString("sys.path.append('./')");
return;
} }
int main(int argc, const char* argv[]) int main(int argc, const char* argv[])
{ {
printf("argc => %d \r\n", argc); printf("argc => %d \r\n", argc);
printf("argv => %s \r\n", *argv); printf("argv => %s \r\n\r\n", *argv);
printf("%s \r\n\r\n", Py_GetVersion());
test_SimpleString(); // 执行一行python脚本语句 test_SimpleString(); // 执行一行python脚本语句
test_CallFunction(); // repl 一条语句一条语句地执行 test_CallFunction(); // repl 一条语句一条语句地执行
......
...@@ -7,13 +7,13 @@ void test_CallModuleClass() { ...@@ -7,13 +7,13 @@ void test_CallModuleClass() {
getCurrentEnv(); getCurrentEnv();
PyObject *pModule = NULL, *pDict = NULL, *pClass = NULL, *pInstance = NULL, *result = NULL; PyObject *pModule = NULL, *pDict = NULL, *pClass = NULL, *pInstance = NULL, *result = NULL;
pModule = PyImport_ImportModule("demo"); // 引入模块 pModule = PyImport_ImportModule("demo"); // 引入模块
pDict = PyModule_GetDict(pModule); // 获取模块字典属性 pDict = PyModule_GetDict(pModule); // 获取模块字典属性
pClass = PyDict_GetItemString(pDict, "Class_A"); // 通过字典属性获取模块中的类 pClass = PyDict_GetItemString(pDict, "Class_A"); // 通过字典属性获取模块中的类
pInstance = PyObject_CallObject(pClass, NULL); // 实例化获取的类 pInstance = PyObject_CallObject(pClass, NULL); // 实例化获取的类
result = PyObject_CallMethod(pInstance, "func", "(s)", "python_000"); // 调用类的方法 result = PyObject_CallMethod(pInstance, "func", "(s)", "python_xxx"); // 调用类的方法
char* name = NULL; char* name = NULL;
PyArg_Parse(result, "s", &name); // 将python类型的返回值转换为c/c++类型 PyArg_Parse(result, "s", &name); // 将python类型的返回值转换为c/c++类型
printf("%s\n", name); printf("%s\n", name);
Py_Finalize(); Py_Finalize();
......
...@@ -6,7 +6,6 @@ void test_CallModuleClassReturnTuple() { ...@@ -6,7 +6,6 @@ void test_CallModuleClassReturnTuple() {
Py_Initialize(); Py_Initialize();
getCurrentEnv(); getCurrentEnv();
PyObject *pModule = NULL, *pDict = NULL,*pClass = NULL, *pInstance = NULL, *result = NULL; PyObject *pModule = NULL, *pDict = NULL,*pClass = NULL, *pInstance = NULL, *result = NULL;
pModule =PyImport_ImportModule("demo"); // 引入模块 pModule =PyImport_ImportModule("demo"); // 引入模块
pDict = PyModule_GetDict(pModule); // 获取模块字典属性 pDict = PyModule_GetDict(pModule); // 获取模块字典属性
......
...@@ -7,10 +7,10 @@ void test_CallModuleFunction() { ...@@ -7,10 +7,10 @@ void test_CallModuleFunction() {
getCurrentEnv(); getCurrentEnv();
PyObject *pModule = NULL, *pFunc = NULL, *pArg = NULL; PyObject *pModule = NULL, *pFunc = NULL, *pArg = NULL;
pModule = PyImport_ImportModule("demo"); // 引入模块 pModule = PyImport_ImportModule("demo"); // 引入模块
pFunc = PyObject_GetAttrString(pModule, "print_arg");// 直接获取模块中的函数 pFunc = PyObject_GetAttrString(pModule, "print_arg"); // 直接获取模块中的函数
pArg = Py_BuildValue("(s)", "hello_python"); // 參数类型转换,传递一个字符串。将c/c++类型的字符串转换为python类型。元组中的python类型查看python文档 pArg = Py_BuildValue("(s)", "hello_python"); // 參数类型转换,传递一个字符串。将c/c++类型的字符串转换为python类型。元组中的python类型查看python文档
PyEval_CallObject(pFunc, pArg); // 调用直接获得的函数。并传递參数 PyEval_CallObject(pFunc, pArg); // 调用直接获得的函数。并传递參数
Py_Finalize(); Py_Finalize();
......
...@@ -8,13 +8,13 @@ void test_CallModuleFunctionByParameters() { ...@@ -8,13 +8,13 @@ void test_CallModuleFunctionByParameters() {
getCurrentEnv(); getCurrentEnv();
PyObject *pModule = NULL, *pDict = NULL, *pFunc = NULL, *pArg = NULL, *result = NULL; PyObject *pModule = NULL, *pDict = NULL, *pFunc = NULL, *pArg = NULL, *result = NULL;
pModule = PyImport_ImportModule("demo"); // 引入模块 pModule = PyImport_ImportModule("demo"); // 引入模块
pDict = PyModule_GetDict(pModule); // 获取模块字典属性 //相当于Python模块对象的__dict__ 属性,得到模块名称空间下的字典对象 pDict = PyModule_GetDict(pModule); // 获取模块字典属性 //相当于Python模块对象的__dict__ 属性,得到模块名称空间下的字典对象
pFunc = PyDict_GetItemString(pDict, "add"); // 从字典属性中获取函数 pFunc = PyDict_GetItemString(pDict, "add"); // 从字典属性中获取函数
pArg = Py_BuildValue("(i, i)", 1, 2); // 參数类型转换,传递两个整型參数 pArg = Py_BuildValue("(i, i)", 1, 2); // 參数类型转换,传递两个整型參数
result = PyEval_CallObject(pFunc, pArg); // 调用函数。并得到python类型的返回值 result = PyEval_CallObject(pFunc, pArg); // 调用函数。并得到python类型的返回值
int sum; int sum;
PyArg_Parse(result, "i", &sum); // 将python类型的返回值转换为c/c++类型 PyArg_Parse(result, "i", &sum); // 将python类型的返回值转换为c/c++类型
printf("sum = %d\n", sum); printf("sum = %d\n", sum);
Py_Finalize(); Py_Finalize();
......
...@@ -8,7 +8,7 @@ void test_CallPythonFunction(void) { ...@@ -8,7 +8,7 @@ void test_CallPythonFunction(void) {
// Py_SetPythonHome(L"D:/Anaconda3"); // Py_SetPythonHome(L"D:/Anaconda3");
Py_Initialize(); Py_Initialize();
getCurrentEnv(); getCurrentEnv(); // 设置当前python工作路径,也就是告诉python去哪里加载python文件
// Create some Python objects that will later be assigned values. // Create some Python objects that will later be assigned values.
PyObject *pModule, *pDict, *pFunc_add, *pFunc_hello, *pArgs, *pValue, *pValue2; PyObject *pModule, *pDict, *pFunc_add, *pFunc_hello, *pArgs, *pValue, *pValue2;
......
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