Exemplo n.º 1
0
        public string Initialize(string filePath, string[] dataLines, bool flipBytes, bool syncListViaNetcore)
        {
            byteList = new List <byte[]>();

            //For every line in the list, build up our list of bytes
            for (int i = 0; i < dataLines.Length; i++)
            {
                string t     = dataLines[i];
                byte[] bytes = null;
                try
                {
                    //Get the string as a byte array
                    if ((bytes = CorruptCore_Extensions.StringToByteArray(t)) == null)
                    {
                        throw new Exception($"Error reading list {Path.GetFileName(filePath)}. Valid format is a list of raw hexadecimal values.\nLine{(i + 1)}.\nValue: {t}\n");
                    }
                }
                catch (Exception e)
                {
                    var logger = NLog.LogManager.GetCurrentClassLogger();
                    logger.Error(e, "Error in loadListFromPath");
                    MessageBox.Show(e.Message);
                    return("");
                }

                //If it's big endian, flip it
                if (flipBytes)
                {
                    bytes.FlipBytes();
                }

                byteList.Add(bytes);
            }

            var name = Path.GetFileNameWithoutExtension(filePath);

            //var hash = Filtering.RegisterList(byteList, name, syncListViaNetcore);
            byteList = byteList.Distinct(new CorruptCore_Extensions.ByteArrayComparer()).ToList();

            hashSet = new HashSet <byte[]>(byteList, new CorruptCore_Extensions.ByteArrayComparer());
            string hash = Filtering.RegisterList(this, name, syncListViaNetcore);

            return(hash);
        }
Exemplo n.º 2
0
        private bool GenerateList()
        {
            if (tbListValues.Lines.Length == 0)
            {
                return(false);
            }
            List <String> newList = new List <string>();

            foreach (string line in tbListValues.Lines)
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                string trimmedLine = line.Trim();

                string[] lineParts = trimmedLine.Split('-');

                //We can't do a range on anything besides plain old numbers
                if (lineParts.Length > 1)
                {
                    //Hex
                    if (isHex(lineParts[0]) && isHex(lineParts[1]))
                    {
                        ulong start = safeStringToULongHex(lineParts[0]);
                        ulong end   = safeStringToULongHex(lineParts[1]);

                        for (ulong i = start; i < end; i++)
                        {
                            newList.Add(i.ToString("X"));
                        }
                    }
                    //Decimal
                    else if (isWholeNumber(lineParts[0]) && isWholeNumber(lineParts[1]))
                    {
                        ulong start = ulong.Parse(lineParts[0]);
                        ulong end   = ulong.Parse(lineParts[1]);

                        for (ulong i = start; i < end; i++)
                        {
                            newList.Add(i.ToString("X"));
                        }
                    }
                }
                else
                {
                    //If it's not a range we parse for both prefixes and suffixes then see the type
                    if (isHex(trimmedLine))                     //Hex with 0x prefix
                    {
                        newList.Add(lineParts[0].Substring(2));
                    }
                    else if (Regex.IsMatch(trimmedLine, "^[0-9]+[fF]$"))                     //123f float
                    {
                        float  f = Convert <float>(trimmedLine.Substring(0, trimmedLine.Length - 1));
                        byte[] t = BitConverter.GetBytes(f);
                        newList.Add(CorruptCore_Extensions.BytesToHexString(t));
                    }
                    else if (Regex.IsMatch(trimmedLine, "^[0-9]+[dD]$"))                     //123d double
                    {
                        double d = Convert <double>(trimmedLine.Substring(0, trimmedLine.Length - 1));
                        byte[] t = BitConverter.GetBytes(d);
                        newList.Add(CorruptCore_Extensions.BytesToHexString(t));
                    }
                    else if (isDecimalNumber(trimmedLine))                     //double no suffix
                    {
                        double d = Convert <double>(trimmedLine);
                        byte[] t = BitConverter.GetBytes(d);
                        newList.Add(CorruptCore_Extensions.BytesToHexString(t));
                    }
                    else if (isWholeNumber(trimmedLine))                     //plain old number
                    {
                        newList.Add(ulong.Parse(trimmedLine).ToString("X"));
                    }
                }
            }

            String filename = CorruptCore_Extensions.MakeSafeFilename(tbListName.Text, '-');

            //Handle saving the list to a file
            if (cbSaveFile.Checked)
            {
                if (!String.IsNullOrWhiteSpace(filename))
                {
                    File.WriteAllLines(Path.Combine(CorruptCore.RtcCore.RtcDir, "LISTS", filename + ".txt"), newList);
                }
                else
                {
                    MessageBox.Show("Filename is empty. Unable to save your list to a file");
                }
            }

            //If there's no name just generate one
            if (String.IsNullOrWhiteSpace(filename))
            {
                filename = CorruptCore.RtcCore.GetRandomKey();
            }

            //Register the list and update netcore
            List <Byte[]> byteList = new List <byte[]>();

            foreach (string t in newList)
            {
                byte[] bytes = CorruptCore_Extensions.StringToByteArray(t);
                byteList.Add(bytes);
            }
            string hash = Filtering.RegisterList(byteList, true);

            //Register the list in the ui
            CorruptCore.Filtering.RegisterListInUI(filename, hash);

            return(true);
        }