forked from sy3c4ll/obsidian
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch.c
More file actions
58 lines (43 loc) · 1.67 KB
/
launch.c
File metadata and controls
58 lines (43 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <windows.h>
#include <wchar.h>
#include <shlwapi.h>
int main() {
wchar_t exePath[MAX_PATH];
GetModuleFileNameW(NULL, exePath, MAX_PATH);
if (!getenv("SYNTHV_STUDIO_EXE")) {
PathRemoveFileSpecW(exePath);
PathAppendW(exePath, L"synthv-studio.exe");
} else {
wcscpy(exePath, _wgetenv(L"SYNTHV_STUDIO_EXE"));
}
LPWSTR realCmdLine = GetCommandLineW();
size_t cmdLineSize = wcslen(realCmdLine) + 1;
LPWSTR modifiedCmdLine = (LPWSTR)malloc(cmdLineSize * sizeof(WCHAR));
wcscpy_s(modifiedCmdLine, cmdLineSize, realCmdLine);
STARTUPINFOW si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
if (CreateProcessW(exePath, modifiedCmdLine, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi)) {
LPCWSTR dllPath = getenv("OBSIDIAN_DLL") ? _wgetenv(L"OBSIDIAN_DLL") : L"obsidian.dll";
LPVOID remoteStringAddress = VirtualAllocEx(pi.hProcess, NULL, wcslen(dllPath) * sizeof(WCHAR) + 2,
MEM_COMMIT, PAGE_READWRITE);
WriteProcessMemory(pi.hProcess, remoteStringAddress, dllPath,
wcslen(dllPath) * sizeof(WCHAR) + 1, NULL);
HANDLE hThread = CreateRemoteThread(pi.hProcess, NULL, 0,
(LPTHREAD_START_ROUTINE)LoadLibraryW, remoteStringAddress, 0, NULL);
WaitForSingleObject(hThread, INFINITE);
ResumeThread(pi.hThread);
WaitForSingleObject(pi.hProcess, INFINITE);
DWORD exitCode;
GetExitCodeProcess(pi.hProcess, (LPDWORD)&exitCode);
CloseHandle(hThread);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
VirtualFreeEx(pi.hProcess, remoteStringAddress, 0, MEM_RELEASE);
free(modifiedCmdLine);
return exitCode;
}
return 1;
}