This commit is contained in:
恍兮惚兮 2024-07-26 02:38:25 +08:00
parent fe8719cd46
commit ed6e34302e
2 changed files with 170 additions and 130 deletions

View File

@ -1,15 +1,18 @@
#include "Debonosu.h"
namespace { // unnamed
namespace
{ // unnamed
int _type;
void SpecialHookDebonosuScenario(hook_stack *stack, HookParam *hp, uintptr_t *data, uintptr_t *split, size_t *len)
{
DWORD retn = stack->retaddr;
if (*(WORD *)retn == 0xc483){ // add esp, $ old Debonosu game
if (*(WORD *)retn == 0xc483)
{ // add esp, $ old Debonosu game
hp->offset = get_stack(1);
_type = 1;
}
else{ // new Debonosu game
else
{ // new Debonosu game
hp->offset = get_reg(regs::eax);
_type = 2;
}
@ -19,21 +22,25 @@ void SpecialHookDebonosuScenario(hook_stack* stack, HookParam *hp, uintptr_t *d
*len = ::strlen((char *)*data);
*split = FIXED_SPLIT_VALUE;
}
void hook_after(hook_stack*s,void* data, size_t len){
void hook_after(hook_stack *s, void *data, size_t len)
{
static std::string ts;
ts = std::string((LPSTR)data, len);
if(_type==1){
if (_type == 1)
{
s->stack[1] = (DWORD)ts.c_str();
}
else{
else
{
s->ecx = (DWORD)ts.c_str();
}
}
bool InsertDebonosuScenarioHook()
{
DWORD addr = Util::FindImportEntry(processStartAddress, (DWORD)lstrcatA);
if (!addr) {
if (!addr)
{
ConsoleOutput("Debonosu: lstrcatA is not called");
return false;
}
@ -42,12 +49,14 @@ bool InsertDebonosuScenarioHook()
for (DWORD i = processStartAddress; i < processStopAddress - 4; i++)
if (*(DWORD *)i == search &&
*(WORD *)(i + 4) == addr && // call dword ptr lstrcatA
*(BYTE *)(i - 5) == 0x68) { // push $
*(BYTE *)(i - 5) == 0x68)
{ // push $
DWORD push = *(DWORD *)(i - 4);
for (DWORD j = i + 6, k = j + 0x10; j < k; j++)
if (*(BYTE *)j == 0xb8 &&
*(DWORD *)(j + 1) == push)
if (DWORD hook_addr = SafeFindEnclosingAlignedFunction(i, 0x200)) {
if (DWORD hook_addr = SafeFindEnclosingAlignedFunction(i, 0x200))
{
HookParam hp;
hp.address = hook_addr;
hp.text_fun = SpecialHookDebonosuScenario;
@ -55,7 +64,8 @@ bool InsertDebonosuScenarioHook()
hp.hook_after = hook_after;
hp.hook_font = F_MultiByteToWideChar | F_GetTextExtentPoint32A;
hp.type = USING_STRING | NO_CONTEXT | USING_SPLIT | FIXING_SPLIT | EMBED_ABLE | EMBED_BEFORE_SIMPLE | EMBED_DYNA_SJIS; // there is only one thread
hp.filter_fun=[](void* data, size_t* len, HookParam* hp){
hp.filter_fun = [](void *data, size_t *len, HookParam *hp)
{
return write_string_overwrite(data, len, std::regex_replace(std::string((char *)data, *len), std::regex("\\{(.*?)/(.*?)\\}"), "$1"));
};
ConsoleOutput("INSERT Debonosu");
@ -98,7 +108,8 @@ bool InsertDebonosuNameHook()
0x57 // 0032f678 57 push edi
};
ULONG addr = MemDbg::findBytes(bytes, sizeof(bytes), processStartAddress, processStopAddress);
if (!addr) {
if (!addr)
{
ConsoleOutput("DebonosuName: pattern NOT FOUND");
return false;
}
@ -122,7 +133,8 @@ bool attach(ULONG startAddress, ULONG stopAddress)
if (addr = MemDbg::findBytes(msg, ::strlen(msg + 1), startAddress, stopAddress))
addr = MemDbg::findPushAddress(addr, startAddress, stopAddress);
}
if (!addr) {
if (!addr)
{
const uint8_t bytes[] = {
0x50, // 0010fb80 50 push eax
@ -132,12 +144,14 @@ bool attach(ULONG startAddress, ULONG stopAddress)
};
addr = MemDbg::findBytes(bytes, sizeof(bytes), startAddress, stopAddress);
}
if (!addr) {
if (!addr)
{
return false;
}
// addr = MemDbg::findEnclosingAlignedFunction(addr); // This might not work as the address is not always aligned
addr = MemDbg::findEnclosingFunctionAfterInt3(addr);
if (!addr) {
if (!addr)
{
return false;
}
HookParam hp;
@ -149,17 +163,44 @@ bool attach(ULONG startAddress, ULONG stopAddress)
return NewHook(hp, "Debonosu2");
}
namespace
{
bool debox()
{
//[240726][1282636][でぼの巣製作所] 神楽漫遊記~桂香と初花~ DL版 (files)
auto lua51 = GetModuleHandle(L"lua5.1.dll");
if (!lua51)
return false;
auto lua_tolstring = (DWORD)GetProcAddress(lua51, "lua_tolstring");
if (!lua_tolstring)
return false;
auto addrs = findiatcallormov_all(lua_tolstring, processStartAddress, processStartAddress, processStopAddress, PAGE_EXECUTE);
auto succ = false;
for (auto addr : addrs)
{
HookParam hp;
hp.address = addr + 6;
hp.type = USING_STRING | NO_CONTEXT;
hp.offset = get_reg(regs::eax);
succ |= NewHook(hp, "debonosu");
}
return succ;
}
}
bool InsertDebonosuHook()
{
bool ok = InsertDebonosuScenarioHook();
bool ok = InsertDebonosuScenarioHook() || debox();
if (ok)
InsertDebonosuNameHook();
return ok;
}
bool Debonosu::attach_function() {
bool Debonosu::attach_function()
{
// 1/1/2016 jich: skip izumo4 from studio ego that is not supported by debonosu
if (Util::CheckFile(L"*izumo4*.exe")) {
if (Util::CheckFile(L"*izumo4*.exe"))
{
PcHooks::hookOtherPcFunctions();
return true;
}

View File

@ -362,7 +362,6 @@ void TextHook::Send(uintptr_t lpDataBase)
parsenewlineseperator(pbData, &lpCount);
bool canembed;
;
if (hp.type & EMBED_ABLE)
{
if (!checklengthembedable(hp, lpCount))