Ejemplo n.º 1
0
 // 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) ||
          // Validates GoogleProtobuffer V1.
          GoogleV1Inspector.MatchDecompilableClasses(t)
         );
 }
Ejemplo n.º 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!");
                }
            }
        }
Ejemplo n.º 3
0
        private void DecompileClass_GoogleV1(IRClass target, out List <TypeDefinition> references)
        {
            // Setup containers
            var fieldNames       = new List <string>();
            var targetProperties = new List <IRClassProperty>();
            var allFields        = GoogleV1Inspector.ExtractClassFields(_subject);

            // .. and store the resulting properties into the target class.
            target.Properties = targetProperties;

            // Extract direct fields from the static data of the class.
            var staticConstructor = _subject.Methods.First(GoogleV1Inspector.MatchStaticConstructor);
            Action <CallInfo, List <byte> > cctorOnCall = (CallInfo c, List <byte> w) =>
            {
                GoogleV1Inspector.StaticCctorOnCall(c);
            };
            Action <StoreInfo, List <byte> > cctorOnStore = (StoreInfo s, List <byte> w) =>
            {
                GoogleV1Inspector.StaticCctorOnStore(s, fieldNames);
            };

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

            // Extract direct fields from the serialize method of the class.
            var serializer      = _subject.Methods.First(GoogleV1Inspector.MatchSerializeMethod);
            var localReferences = new List <TypeDefinition>();
            Action <CallInfo, List <byte> > serializeOnCall = (CallInfo c, List <byte> w) =>
            {
                GoogleV1Inspector.SerializeOnCall(c, fieldNames, allFields, targetProperties, localReferences);
            };
            Action <StoreInfo, List <byte> > serializeOnStore = (StoreInfo s, List <byte> w) =>
            {
                GoogleV1Inspector.SerializeOnStore(s);
            };

            // Walk static constructor method.
            MethodWalker.WalkMethod(serializer, serializeOnCall, serializeOnStore);


            references = localReferences;
        }