ReactOS 0.4.15-dev-7705-g2320c37
noexecute.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <windows.h>
5
6#include <pseh/pseh.h>
7
8int test(int x)
9{
10 return x+1;
11}
12
13void execute(char* message, int(*func)(int))
14{
15 ULONG status = 0;
17
18 printf("%s ... ", message);
19
21 {
22 result = func(1);
23 }
25 {
27 }
29 if (status == 0)
30 {
31 printf("OK.\n");
32 }
33 else
34 {
35 printf("Error, status=%lx.\n", status);
36 }
37}
38
39char data[100];
40
41int main(void)
42{
43 unsigned char stack[100];
44 void* heap;
45 ULONG protection;
46
47 printf("NoExecute\n");
48
49 execute("Executing within the code segment", test);
50 memcpy(data, test, 100);
51 execute("Executing within the data segment", (int(*)(int))data);
52 memcpy(stack, test, 100);
53 execute("Executing on stack segment", (int(*)(int))stack);
55 memcpy(heap, test, 100);
56 execute("Executing on the heap with protection PAGE_READWRITE", (int(*)(int))heap);
57 VirtualProtect(heap, 100, PAGE_EXECUTE, &protection);
58 execute("Executing on the heap with protection PAGE_EXECUTE", (int(*)(int))heap);
59
60 return 0;
61}
Definition: _stack.h:55
#define NULL
Definition: types.h:112
#define _SEH_TRY
Definition: framebased.h:244
#define _SEH_HANDLE
Definition: framebased.h:370
#define _SEH_GetExceptionCode()
Definition: framebased.h:158
#define _SEH_END
Definition: framebased.h:358
#define printf
Definition: freeldr.h:94
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLenum func
Definition: glext.h:6028
GLuint64EXT * result
Definition: glext.h:11304
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
void execute(char *message, int(*func)(int))
Definition: noexecute.c:13
int main(void)
Definition: noexecute.c:41
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define PAGE_EXECUTE
Definition: nt_native.h:1306
#define MEM_COMMIT
Definition: nt_native.h:1313
#define test
Definition: rosglue.h:37
static HANDLE heap
Definition: heap.c:65
Definition: tftpd.h:60
Definition: ps.c:97
uint32_t ULONG
Definition: typedefs.h:59
LPVOID NTAPI VirtualAlloc(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD flAllocationType, IN DWORD flProtect)
Definition: virtmem.c:65
BOOL NTAPI VirtualProtect(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD flNewProtect, OUT PDWORD lpflOldProtect)
Definition: virtmem.c:135