Summary:
It seems that when a callvirt is replaced by a calli, Unscrambler throws an exception related to AsmResolver not being able to save the file (apparently due to a stack imbalance).
How to reproduce:
Change a callvirt instruction to a calli one as in the following CIL code:
Note: There is no problem if it is a call which is replaced.
Thrown exception:
Unhandled Exception: System.AggregateException: Construction of the PE image failed with one or more errors. ---> AsmResolver.DotNet.Code.Cil.StackImbalanceException: Stack imbalance was detected at offset IL_0000 in method body of System.Void Test_Unscrambler.Program::Main(String[])
at AsmResolver.DotNet.Code.Cil.CilMethodBody.ComputeMaxStack()
at AsmResolver.DotNet.Code.Cil.CilMethodBodySerializer.SerializeMethodBody(MethodBodySerializationContext context, MethodDefinition method)
--- End of inner exception stack trace ---
at AsmResolver.DotNet.ModuleDefinition.ToPEImage(IPEImageBuilder imageBuilder)
at AsmResolver.DotNet.ModuleDefinition.Write(String filePath, IPEImageBuilder imageBuilder, IPEFileBuilder fileBuilder)
Summary: It seems that when a
callvirt
is replaced by acalli
, Unscrambler throws an exception related to AsmResolver not being able to save the file (apparently due to a stack imbalance).How to reproduce: Change a
callvirt
instruction to acalli
one as in the following CIL code:Original code:
Obfuscated code:
Note: There is no problem if it is a
call
which is replaced.Thrown exception:
Example file: Test_Calli_Unscrambler.zip