Skip to content

Commit

Permalink
Merge pull request #135 from nicoboss/removal-of-string-table-padding
Browse files Browse the repository at this point in the history
Removal of stringTable padding
  • Loading branch information
nicoboss authored Jul 29, 2023
2 parents db64a96 + fd3d03e commit 2831172
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 11 deletions.
5 changes: 1 addition & 4 deletions nsz/Fs/Hfs0.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,11 @@ def getHeader(self):
stringTable = '\x00'.join(file['name'] for file in self.files)

headerSize = 0x10 + len(self.files) * 0x40 + len(stringTable)
remainder = 0x10 - headerSize % 0x10
headerSize += remainder

h = b''
h += b'HFS0'
h += len(self.files).to_bytes(4, byteorder='little')
h += (len(stringTable)+remainder).to_bytes(4, byteorder='little')
h += (len(stringTable)).to_bytes(4, byteorder='little')
h += b'\x00\x00\x00\x00'

stringOffset = 0
Expand All @@ -92,7 +90,6 @@ def getHeader(self):
stringOffset += len(f['name']) + 1

h += stringTable.encode()
h += remainder * b'\x00'

return h

Expand Down
4 changes: 1 addition & 3 deletions nsz/Fs/Nsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,6 @@ def generateHeader(self, files):
filesNb = len(files)
stringTable = '\x00'.join(os.path.basename(file) for file in files)
headerSize = 0x10 + (filesNb)*0x18 + len(stringTable)
remainder = 0x10 - headerSize%0x10
headerSize += remainder

fileSizes = [os.path.getsize(file) for file in files]
fileOffsets = [sum(fileSizes[:n]) for n in range(filesNb)]
Expand All @@ -419,7 +417,7 @@ def generateHeader(self, files):
header = b''
header += b'PFS0'
header += pk('<I', filesNb)
header += pk('<I', len(stringTable)+remainder)
header += pk('<I', len(stringTable))
header += b'\x00\x00\x00\x00'
for n in range(filesNb):
header += pk('<Q', fileOffsets[n])
Expand Down
5 changes: 1 addition & 4 deletions nsz/Fs/Pfs0.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,11 @@ def getFirstFileOffset(self):
def getHeader(self):
stringTable = '\x00'.join(file['name'] for file in self.files)
headerSize = 0x10 + len(self.files) * 0x18 + len(stringTable)
remainder = 0x10 - headerSize % 0x10
headerSize += remainder

h = b''
h += b'PFS0'
h += len(self.files).to_bytes(4, byteorder='little')
h += (len(stringTable)+remainder).to_bytes(4, byteorder='little')
h += (len(stringTable)).to_bytes(4, byteorder='little')
h += b'\x00\x00\x00\x00'

stringOffset = 0
Expand All @@ -95,7 +93,6 @@ def getHeader(self):
stringOffset += len(f['name']) + 1

h += stringTable.encode()
h += remainder * b'\x00'

return h

Expand Down

0 comments on commit 2831172

Please sign in to comment.