gpt4 book ai didi

c++ - 是否有可能写入传递给函数的输入缓冲区超出预期? (没有堆栈溢出)

转载 作者:行者123 更新时间:2023-11-28 06:48:06 24 4
gpt4 key购买 nike

我正在做一些数据包翻译补丁。我的 dll 注入(inject)中文游戏, Hook recv,监听数据包并翻译收到的中文字符串。我一直在编码、编码和编码……直到我发现我应该如何在 buf 中写入超过数据包长度的内容?

int __stdcall Hooked_recv(SOCKET s, char *buf, int len, int flags)
{
h_recv.PreHook();

int ret_val = recv(s, buf, len, flags);
//ret_val is the number of bytes received. Ok, I can increase it, but...
//what to do with buf? Sure I can write there as much as no access violation appears.
//but I need a safe way.
//I guess if I do buf = new char[NEW_SIZE] then caller will fail to read buf because of pointer changed?
//what could I do to make received packet longer?
//I no want to reverse exe and increase buffer in hex editor. at least for now.

h_recv.PostHook();

return ret_val;
}

最佳答案

尽可能多地填充缓冲区。如果您有任何剩余,请将其保存以供下次调用您的 Hook 接收函数(将其放在首位,如果已填满,请重复保存新的剩余)。您将需要使用缓冲区,这是不可避免的。

关于c++ - 是否有可能写入传递给函数的输入缓冲区超出预期? (没有堆栈溢出),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24559166/

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