Windows 95 VxD C Source Code for VANYDEVD

原创 2000年11月27日 09:13:00

 

Listing 3

/// VANYDEVDc.c

// --------------------------------------------
// Dynamically loadable VxD for ANYDEV board
// --------------------------------------------
#define WIN32_LEAN_AND_MEAN // Excludes un-needed parts of windows.h
#include "windows.h"
#include <e:/ddk95/inc32/vmm.h>
#include <e:/ddk95/inc32/vwin32.h>
#include <e:/ddk95/inc32/debug.h>
#include "VANYDEVD.H"


// -------------------------------------
// Externs defined in assembly module 
// -------------------------------------
// These defined in assembly for the VMM.INC or VPICD.INC file inclusion
extern DWORD GET_BD_MEM(void);
extern DWORD Virt_IRQ(void);
extern DWORD Get_IRQ_Status(void);
extern void UNVirt_IRQ(DWORD IRQhandle);
extern void End_ISR(DWORD IRQhandle);
extern void Physically_Mask_IRQ(DWORD IRQhandle);
extern void Physically_UNMask_IRQ(DWORD IRQhandle);


// ------------------------
// PRAGMA for this DATA 
// ------------------------
// Establish segment
#pragma data_seg ( "_LDATA","_LCODE")


// ------------------------------------
// Data structures MUST be INITIALIZED
// ------------------------------------
ADEV ANYDEVX = {0}; // Main structure for ANYDEV -- shared by app 


// ------------------------
// PRAGMAS for this CODE 
// ------------------------
// Establish segment
#pragma code_seg ( "_LTEXT", "_LCODE" )
//No stack checking for routines in this module
#pragma check_stack(off)


// ----------------
// Disable hardware
// ----------------
void Disable_AnyDev(void)
{
	//This would likely be a port WRITE to DISABLE the board's interrupt	 		
}


// ----------------
// Enable hardware
// ----------------
void Enable_AnyDev(void)
{
	//This would likely be a port WRITE to ENABLE the board's interrupt	 		
}
// --------------------------
// ISR Processing for ANYDEV
// --------------------------
void Process_ISR(void)
{
	//This is where the user might SET FLAGS and indicators in the ANYDEVX structure
	//in order to notify the application that data is available below 1MB	 		
}


// -----------------
// ISR for ANYDEV
// -----------------
void _declspec(naked)ISR_ANYDEV(void)
{
	// Save registers
	_asm sti
	_asm pushad
	_asm pushfd


	//Process the ISR 
	Process_ISR();


	//End ISR
	_asm clc
	End_ISR(ANYDEVX.IRQhandle);


	//Set GOOD return code
	_asm clc


	//Restore saved registers
	_asm popfd
	_asm popad
	_asm ret;
}


// -------------------
// Virtualize the IRQ
// -------------------
DWORD CVirt_IRQ(void)
{
	// If in use by an instance of this program, RETURN with BAD code
	if (ANYDEVX.IRQcount)
		return (BOGUSADDRESS);


	// If in use by another program, RETURN with BAD code
	ANYDEVX.IRQstatus = Get_IRQ_Status();
	if (ANYDEVX.IRQstatus)
		return (BOGUSADDRESS);


	// If IRQ NOT in use this point is reached
	// Set BAD return code
	ANYDEVX.IRQhandle = BOGUSADDRESS;
	// Disable ANYDEV hardware	
	Disable_AnyDev();
	// Get global memory address below 1mb
	ANYDEVX.Global_addr_1MB = GET_BD_MEM();
	if (ANYDEVX.Global_addr_1MB != BOGUSADDRESS)
		{
		// Virtualize the IRQ
		ANYDEVX.IRQhandle = Virt_IRQ();	
		if (ANYDEVX.IRQhandle != BOGUSADDRESS)
			{
			// unmask the IRQ, set OK flag & increment IRQ count
	 		Physically_UNMask_IRQ(ANYDEVX.IRQhandle);
	 		ANYDEVX.IRQflags |= IRQ_VIRT_OK;
			++(ANYDEVX.IRQcount);
			}
		}
	return(ANYDEVX.IRQhandle);
}
// ----------------------
// UN Virtualize the IRQ
// ----------------------
void CUNVirt_IRQ(DWORD IRQhandle)
{
 // if IRQ has been successfully virtualized
 if ((ANYDEVX.IRQhandle != 0)
 &&  (ANYDEVX.IRQhandle != BOGUSADDRESS))
 	{
	// Physically mask the IRQ and UN virtualized it
	Physically_Mask_IRQ(ANYDEVX.IRQhandle);
	UNVirt_IRQ(ANYDEVX.IRQhandle);
	}
// Set UNvirtualized flags and indicators
ANYDEVX.IRQhandle = BOGUSADDRESS;
ANYDEVX.IRQflags &= ~IRQ_VIRT_OK;
	return;
}


// ---------------------------------------
// Set Good Return code for DIOC requests
// ---------------------------------------
void _declspec(naked)GoodReturnDIOC(void)
{
	// Clear eax and carry flag for GOOD return
	_asm xor eax,eax
	_asm clc
	_asm ret;
}


// ---------------------------------------
// Set Bad Return code for DIOC requests
// ---------------------------------------
void _declspec(naked) BadReturnDIOC(void)
{
	// NOTE: 50 is a FCN NOT SUPPORTED code -- ok to use
	// SET carry flag for BAD return
	_asm mov eax,50
	_asm stc
	_asm ret;
}




// ------------------------------
// Routine for ANYDEV Device UNINIT  
// ------------------------------
void CVANYDEVD_Device_UNInit()
{
// Disable ANYDEV, Unvirtualize IRQ, set GOOD return code
	Disable_AnyDev();			
	CUNVirt_IRQ(ANYDEVX.IRQhandle);	
	GoodReturnDIOC();			
	return;
}
// ------------------------------
// Routine for ANYDEV Device INIT  
// ------------------------------


void CVANYDEVD_Device_Init()
{
DWORD retcode;


	// Try to virtualize the IRQ
	retcode = CVirt_IRQ();
	// Set GOOD or BAD return code based on success
	if (retcode == BOGUSADDRESS)
		BadReturnDIOC();
	else
	    GoodReturnDIOC();
	return;
}
// --------------------------------
// Routine for ANYDEV Device IO ctrl  
// --------------------------------
void CVANYDEVD_Device_IOctrl(PDIOCPARAMETERS ptr)
{
DWORD *obuf1;
	// Field the DEV IO requests from VMM
	switch(ptr->dwIoControlCode)
		{
		case(VANYDEVD_INIT_ADEV_HARDWARE):
			ANYDEVX.flags = 0;
			//User likely to require other initialization here
		break;
		case(VANYDEVD_GRAB_ADDRESSES):
			// Point to Output buffer
			obuf1 = (DWORD *) ptr->lpvOutBuffer;
			// Return GLOBAL 1MB addr, addr of data structure
			// and return indicators of IRQ virtuaization request
			*obuf1 = ANYDEVX.Global_addr_1MB;
		  	*(obuf1+1) = (DWORD) &ANYDEVX;
			*(obuf1+2) = (DWORD) ANYDEVX.IRQhandle;
			*(obuf1+3) = (DWORD) ANYDEVX.IRQflags;
			//User might want to return other/different values here
		break;
		case(VANYDEVD_ENABLE_ANYDEV_HDWR):
			//Call routine to enable interrupt
			Enable_AnyDev();
		break;
		case(VANYDEVD_DISABLE_ANYDEV_HWR):
			//Call routine to disable interrupt
			Disable_AnyDev();
		break;
		//The below DIOC_GETVERSION is a part of the dynamic load protocol
		//It MUST return a GOOD code (all codes here use GoodReturnDIOC()
		case(DIOC_GETVERSION):
		case(DIOC_CLOSEHANDLE):
		default:
		break;
		}
 	GoodReturnDIOC();
	return;
}

Windows 95 VxD C Source Code for VANYDEVD

2000年11月27日 09:13:00 Listing 3 /// VANYDEVDc.c // --------------------------------------------/...
  • softart
  • softart
  • 2007年10月27日 07:30
  • 294

使用Windows 95虚拟设备驱动程序(VxD)

大家知道整天都在讨论的CIH病毒利用了VxD技术,掌握了VxD 编程,就等于破除了CIH 病毒神话,彻底清除CIH 病毒。仔细学习这篇文章。VxD介绍本文介绍VxD的作用。如果Windows 95提供...
  • pwhome
  • pwhome
  • 2001年10月25日 12:07
  • 641

Notepad++如何安装并使用source code pro 字体

一直觉得Dev-c++,sublime text中的编程字体很好看,但是却不知道那是什么字体。今天上课,老师向我们推荐了一款字体,source code pro。老师说这个是专门为程序员设计的字体,晚...
  • qq_21148843
  • qq_21148843
  • 2015年06月30日 09:36
  • 1786

live555 vlc sourcecode

/***************************************************************************** * live555.cpp : LIVE...
  • maikforever
  • maikforever
  • 2012年01月12日 15:26
  • 1869

Ubuntu Sublime安装Source Code Pro字体

第一步:安装Sublime找到Sublime官网:http://www.sublimetext.com/点击下载,然后双击安装即可第二步:下载Source Code Pro字体字体下载地址:https...
  • richlaji
  • richlaji
  • 2016年12月03日 14:25
  • 2383

nginx搭建(基于source code)

1.下载(nginx) 下载地址:http://nginx.org/en/download.html 2.上传 在windows系统下通过工具上传到任意一个目录都可以 3.解压...
  • m0_37294838
  • m0_37294838
  • 2017年08月13日 17:54
  • 343

VxD

VxD 程序设计入门We 我们在上一节学会了如何编写一个什么事也不做的VxD程序。在这一节里,我们要给它增加处理控制消息的功能。 VxD的初始化和结束VxD程序分为两种:静态的和动态的。每种的加载方法...
  • jiangtao
  • jiangtao
  • 2000年09月05日 14:49
  • 2718

Iczelion 的 Win32Asm VxD 汇编教程 (五)

VxD例程:消息框在上一节教程里,我们讲了编写一个VxD程序的方法。现在我们要学以致用。在这一节里,我们要编写一个静态VxD,这个静态VxD在一个虚拟机创建或销毁时就会弹出一个消息框。 在这里下载例子...
  • kingzeus
  • kingzeus
  • 2002年02月14日 10:44
  • 678

Eclipse Source Code

Eclipse Source Code Tutorial This tutorial explains how to work with the Eclipse source code. It as...
  • soszou
  • soszou
  • 2013年01月07日 09:40
  • 3172

10 Code Coverage Tools for C & C++

10 Code Coverage Tools for C & C++     Code coverage is a measure used in software ...
  • j123kaishichufa
  • j123kaishichufa
  • 2014年11月21日 16:41
  • 1282
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Windows 95 VxD C Source Code for VANYDEVD
举报原因:
原因补充:

(最多只允许输入30个字)