首页
社区
课程
招聘
[原创]UnrealEngine 5 逆向之类名算法的实现
发表于: 2023-8-13 13:43 10958

[原创]UnrealEngine 5 逆向之类名算法的实现

2023-8-13 13:43
10958

//At engine_struct.h
#ifndef _ENGINE_STRUCT_
#define _ENGINE_STRUCT_
#include "..\global_includes.h"
 
static constexpr uint32_t FNameMaxBlockBits = 13;
static constexpr uint32_t FNameBlockOffsetBits = 16;
static constexpr uint32_t FNameMaxBlocks = 1 << FNameMaxBlockBits;
static constexpr uint32_t FNameBlockOffsets = 1 << FNameBlockOffsetBits;
 
 
struct FNameEntryId;
struct FNameEntryHandle;
struct FNameEntryHeader;
struct FNameEntry;
 
class FNameEntryAllocator;
class FNamePool;
class FName;
 
 
 
 
struct FNameEntryId
{
public:
    uint32_t ToUnstableInt() const { return Value; }
    static FNameEntryId FromUnstableInt(uint32_t Value)
    {
        FNameEntryId Id;
        Id.Value = Value;
        return Id;
    }
private:
    uint32_t Value;
 
};
struct FNameEntryHandle
{
    uint32_t Block = 0;
    uint32_t Offset = 0;
 
    FNameEntryHandle(uint32_t InBlock, uint32_t InOffset)
        : Block(InBlock)
        , Offset(InOffset)
    {}
 
    FNameEntryHandle(FNameEntryId Id)
        : Block(Id.ToUnstableInt() >> FNameBlockOffsetBits)
        , Offset(Id.ToUnstableInt()& (FNameBlockOffsets - 1))
    {}
 
    operator FNameEntryId() const
    {
        return FNameEntryId::FromUnstableInt(Block << FNameBlockOffsetBits | Offset);
    }
 
    explicit operator bool() const { return Block | Offset; }
};
struct FNameEntryHeader
{
    uint16_t bIsWide : 1;
    static constexpr uint32_t ProbeHashBits = 5;
    uint16_t LowercaseProbeHash : ProbeHashBits;
    uint16_t Len : 10;
 
};
struct FNameEntry
{
private:
 
    FNameEntryHeader Header;
    union
    {
        char    AnsiName[1024];
        wchar_t WideName[1024];
    };
public:
    bool isEmpty();
    bool isWide();
 
 
    DWORD getHashValue();
    DWORD getLength();
    std::string getAnsiName();
    std::wstring getWideName();
};
 
class FNameEntryAllocator
{
private:
    void* Lock; //底层就是void* Ptr
    uint32_t CurrentBlock = 0;
    uint32_t CurrentByteCursor = 0;
    uint8_t* Blocks[FNameMaxBlocks] = {};
public:
    enum { Stride = alignof(FNameEntry) };
    enum { BlockSizeBytes = Stride * FNameBlockOffsets };
    FNameEntry& Resolve(FNameEntryHandle Handle) const
    {
        return *reinterpret_cast<FNameEntry*>(Blocks[Handle.Block] + Stride * Handle.Offset);
    }
};
class FNamePool {
private:
    enum { MaxENames = 512 };
    FNameEntryAllocator Entries;
public:
    FNameEntry& Resolve(FNameEntryHandle Handle) const {
        return Entries.Resolve(Handle);
    }
};
class FName {
private:
    FNamePool* GetNamePool()
    {
        return reinterpret_cast<FNamePool*>((DWORD64)GetModuleHandleA("AAAA.exe") + 0xA73DE80);
    }
    FNameEntryId    ComparisonIndex;
    uint32_t        Number;
public:
 
    const FNameEntry* GetDisplayNameEntry()
    {
        return &
            reinterpret_cast<FNamePool*>(GetNamePool())
            ->Resolve(this->ComparisonIndex);
    }
};
#endif // !_ENGINE_STRUCT_
//At engine_struct.h
#ifndef _ENGINE_STRUCT_
#define _ENGINE_STRUCT_
#include "..\global_includes.h"
 
static constexpr uint32_t FNameMaxBlockBits = 13;
static constexpr uint32_t FNameBlockOffsetBits = 16;
static constexpr uint32_t FNameMaxBlocks = 1 << FNameMaxBlockBits;
static constexpr uint32_t FNameBlockOffsets = 1 << FNameBlockOffsetBits;
 
 
struct FNameEntryId;
struct FNameEntryHandle;
struct FNameEntryHeader;
struct FNameEntry;
 
class FNameEntryAllocator;
class FNamePool;
class FName;
 
 
 
 
struct FNameEntryId
{
public:
    uint32_t ToUnstableInt() const { return Value; }
    static FNameEntryId FromUnstableInt(uint32_t Value)
    {
        FNameEntryId Id;
        Id.Value = Value;
        return Id;
    }
private:
    uint32_t Value;
 
};
struct FNameEntryHandle
{
    uint32_t Block = 0;
    uint32_t Offset = 0;
 
    FNameEntryHandle(uint32_t InBlock, uint32_t InOffset)
        : Block(InBlock)
        , Offset(InOffset)
    {}
 
    FNameEntryHandle(FNameEntryId Id)
        : Block(Id.ToUnstableInt() >> FNameBlockOffsetBits)
        , Offset(Id.ToUnstableInt()& (FNameBlockOffsets - 1))
    {}
 
    operator FNameEntryId() const
    {
        return FNameEntryId::FromUnstableInt(Block << FNameBlockOffsetBits | Offset);
    }
 
    explicit operator bool() const { return Block | Offset; }
};
struct FNameEntryHeader
{
    uint16_t bIsWide : 1;
    static constexpr uint32_t ProbeHashBits = 5;
    uint16_t LowercaseProbeHash : ProbeHashBits;
    uint16_t Len : 10;
 
};
struct FNameEntry
{
private:
 
    FNameEntryHeader Header;
    union
    {
        char    AnsiName[1024];
        wchar_t WideName[1024];
    };
public:
    bool isEmpty();

[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)

最后于 2023-8-13 20:56 被Uioa编辑 ,原因: 补充代码附件
上传的附件:
收藏
免费 2
支持
分享
最新回复 (3)
雪    币: 3836
活跃值: (4142)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
感谢分享
2023-8-26 20:26
0
雪    币: 500
活跃值: (915)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
3
666
2023-9-13 15:30
0
雪    币: 171
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
4
太6了 大佬
2024-8-11 23:04
0
游客
登录 | 注册 方可回帖
返回
//