Пример #1
0
/** Reads data from a file. Reads up to @p size bytes of data beginning at byte @p start_va (absolute virtual address) in the
 *  mapped address space and placing the results in @p dst_buf and returning the number of bytes read. The return value could
 *  be smaller than @p size if the reading encounters virtual addresses that are not mapped.  When an unmapped virtual address
 *  is encountered the reading stops (even if subsequent virtual addresses are defined) and one of two things happen: if @p
 *  strict is set (the default) then an MemoryMap::NotMapped exception is thrown, otherwise the @p dst_buf is padded with zeros
 *  so that all @p size bytes are initialized. The @p map is used to map virtual addresses to file offsets; if @p map is NULL
 *  then the map defined in the underlying file is used. */
size_t
SgAsmGenericSection::read_content(const MemoryMap *map, rose_addr_t start_va, void *dst_buf, rose_addr_t size, bool strict)
{
    SgAsmGenericFile *file = get_file();
    ROSE_ASSERT(file!=NULL);
    return file->read_content(map, start_va, dst_buf, size, strict);
}
Пример #2
0
/** Reads data from a file. Reads up to @p size bytes of data beginning at byte @p start_offset from the beginning of the file,
 *  placing the results in @p dst_buf and returning the number of bytes read. The return value could be smaller than @p size
 *  if the end-of-file is reached. If the return value is smaller than @p size then one of two things happen: if @p strict is
 *  set (the default) then an SgAsmExecutableFileFormat::ShortRead exception is thrown; otherwise the @p dst_buf will be
 *  padded with zero bytes so that exactly @p size bytes of @p dst_buf are always initialized. */
size_t
SgAsmGenericSection::read_content(rose_addr_t start_offset, void *dst_buf, rose_addr_t size, bool strict)
{
    SgAsmGenericFile *file = get_file();
    ROSE_ASSERT(file!=NULL);
    return file->read_content(start_offset, dst_buf, size, strict);
}
Пример #3
0
/** Reads data from a file. This behaves the same as read_content() except the @p start_offset is relative to the beginning of
 *  this section.   Reading past the end of the section is not allowed and treated as a short read, and one of two things
 *  happen: if @p strict is set (the default) then an SgAsmExecutableFileFormat::ShortRead exception is thrown, otherwise the
 *  result is zero padded so as to contain exactly @p size bytes. */
size_t
SgAsmGenericSection::read_content_local(rose_addr_t start_offset, void *dst_buf, rose_addr_t size, bool strict)
{
    size_t retval;
    SgAsmGenericFile *file = get_file();
    ROSE_ASSERT(file!=NULL);
    if (start_offset > get_size()) {
        if (strict)
            throw ShortRead(this, start_offset, size);
        retval = 0;
    } else if (start_offset+size > get_size()) {
        if (strict)
            throw ShortRead(this, get_size(), start_offset+size-get_size());
        retval = get_size() - start_offset;
    } else {
        retval = size;
    }

    file->read_content(get_offset()+start_offset, dst_buf, retval, true);
    memset((char*)dst_buf+retval, 0, size-retval);
    return retval;
}