-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add support for NTSTATUS to Win32 error code conversion - Allow codes to be looked up via #define value as well as numeric
- Loading branch information
Showing
6 changed files
with
193 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
using System; | ||
using System.Xml; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace MsgTrans.Library | ||
{ | ||
public class NtStatusToWin32 : Command | ||
{ | ||
NtStatusCommand NtstatusCodes = null; | ||
WinerrorCommand WinerrorCodes = null; | ||
|
||
[DllImport("kernel32.dll")] | ||
public static extern IntPtr LoadLibrary(string FileName); | ||
|
||
[DllImport("kernel32.dll")] | ||
public static extern IntPtr GetProcAddress(IntPtr hModule, string ProcName); | ||
|
||
[DllImport("kernel32.dll")] | ||
public static extern bool FreeLibrary(IntPtr hModule); | ||
|
||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | ||
private delegate ulong fRtlNtStatusToDosError(ulong NtStatusCode); | ||
|
||
|
||
public NtStatusToWin32(MessageTranslator msgTrans, | ||
string ntstatusXml, | ||
string winerrorXml) : | ||
base(msgTrans) | ||
{ | ||
NtstatusCodes = new NtStatusCommand(msgTrans, ntstatusXml); | ||
WinerrorCodes = new WinerrorCommand(msgTrans, winerrorXml); | ||
} | ||
|
||
public override string[] AvailableCommands | ||
{ | ||
get { return new string[] { "ntstat2dos" }; } | ||
} | ||
|
||
public override bool Handle(MessageContext context, | ||
string commandName, | ||
string parameters) | ||
{ | ||
string ntstatusText = parameters; | ||
if (ntstatusText.Equals(String.Empty)) | ||
{ | ||
return false; | ||
} | ||
|
||
if (!NtstatusCodes.Handle(context, commandName, parameters)) | ||
{ | ||
return false; | ||
} | ||
|
||
long DosCode = GetDosCodeFromNtstatus(NtstatusCodes.Number); | ||
if (DosCode == 0xFFFFFFFF) | ||
{ | ||
return false; | ||
} | ||
|
||
if (!WinerrorCodes.Handle(context, commandName, DosCode.ToString())) | ||
{ | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public override string Help() | ||
{ | ||
return "blurgh <value>"; | ||
} | ||
|
||
private long GetDosCodeFromNtstatus(long ntstatus) | ||
{ | ||
ulong DosCode = 0xFFFFFFFF; | ||
IntPtr hModule = LoadLibrary(@"ntdll.dll"); | ||
if (hModule != null) | ||
{ | ||
IntPtr Address = GetProcAddress(hModule, "RtlNtStatusToDosError"); | ||
|
||
fRtlNtStatusToDosError RtlNtStatusToDosError = | ||
(fRtlNtStatusToDosError)Marshal.GetDelegateForFunctionPointer(Address, | ||
typeof(fRtlNtStatusToDosError)); | ||
|
||
DosCode = RtlNtStatusToDosError((ulong)ntstatus); | ||
|
||
FreeLibrary(hModule); | ||
|
||
} | ||
return (long)DosCode; | ||
} | ||
} | ||
} | ||
|
||
|
||
/* | ||
DWORD Status; | ||
RTL_NTSTATUS_TO_DOS_ERROR pRtlNtStatusToDosError; | ||
HMODULE hModule = LoadLibraryW(L"ntdll.dll"); | ||
if (hModule) | ||
{ | ||
pRtlNtStatusToDosError = (RTL_NTSTATUS_TO_DOS_ERROR)GetProcAddress(hModule, "RtlNtStatusToDosError"); | ||
#define STATUS_PROCESS_IS_PROTECTED ((NTSTATUS)0xC0000712L) | ||
Status = pRtlNtStatusToDosError(STATUS_PROCESS_IS_PROTECTED); | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters