Skip to content

Commit 36fff36

Browse files
sunnamed434claude
andcommitted
Add post-obfuscation tips (#198)
Print a short list of actionable tips after a run (how to exclude members via [MethodImpl(NoInlining)] / [Obfuscation], disable the watermark, use the libs directory, pick a preset). Implemented as a TipsNotifier in the obfuscation pipeline, gated by a new "Tips" setting (default on). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 009b088 commit 36fff36

4 files changed

Lines changed: 50 additions & 0 deletions

File tree

src/BitMono.Host/obfuscation.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
// Set to true indicates whether enabled
2929
"NotifyProtections": true,
3030

31+
// Outputs short, helpful tips after obfuscation (how to exclude members, disable watermark, etc)
32+
// Set to true indicates whether enabled
33+
"Tips": true,
34+
3135
// Exclude from obfuscation if method has [MethodImpl(MethodImplOptions.NoInlining)] attribute or NoInlining bit
3236
// Set to true indicates whether enabled
3337
"NoInliningMethodObfuscationExclude": true,

src/BitMono.Obfuscation/BitMonoObfuscator.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class BitMonoObfuscator
1313
private readonly ProtectionsNotifier _protectionsNotifier;
1414
private readonly ProtectionsConfigureForNativeCodeNotifier _protectionsConfigureForNativeCodeNotifier;
1515
private readonly ProtectionExecutionNotifier _protectionExecutionNotifier;
16+
private readonly TipsNotifier _tipsNotifier;
1617
private readonly ILogger _logger;
1718
private ProtectionsSort? _protectionsSort;
1819
private PEImageBuildResult? _imageBuild;
@@ -39,6 +40,7 @@ public BitMonoObfuscator(
3940
_protectionsNotifier = new ProtectionsNotifier(_obfuscationSettings, _logger);
4041
_protectionsConfigureForNativeCodeNotifier = new ProtectionsConfigureForNativeCodeNotifier(_obfuscationSettings, _logger);
4142
_protectionExecutionNotifier = new ProtectionExecutionNotifier(_logger);
43+
_tipsNotifier = new TipsNotifier(_obfuscationSettings, _logger);
4244
}
4345

4446
public async Task ProtectAsync()
@@ -63,6 +65,12 @@ public async Task ProtectAsync()
6365
await _pipeline.InvokeAsync(WriteModuleAsync);
6466
await _pipeline.InvokeAsync(PackAsync);
6567
await _pipeline.InvokeAsync(OutputElapsedTime);
68+
await _pipeline.InvokeAsync(OutputTips);
69+
}
70+
71+
private void OutputTips()
72+
{
73+
_tipsNotifier.Notify();
6674
}
6775

6876
private void OutputLoadedModule()
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
namespace BitMono.Obfuscation.Notifiers;
2+
3+
public class TipsNotifier
4+
{
5+
// Short, actionable hints shown once after a run. Kept in sync with the defaults in
6+
// obfuscation.json (NoInlining/ObfuscationAttribute excludes are enabled by default).
7+
private static readonly string[] Tips =
8+
{
9+
"Mark a method with [MethodImpl(MethodImplOptions.NoInlining)] to exclude it from obfuscation.",
10+
"Mark a type or member with [Obfuscation(Feature = \"ProtectionName\", Exclude = true)] to skip a single protection for it.",
11+
"Set \"Watermark\": false in obfuscation.json (or pass --no-watermark) to disable the BitMono watermark.",
12+
"Drop your dependencies into the 'libs' directory (or pass -l/--libraries) so references resolve and obfuscation goes deeper.",
13+
"Choose how aggressive obfuscation is with --preset Minimal|Balanced|Maximum (or set \"Preset\" in obfuscation.json).",
14+
"See all protections and which runtimes they support: https://bitmono.readthedocs.io",
15+
};
16+
17+
private readonly ObfuscationSettings _obfuscationSettings;
18+
private readonly ILogger _logger;
19+
20+
public TipsNotifier(ObfuscationSettings obfuscationSettings, ILogger logger)
21+
{
22+
_obfuscationSettings = obfuscationSettings;
23+
_logger = logger.ForContext<TipsNotifier>();
24+
}
25+
26+
public void Notify()
27+
{
28+
if (_obfuscationSettings.Tips == false)
29+
{
30+
return;
31+
}
32+
foreach (var tip in Tips)
33+
{
34+
_logger.Information("[Tip]: {0}", tip);
35+
}
36+
}
37+
}

src/BitMono.Shared/Models/ObfuscationSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class ObfuscationSettings
88
public string ReferencesDirectoryName { get; set; }
99
public string OutputDirectoryName { get; set; }
1010
public bool NotifyProtections { get; set; }
11+
public bool Tips { get; set; } = true;
1112
public bool NoInliningMethodObfuscationExclude { get; set; }
1213
public bool SerializableBitObfuscationExclude { get; set; }
1314
public bool ObfuscationAttributeObfuscationExclude { get; set; }

0 commit comments

Comments
 (0)