From 7319b27daebe02c3fbde1669ca8648fb6abd1ada Mon Sep 17 00:00:00 2001 From: Ged Murphy Date: Fri, 26 Jan 2018 16:35:59 +0000 Subject: [PATCH] [MSGTRANS] - Add support for NTSTATUS to Win32 error code conversion - Allow codes to be looked up via #define value as well as numeric --- GUI/MainForm.Designer.cs | 224 ++++++++++++++++++++--- GUI/MainForm.cs | 42 +++-- MsgTrans.Library/Command.cs | 8 +- MsgTrans.Library/MsgTrans.Library.csproj | 1 + MsgTrans.Library/MsgTrans.cs | 5 + MsgTrans.Library/NtStatusCommand.cs | 53 ++++-- MsgTrans.Library/NtStatusToWin32.cs | 108 +++++++++++ MsgTrans.Library/WinerrorCommand.cs | 52 ++++-- 8 files changed, 425 insertions(+), 68 deletions(-) create mode 100644 MsgTrans.Library/NtStatusToWin32.cs diff --git a/GUI/MainForm.Designer.cs b/GUI/MainForm.Designer.cs index ea3e5b0..849a217 100644 --- a/GUI/MainForm.Designer.cs +++ b/GUI/MainForm.Designer.cs @@ -53,7 +53,23 @@ namespace MsgTranslator this.wndmsgCodeTxtBox = new System.Windows.Forms.TextBox(); this.wndmsgCodeLabel = new System.Windows.Forms.Label(); this.wndmsgNumberLabel = new System.Windows.Forms.Label(); + this.status2Dos = new System.Windows.Forms.TabPage(); + this.dosCodeInfoLabel = new System.Windows.Forms.Label(); + this.ntstatusCodeInfoLabel = new System.Windows.Forms.Label(); + this.label11 = new System.Windows.Forms.Label(); + this.dosHexTextBox = new System.Windows.Forms.TextBox(); + this.dosDecimalTextBox = new System.Windows.Forms.TextBox(); + this.dosCodeTxtBox = new System.Windows.Forms.TextBox(); + this.dosDosErrorLabel = new System.Windows.Forms.Label(); + this.dosNumberLabel = new System.Windows.Forms.Label(); + this.label8 = new System.Windows.Forms.Label(); + this.ntstatusHexTextBox = new System.Windows.Forms.TextBox(); + this.ntstatusDecimalTextBox = new System.Windows.Forms.TextBox(); + this.ntstatusCodeTxtBox = new System.Windows.Forms.TextBox(); + this.ntstatusNtStatusLabel = new System.Windows.Forms.Label(); + this.ntstatusNumberLabel = new System.Windows.Forms.Label(); this.bugurlTab = new System.Windows.Forms.TabPage(); + this.JiraSummaryLink = new System.Windows.Forms.LinkLabel(); this.JiraDescriptionTextBox = new System.Windows.Forms.TextBox(); this.label6 = new System.Windows.Forms.Label(); this.JiraAssigneeTextBox = new System.Windows.Forms.TextBox(); @@ -66,17 +82,17 @@ namespace MsgTranslator this.label3 = new System.Windows.Forms.Label(); this.bugLinkLabel = new System.Windows.Forms.LinkLabel(); this.optionsTab = new System.Windows.Forms.TabPage(); + this.CopyrightlinkLabel = new System.Windows.Forms.LinkLabel(); this.optionsRunStartChkBox = new System.Windows.Forms.CheckBox(); this.optionsMinimizeChkBox = new System.Windows.Forms.CheckBox(); this.mainErrLabel = new System.Windows.Forms.Label(); this.tabPage1 = new System.Windows.Forms.TabPage(); this.tabPage2 = new System.Windows.Forms.TabPage(); this.toolTip = new System.Windows.Forms.ToolTip(this.components); - this.JiraSummaryLink = new System.Windows.Forms.LinkLabel(); - this.CopyrightlinkLabel = new System.Windows.Forms.LinkLabel(); this.mainTabControl.SuspendLayout(); this.errorMsgTab.SuspendLayout(); this.wndmsgTab.SuspendLayout(); + this.status2Dos.SuspendLayout(); this.bugurlTab.SuspendLayout(); this.optionsTab.SuspendLayout(); this.SuspendLayout(); @@ -103,6 +119,7 @@ namespace MsgTranslator // this.mainTabControl.Controls.Add(this.errorMsgTab); this.mainTabControl.Controls.Add(this.wndmsgTab); + this.mainTabControl.Controls.Add(this.status2Dos); this.mainTabControl.Controls.Add(this.bugurlTab); this.mainTabControl.Controls.Add(this.optionsTab); this.mainTabControl.Location = new System.Drawing.Point(12, 41); @@ -306,6 +323,150 @@ namespace MsgTranslator this.wndmsgNumberLabel.TabIndex = 0; this.wndmsgNumberLabel.Text = "Number:"; // + // status2Dos + // + this.status2Dos.Controls.Add(this.dosCodeInfoLabel); + this.status2Dos.Controls.Add(this.ntstatusCodeInfoLabel); + this.status2Dos.Controls.Add(this.label11); + this.status2Dos.Controls.Add(this.dosHexTextBox); + this.status2Dos.Controls.Add(this.dosDecimalTextBox); + this.status2Dos.Controls.Add(this.dosCodeTxtBox); + this.status2Dos.Controls.Add(this.dosDosErrorLabel); + this.status2Dos.Controls.Add(this.dosNumberLabel); + this.status2Dos.Controls.Add(this.label8); + this.status2Dos.Controls.Add(this.ntstatusHexTextBox); + this.status2Dos.Controls.Add(this.ntstatusDecimalTextBox); + this.status2Dos.Controls.Add(this.ntstatusCodeTxtBox); + this.status2Dos.Controls.Add(this.ntstatusNtStatusLabel); + this.status2Dos.Controls.Add(this.ntstatusNumberLabel); + this.status2Dos.Location = new System.Drawing.Point(4, 22); + this.status2Dos.Name = "status2Dos"; + this.status2Dos.Padding = new System.Windows.Forms.Padding(3); + this.status2Dos.Size = new System.Drawing.Size(292, 185); + this.status2Dos.TabIndex = 5; + this.status2Dos.Text = "Status to Win32"; + this.status2Dos.UseVisualStyleBackColor = true; + // + // dosCodeInfoLabel + // + this.dosCodeInfoLabel.AutoSize = true; + this.dosCodeInfoLabel.Location = new System.Drawing.Point(60, 102); + this.dosCodeInfoLabel.Name = "dosCodeInfoLabel"; + this.dosCodeInfoLabel.Size = new System.Drawing.Size(178, 13); + this.dosCodeInfoLabel.TabIndex = 27; + this.dosCodeInfoLabel.Text = "Win32 / DOS error code Information"; + // + // ntstatusCodeInfoLabel + // + this.ntstatusCodeInfoLabel.AutoSize = true; + this.ntstatusCodeInfoLabel.Location = new System.Drawing.Point(60, 14); + this.ntstatusCodeInfoLabel.Name = "ntstatusCodeInfoLabel"; + this.ntstatusCodeInfoLabel.Size = new System.Drawing.Size(147, 13); + this.ntstatusCodeInfoLabel.TabIndex = 26; + this.ntstatusCodeInfoLabel.Text = "NTSTATUS code Information"; + // + // label11 + // + this.label11.AutoSize = true; + this.label11.Location = new System.Drawing.Point(162, 126); + this.label11.Name = "label11"; + this.label11.Size = new System.Drawing.Size(12, 13); + this.label11.TabIndex = 25; + this.label11.Text = "/"; + // + // dosHexTextBox + // + this.dosHexTextBox.Location = new System.Drawing.Point(176, 123); + this.dosHexTextBox.Name = "dosHexTextBox"; + this.dosHexTextBox.ReadOnly = true; + this.dosHexTextBox.Size = new System.Drawing.Size(104, 20); + this.dosHexTextBox.TabIndex = 23; + // + // dosDecimalTextBox + // + this.dosDecimalTextBox.Location = new System.Drawing.Point(63, 123); + this.dosDecimalTextBox.Name = "dosDecimalTextBox"; + this.dosDecimalTextBox.ReadOnly = true; + this.dosDecimalTextBox.Size = new System.Drawing.Size(98, 20); + this.dosDecimalTextBox.TabIndex = 22; + // + // dosCodeTxtBox + // + this.dosCodeTxtBox.Location = new System.Drawing.Point(63, 149); + this.dosCodeTxtBox.Name = "dosCodeTxtBox"; + this.dosCodeTxtBox.ReadOnly = true; + this.dosCodeTxtBox.Size = new System.Drawing.Size(217, 20); + this.dosCodeTxtBox.TabIndex = 24; + // + // dosDosErrorLabel + // + this.dosDosErrorLabel.AutoSize = true; + this.dosDosErrorLabel.Location = new System.Drawing.Point(21, 152); + this.dosDosErrorLabel.Name = "dosDosErrorLabel"; + this.dosDosErrorLabel.Size = new System.Drawing.Size(41, 13); + this.dosDosErrorLabel.TabIndex = 20; + this.dosDosErrorLabel.Text = "Win32:"; + // + // dosNumberLabel + // + this.dosNumberLabel.AutoSize = true; + this.dosNumberLabel.Location = new System.Drawing.Point(15, 126); + this.dosNumberLabel.Name = "dosNumberLabel"; + this.dosNumberLabel.Size = new System.Drawing.Size(47, 13); + this.dosNumberLabel.TabIndex = 21; + this.dosNumberLabel.Text = "Number:"; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(162, 38); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(12, 13); + this.label8.TabIndex = 19; + this.label8.Text = "/"; + // + // ntstatusHexTextBox + // + this.ntstatusHexTextBox.Location = new System.Drawing.Point(176, 35); + this.ntstatusHexTextBox.Name = "ntstatusHexTextBox"; + this.ntstatusHexTextBox.ReadOnly = true; + this.ntstatusHexTextBox.Size = new System.Drawing.Size(104, 20); + this.ntstatusHexTextBox.TabIndex = 17; + // + // ntstatusDecimalTextBox + // + this.ntstatusDecimalTextBox.Location = new System.Drawing.Point(63, 35); + this.ntstatusDecimalTextBox.Name = "ntstatusDecimalTextBox"; + this.ntstatusDecimalTextBox.ReadOnly = true; + this.ntstatusDecimalTextBox.Size = new System.Drawing.Size(98, 20); + this.ntstatusDecimalTextBox.TabIndex = 16; + // + // ntstatusCodeTxtBox + // + this.ntstatusCodeTxtBox.Location = new System.Drawing.Point(63, 61); + this.ntstatusCodeTxtBox.Name = "ntstatusCodeTxtBox"; + this.ntstatusCodeTxtBox.ReadOnly = true; + this.ntstatusCodeTxtBox.Size = new System.Drawing.Size(217, 20); + this.ntstatusCodeTxtBox.TabIndex = 18; + // + // ntstatusNtStatusLabel + // + this.ntstatusNtStatusLabel.AutoSize = true; + this.ntstatusNtStatusLabel.Location = new System.Drawing.Point(10, 64); + this.ntstatusNtStatusLabel.Name = "ntstatusNtStatusLabel"; + this.ntstatusNtStatusLabel.Size = new System.Drawing.Size(51, 13); + this.ntstatusNtStatusLabel.TabIndex = 14; + this.ntstatusNtStatusLabel.Text = "NtStatus:"; + // + // ntstatusNumberLabel + // + this.ntstatusNumberLabel.AutoSize = true; + this.ntstatusNumberLabel.Location = new System.Drawing.Point(14, 38); + this.ntstatusNumberLabel.Name = "ntstatusNumberLabel"; + this.ntstatusNumberLabel.Size = new System.Drawing.Size(47, 13); + this.ntstatusNumberLabel.TabIndex = 15; + this.ntstatusNumberLabel.Text = "Number:"; + // // bugurlTab // this.bugurlTab.Controls.Add(this.JiraSummaryLink); @@ -327,6 +488,15 @@ namespace MsgTranslator this.bugurlTab.Text = "JIRA"; this.bugurlTab.UseVisualStyleBackColor = true; // + // JiraSummaryLink + // + this.JiraSummaryLink.AutoSize = true; + this.JiraSummaryLink.Location = new System.Drawing.Point(55, 14); + this.JiraSummaryLink.Name = "JiraSummaryLink"; + this.JiraSummaryLink.Size = new System.Drawing.Size(0, 13); + this.JiraSummaryLink.TabIndex = 18; + this.JiraSummaryLink.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.JiraSummaryLink_LinkClicked); + // // JiraDescriptionTextBox // this.JiraDescriptionTextBox.Location = new System.Drawing.Point(7, 95); @@ -438,6 +608,18 @@ namespace MsgTranslator this.optionsTab.Text = "Options"; this.optionsTab.UseVisualStyleBackColor = true; // + // CopyrightlinkLabel + // + this.CopyrightlinkLabel.AutoSize = true; + this.CopyrightlinkLabel.Cursor = System.Windows.Forms.Cursors.Cross; + this.CopyrightlinkLabel.Location = new System.Drawing.Point(120, 172); + this.CopyrightlinkLabel.Name = "CopyrightlinkLabel"; + this.CopyrightlinkLabel.Size = new System.Drawing.Size(169, 13); + this.CopyrightlinkLabel.TabIndex = 5; + this.CopyrightlinkLabel.TabStop = true; + this.CopyrightlinkLabel.Text = "Copyright 2008-2018 Ged Murphy"; + this.CopyrightlinkLabel.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.CopyrightlinkLabel_LinkClicked); + // // optionsRunStartChkBox // this.optionsRunStartChkBox.AutoSize = true; @@ -489,27 +671,6 @@ namespace MsgTranslator this.toolTip.InitialDelay = 500; this.toolTip.ReshowDelay = 100; // - // JiraSummaryLink - // - this.JiraSummaryLink.AutoSize = true; - this.JiraSummaryLink.Location = new System.Drawing.Point(55, 14); - this.JiraSummaryLink.Name = "JiraSummaryLink"; - this.JiraSummaryLink.Size = new System.Drawing.Size(0, 13); - this.JiraSummaryLink.TabIndex = 18; - this.JiraSummaryLink.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.JiraSummaryLink_LinkClicked); - // - // CopyrightlinkLabel - // - this.CopyrightlinkLabel.AutoSize = true; - this.CopyrightlinkLabel.Cursor = System.Windows.Forms.Cursors.Cross; - this.CopyrightlinkLabel.Location = new System.Drawing.Point(120, 172); - this.CopyrightlinkLabel.Name = "CopyrightlinkLabel"; - this.CopyrightlinkLabel.Size = new System.Drawing.Size(169, 13); - this.CopyrightlinkLabel.TabIndex = 5; - this.CopyrightlinkLabel.TabStop = true; - this.CopyrightlinkLabel.Text = "Copyright 2008-2018 Ged Murphy"; - this.CopyrightlinkLabel.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.CopyrightlinkLabel_LinkClicked); - // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -531,6 +692,8 @@ namespace MsgTranslator this.errorMsgTab.PerformLayout(); this.wndmsgTab.ResumeLayout(false); this.wndmsgTab.PerformLayout(); + this.status2Dos.ResumeLayout(false); + this.status2Dos.PerformLayout(); this.bugurlTab.ResumeLayout(false); this.bugurlTab.PerformLayout(); this.optionsTab.ResumeLayout(false); @@ -586,6 +749,21 @@ namespace MsgTranslator private System.Windows.Forms.Label label3; private System.Windows.Forms.LinkLabel JiraSummaryLink; private System.Windows.Forms.LinkLabel CopyrightlinkLabel; + private System.Windows.Forms.TabPage status2Dos; + private System.Windows.Forms.Label dosCodeInfoLabel; + private System.Windows.Forms.Label ntstatusCodeInfoLabel; + private System.Windows.Forms.Label label11; + private System.Windows.Forms.TextBox dosHexTextBox; + private System.Windows.Forms.TextBox dosDecimalTextBox; + private System.Windows.Forms.TextBox dosCodeTxtBox; + private System.Windows.Forms.Label dosDosErrorLabel; + private System.Windows.Forms.Label dosNumberLabel; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.TextBox ntstatusHexTextBox; + private System.Windows.Forms.TextBox ntstatusDecimalTextBox; + private System.Windows.Forms.TextBox ntstatusCodeTxtBox; + private System.Windows.Forms.Label ntstatusNtStatusLabel; + private System.Windows.Forms.Label ntstatusNumberLabel; } } diff --git a/GUI/MainForm.cs b/GUI/MainForm.cs index 117c21f..3ff6bde 100644 --- a/GUI/MainForm.cs +++ b/GUI/MainForm.cs @@ -13,7 +13,7 @@ namespace MsgTranslator public partial class MainForm : Form { private static string regPath = @"Software\ReactOS\MsgTrans"; - private string[] msgTypes = { "error", "wm", "bug" }; + private string[] msgTypes = { "error", "wm", "ntstat2dos", "bug" }; private List errMessages; private int curErrorPage; @@ -248,9 +248,23 @@ namespace MsgTranslator { if (msgTran.Messages.Count > 1) { - // if we have more than one, they must be error messages - errMessages = msgTran.Messages; - UpdateErrorPage(1); + // check for ntstat2dos + if (msgType == msgTypes[2]) + { + ntstatusDecimalTextBox.Text = msgTran.Messages[0].Number.ToString(); + ntstatusHexTextBox.Text = "0x" + msgTran.Messages[0].Hex; + ntstatusCodeTxtBox.Text = msgTran.Messages[0].Code; + + dosDecimalTextBox.Text = msgTran.Messages[1].Number.ToString(); + dosHexTextBox.Text = "0x" + msgTran.Messages[1].Hex; + dosCodeTxtBox.Text = msgTran.Messages[1].Code; + } + else + { + // if we have more than one, they must be error messages + errMessages = msgTran.Messages; + UpdateErrorPage(1); + } } else { @@ -390,7 +404,7 @@ namespace MsgTranslator { TabControl tc = (TabControl)sender; - if (tc.SelectedIndex == 3) + if (tc.SelectedIndex == 4) { mainErrLabel.Enabled = false; mainErrTxtBox.Enabled = false; @@ -402,14 +416,20 @@ namespace MsgTranslator mainErrTxtBox.Enabled = true; mainLookupButton.Enabled = true; - if (tc.SelectedIndex == 2) + switch (tc.SelectedIndex) { - mainErrLabel.Text = "Issue Num:"; - } - else - { - mainErrLabel.Text = "Message:"; + case 0: + case 1: + mainErrLabel.Text = "Message:"; + break; + case 2: + mainErrLabel.Text = "Status num:"; + break; + case 3: + mainErrLabel.Text = "Issue Num:"; + break; } + } } diff --git a/MsgTrans.Library/Command.cs b/MsgTrans.Library/Command.cs index 231ed2a..5b92b0e 100644 --- a/MsgTrans.Library/Command.cs +++ b/MsgTrans.Library/Command.cs @@ -52,10 +52,10 @@ namespace MsgTrans.Library } protected void AddMessage(MessageType msgType, - long dec, - string hex, - string code, - string msg) + long dec, + string hex, + string code, + string msg) { MsgType = msgType; Number = dec; diff --git a/MsgTrans.Library/MsgTrans.Library.csproj b/MsgTrans.Library/MsgTrans.Library.csproj index d272994..c5253b0 100644 --- a/MsgTrans.Library/MsgTrans.Library.csproj +++ b/MsgTrans.Library/MsgTrans.Library.csproj @@ -65,6 +65,7 @@ + diff --git a/MsgTrans.Library/MsgTrans.cs b/MsgTrans.Library/MsgTrans.cs index 081dbec..14a6a5e 100644 --- a/MsgTrans.Library/MsgTrans.cs +++ b/MsgTrans.Library/MsgTrans.cs @@ -36,6 +36,10 @@ namespace MsgTrans.Library BugUrl = 5, // // Summary: + // NTSTATUS to Win32 code conversion + NtStatusToDos = 5, + // + // Summary: // a custom Check code Custom = 6 } @@ -81,6 +85,7 @@ namespace MsgTrans.Library bugcheckXml)); commands.Add(new WMCommand(this, wmXml)); commands.Add(new BugCommand(this, bugUrl)); + commands.Add(new NtStatusToWin32(this, ntstatusXml, winerrorXml)); } public bool ParseCommandMessage(MessageContext context, diff --git a/MsgTrans.Library/NtStatusCommand.cs b/MsgTrans.Library/NtStatusCommand.cs index c4c169d..ee78307 100644 --- a/MsgTrans.Library/NtStatusCommand.cs +++ b/MsgTrans.Library/NtStatusCommand.cs @@ -26,31 +26,35 @@ namespace MsgTrans.Library return false; } + long dec; + string hex; NumberParser np = new NumberParser(); - if (!np.Parse(ntstatusText)) + if (np.Parse(ntstatusText)) { - return false; + dec = np.Decimal; + hex = np.Hex; } - - string description = GetNtstatusDescription(np.Decimal); + else + { + dec = GetNtStatusNumber(ntstatusText); + if (dec == -1) + { + return false; + } + hex = dec.ToString("X"); + } + + string description = GetNtstatusDescription(dec); if (description != null) { AddMessage(MessageType.NTSTATUS, - np.Decimal, - np.Hex, + dec, + hex, description, null); return true; - }/* - else - { - MsgTrans.MsgOutput.MsgOut(context, - String.Format("I don't know about NTSTATUS {0}.", - ntstatusText)); - - return false; - }*/ + } return false; } @@ -75,5 +79,24 @@ namespace MsgTrans.Library else return null; } + + private long GetNtStatusNumber(string ntstatus) + { + XmlElement root = base.m_XmlDocument.DocumentElement; + XmlNode node = root.SelectSingleNode(String.Format("Ntstatus[@text='{0}']", + ntstatus)); + if (node != null) + { + XmlAttribute value = node.Attributes["value"]; + if (value == null) + throw new Exception("Node has no value attribute."); + + string hex = value.Value; + + return Convert.ToInt64(hex, 16); + } + else + return -1; + } } } diff --git a/MsgTrans.Library/NtStatusToWin32.cs b/MsgTrans.Library/NtStatusToWin32.cs new file mode 100644 index 0000000..911e503 --- /dev/null +++ b/MsgTrans.Library/NtStatusToWin32.cs @@ -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 "; + } + + 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); + } + + */ \ No newline at end of file diff --git a/MsgTrans.Library/WinerrorCommand.cs b/MsgTrans.Library/WinerrorCommand.cs index 9c5bf99..1b00da1 100644 --- a/MsgTrans.Library/WinerrorCommand.cs +++ b/MsgTrans.Library/WinerrorCommand.cs @@ -27,32 +27,37 @@ namespace MsgTrans.Library return false; } + long dec; + string hex; NumberParser np = new NumberParser(); - if (!np.Parse(winerrorText)) + if (np.Parse(winerrorText)) { - return false; + dec = np.Decimal; + hex = np.Hex; } - - string description = GetWinerrorDescription(np.Decimal); + else + { + dec = GetNtStatusNumber(winerrorText); + if (dec == -1) + { + return false; + } + hex = dec.ToString("X"); + } + + string description = GetWinerrorDescription(dec); if (description != null) { - string message = new System.ComponentModel.Win32Exception(Convert.ToInt32(np.Decimal)).Message; + string message = new System.ComponentModel.Win32Exception(Convert.ToInt32(dec)).Message; AddMessage(MessageType.WinError, - np.Decimal, - np.Hex, + dec, + hex, description, message); return true; - }/* - else - { - MsgTrans.MsgOutput.MsgOut(context, - String.Format("I don't know about System Error Code {0}.", - winerrorText)); - return false; - }*/ + } return false; } @@ -77,5 +82,22 @@ namespace MsgTrans.Library else return null; } + + private long GetNtStatusNumber(string winerrorName) + { + XmlElement root = base.m_XmlDocument.DocumentElement; + XmlNode node = root.SelectSingleNode(String.Format("Winerror[@text='{0}']", + winerrorName)); + if (node != null) + { + XmlAttribute value = node.Attributes["value"]; + if (value == null) + throw new Exception("Node has no value attribute."); + + return Convert.ToInt64(value.Value); + } + else + return -1; + } } }