Пример #1
0
	ExceptionHandler* Method::ReadExceptionHandler(
		enum CorExceptionFlag type,
		long tryStart, long tryEnd,
		long handlerStart, long handlerEnd,
		long filterStart, ULONG token) {

		auto pSection = new ExceptionHandler();
		pSection->m_handlerType = type;
		pSection->m_tryStart = GetInstructionAtOffset(tryStart);
		pSection->m_tryEnd = GetInstructionAtOffset(tryStart + tryEnd);
		pSection->m_handlerStart = GetInstructionAtOffset(handlerStart);
		pSection->m_handlerEnd = GetInstructionAtOffset(handlerStart + handlerEnd,
			(type & COR_ILEXCEPTION_CLAUSE_FINALLY) == COR_ILEXCEPTION_CLAUSE_FINALLY,
			(type & COR_ILEXCEPTION_CLAUSE_FAULT) == COR_ILEXCEPTION_CLAUSE_FAULT,
			(type & COR_ILEXCEPTION_CLAUSE_FILTER) == COR_ILEXCEPTION_CLAUSE_FILTER,
			(type & COR_ILEXCEPTION_CLAUSE_NONE) == COR_ILEXCEPTION_CLAUSE_NONE);

		if (filterStart != 0) {
			pSection->m_filterStart = GetInstructionAtOffset(filterStart);
		}

		pSection->m_token = token;
		return pSection;
	}
Пример #2
0
/// <summary>Read the section handler section.</summary>
/// <remarks>All 'Small' sections are to be converted to 'Fat' sections.</remarks>
void Method::ReadSections()
{
    if ((m_header.Flags & CorILMethod_MoreSects) == CorILMethod_MoreSects)
    {
        BYTE flags = 0;
        do
        {
            Align<DWORD>(); // must be DWORD aligned
            flags = Read<BYTE>();
            _ASSERTE((flags & CorILMethod_Sect_EHTable) == CorILMethod_Sect_EHTable);
            if ((flags & CorILMethod_Sect_FatFormat) == CorILMethod_Sect_FatFormat)
            {
                Advance(-1);
                int count = ((Read<ULONG>() >> 8) / 24);
                for (int i = 0; i < count; i++)
                {
                    CorExceptionFlag type = (CorExceptionFlag)Read<ULONG>();
                    long tryStart = Read<long>();
                    long tryEnd = Read<long>();
                    long handlerStart = Read<long>();
                    long handlerEnd = Read<long>();
                    long filterStart = 0;
                    ULONG token = 0;
                    switch (type)
                    {
                    case COR_ILEXCEPTION_CLAUSE_FILTER:
                        filterStart = Read<long>();
                        break;
                    default:
                        token = Read<ULONG>();
                        break;
                    }
                    ExceptionHandler * pSection = new ExceptionHandler();
                    pSection->m_handlerType = type;
                    pSection->m_tryStart = GetInstructionAtOffset(tryStart);
                    pSection->m_tryEnd = GetInstructionAtOffset(tryStart + tryEnd);
                    pSection->m_handlerStart = GetInstructionAtOffset(handlerStart);
                    pSection->m_handlerEnd = GetInstructionAtOffset(handlerStart + handlerEnd,
                                             (type & COR_ILEXCEPTION_CLAUSE_FINALLY) == COR_ILEXCEPTION_CLAUSE_FINALLY);
                    if (filterStart!=0)
                    {
                        pSection->m_filterStart = GetInstructionAtOffset(filterStart);
                    }
                    pSection->m_token = token;
                    m_exceptions.push_back(pSection);
                }
            }
            else
            {
                int count = (int)(Read<BYTE>() / 12);
                Advance(2);
                for (int i = 0; i < count; i++)
                {
                    CorExceptionFlag type = (CorExceptionFlag)Read<USHORT>();
                    long tryStart = Read<USHORT>();
                    long tryEnd = Read<BYTE>();
                    long handlerStart = Read<USHORT>();
                    long handlerEnd = Read<BYTE>();
                    long filterStart = 0;
                    ULONG token = 0;
                    switch (type)
                    {
                    case COR_ILEXCEPTION_CLAUSE_FILTER:
                        filterStart = Read<long>();
                        break;
                    default:
                        token = Read<ULONG>();
                        break;
                    }
                    ExceptionHandler * pSection = new ExceptionHandler();
                    pSection->m_handlerType = type;
                    pSection->m_tryStart = GetInstructionAtOffset(tryStart);
                    pSection->m_tryEnd = GetInstructionAtOffset(tryStart + tryEnd);
                    pSection->m_handlerStart = GetInstructionAtOffset(handlerStart);
                    pSection->m_handlerEnd = GetInstructionAtOffset(handlerStart + handlerEnd,
                                             (type & COR_ILEXCEPTION_CLAUSE_FINALLY) == COR_ILEXCEPTION_CLAUSE_FINALLY);
                    if (filterStart!=0)
                    {
                        pSection->m_filterStart = GetInstructionAtOffset(filterStart);
                    }
                    pSection->m_token = token;
                    m_exceptions.push_back(pSection);
                }
            }
        } while((flags & CorILMethod_Sect_MoreSects) == CorILMethod_Sect_MoreSects);