我正在开发一个代码,它将使用win32 api函数CreateProcess执行另一个exe。
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
STARTUPINFO startupinfo;
PROCESS_INFORMATION process_information;
startupinfo.dwFlags = 0x1;
startupinfo.wShowWindow = 0x0;
startupinfo.cb = sizeof(startupinfo);
if (CreateProcessA ("test.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &startupinfo, &process_information))
{
cout << "[+] We have successfully launched the process\n" ;
cout << "[+] PID: " << process_information.dwProcessId;
WaitForSingleObject(process_information.hProcess, INFINITE);
CloseHandle(process_information.hProcess);
CloseHandle(process_information.hThread);
}
else {
cout << "[-] Error Code: " << GetLastError();
Sleep(3000);
}
return 0;
}
上面的代码就像一个魅力,但我想在这个项目中应用OOP概念。所以我写了......
#include <iostream>
#include <windows.h>
using namespace std;
class CppDBG
{
public:
void load_exe();
};
void CppDBG :: load_exe()
{
STARTUPINFO startupinfo;
PROCESS_INFORMATION process_information;
startupinfo.dwFlags = 0x1;
startupinfo.wShowWindow = 0x0;
startupinfo.cb = sizeof(startupinfo);
if (CreateProcessA ("test.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &startupinfo, &process_information))
{
cout << "[+] We have successfully launched the process\n" ;
cout << "[+] PID: " << process_information.dwProcessId;
WaitForSingleObject(process_information.hProcess, INFINITE);
CloseHandle(process_information.hProcess);
CloseHandle(process_information.hThread);
}
else {
cout << "[-] Error Code: " << GetLastError();
Sleep(3000);
}
}
int main()
{
CppDBG dbg;
dbg.load_exe();
return 0;
}
上面的代码编译正确但运行不正确。
我错过了什么?