Encryqed / Dumper-7

Unreal Engine SDK Generator
561 stars 144 forks source link

Some suggestions #160

Closed kkptm closed 1 week ago

kkptm commented 1 week ago

my initialization function for the UE engine,this applies to almost all unencrypted UE4-5 games:

#define RELOC(p,o) (void*)((char*)p ? (((char*)p + o + 4) + (*(int*)((char*)p + o))) : NULL)
std::vector<__int16> ParserPattern(const char* text)
{
#define __IS_HEX(c) (c>='0'&&c<='9') ||  (c>='a'&&c<='f') ||  (c>='A'&&c<='F')
#define HextoValue(c) ((c >= '0' && c <= '9') ? c - 48 :(c >= 'a' && c <= 'f') ? c - 87 :(c >= 'A' && c <= 'F') ? c - 55 :0)
    std::vector<__int16> result = std::vector<__int16>();
    int len = strlen(text), clen = 0;
    unsigned char tmp = 0;
    for (int i = 0; i < len; i++) {
        if (__IS_HEX(text[i])) {
            if (clen == 0) {
                tmp = (unsigned char)(HextoValue(text[i]) << 4);
                clen += 1;
            }
            else if (clen == 1) {
                tmp |= HextoValue(text[i]);
                result.push_back(tmp);
                clen = 0;
            }
        }
        else {
            if (text[i] == '?') {
                result.push_back(-1);
                if (text[i + 1] == '?') i += 1;
            }
            clen = 0;
        }
    }
    return result;
}
std::vector<void*> FindAllPattern(const char* szModule, const char* sPattern, int offset = 0)
{
    std::vector<void*> result = std::vector<void*>();
    std::vector<__int16> pattern = ParserPattern(sPattern);
    if (pattern.size() == 0) return result;
    MODULEINFO mi{ };
    HMODULE m = NULL;
    if (szModule)
        m = LoadLibraryA(szModule);
    else
        m = GetModuleHandleA(NULL);
    if (!m)
    {
        printf("GetModule Infomation Failed!\n");
        return result;
    }
    if (GetModuleInformation(GetCurrentProcess(), m, &mi, sizeof(mi)))
    {
        unsigned char* begin = (unsigned char*)mi.lpBaseOfDll;
        DWORD size = mi.SizeOfImage;
        for (unsigned char* p = begin + offset; p < (begin + size) - (pattern.size() + 1); p++)
        {
            for (int o = 0; o < pattern.size(); o++)
            {
                if (p[o] != pattern[o] && pattern[o] != -1)
                {
                    goto nxt;
                }
            }
            result.push_back(p);
        nxt:;
        }
    }
    else
    {
        printf("GetModule Infomation Failed!\n");
    }
    return result;
}
BOOL InitGlobals()
{
    ImageBase = (ULONG64)GetModuleHandleA(NULL);
    BOOL result = TRUE;
    BYTE* tmpaddr = NULL;
    auto FNamefounds = FindAllPattern(NULL, "? 8D 05 ? ? ? ?");
    for (auto p : FNamefounds)
    {
        tmpaddr = (BYTE*)RELOC(p, 3);
        if (!IsBadReadPtr(tmpaddr, 8))
        {
            tmpaddr += 0x10;
            BYTE* strPtr = *(BYTE**)tmpaddr;
            if (!IsBadReadPtr(strPtr, 0x80))
            {
                for (int i = 0; i < 0x40; i++)
                {
                    if (!memcmp(strPtr + i, "None", 4))
                    {
                        NamePool = (FNamePool*)RELOC(p, 3);
                        FName_Head_Size = i;
                        while (memcmp("IntProperty", NamePool->GetEntry(10) + FName_Head_Size, 11))
                        {
                            FName_Stride++;
                        }
                        auto NoneEntry = NamePool->GetEntry(0);
                        auto IntPropertyEntry = NamePool->GetEntry(10);
                        UINT16 info = *(UINT16*)(NamePool->GetEntry(0) + (FName_Head_Size - 2));
                        UINT16 info1 = *(UINT16*)(IntPropertyEntry + (FName_Head_Size - 2));
                        while (info >> FName_LenBit != 4 || info1 >> FName_LenBit != 11)
                            FName_LenBit++;
                        printf("FNamePool Found : %p , HeadSize = %d LenBit = %d\n", RELOC(p, 3), i, FName_LenBit);
                        printf("Test : FName(0) = %ws\n", NamePool->GetName(0).c_str());
                        printf("Test : FName(10) = %ws\n", NamePool->GetName(10).c_str());
                        goto FNAME_SUCESS;
                    }
                }
            }
        }
    }
    printf("FName Not Found\n");
FNAME_SUCESS:
    auto founds = FindAllPattern(NULL, "3B 05 ? ? ? ? 7D");
    if (founds.size() > 0)
    {
        std::unordered_map<void*, int> map = std::unordered_map<void*, int>();
        for (auto p : founds)
        {
            map[p] += 1;
        }
        int mx = 0;
        for (auto it : map)
        {
            if (it.second > mx)
            {
                mx = it.second;
                tmpaddr = (BYTE*)RELOC(it.first, 2);
            }
        }
        tmpaddr -= 0x14;
        GUObjectArray = tmpaddr;
        printf("GUObjectArray = %p\n", GUObjectArray);
    }
    else
    {
        printf("GUObjectArray Not Found\n");
    }

    tmpaddr = (BYTE*)FindPattern(NULL, "E8 ? ? ? ? 48 8B 88 ? ? ? ? 48 89 0D");
    if (tmpaddr)
    {
        UWorldAddress = decltype(UWorldAddress)(RELOC(tmpaddr, 15));
        printf("UWorldAddress = %p\n", UWorldAddress);
    }
    else
    {
        tmpaddr = (BYTE*)FindPattern(NULL, "75 07 48 8B 05 ? ? ? ? C3");
        if (tmpaddr)
        {
            UWorldAddress = decltype(UWorldAddress)(RELOC(tmpaddr, 5));
            printf("UWorldAddress = %p\n", UWorldAddress);
        }
        else
        {
            tmpaddr = (BYTE*)FindPattern(NULL, "48 89 05 ? ? ? ? 0F 28 D6");
            if (tmpaddr)
            {
                UWorldAddress = decltype(UWorldAddress)(RELOC(tmpaddr, 3));
                printf("UWorldAddress = %p\n", UWorldAddress);
            }
            else
            {
                printf("UWorldAddress not found\n");
                result = FALSE;
            }
        }
    }
    tmpaddr = (BYTE*)FindPattern(NULL, "E8 ? ? ? ? 45 33 C9 4C 8B ? 33 D2 48 8B C8 E8 ? ? ? ? 48 8B");
    if (tmpaddr)
    {
        _StaticFindObject = decltype(_StaticFindObject)(RELOC(tmpaddr, 17));
        printf("StaticFindObject = %p\n", _StaticFindObject);
    }
    else
    {
        printf("StaticFindObject not found\n");
        result = FALSE;
    }

    tmpaddr = (BYTE*)FindPattern(NULL, "41 FF ? ? ? ? ? F6 C3 02");
    if (!tmpaddr)
        tmpaddr = (BYTE*)FindPattern(NULL, "FF 90 ? ? 00 00 8B D8 A8 01");

    if (tmpaddr)
    {
        while (*(UINT32*)tmpaddr != 0x57565540)
            tmpaddr--;
        _StaticProcessEvent = decltype(_StaticProcessEvent)(tmpaddr);
        printf("StaticProcessEvent = %p\n", _StaticProcessEvent);
    }
    else
    {
        printf("StaticProcessEvent not found\n");
        result = FALSE;
    }

    UWorld* world = *UWorldAddress;

    ULONG64* vTable = *(ULONG64**)world;
    for (int i = 0; i < 1000; i++)
    {
        if (vTable[i] == (ULONG64)_StaticProcessEvent)
        {
            printf("ProcessEvent Index = %d\n",i);
            break;
        }
    }
    _exit:
    return result;
}
Fischsalat commented 1 week ago

What am I supposed to do with this horrible code?