Пример #1
0
    def __init__(self, filename, raw_type, raw_base, raw_big_endian):
        Binary.__init__(self)

        self.raw = open(filename, "rb").read()
        self.raw_base = raw_base
        self.raw_big_endian = raw_big_endian

        arch_lookup = {
            "x86": "x86",
            "x64": "x64",
            "arm": "ARM",
            "mips": "MIPS32",
            "mips64": "MIPS64",
        }

        self.arch = arch_lookup.get(raw_type, None)

        self.add_section(
            raw_base,
            "raw",
            len(self.raw),
            len(self.raw),
            False, # is_exec
            True, # is_data
            self.raw)
Пример #2
0
    def __init__(self, filename, raw_type, raw_base, raw_big_endian):
        Binary.__init__(self)

        self.raw = open(filename, "rb").read()
        self.raw_base = raw_base
        self.raw_big_endian = raw_big_endian

        arch_lookup = {
            "x86": "x86",
            "x64": "x64",
            "arm": "ARM",
            "mips": "MIPS32",
            "mips64": "MIPS64",
        }

        self.arch = arch_lookup.get(raw_type, None)

        self.add_section(
            raw_base,
            "raw",
            len(self.raw),
            len(self.raw),
            False, # is_exec
            True, # is_data
            False, # is_bss
            self.raw)
Пример #3
0
    def __init__(self, db, filename):
        Binary.__init__(self)

        self.db = db

        self.pe = PE2(filename, fast_load=True)
        self.__data_sections = []
        self.__data_sections_content = []
        self.__exec_sections = []

        self.set_arch_name()

        base = self.pe.OPTIONAL_HEADER.ImageBase

        for s in self.pe.sections:
            start = base + s.VirtualAddress

            is_data = self.__section_is_data(s)
            is_exec = self.__section_is_exec(s)

            if is_data or is_exec:
                bisect.insort_left(self._sorted_sections, start)

            self._abs_sections[start] = SectionAbs(
                    s.Name.decode().rstrip(' \0'),
                    start,
                    s.Misc_VirtualSize,
                    s.SizeOfRawData,
                    is_exec,
                    is_data,
                    s.get_data())
Пример #4
0
    def __init__(self, db, filename):
        Binary.__init__(self)

        self.db = db

        self.pe = PE2(filename, fast_load=True)
        self.__data_sections = []
        self.__data_sections_content = []
        self.__exec_sections = []

        self.set_arch_name()

        base = self.pe.OPTIONAL_HEADER.ImageBase

        for s in self.pe.sections:
            name = s.Name.decode().rstrip(' \0')
            self.add_section(
                base + s.VirtualAddress,
                name,
                s.Misc_VirtualSize,
                s.SizeOfRawData,
                self.__section_is_exec(s),
                self.__section_is_data(s),
                name == ".bss",
                s.get_data())
Пример #5
0
    def __init__(self, db, filename):
        Binary.__init__(self)

        fd = open(filename, "rb")
        self.elf = ELFFile(fd)
        self.db = db

        self.__parsed_reloc_tables = set()
        self.dtags = {}
        self.jmprel = []
        self.dynamic_seg = None

        self.set_arch_name()

        if self.arch == "MIPS32":
            self.dynamic_tag_translation = {
                0x70000001: "DT_MIPS_RLD_VERSION",
                0x70000005: "DT_MIPS_FLAGS",
                0x70000006: "DT_MIPS_BASE_ADDRESS",
                0x7000000a: "DT_MIPS_LOCAL_GOTNO",
                0x70000011: "DT_MIPS_SYMTABNO",
                0x70000012: "DT_MIPS_UNREFEXTNO",
                0x70000013: "DT_MIPS_GOTSYM",
                0x70000016: "DT_MIPS_RLD_MAP",
                0x70000032: "DT_MIPS_PLTGOT"
            }
        elif self.arch == "MIPS64":
            self.dynamic_tag_translation = {
                0x70000001: "DT_MIPS_RLD_VERSION",
                0x70000005: "DT_MIPS_FLAGS",
                0x70000006: "DT_MIPS_BASE_ADDRESS",
                0x7000000a: "DT_MIPS_LOCAL_GOTNO",
                0x70000011: "DT_MIPS_SYMTABNO",
                0x70000012: "DT_MIPS_UNREFEXTNO",
                0x70000013: "DT_MIPS_GOTSYM",
                0x70000016: "DT_MIPS_RLD_MAP"
            }
        else:
            self.dynamic_tag_translation = {}

        reloc = 0

        # Load sections
        for s in self.elf.iter_sections():
            if not s.name:
                continue

            # Keep only sections R|W|X
            # TODO : is it sufficiant ?
            if s.header.sh_flags & 0xf == 0:
                continue

            name = s.name.decode()
            start = s.header.sh_addr

            if start == 0:
                start = reloc
                reloc += s.header.sh_size

            data = s.data()

            self.add_section(
                start,
                s.name.decode(),
                s.header.sh_size,
                len(data),
                self.__section_is_exec(s),
                self.__section_is_data(s),
                data)

        # Load segments
        rename_counter = 1
        seen = set()
        for seg in self.elf.iter_segments():
            if seg.header.p_type == "PT_DYNAMIC":
                self.dynamic_seg = seg

            if seg.header.p_type != "PT_LOAD":
                continue

            name = seg.header.p_type
            if name in seen:
                name += "_%d" % rename_counter
                rename_counter += 1

            seen.add(name)
            start = seg.header.p_vaddr
            bisect.insort_left(self._sorted_segments, start)

            is_data = self.__segment_is_data(seg)
            is_exec = self.__segment_is_exec(seg)
            data = seg.data()

            self._abs_segments[start] = SegmentAbs(
                    name,
                    start,
                    seg.header.p_memsz,
                    len(data),
                    is_exec,
                    is_data,
                    data,
                    seg.header.p_offset,
                    not self.elf.little_endian)

        # No section headers, we add segments in sections
        if len(self._abs_sections) == 0:
            self._abs_sections = self._abs_segments
            self._sorted_sections = self._sorted_segments