本文整理汇总了C++中FileSpec::ReadFileContents方法的典型用法代码示例。如果您正苦于以下问题:C++ FileSpec::ReadFileContents方法的具体用法?C++ FileSpec::ReadFileContents怎么用?C++ FileSpec::ReadFileContents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileSpec
的用法示例。
在下文中一共展示了FileSpec::ReadFileContents方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetModuleSpecifications
size_t ObjectFile::GetModuleSpecifications(const FileSpec &file,
lldb::offset_t file_offset,
lldb::offset_t file_size,
ModuleSpecList &specs) {
DataBufferSP data_sp(file.ReadFileContents(file_offset, 512));
if (data_sp) {
if (file_size == 0) {
const lldb::offset_t actual_file_size = file.GetByteSize();
if (actual_file_size > file_offset)
file_size = actual_file_size - file_offset;
}
return ObjectFile::GetModuleSpecifications(file, // file spec
data_sp, // data bytes
0, // data offset
file_offset, // file offset
file_size, // file length
specs);
}
return 0;
}
示例2: data_buffer_sp
static bool
FileAtPathContainsArchAndUUID
(
const FileSpec &file_spec,
const ArchSpec *arch,
const lldb_private::UUID *uuid
)
{
DataExtractor data;
off_t file_offset = 0;
DataBufferSP data_buffer_sp (file_spec.ReadFileContents (file_offset, 0x1000));
if (data_buffer_sp && data_buffer_sp->GetByteSize() > 0)
{
data.SetData(data_buffer_sp);
uint32_t data_offset = 0;
uint32_t magic = data.GetU32(&data_offset);
switch (magic)
{
// 32 bit mach-o file
case HeaderMagic32:
case HeaderMagic32Swapped:
case HeaderMagic64:
case HeaderMagic64Swapped:
return SkinnyMachOFileContainsArchAndUUID (file_spec, arch, uuid, file_offset, data, data_offset, magic);
// fat mach-o file
case UniversalMagic:
case UniversalMagicSwapped:
return UniversalMachOFileContainsArchAndUUID (file_spec, arch, uuid, file_offset, data, data_offset, magic);
default:
break;
}
}
return false;
}
示例3: if
static bool
SkinnyMachOFileContainsArchAndUUID
(
const FileSpec &file_spec,
const ArchSpec *arch,
const lldb_private::UUID *uuid, // the UUID we are looking for
off_t file_offset,
DataExtractor& data,
uint32_t data_offset,
const uint32_t magic
)
{
assert(magic == HeaderMagic32 || magic == HeaderMagic32Swapped || magic == HeaderMagic64 || magic == HeaderMagic64Swapped);
if (magic == HeaderMagic32 || magic == HeaderMagic64)
data.SetByteOrder (lldb::endian::InlHostByteOrder());
else if (lldb::endian::InlHostByteOrder() == eByteOrderBig)
data.SetByteOrder (eByteOrderLittle);
else
data.SetByteOrder (eByteOrderBig);
uint32_t i;
const uint32_t cputype = data.GetU32(&data_offset); // cpu specifier
const uint32_t cpusubtype = data.GetU32(&data_offset); // machine specifier
data_offset+=4; // Skip mach file type
const uint32_t ncmds = data.GetU32(&data_offset); // number of load commands
const uint32_t sizeofcmds = data.GetU32(&data_offset); // the size of all the load commands
data_offset+=4; // Skip flags
// Check the architecture if we have a valid arch pointer
if (arch)
{
ArchSpec file_arch(eArchTypeMachO, cputype, cpusubtype);
if (file_arch != *arch)
return false;
}
// The file exists, and if a valid arch pointer was passed in we know
// if already matches, so we can return if we aren't looking for a specific
// UUID
if (uuid == NULL)
return true;
if (magic == HeaderMagic64Swapped || magic == HeaderMagic64)
data_offset += 4; // Skip reserved field for in mach_header_64
// Make sure we have enough data for all the load commands
if (magic == HeaderMagic64Swapped || magic == HeaderMagic64)
{
if (data.GetByteSize() < sizeof(struct mach_header_64) + sizeofcmds)
{
DataBufferSP data_buffer_sp (file_spec.ReadFileContents (file_offset, sizeof(struct mach_header_64) + sizeofcmds));
data.SetData (data_buffer_sp);
}
}
else
{
if (data.GetByteSize() < sizeof(struct mach_header) + sizeofcmds)
{
DataBufferSP data_buffer_sp (file_spec.ReadFileContents (file_offset, sizeof(struct mach_header) + sizeofcmds));
data.SetData (data_buffer_sp);
}
}
for (i=0; i<ncmds; i++)
{
const uint32_t cmd_offset = data_offset; // Save this data_offset in case parsing of the segment goes awry!
uint32_t cmd = data.GetU32(&data_offset);
uint32_t cmd_size = data.GetU32(&data_offset);
if (cmd == LoadCommandUUID)
{
lldb_private::UUID file_uuid (data.GetData(&data_offset, 16), 16);
if (file_uuid == *uuid)
return true;
// Emit some warning messages since the UUIDs do not match!
char path_buf[PATH_MAX];
path_buf[0] = '\0';
const char *path = file_spec.GetPath(path_buf, PATH_MAX) ? path_buf
: file_spec.GetFilename().AsCString();
Host::SystemLog (Host::eSystemLogWarning,
"warning: UUID mismatch detected between binary and:\n\t'%s'\n",
path);
return false;
}
data_offset = cmd_offset + cmd_size;
}
return false;
}
示例4: if
static bool
SkinnyMachOFileContainsArchAndUUID
(
const FileSpec &file_spec,
const ArchSpec *arch,
const lldb_private::UUID *uuid, // the UUID we are looking for
off_t file_offset,
DataExtractor& data,
lldb::offset_t data_offset,
const uint32_t magic
)
{
assert(magic == HeaderMagic32 || magic == HeaderMagic32Swapped || magic == HeaderMagic64 || magic == HeaderMagic64Swapped);
if (magic == HeaderMagic32 || magic == HeaderMagic64)
data.SetByteOrder (lldb::endian::InlHostByteOrder());
else if (lldb::endian::InlHostByteOrder() == eByteOrderBig)
data.SetByteOrder (eByteOrderLittle);
else
data.SetByteOrder (eByteOrderBig);
uint32_t i;
const uint32_t cputype = data.GetU32(&data_offset); // cpu specifier
const uint32_t cpusubtype = data.GetU32(&data_offset); // machine specifier
data_offset+=4; // Skip mach file type
const uint32_t ncmds = data.GetU32(&data_offset); // number of load commands
const uint32_t sizeofcmds = data.GetU32(&data_offset); // the size of all the load commands
data_offset+=4; // Skip flags
// Check the architecture if we have a valid arch pointer
if (arch)
{
ArchSpec file_arch(eArchTypeMachO, cputype, cpusubtype);
if (!file_arch.IsCompatibleMatch(*arch))
return false;
}
// The file exists, and if a valid arch pointer was passed in we know
// if already matches, so we can return if we aren't looking for a specific
// UUID
if (uuid == NULL)
return true;
if (magic == HeaderMagic64Swapped || magic == HeaderMagic64)
data_offset += 4; // Skip reserved field for in mach_header_64
// Make sure we have enough data for all the load commands
if (magic == HeaderMagic64Swapped || magic == HeaderMagic64)
{
if (data.GetByteSize() < sizeof(struct mach_header_64) + sizeofcmds)
{
DataBufferSP data_buffer_sp (file_spec.ReadFileContents (file_offset, sizeof(struct mach_header_64) + sizeofcmds));
data.SetData (data_buffer_sp);
}
}
else
{
if (data.GetByteSize() < sizeof(struct mach_header) + sizeofcmds)
{
DataBufferSP data_buffer_sp (file_spec.ReadFileContents (file_offset, sizeof(struct mach_header) + sizeofcmds));
data.SetData (data_buffer_sp);
}
}
for (i=0; i<ncmds; i++)
{
const lldb::offset_t cmd_offset = data_offset; // Save this data_offset in case parsing of the segment goes awry!
uint32_t cmd = data.GetU32(&data_offset);
uint32_t cmd_size = data.GetU32(&data_offset);
if (cmd == LoadCommandUUID)
{
lldb_private::UUID file_uuid (data.GetData(&data_offset, 16), 16);
if (file_uuid == *uuid)
return true;
return false;
}
data_offset = cmd_offset + cmd_size;
}
return false;
}