Exemplo n.º 1
0
        private void LoadFileTable()
        {
            if (_loadedImages != null)
            {
                return;
            }

            ElfNote fileNote = GetNotes(ElfNoteType.File).Single();

            long position             = 0;
            ElfFileTableHeader header = fileNote.ReadContents <ElfFileTableHeader>(ref position);

            ElfFileTableEntryPointers[]         fileTable = new ElfFileTableEntryPointers[header.EntryCount.ToInt32()];
            List <ElfLoadedImage>               images    = new List <ElfLoadedImage>(fileTable.Length);
            Dictionary <string, ElfLoadedImage> lookup    = new Dictionary <string, ElfLoadedImage>(fileTable.Length);

            for (int i = 0; i < fileTable.Length; i++)
            {
                fileTable[i] = fileNote.ReadContents <ElfFileTableEntryPointers>(ref position);
            }

            long size = fileNote.Header.ContentSize - position;

            byte[] bytes = fileNote.ReadContents(position, (int)size);
            int    start = 0;

            for (int i = 0; i < fileTable.Length; i++)
            {
                int end = start;
                while (bytes[end] != 0)
                {
                    end++;
                }

                string path = Encoding.ASCII.GetString(bytes, start, end - start);
                start = end + 1;

                if (!lookup.TryGetValue(path, out ElfLoadedImage image))
                {
                    image = lookup[path] = new ElfLoadedImage(path);
                }

                image.AddTableEntryPointers(fileTable[i]);
            }

            _loadedImages = lookup.Values.OrderBy(i => i.BaseAddress).ToArray();
        }
Exemplo n.º 2
0
        internal void AddTableEntryPointers(ElfFileTableEntryPointers pointers)
        {
            _fileTable.Add(pointers);

            long start = pointers.Start.ToInt64();

            if (BaseAddress == 0 || start < BaseAddress)
            {
                BaseAddress = start;
            }

            long end = pointers.Stop.ToInt64();

            if (_end < end)
            {
                _end = end;
            }
        }