public byte[] HexStringToBytes(string hexPattern) { return(BytePattern.FromHexBytes(hexPattern) .ToArray()); }
public void Given_HexString(string hexbytes) { var bytes = BytePattern.FromHexBytes(hexbytes).ToArray(); this.mem = Architecture.CreateMemoryArea(LoadAddress, bytes); }
public void Given_OctalBytes(string octalBytes) { var bytes = BytePattern.FromHexBytes(octalBytes).ToArray(); this.mem = new MemoryArea(LoadAddress, bytes); }
protected virtual TInstruction DisassembleHexBytes(string hexBytes) { byte[] instr = BytePattern.FromHexBytes(hexBytes); return(DisassembleBytes(instr)); }
public MaskedPattern LoadMaskedPattern(BytePattern_v1 sPattern) { List <byte> bytes = null; List <byte> mask = null; if (sPattern.Bytes == null) { return(null); } if (sPattern.Mask == null) { bytes = new List <byte>(); mask = new List <byte>(); int shift = 4; int bb = 0; int mm = 0; for (int i = 0; i < sPattern.Bytes.Length; ++i) { char c = sPattern.Bytes[i]; byte b; if (BytePattern.TryParseHexDigit(c, out b)) { bb = bb | (b << shift); mm = mm | (0x0F << shift); shift -= 4; if (shift < 0) { bytes.Add((byte)bb); mask.Add((byte)mm); shift = 4; bb = mm = 0; } } else if (c == '?' || c == '.') { shift -= 4; if (shift < 0) { bytes.Add((byte)bb); mask.Add((byte)mm); shift = 4; bb = mm = 0; } } } Debug.Assert(bytes.Count == mask.Count); } else { bytes = BytePattern.FromHexBytes(sPattern.Bytes); mask = BytePattern.FromHexBytes(sPattern.Mask); } if (bytes.Count == 0) { return(null); } else { return new MaskedPattern { Bytes = bytes.ToArray(), Mask = mask.ToArray() } }; }
public SrecRecord?ParseRecord() { string line; do { line = rdr.ReadLine(); if (line is null) { return(null); } } while (line.Length < 3 || line[0] != 'S'); var bytes = BytePattern.FromHexBytes(line.Substring(2)); //$PERF: use Span<T>. if (bytes.Length < 2) { throw new BadImageFormatException("Bad line format."); } int dataOffset; SrecType type; Address addr; var ch = line[1]; switch (ch) { default: throw new BadImageFormatException($"Unexpected character '{(char) ch}' (U+{ch:X4})."); case '0': type = SrecType.Header; addr = ReadAddress(bytes, 2, u => Address.Ptr16((ushort)u)); dataOffset = 2 + 1; break; case '1': type = SrecType.Data16; addr = ReadAddress(bytes, 2, u => Address.Ptr16((ushort)u)); dataOffset = 2 + 1; break; case '2': type = SrecType.Data24; addr = ReadAddress(bytes, 3, Address.Ptr32); dataOffset = 3 + 1; break; case '3': type = SrecType.Data32; addr = ReadAddress(bytes, 4, Address.Ptr32); dataOffset = 1 + 4; break; case '9': return(ParseStartAddress(bytes, 2, Addr16)); } var nBytes = bytes.Length - dataOffset - 1; var data = new byte[nBytes]; Array.Copy(bytes, dataOffset, data, 0, nBytes); return(new SrecRecord { Type = type, Address = addr, Data = data, }); }
private void Given_TypeSection(string hexbytes) { this.typeSection = BytePattern.FromHexBytes(hexbytes).ToArray(); }