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

前端 未结 3 1795
隐瞒了意图╮
隐瞒了意图╮ 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: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.

提交回复
热议问题