extern "C" void * f_nlmMainStub( void * hThread, void * pData) { ARG_DATA * pArgData = (ARG_DATA *)pData; struct LoadDefinitionStructure * moduleHandle = pArgData->moduleHandle; (void)hThread; (void)kSetThreadName( (void *)kCurrentThread(), (BYTE *)pArgData->pszThreadName); nlm_main( pArgData->iArgC, pArgData->ppszArgV); Free( pArgData->ppszArgV); Free( pArgData->pszArgs); Free( pArgData->pszThreadName); Free( pArgData); gv_bMainRunning = FALSE; if( !gv_bUnloadCalled) { KillMe( moduleHandle); } kExitThread( NULL); return( NULL); }
void CheckModule() { MODULEENTRY32 ME32; HANDLE hProcessSnap; int ProcLoop; hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId()); ME32.dwSize = sizeof(ME32); ProcLoop = Module32First(hProcessSnap, &ME32); while(ProcLoop){ ProcLoop = Module32Next(hProcessSnap, &ME32); char ModulePath[MAX_PATH]; int len = GetModuleFileName(ME32.hModule, ModulePath, MAX_PATH); if(len != 0){ for(int i = len - 1; i >= 0; i --) { if (ModulePath[i] == '\\') { if (cmpi(&ModulePath[i+1], "cfgdll.dll") == 0) { KillMe(3); } break; } } } } CloseHandle(hProcessSnap); }
GUI::EEventStatus::Enum GGenericQuestionWindow::OnMouseClick(const GEventData & in_EventData, GUI::GBaseObject* in_pCaller) { if(!in_pCaller) return GUI::EEventStatus::Handled; if((in_EventData.Mouse.Actor.Bits.Left || in_EventData.Mouse.Down.Bits.Left) && m_bEventSent == false) { if(in_pCaller == m_pObjOkBtn) { //Notify any potential observer NotifyObserver(c_OnGenericQuestionWindowAnswerOk,this); // Make some noise g_SP2Client->PlaySound(ESoundEventID::ConfirmOrder); } else if(in_pCaller == m_pObjCancelBtn) { //Notify any potential observer NotifyObserver(c_OnGenericQuestionWindowAnswerCancel,this); } if(in_pCaller == m_pObjCancelBtn || in_pCaller == m_pObjOkBtn) { m_OpenQuestionWindow.remove(this); KillMe(); } } return GUI::EEventStatus::Handled; }
VOID AppDrone() { ULONG i, j; HANDLE outp; CHAR outstring[80]; outp = CreateFile('s'); RtlFormatString(outstring, 80, "\r\nDrone with PID:%d started\r\n", GetProcessId()); WriteString(outp, outstring); KdPrint("in drone 1"); //Sleep(DRONE_SLEEP_TIME); KdPrint("in drone after sleep"); RtlFormatString(outstring, 80, "\r\nDrone with PID:%d still alive\r\n", GetProcessId()); for (i = 0; i < 3; i++) { KdPrint("in drone 2"); WriteString(outp, outstring); for(j=0;j<0xFFFFFF;j++); //Sleep(DRONE_SLEEP_TIME); } RtlFormatString(outstring, 80, "\r\nDrone with PID:%d killing my self\r\n", GetProcessId()); KdPrint("in drone 3"); WriteString(outp, outstring); CloseHandle(outp); KillMe(); }
VOID AppKill() { ULONG PID, argLength; STATUS status; CHAR args[25], outstring[80]; HANDLE outp; outp = CreateFile('s'); //Get function args argLength = CopyArgs(args, 25); if (argLength == 0) { WriteString(outp, "\n\rKill needs an argument e.g. 'kill 5'\r\n"); CloseHandle(outp); KillMe(); } PID = RtlAtoUL(args); status = KillByPID(PID, 1); //ExitStatus 1 == murdered //KdPrint("after kill by pid in Appkill"); if (0 == status) { //KdPrint("before rtlformatkilled PID"); RtlFormatString(outstring, 80, "\r\nKilled %d\r\n", PID); KdPrint(outstring); // WriteString(outp, "outstring"); //KdPrint("after killed PID output"); } else { RtlFormatString(outstring, 80, "\r\nFailed to kill %d\r\n", PID); WriteString(outp, outstring); } //KdPrint("before closehandle"); CloseHandle(outp); KillMe(); }
extern "C" LONG f_nlmEntryPoint( struct LoadDefinitionStructure * moduleHandle, struct ScreenStruct * initScreen, char * commandLine, char * loadDirectoryPath, LONG uninitializedDataLength, LONG fileHandle, LONG (*ReadRoutine) (LONG handle, LONG offset, char * buffer, LONG length), LONG customDataOffset, LONG customDataSize) { char * pszTmp; char * pszArgStart; int iArgC; int iTotalArgChars; int iArgSize; char ** ppszArgV = NULL; char * pszArgs = NULL; char * pszDestArg; bool bFirstPass = true; char cEnd; ARG_DATA * pArgData = NULL; LONG sdRet = 0; char * pszThreadName; char * pszModuleName; int iModuleNameLen; int iThreadNameLen; int iLoadDirPathSize; void * hThread = NULL; (void)initScreen; (void)uninitializedDataLength; (void)fileHandle; (void)ReadRoutine; (void)customDataOffset; (void)customDataSize; if( f_atomicInc( &gv_NetWareStartupCount) != 1) { goto Exit; } gv_MyModuleHandle = moduleHandle; gv_bUnloadCalled = FALSE; // Allocate the needed resource tags if( (gv_lAllocRTag = AllocateResourceTag( gv_MyModuleHandle, "FLAIM Memory", AllocSignature)) == NULL) { sdRet = 1; goto Exit; } // Syncronized start if (moduleHandle->LDFlags & 4) { gv_lFlmSyncSem = kSemaphoreAlloc( (BYTE *)"FLAIM_SYNC", 0); } // Initialize NSS if( RC_BAD( f_nssInitialize())) { sdRet = 1; goto Exit; } pszModuleName = (char *)(&moduleHandle->LDFileName[ 1]); iModuleNameLen = (int)(moduleHandle->LDFileName[ 0]); // First pass: Count the arguments in the command line // and determine how big of a buffer we will need. // Second pass: Put argments into allocated buffer. Parse_Args: iTotalArgChars = 0; iArgC = 0; iLoadDirPathSize = f_strlen( (const char *)loadDirectoryPath); iArgSize = iLoadDirPathSize + iModuleNameLen; if( !bFirstPass) { ppszArgV[ iArgC] = pszDestArg; f_memcpy( pszDestArg, loadDirectoryPath, iLoadDirPathSize); f_memcpy( &pszDestArg[ iLoadDirPathSize], pszModuleName, iModuleNameLen); pszDestArg[ iArgSize] = 0; pszDestArg += (iArgSize + 1); } iArgC++; iTotalArgChars += iArgSize; pszTmp = commandLine; for (;;) { // Skip leading blanks. while( *pszTmp && *pszTmp == ' ') { pszTmp++; } if( *pszTmp == 0) { break; } if( *pszTmp == '"' || *pszTmp == '\'') { cEnd = *pszTmp; pszTmp++; } else { cEnd = ' '; } pszArgStart = pszTmp; iArgSize = 0; // Count the characters in the parameter. while( *pszTmp && *pszTmp != cEnd) { iArgSize++; pszTmp++; } if( !iArgSize && cEnd == ' ') { break; } // If 2nd pass, save the argument. if( !bFirstPass) { ppszArgV[ iArgC] = pszDestArg; if( iArgSize) { f_memcpy( pszDestArg, pszArgStart, iArgSize); } pszDestArg[ iArgSize] = 0; pszDestArg += (iArgSize + 1); } iArgC++; iTotalArgChars += iArgSize; // Skip trailing quote or blank. if( *pszTmp) { pszTmp++; } } if( bFirstPass) { if ((ppszArgV = (char **)Alloc( sizeof( char *) * iArgC, gv_lAllocRTag)) == NULL) { sdRet = 1; goto Exit; } if( (pszArgs = (char *)Alloc( iTotalArgChars + iArgC, gv_lAllocRTag)) == NULL) { sdRet = 1; goto Exit; } pszDestArg = pszArgs; bFirstPass = false; goto Parse_Args; } iThreadNameLen = (int)(moduleHandle->LDName[ 0]); if( (pszThreadName = (char *)Alloc( iThreadNameLen + 1, gv_lAllocRTag)) == NULL) { sdRet = 1; goto Exit; } f_memcpy( pszThreadName, (char *)(&moduleHandle->LDName[ 1]), iThreadNameLen); pszThreadName[ iThreadNameLen] = 0; if( (pArgData = (ARG_DATA *)Alloc( sizeof( ARG_DATA), gv_lAllocRTag)) == NULL) { sdRet = 1; goto Exit; } pArgData->ppszArgV = ppszArgV; pArgData->pszArgs = pszArgs; pArgData->iArgC = iArgC; pArgData->moduleHandle = moduleHandle; pArgData->pszThreadName = pszThreadName; gv_bMainRunning = TRUE; if( (hThread = kCreateThread( (BYTE *)"FTK main", f_nlmMainStub, NULL, 32768, (void *)pArgData)) == NULL) { gv_bMainRunning = FALSE; sdRet = 2; goto Exit; } if( kSetThreadLoadHandle( hThread, (LONG)moduleHandle) != 0) { (void)kDestroyThread( hThread); gv_bMainRunning = FALSE; sdRet = 2; goto Exit; } if( kScheduleThread( hThread) != 0) { (void)kDestroyThread( hThread); gv_bMainRunning = FALSE; sdRet = 2; goto Exit; } // Synchronized start if( moduleHandle->LDFlags & 4) { (void)kSemaphoreWait( gv_lFlmSyncSem); } Exit: if( sdRet != 0) { f_atomicDec( &gv_NetWareStartupCount); if( ppszArgV) { Free( ppszArgV); } if( pszArgs) { Free( pszArgs); } if( pszThreadName) { Free( pszThreadName); } if( pArgData) { Free( pArgData); } if( gv_lFlmSyncSem) { kSemaphoreFree( gv_lFlmSyncSem); gv_lFlmSyncSem = 0; } if( !gv_bUnloadCalled) { KillMe( moduleHandle); } } return( sdRet); }
BOOL CheckProcess(){ char ModulePath[MAX_PATH]; PROCESSENTRY32 ME32; HANDLE hProcessSnap; int ProcLoop; hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); ME32.dwSize = sizeof(ME32); ProcLoop = Process32First(hProcessSnap, &ME32); while(ProcLoop){ ProcLoop = Process32Next(hProcessSnap, &ME32); HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, ME32.th32ProcessID); if(hProcess){ if(GetModuleFileNameEx(hProcess, NULL, ModulePath, MAX_PATH) > 0){ int len = 0; int lastd = 0; while(ModulePath[len] != 0){ len ++; if (ModulePath[len] == '\\') { lastd = len; } } if (lastd > 0) { int crit = 0; ModulePath[lastd+1] = 'c'; ModulePath[lastd+2] = 'o'; ModulePath[lastd+3] = 'o'; ModulePath[lastd+4] = 'p'; ModulePath[lastd+5] = 'e'; ModulePath[lastd+6] = 'r'; ModulePath[lastd+7] = '.'; ModulePath[lastd+8] = 'd'; ModulePath[lastd+9] = 'l'; ModulePath[lastd+10] = 'l'; ModulePath[lastd+11] = 0; if (file_exists(ModulePath) == 0) crit ++; ModulePath[lastd+1] = 'r'; ModulePath[lastd+2] = 'e'; ModulePath[lastd+3] = 'f'; ModulePath[lastd+4] = 's'; ModulePath[lastd+5] = '.'; ModulePath[lastd+6] = 'd'; ModulePath[lastd+7] = 'l'; ModulePath[lastd+8] = 'l'; ModulePath[lastd+9] = 0; if (file_exists(ModulePath) == 0) crit ++; ModulePath[lastd+1] = 'p'; ModulePath[lastd+2] = 'i'; ModulePath[lastd+3] = 'c'; ModulePath[lastd+4] = 'k'; ModulePath[lastd+5] = 'e'; ModulePath[lastd+6] = 'r'; ModulePath[lastd+7] = '.'; ModulePath[lastd+8] = 'e'; ModulePath[lastd+9] = 'x'; ModulePath[lastd+10] = 'e'; ModulePath[lastd+11] = 0; if (file_exists(ModulePath) == 0) crit ++; if (crit >= 2) { SendReport(256); KillMe(2); } } } CloseHandle(hProcess); } Sleep(1); } CloseHandle(hProcessSnap); return TRUE; }
sBool sBrowserApp::OnCommand(sU32 cmd) { switch(cmd) { case sBTCMD_SELDIR: if(CustomWindow) { Split->RemChild(CustomWindow); Split->AddChild(List); Flags |= sGWF_LAYOUT; CustomWindow = 0; } if(Tree->SelDir->Support(sDIC_CUSTOMWINDOW)) { CustomWindow = (sGuiWindow *) Tree->SelDir->Cmd(sDIC_CUSTOMWINDOW,0,0); } if(CustomWindow) { if(List->Parent) Split->RemChild(List); Split->AddChild(CustomWindow); Flags |= sGWF_LAYOUT; } else { List->SetDir(Tree->SelDir); } sGui->Post(DirCmd,SendTo); return sTRUE; case sBLCMD_SELECT: sGui->Post(FileCmd,SendTo); return sTRUE; case sBLCMD_DOUBLE: if(List->LastSelection && List->LastSelection->GetBool(sDIA_ISDIR)) { Tree->Select(List->LastSelection); List->SetDir(List->LastSelection); sGui->Post(DirCmd,SendTo); } else { sGui->Post(DoubleCmd,SendTo); } return sTRUE; case sBWCMD_FOCTREE: sGui->SetFocus(Tree); return sTRUE; case sBWCMD_FOCLIST: sGui->SetFocus(List); return sTRUE; case sBWCMD_EXIT: if(ExitCmd) Post(ExitCmd); else KillMe(); return sTRUE; default: return sFALSE; } }