0

Question: I'd like to know if I would need to ask for specific permissions and/or do something extra to make it "trustworthy" in case my program copies a dll file multiple times to the temp directory. If I do this, would the program be picked up as malicious software by anti-viruses?

Sample Code:

if (needANewCopyOfTheDll)
{
    string fileName = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".dll";
    // Here, copy my dll to the new file.
}

But why? I have a static library written in C++, and it has global variables, initialization procedures, and so many other stuff. I'd like to have different instances of that library and I can only load the same dll once in the memory. Thus I was thinking of wrapping the library in an instance class, and when I needed a new instance of it just copy the dll file to the temp directory and get a new handle for it using LoadLibrary() function in kernel32.dll

hattenn
  • 4,371
  • 9
  • 41
  • 80
  • This is the solution to the wrong question. The question should be "How can I have multiple instances of things in my library", to which the answer would be "use OOP". What you are doing is writing a terrible, terrible hack, when you should be re-factoring your code. – SecurityMatt Feb 17 '13 at 01:14
  • If you cannot re-write the static library then what you are attemting is probably the only solution. Writing to temp dir is fine. – David Heffernan Feb 17 '13 at 08:29
  • @SecurityMatt The library is written by someone else, I'm aware of how terrible it is. I just need to live with it, as we all do sometimes. – hattenn Feb 17 '13 at 10:01

1 Answers1

1

Copying to the temporary directory does not require any special permissions. You can just do it, it should be no problem. Lots of programs do that.

It's not clear from your question whether your software is picked up as malicious or not. If it is, I suspect it is because you're loading a dll from the temporary directory.

What you do sounds like a pretty big hack anyway. You should rather rewrite your library to not use global variables.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Unfortunately I'm not the coder of the library, and I have to somehow live with it. And thanks for the answer. – hattenn Feb 16 '13 at 22:33