Skip to content

Commit

Permalink
修复部分选择支替换失败的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ssynn committed Jun 23, 2020
1 parent 37eb604 commit 689e428
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 14 deletions.
Binary file modified bin/hook_lilim.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@

## 注意
1. 仅支持AOS2
2. 字典内不能出现除 \\n \\f [ ] 以外的任何半角字符,可以使用 fix_dixt 把半角转换为全角字符
2. 字典内不能出现除 \\n \\f [ ] 以外的任何半角字符,可以使用 fix_dict 把半角转换为全角字符
3. 提取文本后记得检查,删除字典内不该提取的文本
4. 部分代码参考(复制)Textractor
82 changes: 69 additions & 13 deletions scr/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ void FillRange();
void loadJpChs();
void HookSelection();
void UnHookSelection();
void ReplaceSelection();
//void ReplaceSelection();
void __fastcall ReplaceSelection2(void* pThis);


DWORD findBytes(const void* pattern, DWORD patternSize, DWORD lowerBound, DWORD upperBound);


BOOL APIENTRY DllMain( HMODULE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
Expand Down Expand Up @@ -76,7 +79,7 @@ void Hook()
{
// 1. 初始化地址
void* addr = OpenProcessAddr;

// 2. Hook
//一般代码段是不可写的,需要改成可写
VirtualProtect((LPVOID)addr, 5, PAGE_EXECUTE_READWRITE, &oldProtect);
Expand Down Expand Up @@ -170,8 +173,8 @@ void InitGlobal()
{
//char** table;
vector<vector<unsigned char>> table = {
{ 0x83, 0xC4, 0x08, 0x83, 0xFF, 0x02 }, // log函数
{ 0x53, 0x56, 0x57, 0x68, 0x00, 0x00, 0x04, 0x00, 0xE8 }, // 选择支HOOK点
{ 0x83, 0xC4, 0x08, 0x83, 0xFF, 0x02 }, // log函数
{ 0x53, 0x8B, 0xD9, 0x56, 0x8B, 0x35 }, // 选择支HOOK点
{ 0xFF, 0xD5, 0x68, 0x00, 0x00, 0x01, 0x00, 0x6A, 0x08, 0x50, 0xFF, 0xD6}, // 文本全局变量
{ 0x53, 0x53, 0x53, 0x53, 0x53, 0x53, 0xB9, 0x02, 0x00, 0x00, 0x00, 0xE8}, // 人名全局变量
{ 0x83, 0xC4, 0x08, 0x33, 0xC9, 0x39, 0x37, 0x74}, // 选择支全局变量
Expand All @@ -197,7 +200,7 @@ void InitGlobal()
{0xba, 0xda, 0xcc, 0xe5, 0x00}
};

int offset[] = {-0x69, -0x26, 0x12, 0x15, -0x4, 0x41, 0xA, -0xA, 0, 0, 0};
int offset[] = { -0x69, -0x1A, 0x12, 0x15, -0x4, 0x41, 0xA, -0xA, 0, 0, 0 };

FillRange();
Log(processStartAddress);
Expand Down Expand Up @@ -262,12 +265,12 @@ void loadIni()
void myFunc()
{
//printf("oldProtect: %d\nOpenProcessAddr: %x\nJmpByte: %x", oldProtect, OpenProcessAddr, *(int*)&JmpByte[1]);

char* p = (char*)*textAddr;
char* pWrite = p;
char* pName = (char*)nameAddr;

char buffer[1000] = {0};
char buffer[1000] = { 0 };
int cnt = 0;
while (cnt < 1000 && *p)
{
Expand All @@ -283,7 +286,7 @@ void myFunc()
// 替换文本
string temp(buffer);
auto vk = jp_chs.find(temp);
char* newText=NULL;
char* newText = NULL;
if (vk != jp_chs.end())
{
// 替换文本
Expand All @@ -306,7 +309,7 @@ void myFunc()
*pName = 0x00;
}
}

UnHook();
if (newText)
{
Expand All @@ -316,7 +319,7 @@ void myFunc()
{
(*(void(*)(char*))OpenProcessAddr)(buffer);
}

Hook();
}

Expand All @@ -328,7 +331,7 @@ void HookSelection()
VirtualProtect(addr, 5, PAGE_EXECUTE_READWRITE, &oldProtextSelection);

JmpByteSelection[0] = 0xE9;
*(DWORD*)&JmpByteSelection[1] = (DWORD)ReplaceSelection - (DWORD)addr - (DWORD)5;
*(DWORD*)&JmpByteSelection[1] = (DWORD)ReplaceSelection2 - (DWORD)addr - (DWORD)5;

memcpy(OldByteSelection, (void*)addr, 5);

Expand All @@ -343,7 +346,7 @@ void UnHookSelection()
VirtualProtect((LPVOID)OutputSelectionAddr, 5, oldProtextSelection, &p);
}


#if 0
void ReplaceSelection()
{
/*
Expand Down Expand Up @@ -391,6 +394,59 @@ void ReplaceSelection()
(*(void(*)())OutputSelectionAddr)();
HookSelection();
}
#endif

void __fastcall ReplaceSelection2(void* pThis)
{
/*
选择支文本可能出现的位置
[*(*addr+(0|4|8|c))+0x120]
*/
if (*PointersPage)
{
int* addPointer = (int*)*PointersPage;
while (*addPointer != 0x00000000 && *addPointer != 0xFFFFFFFF)
{
char* text = (char*)*addPointer;
text += 0x110;
string oldText(text);
if (*text)
{
auto vk = jp_chs.find(oldText);
if (vk != jp_chs.end())
{
for (int i = 0; i < vk->second.length(); i++)
{
text[i] = vk->second[i];
}
text[vk->second.length()] = 0x00;
}
}

text += 0x10;
oldText = string(text);
if (*text)
{
auto vk = jp_chs.find(oldText);
if (vk != jp_chs.end())
{
for (int i = 0; i < vk->second.length(); i++)
{
text[i] = vk->second[i];
}
text[vk->second.length()] = 0x00;
}
}

addPointer++;
}
}


UnHookSelection();
(*(void(__fastcall*)(void*))OutputSelectionAddr)(pThis);
HookSelection();
}


void FillRange()
Expand Down

0 comments on commit 689e428

Please sign in to comment.