mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 09:25:10 +00:00
- Added a little sample which tests the noexecute protection.
svn path=/trunk/; revision=11077
This commit is contained in:
parent
9d63d77c6e
commit
6375fca5be
2 changed files with 97 additions and 0 deletions
32
reactos/apps/tests/noexecute/makefile
Normal file
32
reactos/apps/tests/noexecute/makefile
Normal file
|
@ -0,0 +1,32 @@
|
|||
#
|
||||
# $Id: makefile,v 1.1 2004/09/26 17:00:15 hbirr Exp $
|
||||
#
|
||||
|
||||
PATH_TO_TOP = ../../..
|
||||
|
||||
TARGET_NORC = yes
|
||||
|
||||
TARGET_TYPE = program
|
||||
|
||||
TARGET_APPTYPE = console
|
||||
|
||||
TARGET_NAME = noexecute
|
||||
|
||||
TARGET_SDKLIBS = pseh.a
|
||||
|
||||
TARGET_PCH =
|
||||
|
||||
TARGET_OBJECTS = \
|
||||
noexecute.o
|
||||
|
||||
TARGET_CFLAGS = -Wall -Werror -D__USE_W32API
|
||||
|
||||
DEP_OBJECTS = $(TARGET_OBJECTS)
|
||||
|
||||
include $(PATH_TO_TOP)/rules.mak
|
||||
|
||||
include $(TOOLS_PATH)/helper.mk
|
||||
|
||||
include $(TOOLS_PATH)/depend.mk
|
||||
|
||||
# EOF
|
65
reactos/apps/tests/noexecute/noexecute.c
Normal file
65
reactos/apps/tests/noexecute/noexecute.c
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* $Id: noexecute.c,v 1.1 2004/09/26 17:00:15 hbirr Exp $
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <pseh.h>
|
||||
|
||||
int test(int x)
|
||||
{
|
||||
return x+1;
|
||||
}
|
||||
|
||||
void execute(char* message, int(*func)(int))
|
||||
{
|
||||
ULONG status = 0;
|
||||
ULONG result;
|
||||
|
||||
printf("%s ... ", message);
|
||||
|
||||
_SEH_TRY
|
||||
{
|
||||
result = func(1);
|
||||
}
|
||||
_SEH_HANDLE
|
||||
{
|
||||
status = _SEH_GetExceptionCode();
|
||||
}
|
||||
_SEH_END;
|
||||
if (status == 0)
|
||||
{
|
||||
printf("OK.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Error, status=%lx.\n", status);
|
||||
}
|
||||
}
|
||||
|
||||
char data[100];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned char stack[100];
|
||||
void* heap;
|
||||
ULONG protection;
|
||||
|
||||
printf("NoExecute\n");
|
||||
|
||||
execute("Executing within the code segment", test);
|
||||
memcpy(data, test, 100);
|
||||
execute("Executing within the data segment", (int(*)(int))data);
|
||||
memcpy(stack, test, 100);
|
||||
execute("Executing on stack segment", (int(*)(int))stack);
|
||||
heap = VirtualAlloc(NULL, 100, MEM_COMMIT, PAGE_READWRITE);
|
||||
memcpy(heap, test, 100);
|
||||
execute("Executing on the heap with protection PAGE_READWRITE", (int(*)(int))heap);
|
||||
VirtualProtect(heap, 100, PAGE_EXECUTE, &protection);
|
||||
execute("Executing on the heap with protection PAGE_EXECUTE", (int(*)(int))heap);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue