View Single Post
  #2  
Old 02-10-2016, 14:41
atom0s's Avatar
atom0s atom0s is offline
Family
 
Join Date: Jan 2015
Location: 127.0.0.1
Posts: 396
Rept. Given: 26
Rept. Rcvd 126 Times in 63 Posts
Thanks Given: 54
Thanks Rcvd at 730 Times in 279 Posts
atom0s Reputation: 100-199 atom0s Reputation: 100-199
A version in C# that I made for my Steamless project:
PHP Code:
        /// <summary>
        /// Scans the given data for the given pattern.
        /// 
        /// Notes:
        ///     Patterns are assumed to be 2 byte hex values with spaces.
        ///     Wildcards are represented by ??.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="pattern"></param>
        /// <returns></returns>
        
public static uint FindPattern(byte[] datastring pattern)
        {
            try
            {
                
// Trim the pattern from extra whitespace..
                
var trimPattern pattern.Replace(" """).Trim();

                
// Convert the pattern to a byte array..
                
var patternMask = new List<bool>();
                var 
patternData Enumerable.Range(0trimPattern.Length).Where(=> == 0)
                                            .
Select(=>
                                                {
                                                    var 
bt trimPattern.Substring(x2);
                                                    
patternMask.Add(!bt.Contains('?'));
                                                    return 
bt.Contains('?') ? (byte)Convert.ToByte(bt16);
                                                }).
ToArray();

                
// Scan the given data for our pattern..
                
for (var 0data.Lengthx++)
                {
                    if (!
patternData.Where((ty) => patternMask[y] && != data[y]).Any())
                        return (
uint)x;
                }

                return 
0;
            }
            catch
            {
                return 
0;
            }
        } 
Example usage can be seen in Steamless here:
Code:
https://github.com/atom0s/Steamless
Reply With Quote
The Following User Says Thank You to atom0s For This Useful Post:
CryptXor (02-10-2016)