<commit_before>import pyvex
import elftools
import os

from .. import Backend
from ..symbol import SymbolType
from ...address_translator import AT
from ...utils import stream_or_path
from elftools.elf.descriptions import describe_ei_osabi
from collections import OrderedDict

__all__ = ('MetaELF',)


def maybedecode(string):
    # so... it turns out that pyelftools is garbage and will transparently give you either strings or bytestrings
    # based on pretty much nothing whatsoever
    return string if type(string) is str else string.decode()

class MetaELF(Backend):
    """
    A base class that implements functions used by all backends that can load an ELF.
    """
    def __init__(self, *args, **kwargs):
        super(MetaELF, self).__init__(*args, **kwargs)
        self.os = describe_ei_osabi(elftools.elf.elffile.ELFFile(self.binary_stream).header.e_ident.EI_OSABI)
        self._plt = {}
        self.elfflags = 0
        self.ppc64_initial_rtoc = None

    supported_filetypes = ['elf']

    def _block(self, addr):
        # for sanity checking. we live in the world of heuristics now.
        thumb = self.arch.name.startswith("ARM") and addr % 2 == 1
        realaddr = addr
        if thumb: realaddr -= 1
        dat = self.memory.load(AT.from_lva(realaddr, self).to_rva(), 40)
        return pyvex.IRSB(dat, addr, self.arch, bytes_offset=1 if thumb else 0, opt_level=1)

    def _add_plt_stub(self, name, addr, sanity_check=True):
        # addr is an LVA
        if addr <= 0: return False
        target_addr = self.jmprel[name].linked_addr
        try:
            if sanity_check and target_addr not in [c.value for c in self._block(addr).all_constants]:<commit_msg>backend.elfflags field has been completely busted since it was introduced. set it correctly, fixing #214<commit_after>import pyvex
import elftools
import os

from .. import Backend
from ..symbol import SymbolType
from ...address_translator import AT
from ...utils import stream_or_path
from elftools.elf.descriptions import describe_ei_osabi
from collections import OrderedDict

__all__ = ('MetaELF',)


def maybedecode(string):
    # so... it turns out that pyelftools is garbage and will transparently give you either strings or bytestrings
    # based on pretty much nothing whatsoever
    return string if type(string) is str else string.decode()

class MetaELF(Backend):
    """
    A base class that implements functions used by all backends that can load an ELF.
    """
    def __init__(self, *args, **kwargs):
        super(MetaELF, self).__init__(*args, **kwargs)
        tmp_reader = elftools.elf.elffile.ELFFile(self.binary_stream)
        self.os = describe_ei_osabi(tmp_reader.header.e_ident.EI_OSABI)
        self.elfflags = tmp_reader.header.e_flags
        self._plt = {}
        self.ppc64_initial_rtoc = None

    supported_filetypes = ['elf']

    def _block(self, addr):
        # for sanity checking. we live in the world of heuristics now.
        thumb = self.arch.name.startswith("ARM") and addr % 2 == 1
        realaddr = addr
        if thumb: realaddr -= 1
        dat = self.memory.load(AT.from_lva(realaddr, self).to_rva(), 40)
        return pyvex.IRSB(dat, addr, self.arch, bytes_offset=1 if thumb else 0, opt_level=1)

    def _add_plt_stub(self, name, addr, sanity_check=True):
        # addr is an LVA
        if addr <= 0: return False
        target_addr = self.jmprel[name].linked_addr
        try:
            if sanity_check and target_addr not in [c.value for c in self._block(addr).all_constants]:
{'fraction_non_alphanumeric': 0.09142371921879422, 'fraction_numerical': 0.00735918482875743, 'mean_word_length': 3.1381733021077283, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4793910', 'n_tokens_mistral': 1121, 'n_tokens_neox': 1089, 'n_words': 345}