Skip to content

Commit

Permalink
added decryption option for creating Manifest file
Browse files Browse the repository at this point in the history
  • Loading branch information
gitMenv committed Feb 22, 2023
1 parent a4cfe73 commit ab473dd
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
Binary file modified cpp/castoc_x64.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion cpp/castoc_x64.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ extern __declspec(dllexport) int packGameFiles(char* dirPath, char* manifestPath
extern __declspec(dllexport) void freeStringList(char** stringlist, int n);
extern __declspec(dllexport) char** listGameFiles(char* utocFile, int* n, char* AESKey);
extern __declspec(dllexport) char* getError();
extern __declspec(dllexport) int createManifestFile(char* utocFile, char* ucasFile, char* outputFile);
extern __declspec(dllexport) int createManifestFile(char* utocFile, char* ucasFile, char* outputFile, char* AESKey);
extern __declspec(dllexport) int unpackAllGameFiles(char* utocFile, char* ucasFile, char* outputDirectory, char* AESKey);
extern __declspec(dllexport) int unpackGameFiles(char* utocFile, char* ucasFile, char* outputDirectory, char* regex, char* AESKey);

Expand Down
15 changes: 10 additions & 5 deletions cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void printHelp() {
cout << " list [utocPath, *AES key]: lists all files that are packed in the .utoc/.ucas file" << endl;
cout << " unpackAll [utocPath, ucasPath, outputDir, *AES key]: unpack entire .utoc/.ucas files" << endl;
cout << " unpack [utocPath, ucasPath, outputDir, regex, *AES key]: unpack .utoc/.ucas files based on regex" << endl;
cout << " manifest [utocPath, ucasPath, outputManifest]: creates Manifest file of this .utoc/.ucas file" << endl;
cout << " manifest [utocPath, ucasPath, outputManifest, *AES key]: creates Manifest file of this .utoc/.ucas file" << endl;
cout << " pack [packDir, manifestPath, outputFile, compressionMethod, *AES key]: pack directory into .utoc/.ucas file" << endl;
cout << endl;
cout << "the pack command requires the manifest file, and it packs the input dir to the outputFile{.utoc, .ucas, .pak}; three files are created!" << endl;
Expand Down Expand Up @@ -109,18 +109,23 @@ void unpack(vector<string> args){
}

void manifest(vector<string> args){
//[utocPath, ucasPath, outputManifest]
if(args.size() != 3) {
cout << "expecting exactly 3 arguments for creating a manifest file" << endl;
//[utocPath, ucasPath, outputManifest, aeskey]
if(args.size() < 3) {
cout << "expecting at least 3 arguments for creating a manifest file" << endl;
printHelp();
return;
}
const char* utocPath = args[0].c_str();
const char* ucasPath = args[1].c_str();
const char* outputManifest = args[2].c_str();
char* aeskey = NULL;
if (args.size() == 4) {
const char* aes = args[3].c_str();
}
int n = createManifestFile(const_cast<char*>(utocPath),
const_cast<char*>(ucasPath),
const_cast<char*>(outputManifest));
const_cast<char*>(outputManifest),
aeskey);
if (n < 0){
cout << getError() << endl;
}
Expand Down
Binary file modified cpp/main.exe
Binary file not shown.
31 changes: 29 additions & 2 deletions dllAPI.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,44 @@ func getError() (err *C.char) {
}

//export createManifestFile
func createManifestFile(utocFile *C.char, ucasFile *C.char, outputFile *C.char) C.int {
func createManifestFile(utocFile *C.char, ucasFile *C.char, outputFile *C.char, AESKey *C.char) C.int {
//TODO: check if the "dependencies" part works for more games, and if it's even required.
utocFname := C.GoString(utocFile)
ucasFname := C.GoString(ucasFile)
outputFname := C.GoString(outputFile)
aes := convertAES(AESKey)

d, err := parseUtocFile(utocFname, []byte{})
d, err := parseUtocFile(utocFname, aes)
if err != nil {
staticErr = err.Error()
return C.int(-1)
}

if d.hdr.isEncrypted(){
tmpFile, err := os.CreateTemp("", "tmp")
if err != nil {
staticErr = err.Error()
return C.int(-1)
}
ucasBytes, err := ioutil.ReadFile(ucasFname)
if err != nil {
staticErr = err.Error()
return C.int(-1)
}
decryptedBytes, err := decryptAES(&ucasBytes, aes)
if err != nil {
staticErr = err.Error()
return C.int(-1)
}
tmpFile.Write(*decryptedBytes)
ucasFname = tmpFile.Name()
err = tmpFile.Close()
if err != nil {
fmt.Println("err:", err)
return C.int(-1)
}
defer os.Remove(tmpFile.Name())
}
manifest, err := d.constructManifest(ucasFname)
if err != nil {
staticErr = err.Error()
Expand Down

0 comments on commit ab473dd

Please sign in to comment.