Example #1
0
class ResidentScan:
    def __init__(self, rom_data, base_addr=0):
        self.access = RomAccess(rom_data)
        self.base_addr = base_addr

    def get_all_matchwords(self):
        """scan memory for all occurrences of matchwords"""
        mw = "\x4a\xfc"
        res = []
        off = 0
        num = self.access.size
        rom = self.access.rom_data
        while off < num:
            pos = rom.find(mw, off)
            if pos == -1:
                break
            res.append(pos)
            off = pos + 2
        return res

    def guess_base_addr(self):
        offs = self.get_all_matchwords()
        if len(offs) == 0:
            return None
        base_map = {}
        for off in offs:
            tag_ptr = self.access.read_long(off + 2)
            tag_off = tag_ptr & 0xffff
            if tag_off == off:
                base_addr = tag_ptr & ~0xffff
                if base_addr not in base_map:
                    base_map[base_addr] = 1
                else:
                    base_map[base_addr] += 1
        # one match
        if len(base_map) == 1:
            addr = base_map.keys()[0]
            return addr
        else:
            return sorted(base_map.keys(), key=lambda x: base_map[x])

    def get_all_resident_pos(self):
        offs = self.get_all_matchwords()
        res = []
        for off in offs:
            # check tag ptr
            tag_ptr = self.access.read_long(off + 2)
            if tag_ptr == self.base_addr + off:
                res.append(off)
        return res

    def is_resident_at(self, off):
        mw = self.access.read_word(off)
        if mw != RTC_MATCHWORD:
            return False
        tag_ptr = self.access.read_long(off + 2)
        return tag_ptr == self.base_addr + off

    def get_resident(self, off):
        return Resident.parse(self.access, off, self.base_addr)
Example #2
0
class RomPatcher:
    def __init__(self, rom):
        self.access = RomAccess(rom)
        self.access.make_writable()

    def get_all_patch_names(self):
        res = []
        for p in self.patches:
            res.append(p.name)
        return res

    def find_patch(self, name):
        for p in patches:
            if p.name == name:
                return p

    def apply_patch(self, patch, args=None):
        return patch.apply_patch(self.access, args)

    def get_patched_rom(self):
        return self.access.get_data()
Example #3
0
class RomPatcher:
  def __init__(self, rom):
    self.access = RomAccess(rom)
    self.access.make_writable()

  def get_all_patch_names(self):
    res = []
    for p in self.patches:
      res.append(p.name)
    return res

  def find_patch(self, name):
    for p in patches:
      if p.name == name:
        return p

  def apply_patch(self, patch):
    return patch.apply_patch(self.access)

  def get_patched_rom(self):
    return self.access.get_data()
Example #4
0
 def __init__(self, rom_data):
     RomAccess.__init__(self, rom_data)
 def __init__(self, rom_data, base_addr=0):
   self.access = RomAccess(rom_data)
   self.base_addr = base_addr
class ResidentScan:

  def __init__(self, rom_data, base_addr=0):
    self.access = RomAccess(rom_data)
    self.base_addr = base_addr

  def get_all_matchwords(self):
    """scan memory for all occurrences of matchwords"""
    mw = "\x4a\xfc"
    res = []
    off = 0
    num = self.access.size
    rom = self.access.rom_data
    while off < num:
      pos = rom.find(mw, off)
      if pos == -1:
        break
      res.append(pos)
      off = pos + 2
    return res

  def guess_base_addr(self):
    offs = self.get_all_matchwords()
    if len(offs) == 0:
      return None
    base_map = {}
    for off in offs:
      tag_ptr = self.access.read_long(off+2)
      tag_off = tag_ptr & 0xffff
      if tag_off == off:
        base_addr = tag_ptr & ~0xffff
        if base_addr not in base_map:
          base_map[base_addr] = 1
        else:
          base_map[base_addr] += 1
    # one match
    if len(base_map) == 1:
      addr = base_map.keys()[0]
      return addr
    else:
      return sorted(base_map.keys(), key=lambda x:base_map[x])

  def get_all_resident_pos(self):
    offs = self.get_all_matchwords()
    res = []
    for off in offs:
      # check tag ptr
      tag_ptr = self.access.read_long(off+2)
      if tag_ptr == self.base_addr + off:
        res.append(off)
    return res

  def is_resident_at(self, off):
    mw = self.access.read_word(off)
    if mw != RTC_MATCHWORD:
      return False
    tag_ptr = self.access.read_long(off+2)
    return tag_ptr == self.base_addr + off

  def get_resident(self, off):
    return Resident.parse(self.access, off, self.base_addr)
Example #7
0
 def __init__(self, rom_data, base_addr=0):
     self.access = RomAccess(rom_data)
     self.base_addr = base_addr
Example #8
0
 def __init__(self, rom_data):
   RomAccess.__init__(self, rom_data)
Example #9
0
 def __init__(self, rom):
     self.access = RomAccess(rom)
     self.access.make_writable()
Example #10
0
 def __init__(self, rom):
   self.access = RomAccess(rom)
   self.access.make_writable()