我正在尝试将代码注入我编写的一个小游戏中以保持健康,我想通过将代码注入游戏中来做到这一点,该代码将10在每次render()调用之前设置健康,从而使游戏本质上永不结束。
对于我的项目,我用 C++ 编写了一个小示例游戏,然后在 IDA 中编译和反编译。
我设法找到了health存储0x0000000140005034地址 ( 0x000000014000107D)和主循环地址 ( ),但是我似乎无法弄清楚如何从 IDA 中的静态地址转到实际地址在另一个 C++ 程序中生成进程。
谁能给我一个关于如何实现这一目标的提示?
这是我试图用来将代码注入我的应用程序的代码:
#include <iostream>
#include <Windows.h>
#include "config.h"
STARTUPINFO info = {sizeof(info)};
PROCESS_INFORMATION process;
void injectCodeIntoProccess()
{
// Stuck here, no idea how I could modify my game's code on every loop iteration.
}
void main()
{
if (CreateProcess(EXECUTABLE_PATH, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &info, &process)) {
injectCodeIntoProccess();
WaitForSingleObject(process.hProcess, INFINITE);
} else {
std::cerr << "Error whilst creating process." << std::endl;
exit(1);
}
}
这是我用于我的游戏的代码:
#include <iostream>
#include <Windows.h>
// Health variable
// Address (as found in IDA): .data:0x0000000140005034
int health = 10;
// Render the game
//
// In real world scenario's this would be a 3d world or something
// but we're using 'Health: *..' as the game itself.
void render()
{
std::cout << "Health: ";
for (int i = 0; i < health; i++) std::cout << "*";
std::cout << std::endl;
}
// Gets input from the user
//
// If the user presses a spacebar, increase the health
// by one otherwise, decrease the health by one.
void input()
{
if (GetKeyState(VK_SPACE) < 0) {
health++;
} else {
health--;
}
}
// Simple game
//
// If the player reaches 0 health game over.
// This is checked every 500ms
int main()
{
while (health > 0)
{
input();
render();
Sleep(500);
}
return 0;
}