forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassembly.cpp
77 lines (62 loc) · 1.87 KB
/
assembly.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// ============================================================
//
// Assembly.cpp
//
//
// Implements the Assembly class
//
// ============================================================
#include "common.h"
#include "assembly.hpp"
#include "utils.hpp"
#include "assemblybindercommon.hpp"
namespace BINDER_SPACE
{
Assembly::Assembly()
{
m_cRef = 1;
m_pPEImage = NULL;
m_pAssemblyName = NULL;
m_isInTPA = false;
m_pBinder = NULL;
m_domainAssembly = NULL;
}
Assembly::~Assembly()
{
SAFE_RELEASE(m_pPEImage);
SAFE_RELEASE(m_pAssemblyName);
}
HRESULT Assembly::Init(PEImage *pPEImage, BOOL fIsInTPA)
{
HRESULT hr = S_OK;
ReleaseHolder<AssemblyName> pAssemblyName;
SAFE_NEW(pAssemblyName, AssemblyName);
// Get assembly name def from meta data import and store it for later refs access
IF_FAIL_GO(pAssemblyName->Init(pPEImage));
pAssemblyName->SetIsDefinition(TRUE);
// validate architecture
if (!AssemblyBinderCommon::IsValidArchitecture(pAssemblyName->GetArchitecture()))
{
// Assembly image can't be executed on this platform
IF_FAIL_GO(HRESULT_FROM_WIN32(ERROR_BAD_FORMAT));
}
m_isInTPA = fIsInTPA;
pPEImage->AddRef();
m_pPEImage = pPEImage;
// Now take ownership of assembly name
m_pAssemblyName = pAssemblyName.Extract();
Exit:
return hr;
}
PEImage* Assembly::GetPEImage()
{
return m_pPEImage;
}
LPCWSTR Assembly::GetSimpleName()
{
AssemblyName *pAsmName = GetAssemblyName();
return (pAsmName == nullptr ? nullptr : (LPCWSTR)pAsmName->GetSimpleName());
}
}