简体   繁体   English

将 Dll 嵌入并加载到项目中 - VB.NET / C#

[英]Embedd and Load Dll into Project - VB.NET / C#

I am currently programming an analyze program to check for trojans and malware.我目前正在编写一个分析程序来检查木马和恶意软件。 For this I also use Fiddler Core to intercept and analyze traffic of those trojans.为此,我还使用 Fiddler Core 来拦截和分析这些木马的流量。

Fiddler Core comes additionally with 3 dlls which need to be in the same start folder as the program itself. Fiddler Core 还附带 3 个 dll ,它们需要与程序本身位于同一启动文件夹中。 As I want my Startup folder to be Exe only without any additional dlls displayed I embedded these 3 dlls in my project as resource and load them in ApplicationEvents.由于我希望我的 Startup 文件夹仅是 Exe 而不显示任何其他 dll ,因此我将这 3 个 dll 作为资源嵌入到我的项目中,并将它们加载到 ApplicationEvents 中。

This way works with all DLLs except one, the CertMaker.dll.这种方式适用于除 CertMaker.dll 之外的所有 DLL。 It is responsible for creating the root certificate which is needed to intercept the requests.它负责创建拦截请求所需的根证书。

If I embed the CertMaker.dll it works up to the point that a root certificate is created, but then it does not intercept the requests.如果我嵌入 CertMaker.dll 它可以工作到创建根证书的地步,但它不会拦截请求。 I can't get any queries in. It only works if I write the CertMaker.dll from memory into the startup folder but as I wrote above I want the startup folder to be the exe only.我无法获得任何查询。只有当我将 memory 中的 CertMaker.dll 写入启动文件夹时,它才有效,但正如我在上面所写的,我希望启动文件夹仅是 exe。

Here is my code in case you need it:如果您需要,这是我的代码:

ApplicationEvents.vb:应用事件.vb:

Namespace My
Partial Friend Class MyApplication
    Private WithEvents Domain As AppDomain = AppDomain.CurrentDomain
    Private Function DomainCheck(sender As Object, e As System.ResolveEventArgs) As System.Reflection.Assembly Handles Domain.AssemblyResolve
        If e.Name.Contains("BCMakeCert") Then
            Return System.Reflection.Assembly.Load(My.Resources.Dll1)
        ElseIf e.Name.Contains("CertMaker") Then
            Return System.Reflection.Assembly.Load(My.Resources.Dll2)
        ElseIf e.Name.Contains("FiddlerCore4") Then
            Return System.Reflection.Assembly.Load(My.Resources.Dll3)
        Else
            Return Nothing
        End If
    End Function
End Class
End Namespace

It works only if I write the CertMaker.dll to the Startup Folder:仅当我将 CertMaker.dll 写入启动文件夹时,它才有效:

 Dim appPath As String = Application.StartupPath()
 File.WriteAllBytes(appPath & "/CertMaker.dll", My.Resources.Dll2)

Is there another way to include and load the dll in the project without the dll appearing in the same startup folder ?是否有另一种方法可以在项目中包含和加载 dll 而 dll 不会出现在同一个启动文件夹中 I would like to be able to send the program later as a file without the dlls being in the folder.我希望以后能够将程序作为文件发送,而文件夹中没有 dll。

Use AppDomain.Current.Load(assembly) method if the fiddler's assemblies are.Net based.如果提琴手的程序集是基于 .Net 的,请使用 AppDomain.Current.Load(assembly) 方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM