/*
**
**
** haspdsd_sample.cpp - Sentinel Run-time Environment Installer sample
**
*/
#include <windows.h>
#include <winbase.h>
#include <stdlib.h>
#include <stdio.h>
#include <process.h>
#include "resource.h"
#include <setupapi.h>
#include "haspds.h"
#include "osdef.h"
#include "haspdsd_sample.h"
/*! \file haspdsd_sample.cpp
\brief HASP RTE Sample
*/
#pragma warning(disable:4201)
#pragma warning (disable:4996)
#ifdef LOG
FILE* srmlogfh;
#endif
#ifdef WIN64
#ifdef LEGACY
#define DLLNAME "hdinst_windows_x64.dll"
#else
#define DLLNAME "haspds_windows_x64.dll"
#endif //LEGACY
#else
#ifdef LEGACY
#define DLLNAME "hdinst_windows.dll"
#else
#define DLLNAME "haspds_windows.dll"
#endif
#endif
extern BOOL GetProductVersion(char * szFile, char * buffer);
#define MESSAGE_STRING_LEN 5000
#define RESTART_MAX_CMD_LINE 100
WCHAR wCmdLine[RESTART_MAX_CMD_LINE];
int NewMessageDisplay(HWND hWnd, HINSTANCE hInst,char* FinalMessageString,DWORD Version);
BYTE HinstallTitle[512];
BYTE OsTitle [512];
BYTE FinalMessageString[ MESSAGE_STRING_LEN ]={{0}};
char UsageMsg[ MESSAGE_STRING_LEN ]={{0}};
BYTE DisplayMessages[ MAX_MSG ]={{0}};
HWND HelphWnd;
HINSTANCE hInst;
HINSTANCE HelphInst;
DWORD endproc = 0;
DWORD ExitCode = 0; /** < in case of errors we exit with exitcode = Status << 16 | Error */
HANDLE hthread1=0;
HASPDS_GETVERSION hhls_GetVersion = 0;
HASPDS_GETLASTERRORMESSAGE hhls_GetLastErrorMessage = 0;
HASPDS_EXITPROCESS hhls_ExitProcess=0;
PRegisterApplicationRestart pRegisterApplicationRestart = NULL;
PUnregisterApplicationRestart pUnregisterApplicationRestart = NULL;
BOOL CALLBACK
InfoDialog( HWND hDlg, UINT message, WPARAM uParam, LPARAM lParam );
void CreateDisplayInfo( HINSTANCE hInstance, HASPDS_INFOEX* HhlInfo,HASPDS_VENDOR_INFO_EX* VendorInfo,DWORD InstVer );
void ArrangeHelp( char *UsageMsg );
#define HASPDS_INSTALL_HLP " - Installs the Sentinel Device Driver."
#define HASPDS_HELP_HLP " - Displays this screen."
#define HASPDS_INFO_HLP " - Lists the driver versions that are installed, and those that are contained in this installer."
#define HASPDS_REMOVE_HLP " - Removes Sentinel Run-time Environment. This switch cannot be used if HASP4 or \n\t\tHardlock legacy drivers are present."
#define HASPDS_KILLPROCESS_HLP " - Enables the installation program to terminate processes accessing the driver."
#define HASPDS_NOMSG_HLP " - Disables message display. No messages are displayed when this switch is used."
#define HASPDS_CRITICALMSG_HLP " - Displays only critical messages, such as failures or reboot instructions."
#define HASPDS_FREMOVE_HLP " - Removes the Sentinel Run-time Environment. Previously installed HASP4 and \n\t\tHardlock drivers will remain on your system but are unusable."
#define HASPDS_VERBOSE_HLP " - Adds extended information in the install logfile."
#define HASPDS_FINSTALL_HLP " - Ignores other Windows installations processes. Relevant only with the -i switch."
#define HASPDS_FSRVSTOP_HLP " - Automatically stops HASP Loader or Hardlock server.Relevant only with the -i switch."
#define HASPDS_CHKLLM_HLP " - Checks for LLM active sesions."
typedef struct ValidArgs{
char* SwitchName;
char* ShortSwitch;
DWORD value;
char* help;
DWORD Mandatory;
DWORD ValidOs;
}VALID_ARGS;
VALID_ARGS ValidArguments[]=
{
{"-install","-i",HASPDS_EXE_PARAM_INSTALL,HASPDS_INSTALL_HLP,1, VALID_OS | WINX64 },
{"-remove","-r",HASPDS_EXE_PARAM_REMOVE,HASPDS_REMOVE_HLP,1,VALID_OS | WINX64},
{"-fremove","-fr",HASPDS_EXE_PARAM_FREMOVE,HASPDS_FREMOVE_HLP,1,VALID_OS | WINX64},
{"-info","-info",HASPDS_EXE_PARAM_INFO,HASPDS_INFO_HLP,1,VALID_OS | WINX64},
{"-help","-h",HASPDS_EXE_PARAM_HELP,HASPDS_HELP_HLP,1,VALID_OS | WINX64},
{"-?","-?",HASPDS_EXE_PARAM_HELP,HASPDS_HELP_HLP,1,VALID_OS},
{"-killprocess","-kp",HASPDS_EXE_PARAM_KILLPROC,HASPDS_KILLPROCESS_HLP,0,VALID_OS_NT | WINX64},
{"-nomsg","-nomsg",HASPDS_EXE_PARAM_NOMSG,HASPDS_NOMSG_HLP,0,VALID_OS | WINX64},
{"-criticalmsg","-cm",HASPDS_EXE_PARAM_CRITMSG,HASPDS_CRITICALMSG_HLP,0,VALID_OS | WINX64},
{"-fi","-fi",HASPDS_EXE_PARAM_FINSTALL,HASPDS_FINSTALL_HLP,0,VALID_OS | WINX64},
{"-getver","-getver",HASPDS_EXE_PARAM_GETVER,NULL,1,VALID_OS | WINX64},
{"-v","-v",HASPDS_EXE_PARAM_VERBOSE,NULL,0,VALID_OS | WINX64},
{"-fss","-fss",HASPDS_EXE_PARAM_FSRVSTOP,HASPDS_FSRVSTOP_HLP,0,VALID_OS | WINX64},
{"-chkllm","-chkllm",HASPDS_EXE_PARAM_CHKLLM,HASPDS_CHKLLM_HLP,0,VALID_OS | WINX64},
{0,0,0,0,0,0}
};
typedef struct ThreadArg{
DWORD Parameters;
haspds_status_t Res;
HWND hWnd;
HINSTANCE hInstance;
HANDLE hThread;
}THREAD_ARG;
DWORD WINAPI InstallProc(LPVOID lpParameter)
{
CHAR TempPath[MAX_PATH]={0};
WCHAR DllPath[MAX_PATH]={0}; // no sample
HASPDS_INSTALL hhls_Install = 0;
HASPDS_INSTALL hhls_UnInstall = 0;
HASPDS_GETINFOEX hhls_GetInfo = 0;
HASPDS_GETVENDORINFO hhls_GetVendorInfo = 0;
HASPDS_GETVENDORINFOEX hhls_GetVendorInfoEx = 0;
HASPDS_SETPARAMETER hhls_SetParaneter = 0;
HASPDS_GETLASTERROR hhls_GetLastError = 0;
HASPDS_GETLLMSESSIONS hhls_GetLlmSessions = 0;
HINSTANCE hhlinstDll=0;
HMODULE SetupApiDll = 0;
PSetupPromptReboot pSetupPromptReboot = NULL;
DWORD Version = 0;
THREAD_ARG* args = (THREAD_ARG*)lpParameter;
haspds_status_t Res=HASPDS_STATUS_SUCCESS,Res1;
DWORD size = 0;
DWORD OSVer = 0;
haspds_error lasterr;
char* Buffer = 0;
char* Buffer1 = 0;
OSVer = hhls_GetSystemVersion();
if( OSVer == 0 ){
Res = HASPDS_STATUS_FAILED;
lasterr = HASPDS_ERR_OS_NOT_SUPPORTED;
strcpy((char*)FinalMessageString,"Operating system not supported.");
goto err_ok;
}
strcat((char*)TempPath, DLLNAME);
hhlinstDll = LoadLibrary(TempPath);
if (!hhlinstDll)
{
Res = HASPDS_STATUS_FAILED;
lasterr = HASPDS_ERR_INVALID_PARAM;
sprintf((char*)FinalMessageString,"Could not find %s",TempPath);
goto err_ok;
}
SetupApiDll = LoadLibrary("setupapi.dll");
if (SetupApiDll == NULL)
{
Res = HASPDS_STATUS_FAILED;
lasterr = HASPDS_ERR_LOAD_LIB;
strcpy((char*)FinalMessageString,"Failed to load setupapi.dll.");
goto err_ok;
}
pSetupPromptReboot = (PSetupPromptReboot)GetProcAddress(SetupApiDll,"SetupPromptReboot");
if (pSetupPromptReboot == NULL)
{
Res = HASPDS_STATUS_FAILED;
lasterr = HASPDS_ERR_FCT_PTR;
strcpy((char*)FinalMessageString,"Failed get pointer to a setupapi.dll function.");
goto err_ok;
}
hhls_Install = (HASPDS_INSTALL)GetProcAddress(hhlinstDll,"haspds_Install");
hhls_UnInstall = (HASPDS_INSTALL)GetProcAddress(hhlinstDll,"haspds_UnInstall");
hhls_GetInfo = (HASPDS_GETINFOEX)GetProcAddress(hhlinstDll,"haspds_GetInfoEx");
hhls_GetVendorInfo = (HASPDS_GETVENDORINFO)GetProcAddress(hhlinstDll,"haspds_GetVendorInfo");
hhls_GetVendorInfoEx = (HASPDS_GETVENDORINFOEX)GetProcAddress(hhlinstDll,"haspds_GetVendorInfoEx");
hhls_GetLastErrorMessage = (HASPDS_GETLASTERRORMESSAGE)GetProcAddress(hhlinstDll,"haspds_GetLastErrorMessage");
hhls_GetVersion = (HASPDS_GETVERSION)GetProcAddress(hhlinstDll,"haspds_GetVersion");
hhls_SetParaneter=(HASPDS_SETPARAMETER)GetProcAddress(hhlinstDll,"haspds_SetParameter");
hhls_GetLastError = (HASPDS_GETLASTERROR)GetProcAddress(h