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

Commit

Permalink
feat: dumpvtable3
Browse files Browse the repository at this point in the history
  • Loading branch information
killcerr authored Feb 7, 2024
1 parent 813ce04 commit 6357e67
Showing 1 changed file with 35 additions and 18 deletions.
53 changes: 35 additions & 18 deletions src/DataExtractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ class GetCollisionShapeInterface {
public:
// prevent constructor by default
GetCollisionShapeInterface& operator=(GetCollisionShapeInterface const&);
GetCollisionShapeInterface(GetCollisionShapeInterface const&);
GetCollisionShapeInterface();
GetCollisionShapeInterface(GetCollisionShapeInterface const&);
GetCollisionShapeInterface();
};

void dumpCreativeItemData(const ll::Logger& logger);
Expand All @@ -90,30 +90,47 @@ void extractBlock(ListTag& dest, const Block& block, const ll::Logger& logger);
void extractData();

#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]);
#include <Windows.h>
#include <dbghelp.h>
#include <eh.h>
std::atomic_bool needInit = true;
void init() {
if (needInit) {
needInit = false;
} else {
return;
}
{
HANDLE hProcess;
hProcess = GetCurrentProcess();
SymInitialize(hProcess, NULL, TRUE);
SymSetOptions(SYMOPT_UNDNAME);
}
return strings;
}
std::vector<std::string> symFromAddr(DWORD64 address, HANDLE hProcess = GetCurrentProcess()) {
init();
auto res = std::vector<std::string>();
SymEnumSymbolsForAddr(
hProcess,
address,
[](PSYMBOL_INFO pSymInfo, ULONG SymbolSize, PVOID UserContext) {
auto res = (std::vector<std::string>*)UserContext;
res->push_back(pSymInfo->Name);
return TRUE;
},
&res
);
return res;
}
inline bool isValidPtr(void* p) { return (p >= (void*)0x10000ull) && (p < (void*)0x000F000000000000ull); }

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;
if (*address != 0) {
const auto& array = convertToStringVector(result, *address);
res.push_back({(void*)vtab[count], array});
}
res.push_back({(void*)vtab[count], symFromAddr((uint64_t)(void*)vtab[count])});
} else {
break;
}
Expand Down Expand Up @@ -185,4 +202,4 @@ std::string aabbToStr(const AABB& aabb) {
<< aabb.max.z;
return aabbStr.str();
}
#pragma endregion TOOL_FUNCTION
#pragma endregion TOOL_FUNCTION

0 comments on commit 6357e67

Please sign in to comment.