Example #1
0
        /// <summary>
        /// Creates a new Detour.
        /// </summary>
        /// <param name="target">The original function to detour. (This delegate should already be registered via Magic.RegisterDelegate)</param>
        /// <param name="newTarget">The new function to be called. (This delegate should NOT be registered!)</param>
        /// <param name="name">The name of the detour.</param>
        /// <returns>A <see cref="Detour"/> object containing the required methods to apply, remove, and call the original function.</returns>
        public Detour Create(Delegate target, Delegate newTarget, string name)
        {
#if !NOEXCEPTIONS
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }
            if (newTarget == null)
            {
                throw new ArgumentNullException("newTarget");
            }
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }
            if (!Utilities.HasUFPAttribute(target))
            {
                throw new MissingAttributeException("The target delegate does not have the proper UnmanagedFunctionPointer attribute!");
            }
            if (!Utilities.HasUFPAttribute(newTarget))
            {
                throw new MissingAttributeException(
                          "The new target delegate does not have the proper UnmanagedFunctionPointer attribute!");
            }
#endif

            if (Applications.ContainsKey(name))
            {
                throw new ArgumentException(string.Format("The {0} detour already exists!", name), "name");
            }

            var d = new Detour(target, newTarget, name, Win32);
            Applications.Add(name, d);
            return(d);
        }
Example #2
0
        internal Detour Create(Delegate target, Delegate newTarget, string name)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            if (newTarget == null)
            {
                throw new ArgumentNullException(nameof(newTarget));
            }

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (Applications.ContainsKey(name))
            {
                throw new ArgumentException($"The {nameof(name)} detour already exists!");
            }

            Detour d = new Detour(target, newTarget, name);

            Applications.Add(name, d);
            return(d);
        }
Example #3
0
 /// <summary>
 ///     Creates a new <see cref="Patch" /> at the specified address.
 /// </summary>
 /// <param name="address">The address to begin the patch.</param>
 /// <param name="patchWith">The bytes to be written as the patch.</param>
 /// <param name="name">The name of the patch.</param>
 /// <returns>A patch object that exposes the required methods to apply and remove the patch.</returns>
 internal Patch Create(IntPtr address, byte[] patchWith, string name)
 {
     if (!Applications.ContainsKey(name))
     {
         var p = new Patch(address, patchWith, name, Memory);
         Applications.Add(name, p);
         return(p);
     }
     return(Applications[name]);
 }
Example #4
0
        /// <summary>
        /// Creates a new <see cref="Patch"/> at the specified address.
        /// </summary>
        /// <param name="address">The address to begin the patch.</param>
        /// <param name="patchWith">The bytes to be written as the patch.</param>
        /// <param name="name">The name of the patch.</param>
        /// <returns>A patch object that exposes the required methods to apply and remove the patch.</returns>
        public Patch Create(IntPtr address, byte[] patchWith, string name)
        {
#if !NOEXCEPTIONS
            if (address == IntPtr.Zero)
            {
                throw new ArgumentException("Address cannot be 0!", "address");
            }
            if (patchWith == null || patchWith.Length == 0)
            {
                throw new ArgumentNullException("patchWith", "Patch bytes cannot be null, or 0 bytes long!");
            }
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }
#endif

            if (!Applications.ContainsKey(name))
            {
                return(new Patch(address, patchWith, name, Win32));
            }
            return(null);
        }