Decompiling VB.Net assembly produces code with invalid member variable names; names starting with $STATIC$

前端 未结 3 1759
隐瞒了意图╮
隐瞒了意图╮ 2020-12-21 06:02

I am doing work for a client who has lost the source code for one of their VB.Net WinForms applications. The assembly they have is not obfuscated at all. I am trying to reco

相关标签:
3条回答
  • 2020-12-21 06:38

    In short, what's valid in IL isn't necessarily the same as what's valid in the source language. It's fairly common to give compiler-generated (aka synthetic in some circles) members name which are invalid in the language, as it avoids any possible clashes. These are sometimes called unspeakable names as they can't be "spoken" in the source language. For example, the C# compiler usually includes <> in such names.

    As for resolving the issue - some decompilers will work out where such names have come from automatically, but you can usually simply change the name everywhere. You won't end up with the original source code, but if you look at what you do end up with, you may be able to then work out more easily what the original source did look like.

    Note that the compiler may generate more than just invalid names: in C#, for example, iterators blocks generate IL which in some cases can't be expressed directly in "normal" C# itself. This may not be a problem for you, but it's worth being aware of.

    0 讨论(0)
  • 2020-12-21 06:46

    Those are identifiers generated by the VB.NET compiler to implement the Static keyword. For example:

    Class Example
        Public Sub test()
            Static lookhere As Integer = 42
        End Sub
    End Class
    

    generates this IL:

    .field private specialname int32 $STATIC$test$2001$lookhere
    .field private specialname class [Microsoft.VisualBasic]Microsoft.VisualBasic.CompilerServices.StaticLocalInitFlag $STATIC$test$2001$lookhere$Init
    

    By using reserved letters in the field name, the compiler can be sure there will never be an accidental collision with another field. There's no direct equivalent to Static in the C# language. You can leave them as private fields in the class but you have to watch out for initialization. The purpose of the $Init flag and rather a lot of IL that ensures the variable is correctly initialized. You'll need to rename them by hand.

    0 讨论(0)
  • 2020-12-21 06:52

    Those aren't variables, they are fields (they have access modifiers).

    They will be compiler generated fields which will be generated in a number of different circumstances. The names are purposely invalid to avoid conflicts with "normal" fields.

    If you can provide a little more context someone clever can probably figure out what the source originally looked like for the compiler to emit those fields.

    0 讨论(0)
提交回复
热议问题