This commit is contained in:
恍兮惚兮 2024-12-05 12:52:08 +08:00
parent 37b451f3d4
commit 03c5de87e0
10 changed files with 77 additions and 41 deletions

View File

@ -156,7 +156,7 @@ namespace
struct emfuncinfo struct emfuncinfo
{ {
uint64_t type; uint64_t type;
int argidx; int offset;
int padding; int padding;
decltype(HookParam::text_fun) hookfunc; decltype(HookParam::text_fun) hookfunc;
decltype(HookParam::filter_fun) filterfun; decltype(HookParam::filter_fun) filterfun;
@ -192,7 +192,7 @@ namespace
hpinternal.type = USING_STRING | NO_CONTEXT | BREAK_POINT | op.type; hpinternal.type = USING_STRING | NO_CONTEXT | BREAK_POINT | op.type;
hpinternal.text_fun = op.hookfunc; hpinternal.text_fun = op.hookfunc;
hpinternal.filter_fun = op.filterfun; hpinternal.filter_fun = op.filterfun;
hpinternal.argidx = op.argidx; hpinternal.offset = op.offset;
hpinternal.padding = op.padding; hpinternal.padding = op.padding;
hpinternal.jittype = JITTYPE::RPCS3; hpinternal.jittype = JITTYPE::RPCS3;
NewHook(hpinternal, op._id); NewHook(hpinternal, op._id);

View File

@ -30,7 +30,7 @@ namespace
struct emfuncinfo struct emfuncinfo
{ {
uint64_t type; uint64_t type;
int argidx; int offset;
int padding; int padding;
decltype(HookParam::text_fun) hookfunc; decltype(HookParam::text_fun) hookfunc;
decltype(HookParam::filter_fun) filterfun; decltype(HookParam::filter_fun) filterfun;
@ -117,10 +117,12 @@ bool vita3k::attach_function()
HookParam hpinternal; HookParam hpinternal;
hpinternal.address = entrypoint; hpinternal.address = entrypoint;
hpinternal.emu_addr = em_address; // 用于生成hcode hpinternal.emu_addr = em_address; // 用于生成hcode
hpinternal.type = USING_STRING | NO_CONTEXT | BREAK_POINT | op.type; hpinternal.type = NO_CONTEXT | BREAK_POINT | op.type;
if (!(op.type & USING_CHAR))
hpinternal.type |= USING_STRING;
hpinternal.text_fun = op.hookfunc; hpinternal.text_fun = op.hookfunc;
hpinternal.filter_fun = op.filterfun; hpinternal.filter_fun = op.filterfun;
hpinternal.argidx = op.argidx; hpinternal.offset = op.offset;
hpinternal.padding = op.padding; hpinternal.padding = op.padding;
hpinternal.jittype = JITTYPE::VITA3K; hpinternal.jittype = JITTYPE::VITA3K;
NewHook(hpinternal, op._id); NewHook(hpinternal, op._id);
@ -245,6 +247,14 @@ namespace
s = std::regex_replace(s, std::regex(R"(\\n)"), ""); s = std::regex_replace(s, std::regex(R"(\\n)"), "");
buffer->from(s); buffer->from(s);
} }
void PCSG00530(TextBuffer *buffer, HookParam *)
{
StringFilter(buffer, "#n", 2);
}
void PCSG00833(TextBuffer *buffer, HookParam *)
{
StringFilter(buffer, u8" ", strlen(u8" "));
}
void PCSG00787(TextBuffer *buffer, HookParam *) void PCSG00787(TextBuffer *buffer, HookParam *)
{ {
CharFilter(buffer, '\n'); CharFilter(buffer, '\n');
@ -301,6 +311,29 @@ namespace
Trim(ws); Trim(ws);
buffer->from(WideStringToString(ws)); buffer->from(WideStringToString(ws));
} }
void PCSG01011(hook_stack *stack, HookParam *hp, TextBuffer *buffer, uintptr_t *split)
{
auto address = VITA3K::emu_arg(stack)[7];
while (*(char *)(address - 1))
address -= 1;
buffer->from((char *)address);
static std::string last;
auto s = buffer->strA();
if (s == last)
{
buffer->clear();
last = s;
}
else
{
last = s;
strReplace(s, "\n", "");
auto pos = s.find(u8"×");
if (pos != s.npos)
s = s.substr(pos + strlen(u8"×"));
buffer->from(s);
}
}
void PCSG00912(hook_stack *stack, HookParam *hp, TextBuffer *buffer, uintptr_t *split) void PCSG00912(hook_stack *stack, HookParam *hp, TextBuffer *buffer, uintptr_t *split)
{ {
auto address = VITA3K::emu_arg(stack)[1]; auto address = VITA3K::emu_arg(stack)[1];
@ -616,6 +649,15 @@ namespace
{0x8002BB78, {CODEC_UTF8, 0, 0, 0, PCSG00787, "PCSG00787"}}, // zip安装版 {0x8002BB78, {CODEC_UTF8, 0, 0, 0, PCSG00787, "PCSG00787"}}, // zip安装版
// ニセコイ ヨメイリ!? // ニセコイ ヨメイリ!?
{0x8189e60c, {CODEC_UTF8, 4, 0, 0, 0, "PCSG00397"}}, {0x8189e60c, {CODEC_UTF8, 4, 0, 0, 0, "PCSG00397"}},
// DIABOLIK LOVERS DARK FATE
{0x8002CF8E, {0, 1, 0, 0, PCSG00530, "PCSG00530"}},
// DIABOLIK LOVERS LOST EDEN
{0x8007443E, {0, 0, 0, 0, 0, "PCSG00910"}},
// NORN9 ACT TUNE
{0x8001E288, {CODEC_UTF8, 0, 0, 0, PCSG00833, "PCSG00833"}},
// 空蝉の廻
{0x82535242, {CODEC_UTF16 | USING_CHAR | DATA_INDIRECT, 1, 0, 0, 0, "PCSG01011"}}, // 后缀有人名,需要额外过滤
{0x801AE35A, {CODEC_UTF8, 7, 0, PCSG01011, 0, "PCSG01011"}},
}; };
return 1; return 1;
}(); }();

View File

@ -46,7 +46,7 @@ namespace
struct emfuncinfo struct emfuncinfo
{ {
uint64_t type; uint64_t type;
int argidx; int offset;
int padding; int padding;
decltype(HookParam::text_fun) hookfunc; decltype(HookParam::text_fun) hookfunc;
decltype(HookParam::filter_fun) filterfun; decltype(HookParam::filter_fun) filterfun;
@ -204,7 +204,7 @@ bool yuzu::attach_function()
hpinternal.type |= USING_STRING; hpinternal.type |= USING_STRING;
hpinternal.text_fun = op.hookfunc; hpinternal.text_fun = op.hookfunc;
hpinternal.filter_fun = op.filterfun; hpinternal.filter_fun = op.filterfun;
hpinternal.argidx = op.argidx; hpinternal.offset = op.offset;
hpinternal.padding = op.padding; hpinternal.padding = op.padding;
hpinternal.jittype = JITTYPE::YUZU; hpinternal.jittype = JITTYPE::YUZU;
NewHook(hpinternal, ull2hex(op._id).c_str()); NewHook(hpinternal, ull2hex(op._id).c_str());

View File

@ -71,7 +71,7 @@ namespace monocommon
const char *klassName; const char *klassName;
const char *name; const char *name;
int argsCount; int argsCount;
int argidx; int offset;
decltype(HookParam::text_fun) text_fun = nullptr; decltype(HookParam::text_fun) text_fun = nullptr;
bool Embed = false; bool Embed = false;
bool isstring = true; bool isstring = true;
@ -93,7 +93,7 @@ namespace monocommon
HookParam hp; HookParam hp;
hp.address = addr; hp.address = addr;
hp.argidx = hook.argidx; hp.offset = hook.offset;
hp.text_fun = (decltype(hp.text_fun))hook.text_fun; hp.text_fun = (decltype(hp.text_fun))hook.text_fun;
if (hook.isstring) if (hook.isstring)
{ {

View File

@ -349,7 +349,7 @@ namespace ppsspp
hpinternal.type = USING_STRING | NO_CONTEXT | BREAK_POINT | op.type; hpinternal.type = USING_STRING | NO_CONTEXT | BREAK_POINT | op.type;
hpinternal.text_fun = op.hookfunc; hpinternal.text_fun = op.hookfunc;
hpinternal.filter_fun = op.filterfun; hpinternal.filter_fun = op.filterfun;
hpinternal.argidx = op.argidx; hpinternal.offset = op.offset;
hpinternal.padding = op.padding; hpinternal.padding = op.padding;
hpinternal.jittype = JITTYPE::PPSSPP; hpinternal.jittype = JITTYPE::PPSSPP;
NewHook(hpinternal, op._id); NewHook(hpinternal, op._id);

View File

@ -6,7 +6,7 @@ namespace ppsspp
struct emfuncinfo struct emfuncinfo
{ {
uint64_t type; uint64_t type;
int argidx; int offset;
int padding; int padding;
decltype(HookParam::text_fun) hookfunc; decltype(HookParam::text_fun) hookfunc;
decltype(HookParam::filter_fun) filterfun; decltype(HookParam::filter_fun) filterfun;

View File

@ -1,6 +1,6 @@
#include "MinHook.h" #include "MinHook.h"
#define SEARCH_SJIS_UNSAFE 0 #define DUMP_JIT_ADDR_MAP 0
namespace namespace
{ {
SearchParam sp; SearchParam sp;
@ -10,7 +10,6 @@ namespace
{ {
uint64_t address = 0; uint64_t address = 0;
uint64_t em_addr = 0; uint64_t em_addr = 0;
int argidx = 0;
intptr_t padding = 0; intptr_t padding = 0;
int offset = 0; int offset = 0;
JITTYPE jittype; JITTYPE jittype;
@ -134,7 +133,7 @@ void DoSend(int i, uintptr_t address, char *str, intptr_t padding, JITTYPE jitty
int length = 0, sum = 0; int length = 0, sum = 0;
for (; *(uint16_t *)(str + length) && length < MAX_STRING_SIZE; length += sizeof(uint16_t)) for (; *(uint16_t *)(str + length) && length < MAX_STRING_SIZE; length += sizeof(uint16_t))
sum += *(uint16_t *)(str + length); sum += *(uint16_t *)(str + length);
#if SEARCH_SJIS_UNSAFE #if DUMP_JIT_ADDR_MAP
if (((length > STRING) || (IsDBCSLeadByteEx(932, *str))) && length < MAX_STRING_SIZE - 1) if (((length > STRING) || (IsDBCSLeadByteEx(932, *str))) && length < MAX_STRING_SIZE - 1)
#else #else
if (length > STRING && length < MAX_STRING_SIZE - 1) if (length > STRING && length < MAX_STRING_SIZE - 1)
@ -142,7 +141,7 @@ void DoSend(int i, uintptr_t address, char *str, intptr_t padding, JITTYPE jitty
{ {
// many duplicate results with same address, offset, and third/fourth character will be found: filter them out // many duplicate results with same address, offset, and third/fourth character will be found: filter them out
uint64_t signature = ((uint64_t)i << 56) | ((uint64_t)(str[2] + str[3]) << 48) | address; uint64_t signature = ((uint64_t)i << 56) | ((uint64_t)(str[2] + str[3]) << 48) | address;
#if SEARCH_SJIS_UNSAFE #if DUMP_JIT_ADDR_MAP
#else #else
if (signatureCache[signature % CACHE_SIZE] == signature) if (signatureCache[signature % CACHE_SIZE] == signature)
return; return;
@ -165,7 +164,7 @@ void DoSend(int i, uintptr_t address, char *str, intptr_t padding, JITTYPE jitty
else else
{ {
records[n].em_addr = em_addr; records[n].em_addr = em_addr;
records[n].argidx = i; records[n].offset = i;
} }
for (int j = 0; j < length; ++j) for (int j = 0; j < length; ++j)
@ -290,12 +289,12 @@ void SearchForHooks_Return()
hp.codepage = sp.codepage; hp.codepage = sp.codepage;
hp.jittype = records[i].jittype; hp.jittype = records[i].jittype;
hp.padding = records[i].padding; hp.padding = records[i].padding;
hp.offset = records[i].offset;
if (records[i].jittype == JITTYPE::PC) if (records[i].jittype == JITTYPE::PC)
{ {
if (!records[i].address) if (!records[i].address)
continue; continue;
hp.offset = records[i].offset;
hp.type = CODEC_UTF16 | USING_STRING; hp.type = CODEC_UTF16 | USING_STRING;
hp.address = records[i].address; hp.address = records[i].address;
} }
@ -305,7 +304,6 @@ void SearchForHooks_Return()
continue; continue;
hp.emu_addr = records[i].em_addr; hp.emu_addr = records[i].em_addr;
hp.type = CODEC_UTF16 | USING_STRING | BREAK_POINT | NO_CONTEXT; hp.type = CODEC_UTF16 | USING_STRING | BREAK_POINT | NO_CONTEXT;
hp.argidx = records[i].argidx;
} }
NotifyHookFound(hp, (wchar_t *)records[i].text); NotifyHookFound(hp, (wchar_t *)records[i].text);
if (++results % 100'000 == 0) if (++results % 100'000 == 0)
@ -479,7 +477,7 @@ void SearchForHooks(SearchParam spUser)
} }
ConsoleOutput("%p %p",minemaddr,maxemaddr); ConsoleOutput("%p %p",minemaddr,maxemaddr);
ConsoleOutput("%p %p",sp.minAddress,sp.maxAddress); ConsoleOutput("%p %p",sp.minAddress,sp.maxAddress);
#if SEARCH_SJIS_UNSAFE #if DUMP_JIT_ADDR_MAP
auto f=fopen("1.txt","a"); auto f=fopen("1.txt","a");
for(auto addr:jitaddr2emuaddr){ for(auto addr:jitaddr2emuaddr){
fprintf(f,"%llx => %llx\n", addr.second.second ,addr.first); fprintf(f,"%llx => %llx\n", addr.second.second ,addr.first);

View File

@ -190,20 +190,25 @@ uintptr_t queryrelativeret(HookParam &hp, uintptr_t retaddr)
return relative; return relative;
} }
uintptr_t jitgetaddr(hook_stack *stack, HookParam *hp) uintptr_t jitgetaddr(hook_stack *stack, HookParam *hp, bool offset)
{ {
int off;
if (offset)
off = hp->offset;
else
off = hp->split;
switch (hp->jittype) switch (hp->jittype)
{ {
#ifdef _WIN64 #ifdef _WIN64
case JITTYPE::RPCS3: case JITTYPE::RPCS3:
return RPCS3::emu_arg(stack)[hp->argidx]; return RPCS3::emu_arg(stack)[off];
case JITTYPE::VITA3K: case JITTYPE::VITA3K:
return VITA3K::emu_arg(stack)[hp->argidx]; return VITA3K::emu_arg(stack)[off];
case JITTYPE::YUZU: case JITTYPE::YUZU:
return YUZU::emu_arg(stack, hp->emu_addr)[hp->argidx]; return YUZU::emu_arg(stack, hp->emu_addr)[off];
#endif #endif
case JITTYPE::PPSSPP: case JITTYPE::PPSSPP:
return PPSSPP::emu_arg(stack)[hp->argidx]; return PPSSPP::emu_arg(stack)[off];
default: default:
return 0; return 0;
} }
@ -280,12 +285,12 @@ void TextHook::Send(uintptr_t lpDataBase)
if (hp.jittype != JITTYPE::PC && hp.jittype != JITTYPE::UNITY) if (hp.jittype != JITTYPE::PC && hp.jittype != JITTYPE::UNITY)
{ {
lpDataIn = jitgetaddr(stack, &hp); lpDataIn = jitgetaddr(stack, &hp, true);
plpdatain = (uintptr_t)&lpDataIn; plpdatain = (uintptr_t)&lpDataIn;
} }
else if (hp.jittype == JITTYPE::UNITY) else if (hp.jittype == JITTYPE::UNITY)
{ {
plpdatain = (uintptr_t)argidx(stack, hp.argidx); plpdatain = (uintptr_t)argidx(stack, hp.offset);
lpDataIn = *(uintptr_t *)plpdatain; lpDataIn = *(uintptr_t *)plpdatain;
} }
@ -304,7 +309,10 @@ void TextHook::Send(uintptr_t lpDataBase)
lpSplit = FIXED_SPLIT_VALUE; // fuse all threads, and prevent floating lpSplit = FIXED_SPLIT_VALUE; // fuse all threads, and prevent floating
else if (hp.type & USING_SPLIT) else if (hp.type & USING_SPLIT)
{ {
lpSplit = *(uintptr_t *)(lpDataBase + hp.split); if (hp.jittype != JITTYPE::PC && hp.jittype != JITTYPE::UNITY)
lpSplit = jitgetaddr(stack, &hp, false);
else
lpSplit = *(uintptr_t *)(lpDataBase + hp.split);
if (hp.type & SPLIT_INDIRECT) if (hp.type & SPLIT_INDIRECT)
lpSplit = *(uintptr_t *)(lpSplit + hp.split_index); lpSplit = *(uintptr_t *)(lpSplit + hp.split_index);
} }
@ -418,7 +426,7 @@ void TextHook::Send(uintptr_t lpDataBase)
else if (hp.type & SPECIAL_JIT_STRING) else if (hp.type & SPECIAL_JIT_STRING)
{ {
if (hp.jittype == JITTYPE::UNITY) if (hp.jittype == JITTYPE::UNITY)
unity_ui_string_embed_fun(argidx(stack, hp.argidx), buff); unity_ui_string_embed_fun(argidx(stack, hp.offset), buff);
} }
} }
} }

View File

@ -186,8 +186,6 @@ namespace
return {}; return {};
HCode.erase(0, 1); HCode.erase(0, 1);
HCode = HCode.substr(0, HCode.size() - wcslen(L":JIT:UNITY")); HCode = HCode.substr(0, HCode.size() - wcslen(L":JIT:UNITY"));
hp.argidx = hp.offset;
hp.offset = 0;
hp.address = 0; hp.address = 0;
hp.type &= ~MODULE_OFFSET; hp.type &= ~MODULE_OFFSET;
hp.type &= ~FUNCTION_OFFSET; hp.type &= ~FUNCTION_OFFSET;
@ -223,8 +221,6 @@ namespace
if (hp.jittype != JITTYPE::PC) if (hp.jittype != JITTYPE::PC)
{ {
hp.emu_addr = hp.address; hp.emu_addr = hp.address;
hp.argidx = hp.offset;
hp.offset = 0;
hp.address = 0; hp.address = 0;
hp.type &= ~MODULE_OFFSET; hp.type &= ~MODULE_OFFSET;
hp.type &= ~FUNCTION_OFFSET; hp.type &= ~FUNCTION_OFFSET;
@ -363,14 +359,7 @@ namespace
if (hp.split < 0) if (hp.split < 0)
hp.split += 4; hp.split += 4;
if (hp.jittype == JITTYPE::PC) HCode += HexString(hp.offset);
{
HCode += HexString(hp.offset);
}
else
{
HCode += HexString(hp.argidx);
}
if (hp.type & DATA_INDIRECT) if (hp.type & DATA_INDIRECT)
HCode += L'*' + HexString(hp.index); HCode += L'*' + HexString(hp.index);

View File

@ -123,7 +123,6 @@ struct HookParam
ZeroMemory(this, sizeof(HookParam)); ZeroMemory(this, sizeof(HookParam));
} }
uint64_t emu_addr; uint64_t emu_addr;
int argidx;
JITTYPE jittype; JITTYPE jittype;
char unityfunctioninfo[1024]; char unityfunctioninfo[1024];
}; };