如何调用vxd格式的文件?(100分)

  • 主题发起人 荷塘新月
  • 开始时间

荷塘新月

Unregistered / Unconfirmed
GUEST, unregistred user!
我的程序需要执行某种操作,但是需要利用WINDOWS的某个vxd文件,这个文件WINDOWS可能没有加载,请问如何自己编程调用vxd格式的文件?
 
现在让我们来编写对该 VxD 的测试程序,两个按钮:一个打开 VxD;一个关闭 VxD。
const
VxDName = '//./DELPHIIO.VXD';
...
function TVxDTestForm.OpenVxDDriver: boolean;
begin

HVxDHandle := CreateFile(VxDName,0,0,nil,0,FILE_FLAG_DELETE_ON_CLOSE,0);
Result := HVxDHandle <> INVALID_HANDLE_VALUE;
end;

procedure TVxDTestForm.CloseVxDDriver;
begin

if HVxDHandle <> INVALID_HANDLE_VALUE then
begin

CloseHandle(HVxDHandle);
HVxDHandle := INVALID_HANDLE_VALUE;
end;

[摘录自Hubdog大侠的巨作]
 
用createfile
 
takashiki:
我试了一下,好象不行,程序没有任何反应。
 
第一,你的VXD是静态加载还是动态加载类型的?
第二,这个VXD提供的IOCtrl的接口是什么?
这是必需的
 
我想调用WINDOWS的SMARTVSD.VXD,因为在WIN9X中系统不是自动加载的。
 
hDevice := CreateFile( '//./SMARTVSD', 0, 0, nil,
CREATE_NEW, 0, 0 );
if hDevice=INVALID_HANDLE_VALUE then
Exit;
try
pInData := PSendCmdInParams(@Buffer);
pOutData := @pInData^.bBuffer;
with pInData^do
begin
cBufferSize := IDENTIFY_BUFFER_SIZE;
bDriveNumber := 0;
with irDriveRegsdo
begin
bFeaturesReg := 0;
bSectorCountReg := 1;
bSectorNumberReg := 1;
bCylLowReg := 0;
bCylHighReg := 0;
bDriveHeadReg := $A0;
bCommandReg := IDE_ID_FUNCTION;
end;
end;
if not DeviceIoControl( hDevice, DFP_RECEIVE_DRIVE_DATA,
pInData, SizeOf(TSendCmdInParams)-1, pOutData,
W9xBufferSize, cbBytesReturned, nil ) then
Exit;
finally
CloseHandle(hDevice);
end;
 
元元的哥:
还是不行啊!
 
到旧贴子搜一下
话题446271的标题是: 用Delphi读取硬盘,或主板,或CPU的序列号,或其他好的建议。。。急急急急急急急急急! (100分)
分类:非技术问题 supershan (2001-02-02 10:01:00)
我想利用Delphi读取每台机器中都不相同的信息,曾用过这个函数GetVolumeInformation;
但它只能读取的不是真正的硬盘号,如果重装机器,它将更改,听说用汇编可以做到,
不知是否有高手可以给出源码。win98,winnt,win2000
上都适用才行。期待您的回复,急急急急急急急急急!

吕雪松 (2001-02-02 10:19:00)
能不能顺便读出操作员的身份证号?

pcexplorer (2001-02-02 10:26:00)
{你可以试试以下的方法取的cpu的id,其它嘛让我想想}
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.DFM}
function GetCpuId:longint;assembler;register;
var
temp:longint;
begin
asm
PUSH EBX
PUSH EDI
MOV EDI,EAX
MOV EAX,1
DW $A20F
MOV TEMP,EDX
POP EDI
POP EBX
end;
result:=temp;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.Text:=IntToHex(GetCpuId,8);
end;
end.


kinglaw (2001-02-02 10:55:00)
以下例子可以读出硬盘序列号,但只能在win9x中使用。
要想在win98,winnt,win2000上都适用的话,只能编vxd了。

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.DFM}
type
TGate = record
Off2,op,seg,off1:WORD;
end;
LONGDWORD = INT64;
var
IDTR: LONGDWORD;
SavedGate:TGate;
OurGate: TGate;
dd: array [0..256] of word;
dsn:array [0..20] of char;
//存放硬盘序列号
procedure Ring0Proc();
asm
// Wait for controller not busy
mov dx,01f7h
@1:in al,dx
cmp al,050h
jne @1
// Get first/second drive
dec dx
mov al,0a0h
out dx,al
// Get drive info data
inc dx
mov al,0ech
out dx,al
nop
nop
// Wait for data ready
@2:in al,dx
cmp al,058h
jne @2
nop
nop
// Read sector
xor ecx,ecx
mov dx,01f0h
@3:in ax,dx
mov word ptr dd[ecx*2],ax
inc ecx
cmp ecx,256
jne @3
iretd //中断返回
end;

procedure Change2Ring0();
begin
asm
mov eax, offset Ring0Proc
mov OurGate.off2, ax // 将 中 断 函 数 的 地 址
shr eax, 16 // 填 入 新 造 的 中 断 门
mov OurGate.off1, ax // 描 述 符
mov OurGate.op,0028h
mov OurGate.seg,0ee00h
mov ebx,offset IDTR
sidt [ebx]
// 将 中 断 描 述 符 表 寄 存 器(IDTR)的 内 容 取 出
mov ebx, dword ptr [IDTR+2]
// 取 出 中 断 描 述 符 表(IDT) 基 地 址
add ebx, 8*3
// 计 算Int 3 的 描 述 符 应 放 置 的 地 址 选 用
//Int3 是 因 为 它 在Win32 保 护 模 式 下 未 占 用
mov edi, offset SavedGate
mov esi, ebx
movsd // 保 存 原 来 的Int 9 描 述 符 到
movsd //SavedGate 以 便 恢 复
mov edi, ebx
mov esi, offset OurGate
cli
movsd // 替 换 原 来 的 中 断 门 描 述 符
movsd // 以 安 装 中 断 服 务 例 程
sti
mov eax,6200h
// 用 以 测 试 放 在EAX 中 的 数 据 能 否 正 确 传 到Ring0 中 断
mov ecx,0
// 用 以 测 试 放 在ECX 中 的 数 据
// 能 否 正 确 传 到Ring0 中 断
// 因 为 很 多VxD 服 务 都 用此二 寄 存 器 传 递 参 数
int 3h
// 人 为 触 发 中 断, 平 时 会 出 现保 护 错 误 蓝 屏 或 非 法 操
// 作 对 话 框, 现 在 安 装 了
// 中 断 服 务 例 程 后, 就 会 通 过
//VMM 在Ring0 调 用 中 断 服 务 例 程Ring0Proc
mov edi, ebx
mov esi, offset SavedGate
cli
movsd // 恢 复 原 来 的 中 断 门 描 述 符
movsd
sti
end;
asm
xor ecx,ecx
mov ebx,offset dd[10*2]
@4:mov ax,[ebx]
mov byte ptr dsn[ecx],ah
inc ecx
mov byte ptr dsn[ecx],al
inc ebx
inc ebx
inc ecx
cmp ecx,10
jne @4
end;
showmessage(dsn);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
change2ring0;
end;

end.


supershan (2001-02-02 12:09:00)
读CPU的方法我试过,在六台机器上居然得到相同ID,而且现在intel已把ID封掉了

beta (2001-02-03 00:58:00)
取得硬盘序列号:
Function GetHardDiskSerieNummer : string;
var
Teller : integer;
Lus : integer;
SerieNummer : array[0..24] of char;
begin
result := '';
Teller := 1;
for Lus := 1 to 8do
begin
SerieNummer[Teller] := chr((HardDiskGegevens[10+Lus] div 256 ));
inc(Teller);
SerieNummer[Teller] := CHR((HardDiskGegevens[10+Lus] mod 256 ));
inc(Teller);
end;
result := SerieNummer;
end;


unreal (2001-02-03 01:07:00)
没贴全吧?HardDiskGegevens从哪来的?

beta (2001-02-03 01:15:00)
sorry,这个一定可以,我试过:
function GetHardDiskSerieNumber: string;
var
sysinfo:tsysteminfo;
lpRootPathName : PChar;
// address of root directory of the file system
lpVolumeNameBuffer : PChar;
// address of name of the volume
nVolumeNameSize : DWORD;
// length of lpVolumeNameBuffer
lpVolumeSerialNumber : DWORD;
// address of volume serial number
lpMaximumComponentLength : DWORD;
// address of system's maximum filename length
lpFileSystemFlags : DWORD;
// address of file system flags
lpFileSystemNameBuffer : PChar;
// address of name of file system
nFileSystemNameSize : DWORD;
// length of lpFileSystemNameBuffer
lpRootPathName:=pchar('c:/');
windows.GetSystemInfo(sysinfo);
GetMem( lpVolumeNameBuffer, MAX_PATH + 1 );
GetMem( lpFileSystemNameBuffer, MAX_PATH + 1 );
nVolumeNameSize := MAX_PATH + 1;
nFileSystemNameSize := MAX_PATH + 1;
Windows.GetVolumeInformation( lpRootPathName,
lpVolumeNameBuffer,
nVolumeNameSize,
@lpVolumeSerialNumber,
lpMaximumComponentLength,
lpFileSystemFlags,
lpFileSystemNameBuffer,
nFileSystemNameSize );
Result := Copy( IntToHex( lpVolumeSerialNumber, 0 ), 1, 4 ) + '-' +
Copy( IntToHex( lpVolumeSerialNumber, 0 ), 5, 4 );
end;


loopy (2001-02-03 02:31:00)
look

supershan (2001-02-03 09:29:00)
to beta:
用getvolumeinformation不行的,它得到的是逻辑盘的序列号,重装系统后,将更改

supershan (2001-02-04 09:52:00)
接着这个问题继续请教大家,如果我想把一定信息存到哪里最安全,即使格式化硬盘
也不会消失,而且要能够读和写。请高手指点!!!!!!!!!!!!!
这样的要求可能有难度,因为我要是存到注册表或INI中,用户重装机器后,
我存入的信息就没了,可能有更好的办法。

Siken (2001-02-04 12:53:00)
你可以安装lmd4.0,里面有控件

angelsoft (2001-02-12 02:50:00)
To kinglaw:
 你的程序确实可以得到硬盘的物理序列号,但是我测试发现在98,ME下使用能正常得到,
在95下使用却什么也得不到。why?
另外在2000下使用肯定是不行的,我知道原因,所以没有测试。
 我在以前也发过征求序列号的贴子,但没有得到满意的答复,难道真的没有办法吗?

悲酥清风 (2001-04-05 20:50:00)
supershan:请自己提前或结束你的帖子,谢谢合作。

jiangone (2001-04-13 13:43:00)
这么多好方法, 你听到没有?

cnaoszh (2001-06-22 11:23:00)
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TSrbIoControl = packed record
HeaderLength : ULONG;
Signature : Array[0..7] of Char;
Timeout : ULONG;
ControlCode : ULONG;
ReturnCode : ULONG;
Length : ULONG;
end;

SRB_IO_CONTROL = TSrbIoControl;
PSrbIoControl = ^TSrbIoControl;

TIDERegs = packed record
bFeaturesReg : Byte;
// Used for specifying SMART "commands".
bSectorCountReg : Byte;
// IDE sector count register
bSectorNumberReg : Byte;
// IDE sector number register
bCylLowReg : Byte;
// IDE low order cylinder value
bCylHighReg : Byte;
// IDE high order cylinder value
bDriveHeadReg : Byte;
// IDE drive/head register
bCommandReg : Byte;
// Actual IDE command.
bReserved : Byte;
// reserved. Must be zero.
end;
IDEREGS = TIDERegs;
PIDERegs = ^TIDERegs;

TSendCmdInParams = packed record
cBufferSize : DWORD;
irDriveRegs : TIDERegs;
bDriveNumber : Byte;
bReserved : Array[0..2] of Byte;
dwReserved : Array[0..3] of DWORD;
bBuffer : Array[0..0] of Byte;
end;
SENDCMDINPARAMS = TSendCmdInParams;
PSendCmdInParams = ^TSendCmdInParams;

TIdSector = packed record
wGenConfig : Word;
wNumCyls : Word;
wReserved : Word;
wNumHeads : Word;
wBytesPerTrack : Word;
wBytesPerSector : Word;
wSectorsPerTrack : Word;
wVendorUnique : Array[0..2] of Word;
sSerialNumber : Array[0..19] of Char;
wBufferType : Word;
wBufferSize : Word;
wECCSize : Word;
sFirmwareRev : Array[0..7] of Char;
sModelNumber : Array[0..39] of Char;
wMoreVendorUnique : Word;
wDoubleWordIO : Word;
wCapabilities : Word;
wReserved1 : Word;
wPIOTiming : Word;
wDMATiming : Word;
wBS : Word;
wNumCurrentCyls : Word;
wNumCurrentHeads : Word;
wNumCurrentSectorsPerTrack : Word;
ulCurrentSectorCapacity : ULONG;
wMultSectorStuff : Word;
ulTotalAddressableSectors : ULONG;
wSingleWordDMA : Word;
wMultiWordDMA : Word;
bReserved : Array[0..127] of Byte;
end;
PIdSector = ^TIdSector;

const
IDE_ID_FUNCTION = $EC;
IDENTIFY_BUFFER_SIZE = 512;
DFP_RECEIVE_DRIVE_DATA = $0007c088;
IOCTL_SCSI_MINIPORT = $0004d008;
IOCTL_SCSI_MINIPORT_IDENTIFY = $001b0501;
DataSize = sizeof(TSendCmdInParams)-1+IDENTIFY_BUFFER_SIZE;
BufferSize = SizeOf(SRB_IO_CONTROL)+DataSize;
W9xBufferSize = IDENTIFY_BUFFER_SIZE+16;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.DFM}
procedure ChangeByteOrder( var Data;
Size : Integer );
var ptr : PChar;
i : Integer;
c : Char;
begin
ptr := @Data;
for i := 0 to (Size shr 1)-1do
begin
c := ptr^;
ptr^ := (ptr+1)^;
(ptr+1)^ := c;
Inc(ptr,2);
end;
end;

function GetIdeDiskSerialNumber : String;
var
hDevice : THandle;
cbBytesReturned : DWORD;
pInData : PSendCmdInParams;
pOutData : Pointer;
// PSendCmdOutParams
Buffer : Array[0..BufferSize-1] of Byte;
srbControl : TSrbIoControl absolute Buffer;
begin
Result := '';
FillChar(Buffer,BufferSize,#0);
if Win32Platform=VER_PLATFORM_WIN32_NT then
begin
// Windows NT, Windows 2000
// Get SCSI port handle
hDevice := CreateFile( '//./Scsi0:',
GENERIC_READ or GENERIC_WRITE,
FILE_SHARE_READ or FILE_SHARE_WRITE,
nil, OPEN_EXISTING, 0, 0 );
if hDevice=INVALID_HANDLE_VALUE then
Exit;
try
srbControl.HeaderLength := SizeOf(SRB_IO_CONTROL);
System.Move('SCSIDISK',srbControl.Signature,8);
srbControl.Timeout := 2;
srbControl.Length := DataSize;
srbControl.ControlCode := IOCTL_SCSI_MINIPORT_IDENTIFY;
pInData := PSendCmdInParams(PChar(@Buffer)
+SizeOf(SRB_IO_CONTROL));
pOutData := pInData;
with pInData^do
begin
cBufferSize := IDENTIFY_BUFFER_SIZE;
bDriveNumber := 0;
with irDriveRegsdo
begin
bFeaturesReg := 0;
bSectorCountReg := 1;
bSectorNumberReg := 1;
bCylLowReg := 0;
bCylHighReg := 0;
bDriveHeadReg := $A0;
bCommandReg := IDE_ID_FUNCTION;
end;
end;
if not DeviceIoControl( hDevice, IOCTL_SCSI_MINIPORT,
@Buffer, BufferSize, @Buffer, BufferSize,
cbBytesReturned, nil ) then
Exit;
finally
CloseHandle(hDevice);
end;
end
else
begin
// Windows 95 OSR2, Windows 98
hDevice := CreateFile( '//./SMARTVSD', 0, 0, nil,
CREATE_NEW, 0, 0 );
if hDevice=INVALID_HANDLE_VALUE then
Exit;
try
pInData := PSendCmdInParams(@Buffer);
pOutData := @pInData^.bBuffer;
with pInData^do
begin
cBufferSize := IDENTIFY_BUFFER_SIZE;
bDriveNumber := 0;
with irDriveRegsdo
begin
bFeaturesReg := 0;
bSectorCountReg := 1;
bSectorNumberReg := 1;
bCylLowReg := 0;
bCylHighReg := 0;
bDriveHeadReg := $A0;
bCommandReg := IDE_ID_FUNCTION;
end;
end;
if not DeviceIoControl( hDevice, DFP_RECEIVE_DRIVE_DATA,
pInData, SizeOf(TSendCmdInParams)-1, pOutData,
W9xBufferSize, cbBytesReturned, nil ) then
Exit;
finally
CloseHandle(hDevice);
end;
end;
with PIdSector(PChar(pOutData)+16)^do
begin
ChangeByteOrder(sSerialNumber,SizeOf(sSerialNumber));
SetString(Result,sSerialNumber,SizeOf(sSerialNumber));
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
EDIT1.TEXT:=TRIM(GetIdeDiskSerialNumber);
end;

end.

//win98要 c:/windows/system/的smartvsd.vxd
//copy to c:/windows/system/iosubsys
//reboot your computer and ok
//2000 and ntdo
not need

brianyu (2001-09-18 11:29:00)
pcexplorer 的方法我测试了一下,不能编译
mov word ptr dd[ecx*2],ax 时报错 in line assembles syntax error

bzmouse (2001-09-18 11:36:00)
我有一个读cpu程序,好象带源码,我要找找,你要不要?

goddy (2001-09-18 12:49:00)
不错

engleking (2001-09-18 14:06:00)
读CPU的,只要一个CPUID指令就可以了。

zl (2001-09-18 14:13:00)
是不是每块硬盘都有唯一的序列号(物理的,不是逻辑的)?

zc (2001-09-18 14:47:00)
硬盘有唯一的物理序列号,CPU的是型号。读硬盘序列号程序:
http://chiro.myrice.com/software/DiskInfo.zip
可用于9x/nt/2000,不过9x下需要将SMARTVSD.vxd复制到Windows/system/iosubsys下。

源程序用delphi写的,不用VXD。不用SMARTVSD的也有,不过是拿C++写的。

dandywesley (2001-09-19 19:10:00)
我写的一个VCL保证好用在http://home.online.tj.cn/user/dandy/
全面支持WIN9X/ME/NT/2K/XP
可配合D4,D5,D6,CB4,CB5使用。

angelsoft (2001-09-21 01:47:00)
To dandywesley:
我试了你写的程序,发现在我的电脑上(win98 sr2)无法得到硬盘序列号,我的硬盘肯
定是有序列号的!这是为何,在win95上可以得到

GodWave (2001-09-21 02:12:00)
我也与angelsoft说的情况一样,我的主板也读不出

iwalk (2001-09-21 10:43:00)
关注

brianyu (2001-09-21 10:44:00)
To dandywesley:
我用了你的程序,发现如下问题:
读硬盘序列号的EXE可以执行,也能够读出来
但是读主板和CPU编号的EXE执行的时候就非法操作,具体表现在:
mbinf:=Pchar(Ptr($FEC71));
for i:=11 to LENGTH(string(mbinf))do
FMBinfo:=FMBinfo+mbinf;
//次编号前十一位是Bios升级日期,舍掉
的代码段时候。
我的机器环境:WINNT4.0中文版+SP6

dana (2001-09-21 10:47:00)
up

lwaif (2001-09-21 10:49:00)
关注

goddy (2001-09-21 10:53:00)
csdn上就有我昨天剛下源文件

 
多人接受答案了。
 
顶部