Commit in reactos/apps/tests/noexecute on MAIN
noexecute.c+65added 1.1
makefile+32added 1.1
+97
2 added files
- Added a little sample which tests the noexecute protection.

reactos/apps/tests/noexecute
noexecute.c added at 1.1
diff -N noexecute.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ noexecute.c	26 Sep 2004 17:00:15 -0000	1.1
@@ -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;
+}

reactos/apps/tests/noexecute
makefile added at 1.1
diff -N makefile
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ makefile	26 Sep 2004 17:00:15 -0000	1.1
@@ -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
CVSspam 0.2.8