Permalink
Browse files

Add support for reading and writing custom dll characteristics

  • Loading branch information...
jbevain committed May 23, 2012
1 parent b876fcf commit 4e0cec75888fb06b81b68e9cd59fe3a47944cca5
View
@@ -41,6 +41,7 @@ sealed class Image {
public ModuleKind Kind;
public TargetRuntime Runtime;
public TargetArchitecture Architecture;
+ public ModuleCharacteristics Characteristics;
public string FileName;
public Section [] Sections;
@@ -99,13 +99,14 @@ void ReadImage ()
// Characteristics 2
ushort characteristics = ReadUInt16 ();
- ushort subsystem;
- ReadOptionalHeaders (out subsystem);
+ ushort subsystem, dll_characteristics;
+ ReadOptionalHeaders (out subsystem, out dll_characteristics);
ReadSections (sections);
ReadCLIHeader ();
ReadMetadata ();
image.Kind = GetModuleKind (characteristics, subsystem);
+ image.Characteristics = (ModuleCharacteristics) dll_characteristics;
}
TargetArchitecture ReadArchitecture ()
@@ -136,7 +137,7 @@ static ModuleKind GetModuleKind (ushort characteristics, ushort subsystem)
return ModuleKind.Console;
}
- void ReadOptionalHeaders (out ushort subsystem)
+ void ReadOptionalHeaders (out ushort subsystem, out ushort dll_characteristics)
{
// - PEOptionalHeader
// - StandardFieldsHeader
@@ -176,6 +177,7 @@ void ReadOptionalHeaders (out ushort subsystem)
subsystem = ReadUInt16 ();
// DLLFlags 2
+ dll_characteristics = ReadUInt16 ();
// StackReserveSize 4 || 8
// StackCommitSize 4 || 8
// HeapReserveSize 4 || 8
@@ -192,7 +194,7 @@ void ReadOptionalHeaders (out ushort subsystem)
// CertificateTable 8
// BaseRelocationTable 8
- Advance (pe64 ? 90 : 74);
+ Advance (pe64 ? 88 : 72);
// Debug 8
image.Debug = ReadDataDirectory ();
@@ -267,7 +267,7 @@ void WriteOptionalHeaders ()
WriteUInt32 (0); // Checksum
WriteUInt16 (GetSubSystem ()); // SubSystem
- WriteUInt16 (0x8540); // DLLFlags
+ WriteUInt16 ((ushort) module.Characteristics); // DLLFlags
const ulong stack_reserve = 0x100000;
const ulong stack_commit = 0x1000;
@@ -208,6 +208,7 @@ public sealed class ModuleDefinition : ModuleReference, ICustomAttributeProvider
TargetRuntime runtime;
TargetArchitecture architecture;
ModuleAttributes attributes;
+ ModuleCharacteristics characteristics;
Guid mvid;
internal AssemblyDefinition assembly;
@@ -247,6 +248,11 @@ public sealed class ModuleDefinition : ModuleReference, ICustomAttributeProvider
set { attributes = value; }
}
+ public ModuleCharacteristics Characteristics {
+ get { return characteristics; }
+ set { characteristics = value; }
+ }
+
public string FullyQualifiedName {
get { return fq_name; }
}
@@ -442,6 +448,7 @@ internal ModuleDefinition (Image image)
this.runtime = image.Runtime;
this.architecture = image.Architecture;
this.attributes = image.Attributes;
+ this.characteristics = image.Characteristics;
this.fq_name = image.FileName;
this.reader = new MetadataReader (this);
@@ -866,6 +873,7 @@ public static ModuleDefinition CreateModule (string name, ModuleParameters param
architecture = parameters.Architecture,
mvid = Guid.NewGuid (),
Attributes = ModuleAttributes.ILOnly,
+ Characteristics = (ModuleCharacteristics) 0x8540,
};
if (parameters.AssemblyResolver != null)
View
@@ -51,4 +51,14 @@ public enum ModuleAttributes {
StrongNameSigned = 8,
Preferred32Bit = 0x00020000,
}
+
+ [Flags]
+ public enum ModuleCharacteristics {
+ HighEntropyVA = 0x0020,
+ DynamicBase = 0x0040,
+ NoSEH = 0x0400,
+ NXCompat = 0x0100,
+ AppContainer = 0x1000,
+ TerminalServerAware = 0x8000,
+ }
}
@@ -134,5 +134,11 @@ public void WindowsPhoneNonSignedAssembly (ModuleDefinition module)
Assert.AreEqual (0, module.Image.StrongName.VirtualAddress);
Assert.AreEqual (0, module.Image.StrongName.Size);
}
+
+ [TestModule ("metro.exe", Verify = false)]
+ public void MetroAssembly(ModuleDefinition module)
+ {
+ Assert.AreEqual(ModuleCharacteristics.AppContainer, module.Characteristics & ModuleCharacteristics.AppContainer);
+ }
}
}
Binary file not shown.

0 comments on commit 4e0cec7

Please sign in to comment.