void REEMemoryObject::Write(void* source, size_t size) { SIZE_T size_written; WriteProcessMemory(GetProcessHandle(), GetMemoryInfo(infoMemory)->address, source, size, &size_written); DEBUG_ASSERT(size_written != size); }
void REEMemoryObject::Read(void* dest, size_t size) { SIZE_T size_read; ReadProcessMemory(GetProcessHandle(), GetMemoryInfo(infoMemory)->address, dest, size, &size_read); DEBUG_ASSERT(size_read != size); }
void REEMemoryReservedObject::Write(HREEMEMORY memory, void* source, size_t size) { SIZE_T size_written; WriteProcessMemory(GetProcessHandle(), GetMemoryInfo(memory)->address, source, size, &size_written); DEBUG_ASSERT(size_written != size); }
void REEMemoryReservedObject::Read(HREEMEMORY memory, void* dest, size_t size) { SIZE_T size_read; ReadProcessMemory(GetProcessHandle(), GetMemoryInfo(memory)->address, dest, size, &size_read); DEBUG_ASSERT(size_read != size); }
void KillProcessByName(const char* filename){ DWORD dwProcessID = 0; HANDLE hProcess = GetProcessHandle(filename, &dwProcessID); DWORD dwExitCode = 0; if(hProcess!=NULL){ GetExitCodeProcess(hProcess,&dwExitCode); TerminateProcess(hProcess, dwExitCode); CloseHandle(hProcess); } }
void REEMemoryReservedObject::Distroy() { DEBUG_ASSERT(!VirtualFreeEx( GetProcessHandle(), infoReserved.address, infoReserved.size, MEM_RELEASE)); return; }
void REEMemoryReservedObject::Distroy(HREEMEMORY memory) { REE_MEMORY_INFO* info = GetMemoryInfo(memory); DEBUG_ASSERT(!VirtualFreeEx( GetProcessHandle(), info->address, info->size, MEM_DECOMMIT)); DistroyMemoryInfo(info); }
REEMemoryObject::REEMemoryObject(REEFactoryObject* parent, size_t size) { this->parent = parent; void* AllocMem = VirtualAllocEx( GetProcessHandle(), nullptr, size, DEFAULT_MEMORY_FLAG, DEFAULT_PAGE_FLAG); DEBUG_ASSERT(!AllocMem); this->infoMemory = CreateMemoryInfo(AllocMem, size); }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static char szAppName[] = "OSK-Launcher"; HWND hwnd; MSG msg; WNDCLASSEX wndclass; wndclass.cbSize = sizeof(wndclass); wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = szAppName; wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); RegisterClassEx(&wndclass); hwnd = CreateWindow(szAppName, "The Hello Program", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 300, 200, NULL, NULL, hInstance, NULL); mainHwnd = hwnd; ShowWindow(hwnd, iCmdShow); UpdateWindow(hwnd); ShellExecute(NULL, "open", "C:\\Program\\Click-N-Type\\Click-N-Type.exe", "", "", SW_SHOW); HANDLE hProcess; do { hProcess = GetProcessHandle("Click-N-Type.exe"); Sleep(1); } while (hProcess == NULL); if (!DllInject(hProcess, "C:\\Tobbe\\DevProjects\\C++\\CnTSkin\\Debug\\InjectionDLL.dll")) { MessageBox(HWND_DESKTOP, "An error occurred injecting DLL!", "Error!", MB_OK | MB_ICONERROR); } while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; }
void REEMemoryReservedObject::Allocate(HREEMEMORY* memory, size_t index, size_t size) { void* memoryAddr = VirtualAllocEx( GetProcessHandle(), ADD_ADDRESS(GetReservedMemory(), index), size, DEFAULT_MEMORY_COMMIT_FLAG, DEFAULT_PAGE_FLAG); HREEMEMORY memoryObject = (HREEMEMORY)CreateMemoryInfo(memoryAddr, size); *memory = memoryObject; }
REEMemoryReservedObject::REEMemoryReservedObject(REEFactoryObject* parent, size_t size) { this->parent = parent; void* preAllocMem = VirtualAllocEx( GetProcessHandle(), nullptr, size, DEFAULT_RESERVE_MEMORY_FLAG, DEFAULT_RESERVE_PAGE_FLAG); DEBUG_ASSERT(!preAllocMem); infoReserved = CreateMemoryInfo(preAllocMem, size); }
BOOL IsProcessActive(char * processName) { HANDLE hPrc = NULL; BOOL bRet = FALSE; DWORD dwRet = 0; if(NULL == processName) return bRet; hPrc = GetProcessHandle(processName); if(hPrc == NULL ) return bRet; if(GetExitCodeProcess(hPrc, &dwRet)) { if(dwRet == STILL_ACTIVE) bRet = TRUE; } CloseHandle(hPrc); return bRet; }
BOOL GetSysLogonUserName(char * userNameBuf, unsigned int bufLen) { BOOL bRet = FALSE; if(userNameBuf == NULL || bufLen <= 0) return bRet; { HANDLE eplHandle = NULL; eplHandle = GetProcessHandle("explorer.exe"); if(eplHandle) { if(GetProcessUsername(eplHandle, userNameBuf, bufLen)) { bRet = TRUE; } } if(eplHandle) CloseHandle(eplHandle); } return bRet; }
BOOL GetProcessMemoryUsageKB(char * processName, long * memUsageKB) { BOOL bRet = FALSE; HANDLE hPrc = NULL; PROCESS_MEMORY_COUNTERS pmc; if(NULL == processName || NULL == memUsageKB) return FALSE; hPrc =GetProcessHandle(processName); memset(&pmc, 0, sizeof(pmc)); if (GetProcessMemoryInfo(hPrc, &pmc, sizeof(pmc))) { *memUsageKB = (long)(pmc.WorkingSetSize/DIV); bRet = TRUE; } CloseHandle(hPrc); return bRet; }
//--------------------------------------------------------------------------- void __fastcall TMainForm::Terminate1Click(TObject *Sender){ if (MessageBox(NULL, "You really want to stop functioning(working) the process?", "Elaborate", MB_OKCANCEL) == IDOK) Terminate(GetProcessHandle());}
//--------------------------------------------------------------------------- void __fastcall TMainForm::Searchagain1Click(TObject *Sender){ if ( GetProcessHandle() != 0 ){ SearchForm->Caption = "Search again options"; SearchForm->RadioGroup->Enabled = FALSE; SearchForm->Show();}}
void REEMemoryObject::Distroy() { DEBUG_ASSERT(!VirtualFreeEx(GetProcessHandle())); }
// // Run in thread for each vertex // unsigned DVertexXComputePnController::CommandLoop() { DrError err; UInt32 retries = 0; // // Get the vertex label // DrStr64 label; DVertexCommandBlock::GetPnPropertyLabel(&label, m_vertexId, m_vertexVersion); // // Wait for communication until error // do { // // Create request to get vertex version property // XC_SETANDGETPROCESSINFO_REQINPUT request; memset(&request, 0, sizeof(request)); request.Size = sizeof(request); request.pBlockOnPropertyLabel = label.GetString(); request.BlockOnPropertyversionLastSeen = m_currentCommandVersion; request.MaxBlockTime = XCTIMEINTERVAL_MINUTE; // XXXX request.pPropertyFetchTemplate = (char *) label.GetString(); // // Send the request and check for errors // PXC_SETANDGETPROCESSINFO_REQRESULTS pResults = NULL; err = XcSetAndGetProcessInfo(GetProcessHandle(), &request, &pResults, NULL); if (err == DrError_OK) { // // If request successfully sent, store process status and exit code // DrLogI( "Got command property"); retries = 0; DrError processStatus = pResults->pProcessInfo->ProcessStatus; DrExitCode exitCode = pResults->pProcessInfo->ExitCode; if (processStatus == DrError_OK || exitCode != DrExitCode_StillActive) { // // If the PN thinks we have exited, so better make it so // err = DrError_Fail; } } // // If request was successful and other process doesn't think we're done // if (err == DrError_OK) { if (pResults->pProcessInfo->NumberofProcessProperties != 0) { // // Make sure there's only one property and it's the version // LogAssert(pResults->pProcessInfo-> NumberofProcessProperties == 1); PXC_PROCESSPROPERTY_INFO property = pResults->pProcessInfo->ppProperties[0]; LogAssert(::strcmp(property->pPropertyLabel, label) == 0); // // Update vertex version // UInt64 newVersion = property->PropertyVersion; if (newVersion < m_currentCommandVersion) { // // If vertex version is less than the current version, fail (logic error) // DrLogE( "Property version went back in time. Property %s old version %I64u new version %I64u", label.GetString(), m_currentCommandVersion, newVersion); err = DrError_ProcessPropertyVersionMismatch; } else if (newVersion == m_currentCommandVersion) { // // If version the same, report version the same // DrLogI( "Command timeout with same version. Property %s version %I64u", label.GetString(), m_currentCommandVersion); } else if (newVersion > m_currentCommandVersion) { // // If new vertex version, let GM know what process is handling it // DrLogI( "Property got new version. Property %s old version %I64u new version %I64u", label.GetString(), m_currentCommandVersion, newVersion); m_currentCommandVersion = newVersion; DrRef<DVertexCommandBlock> newCommand; newCommand.Attach(new DVertexCommandBlock()); DrRef<DryadXComputePnProcessPropertyResponse> response; response.Attach(new DryadXComputePnProcessPropertyResponse(pResults->pProcessInfo)); // // Get new vertex command // err = newCommand->ReadFromResponseMessage(response, m_vertexId, m_vertexVersion); // // If no errors in getting command, act on it. Log any failures below // if (err == DrError_OK) { err = ActOnCommand(newCommand); } } } } else { // // Log error and continue // DrLogE( "XcSetAndGetProcessInfo got error: %s", DRERRORSTRING(err)); } // // If the error is related to disconnection, retry up to 4 times // if (err == DrError_RemoteDisconnected || err == DrError_LocalDisconnected || err == DrError_ConnectionFailed || err == DrError_ResponseDisconnect) { ++retries; // todo: move 4 to global if (retries < 4) { DrLogW( "Retrying get"); err = DrError_OK; } } // // If result was allocated, free it before next iteration // if (pResults != NULL) { XCERROR freeError = XcFreeMemory(pResults); LogAssert(freeError == DrError_OK); } } while (err == DrError_OK); // // Close this controller and take no more requests // DrLogD( "About to terminate"); Terminate(err, DrExitCode_Fail); // // Sleep forever, waiting for verticies to complete and take down the process // Sleep(INFINITE); return 0; }
//--------------------------------------------------------------------------- void __fastcall TMainForm::Information1Click(TObject *Sender){ProcessInfoCreate(GetProcessHandle());}
void ThreadContextInfo::SetValidCallTargetForCFG(PVOID callTargetAddress, bool isSetValid) { #ifdef _CONTROL_FLOW_GUARD if (IsCFGEnabled()) { #ifdef _M_ARM AssertMsg(((uintptr_t)callTargetAddress & 0x1) != 0, "on ARM we expect the thumb bit to be set on anything we use as a call target"); AssertMsg(IS_16BYTE_ALIGNED((uintptr_t)callTargetAddress & ~0x1), "callTargetAddress is not 16-byte page aligned?"); #else AssertMsg(IS_16BYTE_ALIGNED(callTargetAddress), "callTargetAddress is not 16-byte page aligned?"); #endif // If SetProcessValidCallTargets is not allowed by global policy (e.g. // OOP JIT is in use in the client), then generate a fast fail // exception as state has been corrupted and attempt is being made to // illegally call SetProcessValidCallTargets. if (!GlobalSecurityPolicy::IsSetProcessValidCallTargetsAllowed()) { RaiseFailFastException(nullptr, nullptr, FAIL_FAST_GENERATE_EXCEPTION_ADDRESS); } PVOID startAddressOfPage = (PVOID)(PAGE_START_ADDR(callTargetAddress)); size_t codeOffset = OFFSET_ADDR_WITHIN_PAGE(callTargetAddress); CFG_CALL_TARGET_INFO callTargetInfo[1]; callTargetInfo[0].Offset = codeOffset; callTargetInfo[0].Flags = (isSetValid ? CFG_CALL_TARGET_VALID : 0); AssertMsg((size_t)callTargetAddress - (size_t)startAddressOfPage <= AutoSystemInfo::PageSize - 1, "Only last bits corresponding to PageSize should be masked"); AssertMsg((size_t)startAddressOfPage + (size_t)codeOffset == (size_t)callTargetAddress, "Wrong masking of address?"); BOOL isCallTargetRegistrationSucceed = GetWinCoreMemoryLibrary()->SetProcessCallTargets(GetProcessHandle(), startAddressOfPage, AutoSystemInfo::PageSize, 1, callTargetInfo); if (!isCallTargetRegistrationSucceed) { DWORD gle = GetLastError(); if (gle == ERROR_COMMITMENT_LIMIT) { //Throw OOM, if there is not enough virtual memory for paging (required for CFG BitMap) Js::Throw::OutOfMemory(); } else if (gle == ERROR_ACCESS_DENIED) { // When this error is set, the target process may be exiting and thus cannot proceed with // JIT output. Throw this exception to safely abort this call. throw Js::OperationAbortedException(); } else { Js::Throw::InternalError(); } } #if DBG if (isSetValid && !JITManager::GetJITManager()->IsOOPJITEnabled()) { _guard_check_icall((uintptr_t)callTargetAddress); } if (PHASE_TRACE1(Js::CFGPhase)) { if (!isSetValid) { Output::Print(_u("DEREGISTER:")); } Output::Print(_u("CFGRegistration: StartAddr: 0x%p , Offset: 0x%x, TargetAddr: 0x%x \n"), (char*)startAddressOfPage, callTargetInfo[0].Offset, ((size_t)startAddressOfPage + (size_t)callTargetInfo[0].Offset)); Output::Flush(); } #endif } #endif // _CONTROL_FLOW_GUARD }
// // Send updated status to vertex service // void DVertexXComputePnController:: SendSetStatusRequest(DryadPnProcessPropertyRequest* r) { // // Cast request to required type and make sure it's valid // DVertexXComputeSetStatus* request = dynamic_cast<DVertexXComputeSetStatus*>(r); LogAssert(request != NULL); // // Wrap request in XComputeSetStatusOverlapped // XComputeSetStatusOverlapped* overlapped = new XComputeSetStatusOverlapped(request); // // Create asynchronous execution information // XC_ASYNC_INFO asyncInfo; memset(&asyncInfo, 0, sizeof(asyncInfo)); asyncInfo.cbSize = sizeof(asyncInfo); asyncInfo.pOperationState = overlapped->GetOperationState(); asyncInfo.IOCP = g_dryadNativePort->GetCompletionPort(); asyncInfo.pOverlapped = overlapped->GetOverlapped(); // // Update request counters // request->IncrementSendCount(); g_dryadNativePort->IncrementOutstandingRequests(); // // Update process info // XCERROR err = XcSetAndGetProcessInfo(GetProcessHandle(), request->MarshalProperty(), request->GetResults(), &asyncInfo); LogAssert(err != DrError_OK); if (err != HRESULT_FROM_WIN32(ERROR_IO_PENDING)) { // // If failed (other than due to pending IO) log failure and update request counter // g_dryadNativePort->DecrementOutstandingRequests(); // // If request assertion true, report errors as warnings, otherwise report as error and fail // todo: this still seems backwards - need to figure out rational // request handles retries itself // if (request->IsAssert()) { DrLogW( "Status request send failed synchronously during assert: not asserting again. done %u send tries, error %s", request->GetSendCount(), DRERRORSTRING(err)); } else { DrLogA( "Status request send failed synchronously. done %u send tries, error %s", request->GetSendCount(), DRERRORSTRING(err)); } delete overlapped; } }