void CreateConsole() { AllocConsole(); HANDLE lStdHandle = GetStdHandle(STD_OUTPUT_HANDLE); int hConHandle = _open_osfhandle(PtrToUlong((ULONG)lStdHandle), _O_TEXT); FILE* fp = _fdopen(hConHandle, "w"); *stdout = *fp; setvbuf(stdout, NULL, _IONBF, 0); lStdHandle = GetStdHandle(STD_INPUT_HANDLE); hConHandle = _open_osfhandle(PtrToUlong((ULONG)lStdHandle), _O_TEXT); fp = _fdopen(hConHandle, "r"); *stdin = *fp; setvbuf(stdin, NULL, _IONBF, 0); lStdHandle = GetStdHandle(STD_ERROR_HANDLE); hConHandle = _open_osfhandle(PtrToUlong((ULONG)lStdHandle), _O_TEXT); fp = _fdopen(hConHandle, "w"); *stderr = *fp; setvbuf(stderr, NULL, _IONBF, 0); ::SetConsoleMode( lStdHandle, ENABLE_ECHO_INPUT ); char szStr[64] = {0}; sprintf_s( szStr, "vIrtuaL W0rLd - Build: %s %s", __DATE__, __TIME__ ); SetConsoleTitleA( szStr ); }
static bool /* knows nothing about records! Only about input buffers */ get_input_bytes(RECSTREAM *rstrm, char *addr, int len) { size_t current; if (rstrm->nonblock) { if (len > (int)(rstrm->in_boundry - rstrm->in_finger)) return false; memcpy(addr, rstrm->in_finger, (size_t) len); rstrm->in_finger += len; return true; } while (len > 0) { current = (size_t) (PtrToUlong(rstrm->in_boundry) - PtrToUlong(rstrm->in_finger)); if (current == 0) { if (!fill_input_buf(rstrm)) return (false); continue; } current = (len < current) ? len : current; memmove(addr, rstrm->in_finger, current); rstrm->in_finger += current; addr += current; len -= current; } return (true); }
DWORD WINAPI BlockedThreadHandler(PVOID pvParam) { HANDLE hParentThread; DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &hParentThread, 0, FALSE, DUPLICATE_SAME_ACCESS); HANDLE handles[3]; DWORD threadID1; handles[0] = CreateThread(NULL, 0, SimpleThreadHandler, hParentThread, 0, &threadID1); DWORD threadID2; handles[1] = CreateThread(NULL, 0, SimpleThreadHandler, hParentThread, 0, &threadID2); DWORD threadID3; handles[2] = CreateThread(NULL, 0, SimpleThreadHandler, hParentThread, 0, &threadID3); _tprintf(TEXT("LockThreads = %u\n"), GetCurrentThreadId()); _tprintf(TEXT(" thread1 = %u (0x%x)\n"), threadID1, PtrToUlong(handles[0])); _tprintf(TEXT(" thread2 = %u (0x%x)\n"), threadID2, PtrToUlong(handles[1])); _tprintf(TEXT(" thread3 = %u (0x%x)\n"), threadID3, PtrToUlong(handles[2])); Sleep(100); // Note: WaitForMultipleObjects is not handled by WCT WaitForMultipleObjects(3, handles, TRUE, INFINITE); //WaitForSingleObject(handles[0], INFINITE); _tprintf(TEXT("LockThreads is over\n")); return(0); }
void CreateConsole(const char *winTitle) { //http://www.gamedev.net/community/forums/viewreply.asp?ID=1958358 int hConHandle = 0; HANDLE lStdHandle = 0; FILE *fp = 0 ; AllocConsole(); if(winTitle) SetConsoleTitleA(winTitle); // redirect unbuffered STDOUT to the console lStdHandle = GetStdHandle(STD_OUTPUT_HANDLE); hConHandle = _open_osfhandle(PtrToUlong(lStdHandle), _O_TEXT); fp = _fdopen(hConHandle, "w"); *stdout = *fp; setvbuf(stdout, NULL, _IONBF, 0); // redirect unbuffered STDIN to the console lStdHandle = GetStdHandle(STD_INPUT_HANDLE); hConHandle = _open_osfhandle(PtrToUlong(lStdHandle), _O_TEXT); fp = _fdopen(hConHandle, "r"); *stdin = *fp; setvbuf(stdin, NULL, _IONBF, 0); // redirect unbuffered STDERR to the console lStdHandle = GetStdHandle(STD_ERROR_HANDLE); hConHandle = _open_osfhandle(PtrToUlong(lStdHandle), _O_TEXT); fp = _fdopen(hConHandle, "w"); *stderr = *fp; setvbuf(stderr, NULL, _IONBF, 0); }
VOID FollowNPC_Enable(PBYTE pFollowNpc1, PBYTE pFollowNpc2, PBYTE pFollowFaction, PFLOAT pFollowNPCDistance, BOOL bEnable) { DWORD dwOldProtect; if(pFollowNpc1 && pFollowNpc2 && VirtualProtect(pFollowNpc1, PtrToUlong(pFollowNpc2) - PtrToUlong(pFollowNpc1) + 1, PAGE_EXECUTE_READWRITE, &dwOldProtect)) { if(bEnable) { if(pFollowNpc1[0] != 0x90) { memcpy(g_bFollowNpcBackup1, pFollowNpc1, sizeof(g_bFollowNpcBackup1)); memcpy(g_bFollowNpcBackup2, pFollowNpc2, sizeof(g_bFollowNpcBackup2)); } memcpy(pFollowNpc1, g_bNop, sizeof(g_bFollowNpcBackup1)); memcpy(pFollowNpc2, g_bNop, sizeof(g_bFollowNpcBackup2)); } else { if(pFollowNpc1[0] == 0x90) { memcpy(pFollowNpc1, g_bFollowNpcBackup1, sizeof(g_bFollowNpcBackup1)); memcpy(pFollowNpc2, g_bFollowNpcBackup2, sizeof(g_bFollowNpcBackup2)); } } VirtualProtect(pFollowNpc1, PtrToUlong(pFollowNpc2) - PtrToUlong(pFollowNpc1) + 1, dwOldProtect, &dwOldProtect); } if(pFollowFaction && VirtualProtect(pFollowFaction, sizeof(g_bFollowNpcBackup3), PAGE_EXECUTE_READWRITE, &dwOldProtect)) { if(bEnable) { if(pFollowFaction[0] != 0x90) { memcpy(g_bFollowNpcBackup3, pFollowFaction, sizeof(g_bFollowNpcBackup3)); } memcpy(pFollowFaction, g_bNop, sizeof(g_bFollowNpcBackup3)); } else { if(pFollowFaction[0] == 0x90) { memcpy(pFollowFaction, g_bFollowNpcBackup3, sizeof(g_bFollowNpcBackup3)); } } VirtualProtect(pFollowFaction, sizeof(g_bFollowNpcBackup3), dwOldProtect, &dwOldProtect); } if(pFollowNPCDistance && VirtualProtect(pFollowNPCDistance, sizeof(FLOAT), PAGE_READWRITE, &dwOldProtect)) { if(bEnable) { *(PDWORD)pFollowNPCDistance = 0x7F800000; } else { *pFollowNPCDistance = 900; } VirtualProtect(pFollowNPCDistance, sizeof(FLOAT), dwOldProtect, &dwOldProtect); } }
/****************************************************************** * DrvSetPrinterData (GDI.281) * */ DWORD WINAPI DrvSetPrinterData16(LPSTR lpPrinter, LPSTR lpProfile, DWORD lpType, LPBYTE lpPrinterData, DWORD dwSize) { LPSTR RegStr_Printer; HKEY hkey = 0; DWORD res = 0; if (HIWORD(lpPrinter)) TRACE("printer %s\n",lpPrinter); else TRACE("printer %p\n",lpPrinter); if (HIWORD(lpProfile)) TRACE("profile %s\n",lpProfile); else TRACE("profile %p\n",lpProfile); TRACE("lpType %08x\n",lpType); if ((!lpPrinter) || (!lpProfile) || (PtrToUlong(lpProfile) == INT_PD_DEFAULT_MODEL) || (HIWORD(lpProfile) && (!strcmp(lpProfile, PrinterModel)))) return ERROR_INVALID_PARAMETER; RegStr_Printer = HeapAlloc(GetProcessHeap(), 0, strlen(Printers) + strlen(lpPrinter) + 2); strcpy(RegStr_Printer, Printers); strcat(RegStr_Printer, lpPrinter); if ((PtrToUlong(lpProfile) == INT_PD_DEFAULT_DEVMODE) || (HIWORD(lpProfile) && (!strcmp(lpProfile, DefaultDevMode)))) { if ( RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey) != ERROR_SUCCESS || RegSetValueExA(hkey, DefaultDevMode, 0, REG_BINARY, lpPrinterData, dwSize) != ERROR_SUCCESS ) res = ERROR_INVALID_PRINTER_NAME; } else { strcat(RegStr_Printer, "\\"); if( (res = RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)) == ERROR_SUCCESS ) { if (!lpPrinterData) res = RegDeleteValueA(hkey, lpProfile); else res = RegSetValueExA(hkey, lpProfile, 0, lpType, lpPrinterData, dwSize); } } if (hkey) RegCloseKey(hkey); HeapFree(GetProcessHeap(), 0, RegStr_Printer); return res; }
VOID scanSendChatMessage_ScanProc(INT iItem, HWND hwndDlg, PBYTE pbFile) { PIMAGE_NT_HEADERS pNtHdr = PIMAGE_NT_HEADERS(pbFile + PIMAGE_DOS_HEADER(pbFile)->e_lfanew); PIMAGE_SECTION_HEADER pSecHdr = PIMAGE_SECTION_HEADER(pNtHdr + 1); PBYTE pbCode = RvaToPointer(pbFile, pSecHdr[0].VirtualAddress); DWORD dwCodeSize = pSecHdr[0].SizeOfRawData; PBYTE pbRData = RvaToPointer(pbFile, pSecHdr[1].VirtualAddress); DWORD dwRDataSize = pSecHdr[1].SizeOfRawData; PBYTE pbData = RvaToPointer(pbFile, pSecHdr[2].VirtualAddress); DWORD dwDataSize = pSecHdr[2].SizeOfRawData; SetItemStatus(iItem, hwndDlg, "Scanning..."); // scan data section for "Unknown chat type" for(DWORD dwDataIndex = 0; dwDataIndex < dwDataSize - (sizeof("Unknown chat type") - 1); dwDataIndex++) { if(MemoryCompare(&pbData[dwDataIndex], (PBYTE)"Unknown chat type", sizeof("Unknown chat type") - 1)) { // calculate va of found string DWORD dwStringVA = OffsetToRva(pbFile, PtrToUlong(pbData) + dwDataIndex - PtrToUlong(pbFile)); if(dwStringVA) { dwStringVA += pNtHdr->OptionalHeader.ImageBase; // scan code section for 'push dwStringVA' for(DWORD dwCodeIndex = 0; dwCodeIndex < dwCodeSize - 8; dwCodeIndex++) { if(pbCode[dwCodeIndex] == 0x68 && *((PDWORD)&pbCode[dwCodeIndex + 1]) == dwStringVA) { // find beginning of procedure for(DWORD dwCodeIndex2 = dwCodeIndex & 0xFFFFFFF0; dwCodeIndex2; dwCodeIndex2 -= 0x10) { if(pbCode[dwCodeIndex2 - 1] == 0x90 || pbCode[dwCodeIndex2 - 1] == 0xC3 || pbCode[dwCodeIndex2 - 3] == 0xC2) { DWORD dwProcRva = OffsetToRva(pbFile, PtrToUlong(pbCode) + dwCodeIndex2 - PtrToUlong(pbFile)); if(dwProcRva) { GetPPD(iItem, hwndDlg)->dwValue = dwProcRva + pNtHdr->OptionalHeader.ImageBase; SetItemStatus(iItem, hwndDlg, "Success"); return; } } } } } } } } GetPPD(iItem, hwndDlg)->dwValue = 0; SetItemStatus(iItem, hwndDlg, "Fail"); }
static NTSTATUS XenUsb_CompleteXenbusInit(PXENUSB_DEVICE_DATA xudd) { PUCHAR ptr; USHORT type; PCHAR setting, value, value2; ULONG i; ptr = xudd->config_page; while((type = GET_XEN_INIT_RSP(&ptr, (PVOID)&setting, (PVOID)&value, (PVOID)&value2)) != XEN_INIT_TYPE_END) { switch(type) { case XEN_INIT_TYPE_RING: /* frontend ring */ FUNCTION_MSG("XEN_INIT_TYPE_RING - %s = %p\n", setting, value); if (strcmp(setting, "urb-ring-ref") == 0) { xudd->urb_sring = (usbif_urb_sring_t *)value; FRONT_RING_INIT(&xudd->urb_ring, xudd->urb_sring, PAGE_SIZE); } if (strcmp(setting, "conn-ring-ref") == 0) { xudd->conn_sring = (usbif_conn_sring_t *)value; FRONT_RING_INIT(&xudd->conn_ring, xudd->conn_sring, PAGE_SIZE); } break; case XEN_INIT_TYPE_EVENT_CHANNEL_DPC: /* frontend event channel */ FUNCTION_MSG("XEN_INIT_TYPE_EVENT_CHANNEL_DPC - %s = %d\n", setting, PtrToUlong(value) & 0x3FFFFFFF); if (strcmp(setting, "event-channel") == 0) { xudd->event_channel = PtrToUlong(value); } break; case XEN_INIT_TYPE_READ_STRING_BACK: case XEN_INIT_TYPE_READ_STRING_FRONT: FUNCTION_MSG("XEN_INIT_TYPE_READ_STRING - %s = %s\n", setting, value); break; default: FUNCTION_MSG("XEN_INIT_TYPE_%d\n", type); break; } } if (xudd->urb_sring == NULL || xudd->conn_sring == NULL || xudd->event_channel == 0) { FUNCTION_MSG("Missing settings\n"); FUNCTION_EXIT(); return STATUS_BAD_INITIAL_PC; } stack_new(&xudd->req_id_ss, REQ_ID_COUNT); for (i = 0; i < REQ_ID_COUNT; i++) { put_id_on_freelist(xudd->req_id_ss, (uint16_t)i); } return STATUS_SUCCESS; }
LRESULT CALLBACK DemoApp::s_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { DemoApp *pThis; LRESULT lRet = 0; if (uMsg == WM_NCCREATE) { LPCREATESTRUCT pcs = reinterpret_cast<LPCREATESTRUCT> (lParam); pThis = reinterpret_cast<DemoApp *> (pcs->lpCreateParams); SetWindowLongPtr(hWnd, GWLP_USERDATA, PtrToUlong(pThis)); lRet = DefWindowProc(hWnd, uMsg, wParam, lParam); } else { pThis = reinterpret_cast<DemoApp *> (GetWindowLongPtr(hWnd, GWLP_USERDATA)); if (pThis) { lRet = pThis->WndProc(hWnd, uMsg, wParam, lParam); } else { lRet = DefWindowProc(hWnd, uMsg, wParam, lParam); } } return lRet; }
LRESULT CALLBACK SnakeD2D::WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { LRESULT result = 0; bool wasHandled = false; if (message == WM_CREATE) { LPCREATESTRUCT pcs = (LPCREATESTRUCT)lParam; SnakeD2D *app = (SnakeD2D*)pcs->lpCreateParams; ::SetWindowLongPtrW( hwnd, GWLP_USERDATA, PtrToUlong(app) ); } else { SnakeD2D *app = reinterpret_cast<SnakeD2D *>(static_cast<LONG_PTR>( ::GetWindowLongPtrW( hwnd, GWLP_USERDATA ))); switch(message) { case WM_KEYDOWN: switch(wParam) { case VK_ESCAPE: PostQuitMessage(0); break; default: break; } wasHandled = true; break; default: break; case WM_PAINT: ValidateRect(hwnd, nullptr); // avoid new wm_paint messages wasHandled = true; result = 0; break; case WM_SIZE: { UINT width = LOWORD(lParam); UINT height = HIWORD(lParam); app->OnResize(width, height); } result = 0; wasHandled = true; break; } } if(!wasHandled) result = DefWindowProc(hwnd, message, wParam, lParam); return result; }
void LockCriticalSections() { InitializeCriticalSection(&cs1); InitializeCriticalSection(&cs2); DWORD threadID1; CreateThread(NULL, 0, LockCriticalSectionHandler, (PVOID)1, 0, &threadID1); DWORD threadID2; CreateThread(NULL, 0, LockCriticalSectionHandler, (PVOID)2, 0, &threadID2); _tprintf(TEXT("LockCriticalSections:\n")); _tprintf(TEXT(" thread1 = %u\n"), threadID1); _tprintf(TEXT(" thread2 = %u\n"), threadID2); _tprintf(TEXT(" &cs1 = 0x%x\n"), PtrToUlong(&cs1)); _tprintf(TEXT(" &cs2 = 0x%x\n"), PtrToUlong(&cs2)); }
LRESULT CALLBACK ControlPadWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { if (Msg == WM_CREATE) { // Pointer to a value to be passed to the window through // the CREATESTRUCT structure is out window object instance. LPCREATESTRUCT pcs = (LPCREATESTRUCT)lParam; ControlPad* pCtrlPad = static_cast<ControlPad*>(pcs->lpCreateParams); // Store the pointer as private data of the window ::SetWindowLongPtr(hWnd, GWLP_USERDATA, PtrToUlong(pCtrlPad)); pCtrlPad->Attach(hWnd); pCtrlPad->OnCreate(); return 0; } // Extract the pointer to out window object ControlPad* pCtrlPad = static_cast<ControlPad*>(UlongToPtr(::GetWindowLongPtr(hWnd, GWLP_USERDATA))); if (pCtrlPad) { pCtrlPad->WindowProc(Msg, wParam, lParam); } return DefWindowProc(hWnd, Msg, wParam, lParam); }
PPH_STRING PhGetServiceNameFromTag( _In_ HANDLE ProcessId, _In_ PVOID ServiceTag ) { static PQUERY_TAG_INFORMATION I_QueryTagInformation = NULL; PPH_STRING serviceName = NULL; TAG_INFO_NAME_FROM_TAG nameFromTag; if (!I_QueryTagInformation) { I_QueryTagInformation = PhGetModuleProcAddress(L"advapi32.dll", "I_QueryTagInformation"); if (!I_QueryTagInformation) return NULL; } memset(&nameFromTag, 0, sizeof(TAG_INFO_NAME_FROM_TAG)); nameFromTag.InParams.dwPid = HandleToUlong(ProcessId); nameFromTag.InParams.dwTag = PtrToUlong(ServiceTag); I_QueryTagInformation(NULL, eTagInfoLevelNameFromTag, &nameFromTag); if (nameFromTag.OutParams.pszName) { serviceName = PhCreateString(nameFromTag.OutParams.pszName); LocalFree(nameFromTag.OutParams.pszName); } return serviceName; }
// Worker Thread Start Routine DWORD CDeviceGeneralPage::OnWorkerThreadStart(LPVOID lpParameter) { UINT i = PtrToUlong(lpParameter); ATLASSERT(i < RTL_NUMBER_OF(m_pUnitDevices)); if (i >= RTL_NUMBER_OF(m_pUnitDevices)) { return 255; } ndas::UnitDevicePtr pUnitDevice = m_pUnitDevices[i]; if (NULL == pUnitDevice.get()) { return 1; } (void) pUnitDevice->UpdateHostStats(); if (::IsWindow(m_hWnd)) { ATLVERIFY(PostMessage(WM_USER_DONE, 0, static_cast<LPARAM>(i))); } return 0; }
//----------------------------------------------------------------------------- // Name: MultisampleTypeChanged // Desc: Respond to a change of selected multisample type. //----------------------------------------------------------------------------- void CD3DSettingsDialog::MultisampleTypeChanged( void ) { D3DMULTISAMPLE_TYPE mst = (D3DMULTISAMPLE_TYPE)PtrToUlong( ComboBoxSelected( IDC_MULTISAMPLE_COMBO ) ); m_d3dSettings.SetMultisampleType( mst ); // Set up max quality for this mst D3DDeviceCombo* pDeviceCombo = m_d3dSettings.PDeviceCombo(); DWORD maxQuality = 0; for( UINT ims = 0; ims < pDeviceCombo->pMultiSampleTypeList->Count(); ims++ ) { D3DMULTISAMPLE_TYPE msType = *(D3DMULTISAMPLE_TYPE*)pDeviceCombo->pMultiSampleTypeList->GetPtr(ims); if( msType == mst ) { maxQuality = *(DWORD*)pDeviceCombo->pMultiSampleQualityList->GetPtr(ims); break; } } ComboBoxClear( IDC_MULTISAMPLE_QUALITY_COMBO ); for( UINT msq = 0; msq < maxQuality; msq++ ) { TCHAR str[100]; wsprintf( str, TEXT("%d"), msq ); ComboBoxAdd( IDC_MULTISAMPLE_QUALITY_COMBO, UlongToPtr( msq ), str ); if( msq == m_d3dSettings.MultisampleQuality() ) ComboBoxSelect( IDC_MULTISAMPLE_QUALITY_COMBO, UlongToPtr( msq ) ); } if (!ComboBoxSomethingSelected( IDC_MULTISAMPLE_QUALITY_COMBO ) && ComboBoxCount( IDC_MULTISAMPLE_QUALITY_COMBO ) > 0) { ComboBoxSelectIndex( IDC_MULTISAMPLE_QUALITY_COMBO, 0 ); } }
/* * @implemented */ INT WINAPI FillRect(HDC hDC, CONST RECT *lprc, HBRUSH hbr) { BOOL Ret; HBRUSH prevhbr = NULL; /* Select brush if specified */ if (hbr) { /* Handle system colors */ if (hbr <= (HBRUSH)(COLOR_MENUBAR + 1)) hbr = GetSysColorBrush(PtrToUlong(hbr) - 1); prevhbr = SelectObject(hDC, hbr); if (prevhbr == NULL) return (INT)FALSE; } Ret = PatBlt(hDC, lprc->left, lprc->top, lprc->right - lprc->left, lprc->bottom - lprc->top, PATCOPY); /* Select old brush */ if (prevhbr) SelectObject(hDC, prevhbr); return (INT)Ret; }
BOOL CALLBACK kull_m_token_getTokens_process_callback(PSYSTEM_PROCESS_INFORMATION pSystemProcessInformation, PVOID pvArg) { BOOL status = TRUE; HANDLE hProcess, hToken; if(hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, PtrToUlong(pSystemProcessInformation->UniqueProcessId))) { if(OpenProcessToken(hProcess, TOKEN_QUERY | TOKEN_DUPLICATE, &hToken)) { status = ((PKULL_M_TOKEN_ENUM_DATA) pvArg)->callback(hToken, PtrToUlong(pSystemProcessInformation->UniqueProcessId), ((PKULL_M_TOKEN_ENUM_DATA) pvArg)->pvArg); CloseHandle(hToken); } CloseHandle(hProcess); } return (((PKULL_M_TOKEN_ENUM_DATA) pvArg)->mustContinue = status); }
NTSTATUS WINAPI HID_Device_read(DEVICE_OBJECT *device, IRP *irp) { HID_XFER_PACKET *packet; BASE_DEVICE_EXTENSION *ext = device->DeviceExtension; UINT buffer_size = RingBuffer_GetBufferSize(ext->ring_buffer); NTSTATUS rc = STATUS_SUCCESS; IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation(irp); int ptr = -1; packet = HeapAlloc(GetProcessHeap(), 0, buffer_size); ptr = PtrToUlong( irp->Tail.Overlay.OriginalFileObject->FsContext ); irp->IoStatus.Information = 0; RingBuffer_ReadNew(ext->ring_buffer, ptr, packet, &buffer_size); if (buffer_size) { IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation( irp ); NTSTATUS rc; ULONG out_length; packet->reportBuffer = (BYTE *)packet + sizeof(*packet); TRACE_(hid_report)("Got Packet %p %i\n", packet->reportBuffer, packet->reportBufferLen); rc = copy_packet_into_buffer(packet, irp->AssociatedIrp.SystemBuffer, irpsp->Parameters.Read.Length, &out_length); irp->IoStatus.Information = out_length; irp->IoStatus.u.Status = rc; IoCompleteRequest(irp, IO_NO_INCREMENT); } else { BASE_DEVICE_EXTENSION *extension = device->DeviceExtension; if (extension->poll_interval) { TRACE_(hid_report)("Queue irp\n"); InsertTailList(&ext->irp_queue, &irp->Tail.Overlay.s.ListEntry); rc = STATUS_PENDING; } else { HID_XFER_PACKET packet; TRACE("No packet, but opportunistic reads enabled\n"); packet.reportId = ((BYTE*)irp->AssociatedIrp.SystemBuffer)[0]; packet.reportBuffer = &((BYTE*)irp->AssociatedIrp.SystemBuffer)[1]; packet.reportBufferLen = irpsp->Parameters.Read.Length - 1; rc = call_minidriver(IOCTL_HID_GET_INPUT_REPORT, device, NULL, 0, &packet, sizeof(packet)); if (rc == STATUS_SUCCESS) { ((BYTE*)irp->AssociatedIrp.SystemBuffer)[0] = packet.reportId; irp->IoStatus.Information = packet.reportBufferLen + 1; irp->IoStatus.u.Status = rc; } IoCompleteRequest(irp, IO_NO_INCREMENT); } } HeapFree(GetProcessHeap(), 0, packet); return rc; }
//----------------------------------------------------------------------------- // Name: ResolutionChanged // Desc: Respond to a change of selected resolution by rebuilding the // refresh rate list. //----------------------------------------------------------------------------- void CD3DSettingsDialog::ResolutionChanged( void ) { if (m_d3dSettings.IsWindowed) return; D3DAdapterInfo* pAdapterInfo = (D3DAdapterInfo*)ComboBoxSelected( IDC_ADAPTER_COMBO ); if( pAdapterInfo == NULL ) return; // Update settingsNew with new resolution DWORD dwResolutionData = PtrToUlong( ComboBoxSelected( IDC_RESOLUTION_COMBO ) ); UINT width = LOWORD( dwResolutionData ); UINT height = HIWORD( dwResolutionData ); m_d3dSettings.Fullscreen_DisplayMode.Width = width; m_d3dSettings.Fullscreen_DisplayMode.Height = height; // Update refresh rate list based on new resolution D3DFORMAT adapterFormat = (D3DFORMAT)PtrToUlong( ComboBoxSelected( IDC_ADAPTERFORMAT_COMBO ) ); ComboBoxClear( IDC_REFRESHRATE_COMBO ); for( UINT idm = 0; idm < pAdapterInfo->pDisplayModeList->Count(); idm++ ) { D3DDISPLAYMODE displayMode = *(D3DDISPLAYMODE*)pAdapterInfo->pDisplayModeList->GetPtr(idm); if (displayMode.Format == adapterFormat && displayMode.Width == width && displayMode.Height == height) { TCHAR strRefreshRate[50]; if( displayMode.RefreshRate == 0 ) lstrcpy( strRefreshRate, TEXT("Default Rate") ); else _sntprintf_s( strRefreshRate, 50, 50, TEXT("%d Hz"), displayMode.RefreshRate ); strRefreshRate[49] = 0; if( !ComboBoxContainsText( IDC_REFRESHRATE_COMBO, strRefreshRate ) ) { ComboBoxAdd( IDC_REFRESHRATE_COMBO, UlongToPtr( displayMode.RefreshRate ), strRefreshRate ); if (m_d3dSettings.Fullscreen_DisplayMode.RefreshRate == displayMode.RefreshRate) ComboBoxSelect( IDC_REFRESHRATE_COMBO, UlongToPtr( displayMode.RefreshRate ) ); } } } if (!ComboBoxSomethingSelected( IDC_REFRESHRATE_COMBO ) && ComboBoxCount( IDC_REFRESHRATE_COMBO ) > 0) { ComboBoxSelectIndex( IDC_REFRESHRATE_COMBO, 0 ); } }
//----------------------------------------------------------------------------- // Name: RefreshRateChanged // Desc: Respond to a change of selected refresh rate. //----------------------------------------------------------------------------- void CD3DSettingsDialog::RefreshRateChanged( void ) { if( m_d3dSettings.IsWindowed ) return; // Update settingsNew with new refresh rate UINT refreshRate = PtrToUlong( ComboBoxSelected( IDC_REFRESHRATE_COMBO ) ); m_d3dSettings.Fullscreen_DisplayMode.RefreshRate = refreshRate; }
// 窗口过程函数 LRESULT CALLBACK ThisApp::WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { LRESULT result = 0; // 创建时 设置指针 if (message == WM_CREATE) { auto pcs = reinterpret_cast<LPCREATESTRUCT>(lParam); auto pOurApp = reinterpret_cast<ThisApp*>(pcs->lpCreateParams); ::SetWindowLongPtrW(hwnd, GWLP_USERDATA, PtrToUlong(pOurApp)); result = 1; } else { ThisApp *pOurApp = reinterpret_cast<ThisApp *>(static_cast<LONG_PTR>( ::GetWindowLongPtrW(hwnd, GWLP_USERDATA)) ); // 处理标记 bool wasHandled = false; if (pOurApp){ switch (message) { case WM_LBUTTONDOWN: pOurApp->m_ImagaRenderer.PushPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); __fallthrough; case WM_MOUSEMOVE: pOurApp->m_ImagaRenderer.Lock(); if (pOurApp->m_ImagaRenderer.now_point) { pOurApp->m_ImagaRenderer.now_point->x = static_cast<float>(GET_X_LPARAM(lParam)); pOurApp->m_ImagaRenderer.now_point->y = static_cast<float>(GET_Y_LPARAM(lParam)); } pOurApp->m_ImagaRenderer.Unlock(); break; case WM_RBUTTONDOWN: pOurApp->m_ImagaRenderer.Lock(); pOurApp->m_ImagaRenderer.now_point = nullptr; pOurApp->m_ImagaRenderer.Unlock(); break; case WM_CLOSE: // 将收尾操作(如结束全部子线程)放在这里 pOurApp->m_bExit = TRUE; // join pOurApp->m_threadRender.join(); ::DestroyWindow(hwnd); result = 1; wasHandled = true; break; case WM_DESTROY: ::PostQuitMessage(0); result = 1; wasHandled = true; break; } } // 默认处理标记 if (!wasHandled) { result = ::DefWindowProcW(hwnd, message, wParam, lParam); } } return result; }
LRESULT CALLBACK SimpleText::WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { if (message == WM_CREATE) { LPCREATESTRUCT pcs = (LPCREATESTRUCT)lParam; SimpleText *pSimpleText = (SimpleText *)pcs->lpCreateParams; ::SetWindowLongPtrW( hwnd, GWLP_USERDATA, PtrToUlong(pSimpleText)); return 1; } SimpleText *pSimpleText = reinterpret_cast<SimpleText *>( ::GetWindowLongPtr(hwnd, GWLP_USERDATA)); if (pSimpleText) { switch(message) { case WM_SIZE: { UINT width = LOWORD(lParam); UINT height = HIWORD(lParam); pSimpleText->OnResize(width, height); } return 0; case WM_PAINT: case WM_DISPLAYCHANGE: { PAINTSTRUCT ps; BeginPaint(hwnd, &ps); pSimpleText->DrawD2DContent(); EndPaint( hwnd, &ps ); } return 0; case WM_DESTROY: { PostQuitMessage(0); } return 1; } } return DefWindowProc( hwnd, message, wParam, lParam ); }
void SDL_PrintStackTrace() { /* For some reason this is giving the incorrect symbol names */ typedef USHORT (WINAPI *CaptureStackBackTraceFn)(ULONG,ULONG,PVOID*,PULONG); typedef BOOL (WINAPI *SymInitializeFn)(HANDLE,PCTSTR,BOOL); typedef BOOL (WINAPI *SymFromAddrFn)(HANDLE,DWORD64,PDWORD64,PSYMBOL_INFO); CaptureStackBackTraceFn CaptureStackBackTrace = (CaptureStackBackTraceFn)(GetProcAddress(LoadLibrary("kernel32.dll"), "RtlCaptureStackBackTrace")); SymInitializeFn SymInitialize = (SymInitializeFn)(GetProcAddress(LoadLibrary("Dbghelp.dll"), "SymInitialize")); SymFromAddrFn SymFromAddr = (SymFromAddrFn)(GetProcAddress(LoadLibrary("Dbghelp.dll"), "SymFromAddr")); if ((CaptureStackBackTrace == NULL) || (SymInitialize == NULL) || (SymFromAddr == NULL)) { printf("[STACK] Could not retrieve functions for stack trace\n"); return; } HANDLE process = GetCurrentProcess(); if (process == 0) { printf("[STACK] Could not retrieve current process\n"); return; } if (SymInitialize(process, NULL, TRUE) == 0) { printf("[STACK] Could not ilitialize symbols for process\n"); return; } if (sizeof(void*) != sizeof(DWORD64)) { printf("[STACK] Cannot retrive stack symbols on 32-bit binary\n"); return; } SYMBOL_INFO* symbol = calloc(sizeof(SYMBOL_INFO) + 256, 1); symbol->MaxNameLen = 255; symbol->SizeOfStruct = sizeof(SYMBOL_INFO); void* stack[32]; int frames = CaptureStackBackTrace(0, 32, stack, NULL); printf ("[STACK] (%i frames)\n", frames); for(int i = 0; i < frames; i++ ){ DWORD64 address = PtrToUlong(stack[i]); if (SymFromAddr(process, address, 0, symbol)) { printf(" %i: %s - %08X\n", frames-i-1, symbol->Name, (unsigned int)symbol->Address ); } else { DWORD error = GetLastError(); printf(" %i: SymFromAddr returned error %d\n", frames-i-1, (int)error); } } free(symbol); }
ULONG BtrFuseTrapLite( IN PVOID Address, IN PVOID Destine, IN PBTR_TRAP_OBJECT Trap ) { PUCHAR Buffer; ASSERT(!FlagOn(Trap->TrapFlag, BTR_FLAG_JMP_UNSUPPORTED)); if (FlagOn(Trap->TrapFlag, BTR_FLAG_JMP_RM32)) { Trap->HijackedLength = 6; } else if (FlagOn(Trap->TrapFlag, BTR_FLAG_JMP_REL32)) { Trap->HijackedLength = 5; } else { ASSERT(0); } RtlCopyMemory(Trap->OriginalCopy, Address, Trap->HijackedLength); // // Connect trap back to target via jmp dword ptr[m32] m32 // Buffer = (PUCHAR)&Trap->HijackedCode[0]; Buffer[0] = (UCHAR)0xff; Buffer[1] = (UCHAR)0x25; *(PULONG)&Buffer[2] = PtrToUlong(&Trap->BackwardAddress); // // N.B. for BTR_FLAG_FUSELITE, we just jump to previous hooked handler (hooked), // or stub's function body (not hooked) // Trap->BackwardAddress = Destine; // // Copy original jmp instruction in the end. // RtlCopyMemory(&Buffer[6], Address, Trap->HijackedLength); // // Connect trap to runtime // if (!FlagOn(Trap->TrapFlag, BTR_FLAG_CALLBACK)) { Trap->TrapProcedure = &BtrTrapProcedure; Trap->Procedure = &Trap->TrapProcedure; } return S_OK; }
static bool /* consumes input bytes; knows nothing about records! */ skip_input_bytes(RECSTREAM *rstrm, long cnt) { u_int32_t current; while (cnt > 0) { current = (size_t)(PtrToUlong(rstrm->in_boundry) - PtrToUlong(rstrm->in_finger)); if (current == 0) { if (! fill_input_buf(rstrm, INT_MAX)) return (FALSE); continue; } current = (u_int32_t)((cnt < current) ? cnt : current); rstrm->in_finger += current; cnt -= current; } return (TRUE); }
NTSTATUS WINAPI HID_Device_close(DEVICE_OBJECT *device, IRP *irp) { BASE_DEVICE_EXTENSION *ext = device->DeviceExtension; int ptr = PtrToUlong(irp->Tail.Overlay.OriginalFileObject->FsContext); TRACE("Close handle on device %p\n", device); RingBuffer_RemovePointer(ext->ring_buffer, ptr); irp->IoStatus.u.Status = STATUS_SUCCESS; IoCompleteRequest( irp, IO_NO_INCREMENT ); return STATUS_SUCCESS; }
DWORD WINAPI AfsAdmSvr_AutoOpen_ThreadProc (PVOID lp) { DWORD dwScope = PtrToUlong(lp); ULONG status; if (!l.fOperational) return 0; // First we'll have to find out which cell to open // TCHAR szCell[ cchNAME ]; if (!CELL::GetDefaultCell (szCell, &status)) { Print (dlERROR, TEXT("CELL::GetDefaultCell failed; error 0x%08lX"), status); } else { // Then try to actually open the cell // Print (dlSTANDARD, TEXT("Auto-opening cell %s; scope=%s"), szCell, (dwScope == (AFSADMSVR_SCOPE_VOLUMES | AFSADMSVR_SCOPE_USERS)) ? TEXT("full") : (dwScope == AFSADMSVR_SCOPE_VOLUMES) ? TEXT("volumes") : TEXT("users")); LPIDENT lpiCell; if ((lpiCell = CELL::OpenCell ((LPTSTR)szCell, &status)) == NULL) { Print (dlERROR, TEXT("Auto-open of cell %s failed; error 0x%08lX"), szCell, status); } else { LPCELL lpCell; if ((lpCell = lpiCell->OpenCell (&status)) == NULL) { Print (dlERROR, TEXT("Auto-open: OpenCell failed; error 0x%08lX"), status); } else { AfsAdmSvr_AddToMinScope (dwScope); if (!lpCell->RefreshAll (&status)) Print (dlERROR, TEXT("Auto-open: RefreshCell failed; error 0x%08lX"), status); else Print (dlSTANDARD, TEXT("Auto-open of cell %s successful"), szCell); lpCell->Close(); // We intentionally do not call CELL::CloseCell() here--as would // ordinarily be necessary to balance our CELL::OpenCell() call // above--because we never want to close our cache for this cell. // The point of calling AutoOpen() up front is to keep an admin // server alive and ready for use on a particular cell--calling // CELL::CloseCell() here negates that purpose. } } } return 0; }
/* * Internal useful routines */ static bool flush_out(RECSTREAM *rstrm, bool eor) { u_int32_t eormask = (eor == true) ? LAST_FRAG : 0; u_int32_t len = (u_int32_t) (PtrToUlong(rstrm->out_finger) - PtrToUlong(rstrm->frag_header) - sizeof(u_int32_t)); *(rstrm->frag_header) = htonl(len | eormask); len = (u_int32_t) (PtrToUlong(rstrm->out_finger) - PtrToUlong(rstrm->out_base)); if ((*(rstrm->writeit)) (rstrm->xdrs, rstrm->tcp_handle, rstrm->out_base, (int)len) != (int)len) return (false); rstrm->frag_header = (u_int32_t *) (void *)rstrm->out_base; rstrm->out_finger = (char *)rstrm->out_base + sizeof(u_int32_t); return (true); }
void LockInfinite() { HANDLE hMutex = CreateMutex(NULL, TRUE, TEXT("InfiniteMutex")); DWORD threadID; CloseHandle( CreateThread(NULL, 0, LockInfiniteMutexHandler, (PVOID)hMutex, 0, &threadID)); _tprintf(TEXT("Infinite wait on 0x%x by %u:\n"), PtrToUlong(hMutex), threadID); }
/****************************************************************************** * PointerMoniker_Hash ******************************************************************************/ static HRESULT WINAPI PointerMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash) { PointerMonikerImpl *This = impl_from_IMoniker(iface); if (pdwHash==NULL) return E_POINTER; *pdwHash = PtrToUlong(This->pObject); return S_OK; }