ReactOS 0.4.16-dev-334-g4d9f67c
assembly.c File Reference
#include "mscoree_private.h"
#include <winver.h>
#include <dbghelp.h>
Include dependency graph for assembly.c:

Go to the source code of this file.

Classes

struct  METADATAHDR
 
struct  METADATASTREAMHDR
 
struct  tagCLRTABLE
 
struct  tagASSEMBLY
 

Typedefs

typedef struct tagCLRTABLE CLRTABLE
 

Functions

static LPWSTR strdupW (LPCWSTR src)
 
static voidassembly_rva_to_va (ASSEMBLY *assembly, ULONG rva)
 
static ULONG assembly_datadir_get_data (ASSEMBLY *assembly, IMAGE_DATA_DIRECTORY *datadir, void **data)
 
static HRESULT parse_metadata_header (ASSEMBLY *assembly, DWORD *hdrsz)
 
static HRESULT parse_clr_metadata (ASSEMBLY *assembly)
 
static HRESULT parse_pe_header (ASSEMBLY *assembly)
 
static HRESULT parse_headers (ASSEMBLY *assembly)
 
HRESULT assembly_create (ASSEMBLY **out, LPCWSTR file)
 
HRESULT assembly_from_hmodule (ASSEMBLY **out, HMODULE hmodule)
 
HRESULT assembly_release (ASSEMBLY *assembly)
 
HRESULT assembly_get_runtime_version (ASSEMBLY *assembly, LPSTR *version)
 
HRESULT assembly_get_vtable_fixups (ASSEMBLY *assembly, VTableFixup **fixups, DWORD *count)
 

Typedef Documentation

◆ CLRTABLE

Function Documentation

◆ assembly_create()

HRESULT assembly_create ( ASSEMBLY **  out,
LPCWSTR  file 
)

Definition at line 191 of file assembly.c.

192{
194 HRESULT hr;
195
196 *out = NULL;
197
199 if (!assembly)
200 return E_OUTOFMEMORY;
201
202 assembly->is_mapped_file = 1;
203
204 assembly->path = strdupW(file);
205 if (!assembly->path)
206 {
208 goto failed;
209 }
210
213 if (assembly->hfile == INVALID_HANDLE_VALUE)
214 {
216 goto failed;
217 }
218
220 0, 0, NULL);
221 if (!assembly->hmap)
222 {
224 goto failed;
225 }
226
227 assembly->data = MapViewOfFile(assembly->hmap, FILE_MAP_READ, 0, 0, 0);
228 if (!assembly->data)
229 {
231 goto failed;
232 }
233
235 if (FAILED(hr)) goto failed;
236
237 *out = assembly;
238 return S_OK;
239
240failed:
242 return hr;
243}
static WCHAR * strdupW(const WCHAR *src)
Definition: main.c:92
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define PAGE_READONLY
Definition: compat.h:138
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:744
#define GENERIC_READ
Definition: compat.h:135
#define CreateFileW
Definition: compat.h:741
#define FILE_MAP_READ
Definition: compat.h:776
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define MapViewOfFile
Definition: compat.h:745
#define FILE_SHARE_READ
Definition: compat.h:136
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
HRESULT assembly_release(ASSEMBLY *assembly)
Definition: assembly.c:694
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
static HRESULT parse_headers(ASSEMBLY *assembly)
Definition: assembly.c:179
static FILE * out
Definition: regtests2xml.c:44
HRESULT hr
Definition: shlfolder.c:183
Definition: fci.c:127
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92

◆ assembly_datadir_get_data()

static ULONG assembly_datadir_get_data ( ASSEMBLY assembly,
IMAGE_DATA_DIRECTORY datadir,
void **  data 
)
static

Definition at line 89 of file assembly.c.

91{
92 if (!datadir->VirtualAddress || !datadir->Size)
93 {
94 *data = NULL;
95 return 0;
96 }
97 else
98 {
100 return datadir->Size;
101 }
102}
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
static void * assembly_rva_to_va(ASSEMBLY *assembly, ULONG rva)
Definition: assembly.c:81

Referenced by assembly_get_vtable_fixups(), and parse_pe_header().

◆ assembly_from_hmodule()

HRESULT assembly_from_hmodule ( ASSEMBLY **  out,
HMODULE  hmodule 
)

Definition at line 245 of file assembly.c.

246{
248 HRESULT hr;
249
250 *out = NULL;
251
253 if (!assembly)
254 return E_OUTOFMEMORY;
255
256 assembly->is_mapped_file = 0;
257
258 assembly->data = (BYTE*)hmodule;
259
261 if (SUCCEEDED(hr))
262 *out = assembly;
263 else
265
266 return hr;
267}
#define SUCCEEDED(hr)
Definition: intsafe.h:50
static HMODULE hmodule
Definition: rasapi.c:29
unsigned char BYTE
Definition: xxhash.c:193

Referenced by FixupVTable().

◆ assembly_get_runtime_version()

HRESULT assembly_get_runtime_version ( ASSEMBLY assembly,
LPSTR version 
)

Definition at line 287 of file assembly.c.

288{
289 *version = assembly->metadatahdr->Version;
290
291 return S_OK;
292}
static const WCHAR version[]
Definition: asmname.c:66

◆ assembly_get_vtable_fixups()

HRESULT assembly_get_vtable_fixups ( ASSEMBLY assembly,
VTableFixup **  fixups,
DWORD count 
)

Definition at line 294 of file assembly.c.

295{
296 ULONG size;
297
298 size = assembly_datadir_get_data(assembly, &assembly->corhdr->VTableFixups, (void**)fixups);
299 *count = size / sizeof(VTableFixup);
300
301 return S_OK;
302}
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLsizeiptr size
Definition: glext.h:5919
static ULONG assembly_datadir_get_data(ASSEMBLY *assembly, IMAGE_DATA_DIRECTORY *datadir, void **data)
Definition: assembly.c:89
struct _VTableFixup VTableFixup
uint32_t ULONG
Definition: typedefs.h:59

Referenced by FixupVTable().

◆ assembly_release()

HRESULT assembly_release ( ASSEMBLY assembly)

Definition at line 269 of file assembly.c.

270{
271 if (!assembly)
272 return S_OK;
273
274 if (assembly->is_mapped_file)
275 {
277 CloseHandle(assembly->hmap);
278 CloseHandle(assembly->hfile);
279 }
280 HeapFree(GetProcessHeap(), 0, assembly->metadatahdr);
281 HeapFree(GetProcessHeap(), 0, assembly->path);
283
284 return S_OK;
285}
#define CloseHandle
Definition: compat.h:739
#define UnmapViewOfFile
Definition: compat.h:746
#define HeapFree(x, y, z)
Definition: compat.h:735

◆ assembly_rva_to_va()

static void * assembly_rva_to_va ( ASSEMBLY assembly,
ULONG  rva 
)
static

Definition at line 81 of file assembly.c.

82{
83 if (assembly->is_mapped_file)
84 return ImageRvaToVa(assembly->nthdr, assembly->data, rva, NULL);
85 else
86 return assembly->data + rva;
87}
PVOID WINAPI ImageRvaToVa(_In_ PIMAGE_NT_HEADERS, _In_ PVOID, _In_ ULONG, _In_opt_ PIMAGE_SECTION_HEADER *)

Referenced by assembly_datadir_get_data(), and parse_metadata_header().

◆ parse_clr_metadata()

static HRESULT parse_clr_metadata ( ASSEMBLY assembly)
static

Definition at line 137 of file assembly.c.

138{
139 HRESULT hr;
140 DWORD hdrsz;
141
143 if (FAILED(hr))
144 return hr;
145
146 return S_OK;
147}
unsigned long DWORD
Definition: ntddk_ex.h:95
static HRESULT parse_metadata_header(ASSEMBLY *assembly, DWORD *hdrsz)
Definition: assembly.c:529

◆ parse_headers()

static HRESULT parse_headers ( ASSEMBLY assembly)
static

Definition at line 179 of file assembly.c.

180{
181 HRESULT hr;
182
184
185 if (SUCCEEDED(hr))
187
188 return hr;
189}
static HRESULT parse_pe_header(ASSEMBLY *assembly)
Definition: assembly.c:603
static HRESULT parse_clr_metadata(ASSEMBLY *assembly)
Definition: assembly.c:560

Referenced by assembly_create(), and assembly_from_hmodule().

◆ parse_metadata_header()

static HRESULT parse_metadata_header ( ASSEMBLY assembly,
DWORD hdrsz 
)
static

Definition at line 104 of file assembly.c.

105{
106 METADATAHDR *metadatahdr;
107 BYTE *ptr, *dest;
108 DWORD size, ofs;
109 ULONG rva;
110
111 rva = assembly->corhdr->MetaData.VirtualAddress;
113 if (!ptr)
114 return E_FAIL;
115
116 metadatahdr = (METADATAHDR *)ptr;
117
118 assembly->metadatahdr = HeapAlloc(GetProcessHeap(), 0, sizeof(METADATAHDR));
119 if (!assembly->metadatahdr)
120 return E_OUTOFMEMORY;
121
123 memcpy(assembly->metadatahdr, metadatahdr, size);
124
125 assembly->metadatahdr->Version = (LPSTR)&metadatahdr->Version;
126
128 ptr += FIELD_OFFSET(METADATAHDR, Version) + metadatahdr->VersionLength + 1;
129 dest = (BYTE *)assembly->metadatahdr + ofs;
130 memcpy(dest, ptr, sizeof(METADATAHDR) - ofs);
131
132 *hdrsz = sizeof(METADATAHDR) - sizeof(LPSTR) + metadatahdr->VersionLength + 1;
133
134 return S_OK;
135}
#define E_FAIL
Definition: ddrawi.h:102
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static PVOID ptr
Definition: dispmode.c:27
static char * dest
Definition: rtl.c:135
ULONG VersionLength
Definition: fusionpriv.h:48
LPSTR Version
Definition: fusionpriv.h:49
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE _In_ USHORT _In_ USHORT Version
Definition: wdffdo.h:469
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
char * LPSTR
Definition: xmlstorage.h:182

◆ parse_pe_header()

static HRESULT parse_pe_header ( ASSEMBLY assembly)
static

Definition at line 149 of file assembly.c.

150{
151 IMAGE_DATA_DIRECTORY *datadirs;
152
153 assembly->nthdr = ImageNtHeader(assembly->data);
154 if (!assembly->nthdr)
155 return E_FAIL;
156
157 if (assembly->nthdr->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
158 {
160 (IMAGE_OPTIONAL_HEADER64 *)&assembly->nthdr->OptionalHeader;
161 datadirs = opthdr->DataDirectory;
162 }
163 else
164 {
166 (IMAGE_OPTIONAL_HEADER32 *)&assembly->nthdr->OptionalHeader;
167 datadirs = opthdr->DataDirectory;
168 }
169
170 if (!datadirs)
171 return E_FAIL;
172
174 return E_FAIL;
175
176 return S_OK;
177}
PIMAGE_NT_HEADERS WINAPI ImageNtHeader(_In_ PVOID)
#define IMAGE_NT_OPTIONAL_HDR64_MAGIC
Definition: ntimage.h:377
#define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR
Definition: ntimage.h:489
IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]
Definition: ntimage.h:370
IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]
Definition: ntddk_ex.h:178

◆ strdupW()

static LPWSTR strdupW ( LPCWSTR  src)
inlinestatic

Definition at line 67 of file assembly.c.

68{
70
71 if (!src)
72 return NULL;
73
74 dest = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(src) + 1) * sizeof(WCHAR));
75 if (dest)
77
78 return dest;
79}
#define lstrcpyW
Definition: compat.h:749
#define lstrlenW
Definition: compat.h:750
GLenum src
Definition: glext.h:6340
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184