MCPcopy Create free account
hub / github.com/alliedmodders/sourcemod / FindPatternInFile

Method FindPatternInFile

tools/gdc-psyfork/MemoryUtils.cpp:71–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71void *MemoryUtils::FindPatternInFile(int fd, const char *pattern, size_t len, int &matches, bool &atFuncStart)
72{
73 size_t size;
74 size = lseek (fd , 0 , SEEK_END);
75
76 matches = 0;
77 // TODO: fix this
78 atFuncStart = true;
79
80 lseek(fd, 0, SEEK_SET);
81
82 void *map;
83 char *ptr, *start, *end;
84 bool found = true;
85 map = mmap(0, size, PROT_READ, MAP_SHARED, fd, 0);
86
87 ptr = (char *)map;
88 start = ptr;
89 end = ptr + size;
90
91 void *firstMatch = NULL;
92
93 while (ptr < end)
94 {
95 found = true;
96 for (register size_t i = 0; i < len; i++)
97 {
98 if (pattern[i] != '\x2A' && pattern[i] != ptr[i])
99 {
100 found = false;
101 break;
102 }
103 }
104
105 if (found)
106 {
107 if( !firstMatch )
108 {
109 firstMatch = ptr;
110 if( ptr - start >= 1 )
111 {
112 unsigned char oneBack = *(unsigned char*)((intptr_t)ptr - 1);
113 if( oneBack != 0xC3 && oneBack != 0xCB && oneBack != 0xCC )
114 {
115 if( ptr - start >= 3 )
116 {
117 unsigned char threeBack = *(unsigned char*)((intptr_t)ptr - 3);
118 if( threeBack != 0xCA && threeBack != 0xC2 )
119 {
120 atFuncStart = false;
121 }
122 }
123 else
124 {
125 atFuncStart = false;
126 }
127 }
128 }

Callers 2

GetWindowsSigPtrFunction · 0.80
checkSigStringWFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected