Beispiel #1
0
        public static CorDynamicInfoHook Hook(ICorJitInfo *comp)
        {
            ICorDynamicInfo *dynInfo  = ICorJitInfo.ICorDynamicInfo(comp);
            IntPtr *         vfTbl    = dynInfo->vfptr;
            const int        SLOT_NUM = 0x27;
            IntPtr *         newVfTbl = (IntPtr *)Marshal.AllocHGlobal(SLOT_NUM * IntPtr.Size);

            for (int i = 0; i < SLOT_NUM; i++)
            {
                newVfTbl[i] = vfTbl[i];
            }
            if (ctNum == -1)
            {
                for (int i = 0; i < SLOT_NUM; i++)
                {
                    bool overrided = true;
                    for (byte *func = (byte *)vfTbl[i]; *func != 0xe9; func++)
                    {
                        if (IntPtr.Size == 8 ?
                            (*func == 0x48 && *(func + 1) == 0x81 && *(func + 2) == 0xe9) :
                            (*func == 0x83 && *(func + 1) == 0xe9))
                        {
                            overrided = false;
                            break;
                        }
                    }
                    if (overrided)
                    {
                        ctNum = i + 8;
                        break;
                    }
                }
            }

            CorDynamicInfoHook ret = new CorDynamicInfoHook()
            {
                info     = dynInfo,
                comp     = comp,
                newVfTbl = newVfTbl,
                oriVfTbl = vfTbl
            };

            ret.n_constructStringLiteral = new constructStringLiteral(ret.hookConstructStr);
            ret.o_constructStringLiteral = Marshal.GetDelegateForFunctionPointer(vfTbl[ctNum], typeof(constructStringLiteral)) as constructStringLiteral;
            newVfTbl[ctNum] = Marshal.GetFunctionPointerForDelegate(ret.n_constructStringLiteral);

            dynInfo->vfptr = newVfTbl;
            return(ret);
        }
Beispiel #2
0
 public static ICorStaticInfo *ICorStaticInfo(ICorDynamicInfo *ptr)
 {
     return((ICorStaticInfo *)((byte *)&ptr->vbptr + ptr->vbptr[hasLinkInfo ? 9 : 8]));
 }
Beispiel #3
0
 public static ICorStaticInfo *ICorStaticInfo(ICorDynamicInfo *ptr)
 {
     return(null);
 }