本文整理汇总了C++中DataExtractor::PeekData方法的典型用法代码示例。如果您正苦于以下问题:C++ DataExtractor::PeekData方法的具体用法?C++ DataExtractor::PeekData怎么用?C++ DataExtractor::PeekData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataExtractor
的用法示例。
在下文中一共展示了DataExtractor::PeekData方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: data
static bool
GetNetBSDProcessArgs (const ProcessInstanceInfoMatch *match_info_ptr,
ProcessInstanceInfo &process_info)
{
if (!process_info.ProcessIDIsValid())
return false;
int pid = process_info.GetProcessID();
int mib[4] = { CTL_KERN, KERN_PROC_ARGS, pid, KERN_PROC_ARGV };
char arg_data[8192];
size_t arg_data_size = sizeof(arg_data);
if (::sysctl (mib, 4, arg_data, &arg_data_size , NULL, 0) != 0)
return false;
DataExtractor data (arg_data, arg_data_size, lldb::endian::InlHostByteOrder(), sizeof(void *));
lldb::offset_t offset = 0;
const char *cstr;
cstr = data.GetCStr (&offset);
if (!cstr)
return false;
process_info.GetExecutableFile().SetFile(cstr, false);
if (!(match_info_ptr == NULL ||
NameMatches (process_info.GetExecutableFile().GetFilename().GetCString(),
match_info_ptr->GetNameMatchType(),
match_info_ptr->GetProcessInfo().GetName())))
return false;
Args &proc_args = process_info.GetArguments();
while (1)
{
const uint8_t *p = data.PeekData(offset, 1);
while ((p != NULL) && (*p == '\0') && offset < arg_data_size)
{
++offset;
p = data.PeekData(offset, 1);
}
if (p == NULL || offset >= arg_data_size)
break;
cstr = data.GetCStr(&offset);
if (!cstr)
break;
proc_args.AppendArgument(cstr);
}
return true;
}
示例2: ReadFromMemory
bool Type::ReadFromMemory(ExecutionContext *exe_ctx, lldb::addr_t addr,
AddressType address_type, DataExtractor &data) {
if (address_type == eAddressTypeFile) {
// Can't convert a file address to anything valid without more
// context (which Module it came from)
return false;
}
const uint64_t byte_size = GetByteSize();
if (data.GetByteSize() < byte_size) {
lldb::DataBufferSP data_sp(new DataBufferHeap(byte_size, '\0'));
data.SetData(data_sp);
}
uint8_t *dst = const_cast<uint8_t *>(data.PeekData(0, byte_size));
if (dst != nullptr) {
if (address_type == eAddressTypeHost) {
// The address is an address in this process, so just copy it
if (addr == 0)
return false;
memcpy(dst, (uint8_t *)nullptr + addr, byte_size);
return true;
} else {
if (exe_ctx) {
Process *process = exe_ctx->GetProcessPtr();
if (process) {
Error error;
return exe_ctx->GetProcessPtr()->ReadMemory(addr, dst, byte_size,
error) == byte_size;
}
}
}
}
return false;
}
示例3: sizeof
bool
ObjectContainerBSDArchive::MagicBytesMatch (const DataExtractor &data)
{
uint32_t offset = 0;
const char* armag = (const char* )data.PeekData (offset, sizeof(ar_hdr));
if (armag && ::strncmp(armag, ARMAG, SARMAG) == 0)
{
armag += offsetof(struct ar_hdr, ar_fmag) + SARMAG;
if (strncmp(armag, ARFMAG, 2) == 0)
return true;
}
示例4: if
//.........这里部分代码省略.........
data.SetByteOrder(target->GetArchitecture().GetByteOrder());
data.SetAddressByteSize(target->GetArchitecture().GetAddressByteSize());
break;
}
}
// fallback to host settings
data.SetByteOrder(endian::InlHostByteOrder());
data.SetAddressByteSize(sizeof(void *));
break;
}
// Bail if we encountered any errors
if (error.Fail())
return error;
if (address == LLDB_INVALID_ADDRESS)
{
error.SetErrorStringWithFormat ("invalid %s address", address_type == eAddressTypeHost ? "host" : "load");
return error;
}
// If we got here, we need to read the value from memory
size_t byte_size = GetValueByteSize (&error, exe_ctx);
// Bail if we encountered any errors getting the byte size
if (error.Fail())
return error;
// Make sure we have enough room within "data", and if we don't make
// something large enough that does
if (!data.ValidOffsetForDataOfSize (data_offset, byte_size))
{
DataBufferSP data_sp(new DataBufferHeap (data_offset + byte_size, '\0'));
data.SetData(data_sp);
}
uint8_t* dst = const_cast<uint8_t*>(data.PeekData (data_offset, byte_size));
if (dst != NULL)
{
if (address_type == eAddressTypeHost)
{
// The address is an address in this process, so just copy it.
if (address == 0)
{
error.SetErrorStringWithFormat("trying to read from host address of 0.");
return error;
}
memcpy (dst, (uint8_t*)NULL + address, byte_size);
}
else if ((address_type == eAddressTypeLoad) || (address_type == eAddressTypeFile))
{
if (file_so_addr.IsValid())
{
// We have a file address that we were able to translate into a
// section offset address so we might be able to read this from
// the object files if we don't have a live process. Lets always
// try and read from the process if we have one though since we
// want to read the actual value by setting "prefer_file_cache"
// to false.
const bool prefer_file_cache = false;
if (exe_ctx->GetTargetRef().ReadMemory(file_so_addr, prefer_file_cache, dst, byte_size, error) != byte_size)
{
error.SetErrorStringWithFormat("read memory from 0x%" PRIx64 " failed", (uint64_t)address);
}
}
else
{
// The execution context might have a NULL process, but it
// might have a valid process in the exe_ctx->target, so use
// the ExecutionContext::GetProcess accessor to ensure we
// get the process if there is one.
Process *process = exe_ctx->GetProcessPtr();
if (process)
{
const size_t bytes_read = process->ReadMemory(address, dst, byte_size, error);
if (bytes_read != byte_size)
error.SetErrorStringWithFormat("read memory from 0x%" PRIx64 " failed (%u of %u bytes read)",
(uint64_t)address,
(uint32_t)bytes_read,
(uint32_t)byte_size);
}
else
{
error.SetErrorStringWithFormat("read memory from 0x%" PRIx64 " failed (invalid process)", (uint64_t)address);
}
}
}
else
{
error.SetErrorStringWithFormat ("unsupported AddressType value (%i)", address_type);
}
}
else
{
error.SetErrorStringWithFormat ("out of memory");
}
return error;
}
示例5: s_regex
//.........这里部分代码省略.........
const uint8_t *opcode_data = data.GetDataStart();
const size_t opcode_data_len = data.GetByteSize();
llvm::MCInst inst;
size_t inst_size = mc_disasm_ptr->GetMCInst (opcode_data,
opcode_data_len,
pc,
inst);
if (inst_size > 0)
{
mc_disasm_ptr->SetStyle(use_hex_immediates, hex_style);
mc_disasm_ptr->PrintMCInst(inst, out_string, sizeof(out_string));
}
llvm_disasm.Unlock();
if (inst_size == 0)
{
m_comment.assign ("unknown opcode");
inst_size = m_opcode.GetByteSize();
StreamString mnemonic_strm;
lldb::offset_t offset = 0;
lldb::ByteOrder byte_order = data.GetByteOrder();
switch (inst_size)
{
case 1:
{
const uint8_t uval8 = data.GetU8 (&offset);
m_opcode.SetOpcode8 (uval8, byte_order);
m_opcode_name.assign (".byte");
mnemonic_strm.Printf("0x%2.2x", uval8);
}
break;
case 2:
{
const uint16_t uval16 = data.GetU16(&offset);
m_opcode.SetOpcode16(uval16, byte_order);
m_opcode_name.assign (".short");
mnemonic_strm.Printf("0x%4.4x", uval16);
}
break;
case 4:
{
const uint32_t uval32 = data.GetU32(&offset);
m_opcode.SetOpcode32(uval32, byte_order);
m_opcode_name.assign (".long");
mnemonic_strm.Printf("0x%8.8x", uval32);
}
break;
case 8:
{
const uint64_t uval64 = data.GetU64(&offset);
m_opcode.SetOpcode64(uval64, byte_order);
m_opcode_name.assign (".quad");
mnemonic_strm.Printf("0x%16.16" PRIx64, uval64);
}
break;
default:
if (inst_size == 0)
return;
else
{
const uint8_t *bytes = data.PeekData(offset, inst_size);
if (bytes == NULL)
return;
m_opcode_name.assign (".byte");
m_opcode.SetOpcodeBytes(bytes, inst_size);
mnemonic_strm.Printf("0x%2.2x", bytes[0]);
for (uint32_t i=1; i<inst_size; ++i)
mnemonic_strm.Printf(" 0x%2.2x", bytes[i]);
}
break;
}
m_mnemonics.swap(mnemonic_strm.GetString());
return;
}
else
{
if (m_does_branch == eLazyBoolCalculate)
{
const bool can_branch = mc_disasm_ptr->CanBranch(inst);
if (can_branch)
m_does_branch = eLazyBoolYes;
else
m_does_branch = eLazyBoolNo;
}
}
static RegularExpression s_regex("[ \t]*([^ ^\t]+)[ \t]*([^ ^\t].*)?", REG_EXTENDED);
RegularExpression::Match matches(3);
if (s_regex.Execute(out_string, &matches))
{
matches.GetMatchAtIndex(out_string, 1, m_opcode_name);
matches.GetMatchAtIndex(out_string, 2, m_mnemonics);
}
}
}
示例6: WriteRegisterSet
bool
RegisterContextMach_i386::WriteRegisterBytes (uint32_t reg, DataExtractor &data, uint32_t data_offset)
{
int set = GetSetForNativeRegNum (reg);
if (set == -1)
return false;
if (ReadRegisterSet(set, false) != KERN_SUCCESS)
return false;
const RegisterInfo * reg_info = GetRegisterInfoAtIndex (reg);
if (reg_info == NULL && data.ValidOffsetForDataOfSize(data_offset, reg_info->byte_size))
return false;
uint32_t offset = data_offset;
switch (reg)
{
case gpr_eax:
case gpr_ebx:
case gpr_ecx:
case gpr_edx:
case gpr_edi:
case gpr_esi:
case gpr_ebp:
case gpr_esp:
case gpr_ss:
case gpr_eflags:
case gpr_eip:
case gpr_cs:
case gpr_ds:
case gpr_es:
case gpr_fs:
case gpr_gs:
(&gpr.eax)[reg - gpr_eax] = data.GetU32 (&offset);
break;
case fpu_fcw:
fpu.fcw = data.GetU16(&offset);
break;
case fpu_fsw:
fpu.fsw = data.GetU16(&offset);
break;
case fpu_ftw:
fpu.ftw = data.GetU8(&offset);
break;
case fpu_fop:
fpu.fop = data.GetU16(&offset);
break;
case fpu_ip:
fpu.ip = data.GetU32(&offset);
break;
case fpu_cs:
fpu.cs = data.GetU16(&offset);
break;
case fpu_dp:
fpu.dp = data.GetU32(&offset);
break;
case fpu_ds:
fpu.ds = data.GetU16(&offset);
break;
case fpu_mxcsr:
fpu.mxcsr = data.GetU32(&offset);
break;
case fpu_mxcsrmask:
fpu.mxcsrmask = data.GetU32(&offset);
break;
case fpu_stmm0:
case fpu_stmm1:
case fpu_stmm2:
case fpu_stmm3:
case fpu_stmm4:
case fpu_stmm5:
case fpu_stmm6:
case fpu_stmm7:
::memcpy (fpu.stmm[reg - fpu_stmm0].bytes, data.PeekData(offset, reg_info->byte_size), reg_info->byte_size);
return false;
case fpu_xmm0:
case fpu_xmm1:
case fpu_xmm2:
case fpu_xmm3:
case fpu_xmm4:
case fpu_xmm5:
case fpu_xmm6:
case fpu_xmm7:
// These values don't fit into scalar types, RegisterContext::ReadRegisterBytes()
// must be used for these registers
::memcpy (fpu.xmm[reg - fpu_xmm0].bytes, data.PeekData(offset, reg_info->byte_size), reg_info->byte_size);
//.........这里部分代码省略.........
示例7: CalculateMnemonicOperandsAndComment
virtual void
CalculateMnemonicOperandsAndComment (const lldb_private::ExecutionContext *exe_ctx)
{
DataExtractor data;
const AddressClass address_class = GetAddressClass ();
if (m_opcode.GetData(data, address_class))
{
char out_string[512];
::LLVMDisasmContextRef disasm_context;
if (address_class == eAddressClassCodeAlternateISA)
disasm_context = m_disasm.m_alternate_disasm_context;
else
disasm_context = m_disasm.m_disasm_context;
lldb::addr_t pc = LLDB_INVALID_ADDRESS;
if (exe_ctx)
{
Target *target = exe_ctx->GetTargetPtr();
if (target)
pc = m_address.GetLoadAddress(target);
}
if (pc == LLDB_INVALID_ADDRESS)
pc = m_address.GetFileAddress();
m_disasm.Lock(this, exe_ctx);
uint8_t *opcode_data = const_cast<uint8_t *>(data.PeekData (0, 1));
const size_t opcode_data_len = data.GetByteSize();
size_t inst_size = ::LLVMDisasmInstruction (disasm_context,
opcode_data,
opcode_data_len,
pc,
out_string,
sizeof(out_string));
m_disasm.Unlock();
if (inst_size == 0)
{
m_comment.assign ("unknown opcode");
inst_size = m_opcode.GetByteSize();
StreamString mnemonic_strm;
uint32_t offset = 0;
switch (inst_size)
{
case 1:
{
const uint8_t uval8 = data.GetU8 (&offset);
m_opcode.SetOpcode8 (uval8);
m_opcode_name.assign (".byte");
mnemonic_strm.Printf("0x%2.2x", uval8);
}
break;
case 2:
{
const uint16_t uval16 = data.GetU16(&offset);
m_opcode.SetOpcode16(uval16);
m_opcode_name.assign (".short");
mnemonic_strm.Printf("0x%4.4x", uval16);
}
break;
case 4:
{
const uint32_t uval32 = data.GetU32(&offset);
m_opcode.SetOpcode32(uval32);
m_opcode_name.assign (".long");
mnemonic_strm.Printf("0x%8.8x", uval32);
}
break;
case 8:
{
const uint64_t uval64 = data.GetU64(&offset);
m_opcode.SetOpcode64(uval64);
m_opcode_name.assign (".quad");
mnemonic_strm.Printf("0x%16.16llx", uval64);
}
break;
default:
if (inst_size == 0)
return;
else
{
const uint8_t *bytes = data.PeekData(offset, inst_size);
if (bytes == NULL)
return;
m_opcode_name.assign (".byte");
m_opcode.SetOpcodeBytes(bytes, inst_size);
mnemonic_strm.Printf("0x%2.2x", bytes[0]);
for (uint32_t i=1; i<inst_size; ++i)
mnemonic_strm.Printf(" 0x%2.2x", bytes[i]);
}
break;
}
m_mnemocics.swap(mnemonic_strm.GetString());
return;
}
//.........这里部分代码省略.........
示例8: if
//.........这里部分代码省略.........
if (exe_ctx)
{
Target *target = exe_ctx->GetTargetPtr();
if (target)
{
data.SetByteOrder(target->GetArchitecture().GetByteOrder());
data.SetAddressByteSize(target->GetArchitecture().GetAddressByteSize());
break;
}
}
// fallback to host settings
data.SetByteOrder(lldb::endian::InlHostByteOrder());
data.SetAddressByteSize(sizeof(void *));
break;
}
// Bail if we encountered any errors
if (error.Fail())
return error;
if (address == LLDB_INVALID_ADDRESS)
{
error.SetErrorStringWithFormat ("invalid %s address", address_type == eAddressTypeHost ? "host" : "load");
return error;
}
// If we got here, we need to read the value from memory
uint32_t byte_size = GetValueByteSize (ast_context, &error);
// Bail if we encountered any errors getting the byte size
if (error.Fail())
return error;
// Make sure we have enough room within "data", and if we don't make
// something large enough that does
if (!data.ValidOffsetForDataOfSize (data_offset, byte_size))
{
DataBufferSP data_sp(new DataBufferHeap (data_offset + byte_size, '\0'));
data.SetData(data_sp);
}
uint8_t* dst = const_cast<uint8_t*>(data.PeekData (data_offset, byte_size));
if (dst != NULL)
{
if (address_type == eAddressTypeHost)
{
// The address is an address in this process, so just copy it
memcpy (dst, (uint8_t*)NULL + address, byte_size);
}
else if ((address_type == eAddressTypeLoad) || (address_type == eAddressTypeFile))
{
if (file_so_addr.IsValid())
{
// We have a file address that we were able to translate into a
// section offset address so we might be able to read this from
// the object files if we don't have a live process. Lets always
// try and read from the process if we have one though since we
// want to read the actual value by setting "prefer_file_cache"
// to false.
const bool prefer_file_cache = false;
if (exe_ctx->GetTargetRef().ReadMemory(file_so_addr, prefer_file_cache, dst, byte_size, error) != byte_size)
{
error.SetErrorStringWithFormat("read memory from 0x%llx failed", (uint64_t)address);
}
}
else
{
// The execution context might have a NULL process, but it
// might have a valid process in the exe_ctx->target, so use
// the ExecutionContext::GetProcess accessor to ensure we
// get the process if there is one.
Process *process = exe_ctx->GetProcessPtr();
if (process)
{
const size_t bytes_read = process->ReadMemory(address, dst, byte_size, error);
if (bytes_read != byte_size)
error.SetErrorStringWithFormat("read memory from 0x%llx failed (%u of %u bytes read)",
(uint64_t)address,
(uint32_t)bytes_read,
(uint32_t)byte_size);
}
else
{
error.SetErrorStringWithFormat("read memory from 0x%llx failed (invalid process)", (uint64_t)address);
}
}
}
else
{
error.SetErrorStringWithFormat ("unsupported AddressType value (%i)", address_type);
}
}
else
{
error.SetErrorStringWithFormat ("out of memory");
}
return error;
}
示例9: switch
bool
DWARFFormValue::ExtractValue(const DataExtractor& data, lldb::offset_t* offset_ptr, const DWARFCompileUnit* cu)
{
bool indirect = false;
bool is_block = false;
m_value.data = NULL;
// Read the value for the form into value and follow and DW_FORM_indirect instances we run into
do
{
indirect = false;
switch (m_form)
{
case DW_FORM_addr: m_value.value.uval = data.GetMaxU64(offset_ptr, DWARFCompileUnit::GetAddressByteSize(cu)); break;
case DW_FORM_block2: m_value.value.uval = data.GetU16(offset_ptr); is_block = true; break;
case DW_FORM_block4: m_value.value.uval = data.GetU32(offset_ptr); is_block = true; break;
case DW_FORM_data2: m_value.value.uval = data.GetU16(offset_ptr); break;
case DW_FORM_data4: m_value.value.uval = data.GetU32(offset_ptr); break;
case DW_FORM_data8: m_value.value.uval = data.GetU64(offset_ptr); break;
case DW_FORM_string: m_value.value.cstr = data.GetCStr(offset_ptr);
// Set the string value to also be the data for inlined cstr form values only
// so we can tell the differnence between DW_FORM_string and DW_FORM_strp form
// values;
m_value.data = (uint8_t*)m_value.value.cstr; break;
case DW_FORM_exprloc:
case DW_FORM_block: m_value.value.uval = data.GetULEB128(offset_ptr); is_block = true; break;
case DW_FORM_block1: m_value.value.uval = data.GetU8(offset_ptr); is_block = true; break;
case DW_FORM_data1: m_value.value.uval = data.GetU8(offset_ptr); break;
case DW_FORM_flag: m_value.value.uval = data.GetU8(offset_ptr); break;
case DW_FORM_sdata: m_value.value.sval = data.GetSLEB128(offset_ptr); break;
case DW_FORM_strp: m_value.value.uval = data.GetU32(offset_ptr); break;
// case DW_FORM_APPLE_db_str:
case DW_FORM_udata: m_value.value.uval = data.GetULEB128(offset_ptr); break;
case DW_FORM_ref_addr:
if (cu->GetVersion() <= 2)
m_value.value.uval = data.GetMaxU64(offset_ptr, DWARFCompileUnit::GetAddressByteSize(cu));
else
m_value.value.uval = data.GetU32(offset_ptr); // 4 for DWARF32, 8 for DWARF64, but we don't support DWARF64 yet
break;
case DW_FORM_ref1: m_value.value.uval = data.GetU8(offset_ptr); break;
case DW_FORM_ref2: m_value.value.uval = data.GetU16(offset_ptr); break;
case DW_FORM_ref4: m_value.value.uval = data.GetU32(offset_ptr); break;
case DW_FORM_ref8: m_value.value.uval = data.GetU64(offset_ptr); break;
case DW_FORM_ref_udata: m_value.value.uval = data.GetULEB128(offset_ptr); break;
case DW_FORM_indirect:
m_form = data.GetULEB128(offset_ptr);
indirect = true;
break;
case DW_FORM_sec_offset: m_value.value.uval = data.GetU32(offset_ptr); break;
case DW_FORM_flag_present: m_value.value.uval = 1; break;
case DW_FORM_ref_sig8: m_value.value.uval = data.GetU64(offset_ptr); break;
default:
return false;
break;
}
} while (indirect);
if (is_block)
{
m_value.data = data.PeekData(*offset_ptr, m_value.value.uval);
if (m_value.data != NULL)
{
*offset_ptr += m_value.value.uval;
}
}
return true;
}