134 lines
3.9 KiB
Plaintext
134 lines
3.9 KiB
Plaintext
#include <image/pehdr.hpp>
|
|
#include <common/openfile.hpp>
|
|
#include <common/file.hpp>
|
|
|
|
#include <watchdog/watchdogservice.hpp>
|
|
|
|
#include <psapint/psapi.hpp>
|
|
|
|
int PASCAL WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszCmdLine,int nCmdShow)
|
|
{
|
|
|
|
// char *pszCmd=::GetCommandLine();
|
|
|
|
// ::WinExec("D:\\Program Files\\jakarta-tomcat-3.2.1\\bin\\startup.bat",SW_SHOWNORMAL);
|
|
// ::WinExec("D:\\parts\\JBoss-2.2.1\\bin\\run.bat",SW_SHOWNORMAL);
|
|
|
|
/*
|
|
HKLM/Diversified/WatchDog
|
|
name
|
|
apppath
|
|
args
|
|
method
|
|
address
|
|
|
|
|
|
*/
|
|
|
|
|
|
// return 0;
|
|
|
|
ProcessAPI processAPI;
|
|
ProcessInfoList processInfoList;
|
|
ModuleInfoList moduleInfoList;
|
|
|
|
processAPI.enumProcesses(processInfoList);
|
|
|
|
for(int index=0;index<processInfoList.size();index++)
|
|
{
|
|
String str=String("Process:")+processInfoList[index].processID().toString()+String("\n");
|
|
::OutputDebugString(str.str());
|
|
processAPI.enumProcessModules(processInfoList[index].processID(),moduleInfoList);
|
|
|
|
if(moduleInfoList.size())
|
|
{
|
|
String strModuleFileName;
|
|
String strModuleBaseName;
|
|
MODULEINFO moduleInfo;
|
|
HANDLE hProcess;
|
|
processAPI.getModuleFileName(processInfoList[index].processID(),moduleInfoList[0].module(),strModuleFileName);
|
|
processAPI.getModuleBaseName(processInfoList[index].processID(),moduleInfoList[0].module(),strModuleBaseName);
|
|
hProcess=OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,false, processInfoList[index].processID().processID());
|
|
::OutputDebugString(String("ModuleFileName:")+strModuleFileName+String("\n"));
|
|
::OutputDebugString(String("ModuleBaseName:")+strModuleBaseName+String("\n"));
|
|
|
|
FileHandle peFile(strModuleFileName,FileHandle::Read,FileHandle::ShareReadWrite);
|
|
FileMap peMap(peFile);
|
|
PureViewOfFile peView(peMap);
|
|
PEHeader peHeader;
|
|
peHeader<<peView;
|
|
if(!peHeader.isOkay())continue;
|
|
char buffer[128];
|
|
DWORD bytesRead(0);
|
|
// DWORD base=peHeader.dataBase()+peHeader.imageBase();
|
|
// DWORD base=peHeader.imageBase()+peHeader.dataBase();
|
|
// DWORD base=peHeader.dataBase(); // peHeader.imageBase()+
|
|
|
|
DWORD base=0x00132520;
|
|
if(::ReadProcessMemory(hProcess,(const void*)base,buffer,sizeof(buffer),&bytesRead))
|
|
{
|
|
::OutputDebugString("Read success");
|
|
File outFile;
|
|
outFile.open("c:\\image.txt","wb");
|
|
outFile.write(buffer,sizeof(buffer));
|
|
outFile.close();
|
|
}
|
|
::CloseHandle(hProcess);
|
|
|
|
|
|
|
|
|
|
// if(!peHeader.isOkay())return FALSE;
|
|
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
|
|
ServiceControlManager serviceControlManager;
|
|
ServiceHandle service;
|
|
CreateServiceParams createServiceParams;
|
|
String strPathBinaryFile;
|
|
String strCommandLine;
|
|
String serviceName;
|
|
String serviceDisplayName;
|
|
|
|
serviceName="WatchDog";
|
|
serviceDisplayName="WatchDog Service";
|
|
strCommandLine=lpszCmdLine;
|
|
if(strCommandLine=="register")
|
|
{
|
|
::GetModuleFileName(::GetModuleHandle(0),strPathBinaryFile,String::MaxString);
|
|
createServiceParams.setServiceName(serviceName);
|
|
createServiceParams.setDisplayName(serviceDisplayName);
|
|
createServiceParams.setDesiredAccess(SERVICE_ALL_ACCESS);
|
|
createServiceParams.setServiceType(SERVICE_WIN32_OWN_PROCESS);
|
|
createServiceParams.setStartType(SERVICE_AUTO_START);
|
|
createServiceParams.setErrorControl(SERVICE_ERROR_IGNORE);
|
|
createServiceParams.setBinaryPathName(strPathBinaryFile);
|
|
if(!serviceControlManager.createService(createServiceParams,service))
|
|
::OutputDebugString(serviceControlManager.getLastErrorCode()+String("\n"));
|
|
}
|
|
else if(strCommandLine=="unregister")
|
|
{
|
|
if(!serviceControlManager.deleteService(serviceName))
|
|
::OutputDebugString(serviceControlManager.getLastErrorCode()+String("\n"));
|
|
}
|
|
else
|
|
{
|
|
WatchDogService service;
|
|
service.startServiceControlDispatcher(serviceName);
|
|
// Service::getInstance().startServiceControlDispatcher(serviceName);
|
|
|
|
|
|
// Service service;
|
|
// service.startServiceControlDispatcher();
|
|
// if(!serviceControlManager.startService(serviceName))
|
|
// ::OutputDebugString(serviceControlManager.getLastErrorCode()+String("\n"));
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
|