Rename field and method

This commit is contained in:
de4dot 2013-10-25 22:08:52 +02:00
parent c956e0fc2e
commit d53e321b99

View File

@ -25,12 +25,12 @@ namespace de4dot.blocks {
public class StackTracePatcher { public class StackTracePatcher {
static readonly FieldInfo methodField; static readonly FieldInfo methodField;
static readonly FieldInfo framesField; static readonly FieldInfo framesField;
static readonly FieldInfo iMethodsToSkip; static readonly FieldInfo methodsToSkipField;
static StackTracePatcher() { static StackTracePatcher() {
methodField = GetStackFrameMethodField(); methodField = GetStackFrameMethodField();
framesField = GetStackTraceStackFramesField(); framesField = GetStackTraceStackFramesField();
iMethodsToSkip = GetMethodsToSkip(); methodsToSkipField = GetMethodsToSkipField();
} }
static FieldInfo GetStackFrameMethodField() { static FieldInfo GetStackFrameMethodField() {
@ -43,7 +43,7 @@ namespace de4dot.blocks {
return GetFieldThrow(typeof(StackTrace), typeof(StackFrame[]), flags, "Could not find StackTrace's frames (StackFrame[]) field"); return GetFieldThrow(typeof(StackTrace), typeof(StackFrame[]), flags, "Could not find StackTrace's frames (StackFrame[]) field");
} }
static FieldInfo GetMethodsToSkip() { static FieldInfo GetMethodsToSkipField() {
var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance; var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
return GetFieldThrow(typeof(StackTrace), "m_iMethodsToSkip", flags, "Could not find StackTrace's iMethodsToSkip field"); return GetFieldThrow(typeof(StackTrace), "m_iMethodsToSkip", flags, "Could not find StackTrace's iMethodsToSkip field");
} }
@ -81,7 +81,7 @@ namespace de4dot.blocks {
public static StackTrace WriteStackFrame(StackTrace stackTrace, int frameNo, MethodBase newMethod) { public static StackTrace WriteStackFrame(StackTrace stackTrace, int frameNo, MethodBase newMethod) {
var framesField = GetStackTraceStackFramesField(); var framesField = GetStackTraceStackFramesField();
var frames = (StackFrame[])framesField.GetValue(stackTrace); var frames = (StackFrame[])framesField.GetValue(stackTrace);
int numFramesToSkip = (int)iMethodsToSkip.GetValue(stackTrace); int numFramesToSkip = (int)methodsToSkipField.GetValue(stackTrace);
WriteMethodBase(frames[numFramesToSkip + frameNo], newMethod); WriteMethodBase(frames[numFramesToSkip + frameNo], newMethod);
return stackTrace; return stackTrace;
} }