Sep 19, 2020 08:47 AM
(This post was last modified: Sep 19, 2020 11:24 AM by fisica638.)
Hi, I have a problem.
I am injecting code with my following method.
Method :
Class to Inject:
This works fine.
The problem I have is when the Class to Inject has declarations / Properties outside the methods. if it has any declarations outside the Sub InitializeTestingDebug (), Crahstea my generated app.
Example :
It also doesn't work correctly when I call some function from the method Sub InitializeTestingDebug ()
Example :
Someone help me fix this problem, please.
I am injecting code with my following method.
Method :
Code
Module Anti_Debug
Sub Execute2(ByVal GetAssembly As ModuleDef)
Dim typeModule = ModuleDefMD.Load(GetType(Testting).Module)
Dim cctor = GetAssembly.GlobalType.FindOrCreateStaticConstructor()
Dim typeDef = typeModule.ResolveTypeDef(MDToken.ToRID(GetType(Testting).MetadataToken))
Dim members = InjectHelper.Inject(typeDef, GetAssembly.GlobalType, GetAssembly)
Dim init = CType(members.Single(Function(method) method.Name = "InitializeTestingDebug"), MethodDef)
cctor.Body.Instructions.Insert(0, Instruction.Create(OpCodes.Call, init))
For Each MDDef In GetAssembly.GlobalType.Methods
If Not MDDef.Name = ".ctor" Then Continue For
GetAssembly.GlobalType.Remove(MDDef)
Exit For
Next
End Sub
End ModuleClass to Inject:
Code
Module Testting
Private Sub InitializeTestingDebug()
MsgBox("Test Fun.")
End Sub
End ModuleThis works fine.
The problem I have is when the Class to Inject has declarations / Properties outside the methods. if it has any declarations outside the Sub InitializeTestingDebug (), Crahstea my generated app.
Example :
Code
Module Testting
Private _LogResult As String = String.Empty
Public ReadOnly Property LogResult As String
Get
Return _LogResult
End Get
End Property
Private Sub InitializeTestingDebug()
MsgBox("Test Fun.")
End Sub
End ModuleIt also doesn't work correctly when I call some function from the method Sub InitializeTestingDebug ()
Example :
Code
Module Testting
Private Sub InitializeTestingDebug()
MsgBox(WelcomeMessage)
End Sub
Private Function WelcomeMessage() As String
Return "Test Fun."
End Function
End ModuleSomeone help me fix this problem, please.

