Commit 8f985a33 authored by James Hawkins's avatar James Hawkins Committed by Alexandre Julliard

fusion: The VersionLength member is not constant, so dynamically load the metadata header.

parent 378fde9a
...@@ -271,22 +271,54 @@ static HRESULT parse_clr_tables(ASSEMBLY *assembly, ULONG offset) ...@@ -271,22 +271,54 @@ static HRESULT parse_clr_tables(ASSEMBLY *assembly, ULONG offset)
return S_OK; return S_OK;
} }
static HRESULT parse_metadata_header(ASSEMBLY *assembly, DWORD *hdrsz)
{
METADATAHDR *metadatahdr;
BYTE *ptr, *dest;
DWORD size, ofs;
ULONG rva;
rva = assembly->corhdr->MetaData.VirtualAddress;
ptr = ImageRvaToVa(assembly->nthdr, assembly->data, rva, NULL);
if (!ptr)
return E_FAIL;
metadatahdr = (METADATAHDR *)ptr;
assembly->metadatahdr = HeapAlloc(GetProcessHeap(), 0, sizeof(METADATAHDR));
if (!assembly->metadatahdr)
return E_OUTOFMEMORY;
size = FIELD_OFFSET(METADATAHDR, Version);
memcpy(assembly->metadatahdr, metadatahdr, size);
/* we don't care about the version string */
ofs = FIELD_OFFSET(METADATAHDR, Flags);
ptr += FIELD_OFFSET(METADATAHDR, Version) + metadatahdr->VersionLength + 1;
dest = (BYTE *)assembly->metadatahdr + ofs;
memcpy(dest, ptr, sizeof(METADATAHDR) - ofs);
*hdrsz = sizeof(METADATAHDR) - sizeof(LPSTR) + metadatahdr->VersionLength + 1;
return S_OK;
}
static HRESULT parse_clr_metadata(ASSEMBLY *assembly) static HRESULT parse_clr_metadata(ASSEMBLY *assembly)
{ {
METADATASTREAMHDR *streamhdr; METADATASTREAMHDR *streamhdr;
ULONG rva, i, ofs; ULONG rva, i, ofs;
LPSTR stream; LPSTR stream;
HRESULT hr; HRESULT hr;
DWORD hdrsz;
BYTE *ptr; BYTE *ptr;
rva = assembly->corhdr->MetaData.VirtualAddress; hr = parse_metadata_header(assembly, &hdrsz);
assembly->metadatahdr = ImageRvaToVa(assembly->nthdr, assembly->data, if (FAILED(hr))
rva, NULL); return hr;
if (!assembly->metadatahdr)
return E_FAIL;
ptr = ImageRvaToVa(assembly->nthdr, assembly->data, rva = assembly->corhdr->MetaData.VirtualAddress;
rva + sizeof(METADATAHDR), NULL); ptr = ImageRvaToVa(assembly->nthdr, assembly->data, rva + hdrsz, NULL);
if (!ptr) if (!ptr)
return E_FAIL; return E_FAIL;
...@@ -393,7 +425,7 @@ HRESULT assembly_create(ASSEMBLY **out, LPCWSTR file) ...@@ -393,7 +425,7 @@ HRESULT assembly_create(ASSEMBLY **out, LPCWSTR file)
return S_OK; return S_OK;
failed: failed:
assembly_release( assembly ); assembly_release(assembly);
return hr; return hr;
} }
...@@ -402,6 +434,7 @@ HRESULT assembly_release(ASSEMBLY *assembly) ...@@ -402,6 +434,7 @@ HRESULT assembly_release(ASSEMBLY *assembly)
if (!assembly) if (!assembly)
return S_OK; return S_OK;
HeapFree(GetProcessHeap(), 0, assembly->metadatahdr);
HeapFree(GetProcessHeap(), 0, assembly->path); HeapFree(GetProcessHeap(), 0, assembly->path);
UnmapViewOfFile(assembly->data); UnmapViewOfFile(assembly->data);
CloseHandle(assembly->hmap); CloseHandle(assembly->hmap);
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#include "winbase.h" #include "winbase.h"
#include "winuser.h" #include "winuser.h"
#include <pshpack1.h>
typedef struct typedef struct
{ {
ULONG Signature; ULONG Signature;
...@@ -34,13 +36,11 @@ typedef struct ...@@ -34,13 +36,11 @@ typedef struct
USHORT MinorVersion; USHORT MinorVersion;
ULONG Reserved; ULONG Reserved;
ULONG VersionLength; ULONG VersionLength;
BYTE Version[12]; LPSTR Version;
BYTE Flags; BYTE Flags;
WORD Streams; WORD Streams;
} METADATAHDR; } METADATAHDR;
#include <pshpack1.h>
typedef struct typedef struct
{ {
DWORD Offset; DWORD Offset;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment