主にプログラミング関連のメモ帳 ♪(✿╹ヮ╹)ノ
書いてあるコードは自己責任でご自由にどうぞ。記事本文の無断転載は禁止です。
2022/06/16
前回の記事の続きで、今回は任意の場所に、任意の処理を差し込んでみようと思います。
使うライブラリは Hooking.Patterns と Injectors の改変版です。
使い方はカンタンで、うさみみハリケーンとかで任意のプログラムのメモリーをダンプし、該当する処理が書かれている部分のメモリパターンを、 Hooking.Patterns
ライブラリーで検索します。
コードにするとこんな感じです:
auto pattern = hook::pattern("E8 84 BE 0D FF");
if (!pattern.count_hint(1).empty())
{
auto address = pattern.get(0).get<std::uintptr_t>();
}
検索したら、 Injectors の改変版を使って、処理を書き換えます:
struct RewriteSomeAssembly
{
void operator()(Injector::reg_pack& regs) const
{
// your code here...
}
};
// (略)
{
// 1 の部分は書き換える領域分だけ調節する
Injector::MakeInline<RewriteSomeAssembly>(address, address + 1);
}
これで終わり。
これで任意の場所に任意の処理を差し込めました。おつかれさまでした。