Skip to content

Commit 7019530

Browse files
author
Fayvel Victor
committed
Compare binary ROM data using binary datatype without string conversion
1 parent 6255821 commit 7019530

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/m64py/archive.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import shutil
2222
import tempfile
2323
from subprocess import Popen, PIPE
24+
import binascii
2425

2526
from m64py.utils import which
2627

@@ -47,9 +48,9 @@
4748
if HAS_7Z or LZMA_CMD: EXT_FILTER += " *.7z"
4849

4950
ROM_TYPE = {
50-
'80371240': 'z64 (native)',
51-
'37804012': 'v64 (byteswapped)',
52-
'40123780': 'n64 (wordswapped)'
51+
b'80371240': 'z64 (native)',
52+
b'37804012': 'v64 (byteswapped)',
53+
b'40123780': 'n64 (wordswapped)'
5354
}
5455

5556

@@ -153,17 +154,17 @@ def get_filetype(self):
153154
fd = open(self.file, "rb")
154155
magic = fd.read(4)
155156
fd.close()
156-
if magic == 'PK\03\04':
157+
if magic == b'PK\03\04':
157158
return ZIP
158-
elif magic.startswith('\037\213'):
159+
elif magic.startswith(b'\037\213'):
159160
return GZIP
160-
elif magic.startswith('BZh'):
161+
elif magic.startswith(b'BZh'):
161162
return BZIP
162-
elif magic == 'Rar!':
163+
elif magic == b'Rar!':
163164
return RAR
164-
elif magic == '7z\xbc\xaf':
165+
elif magic == b'7z\xbc\xaf':
165166
return LZMA
166-
elif magic.encode('hex') in ROM_TYPE.keys():
167+
elif binascii.hexlify(magic) in ROM_TYPE.keys():
167168
return ROM
168169
return None
169170

src/m64py/core/core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import signal
2020
import ctypes as C
2121
import subprocess
22+
import binascii
2223

2324
from m64py.core.defs import *
2425
from m64py.core.config import Config
@@ -295,7 +296,7 @@ def detach_plugins(self):
295296
def rom_open(self, romfile):
296297
"""Reads in a binary ROM image"""
297298
self.rom_length = len(romfile)
298-
self.rom_type = ROM_TYPE[romfile[:4].encode('hex')]
299+
self.rom_type = ROM_TYPE[binascii.hexlify(romfile[:4])]
299300
romlength = C.c_int(self.rom_length)
300301
rombuffer = C.c_buffer(romfile)
301302
rval = self.m64p.CoreDoCommand(

0 commit comments

Comments
 (0)