1+ using System ;
2+ using System . Xml ;
3+ using System . Runtime . InteropServices ;
4+
5+ namespace MsgTrans . Library
6+ {
7+ public class NtStatusToWin32 : Command
8+ {
9+ NtStatusCommand NtstatusCodes = null ;
10+ WinerrorCommand WinerrorCodes = null ;
11+
12+ [ DllImport ( "kernel32.dll" ) ]
13+ public static extern IntPtr LoadLibrary ( string FileName ) ;
14+
15+ [ DllImport ( "kernel32.dll" ) ]
16+ public static extern IntPtr GetProcAddress ( IntPtr hModule , string ProcName ) ;
17+
18+ [ DllImport ( "kernel32.dll" ) ]
19+ public static extern bool FreeLibrary ( IntPtr hModule ) ;
20+
21+ [ UnmanagedFunctionPointer ( CallingConvention . Cdecl ) ]
22+ private delegate ulong fRtlNtStatusToDosError ( ulong NtStatusCode ) ;
23+
24+
25+ public NtStatusToWin32 ( MessageTranslator msgTrans ,
26+ string ntstatusXml ,
27+ string winerrorXml ) :
28+ base ( msgTrans )
29+ {
30+ NtstatusCodes = new NtStatusCommand ( msgTrans , ntstatusXml ) ;
31+ WinerrorCodes = new WinerrorCommand ( msgTrans , winerrorXml ) ;
32+ }
33+
34+ public override string [ ] AvailableCommands
35+ {
36+ get { return new string [ ] { "ntstat2dos" } ; }
37+ }
38+
39+ public override bool Handle ( MessageContext context ,
40+ string commandName ,
41+ string parameters )
42+ {
43+ string ntstatusText = parameters ;
44+ if ( ntstatusText . Equals ( String . Empty ) )
45+ {
46+ return false ;
47+ }
48+
49+ if ( ! NtstatusCodes . Handle ( context , commandName , parameters ) )
50+ {
51+ return false ;
52+ }
53+
54+ long DosCode = GetDosCodeFromNtstatus ( NtstatusCodes . Number ) ;
55+ if ( DosCode == 0xFFFFFFFF )
56+ {
57+ return false ;
58+ }
59+
60+ if ( ! WinerrorCodes . Handle ( context , commandName , DosCode . ToString ( ) ) )
61+ {
62+ return false ;
63+ }
64+
65+ return true ;
66+ }
67+
68+ public override string Help ( )
69+ {
70+ return "blurgh <value>" ;
71+ }
72+
73+ private long GetDosCodeFromNtstatus ( long ntstatus )
74+ {
75+ ulong DosCode = 0xFFFFFFFF ;
76+ IntPtr hModule = LoadLibrary ( @"ntdll.dll" ) ;
77+ if ( hModule != null )
78+ {
79+ IntPtr Address = GetProcAddress ( hModule , "RtlNtStatusToDosError" ) ;
80+
81+ fRtlNtStatusToDosError RtlNtStatusToDosError =
82+ ( fRtlNtStatusToDosError ) Marshal . GetDelegateForFunctionPointer ( Address ,
83+ typeof ( fRtlNtStatusToDosError ) ) ;
84+
85+ DosCode = RtlNtStatusToDosError ( ( ulong ) ntstatus ) ;
86+
87+ FreeLibrary ( hModule ) ;
88+
89+ }
90+ return ( long ) DosCode ;
91+ }
92+ }
93+ }
94+
95+
96+ /*
97+ DWORD Status;
98+ RTL_NTSTATUS_TO_DOS_ERROR pRtlNtStatusToDosError;
99+ HMODULE hModule = LoadLibraryW(L"ntdll.dll");
100+ if (hModule)
101+ {
102+ pRtlNtStatusToDosError = (RTL_NTSTATUS_TO_DOS_ERROR)GetProcAddress(hModule, "RtlNtStatusToDosError");
103+
104+ #define STATUS_PROCESS_IS_PROTECTED ((NTSTATUS)0xC0000712L)
105+ Status = pRtlNtStatusToDosError(STATUS_PROCESS_IS_PROTECTED);
106+ }
107+
108+ */
0 commit comments