Validated Intel HEX and Motorola S-record firmware image toolkit
let parsed = @firmware.parse_firmware_image(
":03001000010203E7\n:00000001FF",
).unwrap()
let image = parsed.image()
println(@firmware.render_statistics_text(@firmware.analyze_image(image)))pub struct AuditFinding {
code_value : String
severity_value : AuditSeverity
message_value : String
address_value : UInt64?
} derive(Eq, Debug)fn AuditPolicy::new(max_gap_bytes? : UInt64?, allowed_start? : UInt64?, allowed_end_exclusive? : UInt64?, max_segments? : Int?, max_total_bytes? : Int?, require_entry_in_data? : Bool) -> Result[AuditPolicy, FirmwareError]pub struct ByteDifference {
address_value : UInt64
kind_value : ByteDifferenceKind
left_value : Byte?
right_value : Byte?
} derive(Eq, Debug)pub struct DocumentStatistics {
format_value : FirmwareFormat
total_records_value : Int
data_records_value : Int
metadata_records_value : Int
data_bytes_value : Int
largest_data_record_value : Int
entry_point_value : UInt64?
has_header_value : Bool
declared_data_records_value : Int?
category_values : Array[RecordCategoryStatistics]
} derive(Eq, Debug)pub struct FirmwareBatch {
item_values : Array[FirmwareBatchItem]
success_count_value : Int
failure_count_value : Int
total_bytes_value : Int
} derive(Eq, Debug)pub struct FirmwareBatchItem {
label_value : String
format_value : FirmwareFormat?
image_value : FirmwareImage?
error_value : FirmwareError?
} derive(Eq, Debug)fn FirmwareChunk::create(address : UInt64, data : Bytes, line_index? : Int) -> Result[FirmwareChunk, FirmwareError]pub struct FirmwareError {
code_value : String
message_value : String
position_value : SourcePosition
} derive(Eq, Debug)fn FirmwareError::new(code : FirmwareErrorCode, message : String, position : SourcePosition) -> FirmwareErrorpub(all) enum FirmwareErrorCode {
HexOddLength
HexInvalidDigit
RecordEmpty
RecordInvalidPrefix
RecordInvalidType
RecordLengthMismatch
RecordTooLong
ChecksumMismatch
AddressOutOfRange
ImageOverlap
ImageInvalidRange
IntegrityViolation
DocumentMissingTerminator
DocumentRecordAfterTerminator
DocumentDuplicateMetadata
} derive(Eq, Debug)pub struct FirmwareImage {
segment_values : Array[ImageSegment]
entry_point_value : UInt64?
} derive(Eq, Debug)fn FirmwareImage::coverage(self : FirmwareImage, start : UInt64, end_exclusive : UInt64) -> Result[RangeCoverage, FirmwareError]fn FirmwareImage::erase(self : FirmwareImage, start : UInt64, end_exclusive : UInt64) -> Result[FirmwareImage, FirmwareError]fn FirmwareImage::fill_gaps(self : FirmwareImage, value : Byte, max_fill_bytes : Int) -> Result[FirmwareImage, FirmwareError]fn FirmwareImage::from_chunks(chunks : Array[FirmwareChunk], policy? : OverlapPolicy, entry_point? : UInt64?) -> Result[FirmwareImage, FirmwareError]fn FirmwareImage::from_intel_document(document : IntelHexDocument, policy? : OverlapPolicy) -> Result[FirmwareImage, FirmwareError]fn FirmwareImage::from_srecord_document(document : SRecordDocument, policy? : OverlapPolicy) -> Result[FirmwareImage, FirmwareError]fn FirmwareImage::merge(self : FirmwareImage, other : FirmwareImage, policy? : OverlapPolicy) -> Result[FirmwareImage, FirmwareError]fn FirmwareImage::read_range(self : FirmwareImage, start : UInt64, length : Int, missing : MissingBytePolicy, max_bytes : Int) -> Result[Bytes, FirmwareError]fn FirmwareImage::relocate(self : FirmwareImage, new_base : UInt64) -> Result[FirmwareImage, FirmwareError]fn FirmwareImage::slice(self : FirmwareImage, start : UInt64, end_exclusive : UInt64) -> Result[FirmwareImage, FirmwareError]fn FirmwareImage::to_intel_hex(self : FirmwareImage, record_bytes? : Int) -> Result[String, FirmwareError]fn FirmwareImage::to_srecord(self : FirmwareImage, record_bytes? : Int, header? : String) -> Result[String, FirmwareError]fn FirmwareImage::write(self : FirmwareImage, address : UInt64, data : Bytes) -> Result[FirmwareImage, FirmwareError]pub struct FirmwareInput {
label_value : String
text_value : String
format_value : FirmwareFormat?
policy_value : OverlapPolicy
} derive(Eq, Debug)fn FirmwareInput::new(label : String, text : String, format? : FirmwareFormat?, policy? : OverlapPolicy) -> FirmwareInputpub struct ImageAudit {
finding_values : Array[AuditFinding]
segment_count_value : Int
total_bytes_value : Int
gap_count_value : Int
} derive(Eq, Debug)pub struct ImageComparison {
difference_values : Array[ByteDifference]
added_count_value : Int
removed_count_value : Int
changed_count_value : Int
} derive(Eq, Debug)pub struct ImageLayout {
placement_values : Array[SegmentPlacement]
mapped_bytes_value : UInt64
unmapped_bytes_value : UInt64
fully_mapped_segments_value : Int
partially_mapped_segments_value : Int
unmapped_segments_value : Int
entry_region_value : String?
entry_was_present_value : Bool
} derive(Eq, Debug)pub struct ImageManifest {
segment_digest_values : Array[SegmentDigest]
total_bytes_value : Int
entry_point_value : UInt64?
fingerprint_value : UInt
} derive(Eq, Debug)fn ImagePatch::apply(self : ImagePatch, source : FirmwareImage) -> Result[FirmwareImage, FirmwareError]pub struct IntelHexDocument {
record_values : Array[IntelHexRecord]
chunk_values : Array[FirmwareChunk]
entry_point_value : UInt64?
} derive(Eq, Debug)pub struct IntelHexRecord {
record_type_value : IntelRecordType
address_value : Int
data_value : Bytes
checksum_value : Byte
line_index_value : Int
} derive(Eq, Debug)fn MemoryMap::region_containing_range(self : MemoryMap, start : UInt64, end_exclusive : UInt64) -> MemoryRegion?fn MemoryRegion::contains_range(self : MemoryRegion, start : UInt64, end_exclusive : UInt64) -> Boolfn MemoryRegion::create(name : String, start : UInt64, end_exclusive : UInt64, writable? : Bool, executable? : Bool) -> Result[MemoryRegion, FirmwareError]pub struct ParsedFirmware {
format_value : FirmwareFormat
image_value : FirmwareImage
record_count_value : Int
} derive(Eq, Debug)pub struct SRecord {
record_type_value : SRecordType
address_value : UInt64
data_value : Bytes
checksum_value : Byte
line_index_value : Int
} derive(Eq, Debug)fn checksum_sum(bytes : Bytes) -> Intfn compare_images(left : FirmwareImage, right : FirmwareImage, max_differences? : Int) -> Result[ImageComparison, FirmwareError]fn crc16_ccitt_false(data : Bytes) -> Intfn create_image_patch(source : FirmwareImage, target : FirmwareImage, max_differences? : Int) -> Result[ImagePatch, FirmwareError]fn decode_firmware_chunks(chunks : Array[Bytes], format? : FirmwareFormat?, policy? : OverlapPolicy, max_line_bytes? : Int) -> Result[ParsedFirmware, FirmwareError]fn encode_hex_bytes(bytes : Bytes) -> Stringfn ones_complement_checksum(bytes : Bytes) -> Bytefn ones_complement_valid(bytes : Bytes) -> Boolfn parse_firmware_image(text : String, format? : FirmwareFormat?, policy? : OverlapPolicy) -> Result[ParsedFirmware, FirmwareError]fn parse_intel_hex_record(line : String, line_index? : Int) -> Result[IntelHexRecord, FirmwareError]fn twos_complement_checksum(bytes : Bytes) -> Bytefn twos_complement_valid(bytes : Bytes) -> BoolValidated Intel HEX and Motorola S-record firmware image toolkit