📄 unitmain.pas
字号:
unit UnitMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,registry,math;
const
FILE_DEVICE_UNKNOWN=$00000022;
METHOD_NEITHER=3;
FILE_ANY_ACCESS=0;
DIOC_MY1=FILE_DEVICE_UNKNOWN shl 16 +
1 shl 2+
METHOD_NEITHER +
FILE_ANY_ACCESS shl 14;
type
TMemoryRW=packed record
ReadOrNot:BOOL;
Segment,Offset:WORD;
Count:WORD;
end;
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
OpenDialog1: TOpenDialog;
Button3: TButton;
ListBox1: TListBox;
Label1: TLabel;
Label2: TLabel;
Label4: TLabel;
Edit2: TEdit;
Edit4: TEdit;
Edit3: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
vxd:longword;
filename:string;
buffer:pchar;
implementation
{$R *.DFM}
procedure TForm1.Button2Click(Sender: TObject);
begin
OpenDialog1.FileName:=edit1.text;
if OpenDialog1.Execute then
edit1.text:=OpenDialog1.FileName;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
RecBytes:Cardinal;
i:integer;
s:string;
Buffer:Pchar;
t:TMemoryRW;
begin
if strtoint('$'+edit2.text)>$FFFF then
begin
messagedlg('段地址不能超过$FFFF',mtwarning,[mbok],0);
exit;
end;
t.Segment:=strtoint('$'+edit2.text);
if strtoint('$'+edit3.text)>$FFFF then
begin
messagedlg('偏移量不能超过$FFFF',mtwarning,[mbok],0);
exit;
end;
t.Offset:=strtoint('$'+edit3.text);
if strtoint('$'+edit4.text)>$FFFF then
begin
messagedlg('不能读取超过$FFFF的数据',mtwarning,[mbok],0);
exit;
end;
listbox1.clear;
t.Count:=min(strtoint('$'+edit4.text),$10000-t.Offset);
if t.count=0 then exit;
t.ReadOrNot:=true; {读}
getmem(Buffer,t.Count);
if DeviceIoControl(vxd,DIOC_MY1,@t,sizeof(TMemoryRW),Buffer,t.Count,RecBytes,nil) and
(RecBytes=t.Count) then
begin
s:='';
for i:=0 to t.Count-1 do
begin
s:=s+format('%.2x ',[ord(buffer[i])]);
if (i mod 16=15)or(i=t.Count-1) then
begin
listbox1.items.add(s);
s:='';
end;
end;
{ t.ReadOrNot:=false; //写
if DeviceIoControl(vxd,DIOC_MY1,@t,sizeof(TMemoryRW),Buffer,t.Count,RecBytes,nil) and
(RecBytes=t.Count) then
else showmessage('write error'); }
end;
freemem(Buffer,t.Count);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
t:TMemoryRW;
RecBytes:Cardinal;
Buffer:Pchar;
i:integer;
begin
if button1.Caption='开始' then
begin
vxd:=createfile(pchar('\\.\'+edit1.text),0,0,nil,Create_new,File_Flag_Delete_On_Close,0);
if vxd=invalid_handle_value then
begin
filename:=extractfilename(edit1.text);
copyfile(pchar(edit1.text),pchar(filename),false);
vxd:=createfile(pchar('\\.\'+filename),0,0,nil,Create_new,File_Flag_Delete_On_Close,0);
if vxd=invalid_handle_value then deletefile(filename);
end
else filename:='';
if vxd<>invalid_handle_value then
begin
button1.Caption:='结束';
Button3.Enabled:=true;
end;
end
else begin
if filename<>'' then deletefile(filename);
button1.Caption:='开始';
Button3.Enabled:=false;
end;
t.Segment:=$F;
t.Offset:=$FFF5;
t.Count:=$B;
t.ReadOrNot:=true; {读}
getmem(Buffer,t.Count);
if DeviceIoControl(vxd,DIOC_MY1,@t,sizeof(TMemoryRW),Buffer,t.Count,RecBytes,nil) and
(RecBytes=t.Count) then
begin
Listbox1.Items.Add('BIOS日期:'+Buffer);
end;
//串口
t.Segment:=$0;
t.Offset:=$400;
t.Count:=$E;
t.ReadOrNot:=true; {读}
getmem(Buffer,t.Count);
if DeviceIoControl(vxd,DIOC_MY1,@t,sizeof(TMemoryRW),Buffer,t.Count,RecBytes,nil) and
(RecBytes=t.Count) then
begin
for i:=0 to 3 do
begin
listbox1.Items.add(format('串口%d输入/输出范围: %X',[i+1,pword(@Buffer[i*2])^]));
end;
for i:=0 to 2 do
begin
listbox1.Items.add(format('并口%d输入/输出范围: %X',[i+1,pword(@Buffer[8+i*2])^]));
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -