This commit is contained in:
2024-08-07 09:16:27 -04:00
parent fdfadd5c7e
commit 5f971cf684
5200 changed files with 731717 additions and 0 deletions

19
service/EventLog.cpp Normal file
View File

@@ -0,0 +1,19 @@
#include <service/EventLog.hpp>
bool EventLog::open(const String &strSourceName,const String &strServerName)
{
close();
mServerName=strServerName;
mSourceName=strSourceName;
if(!mSourceName.length())mSourceName="Application";
mhEventLog=::RegisterEventSource(mServerName.isNull()?0:mServerName.str(),mSourceName.isNull()?0:mSourceName.str());
return isOkay();
}
bool EventLog::reportEvent(const String &strMessage,EventType eventType,DWORD eventID,WORD category,PSID userSID)
{
char const *str[]={strMessage.str()};
if(!isOkay()||!strMessage.length())return false;
return ::ReportEvent(mhEventLog,int(eventType),category,eventID,userSID,1,0,str,0)?true:false;
}

63
service/EventLog.hpp Normal file
View File

@@ -0,0 +1,63 @@
#ifndef _SERVICE_EVENTLOG_HPP_
#define _SERVICE_EVENTLOG_HPP_
#ifndef _COMMON_STRING_HPP_
#include <common/string.hpp>
#endif
class EventLog
{
public:
enum EventType{Error=EVENTLOG_ERROR_TYPE,Warning=EVENTLOG_WARNING_TYPE,Information=EVENTLOG_INFORMATION_TYPE};
EventLog(void);
virtual ~EventLog();
bool open(const String &strSourceName=String(),const String &strServerName=String());
void close(void);
bool reportEvent(const String &strMessage,EventType eventType=Error,DWORD eventID=0,WORD category=0,PSID userSID=0);
bool isOkay(void)const;
private:
enum {MaxNameLength=256};
EventLog &operator=(const EventLog &eventLog);
EventLog(const EventLog &eventLog);
HANDLE mhEventLog;
String mServerName;
String mSourceName;
};
inline
EventLog::EventLog(void)
: mhEventLog(0)
{
}
inline
EventLog::EventLog(const EventLog &/*eventLog*/)
{ // private implementation
}
inline
EventLog::~EventLog()
{
close();
}
inline
EventLog &EventLog::operator=(const EventLog &/*eventLog*/)
{ // private implementation
return *this;
}
inline
void EventLog::close(void)
{
if(!mhEventLog)return;
::DeregisterEventSource(mhEventLog);
mhEventLog=0;
}
inline
bool EventLog::isOkay(void)const
{
return mhEventLog?true:false;
}
#endif

110
service/GenericService.cpp Normal file
View File

@@ -0,0 +1,110 @@
#include <service/GenericService.hpp>
#include <service/ServiceStatus.hpp>
GenericService::GenericService(void)
: mhServiceHandle(0), mState(Stopped)
{
}
GenericService::GenericService(const GenericService &/*someGenericService*/)
{ // private implementation
}
GenericService::~GenericService()
{
}
GenericService &GenericService::operator=(const GenericService &/*someGenericService*/)
{ // private implementation
return *this;
}
bool GenericService::startService(const String &strServiceName)
{
SERVICE_TABLE_ENTRY serviceEntry[2];
bool result;
::memset(&serviceEntry,0,sizeof(serviceEntry));
mServiceName=strServiceName;
mEventLog.open(mServiceName);
serviceEntry[0].lpServiceName=(char*)mServiceName;
serviceEntry[0].lpServiceProc=getServiceMainBase();
result=::StartServiceCtrlDispatcher(&serviceEntry[0])?true:false;
if(!result){::OutputDebugString("<GenericService::startService> StartServiceCtrlDispatcher(FAILED)\n");return false;}
::OutputDebugString("<GenericService::startService> StartServiceCtrlDispatcher(OK)\n");
return true;
}
void GenericService::svcMain(DWORD dwArg,LPTSTR *lpszArg)
{
ServiceStatus serviceStatus(SERVICE_WIN32_OWN_PROCESS,SERVICE_START_PENDING,SERVICE_ACCEPT_PAUSE_CONTINUE|SERVICE_ACCEPT_STOP|SERVICE_ACCEPT_SHUTDOWN,NO_ERROR,NO_ERROR,0,WaitHint);
mhServiceHandle=::RegisterServiceCtrlHandler(mServiceName,getServiceHandlerBase());
if(!mhServiceHandle)return;
serviceMain(dwArg,lpszArg);
}
void GenericService::svcHandler(DWORD dwControl)
{
switch(dwControl)
{
case SERVICE_CONTROL_STOP :
::OutputDebugString("<GenericService::serviceHandler> (OK)\n");
ctrlStop();
break;
case SERVICE_CONTROL_PAUSE :
::OutputDebugString("<GenericService::serviceHandler> (OK)\n");
ctrlPause();
break;
case SERVICE_CONTROL_CONTINUE :
::OutputDebugString("<GenericService::serviceHandler> (OK)\n");
ctrlContinue();
break;
case SERVICE_CONTROL_INTERROGATE :
::OutputDebugString("<GenericService::serviceHandler> (OK)\n");
ctrlInterrogate();
break;
case SERVICE_CONTROL_SHUTDOWN :
::OutputDebugString("<GenericService::serviceHandler> (OK)\n");
ctrlShutdown();
break;
}
}
// virtuals
void GenericService::serviceMain(DWORD dwArg,LPTSTR *lpszArg)
{
ServiceStatus serviceStatus(SERVICE_WIN32_OWN_PROCESS,SERVICE_RUNNING,SERVICE_ACCEPT_PAUSE_CONTINUE|SERVICE_ACCEPT_STOP|SERVICE_ACCEPT_SHUTDOWN,NO_ERROR,NO_ERROR,0,0);
setServiceStatus(serviceStatus);
while(Stopped!=state()){::Sleep(1000);}
return;
}
void GenericService::ctrlStop(void)
{
ServiceStatus serviceStatus(SERVICE_WIN32_OWN_PROCESS,SERVICE_STOPPED,SERVICE_ACCEPT_PAUSE_CONTINUE|SERVICE_ACCEPT_STOP|SERVICE_ACCEPT_SHUTDOWN,NO_ERROR,NO_ERROR,0,0);
setServiceStatus(serviceStatus);
}
void GenericService::ctrlPause(void)
{
ServiceStatus serviceStatus(SERVICE_WIN32_OWN_PROCESS,SERVICE_PAUSED,SERVICE_ACCEPT_PAUSE_CONTINUE|SERVICE_ACCEPT_STOP|SERVICE_ACCEPT_SHUTDOWN,NO_ERROR,NO_ERROR,0,0);
setServiceStatus(serviceStatus);
}
void GenericService::ctrlContinue(void)
{
ServiceStatus serviceStatus(SERVICE_WIN32_OWN_PROCESS,SERVICE_RUNNING,SERVICE_ACCEPT_PAUSE_CONTINUE|SERVICE_ACCEPT_STOP|SERVICE_ACCEPT_SHUTDOWN,NO_ERROR,NO_ERROR,0,0);
setServiceStatus(serviceStatus);
}
void GenericService::ctrlShutdown(void)
{
ServiceStatus serviceStatus(SERVICE_WIN32_OWN_PROCESS,SERVICE_STOPPED,SERVICE_ACCEPT_PAUSE_CONTINUE|SERVICE_ACCEPT_STOP|SERVICE_ACCEPT_SHUTDOWN,NO_ERROR,NO_ERROR,0,0);
setServiceStatus(serviceStatus);
}
void GenericService::ctrlInterrogate(void)
{
ServiceStatus serviceStatus(SERVICE_WIN32_OWN_PROCESS,state(),SERVICE_ACCEPT_PAUSE_CONTINUE|SERVICE_ACCEPT_STOP|SERVICE_ACCEPT_SHUTDOWN,NO_ERROR,NO_ERROR,0,0);
setServiceStatus(serviceStatus);
}

103
service/GenericService.hpp Normal file
View File

@@ -0,0 +1,103 @@
#ifndef _SERVICE_GENERICSERVICE_HPP_
#define _SERVICE_GENERICSERVICE_HPP_
#ifndef _COMMON_STRING_HPP_
#include <common/string.hpp>
#endif
#ifndef _COMMON_WINSVC_HPP_
#include <common/winsvc.hpp>
#endif
#ifndef _SERVICE_SERVICEHOOK_HPP_
#include <service/ServiceHook.hpp>
#endif
#ifndef _SERVICE_SERVICESTATUS_HPP_
#include <service/ServiceStatus.hpp>
#endif
#ifndef _SERVICE_EVENTLOG_HPP_
#include <service/EventLog.hpp>
#endif
class GenericService : private ServiceHook
{
public:
enum State{Paused,Running,Stopped};
GenericService(void);
virtual ~GenericService();
bool setServiceStatus(const ServiceStatus &serviceStatus);
bool startService(const String &strServiceName);
bool isOkay(void)const;
bool isPaused(void)const;
bool isRunning(void)const;
bool isStopped(void)const;
State state(void)const;
bool reportEvent(const String &strMessage,EventLog::EventType eventType,DWORD eventID=0,DWORD category=0,PSID userSID=0);
protected:
virtual void serviceMain(DWORD dwArgc,LPTSTR *lpszArg);
virtual void ctrlStop(void);
virtual void ctrlPause(void);
virtual void ctrlContinue(void);
virtual void ctrlInterrogate(void);
virtual void ctrlShutdown(void);
private:
enum{WaitHint=5000};
GenericService(const GenericService &someGenericService);
GenericService &operator=(const GenericService &someGenericService);
virtual void svcMain(DWORD dwArg,LPTSTR *lpszArg);
virtual void svcHandler(DWORD dwControl);
void state(State state);
SERVICE_STATUS_HANDLE mhServiceHandle;
String mServiceName;
EventLog mEventLog;
State mState;
};
inline
bool GenericService::isOkay(void)const
{
return mhServiceHandle?true:false;
}
inline
GenericService::State GenericService::state(void)const
{
return mState;
}
inline
void GenericService::state(State state)
{
mState=state;
}
inline
bool GenericService::isPaused(void)const
{
return Paused==state();
}
inline
bool GenericService::isRunning(void)const
{
return Running==state();
}
inline
bool GenericService::isStopped(void)const
{
return Stopped==state();
}
inline
bool GenericService::setServiceStatus(const ServiceStatus &serviceStatus)
{
if(!isOkay())return false;
state(State(serviceStatus.currentState()));
return ::SetServiceStatus(mhServiceHandle,&((ServiceStatus&)serviceStatus).getSERVICESTATUS())?true:false;
}
inline
bool GenericService::reportEvent(const String &strMessage,EventLog::EventType eventType,DWORD eventID,DWORD category,PSID userSID)
{
return mEventLog.reportEvent(strMessage,eventType,eventID,category,userSID);
}
#endif

60
service/ServiceHook.hpp Normal file
View File

@@ -0,0 +1,60 @@
#ifndef _SERVICE_SERVICEHOOK_HPP_
#define _SERVICE_SERVICEHOOK_HPP_
#ifndef _HOOKPROC_APIENTRY_HPP_
#include <hookproc/apientry.hpp>
#endif
#ifndef _HOOKPROC_PROCADDRESS_HPP_
#include <hookproc/procaddr.hpp>
#endif
class ServiceHook;
typedef ProcAddress<ServiceHook> ServiceHookProc;
class ServiceHook : private ServiceHookProc
{
public:
typedef void (__stdcall *LPFNSERVICEMAIN)(DWORD dwArgc,LPTSTR *lpszArg);
typedef void (__stdcall *LPFNSERVICEHANDLER)(DWORD dwControl);
ServiceHook(void);
virtual ~ServiceHook();
LPFNSERVICEMAIN getServiceMainBase(void)const;
LPFNSERVICEHANDLER getServiceHandlerBase(void)const;
protected:
virtual void svcMain(DWORD dwArgc,LPTSTR *lpszArg);
virtual void svcHandler(DWORD dwControl);
private:
enum {ParamLength=8};
enum {ServiceMainParamLength=8,ServiceHandlerParamLength=4};
ServiceHook &operator=(const ServiceHook &someServiceHook);
void serviceMainEntryProc(DWORD dwArgc,LPTSTR *lpszArg);
void serviceHandlerEntryProc(DWORD dwControl);
APIEntry mServiceMainEntry;
APIEntry mServiceHandlerEntry;
};
inline
ServiceHook::ServiceHook(void)
: mServiceMainEntry(ServiceMainParamLength,(DWORD)this,getProcAddress((ProcAddress<ServiceHook>::LPFNMETHODVOID)&ServiceHook::serviceMainEntryProc)),
mServiceHandlerEntry(ServiceHandlerParamLength,(DWORD)this,getProcAddress((ProcAddress<ServiceHook>::LPFNMETHODVOID)&ServiceHook::serviceHandlerEntryProc))
{
}
inline
ServiceHook &ServiceHook::operator=(const ServiceHook &someServiceHook)
{ // private implementation
return *this;
}
inline
ServiceHook::LPFNSERVICEMAIN ServiceHook::getServiceMainBase(void)const
{
return (LPFNSERVICEMAIN)mServiceMainEntry.codeBase();
}
inline
ServiceHook::LPFNSERVICEHANDLER ServiceHook::getServiceHandlerBase(void)const
{
return (LPFNSERVICEHANDLER)mServiceHandlerEntry.codeBase();
}
#endif

View File

@@ -0,0 +1,91 @@
#include <service/ServiceManager.hpp>
#include <common/regkey.hpp>
ServiceManager::ServiceManager()
: mhServiceControl(0)
{
open();
}
ServiceManager::~ServiceManager()
{
close();
}
bool ServiceManager::open(void)
{
close();
mhServiceControl=::OpenSCManager(0,0,SC_MANAGER_CONNECT|SC_MANAGER_CREATE_SERVICE|SC_MANAGER_ENUMERATE_SERVICE|GENERIC_READ|GENERIC_WRITE);
return isOkay();
}
void ServiceManager::close(void)
{
if(!isOkay())return;
::CloseServiceHandle(mhServiceControl);
mhServiceControl=0;
}
bool ServiceManager::createService(const String &strServiceName,const String &strDisplayName,const String &strBinPath,const String &strAccountName,const String &strPassword)
{
SC_HANDLE hService;
if(!isOkay())return false;
hService=::CreateService(mhServiceControl,strServiceName,strDisplayName,
SERVICE_ALL_ACCESS|GENERIC_READ|GENERIC_WRITE,
SERVICE_WIN32_OWN_PROCESS,SERVICE_AUTO_START,SERVICE_ERROR_NORMAL,strBinPath,
0,0,0,0,0);
if(!hService)return false;
::CloseServiceHandle(hService);
createEventLogEntry(strServiceName,strBinPath);
return true;
}
bool ServiceManager::deleteService(const String &strServiceName)
{
SC_HANDLE hService;
bool returnCode;
if(!isOkay())return false;
hService=::OpenService(mhServiceControl,strServiceName,SERVICE_ALL_ACCESS);
if(!hService)return false;
returnCode=::DeleteService(hService)?true:false;
::CloseServiceHandle(hService);
removeEventLogEntry(strServiceName);
return returnCode;
}
void ServiceManager::createEventLogEntry(const String &strServiceName,const String &strBinPath)
{
RegKey regKey(RegKey::LocalMachine);
String strTopLevelKey("SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application");
String strKeyName;
if(strServiceName.isNull())return;
strKeyName=strTopLevelKey+String("\\")+strServiceName;
if(!regKey.openKey(strKeyName))
{
if(!regKey.createKey(strKeyName,""))return;
if(!regKey.openKey(strKeyName))return;
}
regKey.setValue("EventMessageFile",strBinPath);
regKey.setValue("TypesSupported",7);
regKey.closeKey();
}
void ServiceManager::removeEventLogEntry(const String &strServiceName)
{
RegKey regKey(RegKey::LocalMachine);
String strTopLevelKey("SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application");
if(strServiceName.isNull())return;
if(!regKey.openKey(strTopLevelKey))return;
regKey.deleteKey(strServiceName);
}
bool ServiceManager::isOkay(void)const
{
return mhServiceControl?true:false;
}

View File

@@ -0,0 +1,26 @@
#ifndef _TRANSACTIONSERVER_SERVICEMANAGER_H_
#define _TRANSACTIONSERVER_SERVICEMANAGER_H_
#ifndef _COMMON_STRING_HPP_
#include <common/string.hpp>
#endif
#ifndef _COMMON_WINSVC_HPP_
#include <common/winsvc.hpp>
#endif
class ServiceManager
{
public:
ServiceManager();
virtual ~ServiceManager();
bool createService(const String &strServiceName,const String &strDisplayName,const String &strBinPath,const String &strAccountName=String(),const String &strPassword=String());
bool deleteService(const String &strServiceName);
bool isOkay(void)const;
private:
void createEventLogEntry(const String &strServiceName,const String &strBinPath);
void removeEventLogEntry(const String &strServiceName);
bool open(void);
void close(void);
SC_HANDLE mhServiceControl;
};
#endif

156
service/ServiceStatus.hpp Normal file
View File

@@ -0,0 +1,156 @@
#ifndef _SERVICE_SERVICESTATUS_HPP_
#define _SERVICE_SERVICESTATUS_HPP_
#ifndef _COMMON_WINSVC_HPP_
#include <common/winsvc.hpp>
#endif
class ServiceStatus : private SERVICE_STATUS
{
public:
ServiceStatus(void);
ServiceStatus(DWORD svcType,DWORD svcState,DWORD ctlsAccept,DWORD w32Exit,DWORD svcExit,DWORD ckPoint,DWORD waitHint);
virtual ~ServiceStatus();
DWORD serviceType(void)const;
void serviceType(DWORD serviceType);
DWORD currentState(void)const;
void currentState(DWORD currentState);
DWORD controlsAccepted(void)const;
void controlsAccepted(DWORD controlsAccepted);
DWORD win32ExitCode(void)const;
void win32ExitCode(DWORD win32ExitCode);
DWORD serviceExitCode(void)const;
void serviceExitCode(DWORD serviceExitCode);
DWORD checkPoint(void)const;
void checkPoint(DWORD checkPoint);
DWORD waitHint(void)const;
void waitHint(DWORD waitHint);
SERVICE_STATUS &getSERVICESTATUS(void);
private:
void zeroInit(void);
};
inline
ServiceStatus::ServiceStatus(void)
{
zeroInit();
}
inline
ServiceStatus::ServiceStatus(DWORD svcType,DWORD svcState,DWORD ctlsAccept,DWORD w32Exit,DWORD svcExit,DWORD ckPoint,DWORD waitHint)
{
SERVICE_STATUS::dwServiceType=svcType;
SERVICE_STATUS::dwCurrentState=svcState;
SERVICE_STATUS::dwControlsAccepted=ctlsAccept;
SERVICE_STATUS::dwWin32ExitCode=w32Exit;
SERVICE_STATUS::dwServiceSpecificExitCode=svcExit;
SERVICE_STATUS::dwCheckPoint=ckPoint;
SERVICE_STATUS::dwWaitHint=waitHint;
}
inline
ServiceStatus::~ServiceStatus()
{
}
inline
DWORD ServiceStatus::serviceType(void)const
{
return SERVICE_STATUS::dwServiceType;
}
inline
void ServiceStatus::serviceType(DWORD serviceType)
{
SERVICE_STATUS::dwServiceType=serviceType;
}
inline
DWORD ServiceStatus::currentState(void)const
{
return SERVICE_STATUS::dwCurrentState;
}
inline
void ServiceStatus::currentState(DWORD currentState)
{
SERVICE_STATUS::dwCurrentState=currentState;
}
inline
DWORD ServiceStatus::controlsAccepted(void)const
{
return SERVICE_STATUS::dwControlsAccepted;
}
inline
void ServiceStatus::controlsAccepted(DWORD controlsAccepted)
{
SERVICE_STATUS::dwControlsAccepted=controlsAccepted;
}
inline
DWORD ServiceStatus::win32ExitCode(void)const
{
return SERVICE_STATUS::dwWin32ExitCode;
}
inline
void ServiceStatus::win32ExitCode(DWORD win32ExitCode)
{
SERVICE_STATUS::dwWin32ExitCode=win32ExitCode;
}
inline
DWORD ServiceStatus::serviceExitCode(void)const
{
return SERVICE_STATUS::dwServiceSpecificExitCode;
}
inline
void ServiceStatus::serviceExitCode(DWORD serviceExitCode)
{
SERVICE_STATUS::dwServiceSpecificExitCode=serviceExitCode;
}
inline
DWORD ServiceStatus::checkPoint(void)const
{
return SERVICE_STATUS::dwCheckPoint;
}
inline
void ServiceStatus::checkPoint(DWORD checkPoint)
{
SERVICE_STATUS::dwCheckPoint=checkPoint;
}
inline
DWORD ServiceStatus::waitHint(void)const
{
return SERVICE_STATUS::dwWaitHint;
}
inline
void ServiceStatus::waitHint(DWORD waitHint)
{
SERVICE_STATUS::dwWaitHint=waitHint;
}
inline
SERVICE_STATUS &ServiceStatus::getSERVICESTATUS(void)
{
return *this;
}
inline
void ServiceStatus::zeroInit(void)
{
SERVICE_STATUS::dwServiceType=0;
SERVICE_STATUS::dwCurrentState=0;
SERVICE_STATUS::dwControlsAccepted=0;
SERVICE_STATUS::dwWin32ExitCode=0;
SERVICE_STATUS::dwServiceSpecificExitCode=0;
SERVICE_STATUS::dwCheckPoint=0;
SERVICE_STATUS::dwWaitHint=0;
}
#endif

133
service/scraps.txt Normal file
View File

@@ -0,0 +1,133 @@
#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;
}

108
service/service.dsp Normal file
View File

@@ -0,0 +1,108 @@
# Microsoft Developer Studio Project File - Name="service" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
CFG=service - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "service.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "service.mak" CFG="service - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "service - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "service - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "service - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "service - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD CPP /nologo /Gz /Zp8 /MTd /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /D "STRICT" /D "__FLAT__" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo /out:"..\exe\service.lib"
!ENDIF
# Begin Target
# Name "service - Win32 Release"
# Name "service - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\EventLog.cpp
# End Source File
# Begin Source File
SOURCE=.\GenericService.cpp
# End Source File
# Begin Source File
SOURCE=.\servicehook.cpp
# End Source File
# Begin Source File
SOURCE=.\ServiceManager.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# End Target
# End Project

29
service/service.dsw Normal file
View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "service"=.\service.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

BIN
service/service.opt Normal file

Binary file not shown.

33
service/service.plg Normal file
View File

@@ -0,0 +1,33 @@
<html>
<body>
<pre>
<h1>Build Log</h1>
<h3>
--------------------Configuration: service - Win32 Debug--------------------
</h3>
<h3>Command Lines</h3>
Creating temporary file "C:\WINNT\Profiles\sean\LOCALS~1\Temp\RSP1C.tmp" with contents
[
/nologo /Gz /MTd /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /D "STRICT" /D "__FLAT__" /Fp"Debug/service.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c
"D:\work\service\EventLog.cpp"
"D:\work\service\GenericService.cpp"
"D:\work\service\servicehook.cpp"
"D:\work\service\ServiceManager.cpp"
]
Creating command line "cl.exe @C:\WINNT\Profiles\sean\LOCALS~1\Temp\RSP1C.tmp"
Creating command line "link.exe -lib /nologo /out:"..\exe\service.lib" .\Debug\EventLog.obj .\Debug\GenericService.obj .\Debug\servicehook.obj .\Debug\ServiceManager.obj "
<h3>Output Window</h3>
Compiling...
EventLog.cpp
GenericService.cpp
servicehook.cpp
ServiceManager.cpp
Creating library...
<h3>Results</h3>
service.lib - 0 error(s), 0 warning(s)
</pre>
</body>
</html>

30
service/servicehook.cpp Normal file
View File

@@ -0,0 +1,30 @@
#include <service/ServiceHook.hpp>
#include <common/string.hpp>
ServiceHook::~ServiceHook()
{
}
void ServiceHook::serviceMainEntryProc(DWORD dwArgc,LPTSTR *lpszArg)
{
svcMain(dwArgc,lpszArg);
}
void ServiceHook::serviceHandlerEntryProc(DWORD dwControl)
{
svcHandler(dwControl);
}
// *** virtuals
void ServiceHook::svcMain(DWORD dwArgc,LPTSTR *lpszArg)
{
::OutputDebugString("ServiceHook::serviceMain\n");
return;
}
void ServiceHook::svcHandler(DWORD dwControl)
{
::OutputDebugString("ServiceHook::serviceHandler\n");
return;
}