Skip to content

Commit

Permalink
improve functions script
Browse files Browse the repository at this point in the history
  • Loading branch information
MJx0 committed Nov 13, 2022
1 parent c204c13 commit 8c34101
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 43 deletions.
68 changes: 40 additions & 28 deletions iOS_UE4Dumper/Tweak/src/Core/Dumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,16 @@ namespace Dumper

void to_json(json &j, const IdaFunction &f)
{
if (f.Parent.empty() || f.Parent == "None" || f.Name.empty() || f.Name == "None")
if (f.Parent.empty() || f.Parent == "None" || f.Parent == "null")
return;
if (f.Parent == "null" || f.Name == "null")
if (f.Name.empty() || f.Name == "None" || f.Name == "null")
return;

std::string Name = f.Parent;
Name += "$$";
Name += f.Name;
std::string fname = ioutils::replace_specials(f.Parent, '_');
fname += "$$";
fname += ioutils::replace_specials(f.Name, '_');

char chars[] = " /\\:;*?\"\'`~<>|,.[]{}-+=()!@#%^&";
for (auto c : chars)
{
auto pos = Name.find(c);
if (pos != std::string::npos)
{
Name[pos] = '_';
}
}

j = json{{"Name", Name}, {"Address", f.Address - __pagezero_size}};
j = json{{"Name", fname}, {"Address", f.Address - __pagezero_size}};
}
};

Expand Down Expand Up @@ -190,9 +180,8 @@ namespace Dumper
int structs_saved = 0;
int enums_saved = 0;

std::string exe_name_str = exe_info.name;
exe_name_str = exe_name_str.substr(exe_name_str.find_last_of("/\\") + 1);

static bool processInternal_once = false;

for (UE_UPackage package : packages)
{
package.Process();
Expand All @@ -203,18 +192,41 @@ namespace Dumper
structs_saved += package.Structures.size();
enums_saved += package.Enums.size();

if (package.Classes.size())
for (const auto &cls : package.Classes)
{
if (!cls.Functions.size())
continue;

for (const auto &func : cls.Functions)
{
// UObject::ProcessInternal for blueprint functions
if(!processInternal_once && (func.EFlags & FUNC_BlueprintEvent))
{
JsonGen::idaFunctions.push_back({"UObject", "ProcessInternal", func.Func - Profile::BaseAddress});
processInternal_once = true;
}

if (func.EFlags & FUNC_Native)
{
std::string execFuncName = "exec";
execFuncName += func.Name;
JsonGen::idaFunctions.push_back({cls.Name, execFuncName, func.Func - Profile::BaseAddress});
}
}
}

for (const auto &st : package.Structures)
{
for (const auto &cls : package.Classes)
if (!st.Functions.size())
continue;

for (const auto &func : st.Functions)
{
if (!cls.Functions.size())
continue;
// get important only functions
if (cls.FullName.rfind("Class Engine.") != 0 && cls.FullName.find(exe_name_str) == std::string::npos)
continue;
for (const auto &func : cls.Functions)
if (func.EFlags & FUNC_Native)
{
JsonGen::idaFunctions.push_back({cls.Name, func.Name, func.Func - Profile::BaseAddress});
std::string execFuncName = "exec";
execFuncName += func.Name;
JsonGen::idaFunctions.push_back({st.Name, execFuncName, func.Func - Profile::BaseAddress});
}
}
}
Expand Down
40 changes: 40 additions & 0 deletions iOS_UE4Dumper/Tweak/src/Core/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,44 @@ uint8_t *GetSegmentData(const void *hdr, const char *seg, unsigned long *sz)
#endif

return getsegmentdata(header, seg, sz);
}

namespace ioutils
{
std::string remove_specials(std::string s)
{
for (int i = 0; i < s.size(); i++)
{
if (!((s[i] < 'A' || s[i] > 'Z') && (s[i] < 'a' || s[i] > 'z')))
continue;

if (!(s[i] < '0' || s[i] > '9'))
continue;

if (s[i] == '_')
continue;

s.erase(s.begin() + i);
--i;
}
return s;
}

std::string replace_specials(std::string s, char c)
{
for (int i = 0; i < s.size(); i++)
{
if (!((s[i] < 'A' || s[i] > 'Z') && (s[i] < 'a' || s[i] > 'z')))
continue;

if (!(s[i] < '0' || s[i] > '9'))
continue;

if (s[i] == '_')
continue;

s[i] = c;
}
return s;
}
}
8 changes: 7 additions & 1 deletion iOS_UE4Dumper/Tweak/src/Core/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ T vm_rpm_ptr(void *address)

std::string vm_rpm_str(void *address, int max_len = 0xff);

uint8_t *GetSegmentData(const void*, const char*, unsigned long*);
uint8_t *GetSegmentData(const void*, const char*, unsigned long*);

namespace ioutils
{
std::string remove_specials(std::string s);
std::string replace_specials(std::string s, char c);
}
20 changes: 9 additions & 11 deletions iOS_UE4Dumper/Tweak/src/Core/wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,14 @@ int16 UE_UFunction::GetReturnValueOffset() const
return vm_rpm_ptr<int16>(object + Profile::offsets.UFunction.ReturnValueOffset);
}

uint32 UE_UFunction::GetFunctionEFlags() const
{
return vm_rpm_ptr<uint32>(object + Profile::offsets.UFunction.EFunctionFlags);
}

std::string UE_UFunction::GetFunctionFlags() const
{
auto flags = vm_rpm_ptr<uint32>(object + Profile::offsets.UFunction.EFunctionFlags);
auto flags = GetFunctionEFlags();
std::string result;
if (flags == FUNC_None)
{
Expand Down Expand Up @@ -1390,6 +1395,7 @@ void UE_UPackage::GenerateFunction(UE_UFunction fn, Function *out)
{
out->Name = fn.GetName();
out->FullName = fn.GetFullName();
out->EFlags = fn.GetFunctionEFlags();
out->Flags = fn.GetFunctionFlags();
out->NumParams = fn.GetNumParams();
out->ParamSize = fn.GetParamSize();
Expand Down Expand Up @@ -1725,16 +1731,8 @@ bool UE_UPackage::Save(const char *fulldump_dir, const char *dumpheaders_dir)
return false;
}

std::string packageName = GetObject().GetName();
char chars[] = "/\\:*?\"<>|";
for (auto c : chars)
{
auto pos = packageName.find(c);
if (pos != std::string::npos)
{
packageName[pos] = '_';
}
}
// make safe to use as a file name
std::string packageName = ioutils::replace_specials(GetObject().GetName(), '_');

File fulldump_file;

Expand Down
2 changes: 2 additions & 0 deletions iOS_UE4Dumper/Tweak/src/Core/wrappers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ class UE_UFunction : public UE_UStruct
int16 GetParamSize() const;
int16 GetReturnValueOffset() const;

uint32 GetFunctionEFlags() const;
std::string GetFunctionFlags() const;
static UE_UClass StaticClass();
};
Expand Down Expand Up @@ -709,6 +710,7 @@ class UE_UPackage
std::string FullName;
std::string CppName;
std::string Params;
uint32 EFlags;
std::string Flags;
int8 NumParams = 0;
int16 ParamSize = 0;
Expand Down
6 changes: 3 additions & 3 deletions scripts/ida_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

imageBase = idaapi.get_imagebase()

for func_entry in json_data['Functions']:
for func_entry in json_data['Functions']
name = func_entry['Name'];
addr = imageBase+func_entry['Address'];
addr = imageBase+func_entry['Address']
ret = idc.set_name(addr, name, SN_NOWARN | SN_NOCHECK)
if ret == 0:
new_name = name+'_'+str(addr)
ret = idc.set_name(addr, new_name, SN_NOWARN | SN_NOCHECK)
ret = idc.set_name(addr, new_name, SN_NOWARN | SN_NOCHECK)

0 comments on commit 8c34101

Please sign in to comment.