Skip to content

Commit da29231

Browse files
committed
extract functions
1 parent 397a1b2 commit da29231

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

src/custom/custom.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -94,31 +94,6 @@ extern void Initializer();
9494
ShadowMemory shadow_memory;
9595
} // namespace m2c
9696

97-
#if _WIN32
98-
void *memmem(const void *haystack,
99-
size_t haystack_len,
100-
const void *const needle,
101-
const size_t needle_len)
102-
{
103-
if (haystack == NULL)
104-
return NULL; // or assert(haystack != NULL);
105-
if (haystack_len == 0)
106-
return NULL;
107-
if (needle == NULL)
108-
return NULL; // or assert(needle != NULL);
109-
if (needle_len == 0)
110-
return NULL;
111-
112-
for (const char *h = (const char *)haystack; haystack_len >= needle_len;
113-
++h, --haystack_len) {
114-
if (!memcmp(h, needle, needle_len)) {
115-
return (void *)h;
116-
}
117-
}
118-
return NULL;
119-
}
120-
#endif
121-
12297
void masm2c_exit(unsigned char exit)
12398
{
12499
init++;

src/custom/utils.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,28 @@ size_t countEqual(const db *addr1, const db *addr2, int len)
138138
}
139139
return bytes;
140140
}
141+
142+
#if _WIN32
143+
void *memmem(const void *haystack,
144+
size_t haystack_len,
145+
const void *const needle,
146+
const size_t needle_len)
147+
{
148+
if (haystack == NULL)
149+
return NULL; // or assert(haystack != NULL);
150+
if (haystack_len == 0)
151+
return NULL;
152+
if (needle == NULL)
153+
return NULL; // or assert(needle != NULL);
154+
if (needle_len == 0)
155+
return NULL;
156+
157+
for (const char *h = (const char *)haystack; haystack_len >= needle_len;
158+
++h, --haystack_len) {
159+
if (!memcmp(h, needle, needle_len)) {
160+
return (void *)h;
161+
}
162+
}
163+
return NULL;
164+
}
165+
#endif

src/custom/utils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99

1010
//void hexDump(void *addr, int len);
1111
size_t countEqual(const db *addr1, const db *addr2, int len);
12+
#if _WIN32
13+
void *memmem(const void *haystack,
14+
size_t haystack_len,
15+
const void *const needle,
16+
const size_t needle_len);
17+
#endif
18+
1219
namespace m2c {
1320
void cmpHexDump(void *addr1, void *addr2, int len);
1421
}

0 commit comments

Comments
 (0)