示例#1
0
 /// <summary>
 ///     Performs a pattern scan.
 /// </summary>
 /// <param name="processHandle">The process the <see cref="ProcessModule" /> containing the data resides in.</param>
 /// <param name="processModule">The <see cref="ProcessModule" /> that contains the pattern data resides in.</param>
 /// <param name="data">The array of bytes containing the data to search for matches in.</param>
 /// <param name="mask">
 ///     The mask that defines the byte pattern we are searching for.
 ///     <example>
 ///         <code>
 /// var bytes = new byte[]{55,45,00,00,55} ;
 /// var mask = "xx??x";
 /// </code>
 ///     </example>
 /// </param>
 /// <param name="offsetToAdd">The offset to add to the offset result found from the pattern.</param>
 /// <param name="reBase">If the address should be rebased to this  Instance's base address.</param>
 /// <param name="wildCardChar">
 ///     [Optinal] The 'wild card' defines the <see cref="char" /> value that the mask uses to differentiate
 ///     between pattern data that is relevant, and pattern data that should be ignored. The default value is 'x'.
 /// </param>
 /// <param name="pattern">The byte array that contains the pattern of bytes we're looking for.</param>
 /// <returns>A new <see cref="PatternScanResult" /> instance.</returns>
 public static PatternScanResult Find(SafeMemoryHandle processHandle, ProcessModule processModule, byte[] data,
     byte[] pattern,
     string mask, int offsetToAdd, bool reBase, char wildCardChar = 'x')
 {
     for (var offset = 0; offset < data.Length; offset++)
     {
         if (mask.Where((m, b) => m == 'x' && pattern[b] != data[b + offset]).Any()) continue;
         var found = MemoryCore.Read<IntPtr>(processHandle,
             processModule.BaseAddress + offset + offsetToAdd);
         var result = new PatternScanResult
         {
             OriginalAddress = found,
             Address = reBase ? found : found.Subtract(processModule.BaseAddress),
             Offset = (IntPtr) offset
         };
         return result;
     }
     // If this is reached, the pattern was not found.
     throw new Exception("The pattern scan for the pattern mask: " + "[" + mask + "]" + " was not found.");
 }
 /// <summary>
 ///     Performs a pattern scan.
 /// </summary>
 /// <param name="processHandle">The process the <see cref="ProcessModule" /> containing the data resides in.</param>
 /// <param name="processModule">The <see cref="ProcessModule" /> that contains the pattern data resides in.</param>
 /// <param name="data">The array of bytes containing the data to search for matches in.</param>
 /// <param name="mask">
 ///     The mask that defines the byte pattern we are searching for.
 ///     <example>
 ///         <code>
 /// var bytes = new byte[]{55,45,00,00,55} ;
 /// var mask = "xx??x";
 /// </code>
 ///     </example>
 /// </param>
 /// <param name="offsetToAdd">The offset to add to the offset result found from the pattern.</param>
 /// <param name="reBase">If the address should be rebased to this  Instance's base address.</param>
 /// <param name="wildCardChar">
 ///     [Optinal] The 'wild card' defines the <see cref="char" /> value that the mask uses to differentiate
 ///     between pattern data that is relevant, and pattern data that should be ignored. The default value is 'x'.
 /// </param>
 /// <param name="pattern">The byte array that contains the pattern of bytes we're looking for.</param>
 /// <returns>A new <see cref="PatternScanResult" /> instance.</returns>
 public static PatternScanResult Find(SafeMemoryHandle processHandle, ProcessModule processModule, byte[] data,
                                      byte[] pattern,
                                      string mask, int offsetToAdd, bool reBase, char wildCardChar = 'x')
 {
     for (var offset = 0; offset < data.Length; offset++)
     {
         if (mask.Where((m, b) => m == 'x' && pattern[b] != data[b + offset]).Any())
         {
             continue;
         }
         var found = MemoryCore.Read <IntPtr>(processHandle,
                                              processModule.BaseAddress + offset + offsetToAdd);
         var result = new PatternScanResult
         {
             OriginalAddress = found,
             Address         = reBase ? found : found.Subtract(processModule.BaseAddress),
             Offset          = (IntPtr)offset
         };
         return(result);
     }
     // If this is reached, the pattern was not found.
     throw new Exception("The pattern scan for the pattern mask: " + "[" + mask + "]" + " was not found.");
 }
示例#3
0
        /// <summary>
        ///     Performs a pattern scan.
        /// </summary>
        /// <param name="pattern">The byte array that contains the pattern of bytes we're looking for.</param>
        /// <param name="mask">
        ///     The mask that defines the byte pattern we are searching for.
        ///     <example>
        ///         <code>
        /// var bytes = new byte[]{55,45,00,00,55} ;
        /// var mask = "xx??x";
        /// </code>
        ///     </example>
        /// </param>
        /// <param name="offsetToAdd">The offset to add to the offset result found from the pattern.</param>
        /// <param name="rebaseResult">
        ///     If the final address result should be rebased to the base address of the
        ///     <see cref="ProcessModule" /> the pattern data resides in.
        /// </param>
        /// <returns>A new <see cref="PatternScanResult" /> instance.</returns>
        public PatternScanResult FindPattern(byte[] pattern, string mask, int offsetToAdd, bool rebaseResult)
        {
            for (var offset = 0; offset < Data.Length; offset++)
            {
                if (mask.Where((m, b) => m == 'x' && pattern[b] != Data[b + offset]).Any())
                {
                    continue;
                }

                var found = MemorySharp.Read<IntPtr>(BaseAddress + offset + offsetToAdd);

                var result = new PatternScanResult
                {
                    OriginalAddress = found,
                    Address = rebaseResult ? found : IntPtr.Subtract(found, (int) BaseAddress),
                    Offset = (IntPtr) offset
                };

                return result;
            }
            throw new Exception("Could not find the pattern.");
        }