36 internal string copyright;
37 internal string trademark;
38 internal string product;
39 internal string company;
42 internal string informationalVersion;
45 internal void SetName(AssemblyName name)
50 internal void SetFileName(
string assemblyFileName)
52 this.fileName =
System.IO.Path.GetFileName(assemblyFileName);
55 internal void SetAttribute(AssemblyBuilder
asm, CustomAttributeBuilder cab)
57 var u = cab.Constructor.Module.Universe;
58 var type = cab.Constructor.DeclaringType;
59 if (copyright ==
null && type == u.System_Reflection_AssemblyCopyrightAttribute)
61 copyright = (string)cab.DecodeBlob(
asm).GetConstructorArgument(0);
63 else if (trademark ==
null && type == u.System_Reflection_AssemblyTrademarkAttribute)
65 trademark = (string)cab.DecodeBlob(
asm).GetConstructorArgument(0);
67 else if (product ==
null && type == u.System_Reflection_AssemblyProductAttribute)
69 product = (string)cab.DecodeBlob(
asm).GetConstructorArgument(0);
71 else if (company ==
null && type == u.System_Reflection_AssemblyCompanyAttribute)
73 company = (string)cab.DecodeBlob(
asm).GetConstructorArgument(0);
75 else if (description ==
null && type == u.System_Reflection_AssemblyDescriptionAttribute)
77 description = (string)cab.DecodeBlob(
asm).GetConstructorArgument(0);
79 else if (title ==
null && type == u.System_Reflection_AssemblyTitleAttribute)
81 title = (string)cab.DecodeBlob(
asm).GetConstructorArgument(0);
83 else if (informationalVersion ==
null && type == u.System_Reflection_AssemblyInformationalVersionAttribute)
85 informationalVersion = (string)cab.DecodeBlob(
asm).GetConstructorArgument(0);
87 else if (fileVersion ==
null && type == u.System_Reflection_AssemblyFileVersionAttribute)
89 fileVersion = (string)cab.DecodeBlob(
asm).GetConstructorArgument(0);
95 if (fileVersion ==
null)
97 if (name.Version !=
null)
99 fileVersion = name.Version.ToString();
103 fileVersion =
"0.0.0.0";
112 if (name.CultureInfo !=
null)
113 lcid = name.CultureInfo.LCID;
115 catch (ArgumentException)
120 var filever = ParseVersionRobust(fileVersion);
121 var fileVersionMajor = filever.Major;
122 var fileVersionMinor = filever.Minor;
123 var fileVersionBuild = filever.Build;
124 var fileVersionRevision = filever.Revision;
126 var productVersionMajor = fileVersionMajor;
127 var productVersionMinor = fileVersionMinor;
128 var productVersionBuild = fileVersionBuild;
129 var productVersionRevision = fileVersionRevision;
130 if (informationalVersion !=
null)
132 Version productver = ParseVersionRobust(informationalVersion);
133 productVersionMajor = productver.Major;
134 productVersionMinor = productver.Minor;
135 productVersionBuild = productver.Build;
136 productVersionRevision = productver.Revision;
140 stringTable.Write((
short)0);
141 stringTable.Write((
short)0);
142 stringTable.Write((
short)1);
143 WriteUTF16Z(stringTable,
string.Format(
"{0:x4}{1:x4}", lcid, codepage));
144 stringTable.Align(4);
146 WriteString(stringTable,
"Comments", description);
147 WriteString(stringTable,
"CompanyName", company);
148 WriteString(stringTable,
"FileDescription", title);
149 WriteString(stringTable,
"FileVersion", fileVersion);
150 WriteString(stringTable,
"InternalName", name.Name);
151 WriteString(stringTable,
"LegalCopyright", copyright);
152 WriteString(stringTable,
"LegalTrademarks", trademark);
153 WriteString(stringTable,
"OriginalFilename", fileName);
154 WriteString(stringTable,
"ProductName", product);
155 WriteString(stringTable,
"ProductVersion", informationalVersion);
157 stringTable.Position = 0;
158 stringTable.Write((
short)stringTable.Length);
161 stringFileInfo.Write((
short)0);
162 stringFileInfo.Write((
short)0);
163 stringFileInfo.Write((
short)1);
164 WriteUTF16Z(stringFileInfo,
"StringFileInfo");
165 stringFileInfo.Align(4);
166 stringFileInfo.Write(stringTable);
167 stringFileInfo.Position = 0;
168 stringFileInfo.Write((
short)stringFileInfo.Length);
170 var preamble1 =
new byte[] {
174 0x56, 0x00, 0x53, 0x00, 0x5F, 0x00, 0x56, 0x00, 0x45, 0x00, 0x52, 0x00, 0x53, 0x00, 0x49, 0x00, 0x4F, 0x00, 0x4E, 0x00, 0x5F, 0x00, 0x49, 0x00, 0x4E, 0x00, 0x46, 0x00, 0x4F, 0x00, 0x00, 0x00,
177 0xBD, 0x04, 0xEF, 0xFE,
178 0x00, 0x00, 0x01, 0x00,
181 byte[] preamble2 =
new byte[] {
182 0x3F, 0x00, 0x00, 0x00,
183 0x00, 0x00, 0x00, 0x00,
184 0x04, 0x00, 0x00, 0x00,
185 0x02, 0x00, 0x00, 0x00,
186 0x00, 0x00, 0x00, 0x00,
187 0x00, 0x00, 0x00, 0x00,
188 0x00, 0x00, 0x00, 0x00,
194 0x56, 0x00, 0x61, 0x00, 0x72, 0x00, 0x46, 0x00, 0x69, 0x00, 0x6C, 0x00, 0x65, 0x00, 0x49, 0x00, 0x6E, 0x00, 0x66, 0x00, 0x6F, 0x00, 0x00, 0x00,
200 0x54, 0x00, 0x72, 0x00, 0x61, 0x00, 0x6E, 0x00, 0x73, 0x00, 0x6C, 0x00, 0x61, 0x00, 0x74, 0x00, 0x69, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x00, 0x00,
204 bb.Write((
short)(2 + preamble1.Length + 8 + 8 + preamble2.Length + 4 + stringFileInfo.Length));
206 bb.Write((
short)fileVersionMinor);
207 bb.Write((
short)fileVersionMajor);
208 bb.Write((
short)fileVersionRevision);
209 bb.Write((
short)fileVersionBuild);
210 bb.Write((
short)productVersionMinor);
211 bb.Write((
short)productVersionMajor);
212 bb.Write((
short)productVersionRevision);
213 bb.Write((
short)productVersionBuild);
215 bb.Write((
short)lcid);
216 bb.Write((
short)codepage);
217 bb.Write(stringFileInfo);
220 static void WriteUTF16Z(
ByteBuffer bb,
string str)
222 foreach (
char c
in str)
228 static void WriteString(
ByteBuffer bb,
string name,
string value)
231 var pos = bb.Position;
233 bb.Write((
short)(value.Length + 1));
235 WriteUTF16Z(bb, name);
237 WriteUTF16Z(bb, value);
239 var savedPos = bb.Position;
241 bb.Write((
short)(savedPos - pos));
242 bb.Position = savedPos;
245 static Version ParseVersionRobust(
string ver)
248 var major = ParseVersionPart(ver,
ref index);
249 var minor = ParseVersionPart(ver,
ref index);
250 var build = ParseVersionPart(ver,
ref index);
251 var revision = ParseVersionPart(ver,
ref index);
252 return new Version(major, minor, build, revision);
255 static ushort ParseVersionPart(
string str,
ref int pos)
258 while (pos < str.Length)
266 else if (c >=
'0' && c <=
'9')
269 value += (ushort)(c -
'0');