The Evil Within 2 .ptr .pkr

Extraction and unpacking of game archives and compression, encryption, obfuscation, decoding of unknown files
stevenking10
Posts: 13
Joined: Fri Mar 18, 2016 3:32 pm

Re: The Evil Within 2 .ptr .pkr

Post by stevenking10 »

repack ?
Oblivion
Posts: 4
Joined: Sat Oct 14, 2017 11:08 am

Re: The Evil Within 2 .ptr .pkr

Post by Oblivion »

Any progress with repack? thx
shadow_lonely
Posts: 216
Joined: Mon Oct 06, 2014 3:30 am

Re: The Evil Within 2 .ptr .pkr

Post by shadow_lonely »

Anyone can explain more about structures's files for write a program can unpack and repack. Thanks.
Delutto
Posts: 561
Joined: Tue Oct 13, 2015 1:26 pm

Re: The Evil Winhin 2 .ptr .pkr

Post by Delutto »

aluigi wrote:I guess it's caused by the weird deflate
Sorry to bother you with this subject again but I don't think that problem is with deflate, because I made a test: repacking only the PTR file and keeping the original PKR file, the game works normally.
I think that unknown 8 bytes from PTR are some checksum of the PKR file.
If you have some time and desire, please check this again.
Game executable and file sample: http://www.mediafire.com/file/aytstj7a7sjmboi/The_Evil_Within_2.7z/file
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: The Evil Within 2 .ptr .pkr

Post by aluigi »

Eh I don't think I'm going to return on this mainly because there is nothing else to do from my side (reimport mode can't calculate crc in any case).
If that 64bit field at offset 8 after VER "may" be a crc (2 32 or a 64) of pkr, then the game should refuse to load it even if you change of the bytes from offset 4 to 0xf of pkr.
GHOST DEAD
Posts: 218
Joined: Wed Jul 19, 2017 5:04 am

Re: The Evil Within 2 .ptr .pkr

Post by GHOST DEAD »

i edited sounds and mesh files with this script, but i found two english localization file in two dfferent side, where is the main text?
GHOST DEAD
Posts: 218
Joined: Wed Jul 19, 2017 5:04 am

Re: The Evil Within 2 .ptr .pkr

Post by GHOST DEAD »

i found something... this script has a problem and can not work on loc_.ptr files... for edit this files, we need to edit both .ptr and .pkr, but this script just can support on pkr in import, thats why game crashing in start...
GHOST DEAD
Posts: 218
Joined: Wed Jul 19, 2017 5:04 am

Re: The Evil Within 2 .ptr .pkr

Post by GHOST DEAD »

PTR just has Name Files,
the_evil_within_2.bms Can Extract all Files successfully in PKR, but Cant import file's
Because This script change the compression type in Reimport mode and game can't read this Compression type in Reimported file with this QuivkBMS script

this is not deflate, actually it's Zlib, and This is not like other compression method

For Example:
if i extract a PKR and Reimport Again Without any edit or Change in File's, and when i Compare this reimported file with original file In Hex-Editor, this two file must be same data, but its not same data, because QuickBMS change This Compression Type in Reimport and game can't read This Compression Type (That is Why Game Will Crash In Start)
Problem is Compression Type and We Must Find Right Compression type
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: The Evil Within 2 .ptr .pkr

Post by aluigi »

It's not zlib (2-bytes header + deflate + crc), it's just raw deflate (not even deflatex, just deflate).
If it was zlib first of all you would have found results with offzip (-z 15) and then OFFSET points exactly to the beginning of the compressed stream (if it was zlib then deflate would have worked from OFFSET + 2).
Recompressed data doesn't have the same bytes even if you don't change it because the implementations, settings and versions of the compression algorithms are ever different.
Files reimported and reextracted are identical in case that's what you meant (tested with loc_01.pkr/ptr).

From my side I have really nothing else to add, the work I did is complete and the script correctly extract all the files, so I hope you understand if I start to ignore this topic for not wasting other time on it.
GHOST DEAD
Posts: 218
Joined: Wed Jul 19, 2017 5:04 am

Re: The Evil Within 2 .ptr .pkr

Post by GHOST DEAD »

aluigi... finally i found it...

quickbms using ( inflate version:1.2.11)
but this game using inflate version: 1.2.3

you nust update your quickBMS.exe, becuasu we need to inflate_noerror to repack
i tested in game and works fine with inflate_noerror
InKviZ
Posts: 124
Joined: Fri Oct 24, 2014 2:55 pm

Re: The Evil Within 2 .ptr .pkr

Post by InKviZ »

*.PTR
Code:
UINT32 - XORed by 0xFADC4688 decompressed PTR size
UINT32 - version
UINT32 - splited to 4 parts and XORed first 32768 bytes (32 KB) PKR MD5
UINT32 - splited to 4 parts and XORed decompressed PTR MD5


You should compress PTR file. It's work fine with C# DeflateStream. And you don't need compress PKR data.
GHOST DEAD
Posts: 218
Joined: Wed Jul 19, 2017 5:04 am

Re: The Evil Within 2 .ptr .pkr

Post by GHOST DEAD »

Final information

ptr: it's just name files and hash table
pkr: main Data and base files,

first of first, its a deflate compression (1998 - 2005 v1.2.3)
for extract file: quickBMS can support deflate and we must ust deflate_noerror cause this is a noerror mode and The_Evil_Within_2.bms can extract this file verry well (with right algoritm)...

for repack: as i know, we have a flate... so, in two mode with de&in (de[b]flate_noerror and in[/b]flate_noerror), quickBMS can support deflate with noerror... but quikBMS can't support inflate with noerror
end of word: We need inflate_noerror for import files in .pkr
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: The Evil Within 2 .ptr .pkr

Post by aluigi »

I would like to clarify something about the "_noerror" in "deflate_noerror".

In the script deflate_noerror is used for the following 2 reasons:
- the first time because the decompressed size of the TOC wasn't known (InKviZ is right about the xor but it's not necessary for the decompression, maybe other games will change the xor)
- the second time because there is probably a missing terminator bit in the compressed files or something similar and so the zlib library (and any other library) will return an error

Now "deflate_noerror" is EXACTLY THE SAME of "deflate", same algorithm and same code, with the following improvements:
- it doesn't care about the decompressed size because it will continue to decompress the input data and increase the output buffer until zlib says that there is stuff to decompress (just like comtype unzip_dynamic)
- if the algorithm returns an error, deflate_noerror will return the data decompressed till that moment instead of breaking the extraction and returning an error. for some types of errors it may return the original compressed data

Therefore DOES NOT EXISTS an inflate_noerror because deflate and deflate_noerror are the same.

Just in case you are asking what is comtype unzip_dynamic, well it's a zlib_noerror that switches to deflate_noerror in case of errors and switches to no compression if that fails too.

I know, it's technical stuff that people usually can't know, but I'm happy to provide these info if something is not clear.

Basically what you would need in this case, if you are 100% sure that it's not something related to a checksum/hash used in the archive that avoid the files to be loaded, would be to know what's the small customization that the game uses in its deflate implementation but even in that case after all the work are you going to write a rebuilder with a custom zlib from scratch?
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: The Evil Within 2 .ptr .pkr

Post by aluigi »

And yes I confirm that indeed is the "bfinal" bit which is never set to 1 like instead it should be.
You are going crazy if you check the zlib source code while with tinflate.c it's very simple:

Code: Select all

   do {
      ...
      /* read final block flag */
      bfinal = tinf_getbit(&d);
      ...
   } while (!bfinal);
InKviZ
Posts: 124
Joined: Fri Oct 24, 2014 2:55 pm

Re: The Evil Within 2 .ptr .pkr

Post by InKviZ »

common.ptr and common.pkr as example.
On the first image we skip header (0x10 bytes), select next 0x8000 bytes and calculate MD5 and get AAA643D74BB3433E09F662006A05EDB8

Image

Then (img2) we split this hash to 4 parts and XOR it.
Code:
0xAAA643D7 ^ 0x4BB3433E ^ 0x09F66200 ^ 0x6A05EDB8 = 0x82E68F51

Image

As i promise Zotya0330. I'll share tool source when return to home, monday-tuesday.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: The Evil Within 2 .ptr .pkr

Post by aluigi »

@InKviZ
That's the TOC while users are interested in importing the files.
The topic is already confusing by itself, let's try to stay focused on one matter at time :)
Delutto
Posts: 561
Joined: Tue Oct 13, 2015 1:26 pm

Re: The Evil Within 2 .ptr .pkr

Post by Delutto »

The Evil Within 2 PKR Tool
By Delutto
See Readme.txt for instructions.
The_Evil_Within_2_PKR_Tool_By_Delutto.7z
Notes:
- Based on aluigi research: http://aluigi.org/bms/the_evil_within_2.bms and file verification research by ripper: http://forum.xentax.com/viewtopic.php?f=35&p=141001.

Updates:

Code: Select all

07/08/2018
  - Add support to BIMAGE files.(Experimental)

06/08/2018
  - Add support for PS4 files.(Experimental)
  - Text bugfix.

06/03/2018
  - Add support to Import Mode, thanks ripper: http://forum.xentax.com/viewtopic.php?f=35&t=17407
  - Automatic convertion of LANB files (localizations files).

Image
Last edited by Delutto on Thu Jul 12, 2018 3:28 am, edited 4 times in total.
shadow_lonely
Posts: 216
Joined: Mon Oct 06, 2014 3:30 am

Re: The Evil Within 2 .ptr .pkr

Post by shadow_lonely »

Delutto wrote:The Evil Within 2 PKR Tool
By Delutto
See Readme.txt for instructions.The_Evil_Within_2_PKR_Tool_By_Delutto.7z
Notes:
- Based on aluigi research: http://aluigi.org/bms/the_evil_within_2.bms and file verification research by ripper: http://forum.xentax.com/viewtopic.php?f=35&p=141001.
- Moding p1_loc_01.pkr/ptr, I could see that the game stop of recognize the unicode fonts. I don't know why, could be a problem related to uncompressed files, or something related to game patch system or a problem in my import algo. I'm working on that.
Anyway, ripper will release a tool.

Image

Thanks! You're my hero. Hope that tool will support PS4 file in the furture. I tested it with PS4 file: https://1drv.ms/u/s!AqHXyzDaH_sGiUoSOw9It4jZpiX6
PC files working flamless. Thank you very much.
Delutto
Posts: 561
Joined: Tue Oct 13, 2015 1:26 pm

Re: The Evil Within 2 .ptr .pkr

Post by Delutto »

shadow_lonely wrote:Hope that tool will support PS4 file in the furture. I tested it with PS4 file: https://1drv.ms/u/s!AqHXyzDaH_sGiUoSOw9It4jZpiX6.
Try this mod file and let me know what happen.
PS4_loc_01.7z
GHOST DEAD
Posts: 218
Joined: Wed Jul 19, 2017 5:04 am

Re: The Evil Within 2 .ptr .pkr

Post by GHOST DEAD »

thanks... But Text's are UTF-8 in .lanb, but tool Export/Import text in ANSI... Can you fix that?
your jobs is Great and thank to you for all of this :)