Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

utxcpt1.c File Reference

#include <ntos.h>

Go to the source code of this file.

Functions

 main ()


Function Documentation

main  ) 
 

Definition at line 5 of file utxcpt1.c.

References DbgPrint, EXCEPTION_EXECUTE_HANDLER, NtAllocateVirtualMemory(), NtProtectVirtualMemory(), NTSTATUS(), NULL, ObjectAttributes, and Offset.

00006 { 00007 LONG i, j; 00008 PULONG p4, p3, p2, p1; 00009 ULONG Size1, Size2, Size3; 00010 NTSTATUS status; 00011 HANDLE CurrentProcessHandle; 00012 MEMORY_BASIC_INFORMATION MemInfo; 00013 ULONG OldProtect; 00014 STRING Name3; 00015 HANDLE Section1; 00016 OBJECT_ATTRIBUTES ObjectAttributes; 00017 ULONG ViewSize, Offset; 00018 00019 CurrentProcessHandle = NtCurrentProcess(); 00020 00021 for(i=0;i<3;i++){ 00022 DbgPrint("Hello World...\n\n"); 00023 } 00024 00025 DbgPrint("allocating virtual memory\n"); 00026 00027 p1 = (PULONG)NULL; 00028 Size1 = 5*4096; 00029 00030 status = NtAllocateVirtualMemory (CurrentProcessHandle, (PVOID)&p1, 00031 0, &Size1, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); 00032 00033 DbgPrint("created vm status %X start %lx size %lx\n", 00034 status, (ULONG)p1, Size1); 00035 00036 p2 = p1; 00037 00038 *p2 = 99; 00039 Size2 = 4; 00040 00041 status = NtProtectVirtualMemory (CurrentProcessHandle, (PVOID)&p2, 00042 &Size2, PAGE_GUARD | PAGE_READONLY, &OldProtect); 00043 00044 DbgPrint("protected VM status %X, base %lx, size %lx, old protect %lx\n", 00045 status, p2, Size2, OldProtect); 00046 00047 p3 = p1 + 1024; 00048 00049 *p3 =91; 00050 Size2 = 4; 00051 00052 status = NtProtectVirtualMemory (CurrentProcessHandle, (PVOID)&p3, 00053 &Size2, PAGE_NOACCESS, &OldProtect); 00054 00055 DbgPrint("protected VM status %X, base %lx, size %lx, old protect %lx\n", 00056 status, p3, Size2, OldProtect); 00057 try { 00058 *p2 = 94; 00059 00060 } except (EXCEPTION_EXECUTE_HANDLER) { 00061 status = GetExceptionCode(); 00062 DbgPrint("got an exception of %X\n",status); 00063 } 00064 00065 try { 00066 i = *p2; 00067 } except (EXCEPTION_EXECUTE_HANDLER) { 00068 status = GetExceptionCode(); 00069 DbgPrint("got an exception of %X\n",status); 00070 } 00071 00072 DbgPrint("value of p2 should be 94 is %ld\n",*p2); 00073 00074 try { 00075 *p3 = 94; 00076 00077 } except (EXCEPTION_EXECUTE_HANDLER) { 00078 status = GetExceptionCode(); 00079 DbgPrint("got an exception of %X\n",status); 00080 } 00081 00082 return 0; 00083 }


Generated on Sat May 15 19:46:06 2004 for test by doxygen 1.3.7