import {S19MemoryMap} from 'ECB';

let memMap1 = new S19MemoryMap();
let memMap2 = new S19MemoryMap([[0, new Buffer(1,2,3,4)]]);
let memMap3 = new S19MemoryMap({0: new Buffer(1,2,3,4)});
let memMap4 = new S19MemoryMap({0xCF0: new Buffer(1,2,3,4)});

const block = S19MemoryMap.fromS19(s19Text);

Constructors

  • Parameters

    • Optionalblocks: null | Iterable<[number, Buffer]> | { [key: string]: Buffer }

      The initial value for the memory blocks inside this S19MemoryMap. 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 S19MemoryMap

Accessors

  • get size(): number
  • Returns number

Methods

  • Returns IterableIterator<[number, Buffer]>

  • Returns a String of text representing a .s19 file.
    The writer has an opinionated behaviour. Automatically chooses between S1 (16-bit), S2 (24-bit), and S3 (32-bit) records based on the maximum address. Uses S2 if any address exceeds 0xFFFF, S3 if any address exceeds 0xFFFFFF.

    Parameters

    • OptionallineSize: number = 16

      Maximum number of bytes to be encoded in each data record. Must have a value between 1 and 255, as per the specification.

    Returns string

    String of text with the .s19 representation of the input binary data

    import {S19MemoryMap} from 'ECB';

    let memMap = new S19MemoryMap();
    let bytes = new Buffer(....);
    memMap.set(0x0FF80000, bytes); // The block with 'bytes' will start at offset 0x0FF80000

    let string = memMap.asS19String();
  • Returns void

  • Performs a deep copy of the current S19MemoryMap, returning a new one with exactly the same contents, but allocating new memory for each of its Buffers.

    Returns S19MemoryMap

  • Checks whether the current memory map contains the one given as a parameter.


    "Contains" means that all the offsets that have a byte value in the given memory map have a value in the current memory map, and that the byte values are the same.
    An empty memory map is always contained in any other memory map.
    Returns boolean true if the memory map is contained, false otherwise.

    Parameters

    Returns boolean

  • Parameters

    • addr: number

    Returns boolean

  • Returns IterableIterator<[number, Buffer]>

  • Parameters

    • callback: (value: Buffer, key: number, map: Map<number, Buffer>) => void
    • OptionalthisArg: any

    Returns void

  • Parameters

    • addr: number

    Returns undefined | Buffer

  • Locates the Buffer which contains the given offset, and returns the four bytes held at that offset, as a 32-bit unsigned integer.


    Behaviour is similar to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32|DataView.prototype.getUint32, except that this operates over a S19MemoryMap instead of over an ArrayBuffer, and that this may return undefined if the address is not entirely contained within one of the Buffers.

    Parameters

    • offset: number

      The memory offset to read the data

    • OptionallittleEndian: boolean

      Whether to fetch the 4 bytes as a little- or big-endian integer

    Returns undefined | number

    An unsigned 32-bit integer number

  • Parameters

    • addr: number

    Returns boolean

  • Returns a new instance of S19MemoryMap, containing the same data, but concatenating together those memory blocks that are adjacent.
    The insertion order of keys in the S19MemoryMap is guaranteed to be strictly ascending. In other words, when iterating through the S19MemoryMap, 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 S19MemoryMap might have more entries than the input one.
    If there is any overlap between blocks, an error will be thrown.
    The returned S19MemoryMap will use newly allocated memory.

    Parameters

    • OptionalmaxBlockSize: number = Infinity

      Maximum size of the Buffers in the returned S19MemoryMap.

    Returns S19MemoryMap

  • Returns IterableIterator<number>

  • Returns a new instance of S19MemoryMap, where:

    • Each key (the start address of each Buffer) is a multiple of pageSize
    • The size of each Buffer is exactly pageSize
    • Bytes from the input map to bytes in the output
    • Bytes not in the input are replaced by a padding value

    The scenario is wanting to prepare pages of bytes for a write operation, where the write operation affects a whole page/sector at once.
    The insertion order of keys in the output S19MemoryMap is guaranteed to be strictly ascending. In other words, when iterating through the S19MemoryMap, the addresses will be ordered in ascending order.
    The Buffers in the output will be newly allocated.

    Parameters

    • OptionalpageSize: number = 1024

      The size of the output pages, in bytes

    • Optionalpad: number = 0xff

      The byte value to use for padding

    Returns S19MemoryMap

  • Parameters

    • addr: number
    • value: Buffer

    Returns Map<number, Buffer>

  • 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 S19MemoryMap will have a value of padByte.


    This method allocates new memory.

    Parameters

    • address: number

      The start address of the slice

    • length: number

      The length of memory map to slice out

    • OptionalpadByte: number = 0xff

      The value of the byte assumed to be used as padding

    Returns Buffer

  • Returns IterableIterator<Buffer>

  • Given the output of the overlapS19MemoryMaps (a Map of address to an Array of (id, Buffer) tuples), returns a S19MemoryMap. 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 .s19 files, not worrying about their overlaps.

    Parameters

    • overlaps: Map<number, [string, Buffer][]>

      The (possibly overlapping) input memory blocks

    Returns S19MemoryMap

    The flattened memory blocks

  • Given one Buffer, looks through its contents and returns a new S19MemoryMap, 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.

    Parameters

    • bytes: Buffer

      The input data

    • OptionalpadByte: number = 0xff

      The value of the byte assumed to be used as padding

    • OptionalminPadLength: number = 64

      The minimum number of consecutive pad bytes to be considered actual padding

    Returns S19MemoryMap

  • Parses a string containing data formatted in "Motorola S-record" format, and returns an instance of S19MemoryMap.
    Supports S0 (header), S1 (16-bit data), S2 (24-bit data), S3 (32-bit data), S5/S6 (count), S7/S8/S9 (end) records.
    The insertion order of keys in the S19MemoryMap is guaranteed to be strictly ascending. In other words, when iterating through the S19MemoryMap, 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.
    If maxBlockSize is given, any contiguous data block larger than that will be split in several blocks.

    Parameters

    • s19Text: string

      The contents of a .s19 file.

    • OptionalmaxBlockSize: number = Infinity

      Maximum size of the returned Buffers.

    Returns S19MemoryMap

    import {S19MemoryMap} from 'ECB';

    let srecordString =
    "S00F000068656C6C6F202020202000003C\n" +
    "S11F00007C0802A6900100049421FFF07C6C1B787C8C23784E800020E8010010C\n" +
    "S5030001FB\n" +
    "S9030000FC";

    let memMap = S19MemoryMap.fromS19(srecordString);

    for (let [address, dataBlock] of memMap) {
    console.log('Data block at ', address, ', bytes: ', dataBlock);
    }
  • Given a https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map|Map of S19MemoryMaps, 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 S19MemoryMaps, from several calls to module:ECB~s19ToArrays|s19ToArrays, 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.

    Parameters

    • S19MemoryMaps: Map<string, S19MemoryMap>

      The input memory block sets

    Returns Map<any, any>

    The map of possibly overlapping memory blocks