Return operand memory access translation.
336245
def resolve_memory_access(self, tb, x86_mem_operand):
        
        size = self.__get_memory_access_size(x86_mem_operand)

        addr = None

        if x86_mem_operand.base:
            addr = ReilRegisterOperand(x86_mem_operand.base, size)

        if x86_mem_operand.index and x86_mem_operand.scale != 0x0:
            index = ReilRegisterOperand(x86_mem_operand.index, size)
            scale = ReilImmediateOperand(x86_mem_operand.scale, size)
            scaled_index = tb.temporal(size)

            tb.add(tb._builder.gen_mul(index, scale, scaled_index))

            if addr:
                tmp = tb.temporal(size)

                tb.add(tb._builder.gen_add(addr, scaled_index, tmp))

                addr = tmp
            else:
                addr = scaled_index

        if x86_mem_operand.displacement != 0x0:
            disp = ReilImmediateOperand(x86_mem_operand.displacement, size)

            if addr:
                tmp = tb.temporal(size)

                tb.add(tb._builder.gen_add(addr, disp, tmp))

                addr = tmp
            else:
                addr = disp
        else:
            if not addr:
                disp = ReilImmediateOperand(x86_mem_operand.displacement, size)

                addr = disp

        # TODO Improve this code and add support for the rest of the segments.
        if x86_mem_operand.segment in ["gs", "fs"]:
            seg_base_addr_map = {
                "gs": "gs_base_addr",
                "fs": "fs_base_addr",
            }

            seg_base = ReilRegisterOperand(seg_base_addr_map[x86_mem_operand.segment], size)

            if addr:
                tmp = tb.temporal(size)

                tb.add(tb._builder.gen_add(addr, seg_base, tmp))

                addr = tmp
            else:
                addr = seg_base

        return addr
913210
def get_size_in_bytes(self, handle):
        """"""
        fpath = self._fpath_from_handle(handle)
        return os.stat(fpath).st_size
400890
def meminfo():
    """"""
    f = open("/proc/meminfo")
    hwinfo = {}
    for line in f.readlines():
        meml = line.split()
        if (meml[0] == "MemTotal:"):
            mem = int(meml[1])
            hwinfo["Mem_MiB"] = mem/1024
        elif (meml[0] == "SwapTotal:"):
            swap = int(meml[1])
            hwinfo["Swap_MiB"] = swap/1024
    f.close()
    return hwinfo
542779
def to_raw_address(addr, section):
        """"""
        return addr - section.header.VirtualAddress + section.header.PointerToRawData
110611
def copy_constant_memory_args(self, cmem_args):
        """"""
        if self.lang == "CUDA":
            self.dev.copy_constant_memory_args(cmem_args)
        else:
            raise Exception("Error cannot copy constant memory arguments when language is not CUDA")
96173
def get_memory(self, start, size):
        
        LOG.debug('get_memory: %d bytes from %x', size, start)
        return get_memory(self.ida.idaapi, start, size,
                          default_byte=self.default_byte)
266728
def get_memfree(memory, parallel):
  """"""
  number = int(memory.rstrip(string.ascii_letters))
  memtype = memory.lstrip(string.digits)
  if not memtype:
    memtype = "G"
  return "%d%s" % (number*parallel, memtype)
682041
def _read_as_int(self, addr, numBytes):
        """"""
        buf = self.read_register(addr, numBytes)
        if len(buf) >= 4:
            return struct.unpack_from("<i", buf)[0]
        else:
            rtn = 0
            for i, byte in enumerate(buf):
                rtn |= byte << 8 * i
            return rtn
1068095
def move(self,operand1, operand2):
        
        if isinstance(operand1, int):
            output_type = self.symtab.get_type(operand1)
            self.free_if_register(operand1)
        else:
            output_type = SharedData.TYPES.NO_TYPE
        self.newline_text("MOV \t{0},{1}".format(self.symbol(operand1), self.symbol(operand2)), True)
        if isinstance(operand2, int):
            if self.symtab.get_kind(operand2) == SharedData.KINDS.WORKING_REGISTER:
                self.symtab.set_type(operand2, output_type)
989880
def get_total_memory():
    """"""
    if platform.system() != "Linux":
        return None

    with open("/proc/meminfo", "r") as in_file:
        for line in in_file:
            info = line.split()
            if info[0] == "MemTotal:" and info[-1] == "kB":
                memory_mb = int(int(info[1]) / 1024)
                return memory_mb

    return None
645029
def parse_operand(string, location, tokens):
    
    mod = " ".join(tokens.get("modifier", ""))

    if "immediate" in tokens:
        imm = parse_immediate("".join(tokens["immediate"]))
        size = modifier_size.get(mod, None)

        oprnd = X86ImmediateOperand(imm, size)

    if "register" in tokens:
        name = tokens["register"]
        size = arch_info.registers_size[tokens["register"]]

        oprnd = X86RegisterOperand(name, size)

    if "memory" in tokens:
        seg_reg = tokens.get("segment", None)
        base_reg = tokens.get("base", None)
        index_reg = tokens.get("index", None)
        scale_imm = int(tokens.get("scale", "0x1"), 16)
        displ_imm = int("".join(tokens.get("displacement", "0x0")), 16)

        oprnd = X86MemoryOperand(seg_reg, base_reg, index_reg, scale_imm, displ_imm)

    oprnd.modifier = mod

    if not oprnd.size and oprnd.modifier:
        oprnd.size = modifier_size[oprnd.modifier]

    return oprnd
1083001
def ReadBytes(self, address, num_bytes):
    """"""
    pdata = ctypes.c_void_p(0)
    data_cnt = ctypes.c_uint32(0)

    ret = libc.mach_vm_read(self.task, ctypes.c_ulonglong(address),
                            ctypes.c_longlong(num_bytes), ctypes.pointer(pdata),
                            ctypes.pointer(data_cnt))
    if ret:
      raise process_error.ProcessError("Error in mach_vm_read, ret=%s" % ret)
    buf = ctypes.string_at(pdata.value, data_cnt.value)
    libc.vm_deallocate(self.mytask, pdata, data_cnt)
    return buf
748541
def instruction_LSL_memory(self, opcode, ea, m):
        
        r = self.LSL(m)
#        log.debug("$%x LSL memory value $%x << 1 = $%x and write it to $%x \t| %s" % (
#            self.program_counter,
#            m, r, ea,
#            self.cfg.mem_info.get_shortest(ea)
#        ))
        return ea, r & 0xff
240459
def memory_read(self, start_position: int, size: int) -> memoryview:
        
        return self._memory.read(start_position, size)
75373
def parse_operand(string, location, tokens):
    
    sizes = {
        "dqword":  128,
        "pointer": 72,
        "qword":   64,
        "pointer": 40,
        "dword":   32,
        "word":    16,
        "byte":    8,
        "bit":     1,
    }

    if "immediate" in tokens:
        imm_str = "".join(tokens["immediate"])
        base = 16 if imm_str.startswith("0x") or imm_str.startswith("-0x") else 10

        imm = int(imm_str, base)

        oprnd = ReilImmediateOperand(imm)

    if "register" in tokens:
        if tokens["register"] in ["e", "empty"]:
            oprnd = ReilEmptyOperand()

            oprnd.size = 0
        else:
            name = tokens["register"]

            oprnd = ReilRegisterOperand(name)

    if "size" in tokens:
        oprnd.size = int(sizes[tokens["size"]])

    return [oprnd]
1286644
def get_call_data(
    global_state: GlobalState,
    memory_start: Union[int, BitVec],
    memory_size: Union[int, BitVec],
):
    
    state = global_state.mstate
    transaction_id = "{}_internalcall".format(global_state.current_transaction.id)

    memory_start = cast(
        BitVec,
        (
            symbol_factory.BitVecVal(memory_start, 256)
            if isinstance(memory_start, int)
            else memory_start
        ),
    )
    memory_size = cast(
        BitVec,
        (
            symbol_factory.BitVecVal(memory_size, 256)
            if isinstance(memory_size, int)
            else memory_size
        ),
    )

    uses_entire_calldata = simplify(
        memory_size - global_state.environment.calldata.calldatasize == 0
    )

    if uses_entire_calldata is True:
        return global_state.environment.calldata

    try:
        calldata_from_mem = state.memory[
            util.get_concrete_int(memory_start) : util.get_concrete_int(
                memory_start + memory_size
            )
        ]
        return ConcreteCalldata(transaction_id, calldata_from_mem)
    except TypeError:
        log.debug("Unsupported symbolic calldata offset")
        return SymbolicCalldata(transaction_id)
597926
def _addf(ins):
    ''' 
    '''
    op1, op2 = tuple(ins.quad[2:])

    if _f_ops(op1, op2) is not None:
        opa, opb = _f_ops(op1, op2)
        if opb == 0:  # A + 0 => A
            output = _float_oper(opa)
            output.extend(_fpush())
            return output

    output = _float_oper(op1, op2)
    output.append('call __ADDF')
    output.extend(_fpush())
    REQUIRES.add('addf.asm')
    return output