badamczewski / PowerUp

⚡ Decompilation Tools and High Productivity Utilities ⚡
GNU Affero General Public License v3.0
1.64k stars 54 forks source link

System.IndexOutOfRangeException at PowerUp.Watcher.ILWriter.ToILString:100 #11

Closed xzxzxc closed 2 years ago

xzxzxc commented 2 years ago

When I try to process the next code void a(){} with command line arguments -cs input.cs output.asm output.il I have the next error in the output.il file

System.IndexOutOfRangeException: Index was outside the bounds of the array. at PowerUp.Watcher.ILWriter.ToILString(DecompilationUnit unit) in E:\tools\PowerUp-main\src\PowerUp.Watcher\ILWriter.cs:line 100 at PowerUp.Watcher.CSharpWatcher.ToILString(DecompilationUnit unit) in E:\tools\PowerUp-main\src\PowerUp.Watcher\CSharpWatcher.cs:line 319 at PowerUp.Watcher.CSharpWatcher.TryWriteIL(DecompilationUnit unit, String& result) in E:\tools\PowerUp-main\src\PowerUp.Watcher\CSharpWatcher.cs:line 269

I managed to fix it by changing the line ILWriter.cs#L20 to the next one

var lines = unit.InputSouceCode.Replace("\r", string.Empty).Split('\n');

And I got the next result in the output.il


.class public auto ansi beforefieldinit CompilerGen
extends [System.Private.CoreLib]System.Object
{
    .method private hidebysig 
    instance void a () cil managed     
    {
        .maxstack 8

        // void a(){}
        IL_0000: ret         
    }     

    .method public hidebysig specialname rtspecialname 
    instance void .ctor () cil managed     
    {
        .maxstack 8

        IL_0000: ldarg.0     
        IL_0001: call         instance void [System.Private.CoreLib]System.Object::.ctor()
        IL_0006: ret         
    }     

} 

Please, confirm that my change is okay and I'll create a PR. Or if I did something wrong, please let me know.

I use version from 16afbe9e05b7972cffa611ab2f5c267d624211cc commit with net 5 and Windows.

badamczewski commented 2 years ago

This fix seems to be working; please submit a PR with the fix and add your user to the CLA here (by updating the file :))

https://github.com/badamczewski/PowerUp/blob/main/CLA.md