internal ResourceDirectoryEntry(PeImage image, uint offset, Structures.IMAGE_RESOURCE_DIRECTORY_ENTRY rawEntry, string customName)
 {
     this._image = image;
     this._offset = offset;
     this._rawEntry = rawEntry;
     this._customName = customName;
 }
Exemple #2
0
 internal LibraryReference(PeImage image, uint offset, Structures.IMAGE_IMPORT_DESCRIPTOR rawDescriptor, string libraryName, ImportMethod[] importMethods)
 {
     this._image = image;
     this._offset = offset;
     this._rawDescriptor = rawDescriptor;
     this.LibraryName = libraryName;
     this.ImportMethods = importMethods;
 }
Exemple #3
0
 internal ResourceDirectory(PeImage image, uint offset, ResourcesReader reader, ResourceDirectoryEntry parentEntry, Structures.IMAGE_RESOURCE_DIRECTORY rawDirectory)
 {
     this._image = image;
     this.ParentEntry = parentEntry;
     this._offset = offset;
     this._fileOffset = offset + image.ParentAssembly._ntHeader.OptionalHeader.DataDirectories[(int)DataDirectoryName.Resource].TargetOffset.FileOffset;
     this._rawDirectory = rawDirectory;
     this._reader = reader;
 }
Exemple #4
0
 internal Section(LWin32 assembly,
     uint headeroffset,
     Structures.IMAGE_SECTION_HEADER rawHeader)
 {
     this._rawHeader = rawHeader;
     this.headeroffset = headeroffset;
     this.assembly = assembly;
     this.HasImage = true;
 }
Exemple #5
0
        internal ResourceDataEntry(PeImage image, uint offset, ResourceDirectoryEntry parentEntry, Structures.IMAGE_RESOURCE_DATA_ENTRY rawDataEntry)
        {
            this._image = image;
            this._offset = offset;
            this.ParentEntry = parentEntry;
            this._rawDataEntry = rawDataEntry;

            Section resourceSection = Section.GetSectionByRva(image.ParentAssembly, image.ParentAssembly._ntHeader.OptionalHeader.DataDirectories[(int)DataDirectoryName.Resource].TargetOffset.Rva);
            _targetOffset = OffsetToData - resourceSection.RVA + resourceSection.RawOffset;
        }
Exemple #6
0
 internal DataDirectory(DataDirectoryName name, Section targetSection, uint headerOffset, Structures.IMAGE_DATA_DIRECTORY rawDataDir)
 {
     this._name = name;
     this._headerOffset = headerOffset;
     this._rawDataDir = rawDataDir;
     if (rawDataDir.RVA == 0 || targetSection == null)
     {
         _targetOffset = new Offset(0, 0, 0);
     }
     else
     {
         this._targetOffset = Offset.FromRva(rawDataDir.RVA, targetSection.ParentAssembly);
         this._targetSection = targetSection;
     }
 }
Exemple #7
0
        internal MetaDataStream(NETHeader netheader, int headeroffset, Structures.METADATA_STREAM_HEADER rawHeader, string name)
        {
            this._headeroffset = headeroffset;
            this._netheader = netheader;
            this._streamHeader = rawHeader;
            this._name = name;
            this._indexsize = 2;

            byte[] contents = netheader._assembly._peImage.ReadBytes(StreamOffset, (int)StreamSize);
            _mainStream = new MemoryStream();
            _binReader = new BinaryReader(_mainStream);
            _binWriter = new BinaryWriter(_mainStream);
            _mainStream.Write(contents, 0, contents.Length);
            _mainStream.Seek(0, SeekOrigin.Begin);
        }
Exemple #8
0
        internal DataDirectory(DataDirectoryName name, Section[] assemblySections, uint offset, Structures.IMAGE_DATA_DIRECTORY rawDataDir)
        {
            this._rawDataDir = rawDataDir;
            this._name = name;
            if (rawDataDir.RVA == 0)
            {
                _targetOffset = new Offset(0, 0, 0);
            }
            else
            {
                this._headerOffset = offset;

                _targetSection = Section.GetSectionByRva(assemblySections, rawDataDir.RVA);
                if (_targetSection == null)
                    this.TargetOffset = new Offset(0, rawDataDir.RVA, 0);
                else
                    this._targetOffset = Offset.FromRva(rawDataDir.RVA, assemblySections[0].ParentAssembly);
            }
        }
Exemple #9
0
 private MetaDataStream GetHeap(NETHeader netheader, int headeroffset, Structures.METADATA_STREAM_HEADER rawHeader, string name)
 {
     switch (name)
     {
         case "#~":
         case "#-":
             return new TablesHeap(netheader, headeroffset, rawHeader, name);
         case "#Strings":
             return new StringsHeap(netheader, headeroffset, rawHeader, name);
         case "#US":
             return new UserStringsHeap(netheader, headeroffset, rawHeader, name);
         case "#GUID":
             return new GuidHeap(netheader, headeroffset, rawHeader, name);
         case "#Blob":
             return new BlobHeap(netheader, headeroffset, rawHeader, name);
         default:
             return new MetaDataStream(netheader, headeroffset, rawHeader, name);
     }
 }
Exemple #10
0
 internal UserStringsHeap(NETHeader netheader, int headeroffset, Structures.METADATA_STREAM_HEADER rawHeader, string name)
     : base(netheader, headeroffset, rawHeader, name)
 {
 }
 private string ReadLibraryName(Structures.IMAGE_IMPORT_DESCRIPTOR rawImportDir)
 {
     uint nameoffset = offsetConverter.RvaToFileOffset(rawImportDir.NameRVA);
     return image.ReadZeroTerminatedString(nameoffset);
 }
        private ImportMethod[] ReadImportMethods(Structures.IMAGE_IMPORT_DESCRIPTOR rawImportDir)
        {
            List<ImportMethod> methods = new List<ImportMethod>();

            int currentIndex = 0;
            uint baseoffset = offsetConverter.RvaToFileOffset(rawImportDir.OriginalFirstThunk);
            uint baseft= offsetConverter.RvaToFileOffset(rawImportDir.FirstThunk);

            while (true)
            {

                uint methodOffset = 0;
                uint ftOffset = 0;

                ulong ofunction = ReadFunctionValue(baseoffset, currentIndex, out methodOffset);
                ulong ft = ReadFunctionValue(baseft, currentIndex, out ftOffset);

                if (ofunction == 0 && ft == 0)
                    break;

                ushort hint = 0;
                string name = ReadFunctionName(ofunction, out hint);

                uint rva = (uint)(rawImportDir.FirstThunk + (currentIndex *(header.OptionalHeader.Is32Bit ? sizeof(uint) : sizeof(ulong))));
                methods.Add(new ImportMethod((uint)ofunction, (uint)ft, rva , hint, name));

                //advance to next function value
                image.SetOffset(methodOffset + (header.OptionalHeader.Is32Bit ? sizeof(uint) : sizeof(ulong)));
                currentIndex++;
            }
            return methods.ToArray();
        }