private void AddItem(Object asset, RenameMode objectType) { string filePath = AssetDatabase.GetAssetPath (asset); if (Directory.Exists (filePath)) { string[] directories = Directory.GetDirectories (filePath); foreach (string nextPath in directories) { AddItem (AssetDatabase.LoadAssetAtPath (nextPath, typeof (Object)), RenameMode.Directry); } if (objectDict.ContainsKey (asset) == false) { objectDict.Add (asset, objectType); } } string[] filePathes = Directory.GetFiles (filePath); for (int i=filePathes.Length-1; i>=0; i--) { Object obj = AssetDatabase.LoadAssetAtPath (filePathes[i], typeof (Object)); if (obj == null || objectDict.ContainsKey (obj)) { continue; } objectDict.Add (obj, RenameMode.File); } }
public string ObfuscateName(string name, RenameMode mode) { string newName = null; int? count; name = ParseGenericName(name, out count); if (string.IsNullOrEmpty(name)) { return(string.Empty); } if (mode == RenameMode.Empty) { return(""); } if (mode == RenameMode.Debug) { return("_" + name); } if (mode == RenameMode.Reversible) { if (reversibleRenamer == null) { throw new ArgumentException("Password not provided for reversible renaming."); } newName = reversibleRenamer.Encrypt(name); return(MakeGenericName(newName, count)); } if (nameMap1.ContainsKey(name)) { return(nameMap1[name]); } byte[] hash = Utils.Xor(Utils.SHA1(Encoding.UTF8.GetBytes(name)), nameSeed); for (int i = 0; i < 100; i++) { newName = ObfuscateNameInternal(hash, mode); if (!identifiers.Contains(MakeGenericName(newName, count))) { break; } hash = Utils.SHA1(hash); } if ((mode & RenameMode.Decodable) != 0) { nameMap2[newName] = name; nameMap1[name] = newName; } return(MakeGenericName(newName, count)); }
/// <summary> /// 文件传输 /// </summary> /// <param name="task"></param> public static void CopyFiles(string sourceFileName, string destFileName, RenameMode renameMode) { if (renameMode == RenameMode.Overwrite) { System.IO.File.Copy(sourceFileName, destFileName, true); } else if (renameMode == RenameMode.Accumulate) { FilesReadHelper inputReadHelper = new FilesReadHelper(sourceFileName); FilesReadHelper outputReadHelper = new FilesReadHelper(System.IO.Path.GetDirectoryName(destFileName) + "\\" + System.IO.Path.GetFileName(sourceFileName)); System.IO.File.Copy(sourceFileName, outputReadHelper.Directory + "\\" + outputReadHelper.AccumulativeName); } }
public void ReduceRenameMode(object obj, RenameMode val) { RenameMode original = GetRenameMode(obj); if (original < val) { context.Annotations.Set(obj, RenameModeKey, val); } if (val <= RenameMode.Reflection && obj is IDnlibDef dnlibDef) { var name = ExtractDisplayNormalizedName(dnlibDef, true); SetNormalizedName(dnlibDef, name.NormalizedName); } }
DisplayNormalizedName CompressTypeName(string typeName, RenameMode renameMode) { if (renameMode == RenameMode.Reversible) { if (!_prefixesMap.TryGetValue(typeName, out string prefix)) { _prefixesMap.Add(typeName, GetNextSequentialName()); } return(new DisplayNormalizedName(typeName, prefix)); } return(new DisplayNormalizedName(typeName, typeName)); }
public static string GenerateName(RenameMode rm) { string ascii = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; string unreadable = "✓ ✔ ☑ ♥ ❤ ❥ ❣ ☂ ☔ ☎ ☏ ☒ ☘ ☠ ☹ ☺ ☻ ♬ ♻ ♲ ♿ ⚠ ☃ ʚϊɞ ✖ ✗ ✘ ♒ ♬ ✄ ✂ ✆ ✉ ✦ ✧ ♱ ♰ ♂ ♀ ☿ ❤ ❥ ❦ ❧ ™ ® © ♡ ♦ ♢ ♔ ♕ ♚ ♛ ★ ☆ ✮ ✯ ☄ ☾ ☽ ☼ ☀ ☁ ☂ ☃ ☻ ☺ ☹ ۞ ۩ εїз ☎ ☏ ¢ ☚ ☛ ☜ ☝ ☞ ☟ ✍ ✌ ☢ ☣ ☠ ☮ ☯ ♠ ♤ ♣ ♧ ♥࿂ ე ჳ ᆡ ༄ ♨ ๑ ❀ ✿ ψ ♆ ☪ ☭ ♪ ♩ ♫ ℘ ℑ ℜ ℵ ♏ η α ʊ ϟ ღ ツ 回 ₪ ™ © ® ¿ ¡ № ⇨ ❝ ❞ ℃ƺ ◠ ◡ ╭ ╮ ╯ ╰ ★ ☆ ⊙¤ ㊣★☆♀◆◇◣◢◥▲▼△▽⊿◤ ◥▆ ▇ █ █ ■ "; if (rm == RenameMode.ASCII) { return(RandomString(LeetRandom.rnd.Next(0, 20), ascii)); } else { return(RandomString(LeetRandom.rnd.Next(0, 20), unreadable)); } }
public void ReduceRenameMode(object obj, RenameMode val) { RenameMode original = GetRenameMode(obj); if (original < val) { context.Annotations.Set(obj, RenameModeKey, val); } if (val <= RenameMode.Reflection && obj is IDnlibDef dnlibDef) { string nameWithoutParams = GetSimplifiedFullName(dnlibDef, true); SetOriginalName(dnlibDef, nameWithoutParams); } }
public static string GenerateString(RenameMode mode) { switch (mode) { case RenameMode.Ascii: return(RandomString(Random.Next(1, 7), Ascii)); case RenameMode.Normal: return(GetRandomName()); default: throw new ArgumentOutOfRangeException(nameof(mode), mode, null); } }
DisplayNormalizedName CompressTypeName(string typeName, RenameMode renameMode) { if (renameMode == RenameMode.Reversible) { if (!_prefixesMap.TryGetValue(typeName, out string prefix)) { IncrementNameId(); prefix = Utils.EncodeString(nameId, alphaNumCharset); _prefixesMap.Add(typeName, prefix); } return(new DisplayNormalizedName(typeName, prefix)); } return(new DisplayNormalizedName(typeName, typeName)); }
public string ObfuscateName(string name, RenameMode mode) { string newName = null; int? count; name = ParseGenericName(name, out count); return(Name); //if(string.IsNullOrEmpty(name)) // return string.Empty; //if(mode == RenameMode.Empty) // return ""; //if(mode == RenameMode.Debug) // return "_" + name; //if(mode == RenameMode.Reversible) //{ // if(reversibleRenamer == null) // throw new ArgumentException("Password not provided for reversible renaming."); // newName = reversibleRenamer.Encrypt(name); // return MakeGenericName(newName, count); //} //if(nameMap1.ContainsKey(name)) // return nameMap1[name]; //var hash = Utils.Xor(Utils.SHA1(Encoding.UTF8.GetBytes(name)), nameSeed); //for(var i = 0; i < 100; i++) //{ // newName = ObfuscateNameInternal(hash, mode); // if(!identifiers.Contains(MakeGenericName(newName, count))) // break; // hash = Utils.SHA1(hash); //} //if((mode & RenameMode.Decodable) != 0) //{ // nameMap2[newName] = name; // nameMap1[name] = newName; //} //return MakeGenericName(newName, count); }
public void ProtectionPhase(SpectreContext spctx) { RenameMode mode = RenameMode.UNREADABLE; foreach (ModuleDef module in spctx.Assembly.Modules) { foreach (TypeDef type in module.Types) { if (Utils.CanRename(type)) { type.Name = Utils.GenerateName(mode); } foreach (MethodDef method in type.Methods) { if (Utils.CanRename(method)) { method.Name = Utils.GenerateName(mode); } foreach (var param in method.Parameters) { param.Name = Utils.GenerateName(mode); } } foreach (FieldDef field in type.Fields) { if (Utils.CanRename(field)) { field.Name = Utils.GenerateName(mode); } } foreach (EventDef eventf in type.Events) { if (Utils.CanRename(eventf)) { eventf.Name = Utils.GenerateName(mode); } } } } }
public static string GetName(RenameMode mode, int length) { switch (mode) { case RenameMode.Base64: return(GetRandomName().Base64Representation()); case RenameMode.Chinese: return(GetChineseString(length)); case RenameMode.Invalid: return(GetFuckedString(length)); case RenameMode.Logical: return(GetRandomName()); default: throw new InvalidOperationException(); } }
public string ObfuscateName(string name, RenameMode mode) { if (string.IsNullOrEmpty(name)) { return(string.Empty); } if (mode == RenameMode.Empty) { return(""); } if (mode == RenameMode.Debug) { return("_" + name); } byte[] hash = Utils.Xor(Utils.SHA1(Encoding.UTF8.GetBytes(name)), nameSeed); switch (mode) { case RenameMode.Empty: return(""); case RenameMode.Unicode: return(Utils.EncodeString(hash, unicodeCharset) + "\u202e"); case RenameMode.Letters: return(Utils.EncodeString(hash, letterCharset)); case RenameMode.ASCII: return(Utils.EncodeString(hash, asciiCharset)); case RenameMode.Decodable: var newName = "=" + Utils.EncodeString(hash, alphaNumCharset) + "="; nameDict[newName] = name; return(newName); } throw new NotSupportedException("Rename mode '" + mode + "' is not supported."); }
public ProfileRenamePopUp(ProfileWindow window, float width, int colIndex, string id = "") { m_Window = window; m_id = id; k_Width = width; m_FieldStyle = new GUIStyle(EditorStyles.textField); m_FieldStyle.focused.background = EditorStyles.textField.focused.background; // Renaming a profile if (colIndex == 0) { m_Index = GetProfileIndexById(id); m_Text = m_Window.settings.profileSettings.GetProfileName(id); m_FieldStyle.alignment = TextAnchor.UpperLeft; m_Mode = RenameMode.Profile; } // Renaming a variable else if (colIndex > 0 && m_id == "") { m_Index = colIndex - 1; m_Text = m_Window.settings.profileSettings.profileEntryNames[m_Index].ProfileName; m_FieldStyle.alignment = TextAnchor.MiddleLeft; m_Mode = RenameMode.Variable; } // Renaming a variable value else { m_Index = colIndex - 1; m_Text = m_Window.settings.profileSettings.GetProfile(m_id).values[m_Index].value; m_FieldStyle.alignment = TextAnchor.UpperLeft; m_Mode = RenameMode.Value; } m_OrigText = m_Text; }
public static void Rename(IMemberDef member, RenameMode mode, int depth = 1, int sublength = 10) { member.Name = GetEndName(mode, depth, sublength); }
private void OnGUI() { useSerial = EditorGUILayout.Toggle ("Use Serial", useSerial); if (useSerial == false) { fromName = EditorGUILayout.TextField ("From", fromName); toName = EditorGUILayout.TextField ("To", toName); } else { prefix = EditorGUILayout.TextField (" + Delimiter", prefix); retrofit = EditorGUILayout.TextField (" + Retrofit", retrofit); startSerialNo = EditorGUILayout.IntField (" + Start No", startSerialNo); increment = EditorGUILayout.IntField (" + Increment(s)", increment); format = EditorGUILayout.TextField (" + Format", format); } renameMode = (RenameMode)EditorGUILayout.EnumPopup ("Rename Mode", renameMode); Event dropEvent = Event.current; Rect dropArea = GUILayoutUtility.GetRect (0.0f, 70.0f, GUILayout.ExpandWidth(true)); GUI.Box(dropArea,"Drag & Drop (File or Directry)"); int id = GUIUtility.GetControlID(FocusType.Passive); if (dropEvent.type == EventType.DragExited) { if(dropArea.Contains(dropEvent.mousePosition)) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; DragAndDrop.activeControlID = id; DragAndDrop.AcceptDrag(); foreach(Object draggedObject in DragAndDrop.objectReferences) { RenameMode objectType = RenameMode.File; if (Directory.Exists (AssetDatabase.GetAssetPath(draggedObject))) { objectType = RenameMode.Directry; } AddItem (draggedObject, objectType); } DragAndDrop.activeControlID = 0; Event.current.Use(); } } if (objectDict.Count > 0) { GUILayout.BeginHorizontal (); if (GUILayout.Button ("Rename") == true) { SortByFileName (); Rename (); } if (GUILayout.Button ("Clear") == true) { Clear (); } GUILayout.EndHorizontal (); } scroll = EditorGUILayout.BeginScrollView (scroll); foreach (Object obj in objectDict.Keys) { if (obj == null) { continue; } EditorGUILayout.BeginHorizontal (); if (GUILayout.Button ("Remove", GUILayout.Width (65)) == true) { objectDict.Remove (obj); break; } else { Color fontColor = Color.blue; string filePath = AssetDatabase.GetAssetPath (obj); string fileName = obj.name; if (fileName.Contains (fromName) == false || objectDict[obj] != renameMode) { fontColor = Color.red; } GUI.contentColor = fontColor; GUILayout.Label (filePath.Replace ("Assets/", "")); } GUI.contentColor = Color.white; EditorGUILayout.EndHorizontal (); } EditorGUILayout.EndScrollView (); }
// Token: 0x0600025D RID: 605 RVA: 0x00003465 File Offset: 0x00001665 public void SetRenameMode(object obj, RenameMode val) { this.context.Annotations.Set <RenameMode>(obj, NameService.RenameModeKey, val); }
// Token: 0x06000262 RID: 610 RVA: 0x0001FAF8 File Offset: 0x0001DCF8 public string ObfuscateName(string name, RenameMode mode) { if (string.IsNullOrEmpty(name)) { return(string.Empty); } if (mode == RenameMode.Empty) { return(""); } if (mode == RenameMode.Debug) { return("_" + name); } byte[] hash = Utils.Xor(Utils.SHA1(Encoding.UTF8.GetBytes(name)), this.nameSeed); switch (mode) { case RenameMode.Empty: return(""); /*case RenameMode.Unicode: * return Utils.EncodeString(hash, NameService.unicodeCharset) + ""; * case RenameMode.ASCII: * return Utils.EncodeString(hash, NameService.asciiCharset); * case RenameMode.Letters: * return Utils.EncodeString(hash, NameService.letterCharset);*/ default: switch (mode) { case RenameMode.Decodable: { if (this.nameMap1.ContainsKey(name)) { return(this.nameMap1[name]); } this.IncrementNameId(); string newName = "_" + Utils.EncodeString(hash, NameService.alphaNumCharset) + "_"; this.nameMap2[newName] = name; this.nameMap1[name] = newName; return(newName); } case RenameMode.Sequential: { if (this.nameMap1.ContainsKey(name)) { return(this.nameMap1[name]); } this.IncrementNameId(); //string newName2 = "ᅠ" +Utils.EncodeString(this.nameId, NameService.unicodeCharset )+RandomString(name.Length + new Random().Next(5,10)); string newName2 = "Rzy-Protector" + Utils.EncodeString(this.nameId, NameService.alphaNumCharset) + "CreeperᅠᅠᅠᅠAww ManᅠᅠᅠᅠᅠᅠF**k skidders" + Utils.EncodeString(this.nameId, NameService.alphaNumCharset) + "ᅠᅠᅠᅠᅠhttps://rzy.beᅠᅠᅠᅠaw manᅠ"; if (File.Exists($"{ Directory.GetCurrentDirectory()}\\Configs\\CustomRenamer.rzy")) { string text = File.ReadAllText($"{Directory.GetCurrentDirectory()}\\Configs\\CustomRenamer.rzy"); string customrenamer = text.Split(new char[] { ':' })[0].Replace(" ", ""); if (text.Length > 0.1) { // je dois changer le custom renamer avec prefix le custom rename & sufix newName2 = Utils.EncodeString(this.nameId, NameService.alphaNumCharset) + customrenamer; } } // string newName2 = "Kill-Yourself-<3" + Utils.EncodeString(this.nameId, NameService.alphaNumCharset) + "Kill-Yourself-<3" + Utils.EncodeString(this.nameId, NameService.alphaNumCharset) + Utils.EncodeString(this.nameId, NameService.alphaNumCharset) + "Kill-Yourself-<3" + Utils.EncodeString(this.nameId, NameService.alphaNumCharset) + Utils.EncodeString(this.nameId, NameService.alphaNumCharset) + "Kill-Yourself-<3" + Utils.EncodeString(this.nameId, NameService.alphaNumCharset) + Utils.EncodeString(this.nameId, NameService.alphaNumCharset) + "Kill-Yourself-<3" + Utils.EncodeString(this.nameId, NameService.alphaNumCharset); this.nameMap2[newName2] = name; this.nameMap1[name] = newName2; return(newName2); } case RenameMode.Reversible: if (this.reversibleRenamer == null) { throw new ArgumentException("Password not provided for reversible renaming."); } return(this.reversibleRenamer.Encrypt(name)); default: throw new NotSupportedException("Rename mode '" + mode + "' is not supported."); } break; } }
public void ReduceRenameMode(object obj, RenameMode val) { RenameMode original = GetRenameMode(obj); if (original < val) context.Annotations.Set(obj, RenameModeKey, val); }
public string ObfuscateName(string format, string name, RenameMode mode) { string newName = null; name = ParseGenericName(name, out var count); if (string.IsNullOrEmpty(name)) { return(string.Empty); } if (mode == RenameMode.Empty) { return(""); } if (mode == RenameMode.Debug || mode == RenameMode.Retain) { // When flattening there are issues, in case there is a . in the name of the assembly. newName = MakeGenericName(name.Replace('.', '_'), count); return(mode == RenameMode.Debug ? "_" + newName : newName); } if (mode == RenameMode.Reversible) { if (reversibleRenamer == null) { throw new ArgumentException("Password not provided for reversible renaming."); } newName = reversibleRenamer.Encrypt(name); return(MakeGenericName(newName, count)); } if (nameMap1.ContainsKey(name)) { return(MakeGenericName(nameMap1[name], count)); } byte[] hash = Utils.Xor(Utils.SHA1(Encoding.UTF8.GetBytes(name)), nameSeed); for (int i = 0; i < 100; i++) { newName = ObfuscateNameInternal(hash, mode); try { if (!(format is null)) { newName = string.Format(CultureInfo.InvariantCulture, format, newName); } } catch (FormatException ex) { throw new ArgumentException( string.Format(CultureInfo.InvariantCulture, Resources.NameService_ObfuscateName_InvalidFormat, format), nameof(format), ex); } if (!identifiers.Contains(MakeGenericName(newName, count))) { break; } hash = Utils.SHA1(hash); } if ((mode & RenameMode.Decodable) != 0) { nameMap2[newName] = name; nameMap1[name] = newName; } return(MakeGenericName(newName, count)); }
public string ObfuscateName(string name, RenameMode mode) => ObfuscateName(null, name, mode);
public static void Apply(bool autoFix, RenameMode renameMode, bool overwrite, Action <FileInfo, ErrorCode> progressIncrement) { bool parallelApply = true; Parallel.ForEach(Files, (fileInfo, parallelLoopState) => { if (File.Exists(fileInfo.OriginalFullPath)) { parallelApply = false; parallelLoopState.Break(); } }); int failed = 0; ConcurrentQueue <FileInfo> succeededItems = new ConcurrentQueue <FileInfo>(); void itemChanger(FileInfo fileInfo) { if (autoFix) { fileInfo.ChangedPath = FilesHelper.ReplaceInvalidPathCharacters(fileInfo.ChangedPath); fileInfo.ChangedFilename = FilesHelper.ReplaceInvalidFilenameCharacters(fileInfo.ChangedFilename); } ErrorCode errorMessage = ErrorCode.NoError; if (renameMode == RenameMode.Move) { fileInfo.Move(overwrite, out errorMessage); } else if (renameMode == RenameMode.Copy) { fileInfo.Copy(overwrite, out errorMessage); } progressIncrement?.Invoke(fileInfo, errorMessage); if (errorMessage != ErrorCode.NoError) { Interlocked.Increment(ref failed); } else { succeededItems.Enqueue(fileInfo); } } if (parallelApply) { Daramee.Winston.File.Operation.Begin(true); Parallel.ForEach(Files, itemChanger); Daramee.Winston.File.Operation.End(); } else { Daramee.Winston.File.Operation.Begin(true); Parallel.ForEach(from f in Files where !File.Exists(f.ChangedFullPath) select f, itemChanger); Daramee.Winston.File.Operation.End(); List <FileInfo> sortingFileInfo = new List <FileInfo>(from f in Files where !succeededItems.Contains(f) && f.OriginalFullPath != f.ChangedFullPath select f); List <FileInfo> temp = new List <FileInfo>(); bool changed = false; do { changed = false; Daramee.Winston.File.Operation.Begin(true); foreach (var fileInfo in sortingFileInfo) { if (!File.Exists(fileInfo.ChangedFullPath)) { itemChanger(fileInfo); changed = true; temp.Add(fileInfo); } else { foreach (var succeededFileInfo in Enumerable.Concat(succeededItems, temp)) { if (succeededFileInfo.ChangedFullPath != fileInfo.ChangedFullPath && succeededFileInfo.OriginalFullPath == fileInfo.ChangedFullPath) { itemChanger(fileInfo); changed = true; temp.Add(fileInfo); break; } } } } Daramee.Winston.File.Operation.End(); foreach (var proceed in temp) { sortingFileInfo.Remove(proceed); } temp.Clear(); } while (changed); if (overwrite) { Parallel.ForEach(sortingFileInfo, (fileInfo) => { itemChanger(fileInfo); }); } else { failed += sortingFileInfo.Count; foreach (var fileInfo in sortingFileInfo) { progressIncrement(fileInfo, ErrorCode.IOError); } } } Parallel.ForEach(succeededItems, (fileInfo) => fileInfo.Changed()); }
public string RandomName(RenameMode mode) { return(ObfuscateName(Utils.ToHexString(random.NextBytes(16)), mode)); }
protected override void Execute(ConfuserContext context, ProtectionParameters parameters) { var service = (NameService)context.Registry.GetService <INameService>(); context.Logger.Debug("Renaming..."); foreach (IRenamer renamer in service.Renamers) { foreach (IDnlibDef def in parameters.Targets) { renamer.PreRename(context, service, parameters, def); } context.CheckCancellation(); } var targets = parameters.Targets.ToList(); service.GetRandom().Shuffle(targets); var pdbDocs = new HashSet <string>(); foreach (IDnlibDef def in GetTargetsWithDelay(targets, context, service).WithProgress(targets.Count, context.Logger)) { if (def is ModuleDef && parameters.GetParameter(context, def, "rickroll", false)) { RickRoller.CommenceRickroll(context, (ModuleDef)def); } bool canRename = service.CanRename(def); RenameMode mode = service.GetRenameMode(def); if (def is MethodDef) { var method = (MethodDef)def; if ((canRename || method.IsConstructor) && parameters.GetParameter(context, def, "renameArgs", true)) { foreach (ParamDef param in ((MethodDef)def).ParamDefs) { param.Name = null; } } if (parameters.GetParameter(context, def, "renPdb", false) && method.HasBody) { foreach (var instr in method.Body.Instructions) { if (instr.SequencePoint != null && !pdbDocs.Contains(instr.SequencePoint.Document.Url)) { instr.SequencePoint.Document.Url = service.ObfuscateName(instr.SequencePoint.Document.Url, mode); pdbDocs.Add(instr.SequencePoint.Document.Url); } } foreach (var local in method.Body.Variables) { if (!string.IsNullOrEmpty(local.Name)) { local.Name = service.ObfuscateName(local.Name, mode); } } if (method.Body.HasPdbMethod) { method.Body.PdbMethod.Scope = new PdbScope(); } } } if (!canRename) { continue; } service.SetIsRenamed(def); IList <INameReference> references = service.GetReferences(def); bool cancel = references.Any(r => r.ShouldCancelRename); if (cancel) { continue; } if (def is TypeDef) { var typeDef = (TypeDef)def; if (parameters.GetParameter(context, def, "flatten", true)) { typeDef.Name = service.ObfuscateName(typeDef.FullName, mode); typeDef.Namespace = ""; } else { typeDef.Namespace = context.namespace_prefix + service.ObfuscateName(typeDef.Namespace, mode); typeDef.Name = service.ObfuscateName(typeDef.Name, mode); } foreach (var param in typeDef.GenericParameters) { param.Name = ((char)(param.Number + 1)).ToString(); } } else if (def is MethodDef) { foreach (var param in ((MethodDef)def).GenericParameters) { param.Name = ((char)(param.Number + 1)).ToString(); } def.Name = service.ObfuscateName(def.Name, mode); } else { def.Name = service.ObfuscateName(def.Name, mode); } int updatedReferences = -1; do { var oldUpdatedCount = updatedReferences; // This resolves the changed name references and counts how many were changed. var updatedReferenceList = references.Where(refer => refer.UpdateNameReference(context, service)).ToArray(); updatedReferences = updatedReferenceList.Length; if (updatedReferences == oldUpdatedCount) { var errorBuilder = new StringBuilder(); errorBuilder.AppendLine("Infinite loop detected while resolving name references."); errorBuilder.Append("Processed definition: ").AppendDescription(def, service).AppendLine(); errorBuilder.Append("Assembly: ").AppendLine(context.CurrentModule.FullName); errorBuilder.AppendLine("Faulty References:"); foreach (var reference in updatedReferenceList) { errorBuilder.Append(" - ").AppendLine(reference.ToString(service)); } context.Logger.Error(errorBuilder.ToString().Trim()); throw new ConfuserException(); } context.CheckCancellation(); } while (updatedReferences > 0); } }
// Token: 0x06000262 RID: 610 RVA: 0x0001FAF8 File Offset: 0x0001DCF8 public string ObfuscateName(string name, RenameMode mode) { if (string.IsNullOrEmpty(name)) { return(string.Empty); } if (mode == RenameMode.Empty) { return(""); } if (mode == RenameMode.Debug) { return("_" + name); } byte[] hash = Utils.Xor(Utils.SHA1(Encoding.UTF8.GetBytes(name)), this.nameSeed); switch (mode) { case RenameMode.Empty: return(""); case RenameMode.Unicode: return(Utils.EncodeString(hash, NameService.unicodeCharset) + ""); case RenameMode.ASCII: return(Utils.EncodeString(hash, NameService.asciiCharset)); case RenameMode.Letters: return(Utils.EncodeString(hash, NameService.letterCharset)); default: switch (mode) { case RenameMode.Decodable: { if (this.nameMap1.ContainsKey(name)) { return(this.nameMap1[name]); } this.IncrementNameId(); string newName = "_" + Utils.EncodeString(hash, NameService.alphaNumCharset) + "_"; this.nameMap2[newName] = name; this.nameMap1[name] = newName; return(newName); } case RenameMode.Sequential: { if (this.nameMap1.ContainsKey(name)) { return(this.nameMap1[name]); } this.IncrementNameId(); //string newName2 = "ᅠ" +Utils.EncodeString(this.nameId, NameService.unicodeCharset )+RandomString(name.Length + new Random().Next(5,10)); string newName2 = "Beds-Protector-The-Quick-Brown-FoxᅠᅠᅠᅠᅠJumped-Over-The-Lazy-Dog" + Utils.EncodeString(this.nameId, NameService.alphaNumCharset) + "The-ᅠᅠᅠᅠQuick-Brown-ᅠᅠᅠᅠᅠᅠe-Lazy-Dog" + Utils.EncodeString(this.nameId, NameService.alphaNumCharset) + "ᅠᅠᅠᅠᅠThe-Quick-Brown-Fox-Jumped-Over-The-Laᅠᅠᅠᅠzyᅠ"; // string newName2 = "Kill-Yourself-<3" + Utils.EncodeString(this.nameId, NameService.alphaNumCharset) + "Kill-Yourself-<3" + Utils.EncodeString(this.nameId, NameService.alphaNumCharset) + Utils.EncodeString(this.nameId, NameService.alphaNumCharset) + "Kill-Yourself-<3" + Utils.EncodeString(this.nameId, NameService.alphaNumCharset) + Utils.EncodeString(this.nameId, NameService.alphaNumCharset) + "Kill-Yourself-<3" + Utils.EncodeString(this.nameId, NameService.alphaNumCharset) + Utils.EncodeString(this.nameId, NameService.alphaNumCharset) + "Kill-Yourself-<3" + Utils.EncodeString(this.nameId, NameService.alphaNumCharset); this.nameMap2[newName2] = name; this.nameMap1[name] = newName2; return(newName2); } case RenameMode.Reversible: if (this.reversibleRenamer == null) { throw new ArgumentException("Password not provided for reversible renaming."); } return(this.reversibleRenamer.Encrypt(name)); default: throw new NotSupportedException("Rename mode '" + mode + "' is not supported."); } break; } }
public TransferTask(Guid id, string sourceFileName, string destFileName, TaskType type, RenameMode renameMode, TaskCategory category, int taskSize) { this.ID = id; this.Name = System.IO.Path.GetFileNameWithoutExtension(this.SourceFileName); this.SourceFileName = sourceFileName; this.DestFileName = destFileName; this.Progress = 0; this.Size = taskSize; this.NetSize = 0; this.Speed = 0; this.ElapsedTime = 0; this.LeftTime = int.MaxValue; this.RenameMode = renameMode; this.Type = type; this.Status = TaskStatus.Pending; this.Category = category; }
public string ObfuscateName(string name, RenameMode mode) { if (string.IsNullOrEmpty(name)) { return(string.Empty); } if (mode == RenameMode.Empty) { return(""); } if (mode == RenameMode.Debug) { return("_" + name); } byte[] hash = Utils.Xor(Utils.SHA1(Encoding.UTF8.GetBytes(name)), nameSeed); switch (mode) { case RenameMode.Empty: return(""); case RenameMode.Unicode: return(Utils.EncodeString(hash, unicodeCharset) + "\u202e"); case RenameMode.Letters: return(Utils.EncodeString(hash, letterCharset)); case RenameMode.ASCII: return(Utils.EncodeString(hash, asciiCharset)); case RenameMode.Decodable: { if (nameMap1.ContainsKey(name)) { return(nameMap1[name]); } IncrementNameId(); var newName = Utils.EncodeString(hash, alphaNumCharset); nameMap2[newName] = name; nameMap1[name] = newName; return(newName); } case RenameMode.Sequential: { if (nameMap1.ContainsKey(name)) { return(nameMap1[name]); } IncrementNameId(); var newName = Utils.EncodeString(nameId, alphaNumCharset); nameMap2[newName] = name; nameMap1[name] = newName; return(newName); } case RenameMode.Reversible: { if (reversibleRenamer == null) { throw new ArgumentException("Password not provided for reversible renaming."); } var newName = reversibleRenamer.Encrypt(name); return(newName); } } throw new NotSupportedException("Rename mode '" + mode + "' is not supported."); }
public static void RenameItems(this DirectoryInfo dirInfo, string PatternToReplace, string ReplaceWith, RenameMode Mode = RenameMode.File, bool Recurse = false) { if (!dirInfo.Exists) { return; } if (Mode == RenameMode.File || Mode == RenameMode.Both) { foreach (FileInfo fileInfo in dirInfo.GetFiles()) { if (Regex.IsMatch(fileInfo.Name, PatternToReplace)) { /** * Try-catch to avoid an abort, e.g. in case the replacement already matches the output. */ try { string oldFileName = fileInfo.FullName.TrimEnd('\\'); string newFileName = Regex.Replace(fileInfo.Name, PatternToReplace, ReplaceWith); fileInfo.MoveTo(Path.Combine(fileInfo.DirectoryName, newFileName)); } catch (Exception) { } } } } if (Recurse || Mode == RenameMode.Folder || Mode == RenameMode.Both) { foreach (DirectoryInfo subdirInfo in dirInfo.GetDirectories("*", SearchOption.TopDirectoryOnly)) { if (Recurse) { RenameItems(subdirInfo, PatternToReplace, ReplaceWith, Mode, true); } if ( (Mode == RenameMode.Folder || Mode == RenameMode.Both) && Regex.IsMatch(subdirInfo.Name, PatternToReplace) ) { /** * Try-catch to avoid an abort, e.g. in case the replacement already matches the output. */ try { string oldFolderName = subdirInfo.FullName.TrimEnd('\\'); string newFolderName = Regex.Replace(subdirInfo.Name, PatternToReplace, ReplaceWith); subdirInfo.MoveTo(Path.Combine(dirInfo.FullName, newFolderName)); } catch (Exception) { } } } } }
public void SetRenameMode(object obj, RenameMode val) { context.Annotations.Set(obj, RenameModeKey, val); }
// Token: 0x060002A7 RID: 679 RVA: 0x00020498 File Offset: 0x0001E698 protected override void Execute(ConfuserContext context, ProtectionParameters parameters) { NameService service = (NameService)context.Registry.GetService <INameService>(); context.Logger.Debug("Renaming..."); foreach (IRenamer renamer in service.Renamers) { foreach (IDnlibDef def in parameters.Targets) { renamer.PreRename(context, service, parameters, def); } context.CheckCancellation(); } HashSet <string> pdbDocs = new HashSet <string>(); foreach (IDnlibDef def2 in parameters.Targets.WithProgress(context.Logger)) { if (def2 is ModuleDef && parameters.GetParameter <bool>(context, def2, "rickroll", true)) { RickRoller.CommenceRickroll(context, (ModuleDef)def2); } bool canRename = service.CanRename(def2); RenameMode mode = service.GetRenameMode(def2); if (def2 is MethodDef) { MethodDef method = (MethodDef)def2; if (canRename && parameters.GetParameter <bool>(context, def2, "renameArgs", true)) { foreach (ParamDef param in ((MethodDef)def2).ParamDefs) { param.Name = null; } } if (parameters.GetParameter <bool>(context, def2, "renPdb", true) && method.HasBody) { foreach (Instruction instr in method.Body.Instructions) { if (instr.SequencePoint != null && !pdbDocs.Contains(instr.SequencePoint.Document.Url)) { instr.SequencePoint.Document.Url = service.ObfuscateName(instr.SequencePoint.Document.Url, mode); pdbDocs.Add(instr.SequencePoint.Document.Url); } } foreach (Local local in method.Body.Variables) { if (!string.IsNullOrEmpty(local.Name)) { local.Name = service.ObfuscateName(local.Name, mode); } } method.Body.Scope = null; } } if (canRename) { IList <INameReference> references = service.GetReferences(def2); bool cancel = false; foreach (INameReference refer in references) { cancel |= refer.ShouldCancelRename(); if (cancel) { break; } } if (!cancel) { if (def2 is TypeDef) { TypeDef typeDef = (TypeDef)def2; if (parameters.GetParameter <bool>(context, def2, "flatten", true)) { typeDef.Name = service.ObfuscateName(typeDef.FullName, mode); typeDef.Namespace = ""; } else { typeDef.Namespace = service.ObfuscateName(typeDef.Namespace, mode); typeDef.Name = service.ObfuscateName(typeDef.Name, mode); } using (IEnumerator <GenericParam> enumerator8 = typeDef.GenericParameters.GetEnumerator()) { while (enumerator8.MoveNext()) { GenericParam param2 = enumerator8.Current; param2.Name = ((char)(param2.Number + 1)).ToString(); } goto IL_455; } goto IL_3B6; } goto IL_3B6; IL_455: foreach (INameReference refer2 in references.ToList <INameReference>()) { if (!refer2.UpdateNameReference(context, service)) { context.Logger.ErrorFormat("Failed to update name reference on '{0}'.", new object[] { def2 }); throw new ConfuserException(null); } } context.CheckCancellation(); continue; IL_3B6: if (def2 is MethodDef) { foreach (GenericParam param3 in ((MethodDef)def2).GenericParameters) { param3.Name = ((char)(param3.Number + 1)).ToString(); } def2.Name = service.ObfuscateName(def2.Name, mode); goto IL_455; } def2.Name = service.ObfuscateName(def2.Name, mode); goto IL_455; } } } }
protected override void Execute(ConfuserContext context, ProtectionParameters parameters) { var service = (NameService)context.Registry.GetService <INameService>(); context.Logger.Debug("Renaming..."); foreach (IRenamer renamer in service.Renamers) { foreach (IDnlibDef def in parameters.Targets) { renamer.PreRename(context, service, parameters, def); } context.CheckCancellation(); } var targets = parameters.Targets.ToList(); service.GetRandom().Shuffle(targets); var pdbDocs = new HashSet <string>(); foreach (IDnlibDef def in targets.WithProgress(context.Logger)) { if (def is ModuleDef && parameters.GetParameter(context, def, "rickroll", false)) { RickRoller.CommenceRickroll(context, (ModuleDef)def); } bool canRename = service.CanRename(def); RenameMode mode = service.GetRenameMode(def); if (def is MethodDef) { var method = (MethodDef)def; if ((canRename || method.IsConstructor) && parameters.GetParameter(context, def, "renameArgs", true)) { foreach (ParamDef param in ((MethodDef)def).ParamDefs) { param.Name = null; } } if (parameters.GetParameter(context, def, "renPdb", false) && method.HasBody) { foreach (var instr in method.Body.Instructions) { if (instr.SequencePoint != null && !pdbDocs.Contains(instr.SequencePoint.Document.Url)) { instr.SequencePoint.Document.Url = service.ObfuscateName(instr.SequencePoint.Document.Url, mode); pdbDocs.Add(instr.SequencePoint.Document.Url); } } foreach (var local in method.Body.Variables) { if (!string.IsNullOrEmpty(local.Name)) { local.Name = service.ObfuscateName(local.Name, mode); } } method.Body.Scope = null; } } if (!canRename) { continue; } IList <INameReference> references = service.GetReferences(def); bool cancel = false; foreach (INameReference refer in references) { cancel |= refer.ShouldCancelRename(); if (cancel) { break; } } if (cancel) { continue; } if (def is TypeDef) { var typeDef = (TypeDef)def; if (parameters.GetParameter(context, def, "flatten", true)) { typeDef.Name = service.ObfuscateName(typeDef.FullName, mode); typeDef.Namespace = ""; } else { typeDef.Namespace = service.ObfuscateName(typeDef.Namespace, mode); typeDef.Name = service.ObfuscateName(typeDef.Name, mode); } foreach (var param in typeDef.GenericParameters) { param.Name = ((char)(param.Number + 1)).ToString(); } } else if (def is MethodDef) { foreach (var param in ((MethodDef)def).GenericParameters) { param.Name = ((char)(param.Number + 1)).ToString(); } def.Name = service.ObfuscateName(def.Name, mode); } else { def.Name = service.ObfuscateName(def.Name, mode); } foreach (INameReference refer in references.ToList()) { if (!refer.UpdateNameReference(context, service)) { context.Logger.ErrorFormat("Failed to update name reference on '{0}'.", def); throw new ConfuserException(null); } } context.CheckCancellation(); } }
protected override void Execute(ConfuserContext context, ProtectionParameters parameters) { var service = (NameService)context.Registry.GetService <INameService>(); context.Logger.Debug("Renaming..."); foreach (IRenamer renamer in service.Renamers) { foreach (IDnlibDef def in parameters.Targets) { renamer.PreRename(context, service, parameters, def); } context.CheckCancellation(); } foreach (IDnlibDef def in parameters.Targets.WithProgress(context.Logger)) { if (def is ModuleDef && parameters.GetParameter(context, def, "rickroll", false)) { RickRoller.CommenceRickroll(context, (ModuleDef)def); } bool canRename = service.CanRename(def); if (def is MethodDef) { if (canRename && parameters.GetParameter(context, def, "renameArgs", true)) { foreach (ParamDef param in ((MethodDef)def).ParamDefs) { param.Name = null; } } } if (!canRename && !parameters.GetParameter(context, def, "forceRen", false)) { continue; } RenameMode mode = service.GetRenameMode(def); IList <INameReference> references = service.GetReferences(def); bool cancel = false; foreach (INameReference refer in references) { cancel |= refer.ShouldCancelRename(); if (cancel) { break; } } if (cancel) { continue; } if (def is TypeDef) { var typeDef = (TypeDef)def; if (parameters.GetParameter(context, def, "flatten", true)) { typeDef.Name = service.ObfuscateName(typeDef.FullName, mode); typeDef.Namespace = ""; } else { typeDef.Namespace = service.ObfuscateName(typeDef.Namespace, mode); typeDef.Name = service.ObfuscateName(typeDef.Name, mode); } foreach (var param in typeDef.GenericParameters) { param.Name = ((char)(param.Number + 1)).ToString(); } } else if (def is MethodDef) { foreach (var param in ((MethodDef)def).GenericParameters) { param.Name = ((char)(param.Number + 1)).ToString(); } def.Name = service.ObfuscateName(def.Name, mode); } else { def.Name = service.ObfuscateName(def.Name, mode); } foreach (INameReference refer in references.ToList()) { if (!refer.UpdateNameReference(context, service)) { context.Logger.ErrorFormat("Failed to update name reference on '{0}'.", def); throw new ConfuserException(null); } } context.CheckCancellation(); } }