# 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"