Repository: starofrainnight/winio Branch: master Commit: b095609124b4 Files: 47 Total size: 120.9 KB Directory structure: gitextract_uomszmgh/ ├── .gitignore ├── LICENSE ├── README.md ├── Samples/ │ ├── DumpPhys/ │ │ ├── DumpPhys/ │ │ │ ├── DumpPhys.csproj │ │ │ ├── DumpPhys.manifest │ │ │ ├── Form1.Designer.cs │ │ │ ├── Form1.cs │ │ │ ├── Form1.resx │ │ │ ├── Program.cs │ │ │ └── Properties/ │ │ │ ├── AssemblyInfo.cs │ │ │ ├── Resources.Designer.cs │ │ │ ├── Resources.resx │ │ │ ├── Settings.Designer.cs │ │ │ └── Settings.settings │ │ ├── DumpPhys.sln │ │ └── DumpPhys.suo │ └── DumpPort/ │ ├── DumpPort/ │ │ ├── DumpPort.csproj │ │ ├── DumpPort.manifest │ │ ├── Form1.Designer.cs │ │ ├── Form1.cs │ │ ├── Form1.resx │ │ ├── Program.cs │ │ └── Properties/ │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.resx │ │ ├── Settings.Designer.cs │ │ └── Settings.settings │ ├── DumpPort.sln │ └── DumpPort.suo └── Source/ ├── Dll/ │ ├── InstDrv.cpp │ ├── Phys32.cpp │ ├── Phys32.h │ ├── Port32.cpp │ ├── Port32.h │ ├── WinIo.aps │ ├── WinIo.cpp │ ├── WinIo.def │ ├── WinIo.rc │ ├── WinIo.sln │ ├── WinIo.suo │ ├── WinIo.vcproj │ ├── resource.h │ └── winio.h └── Drv/ ├── MAKEFILE ├── SOURCES ├── WinIo.c └── winio_nt.h ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ # Prerequisites *.d # Compiled Object files *.slo *.lo *.o *.obj # Precompiled Headers *.gch *.pch # Compiled Dynamic libraries *.so *.dylib *.dll # Fortran module files *.mod *.smod # Compiled Static libraries *.lai *.la *.a *.lib # Executables *.exe *.out *.app # Ignore vscode files .vscode ================================================ FILE: LICENSE ================================================ END USER LICENSE AGREEMENT Software License Agreement for WinIo The following terms apply to all files associated with the software unless explicitly disclaimed in individual files. IMPORTANT- PLEASE READ CAREFULLY: BY INSTALLING THE SOFTWARE (AS DEFINED BELOW), OR COPYING THE SOFTWARE, YOU (EITHER ON BEHALF OF YOURSELF AS AN INDIVIDUAL OR ON BEHALF OF AN ENTITY AS ITS AUTHORIZED REPRESENTATIVE) AGREE TO ALL OF THE TERMS OF THIS END USER LICENSE AGREEMENT ("AGREEMENT") REGARDING YOUR USE OF THE SOFTWARE. IF YOU DO NOT AGREE WITH ALL OF THE TERMS OF THIS AGREEMENT, DO NOT INSTALL, COPY OR OTHERWISE USE THE SOFTWARE. 1. GRANT OF LICENSE: Subject to the terms below, Yariv Kaplan ("AUTHOR") hereby grants you a non-exclusive, non-transferable, non-assignable license to install and to use the downloadable version of WinIo ("SOFTWARE"). a. Redistributable Code. You may reproduce and distribute the object code form of the SOFTWARE solely in conjunction with, and as part of, your application ("Permitted Application"); provided that you comply with the following: If you redistribute any portion of the Redistributable Code, you agree that: (i) you will only distribute the Redistributable Code in conjunction with, and as part of, your Permitted Application which adds significant functionality to the Redistributable Code and that distribution of the Permitted Application does not compete with the AUTHOR's distribution of the SOFTWARE; (ii) you will include a valid copyright notice on your Permitted Application; (iii) you will not permit further redistribution of the Redistributable Code; (iv) you will indemnify, hold harmless, and defend the AUTHOR from and against any claims or lawsuits, including attorneys' fees, that arise or result from the use or distribution of your Permitted Application. b. License to use Source Code. You may not sell, lease, rent, transfer or sublicense the source code of this SOFTWARE. 2. MODIFICATION: SOFTWARE Source Code may be modified without the prior written permission of the AUTHOR. Any modifications made to the SOFTWARE will continue to be subject to the terms and conditions of this AGREEMENT. 3. COPYRIGHT: All rights, title, and copyrights in and to the SOFTWARE and any copies of the SOFTWARE are owned by the AUTHOR. The SOFTWARE is protected by copyright laws and international treaty provisions. Therefore, you must treat the SOFTWARE like any other copyrighted material. 4. TITLE: You acknowledge that no title to the intellectual property in the SOFTWARE is transferred to you. Title, ownership, rights, and intellectual property rights in and to the SOFTWARE shall remain the exclusive property of the AUTHOR. The SOFTWARE is protected by copyright laws of the United States and international treaties. 5. LIMITATION OF LIABILITY: You must assume the entire risk of using the SOFTWARE. IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHOR HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. ================================================ FILE: README.md ================================================ # WinIo The WinIo library allows 32-bit and 64-bit Windows applications to directly access I/O ports and physical memory. ## Copyright This library was written by Yariv Kaplan, which could be download from www.internals.com. **WARNING!** This library is strictly copyrighted! All rights are claimed belongs to Yariv Kaplan (even the codes you modified). You must read the LICENESE of WinIo library carefully if you want to use this library (neither generated binaries or source code). ## Why have this repository? Because www.internals.com is down latest, I couldn't download it, so fork this useful library for backup purpose. The tag 2.0 is the version that supported win9X. Lastest viewable content from www.internals.com could be access from [archive.org](http://web.archive.org/web/20160410042019/http://www.internals.com/) . ## Redistributable Files The redistributable files are provided in the \binaries directory (WinIo32.dll, WinIo32.sys and WinIo64.dll) and should be included in the installation package for your application. The WinIo64.sys file must be replaced with a version that is signed with a public code signing certificate (see below). The WinIo files must be placed in the same directory as your application's executable file. ## Privilege Requirements WinIo requires administrative privileges to run properly. This can be achieved by: - Using WinIo from a service running as LocalSystem (SE_LOAD_DRIVER_NAME privilege must be explicitly enabled). - Embedding a manifest file in the application that requests privilege elevation. - Requiring the user to choose the "Run as Administrator" option when launching the application. The included C# samples demonstrate using an embedded manifest file to request privilege elevation. ## Driver Signing Requirements on 64-bit Systems 64-bit versions of Windows only load device drivers that are signed by a code signing certificate issued by a public CA such as Verisign, Thawte, etc. WinIo64.sys must not be deployed on production machines unless a code signing certificate is obtained and used to sign this file. The bundled copy of WinIo64.sys is signed with a self-signed certificate and can only be used on development/test machines with Windows running in a special "test" mode. In order to use the bundled version of WinIo64.sys, you need to take the following steps: - Open an elevated command window by right-clicking the icon and clicking "Run as Administrator". - Type the following command to enable test-signing: bcdedit.exe /set TESTSIGNING ON - Reboot the machine For more information on Windows driver signing requirements, please refer to http://www.microsoft.com/whdc/winlogo/drvsign/kmcs_walkthrough.mspx. ## More Help If you want any further advance help information, just read the WinIo.chm which bundled with released WinIo.zip . ================================================ FILE: Samples/DumpPhys/DumpPhys/DumpPhys.csproj ================================================  Debug AnyCPU 9.0.21022 2.0 {1103585F-D85D-4599-8858-C0D3E9D7419F} WinExe Properties DumpPhys DumpPhys 2.0 publish\ true Disk false Foreground 7 Days false false true 0 1.0.0.%2a false false true DumpPhys.manifest true full false bin\Debug\ DEBUG;TRACE prompt 4 true pdbonly true bin\Release\ TRACE prompt 4 true true bin\x86\Debug\ DEBUG;TRACE true full x86 prompt bin\x86\Release\ TRACE true true pdbonly x86 prompt Form Form1.cs Designer Form1.cs ResXFileCodeGenerator Resources.Designer.cs Designer True Resources.resx True SettingsSingleFileGenerator Settings.Designer.cs True Settings.settings True False .NET Framework 2.0 %28x86%29 true False .NET Framework 3.0 %28x86%29 false False .NET Framework 3.5 false ================================================ FILE: Samples/DumpPhys/DumpPhys/DumpPhys.manifest ================================================ ================================================ FILE: Samples/DumpPhys/DumpPhys/Form1.Designer.cs ================================================ namespace DumpPhys { partial class Form1 { /// /// Required designer variable. /// private System.ComponentModel.IContainer components = null; /// /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.btnGetValue = new System.Windows.Forms.Button(); this.btnSetValue = new System.Windows.Forms.Button(); this.btnQuit = new System.Windows.Forms.Button(); this.txtPhysAddr = new System.Windows.Forms.TextBox(); this.txtValue = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(30, 138); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(176, 13); this.label1.TabIndex = 0; this.label1.Text = "Please enter physical address (hex):"; // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(30, 167); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(63, 13); this.label2.TabIndex = 1; this.label2.Text = "Value (hex):"; // // btnGetValue // this.btnGetValue.Location = new System.Drawing.Point(32, 231); this.btnGetValue.Name = "btnGetValue"; this.btnGetValue.Size = new System.Drawing.Size(75, 23); this.btnGetValue.TabIndex = 2; this.btnGetValue.Text = "Get Value"; this.btnGetValue.UseVisualStyleBackColor = true; this.btnGetValue.Click += new System.EventHandler(this.btnGetValue_Click); // // btnSetValue // this.btnSetValue.Location = new System.Drawing.Point(138, 231); this.btnSetValue.Name = "btnSetValue"; this.btnSetValue.Size = new System.Drawing.Size(75, 23); this.btnSetValue.TabIndex = 3; this.btnSetValue.Text = "Set Value"; this.btnSetValue.UseVisualStyleBackColor = true; this.btnSetValue.Click += new System.EventHandler(this.btnSetValue_Click); // // btnQuit // this.btnQuit.Location = new System.Drawing.Point(244, 231); this.btnQuit.Name = "btnQuit"; this.btnQuit.Size = new System.Drawing.Size(75, 23); this.btnQuit.TabIndex = 4; this.btnQuit.Text = "Quit"; this.btnQuit.UseVisualStyleBackColor = true; this.btnQuit.Click += new System.EventHandler(this.btnQuit_Click); // // txtPhysAddr // this.txtPhysAddr.Location = new System.Drawing.Point(212, 135); this.txtPhysAddr.Name = "txtPhysAddr"; this.txtPhysAddr.Size = new System.Drawing.Size(108, 20); this.txtPhysAddr.TabIndex = 5; // // txtValue // this.txtValue.Location = new System.Drawing.Point(99, 164); this.txtValue.MaxLength = 8; this.txtValue.Name = "txtValue"; this.txtValue.Size = new System.Drawing.Size(59, 20); this.txtValue.TabIndex = 6; // // label3 // this.label3.AutoSize = true; this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 26.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label3.Location = new System.Drawing.Point(81, 22); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(188, 39); this.label3.TabIndex = 7; this.label3.Text = "DumpPhys"; // // label4 // this.label4.AutoSize = true; this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label4.Location = new System.Drawing.Point(63, 73); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(225, 16); this.label4.TabIndex = 8; this.label4.Text = "Copyright 1998-2010 by Yariv Kaplan"; // // label5 // this.label5.AutoSize = true; this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label5.Location = new System.Drawing.Point(117, 102); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(117, 16); this.label5.TabIndex = 9; this.label5.Text = "www.internals.com"; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(350, 272); this.ControlBox = false; this.Controls.Add(this.label5); this.Controls.Add(this.label4); this.Controls.Add(this.label3); this.Controls.Add(this.txtValue); this.Controls.Add(this.txtPhysAddr); this.Controls.Add(this.btnQuit); this.Controls.Add(this.btnSetValue); this.Controls.Add(this.btnGetValue); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Name = "Form1"; this.Text = "DumpPhys - www.internals.com"; this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Button btnGetValue; private System.Windows.Forms.Button btnSetValue; private System.Windows.Forms.Button btnQuit; private System.Windows.Forms.TextBox txtPhysAddr; private System.Windows.Forms.TextBox txtValue; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label5; } } ================================================ FILE: Samples/DumpPhys/DumpPhys/Form1.cs ================================================ // ---------------------------------------------------- // // WinIo v3.0 // // Direct Hardware Access Under Windows // // Copyright 1998-2010 Yariv Kaplan // // http://www.internals.com // // ---------------------------------------------------- // using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Diagnostics; namespace DumpPhys { public unsafe partial class Form1 : Form { [DllImport("kernel32.dll")] private extern static IntPtr LoadLibrary(String DllName); [DllImport("kernel32.dll")] private extern static IntPtr GetProcAddress(IntPtr hModule, String ProcName); [DllImport("kernel32")] private extern static bool FreeLibrary(IntPtr hModule); [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate bool InitializeWinIoType(); [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate bool GetPhysLongType(IntPtr PhysAddr, UInt32 *pPhysVal); [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate bool SetPhysLongType(IntPtr PhysAddr, UInt32 PhysVal); [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate bool ShutdownWinIoType(); IntPtr hMod; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // Check if this is a 32 bit or 64 bit system if (IntPtr.Size == 4) { hMod = LoadLibrary("WinIo32.dll"); txtPhysAddr.MaxLength = 8; txtPhysAddr.Text = "00000000"; } else if (IntPtr.Size == 8) { hMod = LoadLibrary("WinIo64.dll"); txtPhysAddr.MaxLength = 16; txtPhysAddr.Text = "0000000000000000"; } if (hMod == IntPtr.Zero) { MessageBox.Show("Can't find WinIo dll.\nMake sure the WinIo library files are located in the same directory as your executable file.", "DumpPhys", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } IntPtr pFunc = GetProcAddress(hMod, "InitializeWinIo"); if (pFunc != IntPtr.Zero) { InitializeWinIoType InitializeWinIo = (InitializeWinIoType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(InitializeWinIoType)); bool Result = InitializeWinIo(); if (!Result) { MessageBox.Show("Error returned from InitializeWinIo.\nMake sure you are running with administrative privileges and that the WinIo library files are located in the same directory as your executable file.", "DumpPhys", MessageBoxButtons.OK, MessageBoxIcon.Error); FreeLibrary(hMod); this.Close(); } } btnGetValue_Click(this, null); } private void btnGetValue_Click(object sender, EventArgs e) { IntPtr pFunc = GetProcAddress(hMod, "GetPhysLong"); if (pFunc != IntPtr.Zero) { UInt32 PhysVal; UInt64 PhysAddr64; PhysAddr64 = UInt64.Parse(txtPhysAddr.Text, System.Globalization.NumberStyles.HexNumber); GetPhysLongType GetPhysLong = (GetPhysLongType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(GetPhysLongType)); // Call WinIo to get value bool Result = GetPhysLong((IntPtr)PhysAddr64, &PhysVal); if (Result) { txtValue.Text = PhysVal.ToString("X"); } else { MessageBox.Show("Error returned from GetPhysLong", "DumpPhys", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } private void btnQuit_Click(object sender, EventArgs e) { IntPtr pFunc = GetProcAddress(hMod, "ShutdownWinIo"); if (pFunc != IntPtr.Zero) { ShutdownWinIoType ShutdownWinIo = (ShutdownWinIoType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(ShutdownWinIoType)); ShutdownWinIo(); FreeLibrary(hMod); } this.Close(); } private void btnSetValue_Click(object sender, EventArgs e) { IntPtr pFunc = GetProcAddress(hMod, "SetPhysLong"); if (pFunc != IntPtr.Zero) { UInt32 PhysVal; UInt64 PhysAddr64; PhysAddr64 = UInt64.Parse(txtPhysAddr.Text, System.Globalization.NumberStyles.HexNumber); PhysVal = UInt32.Parse(txtValue.Text, System.Globalization.NumberStyles.HexNumber); SetPhysLongType SetPhysLong = (SetPhysLongType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(SetPhysLongType)); // Call WinIo to set value bool Result = SetPhysLong((IntPtr)PhysAddr64, PhysVal); if (!Result) { MessageBox.Show("Error returned from SetPhysLong", "DumpPhys", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } ================================================ FILE: Samples/DumpPhys/DumpPhys/Form1.resx ================================================ text/microsoft-resx 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ================================================ FILE: Samples/DumpPhys/DumpPhys/Program.cs ================================================ using System; using System.Collections.Generic; using System.Windows.Forms; namespace DumpPhys { static class Program { /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } } ================================================ FILE: Samples/DumpPhys/DumpPhys/Properties/AssemblyInfo.cs ================================================ using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("DumpPhys")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("www.internals.com")] [assembly: AssemblyProduct("DumpPhys")] [assembly: AssemblyCopyright("Copyright © Yariv Kaplan 2010")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("16fd1afb-d769-4e14-89ba-eef3670c272b")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] ================================================ FILE: Samples/DumpPhys/DumpPhys/Properties/Resources.Designer.cs ================================================ //------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:2.0.50727.4927 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // //------------------------------------------------------------------------------ namespace DumpPhys.Properties { using System; /// /// A strongly-typed resource class, for looking up localized strings, etc. /// // This class was auto-generated by the StronglyTypedResourceBuilder // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { private static global::System.Resources.ResourceManager resourceMan; private static global::System.Globalization.CultureInfo resourceCulture; [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal Resources() { } /// /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DumpPhys.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } } /// /// Overrides the current thread's CurrentUICulture property for all /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Globalization.CultureInfo Culture { get { return resourceCulture; } set { resourceCulture = value; } } } } ================================================ FILE: Samples/DumpPhys/DumpPhys/Properties/Resources.resx ================================================  text/microsoft-resx 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ================================================ FILE: Samples/DumpPhys/DumpPhys/Properties/Settings.Designer.cs ================================================ //------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:2.0.50727.4927 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // //------------------------------------------------------------------------------ namespace DumpPhys.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); public static Settings Default { get { return defaultInstance; } } } } ================================================ FILE: Samples/DumpPhys/DumpPhys/Properties/Settings.settings ================================================  ================================================ FILE: Samples/DumpPhys/DumpPhys.sln ================================================  Microsoft Visual Studio Solution File, Format Version 10.00 # Visual Studio 2008 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DumpPhys", "DumpPhys\DumpPhys.csproj", "{1103585F-D85D-4599-8858-C0D3E9D7419F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {1103585F-D85D-4599-8858-C0D3E9D7419F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1103585F-D85D-4599-8858-C0D3E9D7419F}.Debug|Any CPU.Build.0 = Debug|Any CPU {1103585F-D85D-4599-8858-C0D3E9D7419F}.Debug|x86.ActiveCfg = Debug|x86 {1103585F-D85D-4599-8858-C0D3E9D7419F}.Debug|x86.Build.0 = Debug|x86 {1103585F-D85D-4599-8858-C0D3E9D7419F}.Release|Any CPU.ActiveCfg = Release|Any CPU {1103585F-D85D-4599-8858-C0D3E9D7419F}.Release|Any CPU.Build.0 = Release|Any CPU {1103585F-D85D-4599-8858-C0D3E9D7419F}.Release|x86.ActiveCfg = Release|x86 {1103585F-D85D-4599-8858-C0D3E9D7419F}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal ================================================ FILE: Samples/DumpPort/DumpPort/DumpPort.csproj ================================================  Debug AnyCPU 9.0.21022 2.0 {8E2C04F3-BDE2-49A4-8736-DE12944D5DDF} WinExe Properties DumpPort DumpPort 2.0 publish\ true Disk false Foreground 7 Days false false true 0 1.0.0.%2a false false true DumpPort.manifest true full false bin\Debug\ DEBUG;TRACE prompt 4 true pdbonly true bin\Release\ TRACE prompt 4 true true bin\x86\Debug\ DEBUG;TRACE true full x86 prompt bin\x86\Release\ TRACE true true pdbonly x86 prompt Form Form1.cs Designer Form1.cs ResXFileCodeGenerator Resources.Designer.cs Designer True Resources.resx True SettingsSingleFileGenerator Settings.Designer.cs True Settings.settings True False .NET Framework 2.0 %28x86%29 true False .NET Framework 3.0 %28x86%29 false False .NET Framework 3.5 false ================================================ FILE: Samples/DumpPort/DumpPort/DumpPort.manifest ================================================ ================================================ FILE: Samples/DumpPort/DumpPort/Form1.Designer.cs ================================================ namespace DumpPort { partial class Form1 { /// /// Required designer variable. /// private System.ComponentModel.IContainer components = null; /// /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.btnGetValue = new System.Windows.Forms.Button(); this.btnSetValue = new System.Windows.Forms.Button(); this.btnQuit = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.txtPortAddr = new System.Windows.Forms.TextBox(); this.txtValue = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // btnGetValue // this.btnGetValue.Location = new System.Drawing.Point(32, 220); this.btnGetValue.Name = "btnGetValue"; this.btnGetValue.Size = new System.Drawing.Size(75, 23); this.btnGetValue.TabIndex = 0; this.btnGetValue.Text = "Get Value"; this.btnGetValue.UseVisualStyleBackColor = true; this.btnGetValue.Click += new System.EventHandler(this.btnGetValue_Click); // // btnSetValue // this.btnSetValue.Location = new System.Drawing.Point(137, 220); this.btnSetValue.Name = "btnSetValue"; this.btnSetValue.Size = new System.Drawing.Size(75, 23); this.btnSetValue.TabIndex = 1; this.btnSetValue.Text = "Set Value"; this.btnSetValue.UseVisualStyleBackColor = true; this.btnSetValue.Click += new System.EventHandler(this.btnSetValue_Click); // // btnQuit // this.btnQuit.Location = new System.Drawing.Point(242, 220); this.btnQuit.Name = "btnQuit"; this.btnQuit.Size = new System.Drawing.Size(75, 23); this.btnQuit.TabIndex = 2; this.btnQuit.Text = "Quit"; this.btnQuit.UseVisualStyleBackColor = true; this.btnQuit.Click += new System.EventHandler(this.btnQuit_Click); // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(44, 140); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(156, 13); this.label1.TabIndex = 3; this.label1.Text = "Please enter port address (hex):"; // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(44, 170); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(63, 13); this.label2.TabIndex = 4; this.label2.Text = "Value (hex):"; // // txtPortAddr // this.txtPortAddr.Location = new System.Drawing.Point(206, 137); this.txtPortAddr.MaxLength = 4; this.txtPortAddr.Name = "txtPortAddr"; this.txtPortAddr.Size = new System.Drawing.Size(36, 20); this.txtPortAddr.TabIndex = 5; this.txtPortAddr.Text = "0"; // // txtValue // this.txtValue.Location = new System.Drawing.Point(113, 167); this.txtValue.MaxLength = 2; this.txtValue.Name = "txtValue"; this.txtValue.Size = new System.Drawing.Size(23, 20); this.txtValue.TabIndex = 6; // // label3 // this.label3.AutoSize = true; this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 26.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label3.Location = new System.Drawing.Point(87, 19); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(174, 39); this.label3.TabIndex = 7; this.label3.Text = "DumpPort"; // // label4 // this.label4.AutoSize = true; this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label4.Location = new System.Drawing.Point(62, 69); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(225, 16); this.label4.TabIndex = 8; this.label4.Text = "Copyright 1998-2010 by Yariv Kaplan"; // // label5 // this.label5.AutoSize = true; this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label5.Location = new System.Drawing.Point(116, 97); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(117, 16); this.label5.TabIndex = 9; this.label5.Text = "www.internals.com"; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(348, 263); this.ControlBox = false; this.Controls.Add(this.label5); this.Controls.Add(this.label4); this.Controls.Add(this.label3); this.Controls.Add(this.txtValue); this.Controls.Add(this.txtPortAddr); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Controls.Add(this.btnQuit); this.Controls.Add(this.btnSetValue); this.Controls.Add(this.btnGetValue); this.Name = "Form1"; this.Text = "DumpPort - www.internals.com"; this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.Button btnGetValue; private System.Windows.Forms.Button btnSetValue; private System.Windows.Forms.Button btnQuit; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox txtPortAddr; private System.Windows.Forms.TextBox txtValue; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label5; } } ================================================ FILE: Samples/DumpPort/DumpPort/Form1.cs ================================================ // ---------------------------------------------------- // // WinIo v3.0 // // Direct Hardware Access Under Windows // // Copyright 1998-2010 Yariv Kaplan // // http://www.internals.com // // ---------------------------------------------------- // using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Diagnostics; namespace DumpPort { public unsafe partial class Form1 : Form { [DllImport("kernel32.dll")] private extern static IntPtr LoadLibrary(String DllName); [DllImport("kernel32.dll")] private extern static IntPtr GetProcAddress(IntPtr hModule, String ProcName); [DllImport("kernel32")] private extern static bool FreeLibrary(IntPtr hModule); [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate bool InitializeWinIoType(); [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate bool GetPortValType(UInt16 PortAddr, UInt32* pPortVal, UInt16 Size); [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate bool SetPortValType(UInt16 PortAddr, UInt32 PortVal, UInt16 Size); [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate bool ShutdownWinIoType(); IntPtr hMod; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // Check if this is a 32 bit or 64 bit system if (IntPtr.Size == 4) { hMod = LoadLibrary("WinIo32.dll"); } else if (IntPtr.Size == 8) { hMod = LoadLibrary("WinIo64.dll"); } if (hMod == IntPtr.Zero) { MessageBox.Show("Can't find WinIo dll.\nMake sure the WinIo library files are located in the same directory as your executable file.", "DumpPort", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } IntPtr pFunc = GetProcAddress(hMod, "InitializeWinIo"); if (pFunc != IntPtr.Zero) { InitializeWinIoType InitializeWinIo = (InitializeWinIoType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(InitializeWinIoType)); bool Result = InitializeWinIo(); if (!Result) { MessageBox.Show("Error returned from InitializeWinIo.\nMake sure you are running with administrative privileges and that the WinIo library files are located in the same directory as your executable file.", "DumpPort", MessageBoxButtons.OK, MessageBoxIcon.Error); FreeLibrary(hMod); this.Close(); } } btnGetValue_Click(this, null); } private void btnQuit_Click(object sender, EventArgs e) { IntPtr pFunc = GetProcAddress(hMod, "ShutdownWinIo"); if (pFunc != IntPtr.Zero) { ShutdownWinIoType ShutdownWinIo = (ShutdownWinIoType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(ShutdownWinIoType)); ShutdownWinIo(); FreeLibrary(hMod); } this.Close(); } private void btnGetValue_Click(object sender, EventArgs e) { IntPtr pFunc = GetProcAddress(hMod, "GetPortVal"); if (pFunc != IntPtr.Zero) { UInt16 PortAddr; UInt32 PortVal; PortAddr = UInt16.Parse(txtPortAddr.Text, System.Globalization.NumberStyles.HexNumber); GetPortValType GetPortVal = (GetPortValType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(GetPortValType)); // Call WinIo to get value bool Result = GetPortVal(PortAddr, &PortVal, 1); if (Result) { txtValue.Text = PortVal.ToString("X"); } else { MessageBox.Show("Error returned from GetPortVal", "DumpPort", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } private void btnSetValue_Click(object sender, EventArgs e) { IntPtr pFunc = GetProcAddress(hMod, "SetPortVal"); if (pFunc != IntPtr.Zero) { UInt16 PortAddr; UInt32 PortVal; PortAddr = UInt16.Parse(txtPortAddr.Text, System.Globalization.NumberStyles.HexNumber); PortVal = UInt32.Parse(txtValue.Text, System.Globalization.NumberStyles.HexNumber); SetPortValType SetPortVal = (SetPortValType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(SetPortValType)); // Call WinIo to set value bool Result = SetPortVal(PortAddr, PortVal, 1 ); if (!Result) { MessageBox.Show("Error returned from SetPortVal", "DumpPort", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } ================================================ FILE: Samples/DumpPort/DumpPort/Form1.resx ================================================ text/microsoft-resx 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ================================================ FILE: Samples/DumpPort/DumpPort/Program.cs ================================================ using System; using System.Collections.Generic; using System.Windows.Forms; namespace DumpPort { static class Program { /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } } ================================================ FILE: Samples/DumpPort/DumpPort/Properties/AssemblyInfo.cs ================================================ using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("DumpPort")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("www.internals.com")] [assembly: AssemblyProduct("DumpPort")] [assembly: AssemblyCopyright("Copyright © Yariv Kaplan 2010")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("e4aa10c8-3c4e-4ea5-8461-4da84bf602f5")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] ================================================ FILE: Samples/DumpPort/DumpPort/Properties/Resources.Designer.cs ================================================ //------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:2.0.50727.4927 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // //------------------------------------------------------------------------------ namespace DumpPort.Properties { using System; /// /// A strongly-typed resource class, for looking up localized strings, etc. /// // This class was auto-generated by the StronglyTypedResourceBuilder // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { private static global::System.Resources.ResourceManager resourceMan; private static global::System.Globalization.CultureInfo resourceCulture; [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal Resources() { } /// /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DumpPort.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } } /// /// Overrides the current thread's CurrentUICulture property for all /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Globalization.CultureInfo Culture { get { return resourceCulture; } set { resourceCulture = value; } } } } ================================================ FILE: Samples/DumpPort/DumpPort/Properties/Resources.resx ================================================  text/microsoft-resx 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ================================================ FILE: Samples/DumpPort/DumpPort/Properties/Settings.Designer.cs ================================================ //------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:2.0.50727.4927 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // //------------------------------------------------------------------------------ namespace DumpPort.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); public static Settings Default { get { return defaultInstance; } } } } ================================================ FILE: Samples/DumpPort/DumpPort/Properties/Settings.settings ================================================  ================================================ FILE: Samples/DumpPort/DumpPort.sln ================================================  Microsoft Visual Studio Solution File, Format Version 10.00 # Visual Studio 2008 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DumpPort", "DumpPort\DumpPort.csproj", "{8E2C04F3-BDE2-49A4-8736-DE12944D5DDF}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {8E2C04F3-BDE2-49A4-8736-DE12944D5DDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8E2C04F3-BDE2-49A4-8736-DE12944D5DDF}.Debug|Any CPU.Build.0 = Debug|Any CPU {8E2C04F3-BDE2-49A4-8736-DE12944D5DDF}.Debug|x86.ActiveCfg = Debug|x86 {8E2C04F3-BDE2-49A4-8736-DE12944D5DDF}.Debug|x86.Build.0 = Debug|x86 {8E2C04F3-BDE2-49A4-8736-DE12944D5DDF}.Release|Any CPU.ActiveCfg = Release|Any CPU {8E2C04F3-BDE2-49A4-8736-DE12944D5DDF}.Release|Any CPU.Build.0 = Release|Any CPU {8E2C04F3-BDE2-49A4-8736-DE12944D5DDF}.Release|x86.ActiveCfg = Release|x86 {8E2C04F3-BDE2-49A4-8736-DE12944D5DDF}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal ================================================ FILE: Source/Dll/InstDrv.cpp ================================================ // ---------------------------------------------------- // // WinIo v3.0 // // Direct Hardware Access Under Windows // // Copyright 1998-2010 Yariv Kaplan // // http://www.internals.com // // ---------------------------------------------------- // #include #include "winio.h" bool _stdcall InstallWinIoDriver(PWSTR pszWinIoDriverPath, bool IsDemandLoaded) { SC_HANDLE hSCManager; SC_HANDLE hService; // Remove any previous instance of the driver RemoveWinIoDriver(); hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if (hSCManager) { // Install the driver hService = CreateService(hSCManager, L"WINIO", L"WINIO", SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, (IsDemandLoaded == true) ? SERVICE_DEMAND_START : SERVICE_SYSTEM_START, SERVICE_ERROR_NORMAL, pszWinIoDriverPath, NULL, NULL, NULL, NULL, NULL); CloseServiceHandle(hSCManager); if (hService == NULL) return false; } else return false; CloseServiceHandle(hService); return true; } bool _stdcall RemoveWinIoDriver() { SC_HANDLE hSCManager; SC_HANDLE hService; LPQUERY_SERVICE_CONFIG pServiceConfig; DWORD dwBytesNeeded; DWORD cbBufSize; bool bResult; StopWinIoDriver(); hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if (!hSCManager) { return false; } hService = OpenService(hSCManager, L"WINIO", SERVICE_ALL_ACCESS); CloseServiceHandle(hSCManager); if (!hService) { return false; } bResult = QueryServiceConfig(hService, NULL, 0, &dwBytesNeeded); if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { cbBufSize = dwBytesNeeded; pServiceConfig = (LPQUERY_SERVICE_CONFIG)malloc(cbBufSize); bResult = QueryServiceConfig(hService, pServiceConfig, cbBufSize, &dwBytesNeeded); if (!bResult) { free(pServiceConfig); CloseServiceHandle(hService); return bResult; } // If service is set to load automatically, don't delete it! if (pServiceConfig->dwStartType == SERVICE_DEMAND_START) { bResult = DeleteService(hService); } } CloseServiceHandle(hService); return bResult; } bool _stdcall StartWinIoDriver() { SC_HANDLE hSCManager; SC_HANDLE hService; bool bResult; hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if (hSCManager) { hService = OpenService(hSCManager, L"WINIO", SERVICE_ALL_ACCESS); CloseServiceHandle(hSCManager); if (hService) { bResult = StartService(hService, 0, NULL) || GetLastError() == ERROR_SERVICE_ALREADY_RUNNING; CloseServiceHandle(hService); } else return false; } else return false; return bResult; } bool _stdcall StopWinIoDriver() { SC_HANDLE hSCManager; SC_HANDLE hService; SERVICE_STATUS ServiceStatus; bool bResult; hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if (hSCManager) { hService = OpenService(hSCManager, L"WINIO", SERVICE_ALL_ACCESS); CloseServiceHandle(hSCManager); if (hService) { bResult = ControlService(hService, SERVICE_CONTROL_STOP, &ServiceStatus); CloseServiceHandle(hService); } else return false; } else return false; return bResult; } ================================================ FILE: Source/Dll/Phys32.cpp ================================================ // ---------------------------------------------------- // // WinIo v3.0 // // Direct Hardware Access Under Windows // // Copyright 1998-2010 Yariv Kaplan // // http://www.internals.com // // ---------------------------------------------------- // #include #include #include "phys32.h" #include "..\drv\winio_nt.h" #include "winio.h" PBYTE _stdcall MapPhysToLin(tagPhysStruct &PhysStruct) { PBYTE pbLinAddr = NULL; DWORD dwBytesReturned; if (!IsWinIoInitialized) return false; if (!DeviceIoControl(hDriver, IOCTL_WINIO_MAPPHYSTOLIN, &PhysStruct, sizeof(tagPhysStruct), &PhysStruct, sizeof(tagPhysStruct), &dwBytesReturned, NULL)) { return NULL; } return (PBYTE)PhysStruct.pvPhysMemLin; } bool _stdcall UnmapPhysicalMemory(tagPhysStruct &PhysStruct) { DWORD dwBytesReturned; if (!IsWinIoInitialized) { return false; } if (!DeviceIoControl(hDriver, IOCTL_WINIO_UNMAPPHYSADDR, &PhysStruct, sizeof(tagPhysStruct), NULL, 0, &dwBytesReturned, NULL)) { return false; } return true; } // Support functions bool _stdcall GetPhysLong(PBYTE pbPhysAddr, PDWORD pdwPhysVal) { PDWORD pdwLinAddr; tagPhysStruct PhysStruct; if (!IsWinIoInitialized) return false; if (g_Is64BitOS) { PhysStruct.pvPhysAddress = (DWORD64)pbPhysAddr; } else { // Avoid sign extension issues PhysStruct.pvPhysAddress = (DWORD64)(DWORD32)pbPhysAddr; } PhysStruct.dwPhysMemSizeInBytes = 4; pdwLinAddr = (PDWORD)MapPhysToLin(PhysStruct); if (pdwLinAddr == NULL) return false; *pdwPhysVal = *pdwLinAddr; UnmapPhysicalMemory(PhysStruct); return true; } bool _stdcall SetPhysLong(PBYTE pbPhysAddr, DWORD dwPhysVal) { PDWORD pdwLinAddr; tagPhysStruct PhysStruct; if (!IsWinIoInitialized) return false; if (g_Is64BitOS) { PhysStruct.pvPhysAddress = (DWORD64)pbPhysAddr; } else { // Avoid sign extension issues PhysStruct.pvPhysAddress = (DWORD64)(DWORD32)pbPhysAddr; } PhysStruct.dwPhysMemSizeInBytes = 4; pdwLinAddr = (PDWORD)MapPhysToLin(PhysStruct); if (pdwLinAddr == NULL) return false; *pdwLinAddr = dwPhysVal; UnmapPhysicalMemory(PhysStruct); return true; } ================================================ FILE: Source/Dll/Phys32.h ================================================ #ifndef PHYS32_H #define PHYS32_H extern DWORD (WINAPI *VxDCall)(DWORD Service, DWORD EAX_Reg, DWORD ECX_Reg); #endif ================================================ FILE: Source/Dll/Port32.cpp ================================================ // ---------------------------------------------------- // // WinIo v3.0 // // Direct Hardware Access Under Windows // // Copyright 1998-2010 Yariv Kaplan // // http://www.internals.com // // ---------------------------------------------------- // #include #include #include #include "port32.h" #include "..\drv\winio_nt.h" #include "winio.h" bool _stdcall GetPortVal(WORD wPortAddr, PDWORD pdwPortVal, BYTE bSize) { if (!IsWinIoInitialized) { return false; } #ifdef _WIN64 tagPortStruct PortStruct; DWORD dwBytesReturned; PortStruct.bSize = bSize; PortStruct.wPortAddr = wPortAddr; return DeviceIoControl(hDriver, IOCTL_WINIO_READPORT, &PortStruct, sizeof(PortStruct), pdwPortVal, sizeof(DWORD), &dwBytesReturned, NULL); #elif _WIN32 // If this is a 64 bit OS, we must use the driver to access I/O ports even if the application is 32 bit if (g_Is64BitOS) { tagPortStruct PortStruct; DWORD dwBytesReturned; PortStruct.bSize = bSize; PortStruct.wPortAddr = wPortAddr; return DeviceIoControl(hDriver, IOCTL_WINIO_READPORT, &PortStruct, sizeof(PortStruct), pdwPortVal, sizeof(DWORD), &dwBytesReturned, NULL); } else { switch (bSize) { case 1: *pdwPortVal = _inp(wPortAddr); break; case 2: *pdwPortVal = _inpw(wPortAddr); break; case 4: *pdwPortVal = _inpd(wPortAddr); break; } } #endif return true; } bool _stdcall SetPortVal(WORD wPortAddr, DWORD dwPortVal, BYTE bSize) { if (!IsWinIoInitialized) { return false; } #ifdef _WIN64 tagPortStruct PortStruct; DWORD dwBytesReturned; PortStruct.bSize = bSize; PortStruct.dwPortVal = dwPortVal; PortStruct.wPortAddr = wPortAddr; return DeviceIoControl(hDriver, IOCTL_WINIO_WRITEPORT, &PortStruct, sizeof(PortStruct), NULL, 0, &dwBytesReturned, NULL); #elif _WIN32 // If this is a 64 bit OS, we must use the driver to access I/O ports even if the application is 32 bit if (g_Is64BitOS) { tagPortStruct PortStruct; DWORD dwBytesReturned; PortStruct.bSize = bSize; PortStruct.dwPortVal = dwPortVal; PortStruct.wPortAddr = wPortAddr; return DeviceIoControl(hDriver, IOCTL_WINIO_WRITEPORT, &PortStruct, sizeof(PortStruct), NULL, 0, &dwBytesReturned, NULL); } else { switch (bSize) { case 1: _outp(wPortAddr, dwPortVal); break; case 2: _outpw(wPortAddr, (WORD)dwPortVal); break; case 4: _outpd(wPortAddr, dwPortVal); break; } } #endif return true; } ================================================ FILE: Source/Dll/Port32.h ================================================ #ifndef PORT32_H #define PORT32_H #pragma pack(1) struct GDT_DESCRIPTOR { WORD Limit_0_15; WORD Base_0_15; BYTE Base_16_23; BYTE Type : 4; BYTE System : 1; BYTE DPL : 2; BYTE Present : 1; BYTE Limit_16_19 : 4; BYTE Available : 1; BYTE Reserved : 1; BYTE D_B : 1; BYTE Granularity : 1; BYTE Base_24_31; }; struct CALLGATE_DESCRIPTOR { WORD Offset_0_15; WORD Selector; WORD ParamCount : 5; WORD Unused : 3; WORD Type : 4; WORD System : 1; WORD DPL : 2; WORD Present : 1; WORD Offset_16_31; }; struct GDTR { WORD wGDTLimit; DWORD dwGDTBase; }; #pragma pack() #endif ================================================ FILE: Source/Dll/WinIo.cpp ================================================ // ---------------------------------------------------- // // WinIo v3.0 // // Direct Hardware Access Under Windows // // Copyright 1998-2010 Yariv Kaplan // // http://www.internals.com // // ---------------------------------------------------- // #define _WIN32_WINNT 0x0501 #include #include #include "phys32.h" #include "..\drv\winio_nt.h" #include "winio.h" HANDLE hDriver = INVALID_HANDLE_VALUE; bool IsWinIoInitialized = false; wchar_t szWinIoDriverPath[32768]; bool g_Is64BitOS; typedef UINT (WINAPI* GETSYSTEMWOW64DIRECTORY)(LPTSTR, UINT); BOOL Is64BitOS() { #ifdef _WIN64 return TRUE; #else GETSYSTEMWOW64DIRECTORY getSystemWow64Directory; HMODULE hKernel32; TCHAR Wow64Directory[32767]; hKernel32 = GetModuleHandle(TEXT("kernel32.dll")); if (hKernel32 == NULL) { // // This shouldn't happen, but if we can't get // kernel32's module handle then assume we are // on x86. We won't ever install 32-bit drivers // on 64-bit machines, we just want to catch it // up front to give users a better error message. // return FALSE; } getSystemWow64Directory = (GETSYSTEMWOW64DIRECTORY)GetProcAddress(hKernel32, "GetSystemWow64DirectoryW"); if (getSystemWow64Directory == NULL) { // // This most likely means we are running // on Windows 2000, which didn't have this API // and didn't have a 64-bit counterpart. // return FALSE; } if ((getSystemWow64Directory(Wow64Directory, _countof(Wow64Directory)) == 0) && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) { return FALSE; } // // GetSystemWow64Directory succeeded // so we are on a 64-bit OS. // return TRUE; #endif } bool GetDriverPath() { PWSTR pszSlash; if (!GetModuleFileName(GetModuleHandle(NULL), szWinIoDriverPath, sizeof(szWinIoDriverPath))) return false; pszSlash = wcsrchr(szWinIoDriverPath, '\\'); if (pszSlash) pszSlash[1] = 0; else return false; if (g_Is64BitOS) wcscat(szWinIoDriverPath, L"winio64.sys"); else wcscat(szWinIoDriverPath, L"winio32.sys"); return true; } bool __stdcall InitializeWinIo() { bool bResult; DWORD dwBytesReturned; g_Is64BitOS = Is64BitOS(); hDriver = CreateFile(L"\\\\.\\WINIO", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); // If the driver is not running, install it if (hDriver == INVALID_HANDLE_VALUE) { GetDriverPath(); bResult = InstallWinIoDriver(szWinIoDriverPath, true); if (!bResult) return false; bResult = StartWinIoDriver(); if (!bResult) return false; hDriver = CreateFile(L"\\\\.\\WINIO", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hDriver == INVALID_HANDLE_VALUE) return false; } // Enable I/O port access for this process if running on a 32 bit OS if (!g_Is64BitOS) { if (!DeviceIoControl(hDriver, IOCTL_WINIO_ENABLEDIRECTIO, NULL, 0, NULL, 0, &dwBytesReturned, NULL)) { return false; } } IsWinIoInitialized = true; return true; } void _stdcall ShutdownWinIo() { DWORD dwBytesReturned; if (hDriver != INVALID_HANDLE_VALUE) { // Disable I/O port access if running on a 32 bit OS if (!g_Is64BitOS) { DeviceIoControl(hDriver, IOCTL_WINIO_DISABLEDIRECTIO, NULL, 0, NULL, 0, &dwBytesReturned, NULL); } CloseHandle(hDriver); } RemoveWinIoDriver(); IsWinIoInitialized = false; } ================================================ FILE: Source/Dll/WinIo.def ================================================ EXPORTS InitializeWinIo ShutdownWinIo MapPhysToLin UnmapPhysicalMemory GetPhysLong SetPhysLong GetPortVal SetPortVal InstallWinIoDriver RemoveWinIoDriver ================================================ FILE: Source/Dll/WinIo.rc ================================================ // Microsoft Visual C++ generated resource script. // #include "resource.h" #define APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // // Generated from the TEXTINCLUDE 2 resource. // #include "afxres.h" ///////////////////////////////////////////////////////////////////////////// #undef APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // English (U.S.) resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) #ifdef _WIN32 LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US #pragma code_page(1252) #endif //_WIN32 ///////////////////////////////////////////////////////////////////////////// // // Version // VS_VERSION_INFO VERSIONINFO FILEVERSION 3,0,0,0 PRODUCTVERSION 3,0,0,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x29L #else FILEFLAGS 0x28L #endif FILEOS 0x40004L FILETYPE 0x2L FILESUBTYPE 0x0L BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "040904b0" BEGIN VALUE "Comments", " " VALUE "CompanyName", "www.internals.com" VALUE "FileDescription", "WinIo" VALUE "FileVersion", "3.0" VALUE "InternalName", "WinIo" VALUE "LegalCopyright", "Copyright 1998-2010, Yariv Kaplan" VALUE "LegalTrademarks", " " VALUE "OriginalFilename", "WinIo.dll" VALUE "PrivateBuild", " " VALUE "ProductName", "WinIo" VALUE "ProductVersion", "3.0" VALUE "SpecialBuild", " " END END BLOCK "VarFileInfo" BEGIN VALUE "Translation", 0x409, 1200 END END #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // TEXTINCLUDE // 1 TEXTINCLUDE BEGIN "resource.h\0" END 2 TEXTINCLUDE BEGIN "#include ""afxres.h""\r\n" "\0" END 3 TEXTINCLUDE BEGIN "\r\n" "\0" END #endif // APSTUDIO_INVOKED #endif // English (U.S.) resources ///////////////////////////////////////////////////////////////////////////// #ifndef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // Generated from the TEXTINCLUDE 3 resource. // ///////////////////////////////////////////////////////////////////////////// #endif // not APSTUDIO_INVOKED ================================================ FILE: Source/Dll/WinIo.sln ================================================  Microsoft Visual Studio Solution File, Format Version 10.00 # Visual Studio 2008 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WinIo", "WinIo.vcproj", "{DE9A75D4-D640-41B8-893B-A384FAF00738}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 Debug|x64 = Debug|x64 Release|Win32 = Release|Win32 Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {DE9A75D4-D640-41B8-893B-A384FAF00738}.Debug|Win32.ActiveCfg = Debug|Win32 {DE9A75D4-D640-41B8-893B-A384FAF00738}.Debug|Win32.Build.0 = Debug|Win32 {DE9A75D4-D640-41B8-893B-A384FAF00738}.Debug|x64.ActiveCfg = Debug|x64 {DE9A75D4-D640-41B8-893B-A384FAF00738}.Debug|x64.Build.0 = Debug|x64 {DE9A75D4-D640-41B8-893B-A384FAF00738}.Release|Win32.ActiveCfg = Release|Win32 {DE9A75D4-D640-41B8-893B-A384FAF00738}.Release|Win32.Build.0 = Release|Win32 {DE9A75D4-D640-41B8-893B-A384FAF00738}.Release|x64.ActiveCfg = Release|x64 {DE9A75D4-D640-41B8-893B-A384FAF00738}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal ================================================ FILE: Source/Dll/WinIo.vcproj ================================================ ================================================ FILE: Source/Dll/resource.h ================================================ //{{NO_DEPENDENCIES}} // Microsoft Developer Studio generated include file. // Used by WinIo.rc // // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 101 #define _APS_NEXT_COMMAND_VALUE 40001 #define _APS_NEXT_CONTROL_VALUE 1000 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif ================================================ FILE: Source/Dll/winio.h ================================================ #ifndef WINIO_H #define WINIO_H #include "..\drv\winio_nt.h" #ifndef WINIO_DLL #define WINIO_API _declspec(dllimport) #else #define WINIO_API #endif extern "C" { WINIO_API bool _stdcall InitializeWinIo(); WINIO_API void _stdcall ShutdownWinIo(); WINIO_API PBYTE _stdcall MapPhysToLin(tagPhysStruct &PhysStruct); WINIO_API bool _stdcall UnmapPhysicalMemory(tagPhysStruct &PhysStruct); WINIO_API bool _stdcall GetPhysLong(PBYTE pbPhysAddr, PDWORD pdwPhysVal); WINIO_API bool _stdcall SetPhysLong(PBYTE pbPhysAddr, DWORD dwPhysVal); WINIO_API bool _stdcall GetPortVal(WORD wPortAddr, PDWORD pdwPortVal, BYTE bSize); WINIO_API bool _stdcall SetPortVal(WORD wPortAddr, DWORD dwPortVal, BYTE bSize); WINIO_API bool _stdcall InstallWinIoDriver(PWSTR pszWinIoDriverPath, bool IsDemandLoaded = false); WINIO_API bool _stdcall RemoveWinIoDriver(); } extern HANDLE hDriver; extern bool IsWinIoInitialized; extern bool g_Is64BitOS; bool _stdcall StartWinIoDriver(); bool _stdcall StopWinIoDriver(); #endif ================================================ FILE: Source/Drv/MAKEFILE ================================================ # # DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source # file to this component. This file merely indirects to the real make file # that is shared by all the driver components of the Windows NT DDK # !INCLUDE $(NTMAKEENV)\makefile.def ================================================ FILE: Source/Drv/SOURCES ================================================ TARGETNAME=WinIo TARGETPATH=. TARGETTYPE=DRIVER NTDEBUG=ntsd SOURCES= winio.c ================================================ FILE: Source/Drv/WinIo.c ================================================ // ---------------------------------------------------- // // WinIo v3.0 // // Direct Hardware Access for Windows // // Copyright 1998-2010 Yariv Kaplan // // http://www.internals.com // // ---------------------------------------------------- // #include #include "winio_nt.h" #define IOPM_SIZE 0x2000 typedef char IOPM[IOPM_SIZE]; // Function definition section // ----------------------------------------------------------------- NTSTATUS WinIoDispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp); void WinIoUnload(IN PDRIVER_OBJECT DriverObject); NTSTATUS UnmapPhysicalMemory(HANDLE PhysicalMemoryHandle, PVOID pPhysMemLin, PVOID PhysSection); NTSTATUS MapPhysicalMemoryToLinearSpace(PVOID pPhysAddress, SIZE_T PhysMemSizeInBytes, PVOID *ppPhysMemLin, HANDLE *pPhysicalMemoryHandle, PVOID *ppPhysSection); #ifndef AMD64 void Ke386SetIoAccessMap(int, IOPM *); void Ke386QueryIoAccessMap(int, IOPM *); void Ke386IoSetAccessProcess(PEPROCESS, int); #endif // ----------------------------------------------------------------- // Installable driver initialization entry point. // This entry point is called directly by the I/O system. NTSTATUS DriverEntry (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath) { UNICODE_STRING DeviceNameUnicodeString; UNICODE_STRING DeviceLinkUnicodeString; NTSTATUS ntStatus; PDEVICE_OBJECT DeviceObject = NULL; KdPrint(("Entering DriverEntry")); RtlInitUnicodeString (&DeviceNameUnicodeString, L"\\Device\\WinIo"); // Create a device object ntStatus = IoCreateDevice (DriverObject, 0, &DeviceNameUnicodeString, FILE_DEVICE_WINIO, 0, FALSE, &DeviceObject); if (NT_SUCCESS(ntStatus)) { // Create dispatch points for device control, create, close. DriverObject->MajorFunction[IRP_MJ_CREATE] = DriverObject->MajorFunction[IRP_MJ_CLOSE] = DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = WinIoDispatch; DriverObject->DriverUnload = WinIoUnload; // Create a symbolic link, e.g. a name that a Win32 app can specify // to open the device. RtlInitUnicodeString (&DeviceLinkUnicodeString, L"\\DosDevices\\WinIo"); ntStatus = IoCreateSymbolicLink (&DeviceLinkUnicodeString, &DeviceNameUnicodeString); if (!NT_SUCCESS(ntStatus)) { // Symbolic link creation failed- note this & then delete the // device object (it's useless if a Win32 app can't get at it). KdPrint(("ERROR: IoCreateSymbolicLink failed")); IoDeleteDevice (DeviceObject); } } else { KdPrint(("ERROR: IoCreateDevice failed")); } KdPrint(("Leaving DriverEntry")); return ntStatus; } // Process the IRPs sent to this device NTSTATUS WinIoDispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) { PIO_STACK_LOCATION IrpStack; ULONG dwInputBufferLength; ULONG dwOutputBufferLength; ULONG dwIoControlCode; PVOID pvIOBuffer; NTSTATUS ntStatus; IOPM* pIOPM = NULL; struct tagPhysStruct PhysStruct; struct tagPortStruct PortStruct; struct tagPhysStruct32 *pPhysStruct32 = NULL; KdPrint(("Entering WinIoDispatch")); // Init to default settings Irp->IoStatus.Status = STATUS_SUCCESS; Irp->IoStatus.Information = 0; IrpStack = IoGetCurrentIrpStackLocation(Irp); // Get the pointer to the input/output buffer and it's length pvIOBuffer = Irp->AssociatedIrp.SystemBuffer; dwInputBufferLength = IrpStack->Parameters.DeviceIoControl.InputBufferLength; dwOutputBufferLength = IrpStack->Parameters.DeviceIoControl.OutputBufferLength; switch (IrpStack->MajorFunction) { case IRP_MJ_CREATE: KdPrint(("IRP_MJ_CREATE")); break; case IRP_MJ_CLOSE: KdPrint(("IRP_MJ_CLOSE")); break; case IRP_MJ_DEVICE_CONTROL: KdPrint(("IRP_MJ_DEVICE_CONTROL")); dwIoControlCode = IrpStack->Parameters.DeviceIoControl.IoControlCode; switch (dwIoControlCode) { // The Ke386 calls are no longer available on x64 Windows #ifndef AMD64 case IOCTL_WINIO_ENABLEDIRECTIO: KdPrint(("IOCTL_WINIO_ENABLEDIRECTIO")); pIOPM = MmAllocateNonCachedMemory(sizeof(IOPM)); if (pIOPM) { RtlZeroMemory(pIOPM, sizeof(IOPM)); Ke386IoSetAccessProcess(PsGetCurrentProcess(), 1); Ke386SetIoAccessMap(1, pIOPM); IrpStack->FileObject->FsContext2 = pIOPM; } else Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES; break; case IOCTL_WINIO_DISABLEDIRECTIO: KdPrint(("IOCTL_WINIO_DISABLEDIRECTIO")); pIOPM = (IOPM *)IrpStack->FileObject->FsContext2; if (pIOPM) { Ke386IoSetAccessProcess(PsGetCurrentProcess(), 0); Ke386SetIoAccessMap(1, pIOPM); MmFreeNonCachedMemory(pIOPM, sizeof(IOPM)); } break; #endif case IOCTL_WINIO_WRITEPORT: KdPrint(("IOCTL_WINIO_WRITEPORT")); if (dwInputBufferLength) { memcpy (&PortStruct, pvIOBuffer, dwInputBufferLength); switch (PortStruct.bSize) { case 1: WRITE_PORT_UCHAR((PUCHAR)(USHORT)PortStruct.wPortAddr, (UCHAR)PortStruct.dwPortVal); break; case 2: WRITE_PORT_USHORT((PUSHORT)(USHORT)PortStruct.wPortAddr, (USHORT)PortStruct.dwPortVal); break; case 4: WRITE_PORT_ULONG((PULONG)(USHORT)PortStruct.wPortAddr, PortStruct.dwPortVal); break; } } else Irp->IoStatus.Status = STATUS_INVALID_PARAMETER; break; case IOCTL_WINIO_READPORT: KdPrint(("IOCTL_WINIO_READPORT")); if (dwInputBufferLength) { memcpy (&PortStruct, pvIOBuffer, dwInputBufferLength); switch (PortStruct.bSize) { case 1: PortStruct.dwPortVal = (ULONG)READ_PORT_UCHAR((PUCHAR)(USHORT)PortStruct.wPortAddr); break; case 2: PortStruct.dwPortVal = (ULONG)READ_PORT_USHORT((PUSHORT)(USHORT)PortStruct.wPortAddr); break; case 4: PortStruct.dwPortVal = READ_PORT_ULONG((PULONG)(USHORT)PortStruct.wPortAddr); break; } memcpy (pvIOBuffer, &PortStruct.dwPortVal, sizeof(PortStruct.dwPortVal)); Irp->IoStatus.Information = sizeof(PortStruct.dwPortVal); } else Irp->IoStatus.Status = STATUS_INVALID_PARAMETER; break; case IOCTL_WINIO_MAPPHYSTOLIN: KdPrint(("IOCTL_WINIO_MAPPHYSTOLIN")); if (dwInputBufferLength) { memcpy (&PhysStruct, pvIOBuffer, dwInputBufferLength); ntStatus = MapPhysicalMemoryToLinearSpace((PVOID)PhysStruct.pvPhysAddress, (SIZE_T)PhysStruct.dwPhysMemSizeInBytes, (PVOID *)&PhysStruct.pvPhysMemLin, (HANDLE *)&PhysStruct.PhysicalMemoryHandle, (PVOID *)&PhysStruct.pvPhysSection); if (NT_SUCCESS(ntStatus)) { memcpy (pvIOBuffer, &PhysStruct, dwInputBufferLength); Irp->IoStatus.Information = dwInputBufferLength; } Irp->IoStatus.Status = ntStatus; } else Irp->IoStatus.Status = STATUS_INVALID_PARAMETER; break; case IOCTL_WINIO_UNMAPPHYSADDR: KdPrint(("IOCTL_WINIO_UNMAPPHYSADDR")); if (dwInputBufferLength) { memcpy (&PhysStruct, pvIOBuffer, dwInputBufferLength); ntStatus = UnmapPhysicalMemory((HANDLE)PhysStruct.PhysicalMemoryHandle, (PVOID)PhysStruct.pvPhysMemLin, (PVOID)PhysStruct.pvPhysSection); Irp->IoStatus.Status = ntStatus; } else Irp->IoStatus.Status = STATUS_INVALID_PARAMETER; break; default: KdPrint(("ERROR: Unknown IRP_MJ_DEVICE_CONTROL")); Irp->IoStatus.Status = STATUS_INVALID_PARAMETER; break; } break; } // DON'T get cute and try to use the status field of the irp in the // return status. That IRP IS GONE as soon as you call IoCompleteRequest. ntStatus = Irp->IoStatus.Status; IoCompleteRequest (Irp, IO_NO_INCREMENT); // We never have pending operation so always return the status code. KdPrint(("Leaving WinIoDispatch")); return ntStatus; } // Delete the associated device and return void WinIoUnload(IN PDRIVER_OBJECT DriverObject) { UNICODE_STRING DeviceLinkUnicodeString; NTSTATUS ntStatus; KdPrint(("Entering WinIoUnload")); RtlInitUnicodeString (&DeviceLinkUnicodeString, L"\\DosDevices\\WinIo"); ntStatus = IoDeleteSymbolicLink (&DeviceLinkUnicodeString); if (NT_SUCCESS(ntStatus)) { IoDeleteDevice (DriverObject->DeviceObject); } else { KdPrint(("ERROR: IoDeleteSymbolicLink")); } KdPrint(("Leaving WinIoUnload")); } NTSTATUS MapPhysicalMemoryToLinearSpace(PVOID pPhysAddress, SIZE_T PhysMemSizeInBytes, PVOID *ppPhysMemLin, HANDLE *pPhysicalMemoryHandle, PVOID *ppPhysSection) { UNICODE_STRING PhysicalMemoryUnicodeString; OBJECT_ATTRIBUTES ObjectAttributes; PHYSICAL_ADDRESS ViewBase; NTSTATUS ntStatus; PHYSICAL_ADDRESS pStartPhysAddress; PHYSICAL_ADDRESS pEndPhysAddress; BOOLEAN Result1, Result2; ULONG IsIOSpace; unsigned char *pbPhysMemLin = NULL; KdPrint(("Entering MapPhysicalMemoryToLinearSpace")); RtlInitUnicodeString (&PhysicalMemoryUnicodeString, L"\\Device\\PhysicalMemory"); InitializeObjectAttributes (&ObjectAttributes, &PhysicalMemoryUnicodeString, OBJ_CASE_INSENSITIVE, (HANDLE) NULL, (PSECURITY_DESCRIPTOR) NULL); *pPhysicalMemoryHandle = NULL; *ppPhysSection = NULL; ntStatus = ZwOpenSection (pPhysicalMemoryHandle, SECTION_ALL_ACCESS, &ObjectAttributes); if (NT_SUCCESS(ntStatus)) { ntStatus = ObReferenceObjectByHandle (*pPhysicalMemoryHandle, SECTION_ALL_ACCESS, (POBJECT_TYPE) NULL, KernelMode, ppPhysSection, (POBJECT_HANDLE_INFORMATION) NULL); if (NT_SUCCESS(ntStatus)) { pStartPhysAddress.QuadPart = (ULONGLONG)(ULONG_PTR)pPhysAddress; pEndPhysAddress.QuadPart = pStartPhysAddress.QuadPart + PhysMemSizeInBytes; IsIOSpace = 0; Result1 = HalTranslateBusAddress (1, 0, pStartPhysAddress, &IsIOSpace, &pStartPhysAddress); IsIOSpace = 0; Result2 = HalTranslateBusAddress (1, 0, pEndPhysAddress, &IsIOSpace, &pEndPhysAddress); if (Result1 && Result2) { // Let ZwMapViewOfSection pick a linear address PhysMemSizeInBytes = (SIZE_T)pEndPhysAddress.QuadPart - (SIZE_T)pStartPhysAddress.QuadPart; ViewBase = pStartPhysAddress; ntStatus = ZwMapViewOfSection (*pPhysicalMemoryHandle, (HANDLE) -1, &pbPhysMemLin, 0L, PhysMemSizeInBytes, &ViewBase, &PhysMemSizeInBytes, ViewShare, 0, PAGE_READWRITE | PAGE_NOCACHE); // If the physical memory is already mapped with a different caching attribute, try again if (ntStatus == STATUS_CONFLICTING_ADDRESSES) { ntStatus = ZwMapViewOfSection (*pPhysicalMemoryHandle, (HANDLE) -1, &pbPhysMemLin, 0L, PhysMemSizeInBytes, &ViewBase, &PhysMemSizeInBytes, ViewShare, 0, PAGE_READWRITE); } if (!NT_SUCCESS(ntStatus)) KdPrint(("ERROR: ZwMapViewOfSection failed")); else { pbPhysMemLin += pStartPhysAddress.QuadPart - ViewBase.QuadPart; *ppPhysMemLin = pbPhysMemLin; } } else KdPrint(("ERROR: HalTranslateBusAddress failed")); } else KdPrint(("ERROR: ObReferenceObjectByHandle failed")); } else KdPrint(("ERROR: ZwOpenSection failed")); if (!NT_SUCCESS(ntStatus)) ZwClose(*pPhysicalMemoryHandle); KdPrint(("Leaving MapPhysicalMemoryToLinearSpace")); return ntStatus; } NTSTATUS UnmapPhysicalMemory(HANDLE PhysicalMemoryHandle, PVOID pPhysMemLin, PVOID pPhysSection) { NTSTATUS ntStatus; KdPrint(("Entering UnmapPhysicalMemory")); ntStatus = ZwUnmapViewOfSection((HANDLE)-1, pPhysMemLin); if (!NT_SUCCESS(ntStatus)) KdPrint(("ERROR: UnmapViewOfSection failed")); if (pPhysSection) ObDereferenceObject(pPhysSection); ZwClose(PhysicalMemoryHandle); KdPrint(("Leaving UnmapPhysicalMemory")); return ntStatus; } ================================================ FILE: Source/Drv/winio_nt.h ================================================ #ifndef WINIONT_H #define WINIONT_H // Define the various device type values. Note that values used by Microsoft // Corporation are in the range 0-32767, and 32768-65535 are reserved for use // by customers. #define FILE_DEVICE_WINIO 0x00008010 // Macro definition for defining IOCTL and FSCTL function control codes. // Note that function codes 0-2047 are reserved for Microsoft Corporation, // and 2048-4095 are reserved for customers. #define WINIO_IOCTL_INDEX 0x810 // Define our own private IOCTL #define IOCTL_WINIO_MAPPHYSTOLIN CTL_CODE(FILE_DEVICE_WINIO, \ WINIO_IOCTL_INDEX, \ METHOD_BUFFERED, \ FILE_ANY_ACCESS) #define IOCTL_WINIO_UNMAPPHYSADDR CTL_CODE(FILE_DEVICE_WINIO, \ WINIO_IOCTL_INDEX + 1, \ METHOD_BUFFERED, \ FILE_ANY_ACCESS) #define IOCTL_WINIO_ENABLEDIRECTIO CTL_CODE(FILE_DEVICE_WINIO, \ WINIO_IOCTL_INDEX + 2, \ METHOD_BUFFERED, \ FILE_ANY_ACCESS) #define IOCTL_WINIO_DISABLEDIRECTIO CTL_CODE(FILE_DEVICE_WINIO, \ WINIO_IOCTL_INDEX + 3, \ METHOD_BUFFERED, \ FILE_ANY_ACCESS) #define IOCTL_WINIO_READPORT CTL_CODE(FILE_DEVICE_WINIO, \ WINIO_IOCTL_INDEX + 4, \ METHOD_BUFFERED, \ FILE_ANY_ACCESS) #define IOCTL_WINIO_WRITEPORT CTL_CODE(FILE_DEVICE_WINIO, \ WINIO_IOCTL_INDEX + 5, \ METHOD_BUFFERED, \ FILE_ANY_ACCESS) #pragma pack(push) #pragma pack(1) struct tagPhysStruct { DWORD64 dwPhysMemSizeInBytes; DWORD64 pvPhysAddress; DWORD64 PhysicalMemoryHandle; DWORD64 pvPhysMemLin; DWORD64 pvPhysSection; }; struct tagPortStruct { USHORT wPortAddr; ULONG dwPortVal; UCHAR bSize; }; #pragma pack(pop) #endif