Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yoitsmidi/c3863aa4feb015b4e588 to your computer and use it in GitHub Desktop.
Save yoitsmidi/c3863aa4feb015b4e588 to your computer and use it in GitHub Desktop.

Revisions

  1. @AltimorTASDK AltimorTASDK created this gist Jan 24, 2016.
    50 changes: 50 additions & 0 deletions ggxrd_hitbox_injector.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    #include <Windows.h>
    #include <TlHelp32.h>
    #include <Psapi.h>

    int main()
    {
    const auto *exe = "GuiltyGearXrd.exe";
    const auto *dll = "ggxrd_hitbox_overlay.dll";

    const auto snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

    PROCESSENTRY32 entry;
    entry.dwSize = sizeof(entry);

    Process32First(snap, &entry);
    do
    {
    const auto proc = OpenProcess(PROCESS_ALL_ACCESS, false, entry.th32ProcessID);

    char path[MAX_PATH];
    if (GetModuleFileNameEx(proc, nullptr, path, MAX_PATH) == 0)
    {
    CloseHandle(proc);
    continue;
    }

    if (strcmp(path + strlen(path) - strlen(exe), exe) != 0)
    {
    CloseHandle(proc);
    continue;
    }

    char dll_path[MAX_PATH];
    GetCurrentDirectory(MAX_PATH, dll_path);
    strcat_s(dll_path, MAX_PATH, "/");
    strcat_s(dll_path, MAX_PATH, dll);

    const auto size = strlen(dll_path) + 1;
    auto *buf = VirtualAllocEx(proc, nullptr, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
    WriteProcessMemory(proc, buf, dll_path, size, nullptr);
    CreateRemoteThread(proc, nullptr, 0, (LPTHREAD_START_ROUTINE)(LoadLibrary), buf, 0, nullptr);

    CloseHandle(proc);
    CloseHandle(snap);
    break;
    }
    while (Process32Next(snap, &entry));

    return 0;
    }