Esempio n. 1
0
        private void ReadCommands(int noOfCommands, Stream stream, SimpleEndianessAwareReader reader)
        {
            for (var i = 0; i < noOfCommands; i++)
            {
                var loadCommandType = reader.ReadUInt32();
                var commandSize     = reader.ReadUInt32();
                switch ((CommandType)loadCommandType)
                {
                case CommandType.SymbolTable:
                    commands[i] = new SymbolTable(reader, stream, is64);
                    break;

                case CommandType.Main:
                    commands[i] = new EntryPoint(reader, stream);
                    break;

                case CommandType.Segment:
                case CommandType.Segment64:
                    commands[i] = new Segment(reader, stream, is64);
                    break;

                default:
                    reader.ReadBytes((int)commandSize - 8); // 8 bytes is the size of the common command header
                    break;
                }
            }
        }
Esempio n. 2
0
        internal Dylib(SimpleEndianessAwareReader reader, Stream stream, uint commandSize) : base(reader, stream)
        {
            var offset               = reader.ReadUInt32();
            var timestamp            = reader.ReadInt32();
            var currentVersion       = reader.ReadUInt32();
            var compatibilityVersion = reader.ReadUInt32();

            Timestamp            = DateTimeOffset.FromUnixTimeSeconds(timestamp).UtcDateTime;
            CurrentVersion       = GetVersion(currentVersion);
            CompatibilityVersion = GetVersion(compatibilityVersion);
            Name = GetString(reader.ReadBytes((int)(commandSize - offset)));
        }
        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;
                }
            }
        }
Esempio n. 4
0
        internal MachO(Stream stream, bool is64, Endianess endianess, bool ownsStream)
        {
            this.is64 = is64;

            using var reader = new SimpleEndianessAwareReader(stream, endianess, ownsStream);

            Machine = (Machine)reader.ReadInt32();
            reader.ReadBytes(4); // we don't support the cpu subtype now
            FileType = (FileType)reader.ReadUInt32();
            var noOfCommands = reader.ReadInt32();

            reader.ReadInt32();  // size of commands
            reader.ReadBytes(4); // we don't support flags now
            if (is64)
            {
                reader.ReadBytes(4); // reserved
            }
            commands = new Command[noOfCommands];
            ReadCommands(noOfCommands, stream, reader);
        }
Esempio n. 5
0
 public static SegmentType ProbeType(SimpleEndianessAwareReader reader)
 {
     return((SegmentType)reader.ReadUInt32());
 }