c++ - 将sleep()注入到外部进程的函数中

原文 标签 c++ c dll inject detours

Inject sleep() into a function of an external process

I know how to inject a DLL into a running process and also how to utilize functions used internally by the process e.g.

void__stdcall remoteMethod(unsigned short id)
{
typedef void (__stdcall *pFunctionAddress)(unsigned short);
pFunctionAddress pMyFunction = (pFunctionAddress)(0xCAFEBABE);
pMyFunction(id);
}

Now i want to add a sleep() into an existing method in the running process - this is the main loop of the program and doesnt stop for a sec and uses up all processing power.

I know that with frameworks like detours i could make a trampoline function which calls my function and then the original one - however my problem is that the while(1) loop is somewhere within the function of the external process. So i know the offset where the loop starts - and after that i would like to first call sleep() and then continue with the normal route of the loop.

The only alternative i saw so far is binary editing the program but this is not a good solution.

Any suggestion? Thanks

Answer

I think you are trying to be too cute here. Just call SuspendThread/ResumeThread alternately on a timer. I know it's ugly, but you aren't going to enter your solution in any beauty pageant I suspect.

翻译

我知道如何将DLL注入正在运行的进程中,以及如何利用进程内部使用的功能,例如

void__stdcall remoteMethod(unsigned short id)
{
typedef void (__stdcall *pFunctionAddress)(unsigned short);
pFunctionAddress pMyFunction = (pFunctionAddress)(0xCAFEBABE);
pMyFunction(id);
}


现在,我想在运行过程中将sleep()添加到现有方法中-这是程序的主循环,不会停止一秒钟,并且会耗尽所有处理能力。

我知道使用绕道绕行的框架,我可以制作一个蹦床函数,该函数先调用我的函数,然后再调用原始函数-但是我的问题是while(1)循环位于外部进程的函数内。所以我知道循环开始的偏移量-之后我想先调用sleep()然后继续循环的正常路线。

到目前为止,我看到的唯一选择是对程序进行二进制编辑,但这不是一个好的解决方案。

有什么建议吗?谢谢
最佳答案
我想你在这里太可爱了。只需在计时器上交替调用SuspendThread / ResumeThread。我知道这很丑陋,但我不会在任何选美比赛中输入您的解决方案。
相关推荐

c++ - 奇怪的“从<类型>到<类型>的无效转换”错误

java - 确定性语言的适用性

c++ - opengl的模具缓冲区没有初始化为零?

c++ - 我将哪个openMP编译指示用于循环阻塞?

c++ - 无法摆脱“对“ XXXX”的未定义引用”

c++ - MSVC10 / MP不能跨项目中的文件夹构建多核

c++ - 找不到stdarg.h

c++ - 目标文件是什么样的

c++ - 从C / C++发送HTTP和https请求

javascript - 为什么在v8::Scope之前创建新的v8::Array会导致分段错误,而v8::String和v8::FunctionTemplate却不会呢?