gpt4 book ai didi

编译已经编写的 C 脚本。 Visual Studio 2017

转载 作者:行者123 更新时间:2023-11-30 16:24:09 31 4
gpt4 key购买 nike

我已经编写了一个 C 脚本,我想将其与 Texmod 一起使用。很久以前就有帖子讲过,但我无法访问。基本上,它允许您将 TexMod 与 .exe 的参数一起使用,例如 -log。我已经下载了 Visual Studios 2017 并尝试使用开发人员控制台通过 cd 到文件夹而不是 cl 'script.c' 来编译它。它生成 .exe 和 .obj,但除此之外什么也不做,即使我双击 .exe 问题是我了解 java,但从未用 C 语言做过任何事情。这是代码:

#include <stdio.h>
#include <windows.h>
#include <tlhelp32.h>

UINT WINAPI EzGetPid(LPCSTR procName, UINT *pid, UINT size);

int main(int argc, char *argv[])
{
if (argc < 1) {
puts("You must specifie the arguments");
return 1;
}

UINT pid = 0;
if (!EzGetPid("Texmod.exe", &pid, 1)) {
puts("You must open Texmod first.");
return 1;
}

BYTE shellcode_tramp[] = "\x58\x6A\x00\x6A\x00\x68\x00\x00\x00\x00\xFF\xE0";
UINT size_tramp = 12;

char arguments[0x500] = {0};
strcpy(arguments, argv[1]);

HANDLE proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
LPVOID remote_tramp = VirtualAllocEx(proc, NULL, 0x1000, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
LPVOID remote_args = (LPVOID)((DWORD)remote_tramp + size_tramp);

*(DWORD*)(&shellcode_tramp[6]) = (DWORD)remote_args;
WriteProcessMemory(proc, remote_tramp, shellcode_tramp, size_tramp, NULL); // Write the trampoline
WriteProcessMemory(proc, remote_args, arguments, strlen(arguments), NULL); // Write the arguments

BYTE firstCall[] = "\xE8\x00\x00\x00\x00\x90";
BYTE secondCall[] = "\xE8\x00\x00\x00\x00\x90";
*(DWORD*)(&firstCall[1]) = (DWORD)remote_tramp - 0x4012E1 - 5;
*(DWORD*)(&secondCall[1]) = (DWORD)remote_tramp - 0x40145B - 5;
WriteProcessMemory(proc, (LPVOID)0x4012E1, firstCall, 6, NULL); // Write first detour call
WriteProcessMemory(proc, (LPVOID)0x40145B, secondCall, 6, NULL); // Write second detour call

CloseHandle(proc);
return 0;
}

UINT WINAPI EzGetPid(LPCSTR procName, UINT *pid, UINT size)
{
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 buffer = {0};
buffer.dwSize = sizeof(PROCESSENTRY32);

UINT count = 0;

while (Process32Next(hSnap, &buffer) && count < size) {
if (!strcmp(buffer.szExeFile, procName))
pid[count++] = buffer.th32ProcessID;
}

CloseHandle(hSnap);
return count;
}

附:我添加了最后一个闭括号,因为我认为我很久以前复制时可能复制错了。

我需要使用 Visual Studios 界面来执行此操作吗?我想知道了解 C 的人是否可以查看我正在尝试编译的代码并帮助解释我缺少的任何内容或有关如何运行它的任何特殊说明。非常感谢您的所有帮助。

最佳答案

您的程序需要参数才能正确运行。您的程序不执行任何操作的原因是因为双击它时,您没有传递任何参数。在您看到调试消息“您必须指定参数”之前,控制台正在关闭。

通常,使用内部注入(inject)的 DLL 方法而不是此外部方法来处理蹦床 Hook 要容易得多。您可以在挂起状态下启动进程,然后注入(inject) DLL 来执行 Trampoline hook。然后您可以轻松修改您正在 Hook 的函数的函数参数。

这是我用于 x86 蹦床钩子(Hook)的代码

bool Detour32(BYTE* src, BYTE* dst, const uintptr_t len)
{
if (len < 5) return false;

DWORD curProtection;
VirtualProtect(src, len, PAGE_EXECUTE_READWRITE, &curProtection);

uintptr_t relativeAddress = dst - src - 5;

*src = 0xE9;

*(uintptr_t*)(src + 1) = relativeAddress;

VirtualProtect(src, len, curProtection, &curProtection);
return true;
}

BYTE* TrampHook32(BYTE* src, BYTE* dst, const uintptr_t len)
{
if (len < 5) return 0;

//Create Gateway
BYTE* gateway = (BYTE*)VirtualAlloc(0, len, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);

//write the stolen bytes to the gateway
memcpy_s(gateway, len, src, len);

//Get the gateway to destination address
uintptr_t gatewayRelativeAddr = src - gateway - 5;

// add the jmp opcode to the end of the gateway
*(gateway + len) = 0xE9;

//Write the address of the gateway to the jmp
*(uintptr_t*)((uintptr_t)gateway + len + 1) = gatewayRelativeAddr;

//Perform the detour
Detour32(src, dst, len);

return gateway;
}

这里是我如何使用它来获取 OpenGL 的 SwapBuffers 函数的示例,在这个示例中我们将 hDc 参数更改为 1337。

typedef BOOL(__stdcall* twglSwapBuffers) (HDC hDc);

twglSwapBuffers owglSwapBuffers;

BOOL __stdcall hkwglSwapBuffers(HDC hDc)
{
hDc = 1337;
return owglSwapBuffers(hDc);
}

owglSwapBuffers = (twglSwapBuffers)mem::TrampHook32((BYTE*)owglSwapBuffers, (BYTE*)hkwglSwapBuffers, 5);

关于编译已经编写的 C 脚本。 Visual Studio 2017,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53708340/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com