-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDK: Add UObjectBase::get_full_name and offset bruteforcing
- Loading branch information
Showing
7 changed files
with
144 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#include "UObject.hpp" | ||
|
||
namespace sdk { | ||
class UStruct : public UObject { | ||
public: | ||
}; | ||
|
||
class UClass : public UStruct { | ||
public: | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
#include "UObjectBase.hpp" | ||
|
||
namespace sdk { | ||
class UObject : public UObjectBase { | ||
public: | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include <Windows.h> | ||
#include <spdlog/spdlog.h> | ||
|
||
#include "UClass.hpp" | ||
#include "UObjectBase.hpp" | ||
|
||
namespace sdk { | ||
void UObjectBase::update_offsets() { | ||
if (s_attempted_update_offsets) { | ||
return; | ||
} | ||
|
||
s_attempted_update_offsets = true; | ||
|
||
SPDLOG_INFO("[UObjectBase] Bruteforcing offsets..."); | ||
|
||
// Look for the first valid pointer in the object array. | ||
// The first valid pointer is ClassPrivate. | ||
for (auto i = sizeof(void*); i < 0x50; i += sizeof(void*)) { | ||
const auto value = *(void**)((uintptr_t)this + i); | ||
|
||
if (value == nullptr || IsBadReadPtr(value, sizeof(void*)) || ((uintptr_t)value & 1) != 0) { | ||
continue; | ||
} | ||
|
||
const auto possible_vtable = *(void**)value; | ||
|
||
if (possible_vtable == nullptr || IsBadReadPtr(possible_vtable, sizeof(void*)) || ((uintptr_t)possible_vtable & 1) != 0) { | ||
continue; | ||
} | ||
|
||
const auto possible_vfunc = *(void**)possible_vtable; | ||
|
||
if (possible_vfunc == nullptr || IsBadReadPtr(possible_vfunc, sizeof(void*))) { | ||
continue; | ||
} | ||
|
||
SPDLOG_INFO("[UObjectBase] Found ClassPrivate at offset 0x{:X}", i); | ||
s_class_private_offset = i; | ||
s_fname_offset = s_class_private_offset + sizeof(void*); | ||
s_outer_private_offset = s_fname_offset + sizeof(void*); | ||
|
||
break; | ||
} | ||
} | ||
|
||
std::wstring UObjectBase::get_full_name() const { | ||
auto c = get_class(); | ||
|
||
if (c == nullptr) { | ||
return L"null"; | ||
} | ||
|
||
auto obj_name = get_fname().to_string(); | ||
|
||
for (auto outer = this->get_outer(); outer != nullptr && outer != this; outer = outer->get_outer()) { | ||
obj_name = outer->get_fname().to_string() + L'.' + obj_name; | ||
} | ||
|
||
return c->get_fname().to_string() + L' ' + obj_name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
|
||
#include "FName.hpp" | ||
|
||
namespace sdk { | ||
class UClass; | ||
class UObject; | ||
|
||
class UObjectBase { | ||
public: | ||
void update_offsets(); | ||
std::wstring get_full_name() const; | ||
|
||
UClass* get_class() const { | ||
return *(UClass**)((uintptr_t)this + s_class_private_offset); | ||
} | ||
|
||
UObject* get_outer() const { | ||
return *(UObject**)((uintptr_t)this + s_outer_private_offset); | ||
} | ||
|
||
FName& get_fname() const { | ||
return *(FName*)((uintptr_t)this + s_fname_offset); | ||
} | ||
|
||
uint32_t get_object_flags() const { | ||
return *(uint32_t*)((uintptr_t)this + s_object_flags_offset); | ||
} | ||
|
||
uint32_t get_internal_index() const { | ||
return *(uint32_t*)((uintptr_t)this + s_internal_index_offset); | ||
} | ||
|
||
private: | ||
static inline bool s_attempted_update_offsets{false}; | ||
static inline uint32_t s_object_flags_offset{0x8}; | ||
static inline uint32_t s_internal_index_offset{0xC}; | ||
static inline uint32_t s_class_private_offset{0x10}; | ||
static inline uint32_t s_fname_offset{0x18}; | ||
static inline uint32_t s_outer_private_offset{0x20}; | ||
}; | ||
} |