-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pseudo-code decompiler and new [@] command
- Loading branch information
Showing
15 changed files
with
2,500 additions
and
186 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#include <iostream> | ||
#include <sstream> | ||
|
||
#include "UPKUtils.h" | ||
#include "UToken.h" | ||
|
||
using namespace std; | ||
|
||
string GetFilename(string str) | ||
{ | ||
unsigned found = str.find_last_of("/\\"); | ||
return str.substr(found + 1); | ||
} | ||
|
||
int main(int argN, char* argV[]) | ||
{ | ||
//cout << "HexToPseudoCode" << endl; | ||
|
||
if (argN < 3 || argN > 4) | ||
{ | ||
cerr << "Usage: HexToPseudoCode UnpackedResourceFile.upk ObjectName [/d]" << endl; | ||
return 1; | ||
} | ||
|
||
UPKUtils package(argV[1]); | ||
|
||
UPKReadErrors err = package.GetError(); | ||
|
||
if (err != UPKReadErrors::NoErrors) | ||
{ | ||
cerr << "Error reading package:\n" << FormatReadErrors(err); | ||
if (package.IsCompressed()) | ||
cerr << "Compression flags:\n" << FormatCompressionFlags(package.GetCompressionFlags()); | ||
return 1; | ||
} | ||
|
||
string NameToFind = argV[2]; | ||
|
||
//cout << "Object to find: " << NameToFind << endl; | ||
|
||
UObjectReference ObjRef = package.FindObject(NameToFind, false); | ||
|
||
if (ObjRef == 0) | ||
{ | ||
cerr << "Unable to find object entry by name " << NameToFind << endl; | ||
return 1; | ||
} | ||
if (ObjRef > 0 && argN == 4 && string(argV[3]) == "/d") | ||
{ | ||
package.SaveExportData((uint32_t)ObjRef); | ||
} | ||
if (ObjRef > 0) | ||
{ | ||
//cout << "Found Export Object:\n" << package.FormatExport(ObjRef, true); | ||
} | ||
else | ||
{ | ||
//cout << "Found Import Object:\n" << package.FormatImport(-ObjRef, true); | ||
} | ||
|
||
if (ObjRef <= 0 || (package.GetExportEntry(ObjRef).Type != "Function" && package.GetExportEntry(ObjRef).Type != "State")) | ||
{ | ||
cerr << "Object is not a Function nor a State, can not convert to pseudo-code!\n"; | ||
return 1; | ||
} | ||
|
||
//cout << "Attempting deserialization:\n"; | ||
|
||
vector<char> ObjData = package.GetExportData(ObjRef); | ||
stringstream stream; | ||
stream.write(ObjData.data(), ObjData.size()); | ||
size_t ScrPos = package.GetScriptRelOffset(ObjRef); | ||
stream.seekg(ScrPos); | ||
|
||
UScriptCode ScrCode; | ||
string PseudoCode = ScrCode.Deserialize(stream, package); | ||
cout << "//This script was generated by HexToPseudoCode decompiler for use with PatchUPK/PatcherGUI tool\n" | ||
<< "UPK_FILE = " << GetFilename(argV[1]) << "\n" | ||
<< "OBJECT = " << NameToFind << " : AUTO\n" | ||
<< "[REPLACEMENT_CODE]\n" | ||
<< PseudoCode; | ||
|
||
return 0; | ||
} | ||
|
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,69 @@ | ||
#include <iostream> | ||
#include <iomanip> | ||
#include <fstream> | ||
#include <string> | ||
|
||
using namespace std; | ||
|
||
#define MAGIC (uint32_t)747443441 | ||
|
||
int main(int argN, char* argV[]) | ||
{ | ||
cout << "UENativeTablesReader" << endl; | ||
|
||
if (argN != 2) | ||
{ | ||
cerr << "Usage: UENativeTablesReader NativeTable.NTL" << endl; | ||
return 1; | ||
} | ||
|
||
ifstream table(argV[1], ios::binary); | ||
if (!table.is_open()) | ||
{ | ||
cerr << "Can't open " << argV[1] << endl; | ||
return 1; | ||
} | ||
|
||
uint32_t magic; | ||
table.read(reinterpret_cast<char*>(&magic), sizeof(magic)); | ||
if (magic != MAGIC) | ||
{ | ||
cerr << "Input file is not a NTL file!\n"; | ||
return 1; | ||
} | ||
|
||
uint32_t num; | ||
table.read(reinterpret_cast<char*>(&num), sizeof(num)); | ||
if (num < 0 || num > 0xFFF) | ||
{ | ||
cerr << "Input file is not a NTL file!\n"; | ||
return 1; | ||
} | ||
|
||
cout << "Num = " << num << endl; | ||
|
||
cout << "HEX\tName\t\t\t\tOpPrec\tType\tToken\n"; | ||
|
||
for (unsigned i = 0; i < num; ++i) | ||
{ | ||
uint8_t NameLen; | ||
string Name; | ||
uint8_t OperPrecedence; | ||
uint8_t Type; | ||
uint32_t ByteToken; | ||
char ch[255]; | ||
|
||
table.read(reinterpret_cast<char*>(&NameLen), sizeof(NameLen)); | ||
table.read(ch, NameLen); | ||
Name = string(ch, NameLen); | ||
table.read(reinterpret_cast<char*>(&OperPrecedence), sizeof(OperPrecedence)); | ||
table.read(reinterpret_cast<char*>(&Type), sizeof(Type)); | ||
table.read(reinterpret_cast<char*>(&ByteToken), sizeof(ByteToken)); | ||
|
||
cout << "0x" << setfill('0') << setw(2) << hex << ByteToken << "\t" << Name | ||
<< "\t\t\t\t" | ||
<< dec << (int)OperPrecedence << "\t" << (int)Type << "\t" << ByteToken << endl; | ||
} | ||
|
||
return 0; | ||
} |
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
Oops, something went wrong.