Last active
November 18, 2016 23:19
-
-
Save TheReturningVoid/32e25a3136be442cc23b3d7273de28bf to your computer and use it in GitHub Desktop.
Python script to create and break apart CTR service command headers
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
#!/bin/env python3 | |
from sys import argv, exit | |
comamndId = 0 | |
normalParams = 0 | |
translateParams = 0 | |
headerCode = 0 | |
if len(argv) == 1: | |
print("""cmdHeader.py v1.0 | |
2016 TheReturningVoid | |
===================== | |
Usage: | |
cmdHeader.py [headerCode] | |
OR | |
cmdHeader.py [commandId] [normalParameters] [translateParameters]""") | |
exit(0) | |
elif len(argv) == 2: | |
commandId = int(argv[1], 16) >> 16 | |
normalParams = (int(argv[1], 16) >> 6) & 31 | |
translateParams = int(argv[1], 16) & 31 | |
headerCode = int(argv[1], 16) | |
elif len(argv) == 4: | |
commandId = int(argv[1], 16) | |
normalParams = int(argv[2], 16) | |
translateParams = int(argv[3], 16) | |
headerCode = (commandId << 16) | ((normalParams & 0x3F) << 6) | (translateParams & 0x3F) | |
else: | |
raise ValueError("Invalid amount of parameters specified!") | |
print("Header code: 0x%s" % hex(headerCode)[2:].upper()) | |
print("Command ID: 0x%s" % hex(commandId)[2:].upper()) | |
print("Amount of normal parameters: 0x%s" % hex(normalParams)[2:].upper()) | |
print("Amount of translateParameters: 0x%s" % hex(translateParams)[2:].upper()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment