示例#1
0
 private static void SaveTxt(FileProto dp)
 {
     using (var w = new StreamWriter("..\\protobins\\" + dp.Name + ".txt"))
     {
         dp.PrintTo(w);
     }
 }
示例#2
0
        private static void ParseProtoBin(FileProto proto)
        {
            var dp = proto;

            SaveTxt(dp);

            SaveProto(dp);
        }
示例#3
0
        private static void SaveAsText(FileProto proto)
        {
            var path = "text\\" + proto.Name + ".txt";
            var dir  = Path.GetDirectoryName(path);

            if (dir != null && !Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            using (var w = new StreamWriter(path))
            {
                proto.PrintTo(w);
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            Console.WriteLine("ProtoBin Extractor started..");

            var files = Directory.GetFiles(".", "*.protobin", SearchOption.AllDirectories);

            Console.WriteLine("Found {0} protobin files.", files.Count());

            foreach (var file in files)
            {
                var proto = FileProto.ParseFrom(File.ReadAllBytes(file));
                Protos.Add(proto);
            }

            foreach (var proto in Protos)
            {
                ParseProtoBin(proto);
            }

            Console.WriteLine("Dumped {0} proto files.", files.Count());
            Console.ReadLine();
        }
示例#5
0
        private static void Main()
        {
            Console.WriteLine("protobin decompiler v0.2");

            var files = Directory.GetFiles("..\\protobins", "*.protobin", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                Protos.Add(FileProto.ParseFrom(File.ReadAllBytes(file)));
            }

            foreach (var p in Protos)
            {
                ParseProtoBin(p);
            }

            GenerateServices();

            Process.Start("xcopy", "..\\protobins\\*.proto ..\\tools /e /i /h /y");

            Console.WriteLine("Done! {0} files decompiled.", files.Length);

            Console.ReadKey();
        }
示例#6
0
 private static void ParseProtoBin(FileProto proto)
 {
     SaveAsText(proto);
     SaveDefinition(proto);
 }
示例#7
0
        private static void SaveDefinition(FileProto proto)
        {
            var path = "definitions\\" + proto.Name;
            var dir  = Path.GetDirectoryName(path);

            if (dir != null && !Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            using (var w = new StreamWriter(path))
            {
                foreach (var d in proto.DependencyList)
                {
                    w.WriteLine("import \"{0}\";", d);
                }

                if (proto.DependencyCount > 0)
                {
                    w.WriteLine();
                }

                if (proto.HasPackage)
                {
                    w.WriteLine("package {0};", proto.Package);
                    w.WriteLine();
                }

                if (proto.HasOptions)
                {
                    foreach (var o in proto.Options.AllFields)
                    {
                        if (o.Key.FieldType == FieldType.Enum)
                        {
                            w.WriteLine("option {0} = {1};", o.Key.Name, ((EnumValue)o.Value).Name);
                        }
                        else if (o.Key.FieldType == FieldType.String)
                        {
                            w.WriteLine("option {0} = \"{1}\";", o.Key.Name, o.Value);
                        }
                        else
                        {
                            w.WriteLine("option {0} = {1};", o.Key.Name, o.Value.ToString().ToLower());
                        }
                    }

                    w.WriteLine();
                }

                foreach (var m in proto.MessageTypeList)
                {
                    w.WriteLine("message {0}", m.Name);
                    w.WriteLine("{");

                    foreach (var n in m.NestedTypeList)
                    {
                        w.WriteLine("    message {0}", n.Name);
                        w.WriteLine("    {");
                        foreach (var ef in n.FieldList)
                        {
                            w.WriteLine("        {0} {1} {2} = {3};", Labels[ef.Label], GetTypeName(ef), ef.Name, ef.Number);
                        }
                        w.WriteLine("    }");
                        w.WriteLine();
                    }

                    foreach (var e in m.EnumTypeList)
                    {
                        w.WriteLine("    enum {0}", e.Name);
                        w.WriteLine("    {");
                        foreach (var ev in e.ValueList)
                        {
                            w.WriteLine("        {0} = {1};", ev.Name, ev.Number);
                        }
                        w.WriteLine("    }");
                        w.WriteLine();
                    }

                    //if (m.EnumTypeCount > 0)
                    //    w.WriteLine();

                    foreach (var f in m.FieldList)
                    {
                        if (f.HasDefaultValue)
                        {
                            w.WriteLine("    {0} {1} {2} = {3} [default = {4}];", Labels[f.Label], GetTypeName(f), f.Name, f.Number, f.Type == Type.TYPE_STRING ? string.Format("\"{0}\"", f.DefaultValue) : f.DefaultValue);
                        }
                        else
                        {
                            if (f.HasOptions && f.Options.HasPacked)
                            {
                                w.WriteLine("    {0} {1} {2} = {3} [packed={4}];", Labels[f.Label], GetTypeName(f), f.Name, f.Number, f.Options.Packed.ToString().ToLower());
                            }
                            else
                            {
                                w.WriteLine("    {0} {1} {2} = {3};", Labels[f.Label], GetTypeName(f), f.Name, f.Number);
                            }
                        }
                    }

                    //if (m.FieldCount > 0)
                    //    w.WriteLine();

                    foreach (var er in m.ExtensionRangeList)
                    {
                        w.WriteLine("    extensions {0} to {1};", er.Start,
                                    er.End == 0x20000000 ? "max" : er.End.ToString());
                    }

                    //if (m.ExtensionRangeCount > 0)
                    //    w.WriteLine();

                    foreach (var ext in m.ExtensionList)
                    {
                        w.WriteLine("    extend {0}", ext.Extendee);
                        w.WriteLine("    {");
                        {
                            w.WriteLine("        {0} {1} {2} = {3};", Labels[ext.Label], GetTypeName(ext), ext.Name, ext.Number);
                        }
                        w.WriteLine("    }");
                    }

                    w.WriteLine("}");
                    w.WriteLine();
                }

                foreach (var s in proto.ServiceList)
                {
                    w.WriteLine("service {0}", s.Name);
                    w.WriteLine("{");

                    foreach (var m in s.MethodList)
                    {
                        w.Write("    rpc {0}({1}) returns({2})", m.Name, m.InputType, m.OutputType);

                        if (m.HasOptions)
                        {
                            w.WriteLine();
                            w.WriteLine("    {");

                            foreach (var o in m.Options.UnknownFields.FieldDictionary)
                            {
                                var fdp = GetExtFieldDescriptorById(o.Key);

                                w.WriteLine("        option ({0}) = {1};", fdp.Name, GetValue(fdp, o.Value));
                            }
                            w.WriteLine("    }");
                        }
                        else
                        {
                            w.WriteLine(";");
                        }
                    }

                    w.WriteLine("}");
                    w.WriteLine();
                }

                foreach (var e in proto.EnumTypeList)
                {
                    w.WriteLine("enum {0}", e.Name);
                    w.WriteLine("{");
                    foreach (var ev in e.ValueList)
                    {
                        w.WriteLine("    {0} = {1};", ev.Name, ev.Number);
                    }
                    w.WriteLine("}");
                    w.WriteLine();
                }

                foreach (var ext in proto.ExtensionList)
                {
                    w.WriteLine("extend {0}", ext.Extendee);
                    w.WriteLine("{");
                    {
                        w.WriteLine("    {0} {1} {2} = {3};", Labels[ext.Label], GetTypeName(ext), ext.Name, ext.Number);
                    }
                    w.WriteLine("}");
                    w.WriteLine();
                }
            }
        }
示例#8
0
文件: Program.cs 项目: Geracl/d3proto
 private static void SaveTxt(FileProto dp)
 {
     using (var w = new StreamWriter("..\\protobins\\" + dp.Name + ".txt"))
     {
         dp.PrintTo(w);
     }
 }
示例#9
0
文件: Program.cs 项目: Geracl/d3proto
        private static void SaveProto(FileProto dp)
        {
            using (var w = new StreamWriter("..\\protobins\\" + dp.Name))
            {
                foreach (var d in dp.DependencyList)
                {
                    w.WriteLine("import \"{0}\";", d);
                }

                if (dp.DependencyCount > 0)
                    w.WriteLine();

                if (dp.HasPackage)
                {
                    w.WriteLine("package {0};", dp.Package);
                    w.WriteLine();
                }

                if (dp.HasOptions)
                {
                    foreach (var o in dp.Options.AllFields)
                    {
                        if (o.Key.FieldType == FieldType.Enum)
                            w.WriteLine("option {0} = {1};", o.Key.Name, ((EnumValue)o.Value).Name);
                        else if (o.Key.FieldType == FieldType.String)
                            w.WriteLine("option {0} = \"{1}\";", o.Key.Name, o.Value);
                        else
                            w.WriteLine("option {0} = {1};", o.Key.Name, o.Value.ToString().ToLower());
                    }

                    w.WriteLine();
                }

                foreach (var m in dp.MessageTypeList)
                {
                    w.WriteLine("message {0}", m.Name);
                    w.WriteLine("{");

                    foreach (var n in m.NestedTypeList)
                    {
                        w.WriteLine("    message {0}", n.Name);
                        w.WriteLine("    {");
                        foreach (var ef in n.FieldList)
                        {
                            w.WriteLine("        {0} {1} {2} = {3};", Labels[ef.Label], GetTypeName(ef), ef.Name, ef.Number);
                        }
                        w.WriteLine("    }");
                        w.WriteLine();
                    }

                    foreach (var e in m.EnumTypeList)
                    {
                        w.WriteLine("    enum {0}", e.Name);
                        w.WriteLine("    {");
                        foreach (var ev in e.ValueList)
                        {
                            w.WriteLine("        {0} = {1};", ev.Name, ev.Number);
                        }
                        w.WriteLine("    }");
                        w.WriteLine();
                    }

                    //if (m.EnumTypeCount > 0)
                    //    w.WriteLine();

                    foreach (var f in m.FieldList)
                    {
                        if (f.HasDefaultValue)
                        {
                            w.WriteLine("    {0} {1} {2} = {3} [default = {4}];", Labels[f.Label], GetTypeName(f), f.Name, f.Number, f.Type == Type.TYPE_STRING ? string.Format("\"{0}\"", f.DefaultValue) : f.DefaultValue);
                        }
                        else
                        {
                            if (f.HasOptions && f.Options.HasPacked)
                            {
                                w.WriteLine("    {0} {1} {2} = {3} [packed={4}];", Labels[f.Label], GetTypeName(f), f.Name, f.Number, f.Options.Packed.ToString().ToLower());
                            }
                            else
                            {
                                w.WriteLine("    {0} {1} {2} = {3};", Labels[f.Label], GetTypeName(f), f.Name, f.Number);
                            }
                        }
                    }

                    //if (m.FieldCount > 0)
                    //    w.WriteLine();

                    foreach (var er in m.ExtensionRangeList)
                    {
                        w.WriteLine("    extensions {0} to {1};", er.Start,
                                    er.End == 0x20000000 ? "max" : er.End.ToString());
                    }

                    //if (m.ExtensionRangeCount > 0)
                    //    w.WriteLine();

                    foreach (var ext in m.ExtensionList)
                    {
                        w.WriteLine("    extend {0}", ext.Extendee);
                        w.WriteLine("    {");
                        {
                            w.WriteLine("        {0} {1} {2} = {3};", Labels[ext.Label], GetTypeName(ext), ext.Name, ext.Number);
                        }
                        w.WriteLine("    }");
                    }

                    w.WriteLine("}");
                    w.WriteLine();
                }

                foreach (var s in dp.ServiceList)
                {
                    w.WriteLine("service {0}", s.Name);
                    w.WriteLine("{");

                    foreach (var m in s.MethodList)
                    {
                        w.Write("    rpc {0}({1}) returns({2})", m.Name, m.InputType, m.OutputType);

                        if (m.HasOptions)
                        {
                            w.WriteLine();
                            w.WriteLine("    {");

                            foreach (var o in m.Options.UnknownFields.FieldDictionary)
                            {
                                var fdp = GetExtFieldDescriptorById(o.Key);

                                w.WriteLine("        option ({0}) = {1};", fdp.Name, GetValue(fdp, o.Value));
                            }
                            w.WriteLine("    }");
                        }
                        else
                            w.WriteLine(";");
                    }

                    w.WriteLine("}");
                    w.WriteLine();
                }

                foreach (var e in dp.EnumTypeList)
                {
                    w.WriteLine("enum {0}", e.Name);
                    w.WriteLine("{");
                    foreach (var ev in e.ValueList)
                    {
                        w.WriteLine("    {0} = {1};", ev.Name, ev.Number);
                    }
                    w.WriteLine("}");
                    w.WriteLine();
                }

                foreach (var ext in dp.ExtensionList)
                {
                    w.WriteLine("extend {0}", ext.Extendee);
                    w.WriteLine("{");
                    {
                        w.WriteLine("    {0} {1} {2} = {3};", Labels[ext.Label], GetTypeName(ext), ext.Name, ext.Number);
                    }
                    w.WriteLine("}");
                    w.WriteLine();
                }
            }
        }
示例#10
0
文件: Program.cs 项目: Geracl/d3proto
        private static void ParseProtoBin(FileProto proto)
        {
            var dp = proto;

            SaveTxt(dp);

            SaveProto(dp);

        }
示例#11
0
文件: Program.cs 项目: wow4all/mooege
        private static void SaveAsText(FileProto proto)
        {
            var path = "text\\" + proto.Name + ".txt";
            var dir = Path.GetDirectoryName(path);
            if (dir != null && !Directory.Exists(dir))
                Directory.CreateDirectory(dir);

            using (var w = new StreamWriter(path))
            {
                proto.PrintTo(w);
            }
        }
示例#12
0
文件: Program.cs 项目: wow4all/mooege
 private static void ParseProtoBin(FileProto proto)
 {
     SaveAsText(proto);
     SaveDefinition(proto);
 }