Optionalblocks: The initial value for the memory blocks inside this HexMemoryMap. All keys must be numeric, and all values must be instances of Buffer. Optionally it can also be a plain Object with only numeric keys.
Returns a String of text representing a .hex file.
The writer has an opinionated behaviour. Check the project's
file for details.
OptionallineSize: number = 16Maximum number of bytes to be encoded in each data record. Must have a value between 1 and 255, as per the specification.
String of text with the .hex representation of the input binary data
Performs a deep copy of the current HexMemoryMap, returning a new one
with exactly the same contents, but allocating new memory for each of its
Buffers.
Checks whether the current memory map contains the one given as a parameter.
The memory map to check
Locates the Buffer which contains the given offset, and returns the four bytes held at that offset, as a 32-bit unsigned integer.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32|DataView.prototype.getUint32,
except that this operates over a HexMemoryMap instead of
over an ArrayBuffer, and that this may return undefined if
the address is not entirely contained within one of the Buffers.
The memory offset to read the data
OptionallittleEndian: booleanWhether to fetch the 4 bytes as a little- or big-endian integer
An unsigned 32-bit integer number
Returns a new instance of HexMemoryMap, containing
the same data, but concatenating together those memory blocks that are adjacent.
The insertion order of keys in the HexMemoryMap is guaranteed to be strictly
ascending. In other words, when iterating through the HexMemoryMap, the addresses
will be ordered in ascending order.
If maxBlockSize is given, blocks will be concatenated together only
until the joined block reaches this size in bytes. This means that the output
HexMemoryMap might have more entries than the input one.
If there is any overlap between blocks, an error will be thrown.
The returned HexMemoryMap will use newly allocated memory.
OptionalmaxBlockSize: number = InfinityMaximum size of the Buffers in the
returned HexMemoryMap.
Returns a new instance of HexMemoryMap, where:
HexMemoryMap is guaranteed
to be strictly ascending. In other words, when iterating through the
HexMemoryMap, the addresses will be ordered in ascending order.
OptionalpageSize: number = 1024The size of the output pages, in bytes
Optionalpad: number = 0xffThe byte value to use for padding
Returns a new instance of HexMemoryMap, containing only data between
the addresses address and address + length.
Behaviour is similar to https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/slice|Array.prototype.slice,
in that the return value is a portion of the current HexMemoryMap.
HexMemoryMap might be empty.
The start address of the slice
The length of memory map to slice out
Returns a new instance of https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32|Buffer, containing only data between
the addresses address and address + length. Any byte without a value
in the input HexMemoryMap will have a value of padByte.
The start address of the slice
The length of memory map to slice out
OptionalpadByte: number = 0xffThe value of the byte assumed to be used as padding
StaticflattenGiven the output of the overlapHexMemoryMaps
(a Map of address to an Array of (id, Buffer) tuples),
returns a HexMemoryMap. This discards the IDs in the process.
The output Map contains as many entries as the input one (using the same addresses
as keys), but the value for each entry will be the Buffer of the last
tuple for each address in the input data.
The scenario is wanting to join together several parsed .hex files, not worrying about
their overlaps.
The (possibly overlapping) input memory blocks
The flattened memory blocks
StaticfromParses a string containing data formatted in "Intel HEX" format, and
returns an instance of HexMemoryMap.
The insertion order of keys in the HexMemoryMap is guaranteed to be strictly
ascending. In other words, when iterating through the HexMemoryMap, the addresses
will be ordered in ascending order.
The parser has an opinionated behaviour, and will throw a descriptive error if it
encounters some malformed input. Check the project's
file for details.
If maxBlockSize is given, any contiguous data block larger than that will
be split in several blocks.
The contents of a .hex file.
OptionalmaxBlockSize: number = InfinityMaximum size of the returned Buffers.
StaticfromGiven one Buffer, looks through its contents and returns a new
HexMemoryMap, stripping away those regions where there are only
padding bytes.
The start of the input Buffer is assumed to be offset zero for the output.
The use case here is dumping memory from a working device and try to see the
"interesting" memory regions it has. This assumes that there is a constant,
predefined padding byte value being used in the "non-interesting" regions.
In other words: this will work as long as the dump comes from a flash memory
which has been previously erased (thus 0xFFs for padding), or from a
previously blanked HDD (thus 0x00s for padding).
This method uses subarray on the input data, and thus does not allocate memory
for the Buffers.
The input data
OptionalpadByte: number = 0xffThe value of the byte assumed to be used as padding
OptionalminPadLength: number = 64The minimum number of consecutive pad bytes to be considered actual padding
StaticoverlapGiven a https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map|Map
of HexMemoryMaps, indexed by a alphanumeric ID,
returns a Map of address to tuples (Arrayss of length 2) of the form
(id, Buffer)s.
The scenario for using this is having several HexMemoryMaps, from several calls to
module:ECB~hexToArrays|hexToArrays, each having a different identifier.
This function locates where those memory block sets overlap, and returns a Map
containing addresses as keys, and arrays as values. Each array will contain 1 or more
(id, Buffer) tuples: the identifier of the memory block set that has
data in that region, and the data itself. When memory block sets overlap, there will
be more than one tuple.
The Buffers in the output are
https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray|subarrays
of the input data; new memory is not allocated for them.
The insertion order of keys in the output Map is guaranteed to be strictly
ascending. In other words, when iterating through the Map, the addresses
will be ordered in ascending order.
When two blocks overlap, the corresponding array of tuples will have the tuples ordered
in the insertion order of the input Map of block sets.
The input memory block sets
The map of possibly overlapping memory blocks
import {HexMemoryMap} from 'ECB';
let memMap1 = HexMemoryMap.fromHex( hexdata1 );
let memMap2 = HexMemoryMap.fromHex( hexdata2 );
let memMap3 = HexMemoryMap.fromHex( hexdata3 );
let maps = new Map([
['file A', blocks1],
['file B', blocks2],
['file C', blocks3]
]);
let overlappings = HexMemoryMap.overlapHexMemoryMaps(maps);
for (let [address, tuples] of overlappings) {
// if 'tuples' has length > 1, there is an overlap starting at 'address'
for (let [address, tuples] of overlappings) {
let [id, bytes] = tuple;
// 'id' in this example is either 'file A', 'file B' or 'file C'
}
}
Example