Skip to content

Commit

Permalink
Merge pull request #2 from LordSk/pak
Browse files Browse the repository at this point in the history
Pak tool 1.0
  • Loading branch information
Delta-473 authored Jul 25, 2020
2 parents 5e93897 + e775269 commit 429fbcc
Show file tree
Hide file tree
Showing 16 changed files with 1,423 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Pak/build
6 changes: 6 additions & 0 deletions Pak/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
OpenSSL_include_x64 = "C:/Prog/Libs/openssl-1.0.2/include"
OpenSSL_libdir_x64 = "C:/Prog/Libs/openssl-1.0.2/lib/Win32/static/Release"
zlib_include = "C:/Prog/Libs/zlib-1.2.11"
zlib_libdir_x64 = "C:/Prog/Libs/zlib-1.2.11"
brotli_include = "C:/Prog/Libs/vcpkg/installed/x64-windows/include"
brotli_libdir_x64 = "C:/Prog/Libs/vcpkg/installed/x64-windows/lib"
110 changes: 110 additions & 0 deletions Pak/genie.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
--
dofile("config.lua");

BUILD_DIR = path.getabsolute("./build")

solution "Pak tools"
location(BUILD_DIR)

configurations {
"Debug",
"Release"
}

platforms {
"x32",
"x64"
}

language "C++"

configuration {"Debug"}
targetsuffix "_debug"
flags {
"Symbols",
"FullSymbols"
}
defines {
"DEBUG",
"CONF_DEBUG"
}
links {
}

configuration {"Release"}
flags {
"Optimize",
"Symbols",
"NoBufferSecurityCheck"
}
defines {
"NDEBUG",
"CONF_RELEASE",
}
links {
}

configuration {}
flags {
"Cpp14"
}

targetdir("../build")

includedirs {
"src",
}

links {
"kernel32",
"user32",
"winmm",
"advapi32"
}

flags {
"NoExceptions",
"NoRTTI",
"EnableSSE",
"EnableSSE2",
"EnableAVX",
"EnableAVX2",
"EnableMinimalRebuild",
"StaticRuntime",
}

defines {
"_CRT_SECURE_NO_DEPRECATE",
"_CRT_NONSTDC_NO_DEPRECATE",
"WIN32_LEAN_AND_MEAN",
"NOMINMAX",
}

-- disable exception related warnings
buildoptions{ "/wd4577", "/wd4530" }


project "pak"
kind "ConsoleApp"

configuration {}

includedirs {
"src",
brotli_include
}

libdirs {
brotli_libdir_x64
}

links {
"brotlidec",
"shlwapi"
}

files {
"src/**.h",
"src/**.c",
"src/**.cpp",
}
Binary file added Pak/scripts/FileList.xml.pak
Binary file not shown.
Binary file added Pak/scripts/FileList.xml.pak_decrypted
Binary file not shown.
12 changes: 12 additions & 0 deletions Pak/scripts/brotli_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
import brotli

f = open("FileList.xml.pak_decrypted", "rb")
data = f.read()
f.close()

decompressed_data = brotli.decompress(data)

f = open("FileList.xml", "wb")
f.write(decompressed_data)
f.close()
36 changes: 36 additions & 0 deletions Pak/scripts/decrypt_pak.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from Crypto.Cipher import AES
import struct

f = open("FileList.xml.pak", "rb")
data = f.read()
f.close()

# read header
header = struct.unpack("4shh", data[:8])
print(header)
to_decrypt = data[8:136]


key = b'\xa0\x1d\x3d\x99\x3b\x82\x0f\x1e\x13\x0a\x89\x55\x8d\xc0\xde\x22'
# key = b'\x49\x59\x63\x55\xfd\x61\x71\x01\x00\xf3\xb9\xde\xb6\x6f\xb2\xa5'

def decrypt(mode):
cipher = AES.new(key, mode)
plaintext = cipher.decrypt(to_decrypt)
sub = struct.unpack("iii", plaintext[:12])
print(sub)

#f = open("out.decrypted", "wb")
#f.write(plaintext)
#f.close()

decrypt(AES.MODE_ECB)
decrypt(AES.MODE_CBC)
decrypt(AES.MODE_CFB)
decrypt(AES.MODE_OFB)
decrypt(AES.MODE_CTR)
decrypt(AES.MODE_OPENPGP)
decrypt(AES.MODE_CCM)
decrypt(AES.MODE_EAX)
decrypt(AES.MODE_GCM)
decrypt(AES.MODE_OCB)
37 changes: 37 additions & 0 deletions Pak/scripts/extract_paks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import shutil
import glob
import sys
import subprocess

if len(sys.argv) < 3:
print('Usage: python extract_paks.py "Path\\To\\MXM" "Path\\To\\Extraction"')
print('Example: python extract_paks.py "C:\\MXM" "C:\\MXM_extracted"')
exit()

script_dir = os.path.dirname(os.path.realpath(__file__))
cur_dir = os.path.realpath(os.getcwd())
input_dir = sys.argv[1]
output_dir = sys.argv[2]

#print(script_dir, cur_dir, input_dir, output_dir)

tool_path = os.path.realpath(os.path.join(script_dir, "pak.exe"))
#print(tool_path)

pak_files = glob.glob(input_dir + '/**/*.pak', recursive=True)
#print(pak_files)

for f in pak_files:
fdir = os.path.dirname(f)[len(input_dir)+1:]
filename = os.path.basename(f)

#print(filename)
#print(filename[:-4])
#print(output_dir)
#print(fdir)
os.makedirs(os.path.join(output_dir, fdir), exist_ok=True)

print('"%s" "%s" "%s"' % (tool_path, f, os.path.join(output_dir, fdir, filename[:-4])))
#os.system('"%s" "%s" "%s"' % (tool_path, f, os.path.join(output_dir, fdir, filename[:-4])))
subprocess.run([tool_path, f, os.path.join(output_dir, fdir, filename[:-4])])
20 changes: 20 additions & 0 deletions Pak/src/base.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "base.h"

FILE* g_LogFile;
const char* g_LogFileName;

void LogInit(const char* name)
{
g_LogFileName = name;
g_LogFile = fopen(g_LogFileName, "wb");
ASSERT(g_LogFile);
}

struct Logger
{
~Logger() {
fclose(g_LogFile);
}
};

static Logger g_Logger;
Loading

0 comments on commit 429fbcc

Please sign in to comment.