Esempio n. 1
0
        /// <summary>
        /// Checks file on VirusTotal
        /// </summary>
        /// <param name="file">String containing file location</param>
        /// <param name="apikey">API key to use for request</param>
        public async void CheckFile(string file, string apikey)
        {
            this.Invoke(new Action(() => label1.Text = lang.GetString("Checking..."))); // Set label text in main thread

            var client  = new RestClient("https://www.virustotal.com");                 // Initialize RestClient
            var request = new RestRequest("vtapi/v2/file/report", Method.POST);         // Initialize RestRequest

            request.AddParameter("apikey", apikey);                                     // Add apikey parameter with API key
            request.AddParameter("resource", GetMD5(file));                             // Add resource paramater with file MD5 checksum

            // Execute request
            var asyncHandle = client.ExecuteAsync(request, response => {
                var content  = response.Content;                       // Get content of response
                dynamic json = JsonConvert.DeserializeObject(content); // Deserialize JSON response

                try
                {
                    // Shitty solution to check, but why not?
                    // If it fails code will not continue
                    // TODO: Actually elegant solution
                    Console.WriteLine(json.permalink.ToString());                                                                                                                                                                                                                                                                                               // Try to echo file permaling, if it does not exist, throw exception and upload file

                    DialogResult dialogResult = MessageBox.Show(lang.GetString("This file was already scanned on ") + json.scan_date + "\n\n" + lang.GetString("Do you want to view results of scan or rescan file? (\"Yes\" to view, \"No\" to rescan)"), lang.GetString("File is already in database"), MessageBoxButtons.YesNo, MessageBoxIcon.Information); // Show dialog with information about previous scan
                    if (dialogResult == DialogResult.Yes)                                                                                                                                                                                                                                                                                                       // Check dialog result
                    {
                        Process.Start(json.permalink.ToString());                                                                                                                                                                                                                                                                                               // Open browser with file link
                        ResetLabel();                                                                                                                                                                                                                                                                                                                           // Set label text back
                    }
                    else if (dialogResult == DialogResult.No)
                    {
                        UploadFile(file, apikey); // Upload file for re-scan
                    }
                }
                catch (Exception error)
                {
                    try
                    {
                        // File was probably not found in database or error so we will try to upload it
                        UploadFile(file, apikey);
                    }
                    catch (Exception err)
                    {
                        //MessageBox.Show("Error sending request!\nOE: " + err.ToString() + "\n\n" + error.ToString(), lang.GetString("Fatal Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); // Show error messagebox
                        errw.Error = "Error sending request!\n\nOE: " + err.ToString();
                        this.Invoke(new Action(() => errw.Show()));
                        ResetLabel(); // Set label text back
                    }
                }
            });
        }
Esempio n. 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            lang = new Languages();                                                                                                                                                                                                                     // Initialize language class
            lang.Init();                                                                                                                                                                                                                                // Run init function

            errw = new ErrorWindow();                                                                                                                                                                                                                   // Initialize ErrorWindow

            label1.Text     = lang.GetString("Drag file here");                                                                                                                                                                                         // Set label text
            linkLabel3.Text = lang.GetString("Settings");                                                                                                                                                                                               // Set settings link text

            if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "Settings.ini"))                                                                                                                                                                   // Check if settings file exists
            {
                MessageBox.Show(lang.GetString("No settings file found!\n\nThis is because you probably opened this app for first time. Please go to settings and add API key."), lang.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); // Show error dialog
            }
            else
            {
                var     parser = new FileIniDataParser();                                                 // Initialize ini file parser
                IniData data   = parser.ReadFile(AppDomain.CurrentDomain.BaseDirectory + "Settings.ini"); // Load settings file
                api       = data["General"]["ApiKey"];                                                    // Get apikey
                theme     = data["General"]["Theme"];                                                     // Get theme
                autoclose = bool.Parse(data["General"]["AutoClose"]);                                     //Get autoclose
            }

            if (theme == "dark")                                        // Check theme
            {
                this.BackColor   = ColorTranslator.FromHtml("#0a0a0a"); // Set back color
                this.ForeColor   = Color.WhiteSmoke;                    // Set fore color
                panel2.BackColor = ColorTranslator.FromHtml("#383838"); // Set panel back color to beautiful grey
                // Set link color
                linkLabel1.LinkColor = ColorTranslator.FromHtml("#b2b2b2");
                linkLabel2.LinkColor = ColorTranslator.FromHtml("#b2b2b2");
                linkLabel3.LinkColor = ColorTranslator.FromHtml("#b2b2b2");
            }

            string[] args = Environment.GetCommandLineArgs(); // Get program arguments

            if (args.Length > 1)
            {
                bool closeWhenDone = false;

                if (autoclose && args.Length > 2)
                {
                    closeWhenDone = args[2].Equals("shell");
                }

                try
                {
                    CheckFile(args[1], api, closeWhenDone); // Upload file
                }
                catch (Exception err)
                {
                    //MessageBox.Show("Error sending request!\nOE: " + err.ToString() + "\n\n" + error.ToString(), lang.GetString("Fatal Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); // Show error messagebox
                    errw.Error = "Error sending request!\n\nOE: " + err.ToString();
                    this.Invoke(new Action(() => errw.Show()));
                    ResetLabel(); // Set label text back
                }
            }
        }
Esempio n. 3
0
        private void Form1_DragDrop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); // Get all files dropped into form

            try
            {
                foreach (string file in files)
                {
                    CheckFile(file, api, false);                            // Check all files each
                }
            }
            catch (Exception err)
            {
                //MessageBox.Show("Error sending request!\nOE: " + err.ToString() + "\n\n" + error.ToString(), lang.GetString("Fatal Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); // Show error messagebox
                errw.Error = "Error sending request!\n\nOE: " + err.ToString();
                this.Invoke(new Action(() => errw.Show()));
                ResetLabel(); // Set label text back
            }
        }