// 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)
         );
 }
Exemple #2
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!");
                }
            }
        }
Exemple #3
0
        private void DecompileClass_SilentOrbit(IRClass target, out List <TypeDefinition> references)
        {
            // Fetch the properties of the type...
            // (At the same time, all references of this class are being collected.)
            var props = SilentOrbitInspector.ExtractClassProperties(_subject, out references);

            // and store the properties.
            target.Properties = props;

            // Extract necessary methods for decompilation
            var serializeEnum   = _subject.Methods.Where(SilentOrbitInspector.MatchSerializeMethod);
            var deserializeEnum = _subject.Methods.Where(SilentOrbitInspector.MatchDeserializeMethod);

            if (!serializeEnum.Any() || !deserializeEnum.Any())
            {
                throw new ExtractionException("No serialize or deserialize methods found!");
            }
            MethodDefinition serialize   = serializeEnum.First();
            MethodDefinition deserialize = deserializeEnum.First();

            // Create a handler for the serialize OnCall action.
            Action <CallInfo, List <byte> > silentOrbitSerializeCallHandler = (CallInfo info,
                                                                               List <byte> w) =>
            {
                // Just chain the call.
                // Property information is updated in place!
                SilentOrbitInspector.SerializeOnCall(info, w, props);
            };

            // Walk the serialize method for additional information.
            MethodWalker.WalkMethod(serialize, silentOrbitSerializeCallHandler, null);

            // Create handler for deserialize oncall action.
            Action <CallInfo, List <byte> > silentOrbitDeserializeCallHandler = (CallInfo info,
                                                                                 List <byte> w) =>
            {
                // Just chain the call.
                // Property information is updated in place!
                SilentOrbitInspector.DeserializeOnCall(info, w, props);
            };

            // Walk the deserialize method for additional information.
            MethodWalker.WalkMethod(deserialize, silentOrbitDeserializeCallHandler, null);
        }