-
Notifications
You must be signed in to change notification settings - Fork 482
/
mm.cpp
46 lines (42 loc) · 782 Bytes
/
mm.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* Module Name:
* mm.cpp
*
* Abstract:
* Generic memory manipulation routines.
*
* Authors:
* Nick Peterson <everdox@gmail.com> | http://everdox.net/
*
* Special thanks to Nemanja (Nemi) Mulasmajic <nm@triplefault.io>
* for his help with the POC.
*
*/
#include "stdafx.h"
#include "mm.h"
/*
* Search a memory buffer for the input signature.
*/
const void* MmSearchMemory(
_In_ const void* Buffer,
_In_ size_t SizeOfBuffer,
_In_ const void* Signature,
_In_ size_t SizeOfSignature)
{
//
// Sanity check...
//
if (SizeOfSignature > SizeOfBuffer)
{
return NULL;
}
PCHAR Memory = (PCHAR)Buffer;
for (size_t i = 0; i < (SizeOfBuffer - SizeOfSignature); ++i)
{
if (!memcmp(&Memory[i], Signature, SizeOfSignature))
{
return &Memory[i];
}
}
return NULL;
}