private int GetInfo(StringBuilder sb, ExceptionHandlingClauses ex, int ad, bool isFat) { sb.Append(" *** Exception Handling Clauses ***\r\n\r\n"); sb.AppendFormat("{0:X8}:", ad); string f = string.Format(isFat ? "{0:X8} " : "{0:X4} ", ex.Flags); f += string.Format("({0})", (COR_ILEXCEPTION_CLAUSE)ex.Flags); sb.AppendFormat("{0,-16} {1}\r\n", f, "Flags: Flags, see below."); ad += isFat ? 4: 2; sb.AppendFormat("{0:X8}:", ad); sb.AppendFormat(isFat ? "{0,-16:X8} " : "{0,-16:X4} ", ex.TryOffset); sb.Append("TryOffset: Offset in bytes of try block from start of the header.\r\n"); ad += isFat ? 4: 2; sb.AppendFormat("{0:X8}:", ad); sb.AppendFormat(isFat ? "{0,-16:X8} " : "{0,-16:X2} ", ex.TryLength); sb.Append("TryLength: Length in bytes of the try block\r\n"); ad += isFat ? 4: 1; sb.AppendFormat("{0:X8}:", ad); sb.AppendFormat(isFat ? "{0,-16:X8} " : "{0,-16:X4} ", ex.HandlerOffset); sb.Append("HandlerOffset: Location of the handler for this try block\r\n"); ad += isFat ? 4: 2; sb.AppendFormat("{0:X8}:", ad); sb.AppendFormat(isFat ? "{0,-16:X8} " : "{0,-16:X2} ", ex.HandlerLength); sb.Append("HandlerLength: Size of the handler code in bytes\r\n"); ad += isFat ? 4: 1; sb.AppendFormat("{0:X8}:", ad); if (ex.Flags == (int)COR_ILEXCEPTION_CLAUSE.EXCEPTION) { string ct; if (ex.ClassToken == 0) { ct = string.Format("{0:X8} (null)", ex.ClassToken); } else { TableBase tb = this.data.idxm.GetTable(ex.ClassToken); ct = string.Format("{0:X8} ({1})", ex.ClassToken, tb.GetTitle()); } sb.AppendFormat("{0,-16:X8} {1}\r\n", ct, "ClassToken: Meta data token for a type-based exception handler"); } else { sb.AppendFormat("{0,-16:X8} {1}\r\n", ex.FilterOffset, "FilterOffset: Offset in method body for filter-based exception handler"); } ad += 4; return(ad); }
private void Parse(PEData data, TableBase m) { this.data = data; this.table = m; this.Flags = this.Size = this.MaxStack = this.CodeSize = this.LocalVarSigTok = 0; this.ilCodes = null; this.ilAddr = 0; this.LocalVarSigTok = 0; this.LocalVarSig = null; this.LocalVars = null; this.ImplMap = null; this.Kind = this.DataSize = 0; this.EHTable = null; this.ReadSignature(); int ad = this.RVA; if (ad == 0) { return; } int h = this.data.data[ad]; if ((h & 3) == (int)CorILMethod.TinyFormat) { this.CodeSize = h >> 2; ad++; } else { h = Util.GetInt16(this.data.data, ad); this.Flags = h & 0xfff; this.Size = (h >> 12) * 4; ad += 2; this.MaxStack = Util.GetInt16(this.data.data, ad); ad += 2; this.CodeSize = Util.GetInt32(this.data.data, ad); ad += 4; this.LocalVarSigTok = Util.GetInt32(this.data.data, ad); ad += 4; this.ReadLocalVars(); } this.ilAddr = ad; ad += this.CodeSize; if ((this.Flags & (int)CorILMethod.MoreSects) == 0) { return; } /// More Sections int pad = 4 - (ad & 3); if (pad < 4) { ad += pad; } int end = ad; this.Kind = this.data.data[ad++]; bool isFat = (this.Kind & (int)CorILMethod_Sect.FatFormat) != 0; if (!isFat) { this.DataSize = this.data.data[ad]; } else { this.DataSize = Util.GetInt24(this.data.data, ad); } ad += 3; end += this.DataSize; this.EHTable = new ArrayList(); while (ad < end) { ExceptionHandlingClauses ex = new ExceptionHandlingClauses(); if (!isFat) { ex.Flags = Util.GetInt16(data.data, ad); ad += 2; ex.TryOffset = Util.GetInt16(data.data, ad); ad += 2; ex.TryLength = data.data[ad++]; ex.HandlerOffset = Util.GetInt16(data.data, ad); ad += 2; ex.HandlerLength = data.data[ad++]; } else { ex.Flags = Util.GetInt32(data.data, ad); ad += 4; ex.TryOffset = Util.GetInt32(data.data, ad); ad += 4; ex.TryLength = Util.GetInt32(data.data, ad); ad += 4; ex.HandlerOffset = Util.GetInt32(data.data, ad); ad += 4; ex.HandlerLength = Util.GetInt32(data.data, ad); ad += 4; } if (ex.Flags == (int)COR_ILEXCEPTION_CLAUSE.EXCEPTION) { ex.ClassToken = Util.GetInt32(data.data, ad); } else { ex.FilterOffset = Util.GetInt32(data.data, ad); } ad += 4; this.EHTable.Add(ex); } }
public void GetInfos(StringBuilder sb) { int ad = this.RVA; if (ad == 0) { return; } sb.Append(" *** Method Header ***\r\n\r\n"); if ((this.Flags & 3) == (int)CorILMethod.TinyFormat) { sb.AppendFormat("{0:X8}:{1,-16:X2} CorILMethod_TinyFormat, CodeSize: {2:X2}\r\n", ad, this.data.data[ad], this.CodeSize); } else { sb.AppendFormat("{0:X8}:{1,-16:X4} Flags: {2:X4}, Size: {3:X2}\r\n", ad, Util.GetInt16(this.data.data, ad), this.Flags, this.Size); sb.AppendFormat("({0})\r\n", (CorILMethod)this.Flags); ad += 2; sb.AppendFormat("{0:X8}:{1,-16:X4} {2}\r\n", ad, this.MaxStack, "MaxStack: Maximum number of items on the operand stack"); ad += 2; sb.AppendFormat("{0:X8}:{1,-16:X8} {2}\r\n", ad, this.CodeSize, "CodeSize: Size in bytes of the actual method body"); ad += 4; string hex = string.Format("{0:X8} {1}", this.LocalVarSigTok, this.data.idxm.GetInfo(this.LocalVarSigTok)); sb.AppendFormat("{0:X8}:{1,-16} {2}\r\n", ad, hex, "LocalVarSigTok: Meta Data token for a signature describing the layout of the local variables for the method. 0 means there are no local variables present"); ad += 4; if (this.LocalVarSig != null) { sb.Append("\r\n"); this.LocalVarSig.GetInfos(sb); sb.Append("\r\n"); this.data.idxm.GetSignatureInfos(sb, this.LocalVarSig.Signature); } } sb.Append("\r\n *** Method Body ***\r\n\r\n"); foreach (object obj in this.ILCodes) { this.GetInfo(sb, obj as ILCode); } ad += this.CodeSize; if ((this.Flags & (int)CorILMethod.MoreSects) == 0) { return; } int pad = 4 - (ad & 3); if (pad < 4) { ad += pad; } sb.Append("\r\n *** Method Data Section ***\r\n\r\n"); string k = string.Format("{0:X2} ({1})", this.Kind, (CorILMethod_Sect)this.Kind); sb.AppendFormat("{0:X8}:{1,-16} {2}\r\n", ad, k, "Kind: Which type of exception block is being used"); ad++; bool isFat = (this.Kind & (int)CorILMethod_Sect.FatFormat) != 0; if (!isFat) { sb.AppendFormat("{0:X8}:{1,-16:X2} {2}\r\n", ad, this.DataSize, "DataSize: Size of the data for the block, including the header, say n*12+4"); ad++; sb.AppendFormat("{0:X8}:{1:X2} {2,-13:X2} {3}\r\n", ad, this.data.data[ad++], this.data.data[ad++], "Reserved: Padding, always 0"); } else { sb.AppendFormat("{0:X8}:{1,-16:X6} {2}\r\n", ad, this.DataSize, "DataSize: Size of the data for the block, including the header, say n*24+4."); ad += 3; } foreach (object obj in this.EHTable) { ExceptionHandlingClauses ex = obj as ExceptionHandlingClauses; sb.Append("\r\n"); ad = this.GetInfo(sb, ex, ad, isFat); } }