ReactOS  0.4.12-dev-918-g6c6e7b8
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 
8 int test(int x)
9 {
10  return x+1;
11 }
12 
13 void execute(char* message, int(*func)(int))
14 {
15  ULONG status = 0;
16  ULONG result;
17 
18  printf("%s ... ", message);
19 
20  _SEH_TRY
21  {
22  result = func(1);
23  }
25  {
27  }
28  _SEH_END;
29  if (status == 0)
30  {
31  printf("OK.\n");
32  }
33  else
34  {
35  printf("Error, status=%lx.\n", status);
36  }
37 }
38 
39 char data[100];
40 
41 int 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 }
GLenum func
Definition: glext.h:6028
Definition: tftpd.h:59
int test(int x)
Definition: noexecute.c:8
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
#define MEM_COMMIT
Definition: nt_native.h:1313
void execute(char *message, int(*func)(int))
Definition: noexecute.c:13
#define _SEH_HANDLE
Definition: framebased.h:370
LPVOID NTAPI VirtualAlloc(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD flAllocationType, IN DWORD flProtect)
Definition: virtmem.c:74
smooth NULL
Definition: ftsmooth.c:416
#define PAGE_EXECUTE
Definition: nt_native.h:1306
Definition: _stack.h:47
BOOL NTAPI VirtualProtect(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD flNewProtect, OUT PDWORD lpflOldProtect)
Definition: virtmem.c:144
int main(void)
Definition: noexecute.c:41
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define _SEH_END
Definition: framebased.h:358
#define _SEH_TRY
Definition: framebased.h:244
unsigned int ULONG
Definition: retypes.h:1
#define _SEH_GetExceptionCode()
Definition: framebased.h:158
GLuint64EXT * result
Definition: glext.h:11304
#define printf
Definition: config.h:203
#define PAGE_READWRITE
Definition: nt_native.h:1304
Definition: ps.c:97