| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | |
| 5 | /***************************************************************************/ |
| 6 | /* routines for parsing file format stuff ... */ |
| 7 | /* this is split off from format.cpp because this uses meta-data APIs that |
| 8 | are not present in many builds. Thus if someone needs things in the format.cpp |
| 9 | file but does not have the meta-data APIs, I want it to link */ |
| 10 | |
| 11 | #include "stdafx.h" |
| 12 | #include "cor.h" |
| 13 | #include "corpriv.h" |
| 14 | |
| 15 | //--------------------------------------------------------------------------------------- |
| 16 | // |
| 17 | static LONG FilterAllExceptions(PEXCEPTION_POINTERS pExceptionPointers, LPVOID lpvParam) |
| 18 | { |
| 19 | if ((pExceptionPointers->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) || |
| 20 | (pExceptionPointers->ExceptionRecord->ExceptionCode == EXCEPTION_ARRAY_BOUNDS_EXCEEDED) || |
| 21 | (pExceptionPointers->ExceptionRecord->ExceptionCode == EXCEPTION_IN_PAGE_ERROR)) |
| 22 | return EXCEPTION_EXECUTE_HANDLER; |
| 23 | |
| 24 | return EXCEPTION_CONTINUE_SEARCH; |
| 25 | } |
| 26 | |
| 27 | //--------------------------------------------------------------------------------------- |
| 28 | // |
| 29 | COR_ILMETHOD_DECODER::COR_ILMETHOD_DECODER( |
| 30 | COR_ILMETHOD * , |
| 31 | void * pInternalImport, |
| 32 | DecoderStatus * wbStatus) |
| 33 | { |
| 34 | STATIC_CONTRACT_NOTHROW; |
| 35 | STATIC_CONTRACT_FORBID_FAULT; |
| 36 | |
| 37 | // Can't put contract because of SEH |
| 38 | // CONTRACTL |
| 39 | // { |
| 40 | // NOTHROW; |
| 41 | // GC_NOTRIGGER; |
| 42 | // FORBID_FAULT; |
| 43 | // } |
| 44 | // CONTRACTL_END |
| 45 | |
| 46 | bool fErrorInInit = false; |
| 47 | struct Param |
| 48 | { |
| 49 | COR_ILMETHOD_DECODER * pThis; |
| 50 | COR_ILMETHOD * ; |
| 51 | } param; |
| 52 | param.pThis = this; |
| 53 | param.header = header; |
| 54 | |
| 55 | PAL_TRY(Param *, pParam, ¶m) |
| 56 | { |
| 57 | // Decode the COR header into a more convenient form |
| 58 | DecoderInit(pParam->pThis, pParam->header); |
| 59 | } |
| 60 | PAL_EXCEPT_FILTER(FilterAllExceptions) |
| 61 | { |
| 62 | fErrorInInit = true; |
| 63 | Code = 0; |
| 64 | SetLocalVarSigTok(0); |
| 65 | if (wbStatus != NULL) |
| 66 | { |
| 67 | *wbStatus = FORMAT_ERROR; |
| 68 | } |
| 69 | } |
| 70 | PAL_ENDTRY |
| 71 | |
| 72 | if (fErrorInInit) |
| 73 | { |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | // If there is a local variable sig, fetch it into 'LocalVarSig' |
| 78 | if ((GetLocalVarSigTok() != 0) && (pInternalImport != NULL)) |
| 79 | { |
| 80 | IMDInternalImport * pMDI = reinterpret_cast<IMDInternalImport *>(pInternalImport); |
| 81 | |
| 82 | if (wbStatus != NULL) |
| 83 | { |
| 84 | if ((!pMDI->IsValidToken(GetLocalVarSigTok())) || |
| 85 | (TypeFromToken(GetLocalVarSigTok()) != mdtSignature) || |
| 86 | (RidFromToken(GetLocalVarSigTok()) == 0)) |
| 87 | { |
| 88 | *wbStatus = FORMAT_ERROR; // failure bad local variable signature token |
| 89 | return; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if (FAILED(pMDI->GetSigFromToken(GetLocalVarSigTok(), &cbLocalVarSig, &LocalVarSig))) |
| 94 | { |
| 95 | // Failure bad local variable signature token |
| 96 | if (wbStatus != NULL) |
| 97 | { |
| 98 | *wbStatus = FORMAT_ERROR; |
| 99 | } |
| 100 | LocalVarSig = NULL; |
| 101 | cbLocalVarSig = 0; |
| 102 | return; |
| 103 | } |
| 104 | |
| 105 | if (wbStatus != NULL) |
| 106 | { |
| 107 | if (FAILED(validateTokenSig(GetLocalVarSigTok(), LocalVarSig, cbLocalVarSig, 0, pMDI)) || |
| 108 | (*LocalVarSig != IMAGE_CEE_CS_CALLCONV_LOCAL_SIG)) |
| 109 | { |
| 110 | *wbStatus = VERIFICATION_ERROR; // failure validating local variable signature |
| 111 | return; |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | if (wbStatus != NULL) |
| 117 | { |
| 118 | *wbStatus = SUCCESS; |
| 119 | } |
| 120 | } // COR_ILMETHOD_DECODER::COR_ILMETHOD_DECODER |
| 121 | |