public void AddEventsRange (uint type_rid, Range range) { Events.Add (type_rid, range); }
public void AddPropertiesRange (uint type_rid, Range range) { Properties.Add (type_rid, range); }
public bool TryGetPropertiesRange (TypeDefinition type, out Range range) { return Properties.TryGetValue (type.token.RID, out range); }
internal bool TryGetCustomAttributeRanges(ICustomAttributeProvider owner, out Range[] ranges) { return CustomAttributes.TryGetValue (owner.MetadataToken, out ranges); }
internal bool TryGetSecurityDeclarationRanges(ISecurityDeclarationProvider owner, out Range[] ranges) { return SecurityDeclarations.TryGetValue (owner.MetadataToken, out ranges); }
public bool TryGetCustomAttributeRange (ICustomAttributeProvider owner, out Range range) { return CustomAttributes.TryGetValue (owner.MetadataToken, out range); }
public bool TryGetPropertiesRange(TypeDefinition type, out Range range) { return(Properties.TryGetValue(type.token.RID, out range)); }
public void Phase3(MetadataProcessor.MetadataAccessor accessor) { MethodTable tbl = accessor.TableHeap.GetTable<MethodTable>(Table.Method); accessor.Codes.Position = 0; codes = accessor.Codes.ReadBytes(accessor.Codes.Length); accessor.Codes.Reset(null); accessor.Codes.Position = 0; uint bas = accessor.Codebase; List<object> o = new List<object>(); for (int i = 0; i < tbl.Length; i++) { if (tbl[i].Col1 == 0) continue; if (excludes.Contains(i) || (tbl[i].Col2 & MethodImplAttributes.CodeTypeMask) != MethodImplAttributes.IL) { if ((tbl[i].Col2 & MethodImplAttributes.CodeTypeMask) != MethodImplAttributes.IL) accessor.Codes.WriteBytes(((accessor.Codes.Position + 15) & ~15) - accessor.Codes.Position); tbl[i].Col1 = (uint)accessor.Codes.Position + bas; Range range = accessor.BodyRanges[new MetadataToken(TokenType.Method, i + 1)]; byte[] buff = new byte[range.Length]; Buffer.BlockCopy(codes, (int)(range.Start - bas), buff, 0, buff.Length); accessor.Codes.WriteBytes(buff); accessor.Codes.WriteBytes(((accessor.Codes.Position + 3) & ~3) - accessor.Codes.Position); } else { tbl[i].Col2 |= MethodImplAttributes.NoInlining; Range range = accessor.BodyRanges[new MetadataToken(TokenType.Method, i + 1)]; range = new Range(range.Start - bas, range.Length); ExtractRefs(bodies[i], i, o); var dat = Transform(bodies[i], i, codes, range); o.Add(dat); } } int[] randArray = new int[o.Count]; for (int i = 0; i < o.Count; i++) randArray[i] = Confuser.Random.Next(); object[] objs = o.ToArray(); Array.Sort(randArray, objs); var mtdDats = new Dictionary<int, MethodData>(); foreach (var i in objs) { if (i is MethodData) { MethodData mtdDat = i as MethodData; mtdDats[mtdDat.Index] = mtdDat; mtdDat.BufferOffset = finalDat.Position; finalDat.WriteBytes(mtdDat.Serialize(fieldLayout)); Confuser.Database.AddEntry("AntiTamper", (0x06000001 + mtdDat.Index).ToString("X"), mtdDat.BufferOffset); } else { StringData strDat = i as StringData; strDat.BufferOffset = finalDat.Position; finalDat.WriteBytes(strDat.Serialize(key5)); Confuser.Database.AddEntry("AntiTamper", strDat.String, strDat.BufferOffset); } } foreach (var i in objs) { if (i is StringData) { StringData dat = i as StringData; uint token = 0x70800000; token |= (uint)dat.BufferOffset; Buffer.BlockCopy(BitConverter.GetBytes(token), 0, mtdDats[dat.Index].ILCodes, dat.Offset, 4); } } byte[] randBuff = new byte[4]; foreach (var i in mtdDats) { uint ptr = (uint)i.Value.BufferOffset; Confuser.Random.NextBytes(randBuff); uint key = BitConverter.ToUInt32(randBuff, 0); tbl[i.Key].Col1 = (uint)accessor.Codes.Position + bas; byte[] buff = i.Value.Serialize(fieldLayout); Crypt(buff, key * (uint)key4, key); finalDat.Position = i.Value.BufferOffset; finalDat.WriteBytes(buff); accessor.Codes.WriteByte(0x46); //flags accessor.Codes.WriteByte(0x21); //ldc.i8 accessor.Codes.WriteUInt64(((ulong)key << 32) | (ptr ^ key)); accessor.Codes.WriteByte(0x20); //ldc.i4 accessor.Codes.WriteUInt32(~(uint)buff.Length ^ key); accessor.Codes.WriteByte(0x26); accessor.BlobHeap.Position = (int)tbl[i.Key].Col5; accessor.BlobHeap.ReadCompressedUInt32(); byte flags = accessor.BlobHeap.ReadByte(); if ((flags & 0x10) != 0) accessor.BlobHeap.ReadCompressedUInt32(); accessor.BlobHeap.ReadCompressedUInt32(); bool hasRet = false; do { byte t = accessor.BlobHeap.ReadByte(); if (t == 0x1f || t == 0x20) continue; hasRet = t != 0x01; } while (false); accessor.Codes.WriteByte(hasRet ? (byte)0x00 : (byte)0x26); accessor.Codes.WriteByte(0x2a); //ret accessor.Codes.WriteBytes(((accessor.Codes.Position + 3) & ~3) - accessor.Codes.Position); } accessor.USHeap.Reset(new byte[0]); }
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; }
public bool TryGetCustomAttributeRange(ICustomAttributeProvider owner, out Range range) { return(CustomAttributes.TryGetValue(owner.MetadataToken, out range)); }
public bool TryGetSecurityDeclarationRange(ISecurityDeclarationProvider owner, out Range range) { return(SecurityDeclarations.TryGetValue(owner.MetadataToken, out range)); }
public bool TryGetGenericParameterRange(IGenericParameterProvider owner, out Range range) { return(GenericParameters.TryGetValue(owner.MetadataToken, out range)); }
public bool TryGetEventsRange(TypeDefinition type, out Range range) { return(Events.TryGetValue(type.token.RID, out range)); }
public void AddEventsRange(uint type_rid, Range range) { Events.Add(type_rid, range); }
public bool TryGetEventsRange (TypeDefinition type, out Range range) { return Events.TryGetValue (type.token.RID, out range); }
internal void AddEventsRange(uint type_rid, Range range) { Events.Add (type_rid, range); }
public bool TryGetGenericParameterRange (IGenericParameterProvider owner, out Range range) { return GenericParameters.TryGetValue (owner.MetadataToken, out range); }
internal bool TryGetGenericParameterRanges(IGenericParameterProvider owner, out Range[] ranges) { return GenericParameters.TryGetValue (owner.MetadataToken, out ranges); }
public bool TryGetSecurityDeclarationRange (ISecurityDeclarationProvider owner, out Range range) { return SecurityDeclarations.TryGetValue (owner.MetadataToken, out range); }
public void AddPropertiesRange(uint type_rid, Range range) { Properties.Add(type_rid, range); }