⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 typeinfo.cs

📁 VB杀手 v1.0.2007.1210(附源码)
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices.ComTypes;
using System.Runtime.InteropServices;

using TYPEATTR = System.Runtime.InteropServices.ComTypes.TYPEATTR;
using TYPEKIND = System.Runtime.InteropServices.ComTypes.TYPEKIND;
using TYPEFLAGS = System.Runtime.InteropServices.ComTypes.TYPEFLAGS;
using IMPLTYPEFLAGS = System.Runtime.InteropServices.ComTypes.IMPLTYPEFLAGS;

using System.Diagnostics;

namespace IDLTest
{
    /// <summary>
    /// 类型信息
    /// </summary>
    [DebuggerDisplay("{Name}")]
    class TypeInfo
    {
        #region 属性
        private String _Name;
        /// <summary>
        /// 名字
        /// </summary>
        public String Name
        {
            get
            {
                if (_Name != null) return _Name;
                _Name = Marshal.GetTypeInfoName(Info);
                return _Name;
            }
            set { _Name = value; }
        }

        public Int32 FuncsCount
        {
            get { return Attr.cFuncs; }
        }

        public Int32 SizeVft
        {
            get { return Attr.cbSizeVft; }
        }

        public TYPEKIND TypeKind
        {
            get { return Attr.typekind; }
        }

        private List<Func> _Funcs;

        public List<Func> Funcs
        {
            get
            {
                if (_Funcs != null) return _Funcs;
                _Funcs = new List<Func>();
                for (int i = 0; i < FuncsCount; i++)
                {
                    IntPtr ip;
                    Info.GetFuncDesc(i, out ip);
                    Func f = new Func(ip);
                    f.info = this;
                    String doc;
                    int context;
                    String help;
                    Info.GetDocumentation(f.fd.memid, out f.Name, out doc, out context, out help);
                    _Funcs.Add(f);
                }
                return _Funcs;
            }
        }

        public override string ToString()
        {
            String s = Name + " (" + FuncsCount.ToString() + ")";
            if ((Attr.wTypeFlags & TYPEFLAGS.TYPEFLAG_FHIDDEN) != 0) s += " [隐]";
            return s;
        }

        private IntPtr _BaseAddress = IntPtr.Zero;
        /// <summary>
        /// 基地址
        /// </summary>
        public IntPtr BaseAddress
        {
            get
            {
                if (_BaseAddress == IntPtr.Zero && ClassGuid != Guid.Empty)
                {
                    try
                    {
                        Object ppv = new object();
                        //只有类Guid才能获得对象
                        Type t = Type.GetTypeFromCLSID(ClassGuid);
                        ppv = Activator.CreateInstance(t);
                        IntPtr ip = Marshal.GetIDispatchForObject(ppv);
                        _BaseAddress = Marshal.ReadIntPtr(ip);
                    }
                    catch { }
                }
                return _BaseAddress;
            }
        }

        public IntPtr StaticAddress
        {
            get
            {
                if (Lib != null && !Lib.IsVB && _BaseAddress != IntPtr.Zero)
                    return (IntPtr)(_BaseAddress.ToInt32() - Lib.VirturlAddress.ToInt32() + Lib.ImageBase.ToInt32());
                else
                    return _BaseAddress;
            }
        }

        /// <summary>
        /// 类Guid
        /// </summary>
        public Guid ClassGuid;
        /// <summary>
        /// 类名
        /// </summary>
        public String ClassName
        {
            get
            {
                if (!Name.StartsWith("_") && !Name.StartsWith("I")) return Name;
                return Name.Substring(1);
            }
        }
        #endregion

        #region 原有属性
        public ITypeInfo Info;

        private TYPEATTR _Attr;
        /// <summary>
        /// 包含类型说明的属性
        /// </summary>
        public TYPEATTR Attr
        {
            get { return _Attr; }
        }
        #endregion

        #region 构造函数
        public TypeLib Lib;

        public TypeInfo(ITypeInfo info)
        {
            Info = info;
            String name = Marshal.GetTypeInfoName(info);

            IntPtr ip;
            Info.GetTypeAttr(out ip);
            _Attr = (TYPEATTR)Marshal.PtrToStructure(ip, typeof(TYPEATTR));

            //ITypeInfo2 inf = (ITypeInfo2)info;
            //if (Attr.cImplTypes > 0)
            //{
            //    IMPLTYPEFLAGS f;
            //    info.GetImplTypeFlags(0, out f);
            //    //object obj = new object();
            //    //inf.GetImplTypeCustData(0, ref ClassGuid, out obj);
            //    CUSTDATA cs = new CUSTDATA();
            //    IntPtr ipp = Marshal.AllocCoTaskMem(Marshal.SizeOf(cs));
            //    //Marshal.StructureToPtr(cs, ipp, true);
            //    inf.GetAllImplTypeCustData(0, ipp);
            //}
        }
        #endregion
    }

    struct CUSTDATAITEM
    {
        Guid guid;
        Object val;
    }

    struct CUSTDATA
    {
        Int32 count;
        CUSTDATAITEM[] arrs;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -