// Obfuscate all local symbols // - enumerate all local symbols and tell the symbol allocator // that it can be obfuscated. // - where there are `holes` in the rank mapping, tell the symbol // allocator to reserve those symbols. These holes are to be // filled by higher frequency symbols on the inner scopes. public void ObfuscateSymbols(RenderContext ctx, SymbolFrequency SymbolFrequency, SymbolAllocator Allocator, string prefix) { // Walk through local symbols int expectedRank = 0; foreach (var symbol in SymbolFrequency.Sort()) { // Ignore public symbols if (symbol.Accessibility != Accessibility.Private) continue; // Ignore non-local symbols if (symbol.Scope != Symbol.ScopeType.local) continue; // Reserve space for inner, higher frequency symbols if (symbol.Rank > expectedRank) { if (ctx.Compiler.Formatted && ctx.Compiler.SymbolInfo) { for (int r = expectedRank; r < symbol.Rank; r++) { ctx.StartLine(); ctx.AppendFormat("// #{0} reserved", r); } } Allocator.ReserveObfuscatedSymbols(symbol.Rank - expectedRank); } string newSymbol = Allocator.OnfuscateSymbol(symbol.Name); // Show info if (ctx.Compiler.Formatted && ctx.Compiler.SymbolInfo) { ctx.StartLine(); ctx.AppendFormat("// #{0} {3}{1} -> {3}{2}", symbol.Rank, symbol.Name, newSymbol, prefix); } expectedRank = symbol.Rank + 1; } }
public void ObfuscateSymbols(RenderContext ctx) { // Obfuscate all symbols ObfuscateSymbols(ctx, Symbols, ctx.Symbols, ""); ObfuscateSymbols(ctx, Members, ctx.Members, "."); // Dump const eliminated variables foreach (var i in Symbols.Where(x=>x.Value.ConstValue!=null)) { // Show info if (ctx.Compiler.Formatted && ctx.Compiler.SymbolInfo) { ctx.StartLine(); ctx.AppendFormat("// {0} -> optimized away (const)", i.Value.Name); } } }