Skip to content

Instantly share code, notes, and snippets.

@RandomInsano
Created July 26, 2015 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RandomInsano/1b3012b43a9eccaabb35 to your computer and use it in GitHub Desktop.
Save RandomInsano/1b3012b43a9eccaabb35 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
'''
Tool to read game media type header information from the original
XBOX's xbe executables.
In retrospect, it would have been much less fiddly to write this in C/C++
Info taken from here:
http://www.caustik.com/cxbx/download/xbe.htm
'''
import argparse
import struct
import codecs
import sys
import os
CERT_LOCATION = 0x0118
BASE_LOCATION = 0x0104
CERT_TITLE_LOCATION = 0x000C
CERT_TITLE_SIZE = 0x0050
CERT_MEDIA_LOCATION = 0x009c
CERT_MEDIA_FLAGS = {
'hd': 0x00000001,
'dvd_x2': 0x00000002,
'dvd_cd': 0x00000004,
'cd': 0x00000008,
'dvd_5_ro': 0x00000010,
'dvd_9_ro': 0x00000020,
'dvd_5_rw': 0x00000040,
'dvd_9_rw': 0x00000080,
'dongle': 0x00000100,
'media_board': 0x00000200,
'hd_insecure': 0x40000000,
'insecure': 0x80000000,
}
def main():
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
parser = argparse.ArgumentParser("XBOX file info dumper")
parser.add_argument('filename', metavar='file',
help='Executable to read.', default='default.xbe')
args = parser.parse_args()
if not os.path.isfile(args.filename):
print("Couldn't find '{0}'.".format(args.filename))
exit(1)
with file(args.filename, 'rb') as f:
header_read(f)
def header_read(f):
f.seek(CERT_LOCATION)
media_offset, = struct.unpack('i', f.read(4))
f.seek(BASE_LOCATION)
base_offset, = struct.unpack('i', f.read(4))
cert_offset = media_offset - base_offset
title = title_read(f, cert_offset)
o = u"Reading header for '{0}':".format(title)
print(o)
media_types = media_read(f, cert_offset)
print(" Media Flags: {0}".format(', '.join(media_types)))
def title_read(f, cert_offset):
f.seek(cert_offset + CERT_TITLE_LOCATION)
data = f.read(CERT_TITLE_SIZE)
text = "unknown"
try:
text = data.decode("UTF-16LE").rstrip('\0')
except:
pass
return text
def media_read(f, cert_offset):
f.seek(cert_offset + CERT_MEDIA_LOCATION)
data = bytearray(f.read(4))
field = struct.unpack('i', f.read(4))[0]
items = []
for k, v in CERT_MEDIA_FLAGS.items():
if (v & field != 0):
items.append(k)
return items
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment