Skip to content

Commit

Permalink
Minor changes to running for multiple browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
gurux13 committed Jan 14, 2024
1 parent dbd049c commit 0bd4ace
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 51 deletions.
17 changes: 16 additions & 1 deletion Configurator/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,25 @@ private void btnMoveEndpoint_Click(object sender, EventArgs e)
btnRefresh_Click(sender, e);
}

private void btnExecutables_Click(object sender, EventArgs e)
private async Task RestartInjectorIfRunning()
{
var injectorProcess = GetInjectorProcess();
if (injectorProcess != null)
{
injectorProcess.Kill();
await injectorProcess.WaitForExitAsync();
Process.Start(".\\ManualInject.exe");
}
}

private async void btnExecutables_Click(object sender, EventArgs e)
{
(new BrowserSelector()).ShowDialog();
RecalculateBrowserCount();
if (systemHelper.GetExecutables().Count != 0)
{
await RestartInjectorIfRunning();
}
}
Color? originalBtnColor = null;
Font? btnBoldFont = null;
Expand Down
110 changes: 66 additions & 44 deletions InjectedDll/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,52 +504,74 @@ BOOL APIENTRY ThreadMain(LPVOID lpModule) {
return TRUE;
}

bool IsCfgActive(HANDLE hProcess) {
PROCESS_MITIGATION_CONTROL_FLOW_GUARD_POLICY policy_status;
if (!GetProcessMitigationPolicy(hProcess, ProcessControlFlowGuardPolicy, &policy_status, sizeof(policy_status))) {
return true;
}
return policy_status.EnableControlFlowGuard;
}

void AllowInCFG() {
auto current_process = GetCurrentProcess();
if (!IsCfgActive(current_process)) {
LOG("CFG not active, not configuring");
return;
}

LOG("Configuring CFG");
void* all_indirect_functions[] = {
Hook::Activate,
Hook::GetPosition,
Hook::GetService,
Hook::ReleaseClient,
Hook::ReleaseClock,
Hook::ReleaseDevice,
RegistryThreadMain
};
DWORD64* all_indirect_functions_int = (DWORD64*)(all_indirect_functions);
DWORD64 range_start = all_indirect_functions_int[0];
DWORD64 range_end = all_indirect_functions_int[0];
for (int i = 0; i < sizeof(all_indirect_functions) / 8; ++i) {
range_start = min(range_start, all_indirect_functions_int[i]);
range_end = max(range_end, all_indirect_functions_int[i]);
}
CFG_CALL_TARGET_INFO info[sizeof(all_indirect_functions) / 8];
for (int i = 0; i < sizeof(all_indirect_functions) / 8; ++i) {
info[i].Offset = all_indirect_functions_int[i] - range_start;
info[i].Flags = CFG_CALL_TARGET_VALID;
}
//__debugbreak();
if (!SetProcessValidCallTargets(current_process, (void*)range_start, range_end - range_start + 80, sizeof(all_indirect_functions) / 8, info)) {
LOG("CFG ERROR: " << GetLastError());
}
LOG("Done CFG configuration");
}
//bool IsCfgActive(HANDLE hProcess) {
// PROCESS_MITIGATION_CONTROL_FLOW_GUARD_POLICY policy_status;
// if (!GetProcessMitigationPolicy(hProcess, ProcessControlFlowGuardPolicy, &policy_status, sizeof(policy_status))) {
// return true;
// }
// return policy_status.EnableControlFlowGuard;
//}
//bool GetMemoryAllocationBaseAndRegionSize(
// PVOID pvAddress,
// PVOID* ppvAllocationBase,
// PSIZE_T pstRegionSize
//)
//{
// SIZE_T stErr = 0;
// MEMORY_BASIC_INFORMATION tMemoryBasicInformation = { 0 };
//
// stErr = VirtualQuery(
// pvAddress,
// &tMemoryBasicInformation,
// sizeof(tMemoryBasicInformation)
// );
// if (0 == stErr)
// {
// return false;
// }
//
// *ppvAllocationBase = tMemoryBasicInformation.AllocationBase;
// *pstRegionSize = tMemoryBasicInformation.RegionSize;
// return true;
//}
//void AllowInCFG() {
// auto current_process = GetCurrentProcess();
// if (!IsCfgActive(current_process)) {
// LOG("CFG not active, not configuring");
// return;
// }
// return;
//
// LOG("Configuring CFG");
// void* all_indirect_functions[] = {
// Hook::Activate,
// Hook::GetPosition,
// Hook::GetService,
// Hook::ReleaseClient,
// Hook::ReleaseClock,
// Hook::ReleaseDevice,
// RegistryThreadMain
// };
// DWORD64* all_indirect_functions_int = (DWORD64*)(all_indirect_functions);
// PVOID base;
// size_t size;
// if (!GetMemoryAllocationBaseAndRegionSize(all_indirect_functions[0], &base, &size)) {
// LOG("Unable to get base address!" << GetLastError());
// }
// CFG_CALL_TARGET_INFO info[sizeof(all_indirect_functions) / 8];
// for (int i = 0; i < sizeof(all_indirect_functions) / 8; ++i) {
// info[i].Offset = all_indirect_functions_int[i] - (DWORD64)base;
// info[i].Flags = CFG_CALL_TARGET_VALID;
// }
// __debugbreak();
// if (!SetProcessValidCallTargets(current_process, base, size, sizeof(all_indirect_functions) / 8, info)) {
// LOG("CFG ERROR: " << GetLastError());
// }
// LOG("Done CFG configuration");
//}

BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
AllowInCFG();
//AllowInCFG();
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH: {
DisableThreadLibraryCalls(hModule);
Expand Down
7 changes: 1 addition & 6 deletions ManualInject/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ int WINAPI WinMain(HINSTANCE hInstance, // HANDLE TO AN INSTANCE. This is th
LPSTR szCmdLine, // Command line arguments. similar to argv in standard C programs
int iCmdShow) // Start window maximized, minimized, etc.
{
/*if (argc == 2) {
Inject(atoi(argv[1]), L"ChromePatcherDll.dll");
return;
}*/
HKEY execKeyHandle;
if (RegOpenKey(HKEY_LOCAL_MACHINE, L"SOFTWARE\\gurux13\\ChromePatcher\\executables", &execKeyHandle) != ERROR_SUCCESS) {
return 1;
Expand Down Expand Up @@ -54,8 +50,7 @@ int WINAPI WinMain(HINSTANCE hInstance, // HANDLE TO AN INSTANCE. This is th
//std::wcout << "Found chrome (" << pid << "), cmdline: " << cmdline << "\n";
if (cmdline.find(L"--utility-sub-type=audio.mojom.AudioService") != std::wstring::npos) {
std::wcout << "Found process " << pid << ", injecting...\n";
Inject(pid, L"Y:\\github\\Chrome-Audio-Delay-Patcher\\output\\InjectedDll.dll");
//Inject(pid, L"InjectedDll.dll");
Inject(pid, L"InjectedDll.dll");
}
}

Expand Down

0 comments on commit 0bd4ace

Please sign in to comment.