Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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)
C#
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);
             

            
        }

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);
}
}
}
Posted
Updated 8-Mar-16 4:39am
v2

1 solution

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:
C#
EmbeddedAssembly.Load(resource1, "MyApplication.SomeNamespace.Aimware.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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900