ReactOS  0.4.13-dev-73-gcfe54aa
noexecute.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <pseh/pseh.h>
Include dependency graph for noexecute.c:

Go to the source code of this file.

Functions

int test (int x)
 
void execute (char *message, int(*func)(int))
 
int main (void)
 

Variables

char data [100]
 

Function Documentation

◆ execute()

void execute ( char message,
int(*)(int func 
)

Definition at line 13 of file noexecute.c.

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 }
GLenum func
Definition: glext.h:6028
Definition: tftpd.h:59
#define _SEH_HANDLE
Definition: framebased.h:370
#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
Definition: ps.c:97

Referenced by add_file_data(), and main().

◆ main()

int main ( void  )

Definition at line 41 of file noexecute.c.

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 }
int test(int x)
Definition: noexecute.c:8
#define MEM_COMMIT
Definition: nt_native.h:1313
void execute(char *message, int(*func)(int))
Definition: noexecute.c:13
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
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned int ULONG
Definition: retypes.h:1
#define printf
Definition: config.h:203
#define PAGE_READWRITE
Definition: nt_native.h:1304

◆ test()

int test ( int  x)

Definition at line 8 of file noexecute.c.

9 {
10  return x+1;
11 }
GLint GLint GLint GLint GLint x
Definition: gl.h:1548

Referenced by main().

Variable Documentation

◆ data

char data[100]

Definition at line 39 of file noexecute.c.