MethodData Transform(MethodBody body, int idx, byte[] codes, Range range) { MethodData ret = new MethodData(); ret.Index = idx; ret.EHs = Mono.Empty <MethodData.MethodEH> .Array; if ((codes[range.Start] & 0x3) == 0x2) { ret.ILCodes = new byte[codes[range.Start] >> 2]; Buffer.BlockCopy(codes, (int)range.Start + 1, ret.ILCodes, 0, ret.ILCodes.Length); ret.LocalVars = 0; ret.MaxStack = (uint)8; ret.Options = (uint)Confuser.Random.Next(0, 2) << 8; } else { ushort flags = BitConverter.ToUInt16(codes, (int)range.Start); ret.ILCodes = new byte[BitConverter.ToInt32(codes, (int)range.Start + 4)]; Buffer.BlockCopy(codes, (int)range.Start + 12, ret.ILCodes, 0, ret.ILCodes.Length); ret.LocalVars = BitConverter.ToUInt32(codes, (int)range.Start + 8); ret.MaxStack = BitConverter.ToUInt16(codes, (int)range.Start + 2); ret.Options = (flags & 0x10) != 0 ? 0x10 : 0U; ret.Options |= (uint)Confuser.Random.Next(0, 2) << 8; if ((flags & 0x8) != 0) { int ptr = (int)range.Start + 12 + ret.ILCodes.Length; var ehs = new List <MethodData.MethodEH>(); byte f; do { ptr = (ptr + 3) & ~3; f = codes[ptr]; uint count; bool isSmall = (f & 0x40) == 0; if (isSmall) { count = codes[ptr + 1] / 12u; } else { count = (BitConverter.ToUInt32(codes, ptr) >> 8) / 24; } ptr += 4; for (int i = 0; i < count; i++) { var clause = new MethodData.MethodEH(); clause.Flags = (ExceptionHandlerType)(codes[ptr] & 0x7); ptr += isSmall ? 2 : 4; clause.TryOffset = isSmall ? BitConverter.ToUInt16(codes, ptr) : BitConverter.ToUInt32(codes, ptr); ptr += isSmall ? 2 : 4; clause.TryLength = isSmall ? codes[ptr] : BitConverter.ToUInt32(codes, ptr); ptr += isSmall ? 1 : 4; clause.HandlerOffset = isSmall ? BitConverter.ToUInt16(codes, ptr) : BitConverter.ToUInt32(codes, ptr); ptr += isSmall ? 2 : 4; clause.HandlerLength = isSmall ? codes[ptr] : BitConverter.ToUInt32(codes, ptr); ptr += isSmall ? 1 : 4; clause.ClassTokenOrFilterOffset = BitConverter.ToUInt32(codes, ptr); ptr += 4; if ((clause.ClassTokenOrFilterOffset & 0xff000000) == 0x1b000000) { ret.Options |= 0x80; } ehs.Add(clause); } }while ((f & 0x80) != 0); ret.EHs = ehs.ToArray(); } } return(ret); }
MethodData Transform(MethodBody body, int idx, byte[] codes, Range range) { MethodData ret = new MethodData(); ret.Index = idx; ret.EHs = Mono.Empty<MethodData.MethodEH>.Array; if ((codes[range.Start] & 0x3) == 0x2) { ret.ILCodes = new byte[codes[range.Start] >> 2]; Buffer.BlockCopy(codes, (int)range.Start + 1, ret.ILCodes, 0, ret.ILCodes.Length); ret.LocalVars = 0; ret.MaxStack = (uint)8; ret.Options = (uint)Confuser.Random.Next(0, 2) << 8; } else { ushort flags = BitConverter.ToUInt16(codes, (int)range.Start); ret.ILCodes = new byte[BitConverter.ToInt32(codes, (int)range.Start + 4)]; Buffer.BlockCopy(codes, (int)range.Start + 12, ret.ILCodes, 0, ret.ILCodes.Length); ret.LocalVars = BitConverter.ToUInt32(codes, (int)range.Start + 8); ret.MaxStack = BitConverter.ToUInt16(codes, (int)range.Start + 2); ret.Options = (flags & 0x10) != 0 ? 0x10 : 0U; ret.Options |= (uint)Confuser.Random.Next(0, 2) << 8; if ((flags & 0x8) != 0) { int ptr = (int)range.Start + 12 + ret.ILCodes.Length; var ehs = new List<MethodData.MethodEH>(); byte f; do { ptr = (ptr + 3) & ~3; f = codes[ptr]; uint count; bool isSmall = (f & 0x40) == 0; if (isSmall) count = codes[ptr + 1] / 12u; else count = (BitConverter.ToUInt32(codes, ptr) >> 8) / 24; ptr += 4; for (int i = 0; i < count; i++) { var clause = new MethodData.MethodEH(); clause.Flags = (ExceptionHandlerType)(codes[ptr] & 0x7); ptr += isSmall ? 2 : 4; clause.TryOffset = isSmall ? BitConverter.ToUInt16(codes, ptr) : BitConverter.ToUInt32(codes, ptr); ptr += isSmall ? 2 : 4; clause.TryLength = isSmall ? codes[ptr] : BitConverter.ToUInt32(codes, ptr); ptr += isSmall ? 1 : 4; clause.HandlerOffset = isSmall ? BitConverter.ToUInt16(codes, ptr) : BitConverter.ToUInt32(codes, ptr); ptr += isSmall ? 2 : 4; clause.HandlerLength = isSmall ? codes[ptr] : BitConverter.ToUInt32(codes, ptr); ptr += isSmall ? 1 : 4; clause.ClassTokenOrFilterOffset = BitConverter.ToUInt32(codes, ptr); ptr += 4; if ((clause.ClassTokenOrFilterOffset & 0xff000000) == 0x1b000000) ret.Options |= 0x80; ehs.Add(clause); } } while ((f & 0x80) != 0); ret.EHs = ehs.ToArray(); } } return ret; }