Skip to content

Implement Improved MaxStackCalculator#572

Open
PhilippNaused wants to merge 1 commit into0xd4d:masterfrom
PhilippNaused:betterMaxStackCalculator
Open

Implement Improved MaxStackCalculator#572
PhilippNaused wants to merge 1 commit into0xd4d:masterfrom
PhilippNaused:betterMaxStackCalculator

Conversation

@PhilippNaused
Copy link

@PhilippNaused PhilippNaused commented Feb 13, 2026

I have refactored the MaxStackCalculator to be faster and not fail on obfuscated code.
The new implementation traverses the instructions the same way an IL interpreter would, using multiple recursion on branch instructions.
Here is the original: https://github.com/PhilippNaused/Vilens/blob/main/src%2FVilens%2FHelpers%2FStackHelper.cs

I tested this on multiple different libraries both before and after code obfuscation.
The old implementation would often fail on obfuscated code. This one doesn't.

The new version is also faster and uses less memory:

Method Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
old 5.243 μs 0.1259 μs 0.1884 μs 1.00 0.05 1.2894 0.0687 21.79 KB 1.00
new 3.460 μs 0.0594 μs 0.0889 μs 0.66 0.03 0.0725 - 1.23 KB 0.06

@PhilippNaused PhilippNaused force-pushed the betterMaxStackCalculator branch from dde0933 to c1386e0 Compare February 13, 2026 08:10
@PhilippNaused PhilippNaused marked this pull request as ready for review February 13, 2026 08:10
@PhilippNaused PhilippNaused force-pushed the betterMaxStackCalculator branch from c1386e0 to 8b1250d Compare February 15, 2026 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant