Seregon/ShadPKG

A tool for deriving PKG packet encryption keys for ps4 written in c++

C++/47.3 KB/No license
scripts/patch_minecraft.py
ShadPKG / scripts / patch_minecraft.py
1#!/usr/bin/env python3
2"""
3Minecraft PS4 PSN Bypass - Complete One-Command Patcher
4Extracts, patches, and creates installation-ready PKG
5"""
6 
7import os
8import sys
9import shutil
10import subprocess
11import tempfile
12from pathlib import Path
13 
14def run_cmd(cmd, cwd=None):
15 """Run command and return success"""
16 result = subprocess.run(cmd, cwd=cwd, capture_output=True, text=True)
17 if result.stdout:
18 print(result.stdout, end='')
19 return result.returncode == 0
20 
21def main():
22 if len(sys.argv) < 2:
23 print(f"Usage: {sys.argv[0]} <minecraft.pkg> [output.pkg] [shadpkg_path]")
24 print(f"Example: {sys.argv[0]} minecraft.pkg minecraft_patched.pkg ./shadpkg")
25 return 1
26
27 pkg_input = Path(sys.argv[1]).resolve()
28 pkg_output = Path(sys.argv[2]).resolve() if len(sys.argv) > 2 else pkg_input.parent / "minecraft_patched.pkg"
29 shadpkg = Path(sys.argv[3]).resolve() if len(sys.argv) > 3 else Path("./shadpkg").resolve()
30
31 if not pkg_input.exists():
32 print(f"[!] PKG not found: {pkg_input}")
33 return 1
34
35 if not shadpkg.exists():
36 print(f"[!] shadpkg not found: {shadpkg}")
37 return 1
38
39 print(f"""
40╔════════════════════════════════════════════════════════════════╗
41║ Minecraft PS4 PSN Bypass Patcher - Complete Solution ║
42╚════════════════════════════════════════════════════════════════╝
43 
44Input PKG: {pkg_input}
45Output PKG: {pkg_output}
46""")
47
48 pkg_output.parent.mkdir(parents=True, exist_ok=True)
49
50 with tempfile.TemporaryDirectory() as tmpdir:
51 tmpdir = Path(tmpdir)
52 extract_dir = tmpdir / "extracted"
53
54 # Step 1: Extract
55 print("[1/4] Extracting PKG...")
56 extract_dir.mkdir(parents=True, exist_ok=True)
57 if not run_cmd([str(shadpkg), "extract", "--input", str(pkg_input), "--export-project", str(extract_dir)]):
58 print("[!] Extraction failed")
59 return 1
60
61 # Step 2: Scan for PSN
62 print("[2/4] Scanning for PSN functions...")
63 eboot = list(extract_dir.rglob("eboot.bin"))
64 if not eboot:
65 print("[!] eboot.bin not found")
66 return 1
67
68 result = subprocess.run([str(shadpkg), "patch", "--scan", "-i", str(eboot[0])], capture_output=True, text=True)
69 psn_count = result.stdout.count("Found")
70 print(f"[+] Found {psn_count} PSN functions/strings")
71
72 # Step 3: Generate options.txt
73 print("[3/4] Generating PSN bypass config...")
74 result = subprocess.run([str(shadpkg), "patch", "--gen-options"], capture_output=True, text=True)
75 lines = result.stdout.split('\n')
76 config = []
77 for line in lines:
78 if line.startswith('mp_username:'):
79 config.append(line)
80 elif config and line.startswith('Save this content'):
81 break
82 elif config:
83 if line.strip():
84 config.append(line)
85
86 if config:
87 with open(extract_dir / "options.txt", 'w') as f:
88 f.write('\n'.join(config))
89
90 # Step 4: Build PKG
91 print("[4/4] Building patched PKG...")
92
93 # Try orbis-pub-cmd
94 result = subprocess.run(["which", "orbis-pub-cmd"], capture_output=True)
95 if result.returncode == 0:
96 cmd = ["orbis-pub-cmd", "image_build", "--image_type", "pkg", "--image_path", str(extract_dir), "--output_path", str(pkg_output)]
97 if run_cmd(cmd):
98 size = pkg_output.stat().st_size / (1024*1024)
99 print(f"""
100╔════════════════════════════════════════════════════════════════╗
101║ SUCCESS! ║
102╚════════════════════════════════════════════════════════════════╝
103 
104Patched PKG: {pkg_output}
105Size: {size:.2f} MB
106 
107Ready to install on PS4!
108 
109NEXT STEPS:
1101. Copy PKG to PS4 via USB or FTP
1112. Use Package Manager to install
1123. Start Minecraft and configure multiplayer
1134. Copy options.txt to save data for PSN bypass
114 
115See MINECRAFT_PSN_BYPASS_README.md for detailed instructions.
116""")
117 return 0
118
119 # If orbis-pub-cmd not available, copy extracted files
120 print("[!] orbis-pub-cmd not found - creating extracted folder instead")
121 pkg_extracted = pkg_output.parent / f"{pkg_output.stem}_extracted"
122 if pkg_extracted.exists():
123 shutil.rmtree(pkg_extracted)
124 shutil.copytree(extract_dir, pkg_extracted)
125
126 print(f"""
127[+] Extracted files saved to: {pkg_extracted}
128 
129To create the final PKG, install LibOrbisPkg and run:
130 orbis-pub-cmd image_build --image_type pkg --image_path "{pkg_extracted}" --output_path "{pkg_output}"
131 
132Or use Patch Builder GUI:
133 https://www.mediafire.com/file/xw0zn2e0rjaf5k7/Patch_Builder_v1.3.3.zip/file
134""")
135 return 0
136 
137if __name__ == "__main__":
138 sys.exit(main())
139