Skip to content

Commit

Permalink
refactor and add error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Artikash committed Aug 12, 2020
1 parent 39b0882 commit b4303e4
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions texthook/engine/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6672,25 +6672,27 @@ bool InsertNitroplusHook()

namespace TokyoNecro {

const BYTE funcSig[] = { 0x55, 0x8b, 0xec };

bool TextHook() {

const BYTE bytecodes[] = {
0x8B, 0xF8, // 8B F8 - mov edi,eax
0x8D, 0x75, 0xD8, // 8D 75 D8 - lea esi,[ebp-28]
0xE8, 0x6C, 0xE1, 0xF4, 0xFF, // E8 6CE1F4FF - call TokyoNecro.exe+35E0
};
ULONG range = min(processStopAddress - processStartAddress, MAX_REL_ADDR);
ULONG addr =
MemDbg::findBytes(bytecodes, sizeof(bytecodes), processStartAddress,
processStartAddress + range);

if (addr == 0ull) {
ConsoleOutput("vnreng:TokyoNecro: pattern not found");
ULONG addr = MemDbg::findBytes(bytecodes, sizeof(bytecodes), processStartAddress, processStopAddress);
if (addr == 0) {
ConsoleOutput("Textractor:TokyoNecro: pattern not found");
return false;
}

// Look for the start of the function
const ULONG function_start = MemDbg::findEnclosingAlignedFunction(addr);
if (memcmp((void*)function_start, funcSig, sizeof(funcSig)) != 0) {
ConsoleOutput("Textractor: TokyoNecro: function start not found");
return false;
}

HookParam hp = {};
hp.address = function_start;
Expand All @@ -6701,10 +6703,8 @@ bool TextHook() {
// using the data in the registers
hp.offset = 0x4;
hp.type = USING_STRING;
ConsoleOutput("Textractor: INSERT TokyoNecroText");
NewHook(hp, "TokyoNecroText");

ConsoleOutput("vnreng: INSERT TokyoNecroText");

return true;
}

Expand Down Expand Up @@ -6752,38 +6752,34 @@ bool DatabaseHook()
0x8D, 0x75, 0xD8, // 8D 75 D8 - lea esi,[ebp-28]
0xE8, 0x0C, 0xE2, 0xF4, 0xFF, // E8 6CE1F4FF - call TokyoNecro.exe+35E0
};
ULONG range = min(processStopAddress - processStartAddress, MAX_REL_ADDR);
ULONG addr =
MemDbg::findBytes(bytecodes, sizeof(bytecodes), processStartAddress,
processStartAddress + range);

if (addr == 0ull) {
ULONG addr = MemDbg::findBytes(bytecodes, sizeof(bytecodes), processStartAddress, processStopAddress);
if (addr == 0) {
ConsoleOutput("vnreng:TokyoNecro: pattern not found");
return false;
}

// Look for the start of the function
const ULONG function_start = MemDbg::findEnclosingAlignedFunction(addr);
if (memcmp((void*)function_start, funcSig, sizeof(funcSig)) != 0) {
ConsoleOutput("Textractor: TokyoNecro: function start not found");
return false;
}

HookParam hp = {};
hp.address = function_start;
hp.offset = 0x4;
hp.type = USING_STRING;
NewHook(hp, "TokyoNecroDatabase");

ConsoleOutput("vnreng: INSERT TokyoNecroDatabase");

return true;
}

} // namespace TokyoNecro

bool InsertTokyoNecroHook()
{
bool result = TokyoNecro::TextHook();
result = TokyoNecro::DatabaseHook() || result;

return result;
TokyoNecro::DatabaseHook();
return TokyoNecro::TextHook();
}

// jichi 6/21/2015
Expand Down

0 comments on commit b4303e4

Please sign in to comment.