在代码中使用嵌入式资源dll [英] Use embedded resource dll in code

查看:86
本文介绍了在代码中使用嵌入式资源dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#2015社区版中有一个项目,我已经将dll作为嵌入式资源,我将其复制到磁盘中,然后到内存流后如何从内存中将其作为文件访问并从磁盘中删除它以便用户无法打开或移动它(在内存中而不是在磁盘上)

I have a Project in C# 2015 Community edition, I have enbedded a dll as an embedded resource, I copy it into disk and after to memory stream how can I Access it from memory as a file and delete it from disk so the user cannot open or move it (while in memory and not on disk)

private void button5_Click(object sender, EventArgs e)
        {
        
            CopyResource("injector.Aimware.dll", "Aimware4.dll");
            string path = "Aimware4.dll";
            //system.MemStream.Read()
            File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden);
            using (FileStream fileStream = File.OpenRead(path))
            {
                MemoryStream memStream = new MemoryStream();
                memStream.SetLength(fileStream.Length);
                fileStream.Read(memStream.GetBuffer(), 0, (int)fileStream.Length);
            }
            Process proc1 = Process.GetProcessesByName("csgo")[0];
              
                    HVInjector.inject(@"c:\Aimware4.dll", proc1);
             

            
        }



对不起记忆编码的新内容



我尝试过:



使用此功能从嵌入式资源到复制到磁盘

private void CopyResource(string resourceName,string file)

{

using(Stream resource = GetType()。Assembly.GetManifestResourceStream(resourceName))

{

if(resource == null)

{

抛出新的ArgumentException(没有这样的资源,resourceName);

}

使用(Stream output = File.OpenWrite(file))

{

resource.CopyTo(输出);

}

}

}


Sorry little NEW to memory coding

What I have tried:

Works from embedded resource to Copy to disk with this function
private void CopyResource(string resourceName, string file)
{
using (Stream resource = GetType().Assembly.GetManifestResourceStream(resourceName))
{
if (resource == null)
{
throw new ArgumentException("No such resource", "resourceName");
}
using (Stream output = File.OpenWrite(file))
{
resource.CopyTo(output);
}
}
}

推荐答案

1)如果你问错误的帮助,你我应该告诉确切的错误信息。我们无法读懂您的想法或看到您的屏幕,所以如果您不告诉我们,我们只能推测。



2)如果您寻求帮助您从CodeProject文章中获得的代码,您应该在文章的留言板上发布您的问题。然后作者将收到通知。你在这里的问题他很可能不会看到。而且他是最有可能帮助你的人。



3)我猜测你需要在那里指定嵌入式资源的命名空间。这样的事情:

1) If you ask for help with an error, you should tell the exact error message. We can't read your mind or see your screen, so if you don't tell us, we can only speculate.

2) If you ask for help with code you got from a CodeProject article, you should post your question on the message board of the article. The author will then get a notification. Your question here he will most likely not see. And he's the one who is most likely to be able to help you.

3) I'm speculating that you need to specify the namespace of the embedded resource there. Something like this:
EmbeddedAssembly.Load(resource1, "MyApplication.SomeNamespace.Aimware.dll";



就像文章的作者那样,你最有可能得到这段代码(参考文献从嵌入式资源加载DLL [ ^ ])。



如果这没有帮助,请在文章的留言板上发布您的问题,不要忘记告诉确切的错误信息。


Like the author of the article did, from where you most likely got this code (ref. Load DLL From Embedded Resource[^]).

If this doesn't help please post your question on the message board of the article and don't forget to tell the exact error message.


这篇关于在代码中使用嵌入式资源dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆