![]() |
ZenWINX Architecture - Reference Manual - Guides |
|
00001 /* 00002 * ZenWINX - WIndows Native eXtended library. 00003 * Copyright (c) 2007-2010 by Dmitri Arkhangelski (dmitriar@gmail.com). 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00027 #include "ntndk.h" 00028 #include "zenwinx.h" 00029 00030 int __stdcall kb_open(void); 00031 void __stdcall kb_close(void); 00032 00033 void winx_create_global_heap(void); 00034 void winx_destroy_global_heap(void); 00035 void winx_init_synch_objects(void); 00036 void winx_destroy_synch_objects(void); 00037 00038 #ifndef STATIC_LIB 00039 BOOL WINAPI DllMain(HANDLE hinstDLL,DWORD dwReason,LPVOID lpvReserved) 00040 { 00041 if(dwReason == DLL_PROCESS_ATTACH){ 00042 winx_create_global_heap(); 00043 winx_init_synch_objects(); 00044 } else if(dwReason == DLL_PROCESS_DETACH){ 00045 winx_destroy_global_heap(); 00046 winx_destroy_synch_objects(); 00047 } 00048 return 1; 00049 } 00050 #endif 00051 00057 void __stdcall zenwinx_native_init(void) 00058 { 00059 winx_create_global_heap(); 00060 winx_init_synch_objects(); 00061 } 00062 00068 void __stdcall zenwinx_native_unload(void) 00069 { 00070 winx_destroy_global_heap(); 00071 winx_destroy_synch_objects(); 00072 } 00073 00092 int __stdcall winx_init(void *peb) 00093 { 00094 PRTL_USER_PROCESS_PARAMETERS pp; 00095 int status; 00096 00097 /* 1. Normalize and get the Process Parameters */ 00098 pp = RtlNormalizeProcessParams(((PPEB)peb)->ProcessParameters); 00099 /* 2. Breakpoint if we were requested to do so */ 00100 if(pp->DebugFlags) DbgBreakPoint(); 00101 /* 3. Open keyboard */ 00102 status = kb_open(); 00103 return status; 00104 } 00105 00112 void __stdcall winx_exit(int exit_code) 00113 { 00114 kb_close(); 00115 /* 00116 * The next call is undocumented, therefore 00117 * we are not checking its result. 00118 */ 00119 (void)NtTerminateProcess(NtCurrentProcess(),exit_code); 00120 } 00121 00128 void __stdcall winx_reboot(void) 00129 { 00130 kb_close(); 00131 (void)winx_enable_privilege(SE_SHUTDOWN_PRIVILEGE); 00132 /* 00133 * The next call is undocumented, therefore 00134 * we are not checking its result. 00135 */ 00136 (void)NtShutdownSystem(ShutdownReboot); 00137 } 00138 00145 void __stdcall winx_shutdown(void) 00146 { 00147 kb_close(); 00148 (void)winx_enable_privilege(SE_SHUTDOWN_PRIVILEGE); 00149 /* 00150 * The next call is undocumented, therefore 00151 * we are not checking its result. 00152 */ 00153 (void)NtShutdownSystem(ShutdownNoReboot); 00154 } 00155