public static string GetPlatformDependentCode(XmlDocument doc) { ExchangeFormat.Exchange exch = ExchangeFormat.Exchange.LoadFromString(doc.InnerXml); return(GetAssemblyFromTAC((Routine)exch)); }
public static void Obfuscate(ref ExchangeFormat.Exchange exch) { Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("\n\tINTERMEDIATE LEVEL OBFUSCATION\n"); Console.ResetColor(); Routine routine = (Routine)exch; Console.Write("Performing logical control"); routine.Validate(); PrintSuccess(); Logging.WriteReadableTAC(routine, "Imported"); bool TryAgain; do { int NumberOfRuns = 0; bool Success; do { Success = true; try { Obfuscation(routine); } catch (ObfuscatorException) { Success = false; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(" . . . . . UNSUCCESSFUL\n"); Console.ResetColor(); } NumberOfRuns++; } while (!Success && NumberOfRuns < Common.MaxNumberOfRuns); if (Success) { TryAgain = false; } else { //Console.WriteLine("Obfuscation failed {0} times. Possible problems: (1) FILLED and NOT_INITIALIZED collision; (2) basic blocks with single GOTO predecessor. Consequence: weaker result.", Common.MaxNumberOfRuns); Console.WriteLine("Obfuscation process was unsuccessful {0} times. Consequence: weaker resilience.", Common.MaxNumberOfRuns); Console.WriteLine("Do you want to try again? (y/n)"); char answer = Convert.ToChar(Console.Read()); switch (answer) { case 'y': case 'Y': Console.WriteLine("Trying again..."); Console.WriteLine(); TryAgain = true; routine = (Routine)exch; break; case 'n': case 'N': Console.WriteLine("Using the resulting code..."); Console.WriteLine(); TryAgain = false; break; default: throw new Exception("Invalid answer!"); } } } while (TryAgain); Console.Write("Logging TAC after obfuscation"); Logging.WriteReadableTAC(routine); routine.Validate(); PrintSuccess(); Console.Write("Collecting and writing statistics"); Logging.WriteStatistics(routine); PrintSuccess(); Console.Write("Performing logical control"); routine.Validate(); PrintSuccess(); exch = (ExchangeFormat.Exchange)routine; }