当在32位游戏的32位版本中与LD_Preload挂钩时,Fopen调用只有在游戏刚开始时才会发生。这是为什么?
我在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论