From 78a13604bfeba1798379d15d6e26f4b6c128bda1 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Mon, 26 Sep 2016 17:23:05 -0400 Subject: Fix NES plugin after API changes --- python/__init__.py | 4 +++- python/examples/nes.py | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) (limited to 'python') diff --git a/python/__init__.py b/python/__init__.py index 80302c0c..26c8fb5d 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -1022,7 +1022,7 @@ class BinaryView(object): self.file = file_metadata self.handle = core.BNCreateCustomBinaryView(self.__class__.name, file_metadata.handle, self._cb) self.notifications = {} - self.next_address = self.entry_point + self.next_address = None # Do NOT try to access view before init() is called, use placeholder @classmethod def register(cls): @@ -1579,6 +1579,8 @@ class BinaryView(object): """ if arch is None: arch = self.arch + if self.next_address is None: + self.next_address = self.entry_point txt, size = arch.get_instruction_text(self.read(self.next_address, self.arch.max_instr_length), self.next_address) self.next_address += size if txt is None: diff --git a/python/examples/nes.py b/python/examples/nes.py index 5cb6bc0d..00f9d8eb 100644 --- a/python/examples/nes.py +++ b/python/examples/nes.py @@ -521,9 +521,9 @@ class NESView(BinaryView): def __init__(self, data): BinaryView.__init__(self, data.file) - self.data = data + self.raw = data self.notification = NESViewUpdateNotification(self) - self.data.register_notification(self.notification) + self.raw.register_notification(self.notification) @classmethod def is_valid_for_data(self, data): @@ -539,7 +539,7 @@ class NESView(BinaryView): def init(self): try: - hdr = self.data.read(0, 16) + hdr = self.raw.read(0, 16) self.rom_banks = struct.unpack("B", hdr[4])[0] self.vrom_banks = struct.unpack("B", hdr[5])[0] self.rom_flags = struct.unpack("B", hdr[6])[0] @@ -592,9 +592,9 @@ class NESView(BinaryView): self.define_auto_symbol(Symbol(DataSymbol, 0x4016, "JOY1")) self.define_auto_symbol(Symbol(DataSymbol, 0x4017, "JOY2")) - sym_files = [self.data.file.filename + ".%x.nl" % self.__class__.bank, - self.data.file.filename + ".ram.nl", - self.data.file.filename + ".%x.nl" % (self.rom_banks - 1)] + sym_files = [self.raw.file.filename + ".%x.nl" % self.__class__.bank, + self.raw.file.filename + ".ram.nl", + self.raw.file.filename + ".%x.nl" % (self.rom_banks - 1)] for f in sym_files: if os.path.exists(f): sym_contents = open(f, "r").read() @@ -634,9 +634,9 @@ class NESView(BinaryView): else: to_read = length if addr < 0xc000: - data = self.data.read(self.rom_offset + bank_ofs + (self.__class__.bank * 0x4000), to_read) + data = self.raw.read(self.rom_offset + bank_ofs + (self.__class__.bank * 0x4000), to_read) else: - data = self.data.read(self.rom_offset + bank_ofs + self.rom_length - 0x4000, to_read) + data = self.raw.read(self.rom_offset + bank_ofs + self.rom_length - 0x4000, to_read) result += data if len(data) < to_read: break @@ -663,9 +663,9 @@ class NESView(BinaryView): else: to_write = length if addr < 0xc000: - written = self.data.write(self.rom_offset + bank_ofs + (self.__class__.bank * 0x4000), value[offset : offset + to_write]) + written = self.raw.write(self.rom_offset + bank_ofs + (self.__class__.bank * 0x4000), value[offset : offset + to_write]) else: - written = self.data.write(self.rom_offset + bank_ofs + self.rom_length - 0x4000, value[offset : offset + to_write]) + written = self.raw.write(self.rom_offset + bank_ofs + self.rom_length - 0x4000, value[offset : offset + to_write]) if written < to_write: break length -= to_write -- cgit v1.3.1