/************************************************************************************
* InpOut32 CSharpExample.cs hacking
* 说明:
* 跟一下CSharpExample.cs中InpOut32怎么使用。
*
* 2017-6-6 深圳 龙华樟坑村 曾剑锋
***********************************************************************************/ 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; namespace InpOut32.Net
{
public partial class CSharpExample : Form
{ /**
* 加载dll相关处理函数
*/
[DllImport("inpout32.dll")]
private static extern UInt32 IsInpOutDriverOpen();
[DllImport("inpout32.dll")]
private static extern void Out32(short PortAddress, short Data);
[DllImport("inpout32.dll")]
private static extern char Inp32(short PortAddress); [DllImport("inpout32.dll")]
private static extern void DlPortWritePortUshort(short PortAddress, ushort Data);
[DllImport("inpout32.dll")]
private static extern ushort DlPortReadPortUshort(short PortAddress); [DllImport("inpout32.dll")]
private static extern void DlPortWritePortUlong(int PortAddress, uint Data);
[DllImport("inpout32.dll")]
private static extern uint DlPortReadPortUlong(int PortAddress); [DllImport("inpoutx64.dll")]
private static extern bool GetPhysLong(ref int PortAddress, ref uint Data);
[DllImport("inpoutx64.dll")]
private static extern bool SetPhysLong(ref int PortAddress, ref uint Data); [DllImport("inpoutx64.dll", EntryPoint="IsInpOutDriverOpen")]
private static extern UInt32 IsInpOutDriverOpen_x64();
[DllImport("inpoutx64.dll", EntryPoint = "Out32")]
private static extern void Out32_x64(short PortAddress, short Data);
[DllImport("inpoutx64.dll", EntryPoint = "Inp32")]
private static extern char Inp32_x64(short PortAddress); [DllImport("inpoutx64.dll", EntryPoint = "DlPortWritePortUshort")]
private static extern void DlPortWritePortUshort_x64(short PortAddress, ushort Data);
[DllImport("inpoutx64.dll", EntryPoint = "DlPortReadPortUshort")]
private static extern ushort DlPortReadPortUshort_x64(short PortAddress); [DllImport("inpoutx64.dll", EntryPoint = "DlPortWritePortUlong")]
private static extern void DlPortWritePortUlong_x64(int PortAddress, uint Data);
[DllImport("inpoutx64.dll", EntryPoint = "DlPortReadPortUlong")]
private static extern uint DlPortReadPortUlong_x64(int PortAddress); [DllImport("inpoutx64.dll", EntryPoint = "GetPhysLong")]
private static extern bool GetPhysLong_x64(ref int PortAddress, ref uint Data);
[DllImport("inpoutx64.dll", EntryPoint = "SetPhysLong")]
private static extern bool SetPhysLong_x64(ref int PortAddress, ref uint Data); bool m_bX64 = false; public CSharpExample()
{
InitializeComponent();
try
{
uint nResult = ;
try
{
// 打开32位驱动,如果失败了,会引发异常,再加载64位驱动
nResult = IsInpOutDriverOpen(); Console.WriteLine("nResult1: " + nResult);
}
catch (BadImageFormatException)
{
Console.WriteLine("nResult2: " + nResult);
nResult = IsInpOutDriverOpen_x64();
if (nResult != )
m_bX64 = true; Console.WriteLine("nResult2: " + nResult); } // 加载32、64位驱动均失败了,就给出相关提示信息
if (nResult == )
{
lblMessage.Text = "Unable to open InpOut32 driver";
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button5.Enabled = false;
button6.Enabled = false;
button7.Enabled = false;
}
}
catch (DllNotFoundException ex) // dll查找是失败异常
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
lblMessage.Text = "Unable to find InpOut32.dll";
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button5.Enabled = false;
button6.Enabled = false;
button7.Enabled = false;
}
} private void button1_Click(object sender, EventArgs e)
{
try
{
// 字符串转16位short类型整数
short iPort = Convert.ToInt16(textBox1.Text); char c;
if (m_bX64)
c = Inp32_x64(iPort);
else
c = Inp32(iPort); // 将读取的数据显示出来
textBox2.Text = Convert.ToInt32(c).ToString();
}
catch (Exception ex)
{
MessageBox.Show("An error occured:\n" + ex.Message);
}
} private void button2_Click(object sender, EventArgs e)
{
try
{
// 字符串转16位short类型整数
short iPort = Convert.ToInt16(textBox1.Text);
short iData = Convert.ToInt16(textBox2.Text);
textBox2.Text = "";
if (m_bX64)
Out32_x64(iPort, iData);
else
Out32(iPort, iData); }
catch (Exception ex)
{
MessageBox.Show("An error occured:\n" + ex.Message);
}
} private void button3_Click(object sender, EventArgs e)
{
try
{
short iPort = Convert.ToInt16(textBox1.Text);
ushort s;
if (m_bX64)
s = DlPortReadPortUshort_x64(iPort);
else
s = DlPortReadPortUshort(iPort); textBox2.Text = Convert.ToUInt16(s).ToString();
}
catch (Exception ex)
{
MessageBox.Show("An error occured:\n" + ex.Message);
}
} private void button4_Click(object sender, EventArgs e)
{
try
{
int nPort = Convert.ToInt32(textBox1.Text); uint l;
if (m_bX64)
l = DlPortReadPortUlong_x64(nPort);
else
l = DlPortReadPortUlong(nPort); textBox2.Text = l.ToString();
}
catch (Exception ex)
{
MessageBox.Show("An error occured:\n" + ex.Message);
}
} private void button5_Click(object sender, EventArgs e)
{
try
{
short sPort = Convert.ToInt16(textBox1.Text);
ushort iData = Convert.ToUInt16(textBox2.Text);
textBox2.Text = ""; if (m_bX64)
DlPortWritePortUshort_x64(sPort, iData);
else
DlPortWritePortUshort(sPort, iData);
}
catch (Exception ex)
{
MessageBox.Show("An error occured:\n" + ex.Message);
}
} private void button6_Click(object sender, EventArgs e)
{
try
{
int nPort = Convert.ToInt32(textBox1.Text);
uint nData = Convert.ToUInt32(textBox2.Text);
textBox2.Text = "";
if (m_bX64)
DlPortWritePortUlong_x64(nPort, nData);
else
DlPortWritePortUlong(nPort, nData);
}
catch (Exception ex)
{
MessageBox.Show("An error occured:\n" + ex.Message);
}
} // 参考:InpOut32 InputTest.cpp hacking
// http://www.cnblogs.com/zengjfgit/p/6945758.html
private void Beep(uint freq)
{
if (m_bX64)
{
Out32_x64(0x43, 0xB6);
Out32_x64(0x42, (byte)(freq & 0xFF));
Out32_x64(0x42, (byte)(freq >> ));
System.Threading.Thread.Sleep();
Out32_x64(0x61, (byte)(Convert.ToByte(Inp32_x64(0x61)) | 0x03));
}
else
{
Out32(0x43, 0xB6);
Out32(0x42, (byte)(freq & 0xFF));
Out32(0x42, (byte)(freq >> ));
System.Threading.Thread.Sleep();
Out32(0x61, (byte)(Convert.ToByte(Inp32(0x61)) | 0x03));
}
} private void StopBeep()
{
if (m_bX64)
Out32_x64(0x61, (byte)(Convert.ToByte(Inp32_x64(0x61)) & 0xFC));
else
Out32(0x61, (byte)(Convert.ToByte(Inp32(0x61)) & 0xFC));
} private void CSharpExample_Load(object sender, EventArgs e)
{
// 启动的时候相当于单击一次
button7_Click(this, null);
} private void ThreadBeeper()
{
for (uint i = ; i < ; i += )
{
uint freq = / i; // 440Hz
Beep(freq);
}
StopBeep();
} private void button7_Click(object sender, EventArgs e)
{
System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadBeeper));
t.Start();
}
}
}

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. ArcEngine开发中“错误类型"****"未定义构造函数”

    from:http://blog.csdn.net/mengdong_zy/article/details/8990593 问题 在ArcEngine开发的时候,在编译时,发现出现这样的错误,出错的地 ...

  2. 算法:LRU(最近最少使用)

    算法:LRU(最近最少使用) 本文参考自小灰文章:https://mp.weixin.qq.com/s/B5xiVeW22ZumbI9KfrYJSg LRU算法 什么是LRU算法 LRU算法又称最近最 ...

  3. HDU 4370 - 0 or 1 (SPFA+思维)

    题意:给一个N*N的矩阵C,和一个N*N的只由0和1组成的矩阵X. X满足以下条件: 1.X 12+X 13+...X 1n=1  2.X 1n+X 2n+...X n-1n=1  3.任意 i (1 ...

  4. react className 样式控制

    1.<div className={ "formbox " + this.state.classArr }></div> 2. this.state.cla ...

  5. Entity FrameWork Code First 之Model分离

    之前一直用DB First新建类库进行使用,最近开始研究Code First.Code First也可以将Model新建在类库里面,然后通过数据迁移等操作生成数据库. 现在说下主要步骤: 1.新建类库 ...

  6. COS-5资源分配与调度

    操作系统是用户和计算机的接口,同时也是计算机硬件和其他软件的接口.操作系统的功能包括管理计算机系统的硬件.软件及数据资源,控制程序运行,改善人机界面,为其它应用软件提供支持,让计算机系统所有资源最大限 ...

  7. shell编程学习笔记之正则表达式初识

    1.对单字符的查找: 1.1单字符: ‘X’ $ grep ‘q’ passwd //查找单个字符 1.2 范围字符 [] [^] 1.3 任意字符 . $ grep '[1-9]' passwd / ...

  8. 最简单的CI框架入门示例--数据库取数据

    前提: 安装好MySQL,Apache,PHP. 1.下载CI框架 下载地址  http://www.codeigniter.com/ 2.配置 database.php配置:    为数据库服务器设 ...

  9. LeetCode——Find the Difference

    LeetCode--Find the Difference Question Given two strings s and t which consist of only lowercase let ...

  10. Codeforces 9C Hexadecimal's Numbers - 有技巧的枚举

    2017-08-01 21:35:53 writer:pprp 集训第一天:作为第一道题来讲,说了两种算法, 第一种是跟二进制数联系起来进行分析: 第二种是用深度搜索来做,虽然接触过深度搜索但是这种题 ...