Created
August 22, 2018 00:47
-
-
Save TellowKrinkle/88fb6a4c0e2132fba0185d631426f65f to your computer and use it in GitHub Desktop.
Correlates offsets with object IDs in unity asset files
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
import sys | |
import unitypack | |
from unitypack.asset import Asset | |
if len(sys.argv) < 3: | |
print("Usage: " + sys.argv[0] + " assetfile.assets (offset | offsetfile.txt)\nOffset file formatting: per line \"offset [printout name]\"") | |
exit() | |
try: | |
targetOffsets = [[int(sys.argv[2], 0), sys.argv[2]]] | |
except: | |
with open(sys.argv[2], "r") as offsetfile: | |
splitLines = ([word.strip() for word in line.split(" ", 1)] for line in offsetfile) | |
targetOffsets = [[int(pair[0], 0), pair[1]] if len(pair) == 2 else [int(pair[0], 0), pair[0]] for pair in splitLines] | |
with open(sys.argv[1], "rb") as assetfile: | |
assets = Asset.from_file(assetfile) | |
for id, obj in assets.objects.items(): | |
for pos, offsetInfo in enumerate(targetOffsets): | |
if obj.data_offset <= offsetInfo[0] and obj.data_offset + obj.size >= offsetInfo[0]: | |
targetOffsets[pos].append(id) | |
for offsetInfo in targetOffsets: | |
if len(offsetInfo) <= 2: | |
print(offsetInfo[1] + ": None found") | |
else: | |
print(offsetInfo[1] + ": " + ", ".join(str(x) for x in offsetInfo[2:])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment