View | Details | Raw Unified | Return to bug 26842
Collapse All | Expand All

(-)a/ikvm-7.2.4630.5/reflect/Writer/ModuleWriter.cs (-5 / +12 lines)
Lines 38-50 namespace IKVM.Reflection.Writer Link Here
38
			PEFileKinds fileKind, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine,
38
			PEFileKinds fileKind, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine,
39
			ResourceSection resources, int entryPointToken)
39
			ResourceSection resources, int entryPointToken)
40
		{
40
		{
41
			WriteModule(keyPair, publicKey, moduleBuilder, fileKind, portableExecutableKind, imageFileMachine, resources, entryPointToken, null);
41
			WriteModule(keyPair, publicKey, moduleBuilder, fileKind, portableExecutableKind, imageFileMachine, resources, entryPointToken, null, null);
42
		}
42
		}
43
43
44
		internal static void WriteModule(StrongNameKeyPair keyPair, byte[] publicKey, ModuleBuilder moduleBuilder,
44
		internal static void WriteModule(StrongNameKeyPair keyPair, byte[] publicKey, ModuleBuilder moduleBuilder,
45
			PEFileKinds fileKind, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine,
45
			PEFileKinds fileKind, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine,
46
			ResourceSection resources, int entryPointToken, Stream stream)
46
			ResourceSection resources, int entryPointToken, Stream stream)
47
		{
47
		{
48
			WriteModule(keyPair, publicKey, moduleBuilder, fileKind, portableExecutableKind, imageFileMachine, resources, entryPointToken, stream, null);
49
		}
50
51
		internal static void WriteModule(StrongNameKeyPair keyPair, byte[] publicKey, ModuleBuilder moduleBuilder,
52
			PEFileKinds fileKind, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine,
53
			ResourceSection resources, int entryPointToken, Stream stream, DateTime timestamp)
54
		{
48
			if (stream == null)
55
			if (stream == null)
49
			{
56
			{
50
				string fileName = moduleBuilder.FullyQualifiedName;
57
				string fileName = moduleBuilder.FullyQualifiedName;
Lines 60-66 namespace IKVM.Reflection.Writer Link Here
60
				}
67
				}
61
				using (FileStream fs = new FileStream(fileName, FileMode.Create))
68
				using (FileStream fs = new FileStream(fileName, FileMode.Create))
62
				{
69
				{
63
					WriteModuleImpl(keyPair, publicKey, moduleBuilder, fileKind, portableExecutableKind, imageFileMachine, resources, entryPointToken, fs);
70
					WriteModuleImpl(keyPair, publicKey, moduleBuilder, fileKind, portableExecutableKind, imageFileMachine, resources, entryPointToken, fs, timestamp);
64
				}
71
				}
65
				// if we're running on Mono, mark the module as executable by using a Mono private API extension
72
				// if we're running on Mono, mark the module as executable by using a Mono private API extension
66
				if (mono)
73
				if (mono)
Lines 70-82 namespace IKVM.Reflection.Writer Link Here
70
			}
77
			}
71
			else
78
			else
72
			{
79
			{
73
				WriteModuleImpl(keyPair, publicKey, moduleBuilder, fileKind, portableExecutableKind, imageFileMachine, resources, entryPointToken, stream);
80
				WriteModuleImpl(keyPair, publicKey, moduleBuilder, fileKind, portableExecutableKind, imageFileMachine, resources, entryPointToken, stream, timestamp);
74
			}
81
			}
75
		}
82
		}
76
83
77
		private static void WriteModuleImpl(StrongNameKeyPair keyPair, byte[] publicKey, ModuleBuilder moduleBuilder,
84
		private static void WriteModuleImpl(StrongNameKeyPair keyPair, byte[] publicKey, ModuleBuilder moduleBuilder,
78
			PEFileKinds fileKind, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine,
85
			PEFileKinds fileKind, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine,
79
			ResourceSection resources, int entryPointToken, Stream stream)
86
			ResourceSection resources, int entryPointToken, Stream stream, DateTime timestamp)
80
		{
87
		{
81
			moduleBuilder.ApplyUnmanagedExports(imageFileMachine);
88
			moduleBuilder.ApplyUnmanagedExports(imageFileMachine);
82
			moduleBuilder.FixupMethodBodyTokens();
89
			moduleBuilder.FixupMethodBodyTokens();
Lines 94-100 namespace IKVM.Reflection.Writer Link Here
94
				resources.Finish();
101
				resources.Finish();
95
			}
102
			}
96
103
97
			PEWriter writer = new PEWriter(stream);
104
			PEWriter writer = new PEWriter(stream, timestamp);
98
			writer.Headers.OptionalHeader.FileAlignment = (uint)moduleBuilder.__FileAlignment;
105
			writer.Headers.OptionalHeader.FileAlignment = (uint)moduleBuilder.__FileAlignment;
99
			switch (imageFileMachine)
106
			switch (imageFileMachine)
100
			{
107
			{
(-)a/ikvm-7.2.4630.5/reflect/Writer/PEWriter.cs (-2 / +23 lines)
Lines 34-43 namespace IKVM.Reflection.Writer Link Here
34
	sealed class PEWriter
34
	sealed class PEWriter
35
	{
35
	{
36
		private readonly BinaryWriter bw;
36
		private readonly BinaryWriter bw;
37
		private readonly IMAGE_NT_HEADERS hdr = new IMAGE_NT_HEADERS();
37
		private readonly IMAGE_NT_HEADERS hdr;
38
38
39
		internal PEWriter(Stream stream)
39
		internal PEWriter(Stream stream)
40
		{
40
		{
41
                        hdr = new IMAGE_NT_HEADERS(null);
42
			bw = new BinaryWriter(stream);
43
			WriteMSDOSHeader();
44
		}
45
		internal PEWriter(Stream stream, DateTime timestamp)
46
		{
47
                        hdr = new IMAGE_NT_HEADERS(timestamp);
41
			bw = new BinaryWriter(stream);
48
			bw = new BinaryWriter(stream);
42
			WriteMSDOSHeader();
49
			WriteMSDOSHeader();
43
		}
50
		}
Lines 131-136 namespace IKVM.Reflection.Writer Link Here
131
		public DWORD Signature = 0x00004550;	// "PE\0\0"
138
		public DWORD Signature = 0x00004550;	// "PE\0\0"
132
		public IMAGE_FILE_HEADER FileHeader = new IMAGE_FILE_HEADER();
139
		public IMAGE_FILE_HEADER FileHeader = new IMAGE_FILE_HEADER();
133
		public IMAGE_OPTIONAL_HEADER OptionalHeader = new IMAGE_OPTIONAL_HEADER();
140
		public IMAGE_OPTIONAL_HEADER OptionalHeader = new IMAGE_OPTIONAL_HEADER();
141
142
		internal IMAGE_NT_HEADERS(DateTime timestamp)
143
		{
144
                        FileHeader = new IMAGE_FILE_HEADER(timestamp);
145
		}
134
	}
146
	}
135
147
136
	sealed class IMAGE_FILE_HEADER
148
	sealed class IMAGE_FILE_HEADER
Lines 147-157 namespace IKVM.Reflection.Writer Link Here
147
159
148
		public WORD Machine;
160
		public WORD Machine;
149
		public WORD NumberOfSections;
161
		public WORD NumberOfSections;
150
		public DWORD TimeDateStamp = (uint)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;
162
		public DWORD TimeDateStamp;
151
		public DWORD PointerToSymbolTable = 0;
163
		public DWORD PointerToSymbolTable = 0;
152
		public DWORD NumberOfSymbols = 0;
164
		public DWORD NumberOfSymbols = 0;
153
		public WORD SizeOfOptionalHeader = 0xE0;
165
		public WORD SizeOfOptionalHeader = 0xE0;
154
		public WORD Characteristics = IMAGE_FILE_EXECUTABLE_IMAGE;
166
		public WORD Characteristics = IMAGE_FILE_EXECUTABLE_IMAGE;
167
168
		internal IMAGE_FILE_HEADER(DateTime timestamp)
169
		{
170
                        if (timestamp == null) {
171
                           TimeDateStamp = (uint)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;
172
                        } else {
173
                           TimeDateStamp = (uint)(timestamp - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;
174
                        }
175
		}
155
	}
176
	}
156
177
157
	sealed class IMAGE_OPTIONAL_HEADER
178
	sealed class IMAGE_OPTIONAL_HEADER

Return to bug 26842