Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
guttir14 committed Jul 10, 2021
1 parent 625d5b4 commit 52e8bc2
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Dumper/Dumper.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>
<AdditionalDependencies>ntdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand Down Expand Up @@ -99,6 +100,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>ntdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Dumper/dumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ STATUS Dumper::Dump() {
};
}

fmt::print("\nSaved packages: {}", saved);
fmt::print("\nSaved packages: {}\n", saved);

if (unsaved.size()) {
unsaved.erase(unsaved.size() - 2);
fmt::print("\nUnsaved empty packages: [ {} ]", unsaved);
fmt::print("Unsaved empty packages: [ {} ]\n", unsaved);
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions Dumper/main.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#include <fmt/core.h>
#include "dumper.h"
#include "utils.h"

int main(int argc, char* argv[])
{
uint64 start;
uint64 end;
uint64 time;

auto dumper = Dumper::GetInstance();

start = GetTime();
switch (dumper->Init(argc, argv))
{
case STATUS::WINDOW_NOT_FOUND: { puts("Can't find UE4 window"); return 1; }
Expand All @@ -18,14 +25,21 @@ int main(int argc, char* argv[])
case STATUS::SUCCESS: { break; };
default: { return 1; }
}
end = GetTime();
time = (end - start) / 10000;
fmt::print("Init time: {} ms\n", time);

start = GetTime();
switch (dumper->Dump())
{
case STATUS::FILE_NOT_OPEN: { puts("Can't open file"); return 1; }
case STATUS::ZERO_PACKAGES: { puts("Size of packages is zero"); return 1; }
case STATUS::SUCCESS: { break; }
default: { return 1; }
}
end = GetTime();
time = (end - start) / 10000;
fmt::print("Dump time: {} ms\n", time);

return 0;
}
8 changes: 8 additions & 0 deletions Dumper/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,11 @@ uint32 GetProccessPath(uint32 pid, wchar_t* processName, uint32 size) {
CloseHandle(hProcess);
return size;
}

extern "C" NTSTATUS NtQuerySystemTime(uint64* SystemTime);

uint64 GetTime() {
uint64 ret;
NtQuerySystemTime(&ret);
return ret;
}
1 change: 1 addition & 0 deletions Dumper/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ uint8* FindSignature(uint8* start, uint8* end, const char* sig, uint32 size);
void* FindPointer(uint8* start, uint8* end, const char* sig, uint32 size, int32 addition = 0);
std::vector<std::pair<uint8*, uint8*>> GetExSections(void *data);
uint32 GetProccessPath(uint32 pid, wchar_t* processName, uint32 size);
uint64 GetTime();
37 changes: 33 additions & 4 deletions Dumper/wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1244,20 +1244,42 @@ void UE_UPackage::GenerateStruct(UE_UStruct object, std::vector<Struct>& arr, bo
void UE_UPackage::GenerateEnum(UE_UEnum object, std::vector<Enum> &arr) {
Enum e;
e.FullName = object.GetFullName();
e.CppName = "enum class " + object.GetName() + " : uint8";

auto names = object.GetNames();

uint64 max = 0;
uint64 nameSize = ((offsets.FName.Number + 4) + 7) & ~(7);
uint64 pairSize = nameSize + 8;

for (uint32 i = 0; i < names.Count; i++) {
uint64 size = (offsets.FName.Number + 4u + 8 + 7u) & ~(7u);
auto name = UE_FName(names.Data + i * size);

auto pair = names.Data + i * pairSize;
auto name = UE_FName(pair);
auto str = name.GetName();
auto pos = str.find_last_of(':');
if (pos != std::string::npos) {
str = str.substr(pos + 1);
}

auto value = Read<int64>(pair + nameSize);
if ((uint64)value > max) max = value;

str.append(" = ").append(fmt::format("{}", value));
e.Members.push_back(str);
}

const char* type = nullptr;

// I didn't see int16 yet, so I assume the engine generates only int32 and uint8:
if (max > 256) {
type = " : int32"; // I assume if enum has a negative value it is int32
}
else {
type = " : uint8";
}

e.CppName = "enum class " + object.GetName() + type;

if (e.Members.size()) {
arr.push_back(e);
}
Expand Down Expand Up @@ -1299,9 +1321,16 @@ void UE_UPackage::SaveStructSpacing(std::vector<Struct> &arr, FILE *file) {
void UE_UPackage::SaveEnum(std::vector<Enum> &arr, FILE *file) {
for (auto &e : arr) {
fmt::print(file, "// {}\n{} {{", e.FullName, e.CppName);
for (auto &m : e.Members) {

auto lastIdx = e.Members.size() - 1;
for (auto i = 0; i < lastIdx; i++) {
auto& m = e.Members.at(i);
fmt::print(file, "\n\t{},", m);
}

auto& m = e.Members.at(lastIdx);
fmt::print(file, "\n\t{}", m);

fmt::print(file, "\n}};\n\n");
}
}
Expand Down

0 comments on commit 52e8bc2

Please sign in to comment.