Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.74 KB | None | 0 0
  1. Imports System.Globalization
  2. Imports System.Text.RegularExpressions
  3. Imports quartus.CSDK
  4. Public Class CFindPattern
  5.  
  6.     Public Function Scanf(Dll As Integer, Pattern As String, Extra As Integer, Offset As Integer, ModeSubtract As Boolean) As Integer
  7.         Dim Off As Integer = BitConverter.ToInt32(mem.RdMem(AobScan(Dll, &H1800000, Pattern, 0) + Extra, 4), 0) + Offset
  8.         If ModeSubtract Then Off -= Dll
  9.         Return Off
  10.     End Function
  11.  
  12.     Private Function AobScan(ByVal Base As Integer, ByVal _Range As Integer, ByVal Signature As String, ByVal Instance As Integer) As Integer
  13.  
  14.         If (Signature <> String.Empty) Then
  15.             Dim New_String As String = Regex.Replace(Signature.Replace("??", "3F"), "[^a-fA-F0-9]", "")
  16.             Dim Count As Integer = -1
  17.             Dim SearchFor As Byte() = New Byte((New_String.Length / 2) - 1) {}
  18.             For i As Integer = 0 To SearchFor.Length - 1
  19.                 SearchFor(i) = Byte.Parse(New_String.Substring(i * 2, 2), NumberStyles.HexNumber)
  20.             Next i
  21.             Dim Sin As Byte() = mem.RdMem(Base, _Range)
  22.  
  23.             Dim Z As Integer = 0, P As Integer = 0
  24.             Dim iEnd As Integer = If(SearchFor.Length < &H20, SearchFor.Length, &H20)
  25.             Dim sBytes As Integer() = New Integer(&H100 - 1) {}
  26.             For j As Integer = 0 To iEnd - 1
  27.                 If (SearchFor(j) = &H3F) Then
  28.                     Z = (Z Or (CInt(1) << ((iEnd - j) - 1)))
  29.                 End If
  30.             Next j
  31.             If (Z <> 0) Then
  32.                 For k As Integer = 0 To sBytes.Length - 1
  33.                     sBytes(k) = Z
  34.                 Next k
  35.             End If
  36.             Z = 1
  37.             Dim index As Integer = (iEnd - 1)
  38.             Do While (index >= 0)
  39.                 sBytes(SearchFor(index)) = (sBytes(SearchFor(index)) Or Z)
  40.                 index -= 1
  41.                 Z = (Z << 1)
  42.             Loop
  43.             Do While (P <= (Sin.Length - SearchFor.Length))
  44.                 Z = (SearchFor.Length - 1)
  45.                 Dim last As Integer = SearchFor.Length
  46.                 Dim m As Integer = -1
  47.                 Do While (m <> 0)
  48.                     m = (m And sBytes(Sin(P + Z)))
  49.                     If (m <> 0) Then
  50.                         If (Z = 0) Then
  51.                             Count += 1
  52.                             If Count = Instance Then
  53.                                 Return Base + P
  54.                             End If
  55.                             P += 2
  56.                         End If
  57.                         last = Z
  58.                     End If
  59.                     Z -= 1
  60.                     m = (m << 1)
  61.                 Loop
  62.                 P += last
  63.             Loop
  64.         End If
  65.         Return -1
  66.     End Function
  67. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement