c++ findpattern
int CompareByteArray(PBYTE ByteArray1, PCHAR ByteArray2, PCHAR Mask, DWORD Length){ DWORD nextStart = 0; char start = ByteArray2[0]; for (DWORD i = 0; i < Length; i++) { if (Mask[i] == '?') { continue; } if (ByteArray1[i] == start) { nextStart = i; } if (ByteArray1[i] != (BYTE)ByteArray2[i]) { return nextStart; } } return -1;} PBYTE FindSignature(LPVOID BaseAddress, DWORD ImageSize, PCHAR Signature, PCHAR Mask){ PBYTE Address = NULL; PBYTE Buffer = (PBYTE) BaseAddress; DWORD Length = strlen(Mask); for (DWORD i = 0; i < (ImageSize - Length); i++) { int result = CompareByteArray((Buffer + i), Signature, Mask, Length); if (result < 0) { Address = (PBYTE)BaseAddress + i; break; } else { i += result; } } return Address;}
// CPP program to illustrate
// std::find
// CPP program to illustrate
// std::find
#include<bits/stdc++.h>
int main ()
{
std::vector<int> vec { 10, 20, 30, 40 };
// Iterator used to store the position
// of searched element
std::vector<int>::iterator it;
// Print Original Vector
std::cout << "Original vector :";
for (int i=0; i<vec.size(); i++)
std::cout << " " << vec[i];
std::cout << "\n";
// Element to be searched
int ser = 30;
// std::find function call
it = std::find (vec.begin(), vec.end(), ser);
if (it != vec.end())
{
std::cout << "Element " << ser <<" found at position : " ;
std::cout << it - vec.begin() << " (counting from zero) \n" ;
}
else
std::cout << "Element not found.\n\n";
return 0;
}