/// <summary> /// Construct a PositionTranslator. /// </summary> /// <param name="randomInts">Random integers used in translation</param> public PositionTranslator(CryptoStreamDef streamType, UInt32[] randomInts) { if (randomInts == null) { throw new ArgumentNullException(); } if (randomInts.Length != 5) { throw new Exception("Integer array must have a length of 5"); } _randomInts = randomInts; _streamType = streamType; }
/// <summary> /// Try and find the type used for crypto streams. /// </summary> /// <returns>Crypto stream TypeDef, or null if none found</returns> public CryptoStreamDef FindCryptoStreamType() { foreach (var typeDef in this.Module.Types.Where(type => type.BaseType != null && type.BaseType.FullName.Equals(typeof(System.IO.Stream).FullName))) { if (CryptoStreamDefV2.Is(typeDef)) { return(new CryptoStreamDefV2(typeDef)); } else if (CryptoStreamDef.Is(typeDef)) { return(new CryptoStreamDef(typeDef)); } } return(null); }
/// <summary> /// Try and find the type used for crypto streams. /// </summary> /// <returns>Crypto stream TypeDef, or null if none found</returns> public CryptoStreamDef FindCryptoStreamType() { foreach (TypeDef type in Module.Types) { if (!type.HasMethods) { continue; } foreach (MethodDef method in type.Methods) { if (!method.HasBody || !method.Body.HasInstructions) { continue; } foreach (Instruction instruction in method.Body.Instructions) { if (instruction.OpCode == OpCodes.Callvirt && ((IMethod)instruction.Operand).Name == "get_CanRead") { return(new CryptoStreamDefV2(type)); } } } } foreach (var typeDef in this.Module.Types.Where(type => type.BaseType != null && type.BaseType.FullName.Equals(typeof(System.IO.Stream).FullName))) { if (CryptoStreamDefV2.Is(typeDef)) { return(new CryptoStreamDefV2(typeDef)); } else if (CryptoStreamDef.Is(typeDef)) { return(new CryptoStreamDef(typeDef)); } } return(null); }
/// <summary> /// Try and find the type used for crypto streams. /// </summary> /// <returns>Crypto stream TypeDef, or null if none found</returns> public CryptoStreamDef FindCryptoStreamType() { var typeDef = this.Module.Types.FirstOrDefault(type => type.BaseType != null && type.BaseType.FullName.Equals(typeof(System.IO.Stream).FullName)); if (typeDef == null) { return(null); } if (CryptoStreamDefV2.Is(typeDef)) { return(new CryptoStreamDefV2(typeDef)); } else if (CryptoStreamDef.Is(typeDef)) { return(new CryptoStreamDef(typeDef)); } else { return(null); } }
/// <summary> /// Construct a PositionTranslator with the default random integers. /// </summary> /// <param name="streamType">Crypto stream type definition</param> public PositionTranslator(CryptoStreamDef streamType) : this(streamType, DefaultPseudoRandomInts) { }