blob: 4fa40176491401e35228f1d047d62ac384a56c67 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# padding stuff
# padding string
class padding:
# the fill string
def __init__(self):
self.string = "This is padding data to alignme"
# return the padding string to align data at a
# given start_index with a specific byte_alignment
def string_fill(self, byte_alignment, start_index):
# check the variables first
if ((type(start_index) != int)
or (type(byte_alignment) != int)
or (start_index < 0)
or (byte_alignment != 4 and byte_alignment != 32)):
return None
# return the fill string
i = 0
rtn = ""
while (start_index % byte_alignment != 0):
rtn += self.string[i]
i += 1
start_index += 1
return bytes(rtn.encode("ascii"))
# name tables
# read name tables found in SMG binary files
# ~ # structure raw
# ~ class smg_name_table_raw:
# ~ # functions
# ~ def __init__(self):
# ~ self.name_count = None
# ~ self.unknown1 = None
# ~ self.name_info = [] # of name_count length
# ~ self.names = [] # of name_count length
# ~ def __str__(self):
# ~ rtn = "Name count: %s\n" % (self.name_count)
# ~ rtn += "Unknown 1: %04X\n" % (self.unknown1)
# ~ rtn += "Names information:\n"
# ~ for i in range(self.name_count):
# ~ rtn += " Name %d:\n" % (i)
# ~ rtn += self.name_info[i].__str__()
# ~ rtn += "Names:\n"
# ~ for i in range(self.name_count):
# ~ rtn += " Index %d -> %s\n" % (i, names[i])
# ~ return rtn
# ~ # information about the names
# ~ class smg_name_info:
# ~ # functions
# ~ def __init__(self):
# ~ self.hash = None
# ~ self.offset = None
# ~ def __str__(self):
# ~ rtn = " Hash: %04X\n" % (self.hash)
# ~ rtn += " Offset: %s\n" % (self.offset)
# ~ return rtn
# ~ # actual structure to use
# ~ class smg_name_table_info:
# ~ # functions
# ~ def __init__(self):
# ~ self.name_count = None
# ~ self.names = [] # of length name_count
# ~ def __init__(self):
# ~ rtn = "Name count: %s\n" % (self.name_count)
# ~ rtn += "Names:\n"
# ~ for i in range(self.name_count):
# ~ rtn += " Index %d -> %s\n" % (names[i])
# ~ return rtn
# ~ # create a global variable to hold temporal information
# ~ name_table_raw_info = None
# ~ name_table_error_str = "name_table-error: "
# ~ f = None
# ~ # main function
# ~ # will read and will check while reading
# ~ def read_name_table(byte_array):
# ~ # make global variables editable
# ~ global f
# ~ global name_table_raw_info
# ~ # "pre read" the file
# ~ result_str = pre_read_name_table(byte_array)
# ~ print(result_str)
# ~ return None
# ~ # function to check an encoded name table before getting its full information out
# ~ def pre_read_name_table(byte_array):
# ~ return name_table_error_str + "all good"
|