Apr 25, 2016 01:08 PM
(This post was last modified: Apr 25, 2016 01:12 PM by KrypteX.)
Hello everyone, I've been trying to work on a few test projects of mine and I'm coming across a bit of an impass.
I'm trying to invoke a DLL/Resource that is embedded into my application, however I keep getting an error saying that the resource that I've embedded cannot be found.
Here's the entire code that I'm using for this project.
If anyone can help me figure out where I'm going wrong it'd be much appreciated.
Also, I'm trying to give credit for where credit is due, not all of this is written by me, so if you see something that doesn't have credits please leave a comment or PM me and I'll put them in.
Shout out to Pr0sus as well, I'm using examples from his crypter source to call the function. I think what could be wrong is the way that the resource is being built here:
And on this line:
I'm trying to invoke a DLL/Resource that is embedded into my application, however I keep getting an error saying that the resource that I've embedded cannot be found.
Here's the entire code that I'm using for this project.
PHP Code
<?php
Imports System.CodeDom
Imports System.Reflection
Imports System.Reflection.Emit
Imports System.Runtime.CompilerServices
Imports System.Text
Imports Microsoft.VisualBasic.CompilerServices
Public Class Form1
Dim isencrypted As Boolean
Dim key As String = "ThisKey"
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Invoke(retrieveFile("tmp", "superhiddenstuffs"), "test.test", "eText", New Object() {TextBox1.Text, key})
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim Library = My.Resources.test
Dim libpath As String = Application.StartupPath & "\" & "tmp.dll"
Dim respath As String = Application.StartupPath & "\" & "tmp.resources"
Dim libname As String = "superhiddenstuffs"
'Clipboard.SetText(mydll)
compile_Core(Library, libpath, Nothing, True)
Using r As New Resources.ResourceWriter(respath)
r.AddResource(libname, Encoding.Default.GetString(IO.File.ReadAllBytes(libpath)))
r.Generate()
End Using
End Sub
Public Shared Function Invoke(ByVal input() As Byte, ByVal cls As String, ByVal procname As String, ByVal args() As Object) As Object
Dim handler As New DynamicMethod("", GetType(Object), New [Type]() {GetType(Byte()), GetType(String), GetType(String), GetType(Object())})
Dim IL As ILGenerator = handler.GetILGenerator
Dim argsLoad() As Type = New [Type]() {GetType(Byte())}
Dim mthLoad As MethodInfo = GetType(Assembly).GetMethod("Load", argsLoad)
Dim argsGTYPE() As Type = New [Type]() {GetType(String)}
Dim mthGTYPE As MethodInfo = GetType(Assembly).GetMethod("GetType", argsGTYPE)
Dim argsActi() As Type = New [Type]() {GetType(Type)}
Dim mthActi As MethodInfo = GetType(Activator).GetMethod("CreateInstance", argsActi)
Dim argsGetVal() As Type = New [Type]() {GetType(Object)}
Dim mthGetVal As MethodInfo = GetType(RuntimeHelpers).GetMethod("GetObjectValue", argsGetVal)
Dim mthCallByName As MethodInfo = GetType(Versioned).GetMethod("CallByName")
IL.Emit(OpCodes.Ldarg_0)
IL.Emit(OpCodes.Call, mthLoad)
IL.Emit(OpCodes.Ldarg_1)
IL.EmitCall(OpCodes.Callvirt, mthGTYPE, Nothing)
IL.Emit(OpCodes.Call, mthActi)
IL.Emit(OpCodes.Call, mthGetVal)
IL.Emit(OpCodes.Ldarg_2)
IL.Emit(OpCodes.Ldc_I4_1)
IL.Emit(OpCodes.Ldarg_3)
IL.Emit(OpCodes.Call, mthCallByName)
IL.Emit(OpCodes.Ret)
Try
Return CallByName(handler, "Invoke", CallType.Method, New Object() {handler, New Object() {input, cls, procname, args}})
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
Public Shared Function retrieveFile(ByVal resName As String, ByVal libname As String) As Byte()
Dim res_Man As New Resources.ResourceManager(resName, Reflection.Assembly.GetEntryAssembly)
Try
Return (Encoding.Default.GetBytes(res_Man.GetObject(resName)))
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
Public Shared Function compile_Core(ByVal input As String, ByVal output As String, ByVal resources As String, ByVal showError As Boolean) As Boolean
Dim provider_Args As New Dictionary(Of String, String)()
provider_Args.Add("CompilerVersion", "v2.0")
Dim provider As New Microsoft.VisualBasic.VBCodeProvider(provider_Args)
Dim c_Param As New Compiler.CompilerParameters
Dim c_Args As String = " /target:library /platform:x86 /optimize /define:_MYTYPE=\""""Empty\"""""
c_Param.GenerateExecutable = True
c_Param.OutputAssembly = output
c_Param.CompilerOptions = c_Args
c_Param.IncludeDebugInformation = False
If resources IsNot Nothing Then
c_Param.EmbeddedResources.Add(resources)
End If
c_Param.ReferencedAssemblies.AddRange({"System.Dll", "System.Windows.Forms.Dll"})
Dim comp_Result As Compiler.CompilerResults = provider.CompileAssemblyFromSource(c_Param, input)
If comp_Result.Errors.Count = 0 Then
Return True
Else
If showError Then
For Each _Error As Compiler.CompilerError In comp_Result.Errors
MessageBox.Show(_Error.ToString)
Next
Return False
End If
Return False
End If
End Function
End Class
If anyone can help me figure out where I'm going wrong it'd be much appreciated.
Also, I'm trying to give credit for where credit is due, not all of this is written by me, so if you see something that doesn't have credits please leave a comment or PM me and I'll put them in.
Shout out to Pr0sus as well, I'm using examples from his crypter source to call the function. I think what could be wrong is the way that the resource is being built here:
PHP Code
<?php
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim Library = My.Resources.test
Dim libpath As String = Application.StartupPath & "\" & "tmp.dll"
Dim respath As String = Application.StartupPath & "\" & "tmp.resources"
Dim libname As String = "superhiddenstuffs"
'Clipboard.SetText(mydll)
compile_Core(Library, libpath, Nothing, True)
Using r As New Resources.ResourceWriter(respath)
r.AddResource(libname, Encoding.Default.GetString(IO.File.ReadAllBytes(libpath)))
r.Generate()
End Using
End Sub
PHP Code
<?php
compile_Core(Library, libpath, Nothing, True)


![[Image: 6xBycLk.gif]](https://i.imgur.com/6xBycLk.gif)

![[Image: PVoDiqS.png]](https://i.imgur.com/PVoDiqS.png)
![[Image: Syr3DlV.png]](https://i.imgur.com/Syr3DlV.png)