Пример #1
0
        private static void WriteEntry2(Region resourceHeader, string type, string data)
        {
            WordToken length = resourceHeader.InsertWordToken();

            resourceHeader.WriteInt16((short)(data.Length + 1)); // w
            resourceHeader.WriteInt16(1);                        // type
            resourceHeader.WriteAsUtf16NullTerminated2(type);
            //padding
            if ((resourceHeader.CurrentLocation.Offset % 4) != 0)
            {
                resourceHeader.WriteInt16(0);
            }
            resourceHeader.WriteAsUtf16NullTerminated2(data);
            //padding
            if ((resourceHeader.CurrentLocation.Offset % 4) != 0)
            {
                resourceHeader.WriteInt16(0);
            }
            length.SetDistanceSinceTaken();
        }
Пример #2
0
        private void WriteVersionHeader()
        {
            Region resourceHeader = writer.AllocateRegion(".rsrc");

            // Resouce Directory Table
            resourceHeader.WriteInt32(0);          //Characteristics
            resourceHeader.WriteInt32(0);          // TimeDateStamp
            resourceHeader.WriteInt16(0);          // mayor version
            resourceHeader.WriteInt16(0);          // minor verson
            resourceHeader.WriteInt16(0);          // number of named entries
            resourceHeader.WriteInt16(1);          // number of id'ed entries
            // Resource Directory Entry
            resourceHeader.WriteInt32(0x10);       // ID (VERSION)
            resourceHeader.WriteInt32(0x80000018); //pointer to next directory
            // Resouce Directory Table
            resourceHeader.WriteInt32(0);          //Characteristics
            resourceHeader.WriteInt32(0);          // TimeDateStamp
            resourceHeader.WriteInt16(0);          // mayor version
            resourceHeader.WriteInt16(0);          // minor verson
            resourceHeader.WriteInt16(0);          // number of named entries
            resourceHeader.WriteInt16(1);          // number of id'ed entries
            // Resource Directory Entry
            resourceHeader.WriteInt32(1);          // ID (1)
            resourceHeader.WriteInt32(0x80000030); //pointer to next directory
            // Resouce Directory Table
            resourceHeader.WriteInt32(0);          //Characteristics
            resourceHeader.WriteInt32(0);          // TimeDateStamp
            resourceHeader.WriteInt16(0);          // mayor version
            resourceHeader.WriteInt16(0);          // minor verson
            resourceHeader.WriteInt16(0);          // number of named entries
            resourceHeader.WriteInt16(1);          // number of id'ed entries
            // Resource Directory Entry
            resourceHeader.WriteInt32(0);          // ID
            resourceHeader.WriteInt32(0x48);       //pointer to leaf
            // Resource Data Entry
            resourceHeader.WritePlaceholderRelative(resourceHeader.CurrentLocation.Increment(0x10));
            IntToken SizeOfResourceBody1 = resourceHeader.InsertIntToken();

            resourceHeader.WriteInt32(0); // codepage (default unicode)
            resourceHeader.WriteInt32(0); // reserved

            long RelativeSizeOfHeader = resourceHeader.CurrentLocation.Offset;

            // struct VS_VERSIONINFO {
            WordToken SizeOfResourceBody2 = resourceHeader.InsertWordToken(); // wLength

            resourceHeader.WriteInt16(0x34);                                  // wValueLength
            resourceHeader.WriteInt16(0);                                     // wType
            resourceHeader.WriteAsUtf16NullTerminated2("VS_VERSION_INFO");
            resourceHeader.WriteInt16(0);                                     // padding1

            // struct VS_FIXEDFILEINFO {
            resourceHeader.WriteInt32(0xFEEF04BD); // dwSignature
            resourceHeader.WriteInt32(0x00010000); // dwStrucVersion
            resourceHeader.WriteInt32(0x00010000); // dwFileVersionMS
            resourceHeader.WriteInt32(0x00000000); // dwFileVersionLS
            resourceHeader.WriteInt32(0x00010000); // dwProductVersionMS
            resourceHeader.WriteInt32(0x00000000); // dwProductVersionLS

            resourceHeader.WriteInt32(0x3f);       // dwFileFlagsMask;
            resourceHeader.WriteInt32(0);          // dwFileFlags;
            resourceHeader.WriteInt32(4);          // dwFileOS;
            resourceHeader.WriteInt32(1);          // dwFileType
            resourceHeader.WriteInt32(0);          // dwFileSubtype
            resourceHeader.WriteInt32(0);          // dwFileDateMS
            resourceHeader.WriteInt32(0);          // dwFileDateLS

            // rest of  //struct VS_VERSIONINFO {
            //  WORD  Padding2[];
            //WORD  Children[];

            WordToken varFileInfo = WriteEntry(resourceHeader, 0, 1, "VarFileInfo");
            WordToken translation = WriteEntry(resourceHeader, 4, 0, "Translation");

            resourceHeader.WriteInt32(0x04B00000); // codepage unicode
            translation.SetDistanceSinceTaken();
            varFileInfo.SetDistanceSinceTaken();
            WordToken varStringFileInfo = WriteEntry(resourceHeader, 0, 1, "StringFileInfo");
            WordToken varVersion        = WriteEntry(resourceHeader, 0, 1, "000004b0");

            WriteEntry2(resourceHeader, "FileDescription", "Something compiled by Bart's compiler.");
            WriteEntry2(resourceHeader, "FileVersion", "1.0.0.0");
            WriteEntry2(resourceHeader, "InternalName", moduleName + ".exe");
            WriteEntry2(resourceHeader, "LegalCopyright", " ");
            WriteEntry2(resourceHeader, "OriginalFilename", moduleName + ".exe");
            WriteEntry2(resourceHeader, "ProductName", moduleName);
            WriteEntry2(resourceHeader, "ProductVersion", "1.0.0.0");
            varVersion.SetDistanceSinceTaken();
            varStringFileInfo.SetDistanceSinceTaken();

            RelativeSizeOfHeader = resourceHeader.CurrentLocation.Offset - RelativeSizeOfHeader;
            SizeOfResourceBody1.SetValue((int)RelativeSizeOfHeader);
            SizeOfResourceBody2.SetValue((int)RelativeSizeOfHeader);
        }