Skip to content

Commit

Permalink
Add new rename mode for not changing the name (#170)
Browse files Browse the repository at this point in the history
* Add rename mode to keep the names the same

* Added new rename mode to unit test
  • Loading branch information
mkaring authored Jul 12, 2020
1 parent 039726e commit 9d08917
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
6 changes: 4 additions & 2 deletions Confuser.Renamer/NameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,11 @@ public string ObfuscateName(string name, RenameMode mode) {

if (mode == RenameMode.Empty)
return "";
if (mode == RenameMode.Debug)
if (mode == RenameMode.Debug || mode == RenameMode.Retain) {
// When flattening there are issues, in case there is a . in the name of the assembly.
return MakeGenericName("_" + name.Replace('.', '_'), count);
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.");
Expand Down
8 changes: 6 additions & 2 deletions Confuser.Renamer/RenameMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public enum RenameMode {
Sequential = 0x11,
Reversible = 0x12,

Debug = 0x20
/// <summary>Add a underscore to the name to mark that it would be renamed.</summary>
Debug = 0x20,

/// <summary>Keep the names as they are.</summary>
Retain = Int32.MaxValue
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public async Task InheritCustomAttribute(string renameMode, bool flatten) {
}

public static IEnumerable<object[]> InheritCustomAttributeData() {
foreach (var renameMode in new string[] { nameof(RenameMode.Unicode), nameof(RenameMode.ASCII), nameof(RenameMode.Letters), nameof(RenameMode.Debug) })
foreach (var renameMode in new string[] { nameof(RenameMode.Unicode), nameof(RenameMode.ASCII), nameof(RenameMode.Letters), nameof(RenameMode.Debug), nameof(RenameMode.Retain) })
foreach (var flatten in new bool[] { true, false })
yield return new object[] { renameMode, flatten };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public async Task RenameDynamicType(string renameMode, bool flatten) {
}

public static IEnumerable<object[]> RenameDynamicTypeData() {
foreach (var renameMode in new string[] { nameof(RenameMode.Unicode), nameof(RenameMode.ASCII), nameof(RenameMode.Letters), nameof(RenameMode.Debug) })
foreach (var renameMode in new string[] { nameof(RenameMode.Unicode), nameof(RenameMode.ASCII), nameof(RenameMode.Letters), nameof(RenameMode.Debug), nameof(RenameMode.Retain) })
foreach (var flatten in new bool[] { true, false })
yield return new object[] { renameMode, flatten };
}
Expand Down

0 comments on commit 9d08917

Please sign in to comment.