Skip to content
This repository has been archived by the owner on Jan 27, 2019. It is now read-only.

Commit

Permalink
Preserve generic parameter count in obfuscated name
Browse files Browse the repository at this point in the history
Fix #463
  • Loading branch information
yck1509 committed Mar 27, 2016
1 parent c890466 commit 6abd572
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions Confuser.Renamer/NameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,30 @@ string ObfuscateNameInternal(byte[] hash, RenameMode mode) {
}
}

string ParseGenericName(string name, out int? count) {
if (name.LastIndexOf('`') != -1) {
int index = name.LastIndexOf('`');
int c;
if (int.TryParse(name.Substring(index + 1), out c)) {
count = c;
return name.Substring(0, index);
}
}
count = null;
return name;
}

string MakeGenericName(string name, int? count) {
if (count == null)
return name;
else
return string.Format("{0}`{1}", name, count.Value);
}

public string ObfuscateName(string name, RenameMode mode) {
string newName = null;
int? count;
name = ParseGenericName(name, out count);

if (string.IsNullOrEmpty(name))
return string.Empty;
Expand All @@ -196,7 +218,7 @@ public string ObfuscateName(string name, RenameMode mode) {
if (reversibleRenamer == null)
throw new ArgumentException("Password not provided for reversible renaming.");
newName = reversibleRenamer.Encrypt(name);
return newName;
return MakeGenericName(newName, count);
}

if (nameMap1.ContainsKey(name))
Expand All @@ -205,7 +227,7 @@ public string ObfuscateName(string name, RenameMode mode) {
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(newName))
if (!identifiers.Contains(MakeGenericName(newName, count)))
break;
hash = Utils.SHA1(hash);
}
Expand All @@ -215,7 +237,7 @@ public string ObfuscateName(string name, RenameMode mode) {
nameMap1[name] = newName;
}

return newName;
return MakeGenericName(newName, count);
}

public string RandomName() {
Expand Down

0 comments on commit 6abd572

Please # to comment.