def try_lookup_litstr(imm): """Return the literal string corresponding to the litstr ID `imm'. If we can't resolve it, just return `imm'.""" if unit.curunit is None: return imm litstr = lookup_litstr(imm, unit.curunit) return string_data_val(rawptr(litstr))
def imm_info(ptr, immtype): """Return the size and value of the immediate at `ptr' with immediate type `immtype'. """ info = {} if immtype in iva_imm_types(): imm = ptr.cast(T('unsigned char').pointer()).dereference() if imm & 0x1: iva_type = T('int32_t') else: iva_type = T('unsigned char') imm = ptr.cast(iva_type.pointer()).dereference() info['size'] = iva_type.sizeof info['value'] = imm >> 1 elif immtype in vec_imm_types(): prefixes = 2 if immtype == V('HPHP::MA') else 1 elm_size = vec_elm_sizes()[vec_imm_types().index(immtype)] num_elms = ptr.cast(T('int32_t').pointer()).dereference() info['size'] = prefixes * T('int32_t').sizeof + \ elm_size * num_elms info['value'] = '<vector>' elif immtype == V('HPHP::RATA'): imm = ptr.cast(T('unsigned char').pointer()).dereference() radb = V('HPHP::kRATArrayDataBit') tag = (imm & ~radb).cast(T('HPHP::RepoAuthType::Tag')) high_bit = (imm & radb) if tag in rata_arrs(): info['size'] = 5 if high_bit else 1 elif tag in rata_objs(): info['size'] = 5 else: info['size'] = 1 info['value'] = str(tag)[len('HPHP::RepoAuthType::Tag::'):] else: table_name = 'HPHP::immSize(unsigned char const*, int)::argTypeToSizes' if immtype >= 0: size = op_table(table_name)[as_idx(immtype)] uint = T(uints_by_size()[int(size)]) imm = ptr.cast(uint.pointer()).dereference() au = imm.cast(T('HPHP::ArgUnion')) info['size'] = size info['value'] = au['u_' + str(immtype)[6:]] # Try to print out literal strings. if immtype == V('HPHP::SA') and unit.curunit is not None: litstr = lookup_litstr(info['value'], unit.curunit) info['value'] = litstr['m_data'] else: info['size'] = 0 info['value'] = None return info
def imm_info(ptr, immtype): """Return the size and value of the immediate at `ptr' with immediate type `immtype'. """ info = {} if immtype in iva_imm_types(): imm = ptr.cast(T('unsigned char').pointer()).dereference() if imm & 0x80: raw = ptr.cast(T('uint32_t').pointer()).dereference() info['value'] = ((raw & 0xffffff00) >> 1) | (raw & 0x7f); info['size'] = 4 else: info['value'] = imm info['size'] = 1 elif immtype in vec_imm_types(): elm_size = vec_elm_sizes()[vec_imm_types().index(immtype)] num_elms = ptr.cast(T('int32_t').pointer()).dereference() info['size'] = T('int32_t').sizeof + elm_size * num_elms info['value'] = '<vector>' elif immtype == V('HPHP::RATA'): imm = ptr.cast(T('unsigned char').pointer()).dereference() radb = V('HPHP::kRATArrayDataBit') tag = (imm & ~radb).cast(T('HPHP::RepoAuthType::Tag')) high_bit = (imm & radb) if tag in rata_arrs(): info['size'] = 5 if high_bit else 1 elif tag in rata_objs(): info['size'] = 5 else: info['size'] = 1 info['value'] = str(tag)[len('HPHP::RepoAuthType::Tag::'):] elif immtype == V('HPHP::LAR'): first = ptr.cast(T('unsigned char').pointer()).dereference() if first & 0x1: first_type = T('int32_t') else: first_type = T('unsigned char') count = (ptr.cast(T('unsigned char').pointer()) + first_type.sizeof).dereference() if count & 0x1: count_type = T('int32_t') else: count_type = T('unsigned char') first = ptr.cast(first_type.pointer()).dereference() count = (ptr.cast(T('unsigned char').pointer()) + first_type.sizeof).cast(count_type.pointer()).dereference() info['size'] = first_type.sizeof + count_type.sizeof info['value'] = 'L:' + str(first >> 1) + '+' + str(count >> 1) else: table_name = 'HPHP::immSize(unsigned char const*, int)::argTypeToSizes' if immtype >= 0: size = op_table(table_name)[as_idx(immtype)] uint = T(uints_by_size()[int(size)]) imm = ptr.cast(uint.pointer()).dereference() au = imm.cast(T('HPHP::ArgUnion')) info['size'] = size info['value'] = au['u_' + str(immtype)[6:]] # Try to print out literal strings. if immtype == V('HPHP::SA') and unit.curunit is not None: litstr = lookup_litstr(info['value'], unit.curunit) info['value'] = string_data_val(rawptr(litstr)) else: info['size'] = 0 info['value'] = None return info
def imm_info(ptr, immtype): """Return the size and value of the immediate at `ptr' with immediate type `immtype'. """ info = {} if immtype in iva_imm_types(): imm = ptr.cast(T('unsigned char').pointer()).dereference() if imm & 0x1: iva_type = T('int32_t') else: iva_type = T('unsigned char') imm = ptr.cast(iva_type.pointer()).dereference() info['size'] = iva_type.sizeof info['value'] = imm >> 1 elif immtype in vec_imm_types(): prefixes = 2 if immtype == V('HPHP::MA') else 1 elm_size = vec_elm_sizes()[vec_imm_types().index(immtype)] num_elms = ptr.cast(T('int32_t').pointer()).dereference() info['size'] = prefixes * T('int32_t').sizeof + \ elm_size * num_elms info['value'] = '<vector>' elif immtype == V('HPHP::RATA'): imm = ptr.cast(T('unsigned char').pointer()).dereference() radb = V('HPHP::kRATArrayDataBit') tag = (imm & ~radb).cast(T('HPHP::RepoAuthType::Tag')) high_bit = (imm & radb) if tag in rata_arrs(): info['size'] = 5 if high_bit else 1 elif tag in rata_objs(): info['size'] = 5 else: info['size'] = 1 info['value'] = str(tag)[len('HPHP::RepoAuthType::Tag::'):] else: table_name = 'HPHP::immSize(HPHP::Op const*, int)::argTypeToSizes' if immtype >= 0: size = op_table(table_name)[as_idx(immtype)] uint = T(uints_by_size()[int(size)]) imm = ptr.cast(uint.pointer()).dereference() au = imm.cast(T('HPHP::ArgUnion')) info['size'] = size info['value'] = au['u_' + str(immtype)[6:]] # Try to print out literal strings. if immtype == V('HPHP::SA') and unit.curunit is not None: litstr = lookup_litstr(info['value'], unit.curunit) info['value'] = litstr['m_data'] else: info['size'] = 0 info['value'] = None return info
def imm_info(ptr, immtype): """Return the size and value of the immediate at `ptr' with immediate type `immtype'. """ info = {} if immtype in iva_imm_types(): imm = ptr.cast(T("unsigned char").pointer()).dereference() if imm & 0x1: iva_type = T("int32_t") else: iva_type = T("unsigned char") imm = ptr.cast(iva_type.pointer()).dereference() info["size"] = iva_type.sizeof info["value"] = imm >> 1 elif immtype in vec_imm_types(): prefixes = 2 if immtype == V("HPHP::MA") else 1 elm_size = vec_elm_sizes()[vec_imm_types().index(immtype)] num_elms = ptr.cast(T("int32_t").pointer()).dereference() info["size"] = prefixes * T("int32_t").sizeof + elm_size * num_elms info["value"] = "<vector>" elif immtype == V("HPHP::RATA"): imm = ptr.cast(T("unsigned char").pointer()).dereference() radb = V("HPHP::kRATArrayDataBit") tag = (imm & ~radb).cast(T("HPHP::RepoAuthType::Tag")) high_bit = imm & radb if tag in rata_arrs(): info["size"] = 5 if high_bit else 1 elif tag in rata_objs(): info["size"] = 5 else: info["size"] = 1 info["value"] = str(tag)[len("HPHP::RepoAuthType::Tag::") :] else: table_name = "HPHP::immSize(HPHP::Op const*, int)::argTypeToSizes" if immtype >= 0: size = op_table(table_name)[as_idx(immtype)] uint = T(uints_by_size()[int(size)]) imm = ptr.cast(uint.pointer()).dereference() au = imm.cast(T("HPHP::ArgUnion")) info["size"] = size info["value"] = au["u_" + str(immtype)[6:]] # Try to print out literal strings. if immtype == V("HPHP::SA") and unit.curunit is not None: litstr = lookup_litstr(info["value"], unit.curunit) info["value"] = litstr["m_data"] else: info["size"] = 0 info["value"] = None return info