1. /************************************************************************************
  2. * InpOut32 CSharpExample.cs hacking
  3. * 说明:
  4. * 跟一下CSharpExample.cs中InpOut32怎么使用。
  5. *
  6. * 2017-6-6 深圳 龙华樟坑村 曾剑锋
  7. ***********************************************************************************/
  8.  
  9. using System;
  10. using System.Collections.Generic;
  11. using System.ComponentModel;
  12. using System.Data;
  13. using System.Drawing;
  14. using System.Text;
  15. using System.Windows.Forms;
  16.  
  17. using System.Runtime.InteropServices;
  18.  
  19. namespace InpOut32.Net
  20. {
  21. public partial class CSharpExample : Form
  22. {
  23.  
  24. /**
  25. * 加载dll相关处理函数
  26. */
  27. [DllImport("inpout32.dll")]
  28. private static extern UInt32 IsInpOutDriverOpen();
  29. [DllImport("inpout32.dll")]
  30. private static extern void Out32(short PortAddress, short Data);
  31. [DllImport("inpout32.dll")]
  32. private static extern char Inp32(short PortAddress);
  33.  
  34. [DllImport("inpout32.dll")]
  35. private static extern void DlPortWritePortUshort(short PortAddress, ushort Data);
  36. [DllImport("inpout32.dll")]
  37. private static extern ushort DlPortReadPortUshort(short PortAddress);
  38.  
  39. [DllImport("inpout32.dll")]
  40. private static extern void DlPortWritePortUlong(int PortAddress, uint Data);
  41. [DllImport("inpout32.dll")]
  42. private static extern uint DlPortReadPortUlong(int PortAddress);
  43.  
  44. [DllImport("inpoutx64.dll")]
  45. private static extern bool GetPhysLong(ref int PortAddress, ref uint Data);
  46. [DllImport("inpoutx64.dll")]
  47. private static extern bool SetPhysLong(ref int PortAddress, ref uint Data);
  48.  
  49. [DllImport("inpoutx64.dll", EntryPoint="IsInpOutDriverOpen")]
  50. private static extern UInt32 IsInpOutDriverOpen_x64();
  51. [DllImport("inpoutx64.dll", EntryPoint = "Out32")]
  52. private static extern void Out32_x64(short PortAddress, short Data);
  53. [DllImport("inpoutx64.dll", EntryPoint = "Inp32")]
  54. private static extern char Inp32_x64(short PortAddress);
  55.  
  56. [DllImport("inpoutx64.dll", EntryPoint = "DlPortWritePortUshort")]
  57. private static extern void DlPortWritePortUshort_x64(short PortAddress, ushort Data);
  58. [DllImport("inpoutx64.dll", EntryPoint = "DlPortReadPortUshort")]
  59. private static extern ushort DlPortReadPortUshort_x64(short PortAddress);
  60.  
  61. [DllImport("inpoutx64.dll", EntryPoint = "DlPortWritePortUlong")]
  62. private static extern void DlPortWritePortUlong_x64(int PortAddress, uint Data);
  63. [DllImport("inpoutx64.dll", EntryPoint = "DlPortReadPortUlong")]
  64. private static extern uint DlPortReadPortUlong_x64(int PortAddress);
  65.  
  66. [DllImport("inpoutx64.dll", EntryPoint = "GetPhysLong")]
  67. private static extern bool GetPhysLong_x64(ref int PortAddress, ref uint Data);
  68. [DllImport("inpoutx64.dll", EntryPoint = "SetPhysLong")]
  69. private static extern bool SetPhysLong_x64(ref int PortAddress, ref uint Data);
  70.  
  71. bool m_bX64 = false;
  72.  
  73. public CSharpExample()
  74. {
  75. InitializeComponent();
  76. try
  77. {
  78. uint nResult = ;
  79. try
  80. {
  81. // 打开32位驱动,如果失败了,会引发异常,再加载64位驱动
  82. nResult = IsInpOutDriverOpen();
  83.  
  84. Console.WriteLine("nResult1: " + nResult);
  85. }
  86. catch (BadImageFormatException)
  87. {
  88. Console.WriteLine("nResult2: " + nResult);
  89. nResult = IsInpOutDriverOpen_x64();
  90. if (nResult != )
  91. m_bX64 = true;
  92.  
  93. Console.WriteLine("nResult2: " + nResult);
  94.  
  95. }
  96.  
  97. // 加载32、64位驱动均失败了,就给出相关提示信息
  98. if (nResult == )
  99. {
  100. lblMessage.Text = "Unable to open InpOut32 driver";
  101. button1.Enabled = false;
  102. button2.Enabled = false;
  103. button3.Enabled = false;
  104. button4.Enabled = false;
  105. button5.Enabled = false;
  106. button6.Enabled = false;
  107. button7.Enabled = false;
  108. }
  109. }
  110. catch (DllNotFoundException ex) // dll查找是失败异常
  111. {
  112. System.Diagnostics.Debug.WriteLine(ex.ToString());
  113. lblMessage.Text = "Unable to find InpOut32.dll";
  114. button1.Enabled = false;
  115. button2.Enabled = false;
  116. button3.Enabled = false;
  117. button4.Enabled = false;
  118. button5.Enabled = false;
  119. button6.Enabled = false;
  120. button7.Enabled = false;
  121. }
  122. }
  123.  
  124. private void button1_Click(object sender, EventArgs e)
  125. {
  126. try
  127. {
  128. // 字符串转16位short类型整数
  129. short iPort = Convert.ToInt16(textBox1.Text);
  130.  
  131. char c;
  132. if (m_bX64)
  133. c = Inp32_x64(iPort);
  134. else
  135. c = Inp32(iPort);
  136.  
  137. // 将读取的数据显示出来
  138. textBox2.Text = Convert.ToInt32(c).ToString();
  139. }
  140. catch (Exception ex)
  141. {
  142. MessageBox.Show("An error occured:\n" + ex.Message);
  143. }
  144. }
  145.  
  146. private void button2_Click(object sender, EventArgs e)
  147. {
  148. try
  149. {
  150. // 字符串转16位short类型整数
  151. short iPort = Convert.ToInt16(textBox1.Text);
  152. short iData = Convert.ToInt16(textBox2.Text);
  153. textBox2.Text = "";
  154. if (m_bX64)
  155. Out32_x64(iPort, iData);
  156. else
  157. Out32(iPort, iData);
  158.  
  159. }
  160. catch (Exception ex)
  161. {
  162. MessageBox.Show("An error occured:\n" + ex.Message);
  163. }
  164. }
  165.  
  166. private void button3_Click(object sender, EventArgs e)
  167. {
  168. try
  169. {
  170. short iPort = Convert.ToInt16(textBox1.Text);
  171. ushort s;
  172. if (m_bX64)
  173. s = DlPortReadPortUshort_x64(iPort);
  174. else
  175. s = DlPortReadPortUshort(iPort);
  176.  
  177. textBox2.Text = Convert.ToUInt16(s).ToString();
  178. }
  179. catch (Exception ex)
  180. {
  181. MessageBox.Show("An error occured:\n" + ex.Message);
  182. }
  183. }
  184.  
  185. private void button4_Click(object sender, EventArgs e)
  186. {
  187. try
  188. {
  189. int nPort = Convert.ToInt32(textBox1.Text);
  190.  
  191. uint l;
  192. if (m_bX64)
  193. l = DlPortReadPortUlong_x64(nPort);
  194. else
  195. l = DlPortReadPortUlong(nPort);
  196.  
  197. textBox2.Text = l.ToString();
  198. }
  199. catch (Exception ex)
  200. {
  201. MessageBox.Show("An error occured:\n" + ex.Message);
  202. }
  203. }
  204.  
  205. private void button5_Click(object sender, EventArgs e)
  206. {
  207. try
  208. {
  209. short sPort = Convert.ToInt16(textBox1.Text);
  210. ushort iData = Convert.ToUInt16(textBox2.Text);
  211. textBox2.Text = "";
  212.  
  213. if (m_bX64)
  214. DlPortWritePortUshort_x64(sPort, iData);
  215. else
  216. DlPortWritePortUshort(sPort, iData);
  217. }
  218. catch (Exception ex)
  219. {
  220. MessageBox.Show("An error occured:\n" + ex.Message);
  221. }
  222. }
  223.  
  224. private void button6_Click(object sender, EventArgs e)
  225. {
  226. try
  227. {
  228. int nPort = Convert.ToInt32(textBox1.Text);
  229. uint nData = Convert.ToUInt32(textBox2.Text);
  230. textBox2.Text = "";
  231. if (m_bX64)
  232. DlPortWritePortUlong_x64(nPort, nData);
  233. else
  234. DlPortWritePortUlong(nPort, nData);
  235. }
  236. catch (Exception ex)
  237. {
  238. MessageBox.Show("An error occured:\n" + ex.Message);
  239. }
  240. }
  241.  
  242. // 参考:InpOut32 InputTest.cpp hacking
  243. // http://www.cnblogs.com/zengjfgit/p/6945758.html
  244. private void Beep(uint freq)
  245. {
  246. if (m_bX64)
  247. {
  248. Out32_x64(0x43, 0xB6);
  249. Out32_x64(0x42, (byte)(freq & 0xFF));
  250. Out32_x64(0x42, (byte)(freq >> ));
  251. System.Threading.Thread.Sleep();
  252. Out32_x64(0x61, (byte)(Convert.ToByte(Inp32_x64(0x61)) | 0x03));
  253. }
  254. else
  255. {
  256. Out32(0x43, 0xB6);
  257. Out32(0x42, (byte)(freq & 0xFF));
  258. Out32(0x42, (byte)(freq >> ));
  259. System.Threading.Thread.Sleep();
  260. Out32(0x61, (byte)(Convert.ToByte(Inp32(0x61)) | 0x03));
  261. }
  262. }
  263.  
  264. private void StopBeep()
  265. {
  266. if (m_bX64)
  267. Out32_x64(0x61, (byte)(Convert.ToByte(Inp32_x64(0x61)) & 0xFC));
  268. else
  269. Out32(0x61, (byte)(Convert.ToByte(Inp32(0x61)) & 0xFC));
  270. }
  271.  
  272. private void CSharpExample_Load(object sender, EventArgs e)
  273. {
  274. // 启动的时候相当于单击一次
  275. button7_Click(this, null);
  276. }
  277.  
  278. private void ThreadBeeper()
  279. {
  280. for (uint i = ; i < ; i += )
  281. {
  282. uint freq = / i; // 440Hz
  283. Beep(freq);
  284. }
  285. StopBeep();
  286. }
  287.  
  288. private void button7_Click(object sender, EventArgs e)
  289. {
  290. System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadBeeper));
  291. t.Start();
  292. }
  293. }
  294. }

InpOut32 CSharpExample.cs hacking的更多相关文章

  1. InpOut32 InputTest.cpp hacking

    /************************************************************************************ * InpOut32 Inp ...

  2. Rootkit Hacking Technology && Defence Strategy Research

    目录 . The Purpose Of Rootkit . Syscall Hijack . LKM Module Hidden . Network Communication Hidden . Fi ...

  3. 我的美国(北美)计算机CS实习面试经验分享

    过去的一年多里,参加了一些面试,虽然面过的公司不多,但都从头一直走到尾.毕竟自己也是花了大量的时间和精力在这一场场的面试里.所以,就絮叨下自己的一些经验,希望能给在美国找实习找工作的同学们提供一点点帮 ...

  4. I.MX6 ar1020 SPI device driver hacking

    /************************************************************************************ * I.MX6 ar1020 ...

  5. OK335xS GPMC nand device register hacking

    /********************************************************************************* * OK335xS GPMC na ...

  6. RFID Hacking–资源大合集

    原文: http://www.freebuf.com/news/others/605.html http://www.proxmark.org/forum/index.php RFID破解神器官方论坛 ...

  7. Hacking/Penetrating tester bookmark collection

    Blogs http://carnal0wnage.blogspot.com/ http://www.mcgrewsecurity.com/ http://www.gnucitizen.org/blo ...

  8. 斯坦福CS课程列表

    http://exploredegrees.stanford.edu/coursedescriptions/cs/ CS 101. Introduction to Computing Principl ...

  9. [C#] 剖析 AssemblyInfo.cs - 了解常用的特性 Attribute

    剖析 AssemblyInfo.cs - 了解常用的特性 Attribute [博主]反骨仔 [原文]http://www.cnblogs.com/liqingwen/p/5944391.html 序 ...

随机推荐

  1. Bootstrap总结二

    参考我的博客:http://www.isedwardtang.com/2017/09/01/bootstrap-primer-2/

  2. hadoop11----socket

    package cn.itcast.bigdata.socket; import java.io.BufferedReader; import java.io.InputStream; import ...

  3. Linux系统服务管理 服务管理

    Linux独立服务管理 启动服务 systemctl start 服务名称.service 设置开机自启动 systemctl enable 服务名称.service 停止开机自启动 systemct ...

  4. 【hihocoder】01背包

    描述 且说上一周的故事里,小Hi和小Ho费劲心思终于拿到了茫茫多的奖券!而现在,终于到了小Ho领取奖励的时刻了! 小Ho现在手上有M张奖券,而奖品区有N件奖品,分别标号为1到N,其中第i件奖品需要ne ...

  5. 20145217《网络对抗》 MAL_简单后门学习总结

    20145217<网络对抗> MAL_简单后门学习总结 实践内容: 1.netcat的应用 2.socat的应用 3.meterpreter的应用 知识点学习总结 后门程序一般是指那些绕过 ...

  6. 查询当天数据(mysql)

    SELECT count(*) as nums FROM go_member_share WHERE DATEDIFF(FROM_UNIXTIME(time, '%Y-%m-%d') , now()) ...

  7. code for 1 - 分治

    2017-08-02 17:23:14 writer:pprp 题意:将n分解为n/2, n%2, n/2三部分,再将n/2分解..得到一个序列只有0和1,给出[l, r]问l到r有几个1 题解:分治 ...

  8. windows拒绝远程登陆

  9. ACM-ICPC北京站总结

    失踪人口回归.... 第一次ACM比赛还是比较紧张的,总体来说发挥还是有一点失常. day1热身赛 一共四道去年和前年的北京站的题目....似乎都是银牌题及以下难度.半个小时我们就完成了嘴巴AK,然而 ...

  10. 不常用的gcd公式

    gcd(a^m-b^m,a^n-b^n)=a^(gcd(m,n))-b^(gcd(m,n))