Unhandled IO error in a bootstrapper WPF(C#) .cs

-3

New errorenter image description hereOkay so I get an error and I don't know how to fix it, any help will be gladly welcome. it's in WPF 2019 visual studio. It's a .cs program [program.cs]

   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
   at System.Uri..ctor(String uriString)
   at Bootstrapper.Program.Main(String[] args) in C:\Users\raduf\Desktop\Exploit Template\Bootstrapper\Program.cs:line 40


System.UriFormatException: 'Invalid URI: The format of the URI could not be determined.' System.UriFormatException HResult=0x80131537 Message=Invalid URI: The format of the URI could not be determined. This exception was originally thrown at this call stack: [External Code] Bootstrapper.Program.Main(string[]) in Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Net;
using System.Diagnostics;

namespace Bootstrapper
{
    class Program
    {
        static String[] files = new string[]
        {
            "https://emaciated-blower.000webhostapp.com/Sploit/MeguSploit/",
        };

        static void Main(string[] args)
        {
            if (!Directory.Exists(Environment.CurrentDirectory + "/Exploit"))
            {
                Directory.CreateDirectory(Environment.CurrentDirectory + "/Exploit");
            }
            Console.Title = "MeguSploit Bootstrapper";
            Console.WriteLine("Updating....");

            foreach (Process process in Process.GetProcessesByName("MeguSploit"))
            {
                process.Kill();
            }

            foreach (string file in files)
            {
                string name = file.Substring(file.LastIndexOf("/") + 1);
                try
                {
                    new WebClient().DownloadFile(new Uri(file), Environment.CurrentDirectory + "/Exploit/" + name);
                }
                catch (IOException ex)  //HERE
                {

                }
            }
            Console.WriteLine("Updated...");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Please go to exploit folder and run the program. Make sure to always ru the bootstrapper to check for updates.");
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Press any key to close...");
            Console.ReadKey();
            Environment.Exit(0);
            Console.Read();



        }
    }
}

Sorry for my bad code I am new into this world. I am trying to get it working for some hours but I can't. Thanks, again.

c#
.net
wpf
visual-studio
asked on Stack Overflow May 15, 2020 by Skeleton Cards • edited May 15, 2020 by Skeleton Cards

1 Answer

0

I believe your problem is in this line

 string name = file.Substring(file.LastIndexOf("/") + 1);

According to your definition of the files array, this would give you an empty string for the name.

    static String[] files = new string[]
    {
        "https://emaciated-blower.000webhostapp.com/Sploit/MeguSploit/",
    };

file.LastIndexOf("/") would be grabbing the / after MeguSploit.

Also unless you have a need for the Uri, you should just use the string overload for the WebClient().DownloadFile() method. (Like Below)

new WebClient().DownloadFile(file, Environment.CurrentDirectory + "/Exploit/" + name);

To download multiple files you would need to define each file that is being downloaded like below.

static String[] files = new string[]
{
    "https://emaciated-blower.000webhostapp.com/Sploit/MeguSploit/test.exe",
    "https://emaciated-blower.000webhostapp.com/Sploit/MeguSploit/test.dll",
    // etc...
};
answered on Stack Overflow May 15, 2020 by Patrick Mcvay • edited May 15, 2020 by Patrick Mcvay

User contributions licensed under CC BY-SA 3.0