Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
feat: dump vtable
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolLoong committed Feb 7, 2024
1 parent 9a92952 commit 71bbc45
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
22 changes: 17 additions & 5 deletions src/DataExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,37 @@ LL_AUTO_TYPE_INSTANCE_HOOK(
}

// MinecraftCommands
LL_AUTO_TYPE_INSTANCE_HOOK(BlockHOOK, HookPriority::Normal, Block, "__gen_??1Block@@UEAA@XZ" void) { origin(); }
LL_AUTO_TYPE_INSTANCE_HOOK(BlockHooK, HookPriority::Normal, Block, "__gen_??1Block@@UEAA@XZ", void) {
dumpVtable(this);
return origin();
}

#pragma endregion HOOK

#pragma region TOOL_FUNCTION
inline bool isValidPtr(void* p) { return (p >= (void*)0x10000ull) && (p < (void*)0x000F000000000000ull); }

// 将 const char* const* 转换为 vector<string>
std::vector<std::string> convertToStringVector(const char* const* arr, size_t size) {
std::vector<std::string> strings;
for (size_t i = 0; i < size; ++i) {
strings.push_back(arr[i]);
}
return strings;
}

std::vector<std::pair<void*, std::vector<std::string>>> dumpVtable(void* obj) {
auto vtab = *(uintptr_t**)obj;
int count = 0;
std::vector<std::pair<void*, std::vector<std::string>>> res;
for (;; count++) {
if (isValidPtr((void*)vtab[count])) {
size_t* address = 0;
auto result = pl::symbol_provider::pl_lookup_symbol((void*)vtab[count], address);
std::string str = *result;
auto result = pl::symbol_provider::pl_lookup_symbol((void*)vtab[count], address);
std::string str = *result;
if (*address != 0) {
res.push_back({(void*)vtab[count], str});
const auto& array = convertToStringVector(result, *address);
res.push_back({(void*)vtab[count], array});
}
} else {
break;
Expand All @@ -148,7 +161,6 @@ std::vector<std::pair<void*, std::vector<std::string>>> dumpVtable(void* obj) {
return res;
}


bool folderExists(const std::string& folderName) {
struct stat info {};
if (stat(folderName.c_str(), &info) != 0) {
Expand Down
3 changes: 2 additions & 1 deletion src/DataExtractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,5 @@ void dumpItemTags(const ll::Logger& logger);
void dumpPropertyTypeData(const ll::Logger& logger);

void extractBlock(ListTag& dest, const Block& block, const ll::Logger& logger);
void extractData();
void extractData();
std::vector<std::pair<void*, std::vector<std::string>>> dumpVtable(void* obj);

0 comments on commit 71bbc45

Please sign in to comment.