Skip to content

Commit c1d1f9e

Browse files
authored
Merge pull request #222 from sunnamed434/bump_asmresolver_version
Bump asmresolver version, and other fixes
2 parents cba414e + a6e37d5 commit c1d1f9e

File tree

4 files changed

+50
-32
lines changed

4 files changed

+50
-32
lines changed

props/SharedPackages.props

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<Project>
22

33
<ItemGroup>
4-
<PackageReference Include="AsmResolver" Version="6.0.0-beta.2" />
5-
<PackageReference Include="AsmResolver.DotNet" Version="6.0.0-beta.2" />
6-
<PackageReference Include="AsmResolver.PE" Version="6.0.0-beta.2" />
4+
<PackageReference Include="AsmResolver" Version="6.0.0-beta.3" />
5+
<PackageReference Include="AsmResolver.DotNet" Version="6.0.0-beta.3" />
6+
<PackageReference Include="AsmResolver.PE" Version="6.0.0-beta.3" />
77
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0" />
88
</ItemGroup>
99

src/BitMono.Protections/BitMethodDotnet.cs

+8-10
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,19 @@ public override Task ExecuteAsync()
2323
continue;
2424
}
2525

26-
var randomMethodBodyIndex = 0;
27-
if (body.Instructions.Count >= 3)
28-
{
29-
randomMethodBodyIndex = _randomNext(0, body.Instructions.Count);
30-
}
31-
26+
const int firstInstruction = 0;
3227
var instruction = GetRandomInstruction();
33-
var label = body.Instructions[randomMethodBodyIndex].CreateLabel();
34-
body.Instructions.Insert(randomMethodBodyIndex, new CilInstruction(CilOpCodes.Br_S));
35-
body.Instructions.Insert(randomMethodBodyIndex + 1, instruction);
36-
body.Instructions[randomMethodBodyIndex].Operand = label;
28+
var label = body.Instructions[firstInstruction].CreateLabel();
29+
body.Instructions.Insert(firstInstruction, new CilInstruction(CilOpCodes.Br_S));
30+
body.Instructions.Insert(firstInstruction + 1, instruction);
31+
body.Instructions[firstInstruction].Operand = label;
3732
}
3833
return Task.CompletedTask;
3934
}
4035

36+
/// <summary>
37+
/// Get the random instruction that breaks the decompiler method.
38+
/// </summary>
4139
private CilInstruction GetRandomInstruction()
4240
{
4341
var randomValue = _randomNext(0, 3);

src/BitMono.Protections/FullRenamer.cs

+35-15
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,59 @@ public FullRenamer(Renamer renamer, IServiceProvider serviceProvider) : base(ser
1010
_renamer = renamer;
1111
}
1212

13-
[SuppressMessage("ReSharper", "InvertIf")]
1413
public override Task ExecuteAsync()
1514
{
1615
foreach (var method in Context.Parameters.Members.OfType<MethodDefinition>())
1716
{
18-
if (method.DeclaringType?.IsModuleType == false && method is { IsConstructor: false, IsVirtual: false })
17+
if (method.DeclaringType?.IsModuleType == true)
1918
{
20-
_renamer.Rename(method);
21-
if (method.HasParameters())
19+
continue;
20+
}
21+
if (method.IsConstructor || method.IsVirtual)
22+
{
23+
continue;
24+
}
25+
if (method.IsCompilerGenerated())
26+
{
27+
continue;
28+
}
29+
_renamer.Rename(method);
30+
if (!method.HasParameters())
31+
{
32+
continue;
33+
}
34+
foreach (var parameter in method.Parameters)
35+
{
36+
if (parameter.Definition == null)
2237
{
23-
foreach (var parameter in method.Parameters)
24-
{
25-
if (parameter.Definition != null)
26-
{
27-
_renamer.Rename(parameter.Definition);
28-
}
29-
}
38+
continue;
3039
}
40+
_renamer.Rename(parameter.Definition);
3141
}
3242
}
3343
foreach (var type in Context.Parameters.Members.OfType<TypeDefinition>())
3444
{
35-
if (type.IsModuleType == false)
45+
if (type.IsModuleType)
46+
{
47+
continue;
48+
}
49+
if (type.IsCompilerGenerated())
3650
{
37-
_renamer.Rename(type);
51+
continue;
3852
}
53+
_renamer.Rename(type);
3954
}
4055
foreach (var field in Context.Parameters.Members.OfType<FieldDefinition>())
4156
{
42-
if (field.DeclaringType?.IsModuleType == false)
57+
if (field.DeclaringType?.IsModuleType == true)
58+
{
59+
continue;
60+
}
61+
if (field.IsCompilerGenerated())
4362
{
44-
_renamer.Rename(field);
63+
continue;
4564
}
65+
_renamer.Rename(field);
4666
}
4767
return Task.CompletedTask;
4868
}

src/BitMono.Protections/UnmanagedString.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ public override Task ExecuteAsync()
1313
{
1414
var moduleImporter = Context.ModuleImporter;
1515
var stringSbytePointerCtor =
16-
moduleImporter.ImportMethod(typeof(string).GetConstructor(new[] { typeof(sbyte*) })!);
16+
moduleImporter.ImportMethod(typeof(string).GetConstructor([typeof(sbyte*)])!);
1717
var stringCharPointerCtor =
18-
moduleImporter.ImportMethod(typeof(string).GetConstructor(new[] { typeof(char*) })!);
18+
moduleImporter.ImportMethod(typeof(string).GetConstructor([typeof(char*)])!);
1919
var stringSbytePointerWithLengthCtor =
20-
moduleImporter.ImportMethod(typeof(string).GetConstructor(new[] { typeof(sbyte*), typeof(int), typeof(int) })!);
20+
moduleImporter.ImportMethod(typeof(string).GetConstructor([typeof(sbyte*), typeof(int), typeof(int)])!);
2121
var stringCharPointerWithLengthCtor =
22-
moduleImporter.ImportMethod(typeof(string).GetConstructor(new[] { typeof(char*), typeof(int), typeof(int) })!);
22+
moduleImporter.ImportMethod(typeof(string).GetConstructor([typeof(char*), typeof(int), typeof(int)])!);
2323
var encodedStrings = new Dictionary<string, MethodDefinition>();
2424
foreach (var method in Context.Parameters.Members.OfType<MethodDefinition>())
2525
{

0 commit comments

Comments
 (0)