I have an old PC game called Air Strike 3D II. I wanted to extract music files but I couldn't figure out how to unpack the .apk file (NOT Android package). 7-zip can't open it. When I open the .apk file with IDA, it says (Unknown COFF machine) and it failed to disassemble it so it's not an assembly file.

The headers always start with 0000803F 99990000. There is a folder named sounds and it contains .wav files, sounds/biglaser.wav, sounds/laser.wav etc... recovering files with WinHex does not help because it is packed and compressed.

I found a log file that says

---- Initializing file system ----

pak1.apk - 733 files
pak2.apk - 45 files
pak4.apk - 1 files
F_Init: 
3 data files found.

I tried to disassemble the .exe file with IDA, but there is nothing useful because it is encrypted or obfuscated.

Google doesn't give me solutions because it returns Android related results. I wish it could show results from 2008 and older.

Here are the files if you want to take a look: https://drive.google.com/open?id=0B_6TXpxCnMc7TGVfOWlYWjVYXzQ

up vote 2 down vote accepted

Update: I've done a write up on the entire file format here: http://www.tkte.ch/2017/02/27/air-strike-3d.html

These files aren't compressed, so don't worry about that. Since all you want to do is extract those waves we can cheat (a lot) and ignore everything else. Lets do a naive check:

> strings -n 4 pak2.apk | grep RIFF -c
40

> strings -n 4 pak2.apk | grep WAVEfmt -c
40

Well that's promising. Looks like we've got a bunch of WAVs encapsulated by RIFFs which is pretty common.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import struct

RIFF_MAGIC = b'RIFF'
RIFF_LENGTH = struct.Struct('<I')


def main():
    in_file = sys.argv[1]

    # Since the files are tiny lets cheat again and just read the entire thing.
    with open(in_file, 'rb') as fin:
        in_file = fin.read()

    offset = 0
    count = 0

    # We're going to skim through the file looking for the start of a RIFF file.
    while True:
        start = in_file.find(RIFF_MAGIC, offset)
        if start == -1:
            # None left, so we're done with this .apk.
            print('Extracted {0} files.'.format(count))
            return

        # Found one, so lets read the next 4 bytes which are the length of the RIFF file.
        length = RIFF_LENGTH.unpack_from(in_file, start + 4)[0]
        # The 8 comes from the 4 bytes for RIFF and the 4 bytes for the length
        # itself, which aren't included in the length.
        offset = start + 8 + length

        # annnnd save it.
        with open('wav_{0}.wav'.format(count), 'wb') as fout:
            fout.write(in_file[start:offset])

        count += 1

if __name__ == '__main__':
    sys.exit(main())

And give it a whirl...

> python extract.py pak2.apk
Extracted 40 files.

Open one of the WAV's in VLC and woohoo, sounds.

  • Thanks for the python script. Tested it and it worked but how about the music files? – byday Mar 1 '17 at 17:37
  • @prouser135 I've done a writeup on the entire file format here: tkte.ch/2017/02/27/air-strike-3d.html. If you like the answer, please mark it as accepted :) – TkTech Mar 1 '17 at 21:07
  • I'm pretty new to Python but i accepted it anyway – byday Mar 3 '17 at 15:47

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.