ROSE 0.11.145.147
|
S-Record hexadecimal data formats.
An S-Record is a simple ASCII-based format for conveying binary information, usually used for loading code and data onto an embedded processor. Multiple versions of S-Record formats exist, with the most popular being a Motorola syntax and an Intel syntax.
The Motorola S-Record format is also known as SRECORD, SREC, S19, S28, and S37. The "S19" name comes from the fact that record types 1 and 9 are used, allowing for 16-bit addresses; "s28" are record types 2 and 8 which allow 24-bit addresses; and "s37" are record types 3 and 7 which allow 32-bit addresses.
The Intel HEX format is another variant of S-Records. The sub-formats "I8HEX", "I16HEX", and "I32HEX" describe the address sizes that are supported, namely 16-bit, 20-bit, and 32-bit (note that the number in the format name doesn't actually match the address width in the first two cases).
ROSE's S-Record parser doesn't restrict which record types can appear within a file – it just parses whatever you hand it and returns a vector of SRecord objects. In fact, it will even allow the input to contain a mixture of Motorola and Intel syntax, although it will mark the less frequently-occuring syntax as errors. If any parsing errors are encountered, they are indicated within the individual SRecord objects.
#include <Rose/BinaryAnalysis/SRecord.h>
Classes | |
class | RunLengthEncoding |
Run-length encoding information. More... | |
Public Types | |
enum | Syntax { SREC_MOTOROLA , SREC_INTEL , SREC_UNKNOWN_SYNTAX } |
Syntax of the S-Record. More... | |
enum | Type { SREC_M_HEADER , SREC_M_DATA16 , SREC_M_DATA24 , SREC_M_DATA32 , SREC_M_RESERVED , SREC_M_COUNT16 , SREC_M_COUNT24 , SREC_M_START32 , SREC_M_START24 , SREC_M_START16 , SREC_I_DATA , SREC_I_END , SREC_I_EXTENDED_SA , SREC_I_START_SA , SREC_I_EXTENDED_LA , SREC_I_START_LA , SREC_UNKNOWN_TYPE } |
Type of S-Record. More... | |
Public Member Functions | |
SRecord () | |
Construct an empty S-Record. | |
std::string | toString () const |
Convert an S-Record to a string. | |
Syntax | syntax () const |
Property: syntax family. | |
SRecord (Type type, rose_addr_t addr, const std::vector< uint8_t > data) | |
Construct an S-Record with data. | |
SRecord (Type type, rose_addr_t addr, const uint8_t *buffer, size_t bufsz) | |
Construct an S-Record with data. | |
Type | type () const |
Property: record type. | |
SRecord & | type (Type type) |
Property: record type. | |
rose_addr_t | address () const |
Property: record starting address. | |
SRecord & | address (rose_addr_t addr) |
Property: record starting address. | |
const std::vector< uint8_t > & | data () const |
Property: record data. | |
std::vector< uint8_t > & | data () |
Property: record data. | |
SRecord & | data (const std::vector< uint8_t > &data) |
Property: record data. | |
const std::string & | error () const |
Property: record error messsage. | |
SRecord & | error (const std::string &error) |
Property: record error messsage. | |
Static Public Member Functions | |
static SRecord | parse (const std::string &) |
Construct an S-Record by parsing a string. | |
static std::vector< SRecord > | parse (std::istream &) |
Construct S-Records by parsing a file. | |
static AddressIntervalSet | dataAddresses (const std::vector< SRecord > &) |
Addresses occupied by all data. | |
static AddressIntervalSet | createSegments (const std::vector< SRecord > &, const MemoryMapPtr &map, rose_addr_t alignment, unsigned accessPermissions, const std::string &segmentName, MemoryMap::Clobber clobber) |
Create segments for S-Records. | |
static Sawyer::Optional< rose_addr_t > | load (const std::vector< SRecord > &, const MemoryMapPtr &) |
Load S-Records into a memory map. | |
static Sawyer::Optional< rose_addr_t > | load (const std::vector< SRecord > &, const MemoryMapPtr &, rose_addr_t alignment, unsigned accessPerms, const std::string &name, MemoryMap::Clobber) |
Load S-Records into a memory map, creating segments if necessary. | |
static std::vector< SRecord > | create (const MemoryMapPtr &, Syntax, size_t bytesPerRecord=28, size_t preferredAddrSize=4) |
Create S-Records from a memory map. | |
static SRecord | parseMotorola (const std::string &) |
Construct a Motorola S-Record by parsing a string. | |
static SRecord | parseIntel (const std::string &) |
Construct an Intel S-Record by parsing a string. | |
static Sawyer::Optional< rose_addr_t > | parseBigEndianInteger (const std::string &, size_t start, size_t nChars) |
Parse a hexadecimal string to an unsigned integer. | |
static unsigned | bigEndian (const std::vector< uint8_t > &data, size_t nBytes) |
Convert the first few bytes of the buffer to a big-endian integer. | |
static size_t | addressNBytes (Type) |
Size of address in bytes. | |
static uint8_t | checksum (Syntax, const std::string &, size_t start, size_t n) |
Compute a checksum for part of a record. | |
void | print (std::ostream &) const |
Print an S-Record to a stream. | |
Type of S-Record.
|
inline |
|
inline |
|
inline |
|
static |
Construct an S-Record by parsing a string.
This parses either a Motorola or Intel syntax S-Record.
|
static |
Construct S-Records by parsing a file.
Returns a vector with one element per line of input. Lines that did not contain an S-Record or which had trailing characters other than white space are reported as SRecord objects of type SREC_NONE and an error message.
|
static |
Addresses occupied by all data.
The specified S-Records are scanned in order to create the set of memory addresses that the data will occupy, and this set is returned.
|
static |
Create segments for S-Records.
The specified memory map is modified to create mapped regions for the specified S-Records using the minimum possible number of segments. First, the S-Records are scanned to obtain a list of addresses. These addresses are expanded by aligning their beginning and ending locations. Then a temporary memory map is created that contains the minimum number of aligned segments necessary to represent all the S-Record data. The created segments have the specified access permissions and names. Finally, the segments are copied into the original map
by calling MemoryMap::linkTo and passing the specified clobber
flag. The temporary map is deleted, but since buffers are reference counted, they will continue to exist if referenced by the specified map
.
The return value is the set of addresses that were added to the map
.
|
static |
Load S-Records into a memory map.
The data from the specified S-Records are loaded into the specified memory map. The map must contains segments at all S-Record addresses or else a MemoryMap::NotMapped exception is thrown. The return value is the execution starting address contained in the S-Records, if any.
|
static |
Load S-Records into a memory map, creating segments if necessary.
This is a convenience function that calls createSegments in order to create any necessary segments in the memory map, and then calls the two-argument version of load in order to load the S-Record data into those segments. Therefore, the arguments are the union of the arguments for those two functions.
Syntax Rose::BinaryAnalysis::SRecord::syntax | ( | ) | const |
Property: syntax family.
This is a read-only property computed from the record type.
|
inline |
|
inline |
Property: record starting address.
Note that Intel S-Record addresses are only partially specified in the individual S-Records; the actual full address depends on the S-Records that came before it. This property is only the partial address for Intel S-Records.
See also, RunLengthEncoding::dataAddress to get the fully specified address.
|
inline |
Property: record starting address.
Note that Intel S-Record addresses are only partially specified in the individual S-Records; the actual full address depends on the S-Records that came before it. This property is only the partial address for Intel S-Records.
See also, RunLengthEncoding::dataAddress to get the fully specified address.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
static |
Parse a hexadecimal string to an unsigned integer.
The parsing looks at characters of the string starting at the specified offset and continuing for the specified number of characters. Each character in that range must be a valid hexadecimal digit representing four bits of the result in big-endian order. Returns the unsigned value if successful, or nothing if a syntax error, short read, or overflow is encountered.
|
static |
Size of address in bytes.
The address is encoded in twice as many ASCII characters.
|
static |
Compute a checksum for part of a record.
Given a string, compute the checksum for the hexadecimal characters starting with the specified start
offset and continuing for n
characters. All characters in the range must be hexadecimal digits, and n
must be even.