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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
/*=============================================================
**
** Source: helper.c
**
** Purpose: This helper process sets up a block of memory, then
** raises an exception to pass that memory location back to the
** parent process. When the parent process is done calling WriteProcessMemory
** we check here that it was written properly.
**
**
**============================================================*/
#include <palsuite.h>
const int MY_EXCEPTION=999;
int __cdecl main(int argc, char *argv[])
{
char* Memory;
char* TheArray[1];
int i;
if(0 != (PAL_Initialize(argc, argv)))
{
return FAIL;
}
Memory = (char*)VirtualAlloc(NULL, 4096, MEM_COMMIT, PAGE_READONLY);
if(Memory == NULL)
{
Fail("ERROR: Attempted to allocate two pages, but the VirtualAlloc "
"call failed. GetLastError() returned %d.\n",GetLastError());
}
TheArray[0] = Memory;
/* Need to sleep for a couple seconds. Otherwise this process
won't be being debugged when the first exception is raised.
*/
Sleep(4000);
RaiseException(MY_EXCEPTION, 0, 1, (ULONG_PTR*)TheArray);
for(i=0; i<4096; ++i)
{
if(Memory[i] != '\0')
{
Fail("ERROR: The memory should be unchanged after the "
"invalid call to WriteProcessMemory, but the char "
"at index %d has changed.\n",i);
}
}
PAL_Terminate();
return PASS;
}
|