Ejemplo n.º 1
0
        /// <summary>
        ///     Logs all transaction scripts formats, so that this way we can identify
        ///     the different ways data might be encoded on the blockchain.
        /// </summary>
        private static void LogScriptPatterns(string[] files, string output_pattern_file = @"e:\patterns.txt")
        {
            var    sb           = new StringBuilder();
            var    patterns     = new Dictionary <string, ScriptPattern>();
            string current_file = null;

            try {
                int block_height = 0;
                foreach (var file in files)
                {
                    current_file = file;
                    foreach (var block in Block.ParseAll(file))
                    {
                        block.Height = block_height++;
                        Console.WriteLine(string.Format("processing block #{0}", block.Height));
                        foreach (var transaction in block.Transactions)
                        {
                            foreach (var txout in transaction.Outs)
                            {
                                var text_script = txout.Script.ToString();

                                var           pattern = Helper.DetectScriptPattern(text_script);
                                ScriptPattern temp;
                                if (!patterns.TryGetValue(pattern, out temp))
                                {
                                    temp = new ScriptPattern()
                                    {
                                        Pattern = pattern,
                                        Example = text_script,
                                        TxId    = transaction.TransactionHash.ToString(),
                                    };
                                    patterns.Add(pattern, temp);
                                }
                                temp.Count++;
                            }
                        }
                    }
                    File.WriteAllText(output_pattern_file, string.Join(Environment.NewLine, patterns.Select(o => o.Value)));
                }
            } catch (Exception ex) {
                throw new FormatException($"An error occured reading the file {current_file}. File might be corrupted or contain extra data. This also occurs when reading block files from old version of bitcoin core.", ex);
            }
        }
Ejemplo n.º 2
0
        //////////////////////////////////////////////////////////////////////////
        private bool IsWellKnownPattern(StringItem Item)
        {
            string ScriptLine = GetFileLine(Item.Filename, Item.Line);

            ScriptLine = ScriptLine.ToUpper();
            ScriptLine = ScriptLine.Replace(" ", "");
            ScriptLine = ScriptLine.Replace("\t", "");

            foreach (string ScriptPattern in ScriptPatterns)
            {
                string Pattern = ScriptPattern.Replace("%string%", Item.OriginalString);
                Pattern = Pattern.ToUpper();

                if (ScriptLine.IndexOf(Pattern) >= 0)
                {
                    return(true);
                }
            }
            return(false);
        }