📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils,Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, JwaWinIoctl, Buttons, ExtCtrls, ComCtrls;
type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
Panel2: TPanel;
Label3: TLabel;
ComboBox2: TComboBox;
Button6: TButton;
Label4: TLabel;
Label6: TLabel;
Timer1: TTimer;
Label8: TLabel;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
GroupBox6: TGroupBox;
Panel1: TPanel;
GroupBox2: TGroupBox;
Button2: TButton;
Button3: TButton;
Edit3: TEdit;
CheckBox2: TCheckBox;
GroupBox1: TGroupBox;
Button1: TButton;
CheckBox1: TCheckBox;
GroupBox3: TGroupBox;
Panel3: TPanel;
GroupBox4: TGroupBox;
Label9: TLabel;
Label10: TLabel;
Button4: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit4: TEdit;
Edit5: TEdit;
GroupBox5: TGroupBox;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Button5: TButton;
Edit6: TEdit;
Edit7: TEdit;
Edit8: TEdit;
Edit9: TEdit;
Memo3: TMemo;
Button7: TButton;
Button8: TButton;
Panel4: TPanel;
Memo2: TMemo;
Panel5: TPanel;
Button9: TButton;
Button10: TButton;
ComboBox1: TComboBox;
Label1: TLabel;
Label2: TLabel;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure ComboBox2Change(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure Edit2Change(Sender: TObject);
procedure Edit4Change(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
procedure getescapetime(Sender: TObject);
public
{ Public declarations }
end;
var
handle22:Tthread;
Form1: TForm1;
alarmmess:integer;
QBytesPerSector: integer = 512;
QSectorCount: integer = 1; //读写扇区数
QSectorStart: integer = 0; //起始扇区数
Qdiskname: pchar;// = '//./PHYSICALDRIVE2'; //驱动盘
mmcfile:string;//mmc镜像文件
mmciss7: boolean; //判断是否为西门子300 mmc 0=否 1=是
oprationobject: boolean; //操作对象0=对磁盘操作 1= 对文件操作
findpass: boolean; //1=找到密码所存放的扇区;
passsector: integer; //密码扇区
passbuff: array[0..8] of char;
password: string;
strdisknum:string;//磁盘序号
str2 :string= 'Original Siemens Equipment. Use only with Siemens SIMATIC. Do not format or partition';
totalsector:int64;
Geometry1: DISK_GEOMETRY_EX ;
sector_mmc_start:int64; //
sector_mmc_end:int64;
sector_file_start:int64;
sector_file_end:int64;
sector_file_total:int64;
filename1:string;
filehand2:THandle;
sectonum:integer=32;
implementation
uses diskop, Unit2;
{$R *.dfm}
Var
timeescaped, tickcount1,tickcount2:int64;
procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
pbuff, pbuff2: pchar;
temp, temp1, temp2,temp3,temp4: integer;
str: string;
s: string;
k, j, m: integer;
finded:boolean;
begin
temp3:=0;
temp4:=0;
findpass := false;
finded:=false;
//读取零扇区判断是否为正确MM卡
QSectorCount := 1; //读写扇区数
QSectorStart := 0; //起始扇区数
pbuff := allocmem(QSectorCount * QBytesPerSector); // 必须是新申请的内存或全局变量,不能是局部变量
if CheckBox1.Checked then
begin
if OpenDialog1.Execute then
begin
Qdiskname:= pchar( OpenDialog1.FileName);
label6.Caption:=Qdiskname;
logicdiskread(Qdiskname, //驱动盘或文件名称
QSectorStart, //起始扇区数
QSectorCount, //读写扇区数
QBytesPerSector, //扇区大小
pbuff[0]);
end;
end else
begin
logicdiskread(Qdiskname, //驱动盘或文件名称
QSectorStart, //起始扇区数
QSectorCount, //读写扇区数
QBytesPerSector, //扇区大小
pbuff[0]);
end;
memo1.Lines.Add('操作对象'+Qdiskname);//
str := '';
for i := 0 to QBytesPerSector - 1 do
begin
str := str + Format('%.2x', [integer(pbuff[i])]) + ' ';
if i mod 16 = 15 then
str := str + #13;
end;
setstring(s, pbuff, 85);
if comparetext(s, str2) = 0 then mmciss7 := true;
if not mmciss7 then
begin
if Application.MessageBox('好像不是mmc卡文件!!!继续操作可能问题' + #13#10 +
'是否继续', '警告', MB_YESNO + MB_DEFBUTTON2 + MB_TOPMOST) =
IDNO then
begin
memo1.Lines.Add(s) ;
memo1.Lines.Add('好像不是mmc卡文件!!继续操作可能问题.选择退出');
exit;
end else
begin
memo1.Lines.Add(s) ;
memo1.Lines.Add('好像不是mmc卡文件!!继续操作可能问题.选择继续');
end
end;
FreeMem(pbuff, QSectorCount * QBytesPerSector); // 使用完后需要释放内存
//若正确则继续执行寻找密码存放扇区
//查找200h 地址 扇区号 1 取出地址228h 连续4 字节 获取系统信息所在扇区
//根据扇区号 查找 01 0b 00 00 取出 后面连续4 个字 最后一个字 为密码存放扇区号
finded:=false;
QSectorCount := 1; //读写扇区数
QSectorStart := 1; //起始扇区数
pbuff := allocmem(QSectorCount * QBytesPerSector);
logicdiskread(Qdiskname, //驱动盘或文件名称
QSectorStart, //起始扇区数
QSectorCount, //读写扇区数
QBytesPerSector, //扇区大小
pbuff[0]);
temp:=0;
temp3:= integer(pbuff[42]) + integer(pbuff[43]) shl 8;
FreeMem(pbuff, QSectorCount * QBytesPerSector); // 使用完后需要释放内存
QSectorCount := 1; //读写扇区数
QSectorStart := temp3; //起始扇区数
pbuff := allocmem(QSectorCount * QBytesPerSector);
logicdiskread(Qdiskname, //驱动盘或文件名称
QSectorStart, //起始扇区数
QSectorCount, //读写扇区数
QBytesPerSector, //扇区大小
pbuff[0]);
for j := 0 to 32 - 1 do // Iterate
begin
//
if ((pbuff[j * 16 + 0] = char($01)) and (pbuff[j * 16 + 1] = char($0B)) and (pbuff[j * 16 + 2] = char($00)) and (pbuff[j * 16 + 3] = char($00)))
then
begin
findpass := true;
temp4:=integer(pbuff[j * 16 + 6]);
end;
if findpass then //如果存在则找到所在扇区
begin
passsector := integer(pbuff[j * 16 + 10]) + integer(pbuff[j * 16 + 11]) shl 8;
//读取密码扇区 西门子300密码存放在 偏移54H处 往后8 个字节
QSectorCount := 1; //读写扇区数
QSectorStart := passsector; //起始扇区数
pbuff2 := allocmem(QSectorCount * QBytesPerSector);
logicdiskread(Qdiskname, //驱动盘或文件名称
QSectorStart, //起始扇区数
QSectorCount, //读写扇区数
QBytesPerSector, //扇区大小
pbuff2[0]);
password := '';
temp1 := 0;
temp2 := 0;
for m := 0 to 3 do // Iterate
begin
temp1 := integer(pbuff2[m * 2 + temp4 - 92 + 1]) + integer(pbuff2[temp4 - 92 + m * 2]) shl 8;
temp := temp1 xor$aaaa xor temp2;
temp2 := temp1;
password := password + char(temp shr 8) + char(temp);
end; // for
memo1.Lines.Add('找到密码:'+password);
// memo1.Text := memo1.Text + ' ' + password;
finded:=true;
FreeMem(pbuff2, QSectorCount * QBytesPerSector);
end;
findpass := false;
end; // for j
findpass := false;
FreeMem(pbuff, QSectorCount * QBytesPerSector); // 使用完后需要释放内存
(*
//若正确则继续执行寻找密码存放扇区
//查找2000h-4000h (即扇区10-20)找到在8倍数地址处
//查找 01 0b 00 00 取出后面的连续4个字值
//最后一个字为密码存放处扇区号码(从零开始)。
finded:=false;
for k := 16 to 32 - 1 do // Iterate
begin
QSectorCount := 1; //读写扇区数
QSectorStart := k; //起始扇区数
pbuff := allocmem(QSectorCount * QBytesPerSector);
logicdiskread(Qdiskname, //驱动盘或文件名称
QSectorStart, //起始扇区数
QSectorCount, //读写扇区数
QBytesPerSector, //扇区大小
pbuff[0]);
findpass := false;
for j := 0 to 32 - 1 do // Iterate
begin
//
if ((pbuff[j * 16 + 0] = char($01)) and (pbuff[j * 16 + 1] = char($0B)) and (pbuff[j * 16 + 2] = char($00)) and (pbuff[j * 16 + 3] = char($00)))
then findpass := true;
if findpass then //如果存在则找到所在扇区
begin
passsector := integer(pbuff[j * 16 + 10]) + integer(pbuff[j * 16 + 11]) shl 8;
//读取密码扇区 西门子300密码存放在 偏移54H处 往后8 个字节
QSectorCount := 1; //读写扇区数
QSectorStart := passsector; //起始扇区数
pbuff2 := allocmem(QSectorCount * QBytesPerSector);
logicdiskread(Qdiskname, //驱动盘或文件名称
QSectorStart, //起始扇区数
QSectorCount, //读写扇区数
QBytesPerSector, //扇区大小
pbuff2[0]);
password := '';
temp1 := 0;
temp2 := 0;
for m := 0 to 3 do // Iterate
begin
temp1 := integer(pbuff2[m * 2 + 84 + 1]) + integer(pbuff2[84 + m * 2]) shl 8;
temp := temp1 xor$aaaa xor temp2;
temp2 := temp1;
password := password + char(temp shr 8) + char(temp);
end; // for
memo1.Lines.Add('找到密码:'+password);
// memo1.Text := memo1.Text + ' ' + password;
finded:=true;
FreeMem(pbuff2, QSectorCount * QBytesPerSector);
end;
findpass := false;
end; // for j
FreeMem(pbuff, QSectorCount * QBytesPerSector); // 使用完后需要释放内存
end; // for k *)
if (not finded) then
memo1.Lines.Add (' 没有找到') ;
finded:=false;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
mmciss7 := false;
oprationobject := false;
Label4.Caption:='';
Qdiskname:= '//./PHYSICALDRIVE2 '; //驱动盘
Qdiskname:='';
Button8.Enabled:=false;
end;
procedure TForm1.Button6Click(Sender: TObject);
var
str: string;
drivers: integer;
driver: char;
i, temp: integer;
begin
ComboBox2.Clear;
drivers := getlogicaldrives;
temp := (1 and drivers);
for i := 0 to 25 do //26个英文字母
begin
if temp = 1 then
begin
driver := char(i + integer('a'));
str := driver + ':';
ComboBox2.Items.Add(str) ;
end;
drivers := (drivers shr 1);
temp := (1 and drivers);
end;
end;
procedure TForm1.ComboBox2Change(Sender: TObject);
var
drivetype:integer;
VolumeName, FileSystemName: array[0..MAX_PATH-1] of char;
VolumeSerialNumber, MaxFilenameLength, FileSystemFlags: DWord;
begin
Label4.Caption:=ComboBox2.Items[ComboBox2.ItemIndex]+#13#10;
if ComboBox2.ItemIndex >=0 then
begin
drivetype :=getdrivetype(pchar(ComboBox2.Items[ComboBox2.ItemIndex]));
case drivetype of
0: label4.Caption:=Label4.Caption+ '未知类型 ' +#13#10;
1: Label4.Caption:=Label4.Caption+ '根驱动器不存在 ' +#13#10 ;
DRIVE_REMOVABLE : Label4.Caption:=Label4.Caption+ '可移动磁盘 ' +#13#10 ;
DRIVE_FIXED : Label4.Caption:=Label4.Caption+ '固定磁盘 ' +#13#10 ;
DRIVE_REMOTE: Label4.Caption:=Label4.Caption+ '网络磁盘 ' +#13#10 ;
DRIVE_CDROM : Label4.Caption:=Label4.Caption+ '光驱 ' +#13#10 ;
DRIVE_RAMDISK : Label4.Caption:=Label4.Caption+ 'RAM磁盘 ' +#13#10 ;
else
Label4.Caption:= '未知错误' ;
end; //end case
//获取分区所在磁盘号
if GetVolumeInfo(pchar(ComboBox2.Items[ComboBox2.ItemIndex])).DiskNumber =$ff then
begin
Label4.Caption:=Label4.Caption+ '磁盘序号'+'error '+#13#10 ; //+inttostr( GetVolumeInfo(pchar(ComboBox2.Items[ComboBox2.ItemIndex])).DiskNumber) ;
Label6.Caption:='出现错误 不能打开此驱动器 ';
Label8.Caption:='';
sector_mmc_start:=0;
sector_mmc_end:=0;
sector_file_start:=0;
sector_file_end:=0;
sector_file_total:=0;
edit2.Text:=inttostr(sector_file_start);
edit4.Text:=inttostr(sector_file_end);
edit7.Text:=inttostr(sector_file_start);
edit8.Text:=inttostr(sector_file_end);
edit1.Text:=inttostr(sector_mmc_start);
edit5.Text:=inttostr(sector_mmc_end);
edit6.Text:=inttostr(sector_mmc_start);
edit9.Text:=inttostr(sector_mmc_end);
end else
begin
Label4.Caption:=Label4.Caption+ '磁盘序号'+inttostr( GetVolumeInfo(pchar(ComboBox2.Items[ComboBox2.ItemIndex])).DiskNumber)+#13#10 ;
strdisknum:= '//./PHYSICALDRIVE'+inttostr( GetVolumeInfo(pchar(ComboBox2.Items[ComboBox2.ItemIndex])).DiskNumber) ;
Qdiskname:='';
Qdiskname:=pchar(strdisknum); //驱动盘
Label6.Caption:=Qdiskname;
Geometry1:= GetDiskGeometry(Qdiskname) ;
label8.Caption:= '';
label8.Caption:= label8.Caption+'柱面数 '+inttostr( int64(Geometry1.Geometry.Cylinders ))+' ' +#13#10 ;
// label8.Caption:='c ' Geometry1.MediaType
label8.Caption:= label8.Caption+'每柱磁道数 '+inttostr(int64( Geometry1.Geometry.TracksPerCylinder ))+' ' +#13#10 ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -