Skip to content

Commit

Permalink
Major bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
RikuKH3 authored Sep 25, 2017
1 parent 97ba2f2 commit ea60bc8
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions unpkg_vita.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ var
LicenseFlags: Word;
utf8s: UTF8String;
WorkbinExist: Boolean;
OutFolder, s, s2: String;
OutFolder, s, s2, s3: String;
i: Integer;
begin
try
Writeln('PS Vita PKG Unpacker v1.2 by RikuKH3');
Writeln('PS Vita PKG Unpacker v1.3 by RikuKH3');
Writeln('------------------------------------');
if ParamCount=0 then begin Writeln('Usage: '+ExtractFileName(ParamStr(0))+' <input pkg file> [output folder] [-key=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF]'); Readln; exit end;

Expand Down Expand Up @@ -182,13 +182,11 @@ begin
for LongWord1:=0 to ItemCnt-1 do begin
MemoryStream1.Position := LongWord1 * $20 + $10;
MemoryStream1.ReadBuffer(ItemSize, 8);
if ItemSize>0 then Inc(NumOfFiles);
if ItemSize<>0 then Inc(NumOfFiles);
end;
s := IntToStr(NumOfFiles);
i := Length(s);

ForceDirectories(OutFolder);

for LongWord1:=0 to ItemCnt-1 do begin
MemoryStream1.Position := LongWord1 * $20;
MemoryStream1.ReadBuffer(NameOffset, 4);
Expand All @@ -200,21 +198,19 @@ begin
MemoryStream1.ReadBuffer(ItemSize, 8);
ItemSize := Swap64(ItemSize);

if ItemSize=0 then begin
MemoryStream1.Position := NameOffset;
SetLength(utf8s, NameSize);
MemoryStream1.ReadBuffer(utf8s[1], NameSize);
CreateDir(OutFolder+string(utf8s));
end else begin
if ItemSize>0 then begin
MemoryStream1.Position := NameOffset;
SetLength(utf8s, NameSize);
MemoryStream1.ReadBuffer(utf8s[1], NameSize);
s3 := StringReplace(string(utf8s),'/','\',[rfReplaceAll]);
ForceDirectories(OutFolder+ExtractFilePath(s3));

FileStream1.Position := DataOffset + ItemOffset;
s2 := IntToStr(ListPos);
s2 := StringOfChar('0', i-Length(s2)) + s2;
Writeln('['+s2+'/'+s+'] ', utf8s);
Writeln('['+s2+'/'+s+'] ', s3);
Inc(ListPos);
FileStream2:=TFileStream.Create(OutFolder+string(utf8s), fmCreate or fmOpenWrite or fmShareDenyWrite);
FileStream2:=TFileStream.Create(OutFolder+s3, fmCreate or fmOpenWrite or fmShareDenyWrite);
try
Cipher.DecryptStream(FileStream1, FileStream2, ItemSize);
finally FileStream2.Free end;
Expand Down

0 comments on commit ea60bc8

Please sign in to comment.