private void _disassemble() { Records = new List <InstructionRecord>(); var sectionsToLoad = _elf.GetSections <ProgBitsSection <uint> >() .Where(x => x.Type == SectionType.ProgBits && x.Flags.HasFlag(SectionFlags.Executable)); foreach (var s in sectionsToLoad) { var stream = new MemoryStream(s.GetContents()); var reader = new SimpleEndianessAwareReader(stream, _elf.Endianess); uint position = 0; while (position < s.Size) { var address = s.LoadAddress + position; var chunk = BitArrayFactory.FromUnsignedInt( reader.ReadUInt32(), InstructionSize * 8 ); var instruction = _instructionSet.Resolve(chunk) ?? new Instruction("UNKNOWN"); instruction.Position = address; instruction.Data = chunk; Records.Add( new InstructionRecord(s.Name, address, instruction) ); position += InstructionSize; } } }
public void BitArrayFactory_InvalidSize() { try { BitArrayFactory.Create(-1); Assert.Fail(); } catch (ArgumentOutOfRangeException) { } }
public void BitArray_ManOrBoy_Set() { for (var capacity = 0; capacity < 100; capacity++) { for (var i = 0; i < capacity; i++) { var arr = BitArrayFactory.Create(capacity); arr[i] = true; for (var j = 0; j < capacity; j++) { Assert.AreEqual(arr[j], i == j); } } } }
public void BitArray_SetAll() { for (var capacity = 0; capacity < 100; capacity++) { for (var i = 0; i < capacity; i++) { var arr = BitArrayFactory.Create(capacity); arr.SetAll(true); for (var j = 0; j < capacity; j++) { Assert.AreEqual(arr[j], true); } arr.SetAll(false); for (var j = 0; j < capacity; j++) { Assert.AreEqual(arr[j], false); } // The difference from above is that we set all to false first then set to true arr = BitArrayFactory.Create(capacity); arr.SetAll(false); for (var j = 0; j < capacity; j++) { Assert.AreEqual(arr[j], false); } arr.SetAll(true); for (var j = 0; j < capacity; j++) { Assert.AreEqual(arr[j], true); } } } }
public void BitArray_Factory_ReturnsCorrectlySizedType() { // i = 0 is hoisted out var arr = BitArrayFactory.Create(0); Assert.AreEqual(arr.Count, 0); for (int i = 1; i < 100; i++) { arr = BitArrayFactory.Create(i); Assert.AreEqual(arr.Count, i); arr[i - 1] = true; try { arr[i] = false; Assert.Fail(); } catch (ArgumentOutOfRangeException) { } } }
public void BitArray_EdgeCases() { // i = 0 is hoisted out var arr = BitArrayFactory.Create(0); try { var dummy = arr[0]; Assert.Fail(); } catch (ArgumentOutOfRangeException) { } for (int i = 1; i < 100; i++) { arr = BitArrayFactory.Create(i); try { var dummy = arr[-1]; Assert.Fail(); } catch (ArgumentOutOfRangeException) { } try { var dummy = arr[i]; Assert.Fail(); } catch (ArgumentOutOfRangeException) { } } }
public Opcode(uint value, ushort size, ushort offset = 0) { Value = BitArrayFactory.FromUnsignedInt(value, size); Offset = offset; }