├── .gitattributes
├── .gitignore
├── App.config
├── Archive.cs
├── Compression
├── Oodle.cs
└── Zlib.cs
├── Core
├── PSARC.cs
├── TEntry.cs
└── TZSize.cs
├── DirectStorage
└── Decompressor.cs
├── Helpers
├── CommendHelper.cs
├── HugeMemoryStream.cs
└── IOHelper.cs
├── LICENSE.md
├── Packer.Designer.cs
├── Packer.resx
├── Program.cs
├── Properties
├── AssemblyInfo.cs
└── app.manifest
├── README.md
├── Resources
└── psarc.exe
├── UnPSARC.csproj
├── UnPSARC.sln
└── packages.config
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Ww][Ii][Nn]32/
27 | [Aa][Rr][Mm]/
28 | [Aa][Rr][Mm]64/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 | [Oo]ut/
33 | [Ll]og/
34 | [Ll]ogs/
35 |
36 | # Visual Studio 2015/2017 cache/options directory
37 | .vs/
38 | # Uncomment if you have tasks that create the project's static files in wwwroot
39 | #wwwroot/
40 |
41 | # Visual Studio 2017 auto generated files
42 | Generated\ Files/
43 |
44 | # MSTest test Results
45 | [Tt]est[Rr]esult*/
46 | [Bb]uild[Ll]og.*
47 |
48 | # NUnit
49 | *.VisualState.xml
50 | TestResult.xml
51 | nunit-*.xml
52 |
53 | # Build Results of an ATL Project
54 | [Dd]ebugPS/
55 | [Rr]eleasePS/
56 | dlldata.c
57 |
58 | # Benchmark Results
59 | BenchmarkDotNet.Artifacts/
60 |
61 | # .NET Core
62 | project.lock.json
63 | project.fragment.lock.json
64 | artifacts/
65 |
66 | # ASP.NET Scaffolding
67 | ScaffoldingReadMe.txt
68 |
69 | # StyleCop
70 | StyleCopReport.xml
71 |
72 | # Files built by Visual Studio
73 | *_i.c
74 | *_p.c
75 | *_h.h
76 | *.ilk
77 | *.meta
78 | *.obj
79 | *.iobj
80 | *.pch
81 | *.pdb
82 | *.ipdb
83 | *.pgc
84 | *.pgd
85 | *.rsp
86 | *.sbr
87 | *.tlb
88 | *.tli
89 | *.tlh
90 | *.tmp
91 | *.tmp_proj
92 | *_wpftmp.csproj
93 | *.log
94 | *.vspscc
95 | *.vssscc
96 | .builds
97 | *.pidb
98 | *.svclog
99 | *.scc
100 |
101 | # Chutzpah Test files
102 | _Chutzpah*
103 |
104 | # Visual C++ cache files
105 | ipch/
106 | *.aps
107 | *.ncb
108 | *.opendb
109 | *.opensdf
110 | *.sdf
111 | *.cachefile
112 | *.VC.db
113 | *.VC.VC.opendb
114 |
115 | # Visual Studio profiler
116 | *.psess
117 | *.vsp
118 | *.vspx
119 | *.sap
120 |
121 | # Visual Studio Trace Files
122 | *.e2e
123 |
124 | # TFS 2012 Local Workspace
125 | $tf/
126 |
127 | # Guidance Automation Toolkit
128 | *.gpState
129 |
130 | # ReSharper is a .NET coding add-in
131 | _ReSharper*/
132 | *.[Rr]e[Ss]harper
133 | *.DotSettings.user
134 |
135 | # TeamCity is a build add-in
136 | _TeamCity*
137 |
138 | # DotCover is a Code Coverage Tool
139 | *.dotCover
140 |
141 | # AxoCover is a Code Coverage Tool
142 | .axoCover/*
143 | !.axoCover/settings.json
144 |
145 | # Coverlet is a free, cross platform Code Coverage Tool
146 | coverage*.json
147 | coverage*.xml
148 | coverage*.info
149 |
150 | # Visual Studio code coverage results
151 | *.coverage
152 | *.coveragexml
153 |
154 | # NCrunch
155 | _NCrunch_*
156 | .*crunch*.local.xml
157 | nCrunchTemp_*
158 |
159 | # MightyMoose
160 | *.mm.*
161 | AutoTest.Net/
162 |
163 | # Web workbench (sass)
164 | .sass-cache/
165 |
166 | # Installshield output folder
167 | [Ee]xpress/
168 |
169 | # DocProject is a documentation generator add-in
170 | DocProject/buildhelp/
171 | DocProject/Help/*.HxT
172 | DocProject/Help/*.HxC
173 | DocProject/Help/*.hhc
174 | DocProject/Help/*.hhk
175 | DocProject/Help/*.hhp
176 | DocProject/Help/Html2
177 | DocProject/Help/html
178 |
179 | # Click-Once directory
180 | publish/
181 |
182 | # Publish Web Output
183 | *.[Pp]ublish.xml
184 | *.azurePubxml
185 | # Note: Comment the next line if you want to checkin your web deploy settings,
186 | # but database connection strings (with potential passwords) will be unencrypted
187 | *.pubxml
188 | *.publishproj
189 |
190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
191 | # checkin your Azure Web App publish settings, but sensitive information contained
192 | # in these scripts will be unencrypted
193 | PublishScripts/
194 |
195 | # NuGet Packages
196 | *.nupkg
197 | # NuGet Symbol Packages
198 | *.snupkg
199 | # The packages folder can be ignored because of Package Restore
200 | **/[Pp]ackages/*
201 | # except build/, which is used as an MSBuild target.
202 | !**/[Pp]ackages/build/
203 | # Uncomment if necessary however generally it will be regenerated when needed
204 | #!**/[Pp]ackages/repositories.config
205 | # NuGet v3's project.json files produces more ignorable files
206 | *.nuget.props
207 | *.nuget.targets
208 |
209 | # Microsoft Azure Build Output
210 | csx/
211 | *.build.csdef
212 |
213 | # Microsoft Azure Emulator
214 | ecf/
215 | rcf/
216 |
217 | # Windows Store app package directories and files
218 | AppPackages/
219 | BundleArtifacts/
220 | Package.StoreAssociation.xml
221 | _pkginfo.txt
222 | *.appx
223 | *.appxbundle
224 | *.appxupload
225 |
226 | # Visual Studio cache files
227 | # files ending in .cache can be ignored
228 | *.[Cc]ache
229 | # but keep track of directories ending in .cache
230 | !?*.[Cc]ache/
231 |
232 | # Others
233 | ClientBin/
234 | ~$*
235 | *~
236 | *.dbmdl
237 | *.dbproj.schemaview
238 | *.jfm
239 | *.pfx
240 | *.publishsettings
241 | orleans.codegen.cs
242 |
243 | # Including strong name files can present a security risk
244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
245 | #*.snk
246 |
247 | # Since there are multiple workflows, uncomment next line to ignore bower_components
248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
249 | #bower_components/
250 |
251 | # RIA/Silverlight projects
252 | Generated_Code/
253 |
254 | # Backup & report files from converting an old project file
255 | # to a newer Visual Studio version. Backup files are not needed,
256 | # because we have git ;-)
257 | _UpgradeReport_Files/
258 | Backup*/
259 | UpgradeLog*.XML
260 | UpgradeLog*.htm
261 | ServiceFabricBackup/
262 | *.rptproj.bak
263 |
264 | # SQL Server files
265 | *.mdf
266 | *.ldf
267 | *.ndf
268 |
269 | # Business Intelligence projects
270 | *.rdl.data
271 | *.bim.layout
272 | *.bim_*.settings
273 | *.rptproj.rsuser
274 | *- [Bb]ackup.rdl
275 | *- [Bb]ackup ([0-9]).rdl
276 | *- [Bb]ackup ([0-9][0-9]).rdl
277 |
278 | # Microsoft Fakes
279 | FakesAssemblies/
280 |
281 | # GhostDoc plugin setting file
282 | *.GhostDoc.xml
283 |
284 | # Node.js Tools for Visual Studio
285 | .ntvs_analysis.dat
286 | node_modules/
287 |
288 | # Visual Studio 6 build log
289 | *.plg
290 |
291 | # Visual Studio 6 workspace options file
292 | *.opt
293 |
294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
295 | *.vbw
296 |
297 | # Visual Studio LightSwitch build output
298 | **/*.HTMLClient/GeneratedArtifacts
299 | **/*.DesktopClient/GeneratedArtifacts
300 | **/*.DesktopClient/ModelManifest.xml
301 | **/*.Server/GeneratedArtifacts
302 | **/*.Server/ModelManifest.xml
303 | _Pvt_Extensions
304 |
305 | # Paket dependency manager
306 | .paket/paket.exe
307 | paket-files/
308 |
309 | # FAKE - F# Make
310 | .fake/
311 |
312 | # CodeRush personal settings
313 | .cr/personal
314 |
315 | # Python Tools for Visual Studio (PTVS)
316 | __pycache__/
317 | *.pyc
318 |
319 | # Cake - Uncomment if you are using it
320 | # tools/**
321 | # !tools/packages.config
322 |
323 | # Tabs Studio
324 | *.tss
325 |
326 | # Telerik's JustMock configuration file
327 | *.jmconfig
328 |
329 | # BizTalk build output
330 | *.btp.cs
331 | *.btm.cs
332 | *.odx.cs
333 | *.xsd.cs
334 |
335 | # OpenCover UI analysis results
336 | OpenCover/
337 |
338 | # Azure Stream Analytics local run output
339 | ASALocalRun/
340 |
341 | # MSBuild Binary and Structured Log
342 | *.binlog
343 |
344 | # NVidia Nsight GPU debugger configuration file
345 | *.nvuser
346 |
347 | # MFractors (Xamarin productivity tool) working folder
348 | .mfractor/
349 |
350 | # Local History for Visual Studio
351 | .localhistory/
352 |
353 | # BeatPulse healthcheck temp database
354 | healthchecksdb
355 |
356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
357 | MigrationBackup/
358 |
359 | # Ionide (cross platform F# VS Code tools) working folder
360 | .ionide/
361 |
362 | # Fody - auto-generated XML schema
363 | FodyWeavers.xsd
--------------------------------------------------------------------------------
/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Archive.cs:
--------------------------------------------------------------------------------
1 | using Gibbed.IO;
2 | using System;
3 | using System.IO;
4 | using System.Runtime.InteropServices;
5 | using UnPSARC.Helpers;
6 |
7 | namespace UnPSARC
8 | {
9 | public class Archive
10 | {
11 | public static string FNameFileHash = BitConverter.ToString(new byte[16]);
12 |
13 | public static void Unpack(Stream ArchiveRaw, string Folder)
14 | {
15 | Stream Reader = ArchiveRaw;
16 | PSARC Psarc = new PSARC(Reader);
17 | Psarc.Read();
18 | Console.WriteLine("Files count: " + Psarc.FilesCount);
19 | int FailedFiles = 0;
20 |
21 | for (int i = 0; i < Psarc.FilesCount; i++)
22 | {
23 | TEntry ThisEntry = Psarc.Entries[i];
24 |
25 | string filenameHash = BitConverter.ToString(ThisEntry.HashNames);
26 |
27 | if (ThisEntry.Offset == 0 || filenameHash == FNameFileHash)
28 | continue;
29 |
30 | string FileName;
31 | if (!Psarc.FileNames.ContainsKey(filenameHash))
32 | {
33 | Console.WriteLine("Archive Contains a hash which is not in filenames table: " + filenameHash);
34 | FileName = "_Unknowns" + Path.DirectorySeparatorChar.ToString() + filenameHash.Replace("-", "") + ".bin";
35 | }
36 | else
37 | {
38 | FileName = Psarc.FileNames[filenameHash].Replace("/", Path.DirectorySeparatorChar.ToString());
39 | }
40 |
41 |
42 | if (FileName.StartsWith(Path.DirectorySeparatorChar.ToString()))
43 | FileName = FileName.Remove(0, 1);
44 |
45 | try
46 | {
47 | TryUnpack(Psarc.Reader, out HugeMemoryStream FileWriter, Psarc.Entries[i], Psarc.ZSizes, Psarc.BlockSize, Psarc.CompressionType);
48 | string outPath = Path.Combine(Folder, FileName);
49 | IOHelper.CheckFolderExists(FileName, Folder);
50 | Stream fileHandle;
51 | if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)){
52 | fileHandle = File.Open(@"\\?\" + outPath, FileMode.Create, FileAccess.Write);
53 | }
54 | else{
55 | fileHandle = File.Open(outPath, FileMode.Create, FileAccess.Write);
56 | }
57 | FileWriter.CopyTo(fileHandle);
58 | fileHandle.Close();
59 | Console.WriteLine("[" + i + "] " + FileName + " Exported!");
60 |
61 | }
62 | catch (Exception ex)
63 | {
64 | var _baseforgroud = Console.ForegroundColor;
65 | Console.ForegroundColor = ConsoleColor.Red;
66 | Console.WriteLine("[" + i + "] " + FileName + " Cannot Exported! Error:" + ex.Message);
67 | Console.ForegroundColor = _baseforgroud;
68 | Console.WriteLine("Press any key to continue unpacking");
69 | Console.ReadKey();
70 | FailedFiles++;
71 | }
72 |
73 | }
74 |
75 | Console.WriteLine($"Unpacking done! | {Psarc.FilesCount - FailedFiles} of {Psarc.FilesCount} Files Exported");
76 | }
77 |
78 | public static void TryUnpack(Stream Reader, out HugeMemoryStream Writer, TEntry ThisEntry, TZSize[] ZSizes, int BlockSize, string CompressionType)
79 | {
80 | long RemainingSize = ThisEntry.UncompressedSize;
81 | int ZSizeIndex = ThisEntry.ZSizeIndex;
82 | long BlockOffset = ThisEntry.Offset;
83 | Stream MEMORY_FILE = new HugeMemoryStream();
84 |
85 | while (MEMORY_FILE.Length < ThisEntry.UncompressedSize)
86 | {
87 | int CompressedSize = ZSizes[ZSizeIndex++].ZSize;
88 |
89 | if (CompressedSize == 0)
90 | CompressedSize = BlockSize;
91 |
92 | if (CompressedSize == ThisEntry.UncompressedSize)
93 | MEMORY_FILE.WriteBytes(Reader.ReadAtOffset(BlockOffset, ThisEntry.UncompressedSize));
94 | else if (RemainingSize < BlockSize || CompressedSize == BlockSize)
95 | MEMORY_FILE.WriteBytes(Reader.ReadAtOffset(BlockOffset, RemainingSize, CompressedSize, CompressionType));
96 | else
97 | MEMORY_FILE.WriteBytes(Reader.ReadAtOffset(BlockOffset, BlockSize, CompressedSize, CompressionType));
98 |
99 | BlockOffset += (uint)CompressedSize;
100 | RemainingSize -= BlockSize;
101 | }
102 |
103 | MEMORY_FILE.Position = 0;
104 | Writer = (HugeMemoryStream)MEMORY_FILE;
105 | }
106 |
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/Compression/Oodle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Runtime.InteropServices;
4 |
5 | namespace UnPSARC
6 | {
7 |
8 | public static class Oodle
9 | {
10 | public enum OodleLZ_Verbosity
11 | {
12 | None,
13 | Max = 3
14 | }
15 | public enum OodleLZ_FuzzSafe
16 | {
17 | No,
18 | Yes
19 | }
20 | public enum OodleLZ_Decode_ThreadPhase
21 | {
22 | ThreadPhase1 = 0x1,
23 | ThreadPhase2 = 0x2,
24 |
25 | Unthreaded = ThreadPhase1 | ThreadPhase2
26 | }
27 | public enum OodleLZ_CheckCRC
28 | {
29 | No,
30 | Yes
31 | }
32 | public enum OodleLZ_OodleCompressionLevel
33 | {
34 | HyperFast4 = -4,
35 | HyperFast3,
36 | HyperFast2,
37 | HyperFast1,
38 | None,
39 | SuperFast,
40 | VeryFast,
41 | Fast,
42 | Normal,
43 | Optimal1,
44 | Optimal2,
45 | Optimal3,
46 | Optimal4,
47 | Optimal5,
48 | // TooHigh,
49 |
50 | Min = HyperFast4,
51 | Max = Optimal5
52 | }
53 | public enum OodleLZ_OodleFormat
54 | {
55 | Invalid = -1,
56 | LZH,
57 | LZHLW,
58 | LZNIB,
59 | None,
60 | LZB16,
61 | LZBLW,
62 | LZA,
63 | LZNA,
64 | Kraken,
65 | Mermaid,
66 | BitKnit,
67 | Selkie,
68 | Hydra,
69 | Leviathan
70 | }
71 |
72 | [DllImport("oo2core_9_win64.dll")]
73 | private static extern long OodleLZ_Decompress(byte[] buffer, long bufferSize, byte[] outputBuffer, long outputBufferSize, OodleLZ_FuzzSafe fuzz, OodleLZ_CheckCRC crc, OodleLZ_Verbosity verbosity, long context, long e, long callback, long callback_ctx, long scratch, long scratch_size, OodleLZ_Decode_ThreadPhase thread_phase);
74 | public static byte[] Decompress(byte[] buffer, int uncompressedSize, OodleLZ_FuzzSafe fuzz, OodleLZ_CheckCRC crc, OodleLZ_Verbosity verbos, OodleLZ_Decode_ThreadPhase threadPhase)
75 | {
76 | byte[] numArray = new byte[uncompressedSize];
77 | long count = OodleLZ_Decompress(buffer, buffer.Length, numArray, (long)uncompressedSize, fuzz, crc, verbos, 0U, 0U, 0U, 0U, 0U, 0U, threadPhase);
78 | if (count == uncompressedSize)
79 | return numArray;
80 | return count < uncompressedSize ? numArray.Take((int)count).ToArray() : throw new Exception("There was an error while decompressing");
81 | }
82 | }
83 | }
--------------------------------------------------------------------------------
/Compression/Zlib.cs:
--------------------------------------------------------------------------------
1 | using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
2 | using System.IO;
3 | using UnPSARC.Helpers;
4 |
5 | namespace UnPSARC
6 | {
7 | public static class Zlib
8 | {
9 | public static byte[] Decompress(byte[] Data,int decompressedSize)
10 | {
11 | var compressedStream = new MemoryStream(Data);
12 | var decompressedStream = new HugeMemoryStream();
13 | try
14 | {
15 | using (var zlibStream = new InflaterInputStream(compressedStream))
16 | {
17 | zlibStream.CopyTo(decompressedStream);
18 | }
19 | decompressedStream.Position = 0;
20 |
21 | }
22 | catch
23 | {
24 | return new byte[decompressedSize];
25 | }
26 |
27 | return decompressedStream.ToByteArray();
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/Core/PSARC.cs:
--------------------------------------------------------------------------------
1 | using Gibbed.IO;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Text;
6 | using UnPSARC.Helpers;
7 |
8 | namespace UnPSARC
9 | {
10 | internal class PSARC
11 | {
12 | private string ArchiveMagic;
13 | private ushort MajorVersion;
14 | private ushort MinorVersion;
15 | public string CompressionType;
16 | public int StartOFDatas;
17 | public int SizeOfEntry;
18 | public int FilesCount;
19 | public int ZSizeCount;
20 | public int BlockSize;
21 | private int Zero;
22 | public TEntry[] Entries;
23 | public TZSize[] ZSizes;
24 | public Dictionary FileNames;
25 | public Stream Reader;
26 | public Stream Writer;
27 | public PSARC(Stream Reader)
28 | {
29 | this.Reader = Reader;
30 | }
31 | public PSARC(Stream Reader, Stream Writer)
32 | {
33 | this.Reader = Reader;
34 | this.Writer = Writer;
35 | }
36 | public void Read()
37 | {
38 | Reader.Seek(0, SeekOrigin.Begin);
39 | ArchiveMagic = Reader.ReadString(4);
40 | if (ArchiveMagic == "DSAR")
41 | {
42 | Console.WriteLine("Archive is Compressed (DSAR), trying to Decompress...");
43 | Reader = DirectStorage.Decompressor.Decompress(Reader);
44 | Reader.Seek(0, SeekOrigin.Begin);
45 | ArchiveMagic = Reader.ReadString(4);
46 | }
47 |
48 | if (ArchiveMagic != "PSAR") throw new Exception("Not valid PSARC file! Magic:" + ArchiveMagic);
49 | MajorVersion = Reader.ReadValueU16(Endian.Big);
50 | MinorVersion = Reader.ReadValueU16(Endian.Big);
51 | CompressionType = Reader.ReadString(4);
52 | if (CompressionType != "oodl" && CompressionType != "zlib") throw new Exception("Unsupported Compression method : " + CompressionType);
53 | if (CompressionType == "oodl" && !Program.oodleExist)
54 | {
55 | Console.WriteLine("'oo2core_9_win64.dll' does not exist in the current application path!!!");
56 | Console.WriteLine("To fix this, copy the dll from your game directory to the same directory that UnPSARC.exe is stored.");
57 | Console.WriteLine("Press any key to exit");
58 | Console.ReadKey();
59 | return;
60 | }
61 |
62 | StartOFDatas = Reader.ReadValueS32(Endian.Big);
63 | SizeOfEntry = Reader.ReadValueS32(Endian.Big);
64 | FilesCount = Reader.ReadValueS32(Endian.Big);
65 | ZSizeCount = (StartOFDatas - (SizeOfEntry * FilesCount) + 32) / 2;
66 | BlockSize = Reader.ReadValueS32(Endian.Big);
67 | Zero = Reader.ReadValueS32(Endian.Big);
68 | Entries = new TEntry[FilesCount];
69 | for (int index = 0; index < FilesCount; ++index)
70 | {
71 | TEntry tentry = new TEntry(index);
72 | tentry.Read(Reader);
73 | Entries[index] = tentry;
74 | }
75 | ZSizes = new TZSize[ZSizeCount];
76 | for (int index = 0; index < ZSizeCount; ++index)
77 | {
78 | TZSize tzsize = new TZSize(index);
79 | tzsize.Read(Reader);
80 | ZSizes[index] = tzsize;
81 | }
82 | Archive.TryUnpack(Reader, out HugeMemoryStream filenamebuffer, Entries[0], ZSizes, BlockSize, CompressionType);
83 | FileNames = new Dictionary(LoadFileNames(filenamebuffer.ToByteArray()));
84 |
85 | }
86 | private Dictionary LoadFileNames(byte[] file)
87 | {
88 | string[] Names = Encoding.UTF8.GetString(file).Split(new[] { "\n", "\0" }, StringSplitOptions.None);
89 | Dictionary ret = new Dictionary();
90 | foreach (string Name in Names)
91 | {
92 | if (!ret.ContainsKey(IOHelper.GetMD5String(Name)))
93 | {
94 | ret.Add(BitConverter.ToString(IOHelper.GetMD5(Name)), Name);
95 | }
96 | if (!ret.ContainsKey(IOHelper.GetMD5String(Name.ToUpper())))
97 | {
98 | ret.Add(BitConverter.ToString(IOHelper.GetMD5(Name.ToUpper())), Name.ToUpper()); // Issue #20
99 | }
100 | if (!ret.ContainsKey(IOHelper.GetMD5String(Name.ToLower())))
101 | {
102 | ret.Add(BitConverter.ToString(IOHelper.GetMD5(Name.ToLower())), Name.ToLower()); // Mostly not needed
103 | }
104 | }
105 | return ret;
106 | }
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/Core/TEntry.cs:
--------------------------------------------------------------------------------
1 | using Gibbed.IO;
2 | using System;
3 | using System.IO;
4 |
5 | namespace UnPSARC
6 | {
7 | public class TEntry
8 | {
9 | private int index;
10 | public byte[] HashNames;
11 | public int ZSizeIndex;
12 | public long UncompressedSize;
13 | public long Offset;
14 | public byte[] OverwriteBuffer = { };
15 | public TEntry(int index) => this.index = index;
16 | public void Read(Stream Reader)
17 | {
18 | HashNames = Reader.ReadBytes(0x10);
19 | ZSizeIndex = Reader.ReadValueS32(Endian.Big);
20 | UncompressedSize = ((Int64)Reader.ReadByte()) << 32 | Reader.ReadValueU32(Endian.Big);
21 | Offset = ((Int64)Reader.ReadByte()) << 32 | Reader.ReadValueU32(Endian.Big);
22 | }
23 |
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Core/TZSize.cs:
--------------------------------------------------------------------------------
1 | using Gibbed.IO;
2 | using System.IO;
3 |
4 | namespace UnPSARC
5 | {
6 | public class TZSize
7 | {
8 | private int index;
9 | public int ZSize;
10 | public TZSize(int index) => this.index = index;
11 | public void Read(Stream Reader)
12 | {
13 | ZSize = Reader.ReadValueU16(Endian.Big);
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/DirectStorage/Decompressor.cs:
--------------------------------------------------------------------------------
1 | using Gibbed.IO;
2 | using K4os.Compression.LZ4;
3 | using System.IO;
4 | using UnPSARC.Helpers;
5 |
6 | namespace UnPSARC.DirectStorage
7 | {
8 | internal class Decompressor
9 | {
10 |
11 | public static Stream Decompress(Stream compressedStream)
12 | {
13 | Stream fs = compressedStream;
14 | fs.Seek(0, SeekOrigin.Begin);
15 | Stream wt = new HugeMemoryStream();
16 | fs.ReadBytes(8);
17 | int count = fs.ReadValueS32();
18 | fs.ReadBytes(20);
19 |
20 | for (int i = 0; i < count; i++)
21 | {
22 | fs.ReadValueS64(); //Decompressed offset
23 | long offsetCom = fs.ReadValueS64();
24 | int sizeDec = fs.ReadValueS32();
25 | int sizeCom = fs.ReadValueS32();
26 | int CompType = fs.ReadByte();
27 | fs.ReadBytes(7);
28 | if (sizeCom == 0) //padding
29 | {
30 | wt.WriteBytes(new byte[sizeDec]);
31 | continue;
32 | }
33 | long back_ = fs.Position;
34 |
35 | fs.Seek(offsetCom, SeekOrigin.Begin);
36 |
37 | var buffer = fs.ReadBytes(sizeCom);
38 |
39 | var target = new byte[sizeDec];
40 | if (CompType == 0)
41 | target = buffer;
42 | else
43 | LZ4Codec.Decode(buffer, 0, buffer.Length, target, 0, target.Length);
44 |
45 | fs.Seek(back_, SeekOrigin.Begin);
46 | wt.WriteBytes(target);
47 | }
48 | return wt;
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Helpers/CommendHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Linq;
4 |
5 | namespace UnPSARC.Helpers
6 | {
7 | internal class CommendHelper
8 | {
9 | public static bool IsFullPath(string path)
10 | {
11 | return !String.IsNullOrWhiteSpace(path)
12 | && path.IndexOfAny(System.IO.Path.GetInvalidPathChars().ToArray()) == -1
13 | && Path.IsPathRooted(path)
14 | && !Path.GetPathRoot(path).Equals(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal);
15 | }
16 | public static bool IsValidPath(string path, bool allowRelativePaths = false)
17 | {
18 | bool isValid;
19 | try
20 | {
21 | string fullPath = Path.GetFullPath(path);
22 | if (allowRelativePaths)
23 | isValid = Path.IsPathRooted(path);
24 | else
25 | {
26 | string root = Path.GetPathRoot(path);
27 | isValid = string.IsNullOrEmpty(root.Trim(new char[] { '\\', '/' })) == false;
28 | }
29 | }
30 | catch
31 | {
32 | isValid = false;
33 | }
34 |
35 | return isValid;
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Helpers/HugeMemoryStream.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace UnPSARC.Helpers
5 | {
6 | public class HugeMemoryStream : Stream
7 | {
8 | #region Fields
9 |
10 | private const int PAGE_SIZE = 1024000;
11 | private const int ALLOC_STEP = 1024;
12 |
13 | private byte[][] _streamBuffers;
14 |
15 | private int _pageCount = 0;
16 | private long _allocatedBytes = 0;
17 |
18 | private long _position = 0;
19 | private long _length = 0;
20 |
21 | #endregion Fields
22 |
23 | #region Internals
24 |
25 | private int GetPageCount(long length)
26 | {
27 | int pageCount = (int)(length / PAGE_SIZE) + 1;
28 |
29 | if ((length % PAGE_SIZE) == 0)
30 | pageCount--;
31 |
32 | return pageCount;
33 | }
34 |
35 | private void ExtendPages()
36 | {
37 | if (_streamBuffers == null)
38 | {
39 | _streamBuffers = new byte[ALLOC_STEP][];
40 | }
41 | else
42 | {
43 | byte[][] streamBuffers = new byte[_streamBuffers.Length + ALLOC_STEP][];
44 |
45 | Array.Copy(_streamBuffers, streamBuffers, _streamBuffers.Length);
46 |
47 | _streamBuffers = streamBuffers;
48 | }
49 |
50 | _pageCount = _streamBuffers.Length;
51 | }
52 |
53 | private void AllocSpaceIfNeeded(long value)
54 | {
55 | if (value < 0)
56 | throw new InvalidOperationException("AllocSpaceIfNeeded < 0");
57 |
58 | if (value == 0)
59 | return;
60 |
61 | int currentPageCount = GetPageCount(_allocatedBytes);
62 | int neededPageCount = GetPageCount(value);
63 |
64 | while (currentPageCount < neededPageCount)
65 | {
66 | if (currentPageCount == _pageCount)
67 | ExtendPages();
68 |
69 | _streamBuffers[currentPageCount++] = new byte[PAGE_SIZE];
70 | }
71 |
72 | _allocatedBytes = (long)currentPageCount * PAGE_SIZE;
73 |
74 | value = Math.Max(value, _length);
75 |
76 | if (_position > (_length = value))
77 | _position = _length;
78 | }
79 |
80 | #endregion Internals
81 |
82 | #region Stream
83 |
84 | public override bool CanRead => true;
85 |
86 | public override bool CanSeek => true;
87 |
88 | public override bool CanWrite => true;
89 |
90 | public override long Length => _length;
91 |
92 | public override long Position
93 | {
94 | get { return _position; }
95 | set
96 | {
97 | if (value > _length)
98 | throw new InvalidOperationException("Position > Length");
99 | else if (value < 0)
100 | throw new InvalidOperationException("Position < 0");
101 | else
102 | _position = value;
103 | }
104 | }
105 |
106 | public override void Flush() { }
107 |
108 | public override int Read(byte[] buffer, int offset, int count)
109 | {
110 | int currentPage = (int)(_position / PAGE_SIZE);
111 | int currentOffset = (int)(_position % PAGE_SIZE);
112 | int currentLength = PAGE_SIZE - currentOffset;
113 |
114 | long startPosition = _position;
115 |
116 | if (startPosition + count > _length)
117 | count = (int)(_length - startPosition);
118 |
119 | while (count != 0 && _position < _length)
120 | {
121 | if (currentLength > count)
122 | currentLength = count;
123 |
124 | Array.Copy(_streamBuffers[currentPage++], currentOffset, buffer, offset, currentLength);
125 |
126 | offset += currentLength;
127 | _position += currentLength;
128 | count -= currentLength;
129 |
130 | currentOffset = 0;
131 | currentLength = PAGE_SIZE;
132 | }
133 |
134 | return (int)(_position - startPosition);
135 | }
136 |
137 | public override long Seek(long offset, SeekOrigin origin)
138 | {
139 | switch (origin)
140 | {
141 | case SeekOrigin.Begin:
142 | break;
143 |
144 | case SeekOrigin.Current:
145 | offset += _position;
146 | break;
147 |
148 | case SeekOrigin.End:
149 | offset = _length - offset;
150 | break;
151 |
152 | default:
153 | throw new ArgumentOutOfRangeException("origin");
154 | }
155 |
156 | return Position = offset;
157 | }
158 |
159 | public override void SetLength(long value)
160 | {
161 | if (value < 0)
162 | throw new InvalidOperationException("SetLength < 0");
163 |
164 | if (value == 0)
165 | {
166 | _streamBuffers = null;
167 | _allocatedBytes = _position = _length = 0;
168 | _pageCount = 0;
169 | return;
170 | }
171 |
172 | int currentPageCount = GetPageCount(_allocatedBytes);
173 | int neededPageCount = GetPageCount(value);
174 |
175 | // Removes unused buffers if decreasing stream length
176 | while (currentPageCount > neededPageCount)
177 | _streamBuffers[--currentPageCount] = null;
178 |
179 | AllocSpaceIfNeeded(value);
180 |
181 | if (_position > (_length = value))
182 | _position = _length;
183 | }
184 |
185 | public override void Write(byte[] buffer, int offset, int count)
186 | {
187 | int currentPage = (int)(_position / PAGE_SIZE);
188 | int currentOffset = (int)(_position % PAGE_SIZE);
189 | int currentLength = PAGE_SIZE - currentOffset;
190 |
191 | long startPosition = _position;
192 |
193 | AllocSpaceIfNeeded(_position + count);
194 |
195 | while (count != 0)
196 | {
197 | if (currentLength > count)
198 | currentLength = count;
199 |
200 | Array.Copy(buffer, offset, _streamBuffers[currentPage++], currentOffset, currentLength);
201 |
202 | offset += currentLength;
203 | _position += currentLength;
204 | count -= currentLength;
205 |
206 | currentOffset = 0;
207 | currentLength = PAGE_SIZE;
208 | }
209 | }
210 |
211 | #endregion Stream
212 | }
213 | }
214 |
--------------------------------------------------------------------------------
/Helpers/IOHelper.cs:
--------------------------------------------------------------------------------
1 | using Gibbed.IO;
2 | using System;
3 | using System.IO;
4 | using System.Runtime.InteropServices;
5 | using System.Xml.Linq;
6 |
7 | namespace UnPSARC
8 | {
9 | public static class IOHelper
10 | {
11 | public static byte[] ReadAtOffset(this Stream s, long Offset, long Size)
12 | {
13 | long pos = s.Position;
14 | s.Seek(Offset, SeekOrigin.Begin);
15 | byte[] log = s.ReadBytes((int)Size);
16 | s.Seek(pos, SeekOrigin.Begin);
17 | return log;
18 | }
19 | public static byte[] ReadAtOffset(this Stream s, long Offset, long size, int ZSize, string CompressionType)
20 | {
21 |
22 | long pos = s.Position;
23 | s.Seek(Offset, SeekOrigin.Begin);
24 | int magic = s.ReadValueU16();
25 | s.Seek(Offset, SeekOrigin.Begin);
26 | byte[] Block = s.ReadBytes(ZSize);
27 | byte[] log = { };
28 | if (CompressionType == "oodl" && magic == 0x68C) log = Oodle.Decompress(Block, (int)size, Oodle.OodleLZ_FuzzSafe.No, Oodle.OodleLZ_CheckCRC.No, Oodle.OodleLZ_Verbosity.None, Oodle.OodleLZ_Decode_ThreadPhase.Unthreaded);
29 | if (CompressionType == "zlib" && magic == 0xDA78) log = Zlib.Decompress(Block, (int)size);
30 | if (log.Length == 0) log = Block;
31 | s.Seek(pos, SeekOrigin.Begin);
32 | return log;
33 | }
34 | public static byte[] ToByteArray(this Stream a)
35 | {
36 | using (MemoryStream ms = new MemoryStream())
37 | {
38 | a.Position = 0;
39 | a.CopyTo(ms);
40 | return ms.ToArray();
41 | }
42 | }
43 | public static byte[] GetMD5(string input)
44 | {
45 | using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
46 | {
47 | byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
48 | byte[] hashBytes = md5.ComputeHash(inputBytes);
49 |
50 | return hashBytes;
51 | }
52 | }
53 | public static string GetMD5String(string input)
54 | {
55 | return BitConverter.ToString(GetMD5(input));
56 | }
57 | public static void CheckFolderExists(string filename, string basefolder)
58 | {
59 | if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
60 | {
61 | if (!Directory.Exists(Path.GetDirectoryName(@"\\?\" + Path.Combine(basefolder, filename))))
62 | {
63 | Directory.CreateDirectory(Path.GetDirectoryName(@"\\?\" + Path.Combine(basefolder, filename)));
64 | }
65 | }
66 | else
67 | {
68 | if (!Directory.Exists(Path.GetDirectoryName(Path.Combine(basefolder, filename))))
69 | {
70 | Directory.CreateDirectory(Path.GetDirectoryName(Path.Combine(basefolder, filename)));
71 | }
72 | }
73 |
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 NoobInCoding
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Packer.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace UnPSARC {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Packer {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Packer() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("UnPSARC.Packer", typeof(Packer).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | ///
64 | /// Looks up a localized resource of type System.Byte[].
65 | ///
66 | internal static byte[] psarc {
67 | get {
68 | object obj = ResourceManager.GetObject("psarc", resourceCulture);
69 | return ((byte[])(obj));
70 | }
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/Packer.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 |
122 | Resources\psarc.exe;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
123 |
124 |
--------------------------------------------------------------------------------
/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.IO;
5 | using UnPSARC.Helpers;
6 |
7 | namespace UnPSARC
8 | {
9 | internal class Program
10 | {
11 | private static string archiveExtension = ".psarc";
12 | public static bool oodleExist = false;
13 |
14 | private static void PrintUsage()
15 | {
16 | Console.WriteLine("Usage:");
17 | Console.WriteLine("Unpack: Unpsarc.exe [destination folder]");
18 | Console.WriteLine(" Pack : Unpsarc.exe [archive filename to create]");
19 | Console.WriteLine("\nPress any key to exit");
20 | Console.ReadKey();
21 | }
22 |
23 | private static bool CheckForOodle()
24 | {
25 | string currentApplicationPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
26 | string currentApplicationDirectory = Path.GetDirectoryName(currentApplicationPath);
27 | string oodleLocation = Path.Combine(currentApplicationDirectory + "oo2core_9_win64.dll");
28 |
29 | return File.Exists(oodleLocation);
30 | }
31 |
32 | static void Main(string[] args)
33 | {
34 | Console.WriteLine("UnPSARC (Archive Tool For PlayStation Archive files 'PSARC')");
35 | Console.WriteLine("By NoobInCoding");
36 | Console.WriteLine("https://github.com/rm-NoobInCoding/UnPSARC");
37 | Console.WriteLine("");
38 |
39 | if (args.Length < 1)
40 | {
41 | PrintUsage();
42 | return;
43 | }
44 |
45 | oodleExist = CheckForOodle();
46 |
47 | bool isFile = File.Exists(args[0]);
48 | bool isDirectory = Directory.Exists(args[0]);
49 | string outputName = null;
50 |
51 | if (args.Length > 1)
52 | {
53 | if ((CommendHelper.IsFullPath(args[1]) && CommendHelper.IsValidPath(args[1])) || !CommendHelper.IsFullPath(args[1]))
54 | outputName = args[1];
55 | else
56 | {
57 | Console.WriteLine("Output directory is not a valid path! Make sure your path is in quotation marks.");
58 | PrintUsage();
59 | return;
60 | }
61 | }
62 | if (isFile && !isDirectory)
63 | {
64 | if (Path.GetExtension(args[0]) == archiveExtension)
65 | {
66 | if (outputName == null)
67 | {
68 | string TempDir = Path.GetDirectoryName(args[0]);
69 | if (TempDir == "") TempDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
70 | string customOutputDirectory = Path.GetFileNameWithoutExtension(args[0]) + "_Unpacked";
71 | // string customOutputDirectory = Path.GetFileNameWithoutExtension(args[0]); // Extract to same folder instead
72 | if (Directory.Exists(customOutputDirectory) == false)
73 | Directory.CreateDirectory(customOutputDirectory);
74 | UnpackArchiveFile(args[0], Path.Combine(TempDir, customOutputDirectory));
75 | }
76 | else
77 | {
78 | UnpackArchiveFile(args[0], outputName);
79 | }
80 | }
81 | }
82 | else if (isDirectory && !isFile)
83 | {
84 | if (outputName == null)
85 | {
86 | Console.WriteLine($"Packing {args[0]} to {Path.GetFileNameWithoutExtension(args[0]) + ".psarc"}");
87 | PackArchiveFile(args[0], "../" + Path.GetFileNameWithoutExtension(args[0]) + ".psarc");
88 | }
89 | else
90 | {
91 | if (!CommendHelper.IsFullPath(outputName))
92 | {
93 | if (outputName.StartsWith(Path.DirectorySeparatorChar.ToString())) outputName = outputName.Remove(0, 1);
94 | outputName = Path.Combine(Environment.CurrentDirectory, outputName);
95 | }
96 | Console.WriteLine($"Packing {args[0]} to {outputName}");
97 | PackArchiveFile(args[0], outputName);
98 |
99 | }
100 |
101 | }
102 | else
103 | {
104 | Console.WriteLine("Input path argument is not a valid file/directory, or does not exist! (Make sure your path is in quotation marks)");
105 | PrintUsage();
106 | }
107 | }
108 |
109 | private static void PackArchiveFile(string contentFolderPath, string outputFilename)
110 | {
111 |
112 | File.WriteAllText(Path.Combine(contentFolderPath, "Filenames.txt"), MakeFileNameTable(contentFolderPath));
113 | File.WriteAllBytes(Path.Combine(contentFolderPath, "r.exe"), Packer.psarc);
114 | ProcessStartInfo psi = new ProcessStartInfo
115 | {
116 | FileName = Path.Combine(contentFolderPath, "r.exe"),
117 | Arguments = $"create -a --skip-missing-files --inputfile=filenames.txt --output=\"{outputFilename}\" -N -y",
118 | RedirectStandardOutput = true,
119 | RedirectStandardError = true,
120 | WorkingDirectory = contentFolderPath,
121 | UseShellExecute = false,
122 | CreateNoWindow = true,
123 | };
124 | using (var process = new Process { StartInfo = psi })
125 | {
126 | process.OutputDataReceived += (sender, e) =>
127 | {
128 | if (e.Data != null)
129 | {
130 | Console.WriteLine(e.Data);
131 | }
132 | };
133 | process.ErrorDataReceived += (sender, e) =>
134 | {
135 | if (e.Data != null)
136 | {
137 | Console.Error.WriteLine(e.Data);
138 | }
139 | };
140 |
141 | process.Start();
142 | process.BeginOutputReadLine();
143 | process.BeginErrorReadLine();
144 | process.WaitForExit();
145 | File.Delete(Path.Combine(contentFolderPath, "r.exe"));
146 | File.Delete(Path.Combine(contentFolderPath, "Filenames.txt"));
147 | }
148 |
149 | }
150 |
151 | private static string MakeFileNameTable(string contentFolderPath)
152 | {
153 | List files = new List();
154 | foreach (string fname in Directory.GetFiles(contentFolderPath, "*.*", SearchOption.AllDirectories))
155 | {
156 | if (Path.GetFileName(fname) == "Filenames.txt")
157 | continue;
158 | string _ = fname.Replace(contentFolderPath + Path.DirectorySeparatorChar.ToString(), "").Replace(Path.DirectorySeparatorChar.ToString(), "/");
159 | files.Add(_);
160 | }
161 | return string.Join("\n", files);
162 | }
163 |
164 | private static void UnpackArchiveFile(string inputPath, string outputDirectory)
165 | {
166 | Console.WriteLine("Unpacking {0}...", Path.GetFileName(inputPath));
167 |
168 | Stream R = File.OpenRead(inputPath);
169 | Archive.Unpack(R, outputDirectory);
170 | R.Close();
171 | }
172 | }
173 | }
174 |
--------------------------------------------------------------------------------
/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 | [assembly: AssemblyTitle("UnPSARC")]
5 | [assembly: AssemblyDescription("Archive Unpacker For Uncharted Legacy Of Thieves Collection PC Version")]
6 | [assembly: AssemblyConfiguration("")]
7 | [assembly: AssemblyCompany("NoobInCoding")]
8 | [assembly: AssemblyProduct("UnPSARC")]
9 | [assembly: AssemblyCopyright("Copyright © 2022")]
10 | [assembly: AssemblyTrademark("")]
11 | [assembly: AssemblyCulture("")]
12 | [assembly: ComVisible(false)]
13 | [assembly: Guid("5f289ee2-144b-4b51-a4eb-b21b83ad4907")]
14 | [assembly: AssemblyVersion("1.3.0.0")]
15 | [assembly: AssemblyFileVersion("1.3.0.0")]
16 |
--------------------------------------------------------------------------------
/Properties/app.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
50 |
58 |
59 |
73 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # UnPSARC
2 |
3 | **UnPSARC** is a comprehensive tool tailored for the manipulation of PlayStation Archive (PSARC) files, which are widely used by Naughty Dog games for data archiving.
4 | > [!NOTE]
5 | > This tool is only for psarc files. The files inside the archive are not within the scope of this tool. Please do not create an issue for these files!
6 |
7 | ## Key Features
8 | - **Extraction**: Effortlessly unpack the contents of PSARC files.
9 | - **Packaging**: Seamlessly create new PSARC files from your directories.
10 |
11 | ## Game Compatibility
12 | - **Uncharted** series (PS3 version compatibility is untested)
13 | - **The Last Of Us** series (PS3 version compatibility is untested)
14 | - **Ghost of Tsushima**
15 | - Other titles employing the PSARC format may also be supported.
16 |
17 | ## Getting Started
18 | To view a comprehensive list of commands and options, execute `UnPSARC.exe` in your command line without any parameters.
19 |
20 | ### Instructions for Uncharted Series (or other games that use Oodle for compression)
21 | 1. Transfer `oo2core_9_win64.dll` from the game directory to the same folder as `UnPSARC.exe`. You can download this dll from internet too.
22 | 2. Simply drag and drop the desired PSARC file onto `UnPSARC.exe` to begin the extraction process.
23 |
24 | ### Instructions for Other Titles
25 | For games that utilize the PSARC format:
26 | - Drag and drop the PSARC file onto `UnPSARC.exe` to start extracting files.
27 |
28 | ## Thanks to
29 | - DKDave
30 | - Rick Gibbed
31 | - Chandler Threepwood
32 | - fillmsm
33 |
34 | ## License
35 | UnPSARC is open-sourced under the MIT License.
36 |
37 |
--------------------------------------------------------------------------------
/Resources/psarc.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rm-NoobInCoding/UnPSARC/187d9450a1be01d385e8ac52dd2d47a0b6314f31/Resources/psarc.exe
--------------------------------------------------------------------------------
/UnPSARC.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {5F289EE2-144B-4B51-A4EB-B21B83AD4907}
8 | Exe
9 | UnPSARC
10 | UnPSARC
11 | v4.8
12 | 512
13 | true
14 | true
15 | false
16 | publish\
17 | true
18 | Disk
19 | false
20 | Foreground
21 | 7
22 | Days
23 | false
24 | false
25 | true
26 | https://github.com/rm-NoobInCoding/UnPSARC
27 | https://github.com/rm-NoobInCoding/UnPSARC/issues
28 | en
29 | UnPSARC
30 | NoobInCoding
31 | true
32 | 1
33 | 1.3.0.%2a
34 | false
35 | true
36 | true
37 |
38 |
39 | AnyCPU
40 | true
41 | full
42 | false
43 | bin\Debug\
44 | DEBUG;TRACE
45 | prompt
46 | 4
47 |
48 |
49 | AnyCPU
50 | pdbonly
51 | true
52 | bin\Release\
53 | TRACE
54 | prompt
55 | 4
56 |
57 |
58 | true
59 | bin\x64\Debug\
60 | DEBUG;TRACE
61 | full
62 | x64
63 | 7.3
64 | prompt
65 | true
66 |
67 |
68 | bin\x64\Release\
69 | TRACE
70 | true
71 | pdbonly
72 | x64
73 | 7.3
74 | prompt
75 | true
76 |
77 |
78 | true
79 | bin\x86\Debug\
80 | DEBUG;TRACE
81 | full
82 | x86
83 | 7.3
84 | prompt
85 | true
86 |
87 |
88 | bin\x86\Release\
89 | TRACE
90 | true
91 | pdbonly
92 | x86
93 | 7.3
94 | prompt
95 | true
96 |
97 |
98 | false
99 |
100 |
101 | F29923473B3080162390AB9C9586B5A827240BA9
102 |
103 |
104 | UnPSARC_TemporaryKey.pfx
105 |
106 |
107 | false
108 |
109 |
110 | LocalIntranet
111 |
112 |
113 | Properties\app.manifest
114 |
115 |
116 |
117 | packages\Gibbed.IO.1.0.0\lib\Gibbed.IO.dll
118 |
119 |
120 | packages\SharpZipLib.1.4.2\lib\netstandard2.0\ICSharpCode.SharpZipLib.dll
121 |
122 |
123 | packages\K4os.Compression.LZ4.1.3.8\lib\net462\K4os.Compression.LZ4.dll
124 |
125 |
126 |
127 | packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll
128 |
129 |
130 |
131 | packages\System.Memory.4.5.5\lib\net461\System.Memory.dll
132 |
133 |
134 |
135 | packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll
136 |
137 |
138 | packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll
139 |
140 |
141 | packages\System.Threading.Tasks.Extensions.4.5.2\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 | True
159 | True
160 | Packer.resx
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 | False
177 | Microsoft .NET Framework 4.8 %28x86 and x64%29
178 | true
179 |
180 |
181 | False
182 | .NET Framework 3.5 SP1
183 | false
184 |
185 |
186 |
187 |
188 | ResXFileCodeGenerator
189 | Packer.Designer.cs
190 |
191 |
192 |
193 |
194 |
195 |
196 |
--------------------------------------------------------------------------------
/UnPSARC.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.0.31903.59
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnPSARC", "UnPSARC.csproj", "{5F289EE2-144B-4B51-A4EB-B21B83AD4907}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Debug|x64 = Debug|x64
12 | Release|Any CPU = Release|Any CPU
13 | Release|x64 = Release|x64
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {5F289EE2-144B-4B51-A4EB-B21B83AD4907}.Debug|Any CPU.ActiveCfg = Debug|x64
17 | {5F289EE2-144B-4B51-A4EB-B21B83AD4907}.Debug|Any CPU.Build.0 = Debug|x64
18 | {5F289EE2-144B-4B51-A4EB-B21B83AD4907}.Debug|x64.ActiveCfg = Debug|x64
19 | {5F289EE2-144B-4B51-A4EB-B21B83AD4907}.Debug|x64.Build.0 = Debug|x64
20 | {5F289EE2-144B-4B51-A4EB-B21B83AD4907}.Release|Any CPU.ActiveCfg = Release|x64
21 | {5F289EE2-144B-4B51-A4EB-B21B83AD4907}.Release|Any CPU.Build.0 = Release|x64
22 | {5F289EE2-144B-4B51-A4EB-B21B83AD4907}.Release|x64.ActiveCfg = Release|x64
23 | {5F289EE2-144B-4B51-A4EB-B21B83AD4907}.Release|x64.Build.0 = Release|x64
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {0D03E5CE-AC0A-4177-AFDC-C6532493531D}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------