Skip to content

Commit fa5ad45

Browse files
author
KingKDot
committed
fix for Cosmali
1 parent 184acd8 commit fa5ad45

File tree

3 files changed

+57
-16
lines changed

3 files changed

+57
-16
lines changed

PowerCrypt/Obfuscator/Helpers/Globals/Globals.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ namespace PowerCrypt.Obfuscator.Helpers.globals
55
public static class Globals
66
{
77
public static string CompressFunctionName { get; set; } = string.Empty;
8+
9+
public static HashSet<string> FunctionNamesToSkip { get; set; } = new HashSet<string>
10+
{
11+
"CheckValidationResult"
12+
};
13+
814
public static List<string> UsedVariables { get; set; } = new List<string>();
915
public static List<string> UsedFunctions { get; set; } = new List<string>();
1016

@@ -24,4 +30,4 @@ public static void AddUsedFunction(string functionName)
2430
}
2531
}
2632
}
27-
}
33+
}

PowerCrypt/Obfuscator/Methods/FunctionObfuscation/FunctionOBF.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ public static string ObfuscateFunctionSimple(string ObfuscateFunction)
1818
Globals.CompressFunctionName = randomString;
1919
}
2020

21+
foreach (var function in Globals.FunctionNamesToSkip)
22+
{
23+
if (function == ObfuscateFunction)
24+
{
25+
Console.WriteLine("Function name is in the skip list, changing it to a random string");
26+
return ObfuscateFunction;
27+
}
28+
}
29+
2130
//add backticks to captial letters
2231
var modifiedString = new System.Text.StringBuilder();
2332
foreach (char c in randomString)

PowerCrypt/Obfuscator/Passes/FourthPass.cs

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using PowerCrypt.Obfuscator.Methods.GeneralControlFlowPostOBF;
55
using PowerCrypt.Settings;
66
using Spectre.Console;
7+
using System.Diagnostics;
78
using System.Management.Automation.Language;
89

910
namespace PowerCrypt.Obfuscator.Passes
@@ -20,23 +21,48 @@ private static List<ReplacementMapUniversal> CollectReplacements(ScriptBlockAst
2021
.Where(stmt => !stmt.FindAll(inner => (inner is IfStatementAst || inner is ForStatementAst || inner is ForEachStatementAst) && inner != stmt, searchNestedScriptBlocks: true).Any() &&
2122
!stmt.FindAll(inner => inner is ReturnStatementAst, searchNestedScriptBlocks: true).Any());
2223

23-
foreach (var node in nodes)
24+
foreach (var function in Globals.FunctionNamesToSkip)
2425
{
25-
if (isFunction && ((FunctionDefinitionAst)node).Name.Equals(Globals.CompressFunctionName))
26+
foreach (var node in nodes)
2627
{
27-
continue;
28-
}
28+
bool shouldSkip = false;
2929

30-
string obfuscatedText = WrapOBF.ObfuscateWithWrap(node.Extent.Text);
31-
allReplacements.Add(new ReplacementMapUniversal
32-
{
33-
StartOffset = node.Extent.StartOffset,
34-
Length = node.Extent.Text.Length,
35-
OriginalName = node.Extent.Text,
36-
Text = obfuscatedText,
37-
Type = node.GetType().Name,
38-
RequiresKeyword = false
39-
});
30+
if (isFunction && ((FunctionDefinitionAst)node).Name.Equals(Globals.CompressFunctionName))
31+
{
32+
continue;
33+
}
34+
35+
foreach (var function2 in Globals.FunctionNamesToSkip)
36+
{
37+
if (isFunction && ((FunctionDefinitionAst)node).Name.Equals(function2))
38+
{
39+
Console.WriteLine(((FunctionDefinitionAst)node).Name);
40+
shouldSkip = true;
41+
break;
42+
}
43+
}
44+
45+
if (shouldSkip)
46+
{
47+
continue;
48+
}
49+
50+
if (isFunction)
51+
{
52+
Console.WriteLine(((FunctionDefinitionAst)node).Name);
53+
}
54+
55+
string obfuscatedText = WrapOBF.ObfuscateWithWrap(node.Extent.Text);
56+
allReplacements.Add(new ReplacementMapUniversal
57+
{
58+
StartOffset = node.Extent.StartOffset,
59+
Length = node.Extent.Text.Length,
60+
OriginalName = node.Extent.Text,
61+
Text = obfuscatedText,
62+
Type = node.GetType().Name,
63+
RequiresKeyword = false
64+
});
65+
}
4066
}
4167

4268
return allReplacements;
@@ -84,4 +110,4 @@ public static string ProcessScript(string scriptContent)
84110
return scriptContent;
85111
}
86112
}
87-
}
113+
}

0 commit comments

Comments
 (0)