Esempio n. 1
0
        private static void PerformDump(DumpConfig dumpConfig)
        {
            EnsureDirectoryExists(dumpConfig.OutputDirectory);

            using (var connection = new SqlConnection(dumpConfig.ConnectionString))
            {
                connection.Open();

                var tablesToDump = TableNameGenerator.GetTablesToDump(connection, dumpConfig);

                var iFile = 1;
                var first = true;
                foreach (var table in tablesToDump)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        Console.WriteLine();
                    }

                    var fileNamePrefix = dumpConfig.FileNamePrefix + iFile.ToString("D3") + "_";

                    var filePath = dumpConfig.OutputDirectory + "/" + fileNamePrefix + table.Schema + "_" + table.Name + dumpConfig.FileNameSuffix + ".sql";
                    Console.WriteLine($"Creating file: {filePath}");

                    TableDumpScriptGenerator.DumpTable(connection, dumpConfig, table, filePath);
                    iFile++;
                }
            }
        }
Esempio n. 2
0
        public AudioListener(IRtspReceiver receiver, string sessionId, ushort cport, ushort dport, CodecLibrariesConfig clConfig, DumpConfig dConfig) : base(cport, dport)
        {
            _receiver  = receiver ?? throw new ArgumentNullException(nameof(receiver));
            _sessionId = sessionId ?? throw new ArgumentNullException(nameof(sessionId));
            _clConfig  = clConfig ?? throw new ArgumentNullException(nameof(clConfig));
            _dConfig   = dConfig ?? throw new ArgumentNullException(nameof(dConfig));

            _raopBuffer    = RaopBufferInit();
            _aesCbcDecrypt = CipherUtilities.GetCipher("AES/CBC/NoPadding");
        }
Esempio n. 3
0
        public AirTunesListener(IRtspReceiver receiver, ushort port, ushort airPlayPort, CodecLibrariesConfig codecConfig, DumpConfig dumpConfig) : base(port)
        {
            _airTunesPort = port;
            _airPlayPort  = airPlayPort;
            _receiver     = receiver ?? throw new ArgumentNullException(nameof(receiver));
            _codecConfig  = codecConfig ?? throw new ArgumentNullException(nameof(codecConfig));
            _dumpConfig   = dumpConfig ?? throw new ArgumentNullException(nameof(dumpConfig));

            // First time that we instantiate AirPlayListener we must create a ED25519 KeyPair
            // var seed = new byte[32];
            // RNGCryptoServiceProvider.Create().GetBytes(seed);
            var seed = Enumerable.Range(0, 32).Select(r => (byte)r).ToArray();

            Chaos.NaCl.Ed25519.KeyPairFromSeed(out byte[] publicKey, out byte[] expandedPrivateKey, seed);

            _publicKey          = publicKey;
            _expandedPrivateKey = expandedPrivateKey;
        }
Esempio n. 4
0
        public static void DumpTable(IDbConnection connection, DumpConfig dumpConfig, TableInfo table, string filePath)
        {
            var identityInsert = dumpConfig.IncludeIdentityInsert;
            var limit          = dumpConfig.Limit;

            var writer = new FileInfo(filePath).CreateText();

            writer.AutoFlush = true;

            var schemaAndTable = table.SchemaAndTableName;

            if (identityInsert && (table.IdentityColumn != null))
            {
                writer.WriteLine($"set identity_insert {schemaAndTable} on");
                writer.WriteLine();
            }
            using (var command = connection.CreateCommand())
            {
                var limitClause = "";

                if (limit.HasValue)
                {
                    limitClause = $"LIMIT {limit} ";
                }

                command.CommandText = $"SELECT {limitClause}* FROM {schemaAndTable} ";

                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        writer.WriteLine(SqlGenerator.GetInsertStatement(table, reader, identityInsert));
                    }
                }
            }
            if (identityInsert && (table.IdentityColumn != null))
            {
                writer.WriteLine();
                writer.WriteLine($"set identity_insert {schemaAndTable} off");
            }
            writer.Close();
        }
Esempio n. 5
0
        private void makeButton_Click(object sender, EventArgs e)
        {
            if (mainHexBox.ByteProvider == null)
            {
                return;
            }

            if (mainHexBox.ByteProvider.Length == 0)
            {
                return;
            }

            var          offsetSize = hexboxAddress - hexboxOffsetAddress;
            Queue <byte> image      = new Queue <byte>();

            for (var index = offsetSize; index < mainHexBox.ByteProvider.Length; index++)
            {
                image.Enqueue(mainHexBox.ByteProvider.ReadByte(index));
            }

            for (int index = dumpDataGridView.Columns.Count; index > 2; index--)
            {
                dumpDataGridView.Columns.RemoveAt((index - 1));
            }

            configList = new List <DumpConfig>();

            bool isFailed    = false;
            int  clusterSize = 0;

            foreach (DataGridViewRow item in dumpDataGridView.Rows)
            {
                if (item.Cells[(int)FixedColumns.Size].Value != null)
                {
                    var config = new DumpConfig();
                    if (!int.TryParse(item.Cells[(int)FixedColumns.Size].Value.ToString(), out config.Size))
                    {
                        isFailed = true;
                    }

                    if (!Enum.TryParse <UserType>(item.Cells[(int)FixedColumns.Type].Value.ToString(), out config.Type))
                    {
                        isFailed = true;
                    }

                    clusterSize += config.Size;

                    configList.Add(config);
                }
            }

            if (isFailed)
            {
                return;
            }

            if (configList.Count <= 0)
            {
                return;
            }

            var quotient  = image.Count / clusterSize;
            var remainder = image.Count - (clusterSize * quotient);

            if ((quotient == 0) ||
                (remainder != 0))
            {
                return;
            }
            else
            {
                var maxDataColumnSize = quotient;

                while (image.Count != 0)
                {
                    foreach (var config in configList)
                    {
                        List <byte> byteList = new List <byte>();

                        for (int i = 0; i < config.Size; i++)
                        {
                            byteList.Add(image.Dequeue());
                        }

                        if (tms320c28xEndianRadioButton.Checked)
                        {
                            byte tmp;
                            switch (config.Size)
                            {
                            case 1:
                                break;

                            case 2:
                                tmp         = byteList[0];
                                byteList[0] = byteList[1];
                                byteList[1] = tmp;

                                break;

                            case 4:
                                tmp         = byteList[0];
                                byteList[0] = byteList[1];
                                byteList[1] = tmp;

                                tmp         = byteList[2];
                                byteList[2] = byteList[3];
                                byteList[3] = tmp;

                                break;

                            case 8:
                                tmp         = byteList[0];
                                byteList[0] = byteList[1];
                                byteList[1] = tmp;

                                tmp         = byteList[2];
                                byteList[2] = byteList[3];
                                byteList[3] = tmp;

                                tmp         = byteList[4];
                                byteList[4] = byteList[5];
                                byteList[5] = tmp;

                                tmp         = byteList[6];
                                byteList[6] = byteList[7];
                                byteList[7] = tmp;

                                break;

                            default:
                                break;
                            }
                        }
                        else
                        {
                            if (bigEndianRadioButton.Checked)
                            {
                                byteList.Reverse();
                            }
                        }

                        ulong rowData = 0;
                        int   digit   = 0;
                        foreach (var tmp in byteList)
                        {
                            rowData += (ulong)(tmp * Math.Pow(2, (digit * 8)));
                            digit++;
                        }

                        string value;
                        UserString.TryParse(config.Type, config.Size, rowData, out value);
                        config.Values.Add(value);
                    }
                }

                if (maxDataColumnSize > 16)
                {
                    maxDataColumnSize = 16;
                }

                for (int index = 0; index < maxDataColumnSize; index++)
                {
                    DataGridViewTextBoxColumn textColumn = new DataGridViewTextBoxColumn();
                    textColumn.HeaderText = "data" + index.ToString();
                    dumpDataGridView.Columns.Add(textColumn);
                }

                int rowIndex = 0;
                foreach (DataGridViewRow item in dumpDataGridView.Rows)
                {
                    if (rowIndex >= configList.Count)
                    {
                        break;
                    }

                    for (int columnIndex = 0; columnIndex < maxDataColumnSize; columnIndex++)
                    {
                        item.Cells[columnIndex + (int)FixedColumns.DataStart].Value = configList[rowIndex].Values[columnIndex];
                    }

                    rowIndex++;
                }
            }
        }
        private static void Main(string[] args)
        {
            Console.WriteLine(DateTime.UtcNow.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'"));
            Console.WriteLine("Drag and drop your dump.cs file (or a partial of it of the correct format) then press enter...");
            string path = @"C:\Users\Sc2ad\Desktop\Code\Android Modding\BeatSaber\1.16.3\DummyDll-Inspector";

            //string path = @"C:\Users\Sc2ad\Desktop\Code\Android Modding\GorillaTag\DummyDll";
            if (!Directory.Exists(path))
            {
                path = Console.ReadLine().Replace("\"", string.Empty);
            }
            bool    parseDlls = false;
            IParser parser;

            if (Directory.Exists(path))
            {
                var parseConfig = new DllConfig()
                {
                };
                parser    = new DllParser(parseConfig);
                parseDlls = true;
            }
            else
            {
                var parseConfig = new DumpConfig()
                {
                };
                parser = new DumpParser(parseConfig);
            }

            Console.WriteLine("Parsing...");
            Stopwatch watch = new();

            watch.Start();
            IParsedData parsed;

            if (parseDlls)
            {
                parsed = parser.Parse(path);
            }
            else
            {
                using var stream = File.OpenRead(path);
                parsed           = parser.Parse(stream);
            }
            watch.Stop();
            //Console.WriteLine(parsed);
            Console.WriteLine($"Parsing took: {watch.Elapsed}!");
            Console.WriteLine("============================================");
            Console.WriteLine("Type the name of an output style (or don't for Normal) then press enter to serialize:");
            var input = "ThrowUnless";

            //var input = Console.ReadLine();
            // TODO: strip non-alphabetic characters out of input before parsing it
            if (Enum.TryParse(input, true, out OutputStyle style))
            {
                Console.WriteLine($"Parsed style '{style}'");
            }

            var libIl2cpp = @"C:\Program Files\Unity\Hub\Editor\2019.3.15f1\Editor\Data\il2cpp\libil2cpp";

            if (!Directory.Exists(libIl2cpp))
            {
                Console.WriteLine("Drag and drop your libil2cpp folder into this window then press enter:");
                libIl2cpp = Console.ReadLine();
            }

            Console.WriteLine("Creating serializer...");
            var config = new SerializationConfig
            {
                OneSourceFile  = true,
                ChunkFrequency = 100,
                // from https://en.cppreference.com/w/cpp/keyword
                IllegalNames = new HashSet <string> {
                    "alignas", "alignof", "and", "and_eq", "asm", "atomic_cancel", "atomic_commit", "atomic_noexcept", "auto",
                    "bitand", "bitor", "bool", "break", "case", "catch", "char", "char8_t", "char16_t", "char32_t", "class",
                    "compl", "concept", "const", "consteval", "constexpr", "constinit", "const_cast", "continue", "co_await",
                    "co_return", "co_yield", "decltype", "default", "delete", "do", "double", "dynamic_cast", "else", "enum",
                    "explicit", "export", "extern", "false", "float", "for", "friend", "goto", "if", "inline", "int", "long",
                    "mutable", "namespace", "new", "noexcept", "not", "not_eq", "nullptr", "operator", "or", "or_eq",
                    "private", "protected", "public", "reflexpr", "register", "reinterpret_cast", "requires", "return",
                    "short", "signed", "sizeof", "static", "static_assert", "static_cast", "struct", "switch", "synchronized",
                    "template", "this", "thread_local", "throw", "true", "try", "typedef", "typeid", "typename", "union",
                    "unsigned", "using", "virtual", "void", "volatile", "wchar_t", "while", "xor", "xor_eq", "INT_MAX", "INT_MIN",
                    "Assert", "bzero", "ID", "VERSION", "NULL"
                },
                IllegalMethodNames = new HashSet <string> {
                    "bzero", "Assert"
                },
                QualifiedBlacklistMethods = new HashSet <(string @namespace, string typeName, string methodName)>
                {
                    ("UnityEngine.ResourceManagement.AsyncOperations", "AsyncOperationHandle", "Convert")
                },
                OutputDirectory                 = Path.Combine(Environment.CurrentDirectory, "output"),
                OutputHeaderDirectory           = "include",
                OutputSourceDirectory           = "src",
                GenericHandling                 = GenericHandling.Do,
                OutputStyle                     = style,
                UnresolvedTypeExceptionHandling = new UnresolvedTypeExceptionHandlingWrapper
                {
                    FieldHandling  = UnresolvedTypeExceptionHandling.DisplayInFile,
                    MethodHandling = UnresolvedTypeExceptionHandling.DisplayInFile,
                    TypeHandling   = UnresolvedTypeExceptionHandling.DisplayInFile
                },
                PrintSerializationProgress          = true,
                PrintSerializationProgressFrequency = 1000,
                Id        = "codegen",
                Version   = "0.2.5",
                Libil2cpp = libIl2cpp,
            };

            if (config.OneSourceFile)
            {
                // If we have one source file, yeet our destination src
                if (Directory.Exists(Path.Combine(config.OutputDirectory, config.OutputSourceDirectory)))
                {
                    Directory.Delete(Path.Combine(config.OutputDirectory, config.OutputSourceDirectory), true);
                }
            }
            Utils.Init(config);

            var serializer = new CppDataSerializer(config, parsed);

            Console.WriteLine("Resolving types...");
            try
            {
                watch.Restart();
                // context unused
                serializer.PreSerialize(null, parsed);
                watch.Stop();
                Console.WriteLine($"Resolution Complete, took: {watch.Elapsed}!");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Console.WriteLine("Performing JSON dump...");
            watch.Restart();
            var jsonOutput = Path.Combine(Environment.CurrentDirectory, "json_output");

            Directory.CreateDirectory(jsonOutput);
            var outp = Path.Combine(jsonOutput, "parsed.json");

            if (File.Exists(outp))
            {
                File.Delete(outp);
            }
            var conf = new JsonSerializerOptions
            {
                WriteIndented = true,
                Encoder       = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
            };
            var strc = new SimpleTypeRefConverter(parsed.Types);

            conf.Converters.Add(strc);
            conf.Converters.Add(new TypeDataConverter(parsed, strc));
            conf.Converters.Add(new MethodConverter());
            conf.Converters.Add(new JsonStringEnumConverter());
            conf.Converters.Add(new FieldConverter());
            conf.Converters.Add(new SpecifierConverter());
            conf.Converters.Add(new PropertyConverter());
            using (var fs = File.OpenWrite(outp))
            {
                JsonSerializer.SerializeAsync(fs, parsed as DllData, conf).Wait();
            }
            watch.Stop();
            Console.WriteLine($"Json Dump took: {watch.Elapsed}!");
            Console.WriteLine("============================================");

            Console.WriteLine("Serializing...");
            try
            {
                watch.Restart();
                serializer.Serialize(null, parsed, true);
                watch.Stop();
                Console.WriteLine($"Serialization Complete, took: {watch.Elapsed}!");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine(string.Join(", ", SerializationConfig.SpecialMethodNames));
            Console.ReadLine();
        }
Esempio n. 7
0
 public DumpParser(DumpConfig config) => _config = config;
Esempio n. 8
0
 public AirPlayService(IAirPlayReceiver airPlayReceiver, IOptions <DumpConfig> dConfig)
 {
     _airPlayReceiver = airPlayReceiver ?? throw new ArgumentNullException(nameof(airPlayReceiver));
     _dConfig         = dConfig?.Value ?? throw new ArgumentNullException(nameof(dConfig));
 }
Esempio n. 9
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Drag and drop your dump.cs file (or a partial of it of the correct format) then press enter...");
            string path;

            if (Directory.Exists(@"C:\Users\Sc2ad\Desktop\Code\Android Modding\BeatSaber\1.8.0\DummyDll"))
            {
                path = @"C:\Users\Sc2ad\Desktop\Code\Android Modding\BeatSaber\1.8.0\DummyDll";
            }
            else
            {
                path = Console.ReadLine().Replace("\"", string.Empty);
            }
            bool    parseDlls = false;
            IParser parser;

            if (Directory.Exists(path))
            {
                var parseConfig = new DllConfig()
                {
                };
                parser    = new DllParser(parseConfig);
                parseDlls = true;
            }
            else
            {
                var parseConfig = new DumpConfig()
                {
                };
                parser = new DumpParser(parseConfig);
            }

            Console.WriteLine("Parsing...");
            Stopwatch watch = new Stopwatch();

            watch.Start();
            IParsedData parsed;

            if (parseDlls)
            {
                parsed = parser.Parse(path);
            }
            else
            {
                using var stream = File.OpenRead(path);
                parsed           = parser.Parse(stream);
            }
            watch.Stop();
            //Console.WriteLine(parsed);
            Console.WriteLine($"Parsing took: {watch.Elapsed}!");
            Console.WriteLine("============================================");
            Console.WriteLine("Type the name of an output style (or don't for Normal) then press enter to serialize:");
            var input = Console.ReadLine();

            // TODO: strip non-alphabetic characters out of input before parsing it
            if (Enum.TryParse(input, true, out OutputStyle style))
            {
                Console.WriteLine($"Parsed style '{style}'");
            }

            var libIl2cpp = "C:/Program Files/Unity/Editor/Data/il2cpp/libil2cpp";

            if (!Directory.Exists(libIl2cpp))
            {
                Console.WriteLine("Drag and drop your libil2cpp folder into this window then press enter:");
                libIl2cpp = Console.ReadLine();
            }

            Console.WriteLine("Creating serializer...");
            var config = new SerializationConfig
            {
                // from https://en.cppreference.com/w/cpp/keyword
                IllegalNames = new HashSet <string> {
                    "alignas", "alignof", "and", "and_eq", "asm", "atomic_cancel", "atomic_commit", "atomic_noexcept", "auto",
                    "bitand", "bitor", "bool", "break", "case", "catch", "char", "char8_t", "char16_t", "char32_t", "class",
                    "compl", "concept", "const", "consteval", "constexpr", "constinit", "const_cast", "continue", "co_await",
                    "co_return", "co_yield", "decltype", "default", "delete", "do", "double", "dynamic_cast", "else", "enum",
                    "explicit", "export", "extern", "false", "float", "for", "friend", "goto", "if", "inline", "int", "long",
                    "mutable", "namespace", "new", "noexcept", "not", "not_eq", "nullptr", "operator", "or", "or_eq",
                    "private", "protected", "public", "reflexpr", "register", "reinterpret_cast", "requires", "return",
                    "short", "signed", "sizeof", "static", "static_assert", "static_cast", "struct", "switch", "synchronized",
                    "template", "this", "thread_local", "throw", "true", "try", "typedef", "typeid", "typename", "union",
                    "unsigned", "using", "virtual", "void", "volatile", "wchar_t", "while", "xor", "xor_eq", "INT_MAX", "INT_MIN"
                },
                IllegalMethodNames = new HashSet <string> {
                    "bzero", "Assert"
                },
                OutputDirectory                 = Path.Combine(Environment.CurrentDirectory, "output"),
                OutputHeaderDirectory           = "include",
                OutputSourceDirectory           = "src",
                GenericHandling                 = GenericHandling.Do,
                OutputStyle                     = style,
                UnresolvedTypeExceptionHandling = new UnresolvedTypeExceptionHandlingWrapper
                {
                    FieldHandling  = UnresolvedTypeExceptionHandling.DisplayInFile,
                    MethodHandling = UnresolvedTypeExceptionHandling.DisplayInFile,
                    TypeHandling   = UnresolvedTypeExceptionHandling.DisplayInFile
                },
                PrintSerializationProgress          = true,
                PrintSerializationProgressFrequency = 1000,
                Id        = "il2cpp_codegen",
                Version   = "0.2.2",
                Libil2cpp = libIl2cpp
            };

            var serializer = new CppDataSerializer(config, parsed);

            Console.WriteLine("Resolving types...");
            try
            {
                watch.Restart();
                // context unused
                serializer.PreSerialize(null, parsed);
                watch.Stop();
                Console.WriteLine($"Resolution Complete, took: {watch.Elapsed}!");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Console.WriteLine("Serializing...");
            try
            {
                watch.Restart();
                serializer.Serialize(null, parsed, true);
                watch.Stop();
                Console.WriteLine($"Serialization Complete, took: {watch.Elapsed}!");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine(string.Join(", ", SerializationConfig.SpecialMethodNames));
            Console.ReadLine();
        }
Esempio n. 10
0
        public static IEnumerable <TableInfo> GetTablesToDump(IDbConnection connection, DumpConfig dumpConfig)
        {
            const string sqlFormat =
                @"select
	t.TABLE_NAME,
	t.TABLE_SCHEMA,
    (select top 1
		c.COLUMN_NAME
	from
		information_schema.columns c
	where
		c.TABLE_NAME = t.TABLE_NAME
		and columnproperty(object_id(c.TABLE_SCHEMA + '.' + c.TABLE_NAME), c.COLUMN_NAME, 'IsIdentity') = 1
	) as identity_column
from
	information_schema.tables t
where
	t.TABLE_TYPE = 'BASE TABLE'{0}
order by
	t.TABLE_NAME"    ;

            var tableNames      = dumpConfig.TableInfos.Select(x => x.Name).ToList();
            var listIsExclusive = dumpConfig.TableListIsExclusive;

            string sqlTableNames;

            if (tableNames.Count == 0)
            {
                sqlTableNames = string.Format(sqlFormat, string.Empty);
            }
            else if (listIsExclusive)
            {
                sqlTableNames = string.Format(sqlFormat,
                                              "\n\tand t.table_name not in ('" + string.Join("', '", tableNames) + "')");
            }
            else
            {
                sqlTableNames = string.Format(sqlFormat,
                                              "\n\tand t.table_name in ('" + string.Join("', '", tableNames) + "')");
            }

            var tableList = new List <TableInfo>();

            using (var command = connection.CreateCommand())
            {
                command.CommandText = sqlTableNames;

                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var tableName      = reader.GetString(0);
                        var tableSchema    = reader.GetString(1);
                        var identityColumn = reader.IsDBNull(2) ? null : reader.GetString(2);

                        var passedInTable = dumpConfig
                                            .TableInfos
                                            .SingleOrDefault(x => x.Name == tableName);

                        var tableInfo = new TableInfo
                        {
                            Name           = tableName,
                            Schema         = tableSchema,
                            IdentityColumn = identityColumn
                        };

                        if (passedInTable != null && passedInTable.OverrideColumns.Any())
                        {
                            tableInfo.OverrideColumns = passedInTable.OverrideColumns;
                        }

                        tableList.Add(tableInfo);
                    }
                }
            }

            var sortedTableList = new List <TableInfo>();

            if (tableNames.Count > 1)
            {
                foreach (var tableName in tableNames)
                {
                    var tableInfo = tableList.Single(x => x.Name == tableName);
                    tableList.Remove(tableInfo);
                    sortedTableList.Add(tableInfo);
                }
            }
            else
            {
                sortedTableList = tableList;
            }

            foreach (var tableInfo in sortedTableList)
            {
                AddColumnFormatInfo(connection, tableInfo);
            }

            return(sortedTableList);
        }
Esempio n. 11
0
        public static void Dump(string dump, string end)
        {
            DumpConfig cfg = new DumpConfig();

            if (cfg.Dump) {
                string t = DateTime.Now.ToString("dd-HH.mm");
                string y = DateTime.Now.ToString("yyyy");
                string m = DateTime.Now.ToString("MMM");

                string file = Path.GetFullPath(cfg.Folder + y + "/" + m + "/" + t + end);
                if (!Directory.Exists(Path.GetDirectoryName(file)))
                    Directory.CreateDirectory(Path.GetDirectoryName(file));
                Logger.Info("Dumping to " + file);

                File.WriteAllText(file, dump);
            }
        }