if (!CliHeaderDir->VirtualAddress)
return STATUS_INVALID_IMAGE_FORMAT;
+ CliHeader = (MonoCLIHeader*)((DWORD_PTR)DosHeader + CliHeaderDir->VirtualAddress);
+ if (CliHeader->ch_flags & CLI_FLAGS_32BITREQUIRED)
+ return STATUS_INVALID_IMAGE_FORMAT;
+
+ if (CliHeader->ch_flags & CLI_FLAGS_ILONLY)
+ {
+ /* Avoid calling _CorDllMain because imports are not resolved for IL only images. */
+ if (NtHeaders64->OptionalHeader.AddressOfEntryPoint != 0)
+ {
+ Address = &NtHeaders64->OptionalHeader.AddressOfEntryPoint;
+ if (!VirtualProtect(Address, sizeof(DWORD), PAGE_READWRITE, &OldProtect))
+ return E_UNEXPECTED;
+ *Address = (DWORD)0;
+ if (!VirtualProtect(Address, sizeof(DWORD), OldProtect, &OldProtect))
+ return E_UNEXPECTED;
+ }
+ }
+
return STATUS_SUCCESS;
}
return E_FAIL;
BaseRelocSize -= RelocBlockSize;
- RelocBlock = (USHORT*)((DWORD_PTR)BaseReloc + IMAGE_SIZEOF_BASE_RELOCATION);
- RelocBlockSize -= IMAGE_SIZEOF_BASE_RELOCATION;
+ RelocBlock = (USHORT*)((DWORD_PTR)BaseReloc + sizeof(IMAGE_BASE_RELOCATION));
+ RelocBlockSize -= sizeof(IMAGE_BASE_RELOCATION);
RelocBlockSize /= sizeof(USHORT);
while (RelocBlockSize-- != 0)
void
mono_load_coree (const char* exe_file_name)
{
+ HMODULE module_handle;
gunichar2* file_name;
UINT required_size;
UINT size;
file_name [size++] = L'\\';
memcpy (&file_name [size], L"mscoree.dll", 12 * sizeof (gunichar2));
- coree_module_handle = LoadLibrary (file_name);
+ module_handle = LoadLibrary (file_name);
g_free (file_name);
- if (coree_module_handle && !SUCCEEDED (MonoFixupCorEE (coree_module_handle))) {
- FreeLibrary (coree_module_handle);
- coree_module_handle = NULL;
+ if (module_handle && !SUCCEEDED (MonoFixupCorEE (module_handle))) {
+ FreeLibrary (module_handle);
+ module_handle = NULL;
}
+
+ coree_module_handle = module_handle;
}
void