Created
October 6, 2019 09:57
-
-
Save garoxas/012111ee0860dc68496603eb566dda55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
import struct | |
import sys | |
from datetime import datetime | |
# https://github.com/switchbrew/libnx/blob/master/nx/include/switch/services/pdm.h#L78 | |
with open('PlayEvent.dat', 'rb') as fin: | |
magic = struct.unpack('i', fin.read(4))[0] | |
if magic != 0: | |
print('Not a valid PlayEvent file', file=sys.stderr) | |
sys.exit(1) | |
number_of_entry = struct.unpack('I', fin.read(4))[0] | |
for i in range(0, number_of_entry): | |
event_data = fin.read(0x1c) | |
event_type = struct.unpack('B', fin.read(1))[0] | |
fin.read(3) # padding | |
timestamp_user = struct.unpack('Q', fin.read(8))[0] | |
timestamp_network = struct.unpack('Q', fin.read(8))[0] | |
timestamp_steady = struct.unpack('Q', fin.read(8))[0] | |
if event_type == 0: | |
title_id = [] | |
title_id.append(struct.unpack('I', event_data[0x0:0x4])[0]) | |
title_id.append(struct.unpack('I', event_data[0x4:0x8])[0]) | |
applet_id = event_data[0xc] | |
storage_id = event_data[0xd] | |
log_policy = event_data[0xe] | |
event_type = event_data[0xf] | |
version = None | |
if applet_id == 1: | |
version = struct.unpack('I', event_data[0x8:0xC])[0] | |
print('%08x %d %s %08x%08x %s %d %d %d %d' % (fin.tell() - 0x38, event_type, datetime.fromtimestamp(timestamp_user), title_id[0], title_id[1], str(version) if version is not None else '', applet_id, storage_id, log_policy, event_type)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment