public override void Initialize(IObfuscationContext context) { Phases.AddRange(new ObfuscatorTaskPhase[] { new MemberGenerationPhase(this) }); }
public override void Apply(IObfuscationContext context) { foreach (var module in context.Assembly.Modules) { AnalyseModule(module); } }
public override void Apply(IObfuscationContext context) { var module = context.Assembly.MainModule; for (int i = 0; i < Random.Next(3, 30); i++) { TypeDefinition targetType; do { targetType = module.Types[Random.Next(module.Types.Count)]; } while (targetType.IsInterface); var junkMethod = new MethodDefinition("junkMethod" + i, MethodAttributes.Static, module.TypeSystem.Void); var parameterCount = Random.Next(-4, 4); if (parameterCount < 0) { parameterCount = 0; } for (int j = 0; j < parameterCount; j++) { junkMethod.Parameters.Add(new ParameterDefinition(module.TypeSystem.Object)); } targetType.Methods.Add(junkMethod); MsilBodyGenerator.AssignRandomMethodBody(junkMethod); } }
protected override object CoreGetObfuscatedValue(IObfuscationContext obfuscationContext, IColumnSpec <Spec> columnSpec, IField field, object columnValue) { long valueHash; object value; long randomSeed; if ((object)obfuscationContext == null) { throw new ArgumentNullException(nameof(obfuscationContext)); } if ((object)columnSpec == null) { throw new ArgumentNullException(nameof(columnSpec)); } if ((object)field == null) { throw new ArgumentNullException(nameof(field)); } if ((object)columnSpec.ObfuscationStrategySpec == null) { throw new InvalidOperationException(string.Format("Specification missing: '{0}'.", nameof(columnSpec.ObfuscationStrategySpec))); } valueHash = obfuscationContext.GetValueHash(null, columnValue); randomSeed = valueHash; value = GetShuffle(randomSeed, columnValue); return(value); }
protected override object CoreGetObfuscatedValue(IObfuscationContext obfuscationContext, IColumnSpec <Spec> columnSpec, IField field, object columnValue) { long valueHash; object value; long randomSeed; if ((object)obfuscationContext == null) { throw new ArgumentNullException(nameof(obfuscationContext)); } if ((object)columnSpec == null) { throw new ArgumentNullException(nameof(columnSpec)); } if ((object)field == null) { throw new ArgumentNullException(nameof(field)); } if ((object)columnSpec.ObfuscationStrategySpec == null) { throw new InvalidOperationException(string.Format("Specification missing: '{0}'.", nameof(columnSpec.ObfuscationStrategySpec))); } valueHash = obfuscationContext.GetValueHash(null, field.FieldName); randomSeed = valueHash; // create a new repeatable yet random-ish math funcion using the random seed, then executes for column value value = GetSurrogateKey(randomSeed, columnValue); return(value); }
protected override object CoreGetObfuscatedValue(IObfuscationContext obfuscationContext, IColumnSpec <Spec> columnSpec, IField field, object columnValue) { object value; if ((object)obfuscationContext == null) { throw new ArgumentNullException(nameof(obfuscationContext)); } if ((object)columnSpec == null) { throw new ArgumentNullException(nameof(columnSpec)); } if ((object)field == null) { throw new ArgumentNullException(nameof(field)); } if ((object)columnSpec.ObfuscationStrategySpec == null) { throw new InvalidOperationException(string.Format("Specification missing: '{0}'.", nameof(columnSpec.ObfuscationStrategySpec))); } //value = GetDefault(field.IsOptional && (columnSpec.ObfuscationStrategySpec.DefaultingCanBeNull ?? false), field.FieldType); value = null; return(value); }
protected override object CoreGetObfuscatedValue(IObfuscationContext obfuscationContext, IColumnSpec <Spec> columnSpec, IField field, object columnValue) { long signHash, valueHash; object value; double varianceFactor; if ((object)obfuscationContext == null) { throw new ArgumentNullException(nameof(obfuscationContext)); } if ((object)columnSpec == null) { throw new ArgumentNullException(nameof(columnSpec)); } if ((object)field == null) { throw new ArgumentNullException(nameof(field)); } if ((object)columnSpec.ObfuscationStrategySpec == null) { throw new InvalidOperationException(string.Format("Specification missing: '{0}'.", nameof(columnSpec.ObfuscationStrategySpec))); } signHash = obfuscationContext.GetSignHash(columnValue); valueHash = obfuscationContext.GetValueHash(columnSpec.ObfuscationStrategySpec.VariancePercentValue, columnValue); varianceFactor = ((((valueHash <= 0 ? 1 : valueHash)) * ((signHash % 2 == 0 ? 1.0 : -1.0))) / 100.0); value = GetVariance(varianceFactor, columnValue); return(value); }
protected override object CoreGetObfuscatedValue(IObfuscationContext obfuscationContext, IColumnSpec <Spec> columnSpec, IField field, object columnValue) { object value; double maskingFactor; if ((object)obfuscationContext == null) { throw new ArgumentNullException(nameof(obfuscationContext)); } if ((object)columnSpec == null) { throw new ArgumentNullException(nameof(columnSpec)); } if ((object)field == null) { throw new ArgumentNullException(nameof(field)); } if ((object)columnSpec.ObfuscationStrategySpec == null) { throw new InvalidOperationException(string.Format("Specification missing: '{0}'.", nameof(columnSpec.ObfuscationStrategySpec))); } maskingFactor = (columnSpec.ObfuscationStrategySpec.MaskingPercentValue.GetValueOrDefault() / 100.0); value = GetMask(maskingFactor, columnValue); return(value); }
public override void Initialize(IObfuscationContext context) { AnalysisReport = new SymbolAnalysisReport(); Phases.AddRange(new ObfuscatorTaskPhase[] { new SymbolAnalysisPhase(this), new SymbolRenamingPhase(this) }); }
public void ApplyAll(IObfuscationContext context) { for (int index = 0; index < Phases.Count; index++) { var phase = Phases[index]; context.LogOutput.WriteMessage(string.Format("Performing phase {0} ({1})...", index + 1, phase.Name)); CurrentPhase = phase; phase.Apply(context); } }
public void Apply(IObfuscationContext context) { Type.Namespace = NewNamespace; Type.Name = NewName; foreach (var overload in MemberOverloads) { overload.Apply(context); } }
public void Apply(IObfuscationContext context) { foreach (var symbol in Symbols) { symbol.Member.Name = NewName; var method = symbol.Member as MethodDefinition; if (method != null) { var generator = context.GetSymbolNameGenerator(); foreach (var parameter in method.Parameters) { parameter.Name = generator.Next(); } } } }
public object GetObfuscatedValue(IObfuscationContext obfuscationContext, IColumnSpec columnSpec, IField field, object originalFieldValue) { IColumnSpec <TObfuscationStrategySpec> _columnSpec; object value; if ((object)obfuscationContext == null) { throw new ArgumentNullException(nameof(obfuscationContext)); } if ((object)columnSpec == null) { throw new ArgumentNullException(nameof(columnSpec)); } if ((object)field == null) { throw new ArgumentNullException(nameof(field)); } if ((object)originalFieldValue == DBNull.Value) { originalFieldValue = null; } if ((object)columnSpec.ObfuscationStrategySpec == null) { throw new InvalidOperationException(string.Format("Specification missing: '{0}'.", nameof(columnSpec.ObfuscationStrategySpec))); } _columnSpec = new ColumnSpec <TObfuscationStrategySpec>(columnSpec); if ((object)_columnSpec.ObfuscationStrategySpec == null) { throw new InvalidOperationException(string.Format("Specification missing: '{0}'.", nameof(_columnSpec.ObfuscationStrategySpec))); } value = this.CoreGetObfuscatedValue(obfuscationContext, _columnSpec, field, originalFieldValue); return(value); }
protected override object CoreGetObfuscatedValue(IObfuscationContext obfuscationContext, IColumnSpec <Spec> columnSpec, IField field, object columnValue) { if ((object)obfuscationContext == null) { throw new ArgumentNullException(nameof(obfuscationContext)); } if ((object)columnSpec == null) { throw new ArgumentNullException(nameof(columnSpec)); } if ((object)field == null) { throw new ArgumentNullException(nameof(field)); } if ((object)columnSpec.ObfuscationStrategySpec == null) { throw new InvalidOperationException(string.Format("Specification missing: '{0}'.", nameof(columnSpec.ObfuscationStrategySpec))); } return(columnValue); }
protected override object CoreGetObfuscatedValue(IObfuscationContext obfuscationContext, IColumnSpec <Spec> columnSpec, IField field, object columnValue) { Type valueType; string _columnValue; long surrogateKey; object surrogateValue; IDictionarySpec dictionarySpec; if ((object)obfuscationContext == null) { throw new ArgumentNullException(nameof(obfuscationContext)); } if ((object)columnSpec == null) { throw new ArgumentNullException(nameof(columnSpec)); } if ((object)field == null) { throw new ArgumentNullException(nameof(field)); } if ((object)columnSpec.ObfuscationStrategySpec == null) { throw new InvalidOperationException(string.Format("Specification missing: '{0}'.", nameof(columnSpec.ObfuscationStrategySpec))); } if ((object)columnValue == null) { return(null); } valueType = columnValue.GetType(); if (valueType != typeof(string)) { return(null); } _columnValue = (string)columnValue; _columnValue = _columnValue.Trim(); if (SolderFascadeAccessor.DataTypeFascade.IsWhiteSpace(_columnValue)) { return(_columnValue); } dictionarySpec = columnSpec.ObfuscationStrategySpec.DictionarySpec; if ((object)dictionarySpec == null) { throw new InvalidOperationException(string.Format("Failed to obtain dictionary.")); } if ((dictionarySpec.RecordCount ?? 0L) <= 0L) { return(null); } surrogateKey = obfuscationContext.GetValueHash(dictionarySpec.RecordCount, columnValue); if (!obfuscationContext.TryGetSurrogateValue(dictionarySpec, surrogateKey, out surrogateValue)) { throw new InvalidOperationException(string.Format("Failed to obtain surrogate value.")); } return(surrogateValue); }
public override void Finalize(IObfuscationContext context) { }
public abstract void Finalize(IObfuscationContext context);
public abstract void Initialize(IObfuscationContext context);
public abstract void Apply(IObfuscationContext context);
protected abstract object CoreGetObfuscatedValue(IObfuscationContext obfuscationContext, IColumnSpec <TObfuscationStrategySpec> columnSpec, IField field, object columnValue);