mirror of
https://github.com/HIllya51/LunaHook.git
synced 2024-11-23 13:55:36 +08:00
takeout
This commit is contained in:
parent
b28b755167
commit
34edb1bfab
@ -61,7 +61,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/version)
|
|||||||
include(generate_product_version)
|
include(generate_product_version)
|
||||||
|
|
||||||
set(VERSION_MAJOR 3)
|
set(VERSION_MAJOR 3)
|
||||||
set(VERSION_MINOR 5)
|
set(VERSION_MINOR 6)
|
||||||
set(VERSION_PATCH 0)
|
set(VERSION_PATCH 0)
|
||||||
set(VERSION_REVISION 0)
|
set(VERSION_REVISION 0)
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include"EME.h"
|
#include "EME.h"
|
||||||
|
|
||||||
/********************************************************************************************
|
/********************************************************************************************
|
||||||
EMEHook hook: (Contributed by Freaka)
|
EMEHook hook: (Contributed by Freaka)
|
||||||
@ -14,28 +14,113 @@ bool InsertEMEHook()
|
|||||||
{
|
{
|
||||||
ULONG addr = MemDbg::findCallAddress((ULONG)::IsDBCSLeadByte, processStartAddress, processStopAddress);
|
ULONG addr = MemDbg::findCallAddress((ULONG)::IsDBCSLeadByte, processStartAddress, processStopAddress);
|
||||||
// no needed as first call to IsDBCSLeadByte is correct, but sig could be used for further verification
|
// no needed as first call to IsDBCSLeadByte is correct, but sig could be used for further verification
|
||||||
//WORD sig = 0x51C3;
|
// WORD sig = 0x51C3;
|
||||||
//while (c && (*(WORD*)(c-2)!=sig))
|
// while (c && (*(WORD*)(c-2)!=sig))
|
||||||
//{
|
//{
|
||||||
// //-0x1000 as FindCallOrJmpAbs always uses an offset of 0x1000
|
// //-0x1000 as FindCallOrJmpAbs always uses an offset of 0x1000
|
||||||
// c = Util::FindCallOrJmpAbs((DWORD)IsDBCSLeadByte,processStopAddress-c-0x1000+4,c-0x1000+4,false);
|
// c = Util::FindCallOrJmpAbs((DWORD)IsDBCSLeadByte,processStopAddress-c-0x1000+4,c-0x1000+4,false);
|
||||||
//}
|
//}
|
||||||
if (!addr) {
|
if (!addr)
|
||||||
|
{
|
||||||
ConsoleOutput("EME: pattern does not exist");
|
ConsoleOutput("EME: pattern does not exist");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
HookParam hp;
|
HookParam hp;
|
||||||
hp.address = addr;
|
hp.address = addr;
|
||||||
hp.offset=get_reg(regs::eax);
|
hp.offset = get_reg(regs::eax);
|
||||||
hp.type = NO_CONTEXT|DATA_INDIRECT|USING_STRING;
|
hp.type = NO_CONTEXT | DATA_INDIRECT | USING_STRING;
|
||||||
ConsoleOutput("INSERT EmonEngine");
|
ConsoleOutput("INSERT EmonEngine");
|
||||||
|
|
||||||
//ConsoleOutput("EmonEngine, hook will only work with text speed set to slow or normal!");
|
// ConsoleOutput("EmonEngine, hook will only work with text speed set to slow or normal!");
|
||||||
//else ConsoleOutput("Unknown EmonEngine engine");
|
// else ConsoleOutput("Unknown EmonEngine engine");
|
||||||
return NewHook(hp, "EmonEngine");
|
return NewHook(hp, "EmonEngine");
|
||||||
}
|
}
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
// LRU template class, recv two type params: key & value
|
||||||
|
template <typename Key>
|
||||||
|
class LRUCache
|
||||||
|
{
|
||||||
|
|
||||||
bool EME::attach_function() {
|
private:
|
||||||
|
// cache capacity
|
||||||
return InsertEMEHook();
|
size_t _capacity = 0;
|
||||||
}
|
// list _keys中key的指向位置
|
||||||
|
std::unordered_map<Key, typename std::list<Key>::iterator> _cache;
|
||||||
|
std::list<Key> _keys;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// construct function
|
||||||
|
LRUCache(size_t size) : _capacity(size){};
|
||||||
|
|
||||||
|
bool contains(Key key)
|
||||||
|
{
|
||||||
|
auto it = _cache.find(key);
|
||||||
|
if (it == _cache.end())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}; // 返回默认值
|
||||||
|
_keys.splice(_keys.begin(), _keys, it->second);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void put(Key key)
|
||||||
|
{
|
||||||
|
auto it = _cache.find(key);
|
||||||
|
if (it != _cache.end())
|
||||||
|
{
|
||||||
|
_keys.splice(_keys.begin(), _keys, it->second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_keys.size() == _capacity)
|
||||||
|
{
|
||||||
|
Key oldKey = _keys.back();
|
||||||
|
_keys.pop_back();
|
||||||
|
_cache.erase(oldKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
_keys.push_front(key);
|
||||||
|
_cache[key] = _keys.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
bool takeout()
|
||||||
|
{
|
||||||
|
//https://vndb.org/v6187
|
||||||
|
//みちくさ~Loitering on the way~
|
||||||
|
|
||||||
|
trigger_fun = [](LPVOID addr, hook_stack *stack)
|
||||||
|
{
|
||||||
|
if (addr != (LPVOID)GetGlyphOutlineA)
|
||||||
|
return false;
|
||||||
|
auto caller = stack->retaddr;
|
||||||
|
auto add = MemDbg::findEnclosingAlignedFunction(caller);
|
||||||
|
if (!add)
|
||||||
|
return true;
|
||||||
|
HookParam hp;
|
||||||
|
hp.address = add;
|
||||||
|
|
||||||
|
hp.type = USING_STRING;
|
||||||
|
hp.offset = get_stack(4);
|
||||||
|
hp.filter_fun = [](LPVOID data, size_t *size, HookParam *)
|
||||||
|
{
|
||||||
|
auto xx = std::string((char *)data, *size);
|
||||||
|
static LRUCache<std::string> last(10);
|
||||||
|
if (last.contains(xx))
|
||||||
|
return false;
|
||||||
|
last.put(xx);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
return NewHook(hp, "takeout");
|
||||||
|
};
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool EME::attach_function()
|
||||||
|
{
|
||||||
|
|
||||||
|
return InsertEMEHook() | takeout();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user