Howto Decode fafreplay body?

Need help? This is the right place!
Note, reporting bugs and issues should be in the Tech Support forum!

Moderator: PhilipJFry

Howto Decode fafreplay body?

Postby MikZZ » 03 Mar 2019, 22:15

Hello guys.
I need help.
Cant understand how to uncompress body of fafreplay.

Here is example of PHP code.

Code: Select all
$parse_str = file("111111.fafreplay", FILE_IGNORE_NEW_LINES);
$body= $parse_str[1];
$body_d= base64_decode($body);
$uncompressed = gzuncompress ($body_d);

But Im getting error: " gzuncompress(): data error"
I have no idea wahts going wrong.
Plese help.
MikZZ
Avatar-of-War
 
Posts: 67
Joined: 10 Jul 2017, 16:07
Has liked: 13 times
Been liked: 17 times
FAF User Name: MikZuperztar

Re: Howto Decode fafreplay body?

Postby MikZZ » 04 Mar 2019, 22:32

PHP script file charset is UTF-8. Same as fafreplay file.
If somebody can help me I will be glad.

As I know the basic thing is:
first decode string by base64
second decompress by zlib


I did that but has no luck.
MikZZ
Avatar-of-War
 
Posts: 67
Joined: 10 Jul 2017, 16:07
Has liked: 13 times
Been liked: 17 times
FAF User Name: MikZuperztar

Re: Howto Decode fafreplay body?

Postby MikZZ » 05 Mar 2019, 00:10

If somebody will get same error I found solution.
This is for PHP.

Well, that block of C# code adds a 4-byte length to the beginning of the gzip-encoded data, which by definition includes a header and a CRC/length trailer. So of course the PHP functions won't recognize it. Cut out all of that BlockCopy crap.

Not tested, but maybe something like this:

https://www.neowin.net/forum/topic/9941 ... ring-gzip/

So code now is:
Code: Select all
$parse_str = file("111111.fafreplay", FILE_IGNORE_NEW_LINES);
$body= $parse_str[1];
$body_d= base64_decode($body);
$uncompressed = gzuncompress (substr($body_d,4));
MikZZ
Avatar-of-War
 
Posts: 67
Joined: 10 Jul 2017, 16:07
Has liked: 13 times
Been liked: 17 times
FAF User Name: MikZuperztar

Re: Howto Decode fafreplay body?

Postby Uveso » 05 Mar 2019, 03:34

Nice one.

Thank's for sharing this!
User avatar
Uveso
Supreme Commander
 
Posts: 1788
Joined: 11 Dec 2015, 20:56
Location: Germany
Has liked: 70 times
Been liked: 291 times
FAF User Name: Uveso

Re: Howto Decode fafreplay body?

Postby relent0r » 04 Sep 2019, 06:40

Bit of a necro but given that this post helped me heaps, for future strugglers.
Python equivalent (probably not a smartest way but still)

Code: Select all
import base64
import zlib

replay = 'C:\\ProgramData\\FAForever\\replays\\10123254-relentless.fafreplay'
f = open(replay,'r')
lines = f.readlines()[1:]
data = base64.b64decode(lines[0])
result = zlib.decompress(data[4:])
f.close()
relent0r
Avatar-of-War
 
Posts: 64
Joined: 30 Dec 2018, 23:22
Has liked: 1 time
Been liked: 6 times
FAF User Name: relentless


Return to Help

Who is online

Users browsing this forum: No registered users and 1 guest