コード例 #1
0
        public void WriteMethod(DataNode node)
        {
            var method = new MethodWriter(this, node);

            Methods.Add(method);
            method.Process();
        }
コード例 #2
0
        void AddMethods(InterfaceGen iface, CodeGenerationOptions opt)
        {
            var handlers = new List <string> ();

            foreach (var m in iface.Methods)
            {
                Methods.Add(new InterfaceEventHandlerImplMethod(iface, m, handlers, opt));
            }

            var is_empty_method = new MethodWriter {
                Name       = "__IsEmpty",
                IsInternal = true,
                IsStatic   = true,
                ReturnType = TypeReferenceWriter.Bool
            };

            is_empty_method.Parameters.Add(new MethodParameterWriter("value", new TypeReferenceWriter(iface.Name + "Implementor")));

            if (!iface.Methods.Any(m => m.EventName != string.Empty) || handlers.Count == 0)
            {
                is_empty_method.Body.Add("return true;");
            }
            else
            {
                is_empty_method.Body.Add($"return {string.Join (" && ", handlers.Select (e => string.Format ("value.{0}Handler == null", e)))};");
            }

            Methods.Add(is_empty_method);
        }
コード例 #3
0
ファイル: Label.cs プロジェクト: anatawa12/Ow2AsmForCs
 internal virtual void put(MethodWriter owner, ByteVector @out, int source, bool wideOffset)
 {
     if ((status & RESOLVED) == 0)
     {
         if (wideOffset)
         {
             addReference(-1 - source, @out.length);
             @out.putInt(-1);
         }
         else
         {
             addReference(source, @out.length);
             @out.putShort(-1);
         }
     }
     else
     {
         if (wideOffset)
         {
             @out.putInt(position - source);
         }
         else
         {
             @out.putShort(position - source);
         }
     }
 }
コード例 #4
0
        // static sbyte n_ByteValueExact (IntPtr jnienv, IntPtr native__this)
        // {
        //  var __this = global::Java.Lang.Object.GetObject<Android.Icu.Math.BigDecimal> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
        //  return __this.ByteValueExact ();
        // }
        public MethodCallback(GenBase type, Method method, CodeGenerationOptions options, string propertyName, bool isFormatted)
        {
            this.type   = type;
            this.method = method;

            property_name = propertyName;
            is_formatted  = isFormatted;
            opt           = options;

            delegate_field  = new MethodCallbackDelegateField(method, options);
            delegate_getter = new GetDelegateHandlerMethod(method, options);

            Name       = "n_" + method.Name + method.IDSignature;
            ReturnType = new TypeReferenceWriter(method.RetVal.NativeType);

            IsStatic  = true;
            IsPrivate = method.IsInterfaceDefaultMethod;

            if (!string.IsNullOrWhiteSpace(method.Deprecated))
            {
                Attributes.Add(new ObsoleteAttr());
            }

            SourceWriterExtensions.AddSupportedOSPlatform(Attributes, method, opt);

            Parameters.Add(new MethodParameterWriter("jnienv", TypeReferenceWriter.IntPtr));
            Parameters.Add(new MethodParameterWriter("native__this", TypeReferenceWriter.IntPtr));

            foreach (var p in method.Parameters)
            {
                Parameters.Add(new MethodParameterWriter(options.GetSafeIdentifier(p.UnsafeNativeName), new TypeReferenceWriter(p.NativeType)));
            }
        }
コード例 #5
0
        void WriteType(FrameworkVersion version, TypeWrapper type)
        {
            var writer = new ClassWriter(this, version, type);

            writer.Write();

            foreach (var item in type.GetConstructors().Where(x => x.IsPublic))
            {
                var itemWriter = new ConstructorWriter(this, version, item);
                itemWriter.Write();
            }

            foreach (var item in type.GetMethodsToDocument())
            {
                // If a method is in another namespace, it is inherited and should not be overwritten
                if (item.DeclaringType.Namespace == type.Namespace)
                {
                    var itemWriter = new MethodWriter(this, version, item);
                    itemWriter.Write();
                }
            }

            foreach (var item in type.GetEvents())
            {
                // If an event is in another namespace, it is inherited and should not be overwritten
                if (item.DeclaringType.Namespace == type.Namespace)
                {
                    var itemWriter = new EventWriter(this, version, item);
                    itemWriter.Write();
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// This method deletes a 'Method' object.
        /// </summary>
        /// <param name='List<PolymorphicObject>'>The 'Method' to delete.
        /// <returns>A PolymorphicObject object with a Boolean value.
        internal PolymorphicObject DeleteMethod(List <PolymorphicObject> parameters, DataConnector dataConnector)
        {
            // Initial Value
            PolymorphicObject returnObject = new PolymorphicObject();

            // If the data connection is connected
            if ((dataConnector != null) && (dataConnector.Connected == true))
            {
                // Create Delete StoredProcedure
                DeleteMethodStoredProcedure deleteMethodProc = null;

                // verify the first parameters is a(n) 'Method'.
                if (parameters[0].ObjectValue as Method != null)
                {
                    // Create Method
                    Method method = (Method)parameters[0].ObjectValue;

                    // verify method exists
                    if (method != null)
                    {
                        // Now create deleteMethodProc from MethodWriter
                        // The DataWriter converts the 'Method'
                        // to the SqlParameter[] array needed to delete a 'Method'.
                        deleteMethodProc = MethodWriter.CreateDeleteMethodStoredProcedure(method);
                    }
                }

                // Verify deleteMethodProc exists
                if (deleteMethodProc != null)
                {
                    // Execute Delete Stored Procedure
                    bool deleted = this.DataManager.MethodManager.DeleteMethod(deleteMethodProc, dataConnector);

                    // Create returnObject.Boolean
                    returnObject.Boolean = new NullableBoolean();

                    // If delete was successful
                    if (deleted)
                    {
                        // Set returnObject.Boolean.Value to true
                        returnObject.Boolean.Value = NullableBooleanEnum.True;
                    }
                    else
                    {
                        // Set returnObject.Boolean.Value to false
                        returnObject.Boolean.Value = NullableBooleanEnum.False;
                    }
                }
            }
            else
            {
                // Raise Error Data Connection Not Available
                throw new Exception("The database connection is not available.");
            }

            // return value
            return(returnObject);
        }
コード例 #7
0
        public static void Main(string[] args)
        {
            Console.Title           = "ExeInjector v0.2";
            Console.CursorVisible   = false;
            Console.BackgroundColor = ConsoleColor.Black;
            Console.SetCursorPosition(0, 0);

            var menu = new Menu
                       (
                new MenuItem("Next", "Welcome to ExeInjector!", () => Console.WriteLine("Select the target assembly.")),
                new MenuItem("Exit", "Terminates the process and closes the window.", () => Environment.Exit(0))
                       );

            menu.ShowMenu();

            do
            {
                var libPath = DialogHelper.SelectFileDialog("Library(.dll)|*.dll");

                if (Path.GetFileName(libPath) == "Assembly-CSharp.dll")
                {
                    Console.Clear();
                    Console.WriteLine("Analyzing...");

                    var analyzer      = new MethodAnalyzer(libPath);
                    var methods       = analyzer.FindMethod();
                    var targetMethods = new MenuItem[methods.Count];

                    for (var i = 0; i < targetMethods.Length; i++)
                    {
                        targetMethods[i] = new MenuItem(methods[i].FullName, "Select the method to inject the code into.", () => Console.WriteLine("Please select an executable file."));
                    }

                    var methodsMenu = new Menu(targetMethods);
                    methodsMenu.ShowMenu(true);

                    var exePath = DialogHelper.SelectFileDialog("Exe(.exe)|*.exe");
                    var writer  = new MethodWriter(exePath);
                    writer.Inject(methods[methodsMenu.Index]);

                    Console.Clear();
                    Console.WriteLine("Target assembly overwrite complete!");
                    analyzer.Finish();
                    break;
                }

                if (libPath == string.Empty)
                {
                    break;
                }

                Console.WriteLine("Assembly-CSharp.dll");
            } while (true);

            Console.ReadKey();
        }
コード例 #8
0
        public void OverrideMethod()
        {
            MethodTemplate template = new MethodTemplate(null, "test", Code.Type("type")).Override();

            template.Code.AddLine(Code.Comment("Some code here"));
            MethodWriter writer = new MethodWriter();

            writer.Write(template, this.output);
            Assert.AreEqual("public override type test()\r\n{\r\n    // Some code here\r\n}", this.output.ToString());
        }
コード例 #9
0
        public void ParameterMethod()
        {
            Assert.Inconclusive("Not implemented yet");
            MethodTemplate template = new MethodTemplate(null, "test", Code.Type("type"));

            template.Parameters.Add(new ParameterTemplate(Code.Type("other"), "param"));
            template.Code.AddLine(Code.Comment("Some code here"));
            MethodWriter writer = new MethodWriter();

            writer.Write(template, this.output);
            Assert.AreEqual("public type test(other param)\r\n{\r\n    // Some code here\r\n}", this.output.ToString());
        }
コード例 #10
0
        protected override void WriteMarshalToNativeMethodDefinition(CppCodeWriter writer)
        {
            string uniqueIdentifier = $"{DefaultMarshalInfoWriter.Naming.ForType(base._type)}_{MarshalingUtils.MarshalTypeToString(base._marshalType)}_ToNativeMethodDefinition";

            MethodWriter.WriteMethodWithMetadataInitialization(writer, base._marshalToNativeFunctionDeclaration, base._marshalToNativeFunctionName, delegate(CppCodeWriter bodyWriter, MetadataUsage metadataUsage, MethodUsage methodUsage) {
                DefaultRuntimeMetadataAccess metadataAccess = new DefaultRuntimeMetadataAccess(null, metadataUsage, methodUsage);
                for (int j = 0; j < base.Fields.Length; j++)
                {
                    base.FieldMarshalInfoWriters[j].WriteMarshalVariableToNative(bodyWriter, new ManagedMarshalValue("unmarshaled", base.Fields[j]), base.FieldMarshalInfoWriters[j].UndecorateVariable($"marshaled.{DefaultMarshalInfoWriter.Naming.ForField(base.Fields[j])}"), null, metadataAccess);
                }
            }, uniqueIdentifier);
        }
コード例 #11
0
        /// <summary>
        /// This method finds a 'Method' object.
        /// </summary>
        /// <param name='List<PolymorphicObject>'>The 'Method' to delete.
        /// <returns>A PolymorphicObject object with a Boolean value.
        internal PolymorphicObject FindMethod(List <PolymorphicObject> parameters, DataConnector dataConnector)
        {
            // Initial Value
            PolymorphicObject returnObject = new PolymorphicObject();

            // locals
            Method method = null;

            // If the data connection is connected
            if ((dataConnector != null) && (dataConnector.Connected == true))
            {
                // Create Find StoredProcedure
                FindMethodStoredProcedure findMethodProc = null;

                // verify the first parameters is a 'Method'.
                if (parameters[0].ObjectValue as Method != null)
                {
                    // Get MethodParameter
                    Method paramMethod = (Method)parameters[0].ObjectValue;

                    // verify paramMethod exists
                    if (paramMethod != null)
                    {
                        // Now create findMethodProc from MethodWriter
                        // The DataWriter converts the 'Method'
                        // to the SqlParameter[] array needed to find a 'Method'.
                        findMethodProc = MethodWriter.CreateFindMethodStoredProcedure(paramMethod);
                    }

                    // Verify findMethodProc exists
                    if (findMethodProc != null)
                    {
                        // Execute Find Stored Procedure
                        method = this.DataManager.MethodManager.FindMethod(findMethodProc, dataConnector);

                        // if dataObject exists
                        if (method != null)
                        {
                            // set returnObject.ObjectValue
                            returnObject.ObjectValue = method;
                        }
                    }
                }
                else
                {
                    // Raise Error Data Connection Not Available
                    throw new Exception("The database connection is not available.");
                }
            }

            // return value
            return(returnObject);
        }
コード例 #12
0
        /// <summary>
        /// This method fetches all 'Method' objects.
        /// </summary>
        /// <param name='List<PolymorphicObject>'>The 'Method' to delete.
        /// <returns>A PolymorphicObject object with all  'Methods' objects.
        internal PolymorphicObject FetchAll(List <PolymorphicObject> parameters, DataConnector dataConnector)
        {
            // Initial Value
            PolymorphicObject returnObject = new PolymorphicObject();

            // locals
            List <Method> methodListCollection = null;

            // Create FetchAll StoredProcedure
            FetchAllMethodsStoredProcedure fetchAllProc = null;

            // If the data connection is connected
            if ((dataConnector != null) && (dataConnector.Connected == true))
            {
                // Get MethodParameter
                // Declare Parameter
                Method paramMethod = null;

                // verify the first parameters is a(n) 'Method'.
                if (parameters[0].ObjectValue as Method != null)
                {
                    // Get MethodParameter
                    paramMethod = (Method)parameters[0].ObjectValue;
                }

                // Now create FetchAllMethodsProc from MethodWriter
                fetchAllProc = MethodWriter.CreateFetchAllMethodsStoredProcedure(paramMethod);
            }

            // Verify fetchAllProc exists
            if (fetchAllProc != null)
            {
                // Execute FetchAll Stored Procedure
                methodListCollection = this.DataManager.MethodManager.FetchAllMethods(fetchAllProc, dataConnector);

                // if dataObjectCollection exists
                if (methodListCollection != null)
                {
                    // set returnObject.ObjectValue
                    returnObject.ObjectValue = methodListCollection;
                }
            }
            else
            {
                // Raise Error Data Connection Not Available
                throw new Exception("The database connection is not available.");
            }

            // return value
            return(returnObject);
        }
コード例 #13
0
        // This replaces any `Java.Lang.ICharSequence` parameters with `string`.
        public static void AddMethodParametersStringOverloads(this MethodWriter method, ParameterList parameters, CodeGenerationOptions opt)
        {
            foreach (var p in parameters)
            {
                var para = new MethodParameterWriter(opt.GetSafeIdentifier(p.Name), new TypeReferenceWriter(opt.GetTypeReferenceName(p).Replace("Java.Lang.ICharSequence", "string").Replace("global::string", "string")));

                if (p.IsEnumified)
                {
                    para.Attributes.Add(new GeneratedEnumAttr());
                }
                if (p.Annotation != null)
                {
                    para.Attributes.Add(new CustomAttr(p.Annotation));
                }

                method.Parameters.Add(para);
            }
        }
コード例 #14
0
ファイル: Label.cs プロジェクト: anatawa12/Ow2AsmForCs
        internal virtual bool resolve(MethodWriter owner, int position, byte[] data)
        {
            bool needUpdate = false;

            this.status  |= RESOLVED;
            this.position = position;
            int i = 0;

            while (i < referenceCount)
            {
                int source    = srcAndRefPositions[i++];
                int reference = srcAndRefPositions[i++];
                int offset;
                if (source >= 0)
                {
                    offset = position - source;
                    if (offset < short.MinValue || offset > short.MaxValue)
                    {
                        int opcode = data[reference - 1] & 0xFF;
                        if (opcode <= Opcodes.JSR)
                        {
                            data[reference - 1] = (byte)(opcode + 49);
                        }
                        else
                        {
                            data[reference - 1] = (byte)(opcode + 20);
                        }
                        needUpdate = true;
                    }
                    data[reference++] = (byte)(offset /*>>>*/ >> 8);
                    data[reference]   = (byte)offset;
                }
                else
                {
                    offset            = position + source + 1;
                    data[reference++] = (byte)(offset /*>>>*/ >> 24);
                    data[reference++] = (byte)(offset /*>>>*/ >> 16);
                    data[reference++] = (byte)(offset /*>>>*/ >> 8);
                    data[reference]   = (byte)offset;
                }
            }
            return(needUpdate);
        }
コード例 #15
0
        public void Basics()
        {
            var method = new MethodWriter {
                Name = "MyMethod", IsPublic = true, ReturnType = TypeReferenceWriter.Void
            };

            method.Parameters.Add(new MethodParameterWriter("test", TypeReferenceWriter.Bool));

            var sw     = new StringWriter();
            var writer = new CodeWriter(sw);

            method.Write(writer);

            var expected =
                @"public void MyMethod (bool test)
{
}
";

            Assert.AreEqual(expected, sw.ToString());
        }
コード例 #16
0
        protected override void WriteMarshalFromNativeMethodDefinition(CppCodeWriter writer)
        {
            string uniqueIdentifier = $"{DefaultMarshalInfoWriter.Naming.ForType(base._type)}_{MarshalingUtils.MarshalTypeToString(base._marshalType)}_FromNativeMethodDefinition";

            MethodWriter.WriteMethodWithMetadataInitialization(writer, base._marshalFromNativeFunctionDeclaration, base._marshalFromNativeFunctionName, delegate(CppCodeWriter bodyWriter, MetadataUsage metadataUsage, MethodUsage methodUsage) {
                DefaultRuntimeMetadataAccess metadataAccess = new DefaultRuntimeMetadataAccess(null, metadataUsage, methodUsage);
                for (int j = 0; j < base.Fields.Length; j++)
                {
                    FieldDefinition field = base.Fields[j];
                    ManagedMarshalValue destinationVariable = new ManagedMarshalValue("unmarshaled", field);
                    if (!field.FieldType.IsValueType())
                    {
                        base.FieldMarshalInfoWriters[j].WriteMarshalVariableFromNative(bodyWriter, base.FieldMarshalInfoWriters[j].UndecorateVariable($"marshaled.{DefaultMarshalInfoWriter.Naming.ForField(field)}"), destinationVariable, null, false, false, metadataAccess);
                    }
                    else
                    {
                        string name = destinationVariable.GetNiceName() + "_temp_" + j;
                        bodyWriter.WriteVariable(field.FieldType, name);
                        base.FieldMarshalInfoWriters[j].WriteMarshalVariableFromNative(bodyWriter, $"marshaled.{DefaultMarshalInfoWriter.Naming.ForField(field)}", new ManagedMarshalValue(name), null, false, false, metadataAccess);
                        bodyWriter.WriteLine(destinationVariable.Store(name));
                    }
                }
            }, uniqueIdentifier);
        }
コード例 #17
0
        void WriteType(FrameworkVersion version, TypeWrapper type)
        {
            var writer = new ClassWriter(this, version, type);

            writer.Write();

            foreach (var item in type.GetConstructors().Where(x => x.IsPublic))
            {
                var itemWriter = new ConstructorWriter(this, version, item);
                itemWriter.Write();
            }

            foreach (var item in type.GetMethodsToDocument())
            {
                var itemWriter = new MethodWriter(this, version, item);
                itemWriter.Write();
            }

            foreach (var item in type.GetEvents())
            {
                var itemWriter = new EventWriter(this, version, item);
                itemWriter.Write();
            }
        }
コード例 #18
0
        public virtual byte[] toByteArray()
        {
            if (index > 0xFFFF)
            {
                throw new RuntimeException("Class file too large!");
            }
            int         size     = 24 + 2 * interfaceCount;
            int         nbFields = 0;
            FieldWriter fb       = firstField;

            while (fb != null)
            {
                ++nbFields;
                size += fb.getSize();
                fb    = (FieldWriter)fb.fv;
            }
            int          nbMethods = 0;
            MethodWriter mb        = firstMethod;

            while (mb != null)
            {
                ++nbMethods;
                size += mb.getSize();
                mb    = (MethodWriter)mb.mv;
            }
            int attributeCount = 0;

            if (bootstrapMethods != null)
            {
                ++attributeCount;
                size += 8 + bootstrapMethods.length;
                newUTF8("BootstrapMethods");
            }
            if (ClassReader.SIGNATURES && signature != 0)
            {
                ++attributeCount;
                size += 8;
                newUTF8("Signature");
            }
            if (sourceFile != 0)
            {
                ++attributeCount;
                size += 8;
                newUTF8("SourceFile");
            }
            if (sourceDebug != null)
            {
                ++attributeCount;
                size += sourceDebug.length + 6;
                newUTF8("SourceDebugExtension");
            }
            if (enclosingMethodOwner != 0)
            {
                ++attributeCount;
                size += 10;
                newUTF8("EnclosingMethod");
            }
            if ((access & Opcodes.ACC_DEPRECATED) != 0)
            {
                ++attributeCount;
                size += 6;
                newUTF8("Deprecated");
            }
            if ((access & Opcodes.ACC_SYNTHETIC) != 0)
            {
                if ((version & 0xFFFF) < Opcodes.V1_5 || (access & ACC_SYNTHETIC_ATTRIBUTE) != 0)
                {
                    ++attributeCount;
                    size += 6;
                    newUTF8("Synthetic");
                }
            }
            if (innerClasses != null)
            {
                ++attributeCount;
                size += 8 + innerClasses.length;
                newUTF8("InnerClasses");
            }
            if (ClassReader.ANNOTATIONS && anns != null)
            {
                ++attributeCount;
                size += 8 + anns.getSize();
                newUTF8("RuntimeVisibleAnnotations");
            }
            if (ClassReader.ANNOTATIONS && ianns != null)
            {
                ++attributeCount;
                size += 8 + ianns.getSize();
                newUTF8("RuntimeInvisibleAnnotations");
            }
            if (ClassReader.ANNOTATIONS && tanns != null)
            {
                ++attributeCount;
                size += 8 + tanns.getSize();
                newUTF8("RuntimeVisibleTypeAnnotations");
            }
            if (ClassReader.ANNOTATIONS && itanns != null)
            {
                ++attributeCount;
                size += 8 + itanns.getSize();
                newUTF8("RuntimeInvisibleTypeAnnotations");
            }
            if (attrs != null)
            {
                attributeCount += attrs.getCount();
                size           += attrs.getSize(this, null, 0, -1, -1);
            }
            size += pool.length;
            ByteVector @out = new ByteVector(size);

            @out.putInt(unchecked ((int)0xCAFEBABE)).putInt(version);
            @out.putShort(index).putByteArray(pool.data, 0, pool.length);
            int mask = Opcodes.ACC_DEPRECATED | ACC_SYNTHETIC_ATTRIBUTE | ((access & ACC_SYNTHETIC_ATTRIBUTE) / TO_ACC_SYNTHETIC);

            @out.putShort(access & ~mask).putShort(name).putShort(superName);
            @out.putShort(interfaceCount);
            for (int i = 0; i < interfaceCount; ++i)
            {
                @out.putShort(interfaces[i]);
            }
            @out.putShort(nbFields);
            fb = firstField;
            while (fb != null)
            {
                fb.put(@out);
                fb = (FieldWriter)fb.fv;
            }
            @out.putShort(nbMethods);
            mb = firstMethod;
            while (mb != null)
            {
                mb.put(@out);
                mb = (MethodWriter)mb.mv;
            }
            @out.putShort(attributeCount);
            if (bootstrapMethods != null)
            {
                @out.putShort(newUTF8("BootstrapMethods"));
                @out.putInt(bootstrapMethods.length + 2).putShort(bootstrapMethodsCount);
                @out.putByteArray(bootstrapMethods.data, 0, bootstrapMethods.length);
            }
            if (ClassReader.SIGNATURES && signature != 0)
            {
                @out.putShort(newUTF8("Signature")).putInt(2).putShort(signature);
            }
            if (sourceFile != 0)
            {
                @out.putShort(newUTF8("SourceFile")).putInt(2).putShort(sourceFile);
            }
            if (sourceDebug != null)
            {
                int len = sourceDebug.length;
                @out.putShort(newUTF8("SourceDebugExtension")).putInt(len);
                @out.putByteArray(sourceDebug.data, 0, len);
            }
            if (enclosingMethodOwner != 0)
            {
                @out.putShort(newUTF8("EnclosingMethod")).putInt(4);
                @out.putShort(enclosingMethodOwner).putShort(enclosingMethod);
            }
            if ((access & Opcodes.ACC_DEPRECATED) != 0)
            {
                @out.putShort(newUTF8("Deprecated")).putInt(0);
            }
            if ((access & Opcodes.ACC_SYNTHETIC) != 0)
            {
                if ((version & 0xFFFF) < Opcodes.V1_5 || (access & ACC_SYNTHETIC_ATTRIBUTE) != 0)
                {
                    @out.putShort(newUTF8("Synthetic")).putInt(0);
                }
            }
            if (innerClasses != null)
            {
                @out.putShort(newUTF8("InnerClasses"));
                @out.putInt(innerClasses.length + 2).putShort(innerClassesCount);
                @out.putByteArray(innerClasses.data, 0, innerClasses.length);
            }
            if (ClassReader.ANNOTATIONS && anns != null)
            {
                @out.putShort(newUTF8("RuntimeVisibleAnnotations"));
                anns.put(@out);
            }
            if (ClassReader.ANNOTATIONS && ianns != null)
            {
                @out.putShort(newUTF8("RuntimeInvisibleAnnotations"));
                ianns.put(@out);
            }
            if (ClassReader.ANNOTATIONS && tanns != null)
            {
                @out.putShort(newUTF8("RuntimeVisibleTypeAnnotations"));
                tanns.put(@out);
            }
            if (ClassReader.ANNOTATIONS && itanns != null)
            {
                @out.putShort(newUTF8("RuntimeInvisibleTypeAnnotations"));
                itanns.put(@out);
            }
            if (attrs != null)
            {
                attrs.put(this, null, 0, -1, -1, @out);
            }
            if (hasAsmInsns)
            {
                anns              = null;
                ianns             = null;
                attrs             = null;
                innerClassesCount = 0;
                innerClasses      = null;
                firstField        = null;
                lastField         = null;
                firstMethod       = null;
                lastMethod        = null;
                compute           = MethodWriter.INSERTED_FRAMES;
                hasAsmInsns       = false;
                new ClassReader(@out.data).accept(this, ClassReader.EXPAND_FRAMES | ClassReader.EXPAND_ASM_INSNS);
                return(toByteArray());
            }
            return(@out.data);
        }
コード例 #19
0
ファイル: CSharpLanguage.cs プロジェクト: se7ensoft/dnSpy
        void WriteToolTipMethod(ITextOutput output, IMethod method)
        {
            var writer = new MethodWriter(this, output, method);
            writer.WriteReturnType();

            WriteToolTip(output, method.DeclaringType);
            output.Write('.', TextTokenType.Operator);
            if (writer.md != null && writer.md.IsConstructor && method.DeclaringType != null)
                output.Write(IdentifierEscaper.Escape(RemoveGenericTick(method.DeclaringType.Name)), TextTokenHelper.GetTextTokenType(method));
            else if (writer.md != null && writer.md.Overrides.Count > 0) {
                var ovrMeth = (IMemberRef)writer.md.Overrides[0].MethodDeclaration;
                WriteToolTipType(output, ovrMeth.DeclaringType, false);
                output.Write('.', TextTokenType.Operator);
                WriteMethodName(output, method, ovrMeth.Name);
            }
            else
                WriteMethodName(output, method, method.Name);

            writer.WriteGenericArguments();
            writer.WriteMethodParameterList('(', ')');
        }
コード例 #20
0
ファイル: CSharpLanguage.cs プロジェクト: se7ensoft/dnSpy
        void WriteToolTip(ITextOutput output, PropertyDef prop)
        {
            var sig = prop.PropertySig;
            var md = prop.GetMethods.FirstOrDefault() ??
                    prop.SetMethods.FirstOrDefault() ??
                    prop.OtherMethods.FirstOrDefault();

            var writer = new MethodWriter(this, output, md);
            writer.WriteReturnType();
            WriteToolTip(output, prop.DeclaringType);
            output.Write('.', TextTokenType.Operator);
            var ovrMeth = md == null || md.Overrides.Count == 0 ? null : md.Overrides[0].MethodDeclaration;
            if (prop.IsIndexer()) {
                if (ovrMeth != null) {
                    WriteToolTipType(output, ovrMeth.DeclaringType, false);
                    output.Write('.', TextTokenType.Operator);
                }
                output.Write("this", TextTokenType.Keyword);
                writer.WriteGenericArguments();
                writer.WriteMethodParameterList('[', ']');
            }
            else if (ovrMeth != null && GetPropName(ovrMeth) != null) {
                WriteToolTipType(output, ovrMeth.DeclaringType, false);
                output.Write('.', TextTokenType.Operator);
                output.Write(IdentifierEscaper.Escape(GetPropName(ovrMeth)), TextTokenHelper.GetTextTokenType(prop));
            }
            else
                output.Write(IdentifierEscaper.Escape(prop.Name), TextTokenHelper.GetTextTokenType(prop));

            output.WriteSpace();
            output.WriteLeftBrace();
            if (prop.GetMethods.Count > 0) {
                output.WriteSpace();
                output.Write("get", TextTokenType.Keyword);
                output.Write(';', TextTokenType.Operator);
            }
            if (prop.SetMethods.Count > 0) {
                output.WriteSpace();
                output.Write("set", TextTokenType.Keyword);
                output.Write(';', TextTokenType.Operator);
            }
            output.WriteSpace();
            output.WriteRightBrace();
        }
コード例 #21
0
ファイル: CSharpLanguage.cs プロジェクト: se7ensoft/dnSpy
        void WriteToolTipWithClassInfo(ITextOutput output, ITypeDefOrRef type)
        {
            var td = type.ResolveTypeDef();

            MethodDef invoke;
            if (IsDelegate(td) && (invoke = td.FindMethod("Invoke")) != null && invoke.MethodSig != null) {
                output.Write("delegate", TextTokenType.Keyword);
                output.WriteSpace();

                var writer = new MethodWriter(this, output, invoke);
                writer.WriteReturnType();

                // Always print the namespace here because that's what VS does. I.e., ignore
                // TOOLTIP_USE_NAMESPACES.
                WriteToolTipType(output, td, true);

                writer.WriteGenericArguments();
                writer.WriteMethodParameterList('(', ')');
                return;
            }

            if (td == null) {
                base.WriteToolTip(output, type, null);
                return;
            }

            string keyword;
            if (td.IsEnum)
                keyword = "enum";
            else if (td.IsValueType)
                keyword = "struct";
            else if (td.IsInterface)
                keyword = "interface";
            else
                keyword = "class";
            output.Write(keyword, TextTokenType.Keyword);
            output.WriteSpace();

            // Always print the namespace here because that's what VS does. I.e., ignore
            // TOOLTIP_USE_NAMESPACES.
            WriteToolTipType(output, type, true, false);
        }