コード例 #1
0
    private void DoInstall()
    {
        HookPool.AddHook(_targetMethod, this);

        if (_codePatcher == null)
        {
            if (GetFunctionAddr())
            {
#if ENABLE_HOOK_DEBUG
                UnityEngine.Debug.Log($"Original [{_targetMethod.DeclaringType.Name}.{_targetMethod.Name}]: {HookUtils.HexToString(_targetPtr.ToPointer(), 64, -16)}");
                UnityEngine.Debug.Log($"Original [{_replacementMethod.DeclaringType.Name}.{_replacementMethod.Name}]: {HookUtils.HexToString(_replacementPtr.ToPointer(), 64, -16)}");
                UnityEngine.Debug.Log($"Original [{_proxyMethod.DeclaringType.Name}.{_proxyMethod.Name}]: {HookUtils.HexToString(_proxyPtr.ToPointer(), 64, -16)}");
#endif

                CreateCodePatcher();
                _codePatcher.ApplyPatch();

#if ENABLE_HOOK_DEBUG
                UnityEngine.Debug.Log($"New [{_targetMethod.DeclaringType.Name}.{_targetMethod.Name}]: {HookUtils.HexToString(_targetPtr.ToPointer(), 64, -16)}");
                UnityEngine.Debug.Log($"New [{_replacementMethod.DeclaringType.Name}.{_replacementMethod.Name}]: {HookUtils.HexToString(_replacementPtr.ToPointer(), 64, -16)}");
                UnityEngine.Debug.Log($"New [{_proxyMethod.DeclaringType.Name}.{_proxyMethod.Name}]: {HookUtils.HexToString(_proxyPtr.ToPointer(), 64, -16)}");
#endif
            }
        }

        isHooked = true;
    }
コード例 #2
0
    public void Uninstall()
    {
        if (!isHooked)
        {
            return;
        }

        _codePatcher.RemovePatch();

        isHooked = false;
        HookPool.RemoveHooker(_targetMethod);
    }
コード例 #3
0
    private void DoInstall()
    {
        HookPool.AddHooker(_targetMethod, this);

        if (GetFunctionAddr())
        {
            BackupHeader();
            PatchTargetMethod();
            PatchProxyMethod();
        }

        isHooked = true;
    }
コード例 #4
0
    public void Uninstall()
    {
        if (!isHooked)
        {
            return;
        }

        byte *pTarget = (byte *)_targetPtr.ToPointer();

        for (int i = 0; i < _targetHeaderBackup.Length; i++)
        {
            *pTarget++ = _targetHeaderBackup[i];
        }

        isHooked = false;
        HookPool.RemoveHooker(_targetMethod);
    }
コード例 #5
0
ファイル: MethodHook.cs プロジェクト: yimi0111/MonoHook
    public void Install()
    {
        if (LDasm.IsiOS()) // iOS 不支持修改 code 所在区域 page
        {
            return;
        }

        if (isHooked)
        {
            return;
        }

        HookPool.AddHooker(_targetMethod, this);

        InitProxyBuff();
        BackupHeader();
        PatchTargetMethod();
        PatchProxyMethod();

        isHooked = true;
    }