summaryrefslogtreecommitdiff
path: root/src/inc/peinformation.h
blob: abac3a1667802adcd9dfce0604ba64118b00c71f (plain)
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
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
// --------------------------------------------------------------------------------
// PEInformation.h
//

// --------------------------------------------------------------------------------

#ifndef PEINFORMATION_H
#define PEINFORMATION_H

#ifndef PEKIND_ENUM_DEFINED
#define PEKIND_ENUM_DEFINED
// This must match the definition of pekind in fusion.idl
typedef enum _tagPEKIND 
{
    peNone      = 0x00000000,
    peMSIL      = 0x00000001,
    peI386      = 0x00000002,
    peIA64      = 0x00000003,
    peAMD64     = 0x00000004,
    peARM       = 0x00000005,
    peARM64     = 0x00000006,
    peInvalid = 0xffffffff
} PEKIND;

#endif


inline bool IsPE64(PEKIND x)
{
    return ( (x == peIA64) || (x == peAMD64) );
}

inline bool IsPE32(PEKIND x)
{
    return ( (x == peI386) || (x == peARM) );
}

inline bool IsPEMSIL(PEKIND x)
{
    return ( (x == peMSIL) );
}

#ifdef _WIN64
inline bool IsProcess32() { return false; }
#else
inline bool IsProcess32() { return true; }
#endif

#if defined(_TARGET_X86_)
inline PEKIND TargetNativePEKIND() { return peI386; }
#elif defined(_TARGET_AMD64_)
inline PEKIND TargetNativePEKIND() { return peAMD64; }
#elif defined(_TARGET_ARM_)
inline PEKIND TargetNativePEKIND() { return peARM; }
#elif defined(_TARGET_ARM64_)
inline PEKIND TargetNativePEKIND() { return peARM64; }
#else
#error Need to define valid TargetNativePEKIND()
#endif

STDAPI RuntimeIsValidAssemblyOnThisPlatform_CheckProcessorArchitecture(PEKIND processorArchitecture, BOOL bForInstall);

//*****************************************************************************
//  Intreprets CLRPeKind and dwImageType to get PeKind as per the CLRBitness
//  API, CLRPeKind and dwImageType can be recoved from GetPEKind() if you
//  have the metadata, or retrieved directly from the headers as per the
//  implementation in shim.cpp:_CorValidateImage.
//*****************************************************************************
HRESULT TranslatePEToArchitectureType(CorPEKind CLRPeKind, DWORD dwImageType, PEKIND * PeKind);
HRESULT TranslatePEToArchitectureType(CorPEKind CLRPeKind, DWORD dwImageType, DWORD dwAssemblyFlags, PEKIND * PeKind);

#endif // PEINFORMATION_H