Skip to content

Commit fdaafaf

Browse files
authored
Merge 40ee77c into acbd871
2 parents acbd871 + 40ee77c commit fdaafaf

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

Confuser.Renamer/NameService.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,15 @@ string MakeGenericName(string name, int? count) {
213213

214214
public string ObfuscateName(string name, RenameMode mode) {
215215
string newName = null;
216-
int? count;
217-
name = ParseGenericName(name, out count);
216+
name = ParseGenericName(name, out var count);
218217

219218
if (string.IsNullOrEmpty(name))
220219
return string.Empty;
221220

222221
if (mode == RenameMode.Empty)
223222
return "";
224223
if (mode == RenameMode.Debug)
225-
return "_" + name;
224+
return MakeGenericName("_" + name, count);
226225
if (mode == RenameMode.Reversible) {
227226
if (reversibleRenamer == null)
228227
throw new ArgumentException("Password not provided for reversible renaming.");

Tests/123_InheritCustomAttr.Test/InheritCustomAttributeTest.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Diagnostics;
34
using System.IO;
45
using System.Threading.Tasks;
56
using Confuser.Core;
67
using Confuser.Core.Project;
8+
using Confuser.Renamer;
79
using Confuser.UnitTest;
810
using Xunit;
911
using Xunit.Abstractions;
@@ -15,13 +17,15 @@ public class InheritCustomAttributeTest {
1517
public InheritCustomAttributeTest(ITestOutputHelper outputHelper) =>
1618
this.outputHelper = outputHelper ?? throw new ArgumentNullException(nameof(outputHelper));
1719

18-
[Fact]
20+
[Theory]
21+
[MemberData(nameof(InheritCustomAttributeData))]
1922
[Trait("Category", "Protection")]
2023
[Trait("Protection", "rename")]
2124
[Trait("Issue", "https://github.com/mkaring/ConfuserEx/issues/123")]
22-
public async Task InheritCustomAttribute() {
25+
[Trait("Issue", "https://github.com/mkaring/ConfuserEx/issues/161")]
26+
public async Task InheritCustomAttribute(string renameMode, bool flatten) {
2327
var baseDir = Environment.CurrentDirectory;
24-
var outputDir = Path.Combine(baseDir, "testtmp");
28+
var outputDir = Path.Combine(baseDir, "testtmp_" + Guid.NewGuid().ToString());
2529
var inputFile = Path.Combine(baseDir, "123_InheritCustomAttr.exe");
2630
var outputFile = Path.Combine(outputDir, "123_InheritCustomAttr.exe");
2731
FileUtilities.ClearOutput(outputFile);
@@ -31,7 +35,10 @@ public async Task InheritCustomAttribute() {
3135
};
3236
proj.Add(new ProjectModule() { Path = inputFile });
3337
proj.Rules.Add(new Rule() {
34-
new SettingItem<Protection>("rename")
38+
new SettingItem<Protection>("rename") {
39+
{ "mode", renameMode },
40+
{ "flatten", flatten ? "True" : "False" }
41+
}
3542
});
3643

3744
var parameters = new ConfuserParameters {
@@ -62,5 +69,11 @@ public async Task InheritCustomAttribute() {
6269

6370
FileUtilities.ClearOutput(outputFile);
6471
}
72+
73+
public static IEnumerable<object[]> InheritCustomAttributeData() {
74+
foreach (var renameMode in new string[] { nameof(RenameMode.Unicode), nameof(RenameMode.ASCII), nameof(RenameMode.Letters), nameof(RenameMode.Debug) })
75+
foreach (var flatten in new bool[] { true, false })
76+
yield return new object[] { renameMode, flatten };
77+
}
6578
}
6679
}

Tests/Confuser.UnitTest/FileUtilities.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.Linq;
34
using System.Security.Cryptography;
45

56
namespace Confuser.UnitTest {
@@ -18,6 +19,14 @@ public static void ClearOutput(string outputFile) {
1819
}
1920
}
2021
catch (UnauthorizedAccessException) { }
22+
23+
try {
24+
var directoryName = Path.GetDirectoryName(outputFile);
25+
if (Directory.Exists(directoryName) && !Directory.EnumerateFileSystemEntries(directoryName).Any()) {
26+
Directory.Delete(directoryName);
27+
}
28+
}
29+
catch (UnauthorizedAccessException) { }
2130
}
2231

2332
public static byte[] ComputeFileChecksum(string file) {

0 commit comments

Comments
 (0)