Exemplo n.º 1
0
        private void FindHeader(Image_Resource_Directory resourceDir)
        {
            int entryCount = resourceDir.NumberOfIdEntries + resourceDir.NumberOfNamedEntries;

            for (int i = 0; i < entryCount; i++)
            {
                Image_Resource_Directory_Entry entry = resourceDir.ImageResourceDirectoryEntries[i];
                if ((entry.OffsetToData & 0x80000000) != 0)
                {
                    Image_Resource_Directory child = (Image_Resource_Directory)entry.ChildEntry;
                    FindHeader(child);
                }
                else
                {
                    Image_Resource_Data_Entry data = (Image_Resource_Data_Entry)entry.ChildEntry;
                    ICON_HEADER      hd            = new ICON_HEADER(data.Data);
                    ICON_DIRECTORY[] ds            = new ICON_DIRECTORY[hd.Count];
                    for (int j = 0; j < ds.Length; j++)
                    {
                        ds[j] = new ICON_DIRECTORY(data.Data, 6 + j * 14);
                        if (ds[j].IConID == this.ID)
                        {
                            Header    = hd;
                            Directory = ds[j];
                            return;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 public IMAGE_CURSOR(byte[] buff, Image_Resource_Directory resourceDir, int cursorID)
 {
     ID       = cursorID;
     FileBody = buff;
     FindHeader(resourceDir);
     FileHeader = new CURSOR_FILE_HEADER(Header);
     InfoHeader = new CURSOR_INFO_HEADER(Directory);
 }
Exemplo n.º 3
0
 public IMAGE_ICON(byte[] buff, Image_Resource_Directory resourceDir, int iconID)
 {
     ID       = iconID;
     FileBody = buff;
     FindHeader(resourceDir);
     FileHeader = new ICON_FILE_HEADER(Header);
     InfoHeader = new ICON_INFO_HEADER(Directory);
 }
Exemplo n.º 4
0
        public Image_Resource_Data_Entry(byte[] buff, PEFileInfo fileInfo, long rootOffset, int resType, int id, int language)
        {
            Type     = resType;
            ID       = id;
            Language = language;

            OffsetToData = (0xffffffff & buff[0]) +
                           ((0xffffffff & buff[1]) << 8) +
                           ((0xffffffff & buff[2]) << 16) +
                           ((0xffffffff & buff[3]) << 24);
            Size = (0xffffffff & buff[4]) +
                   ((0xffffffff & buff[5]) << 8) +
                   ((0xffffffff & buff[6]) << 16) +
                   ((0xffffffff & buff[7]) << 24);
            CodePage = (0xffffffff & buff[8]) +
                       ((0xffffffff & buff[9]) << 8) +
                       ((0xffffffff & buff[10]) << 16) +
                       ((0xffffffff & buff[11]) << 24);
            Reversed = (0xffffffff & buff[12]) +
                       ((0xffffffff & buff[13]) << 8) +
                       ((0xffffffff & buff[14]) << 16) +
                       ((0xffffffff & buff[15]) << 24);

            fileInfo.pFileStream.Position = rootOffset + OffsetToData - fileInfo.SectionVirtualAddress;
            Data = new byte[Size];
            int len = fileInfo.pFileStream.Read(Data, 0, (int)Size);

            switch (resType)
            {
            case 1:      // 光标
            {
                byte[] resHeader = new byte[16];
                fileInfo.pFileStream.Position = rootOffset;
                len = fileInfo.pFileStream.Read(resHeader, 0, 16);
                int entryNumber = (Int32)(((0xffff & resHeader[13]) << 8) + resHeader[12]) + (Int32)(((0xffff & resHeader[15]) << 8) + resHeader[14]);

                byte[] entries = new byte[8 * entryNumber];
                len = fileInfo.pFileStream.Read(entries, 0, 8 * entryNumber);

                UInt32 address = 0;

                for (int i = 0; i < entryNumber; i++)
                {
                    UInt32 name = (0xffffffff & entries[8 * i]) +
                                  ((0xffffffff & entries[8 * i + 1]) << 8) +
                                  ((0xffffffff & entries[8 * i + 2]) << 16) +
                                  ((0xffffffff & entries[8 * i + 3]) << 24);
                    if (name == 12)
                    {
                        address = (0xffffffff & entries[8 * i + 4]) +
                                  ((0xffffffff & entries[8 * i + 5]) << 8) +
                                  ((0xffffffff & entries[8 * i + 6]) << 16) +
                                  ((0xffffffff & entries[8 * i + 7]) << 24);
                        break;
                    }
                }
                Image_Resource_Directory iRD = new Image_Resource_Directory(fileInfo, (address & 0x7fffffff) + rootOffset, rootOffset, 1, 12, 0, 0);
                Instance = new IMAGE_CURSOR(Data, iRD, ID);
                break;
            }

            case 3:      // 图标
            {
                byte[] resHeader = new byte[16];
                fileInfo.pFileStream.Position = rootOffset;
                len = fileInfo.pFileStream.Read(resHeader, 0, 16);
                int entryNumber = (Int32)(((0xffff & resHeader[13]) << 8) + resHeader[12]) + (Int32)(((0xffff & resHeader[15]) << 8) + resHeader[14]);

                byte[] entries = new byte[8 * entryNumber];
                len = fileInfo.pFileStream.Read(entries, 0, 8 * entryNumber);

                UInt32 address = 0;

                for (int i = 0; i < entryNumber; i++)
                {
                    UInt32 name = (0xffffffff & entries[8 * i]) +
                                  ((0xffffffff & entries[8 * i + 1]) << 8) +
                                  ((0xffffffff & entries[8 * i + 2]) << 16) +
                                  ((0xffffffff & entries[8 * i + 3]) << 24);
                    if (name == 14)
                    {
                        address = (0xffffffff & entries[8 * i + 4]) +
                                  ((0xffffffff & entries[8 * i + 5]) << 8) +
                                  ((0xffffffff & entries[8 * i + 6]) << 16) +
                                  ((0xffffffff & entries[8 * i + 7]) << 24);
                        break;
                    }
                }
                Image_Resource_Directory iRD = new Image_Resource_Directory(fileInfo, rootOffset + (address & 0x7fffffff), rootOffset, 1, 14, 0, 0);
                Instance = new IMAGE_ICON(Data, iRD, ID);
                break;
            }

            case 12:      // 组光标
            {
                Instance = new GROUP_CURSOR(Data);
                break;
            }

            case 14:      // 组图标
            {
                Instance = new GROUP_ICON(Data);
                break;
            }

            default:
            {
                Instance = null;
                break;
            }
            }
        }