当在32位游戏的32位版本中与LD_Preload挂钩时,Fopen调用只有在游戏刚开始时才会发生。这是为什么?

发布于 2025-02-05 18:53:28 字数 1435 浏览 3 评论 0原文

我在Linux上使用的LD_Preload使用了此代码来挂接Fopen调用,并且我正在尝试在游戏中使用它。它在游戏的64位版本上正常工作,但是在32位版本上,似乎Fopen首次启动时被称为65次,然后再也不会被调用。我还挂上了Freopen和fdopen,只是为了检查是否被称为,它们不是。有人知道为什么会发生这种情况,而32位版本可能会使用什么功能?

这是代码:

#include <cstdio>
#include <cstring>
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <dlfcn.h>
static auto originalFopen = reinterpret_cast<FILE * (*)(const char* path, const char* mode)>(dlsym(RTLD_NEXT, "fopen"));
static auto originalFdopen = reinterpret_cast<FILE * (*)(int fd, const char* mode)>(dlsym(RTLD_NEXT, "fdopen"));
static auto originalFreopen = reinterpret_cast<FILE * (*)(const char* path, const char* mode, FILE* stream)>(dlsym(RTLD_NEXT, "freopen"));

FILE* f = originalFopen("TEST.txt", "w");

FILE* fopen(const char* path, const char* mode)
{
    std::fwrite("idk1\n", 1, 5, f);

    return originalFopen(path, mode);
}

FILE* fdopen(int fd, const char* mode)
{
    std::fwrite("idk2\n", 1, 5, f);

    return originalFdopen(fd, mode);
}

FILE* freopen(const char* path, const char* mode, FILE* stream)
{
    std::fwrite(path, 1, std::strlen(path), f);
    std::fwrite("\n", 1, 1, f);

    return originalFreopen(path, mode, stream);
}

这是我正在挂接的游戏的源代码: https://github.com/摩擦游戏/遗星季后赛

I have this code I'm using with LD_PRELOAD on linux to hook fopen calls, and I'm trying to use it on a game. It works fine on the 64 bit version of the game, but on the 32 bit version, it seems like fopen just gets called 65 times when the game first starts, then never gets called again. I also hooked freopen and fdopen just to check if those were being called, and they weren't. Does anyone know why this is happening, and what function the 32 bit version might be using instead?

This is the code:

#include <cstdio>
#include <cstring>
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <dlfcn.h>
static auto originalFopen = reinterpret_cast<FILE * (*)(const char* path, const char* mode)>(dlsym(RTLD_NEXT, "fopen"));
static auto originalFdopen = reinterpret_cast<FILE * (*)(int fd, const char* mode)>(dlsym(RTLD_NEXT, "fdopen"));
static auto originalFreopen = reinterpret_cast<FILE * (*)(const char* path, const char* mode, FILE* stream)>(dlsym(RTLD_NEXT, "freopen"));

FILE* f = originalFopen("TEST.txt", "w");

FILE* fopen(const char* path, const char* mode)
{
    std::fwrite("idk1\n", 1, 5, f);

    return originalFopen(path, mode);
}

FILE* fdopen(int fd, const char* mode)
{
    std::fwrite("idk2\n", 1, 5, f);

    return originalFdopen(fd, mode);
}

FILE* freopen(const char* path, const char* mode, FILE* stream)
{
    std::fwrite(path, 1, std::strlen(path), f);
    std::fwrite("\n", 1, 1, f);

    return originalFreopen(path, mode, stream);
}

This is the source code of the game I'm hooking: https://github.com/FrictionalGames/AmnesiaTheDarkDescent

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文