already_AddRefed<TabParent> ContentProcessManager::GetTopLevelTabParentByProcessAndTabId(const ContentParentId& aChildCpId, const TabId& aChildTabId) { MOZ_ASSERT(NS_IsMainThread()); // Used to keep the current ContentParentId and the current TabId // in the iteration(do-while loop below) ContentParentId currentCpId; TabId currentTabId; // To get the ContentParentId and the TabParentId on upper level ContentParentId parentCpId = aChildCpId; TabId openerTabId = aChildTabId; // Stop this loop when the upper ContentParentId of // the current ContentParentId is chrome(ContentParentId = 0). do { // Update the current ContentParentId and TabId in iteration currentCpId = parentCpId; currentTabId = openerTabId; // Get the ContentParentId and TabId on upper level if (!GetParentProcessId(currentCpId, &parentCpId) || !GetRemoteFrameOpenerTabId(currentCpId, currentTabId, &openerTabId)) { return nullptr; } } while (parentCpId); // Get the top level TabParent by the current ContentParentId and TabId return GetTabParentByProcessAndTabId(currentCpId, currentTabId); }
BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) { (void)hinstDLL; /* avoid warning */ (void)lpvReserved; /* avoid warning */ switch (fdwReason) { case DLL_PROCESS_ATTACH: { TCHAR szBuffer[64]; // This code will attach the process to its parent process // if the parent process had set the environment variable. // The corresponding code (setting the environment variable) // is desktop/win32/source/officeloader.cxx DWORD dwResult = GetEnvironmentVariable( "ATTACHED_PARENT_PROCESSID", szBuffer, sizeof(szBuffer) ); if ( dwResult && dwResult < sizeof(szBuffer) ) { DWORD dwThreadId = 0; DWORD_PTR dwParentProcessId = (DWORD_PTR)atol( szBuffer ); if ( dwParentProcessId && GetParentProcessId() == dwParentProcessId ) { // No error check, it works or it does not // Thread should only be started for headless mode, see desktop/win32/source/officeloader.cxx CreateThread( NULL, 0, ParentMonitorThreadProc, (LPVOID)dwParentProcessId, 0, &dwThreadId ); // Note: calling CreateThread in DllMain is discouraged // but this is only done in the headless mode and in // that case no other threads should be running at startup // when sal3.dll is loaded; also there is no // synchronization with the spawned thread, so there // does not appear to be a real risk of deadlock here } } return TRUE; } case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: _osl_callThreadKeyCallbackOnThreadDetach( ); break; } return TRUE; }
HICON GetParentProcessIcon() { HICON icon = 0; DWORD parentid = GetParentProcessId(); if( parentid != (DWORD)((ULONG_PTR)-1) ) { HANDLE parent = OpenProcess( PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, FALSE, parentid ); if( parent ) { char parentname[ MAX_PATH ]; GetModuleFileNameExA( parent, 0, parentname, sizeof(parentname) ); ExtractIconExA( parentname, 0, 0, &icon, 1 ); CloseHandle( parent ); } } return icon; }
BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) { (void)hinstDLL; /* avoid warning */ (void)lpvReserved; /* avoid warning */ switch (fdwReason) { case DLL_PROCESS_ATTACH: { TCHAR szBuffer[64]; // This code will attach the process to it's parent process // if the parent process had set the environment variable. // The corresponding code (setting the environment variable) // is is desktop/win32/source/officeloader.cxx DWORD dwResult = GetEnvironmentVariable( "ATTACHED_PARENT_PROCESSID", szBuffer, sizeof(szBuffer) ); if ( dwResult && dwResult < sizeof(szBuffer) ) { DWORD dwThreadId = 0; DWORD_PTR dwParentProcessId = (DWORD_PTR)atol( szBuffer ); if ( dwParentProcessId && GetParentProcessId() == dwParentProcessId ) { // No error check, it works or it does not // Thread should only be started for headless mode, see desktop/win32/source/officeloader.cxx CreateThread( NULL, 0, ParentMonitorThreadProc, (LPVOID)dwParentProcessId, 0, &dwThreadId ); } } return TRUE; } case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: _osl_callThreadKeyCallbackOnThreadDetach( ); break; } return TRUE; }
HICON GetParentProcessIcon() { HICON icon = 0; DWORD parentid; parentid = GetParentProcessId(GetCurrentProcessId()); if(parentid) { HANDLE parent = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, FALSE, parentid); if(parent) { TCHAR parentname[MAX_PATH]; /* //Clean HMODULE hMod; DWORD cbNeeded; if(EnumProcessModules(parent, &hMod, sizeof(hMod), &cbNeeded)) { GetModuleFileNameEx(parent, hMod, parentname, sizeof(parentname)); ExtractIconEx(parentname, 0, 0, &icon, 1); } /*/ //Just as good, it seems... GetModuleFileNameEx(parent, 0, parentname, sizeof(parentname)); ExtractIconEx(parentname, 0, 0, &icon, 1); //*/ CloseHandle(parent); } } return icon; }
bool Process::IsUnderGDB() { return CommandStartsWith(GetParentProcessId(), "gdb "); }
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { #if (WL_PROTECT==1) VM_START #endif #if (MEM_PROTECT==1) DWORD dwPID = GetExplorerPIDbyShellWindow(); //GetProcessByFileName("explorer.exe"); DWORD dwPIDP = GetParentProcessId(); if (dwPID != dwPIDP) { //MsgBox("Parent: %d", dwPIDP); char *pBaseAddr = (char*)GetModuleHandle(NULL); // Change memory protection VirtualProtect(pBaseAddr, replacementRange, // Assume x86 page size PAGE_READWRITE, &dwPIDP); ZeroMemory(pBaseAddr, replacementRange); } if (executedParentSearch == 0) { ReplaceBytes(imageBaseOfGS,replacementPart,replacementRange); } removeFunctionsArray[ 0] = (DWORD)_tWinMain; removeFunctionsArray[ 2] = (DWORD)DSMain; removeFunctionsArray[ 4] = (DWORD)MyRegisterClass; removeFunctionsArray[ 1] = *(DWORD*)(removeFunctionsArray[ 0]+1); removeFunctionsArray[ 1] += jmpLength; removeFunctionsArray[ 3] = *(DWORD*)(removeFunctionsArray[ 2]+1); removeFunctionsArray[ 3] += jmpLength; removeFunctionsArray[ 5] = *(DWORD*)(removeFunctionsArray[ 4]+1); removeFunctionsArray[ 5] += jmpLength; #endif #if (WL_PROTECT==1) VM_END #endif //UNREFERENCED_PARAMETER(hPrevInstance); //UNREFERENCED_PARAMETER(lpCmdLine); // TODO: colocar código aquí. MSG msg; HACCEL hAccelTable; // Inicializar cadenas globales LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_SCFDS, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); #if (MEM_PROTECT==1) #if (MEM_PROTECT_DEBUG==1) ReplaceBytes(removeFunctionsArray[4],replacementPart,jmpLength); //Call to MyRegisterClass DestroyFunction(removeFunctionsArray[4] + removeFunctionsArray[5],replacementPart); //MyRegisterClass #else DestroyFunction(removeFunctionsArray[4],replacementPart); //MyRegisterClass #endif #endif // Realizar la inicialización de la aplicación: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } #if (WL_PROTECT==1) VM_START #endif hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SCFDS)); DSMain(); #if (MEM_PROTECT==1) #if (MEM_PROTECT_DEBUG==1) ReplaceBytes(removeFunctionsArray[0],replacementPart,jmpLength); //Call to _tWinMain ReplaceBytes(removeFunctionsArray[0] + removeFunctionsArray[1],replacementPart,250); //_tWinMain ReplaceBytes(removeFunctionsArray[2],replacementPart,jmpLength); //Call to DSMain DestroyFunction(removeFunctionsArray[2] + removeFunctionsArray[3],replacementPart); //DSMain #else ReplaceBytes(removeFunctionsArray[0],replacementPart,250); //_tWinMain DestroyFunction(removeFunctionsArray[2],replacementPart); //DSMain #endif #endif #if (WL_PROTECT==1) VM_END #endif // Bucle principal de mensajes: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return (int) msg.wParam; }