예제 #1
0
파일: ServerForm.cs 프로젝트: jpmac26/AODX
        private void OnReceive(IAsyncResult ar)
        {
            try
            {
                Socket receiveSocket = (Socket)ar.AsyncState;
                receiveSocket.EndReceive(ar);

                if (!isClosing & receiveSocket.Connected)
                {
                    //If the masterserver is requesting our info (description, user count, etc.)
                    if (byteData[0] == 101 | receiveSocket.RemoteEndPoint == masterSocket.RemoteEndPoint)
                    {
                        sendServerInfo(masterSocket);
                        masterSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), masterSocket);
                    }
                    else if (byteData[0] == 103)
                        receiveSocket.Close();
                    else if (byteData[0] == 8)
                        sendEvidence(receiveSocket);
                    else if (byteData[0] == 9)
                    {
                        EviData msg = new EviData(byteData);

                        Evidence evi = new Evidence();
                        evi.name = msg.strName;
                        evi.desc = msg.strDesc;
                        evi.note = msg.strNote;
                        evi.index = msg.index;

                        using (MemoryStream ms = new MemoryStream(msg.dataBytes))
                        {
                            evi.icon = Image.FromStream(ms, false, true);
                        }

                        bool found = false;
                        foreach (Evidence item in eviList)
                        {
                            if (item.index == evi.index)
                            {
                                found = true;
                                item.name = evi.name;
                                item.note = evi.note;
                                item.desc = evi.desc;
                                item.icon = evi.icon;
                                break;
                            }
                        }
                        if (found == false)
                        {
                            evi.index = eviList.Count;
                            eviList.Add(evi);
                        }

                        EviData dat = msg;
                        dat.cmdCommand = Command.Evidence;
                        byte[] msgToSend = dat.ToByte();

                        foreach (ClientInfo client in clientList)
                        {
                            client.socket.BeginSend(msgToSend, 0, msgToSend.Length, SocketFlags.None, new AsyncCallback(OnSend), client.socket);
                        }
                        byteData = new byte[1048576];

                        //System.Threading.Thread.Sleep(3000);
                        receiveSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), receiveSocket);
                    }
                    //else if (byteData[0] == 0 | byteData[0] == 1 | byteData[0] == 2 | byteData[0] == 3 | byteData[0] == 4 | byteData[0] == 5 | byteData[0] == 6 | byteData[0] == 7 | byteData[0] == 10 | byteData[0] == 11 | byteData[0] == 12)
                    else if (receiveSocket.RemoteEndPoint != masterSocket.RemoteEndPoint)
                        parseMessage(receiveSocket);
                    else
                    {
                        //TO DO: Look into this, something is definitely wrong when we receive 2 or 3 garbage messages from clients every time they present evidence!!!
                        appendTxtLogSafe("<<" + receiveSocket.RemoteEndPoint.ToString() + " send an invalid packet with the first byte: " + byteData[0] + ">>\r\n");
                        receiveSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), receiveSocket);
                    }
                }
            }
            catch (SocketException)
            { }
            catch (ObjectDisposedException)
            { }
            catch (Exception ex)
            {
                if (Program.debug & !isClosing)
                    MessageBox.Show(ex.Message + ".\r\n" + ((Socket)ar.AsyncState)?.RemoteEndPoint?.ToString() + "\r\n" + ex.StackTrace.ToString(), "AODXServer", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #2
0
파일: iniParser.cs 프로젝트: jpmac26/AODX
        //Currently not called because it would be time-consuming and use lots of data and I haven't implemented evidence yet, so it's pointless
        public static List<Evidence> GetEvidenceData()
        {
            List<Evidence> evidence = new List<Evidence>();
            string dirName = "base/cases/";
            if (Directory.Exists(dirName))
            {
                foreach (string dir in Directory.EnumerateDirectories(dirName))
                {
                    if (dir.Substring(11) == GetServerInfo().Split('|')[9])
                    {
                        foreach (string file in Directory.EnumerateFiles(dir))
                        {
                            using (var fs = new FileStream(file, FileMode.Open))
                            {
                                Evidence evi = new Evidence();
                                evi.filename = file.Split('.').First();
                                switch (file.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries).Last().Split('/').Last().Split('.').Last())
                                {
                                    case "gif":
                                    case "png":
                                    case "bmp":
                                        evi.icon = Image.FromFile(file);

                                        bool found = false;
                                        foreach (Evidence data in evidence)
                                        {
                                            if (data.filename == evi.filename)
                                            {
                                                data.icon = evi.icon;
                                                found = true;
                                                break;
                                            }
                                        }

                                        if (!found)
                                        {
                                            evi.index = evidence.Count;
                                            evidence.Add(evi);
                                        }

                                        break;

                                    case "ini":
                                        if (file.Split('\\').Last() == "case.ini")
                                            break;

                                        //load ini data into name and desc
                                        using (StreamReader r = new StreamReader(fs))
                                        {
                                            while (!r.EndOfStream)
                                            {
                                                string line = r.ReadLine();
                                                if (line.Split(new string[] { " = " }, StringSplitOptions.None)[0].StartsWith("name", StringComparison.OrdinalIgnoreCase))
                                                {
                                                    evi.name = line.Split(new string[] { " = " }, StringSplitOptions.None)[1];
                                                }
                                                else if (line.Split(new string[] { " = " }, StringSplitOptions.None)[0].StartsWith("desc", StringComparison.OrdinalIgnoreCase))
                                                {
                                                    evi.desc = line.Split(new string[] { " = " }, StringSplitOptions.None)[1];
                                                }
                                                else if (line.Split(new string[] { " = " }, StringSplitOptions.None)[0].StartsWith("note", StringComparison.OrdinalIgnoreCase))
                                                {
                                                    evi.note = line.Split(new string[] { " = " }, StringSplitOptions.None)[1];
                                                }
                                            }
                                        }

                                        bool found2 = false;
                                        foreach (Evidence data in evidence)
                                        {
                                            if (data.filename == evi.filename)
                                            {
                                                data.name = evi.name;
                                                data.desc = evi.desc;
                                                data.note = evi.note;
                                                found2 = true;
                                                break;
                                            }
                                        }

                                        if (!found2)
                                        {
                                            evi.index = evidence.Count;
                                            evidence.Add(evi);
                                        }

                                        break;
                                }
                            }
                        }

                        foreach (string dir2 in Directory.EnumerateDirectories(dir))
                        {
                            foreach (string file in Directory.EnumerateFiles(dir2))
                            {
                                using (var fs = new FileStream(file, FileMode.Open))
                                {
                                    Evidence evi = new Evidence();
                                    evi.filename = file.Split('.').First();
                                    switch (file.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries).Last().Split('/').Last().Split('.').Last())
                                    {
                                        case "gif":
                                        case "png":
                                        case "bmp":
                                            evi.icon = Image.FromStream(fs, false, true);

                                            evi.icon.Save("base/test3.gif");

                                            //if (System.Drawing.Imaging.ImageFormat.Gif.Equals(evi.icon.RawFormat))
                                                //MessageBox.Show("GIF");
                                            //else if (System.Drawing.Imaging.ImageFormat.Png.Equals(evi.icon.RawFormat))
                                                //MessageBox.Show("PNG");

                                            bool found = false;
                                            foreach (Evidence data in evidence)
                                            {
                                                if (data.icon != null)
                                                    data.icon.Save("base/test4.gif");
                                                if (data.filename == evi.filename)
                                                {
                                                    data.icon = evi.icon;
                                                    data.icon.Save("base/test4.gif");
                                                    found = true;
                                                    break;
                                                }
                                            }

                                            if (!found)
                                            {
                                                evi.index = evidence.Count;
                                                evidence.Add(evi);
                                            }

                                            evi = null;

                                            break;

                                        case "ini":
                                            //load ini data into name and desc
                                            using (StreamReader r = new StreamReader(fs))
                                            {
                                                while (!r.EndOfStream)
                                                {
                                                    string line = r.ReadLine();
                                                    if (line.Split(new string[] { " = " }, StringSplitOptions.None)[0].StartsWith("name", StringComparison.OrdinalIgnoreCase))
                                                    {
                                                        evi.name = line.Split(new string[] { " = " }, StringSplitOptions.None)[1];
                                                    }
                                                    else if (line.Split(new string[] { " = " }, StringSplitOptions.None)[0].StartsWith("desc", StringComparison.OrdinalIgnoreCase))
                                                    {
                                                        evi.desc = line.Split(new string[] { " = " }, StringSplitOptions.None)[1];
                                                    }
                                                    else if (line.Split(new string[] { " = " }, StringSplitOptions.None)[0].StartsWith("note", StringComparison.OrdinalIgnoreCase))
                                                    {
                                                        evi.note = line.Split(new string[] { " = " }, StringSplitOptions.None)[1];
                                                    }
                                                }
                                            }

                                            bool found2 = false;
                                            foreach (Evidence data in evidence)
                                            {
                                                if (data.icon != null)
                                                    data.icon.Save("base/test4.gif");
                                                if (data.filename == evi.filename)
                                                {
                                                    data.name = evi.name;
                                                    data.desc = evi.desc;
                                                    data.note = evi.note;
                                                    found2 = true;

                                                    data.icon.Save("base/test4.gif");
                                                    break;
                                                }
                                            }

                                            if (!found2)
                                            {
                                                evi.index = evidence.Count;
                                                evidence.Add(evi);
                                            }

                                            evi = null;
                                            break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return evidence;
        }