// Use this method to match all definitions that can be processed by this
 // class. Eg: All classes that have the interface IProtoBuf!
 public static bool MatchDecompilableClasses(TypeDefinition t)
 {
     return
         // Validate SilentOrbit.
         (SilentOrbitInspector.MatchDecompilableClasses(t) ||
          // Validate GoogleProtobuffer.
          GoogleCSInspector.MatchDecompilableClasses(t)
         );
 }
示例#2
0
        private void DecompileClass_Google(IRClass target, out List <TypeDefinition> references)
        {
            // Fetch properties of the type..
            var props = GoogleCSInspector.ExtractClassProperties(_subject, out references);

            // Store properties.
            target.Properties = props;

            // Container of all parsed tags.
            List <ulong> tags = new List <ulong>();
            var          constructEnumeration = _subject.Methods.Where(GoogleCSInspector.MatchStaticConstructor);

            if (!constructEnumeration.Any())
            {
                throw new ExtractionException("No static constructor found!");
            }
            var construct = constructEnumeration.First();
            Action <CallInfo, List <byte> > cctorOnCall = (CallInfo c, List <byte> w) =>
            {
                GoogleCSInspector.StaticCctorOnCall(c, props, tags);
            };
            Action <StoreInfo, List <byte> > cctorOnStore = (StoreInfo s, List <byte> w) =>
            {
                GoogleCSInspector.StaticCctorOnStore(s, props, tags);
            };

            // Walk static constructor method.
            MethodWalker.WalkMethod(construct, cctorOnCall, cctorOnStore);

            // Extract necesary methods for decompilation.
            var serializeEnumeration = _subject.Methods.Where(GoogleCSInspector.MatchSerializeMethod);

            if (!serializeEnumeration.Any())
            {
                throw new ExtractionException("No serialize method found!");
            }

            // Get serialize method.
            var serialize = serializeEnumeration.First();

            // Handler for serialize oncall action.
            Action <CallInfo, List <byte> > googleSerializeOnCall = (CallInfo info, List <byte> w) =>
            {
                // Just chain the call.
                GoogleCSInspector.SerializeOnCall(info, w, props);
            };

            // Walk serialize method.
            MethodWalker.WalkMethod(serialize, googleSerializeOnCall, null);
        }
示例#3
0
        public override void Decompile(out List <TypeDefinition> references)
        {
            // Create a new IRType to be filled in.
            if (IsEnum)
            {
                _constructedSubject = new IREnum(_subject.FullName, _subject.Name)
                {
                    Properties = new List <IREnumProperty>(),
                };
                // Extract the properties from this enum, local function.
                ExtractEnumProperties();

                // Enums have no references to other types.
                references = new List <TypeDefinition>();
            }
            else
            {
                var irClass = new IRClass(_subject.FullName, _subject.Name)
                {
                    PrivateTypes = new List <IRTypeNode>(),
                    Properties   = new List <IRClassProperty>(),
                };
                _constructedSubject = irClass;

                // Test for SilentOrbit decompilation.
                if (SilentOrbitInspector.MatchDecompilableClasses(_subject))
                {
                    DecompileClass_SilentOrbit(irClass, out references);
                }
                // Test for Google Protobuffer V1 decompilation.
                else if (GoogleV1Inspector.MatchDecompilableClasses(_subject))
                {
                    DecompileClass_GoogleV1(irClass, out references);
                }
                // Test for Google Protobuffer decompilation.
                else if (GoogleCSInspector.MatchDecompilableClasses(_subject))
                {
                    DecompileClass_Google(irClass, out references);
                }
                // Else fail..
                else
                {
                    throw new ExtractionException("Unrecognized proto compiler!");
                }
            }
        }