Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Svensson committed Apr 18, 2022
0 parents commit c231241
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
KTX Stats Extractor
-------------------

Extract embedded JSON statistics to `somedemo.json`:

```
./ktx-stats.py somedemo.mvd
```

For more details see `stats.c` in the [KTX repository](https://github.com/QW-Group/ktx).
30 changes: 30 additions & 0 deletions ktx-stats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python
import struct
import json
import sys
import os

with open(sys.argv[1], "rb") as fd:
data = fd.read()

offset = data.rfind(b"\x0a\x00\x00\x03\x00\x00\x00\x00")
offset += 2

content = b""

while data[offset:offset + 4] == b"\x00\x03\x00\x00":
(length,) = struct.unpack("<H", data[offset+10:offset+12])
start = offset + 18
end = start + length - 2
content += data[start:end]
offset = end

try:
json.loads(content)
print("success", sys.argv[1])
(name, _) = os.path.splitext(sys.argv[1])

with open(name + ".json", "wb+") as fd:
fd.write(content)
except:
print("failed to load", sys.argv[1])

0 comments on commit c231241

Please sign in to comment.