📄 unit1.pas
字号:
label8.Caption:= label8.Caption+'每道扇区数 '+inttostr(int64( Geometry1.Geometry.SectorsPerTrack)) +' '+#13#10 ;
label8.Caption:= label8.Caption+'每扇字节数 '+inttostr(int64 ( Geometry1.Geometry.BytesPerSector ) )+' ' +#13#10 ;
totalsector:= int64( Geometry1.Geometry.TracksPerCylinder ) *int64( Geometry1.Geometry.SectorsPerTrack) *int64(Geometry1.Geometry.Cylinders );
label8.Caption:= label8.Caption+'总共扇区数(计算) '+inttostr(totalsector )+' ' +#13#10 ;
if ((Geometry1.DiskSize.QuadPart mod Geometry1.Geometry.BytesPerSector)=0) then
begin
LABEL8.Caption:= label8.Caption+'总共扇区数(返回) '+inttostr( (Geometry1.DiskSize.QuadPart) div Geometry1.Geometry.BytesPerSector );
totalsector:= (Geometry1.DiskSize.QuadPart div Geometry1.Geometry.BytesPerSector );
end
else LABEL8.Caption:= label8.Caption+'出现错误非整扇区' +inttostr( (Geometry1.DiskSize.QuadPart) div Geometry1.Geometry.BytesPerSector );
sector_mmc_start:=0;
if (totalsector>=1) then sector_mmc_end:=totalsector-1 else sector_mmc_end:=0;
sector_file_start:=0;
sector_file_end:=sector_mmc_end;
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;
if GetVolumeInformation(pchar(ComboBox2.Items[ComboBox2.ItemIndex]+'\'),//root directory
VolumeName, // volume name buffer
MAX_PATH, // length of name buffer
@VolumeSerialNumber, // volume serial number
MaxFilenameLength,// maximum file name length
FileSystemFlags,// file system options
FileSystemName, // file system name buffer
MAX_PATH) // length of file system name buffer
then
begin
label1.Caption:='卷名: ' + VolumeName + ' ' +#13#10 +
'序列号: ' +inttohex(VolumeSerialNumber,4) + ' ' +#13#10 +
'文件系统: ' +inttohex(FileSystemFlags,4) + ' ' +#13#10 +
'文件系统名称' + FileSystemName+ ' ' +#13#10 +
SysErrorMessage(GetLastError);
label2.Caption:='';
end else
begin
label2.Caption:= SysErrorMessage(GetLastError)+' '+#13#10;
Label1.Caption:='';
end;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
alarmmess:= alarmmess+1;
case alarmmess mod 5 of //
0: form1.Caption:='S7300 64 128 KB MMC卡工具 ';
1: form1.Caption:='本工具仅供测试与研究勿用与非法用途,对所造成的损失由使用者自负 ';
2: form1.Caption:='本工具仅供内部使用勿随意传播 ';
3: form1.Caption:='作者对使用本工具所造成的一切后果免责';
4: form1.Caption:='若您正在使用本工具,说明您已同意以上信息 ';
end; // case
end;
procedure TForm1.Button4Click(Sender: TObject);
var
I: Integer;
hdiskhand1:THandle;
hfilehand:THandle;
errorcount:integer;//出现错误重试次数;连续三次则不读取跳过
pbuff:pchar;
str,s: string;
fileneedcreat:boolean;
begin
errorcount:=0;
fileneedcreat:=false;
if sector_mmc_end<>0 then
begin
//读取零扇区判断是否为正确MM卡
QSectorCount := 1; //读写扇区数
QSectorStart := 0; //起始扇区数
pbuff := allocmem(QSectorCount * QBytesPerSector); // 必须是新申请的内存或全局变量,不能是局部变量
logicdiskread(Qdiskname, //驱动盘或文件名称
QSectorStart, //起始扇区数
QSectorCount, //读写扇区数
QBytesPerSector, //扇区大小
pbuff[0]);
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
memo2.Lines.Add(s) ;
memo2.Lines.Add('好像不是mmc卡文件!!!') ;
exit;
end
end;
memo2.Lines.Add(s) ;
memo2.Lines.Add('好像是mmc卡文件') ;
FreeMem(pbuff, QSectorCount * QBytesPerSector); // 使用完后需要释放内存
//创建目录
if not DirectoryExists(application.GetNamePath+'data') then //二次目录存在否
CreateDirectory(PChar(application.GetNamePath+'data'),nil); //创建目录
//创建文件 app
filename1:=application.GetNamePath+'data/'+FormatdateTime('yy/mm/dd/hh.nn.ss',now)+'-'+
inttostr( sector_mmc_start)+'-' + inttostr( sector_file_start)+'-'+
inttostr( sector_file_end)+ '-'+ inttostr( sector_mmc_end)+'.mmc';
if Fileexists(filename1) then //判断是否存在
begin
if Application.MessageBox('旧文件已存在!!!' + #13#10 +
'是否覆盖文件', '警告', MB_YESNO + MB_DEFBUTTON2 + MB_TOPMOST) =
IDNO then
begin
fileneedcreat:=false;
exit //退出
end
else
begin
//需要创建
fileneedcreat:=true;
end;
end else fileneedcreat:=true;
if fileneedcreat=True then
begin
FileHand2 := FileCreate(filename1);
FileClose(FileHand2);
end;
//创建线程开始读取制定扇区范围
tickcount1:=gettickcount;
handle22:=mmcread.Create(false) ;
button8.Enabled:=true;
handle22. OnTerminate := getescapetime;
end;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
if GroupBox3.Visible=false then
GroupBox3.Visible:=true
else GroupBox3.Visible:=false;
end;
procedure TForm1.Edit2Change(Sender: TObject);
var
temp:int64;
begin
sector_file_start:=sector_mmc_start;
temp:=strtoint(edit2.Text);
sector_file_start:=temp;
if (temp<=sector_mmc_start) then
begin
sector_file_start:=sector_mmc_start;
end;
if (temp>=sector_file_end) then
begin
sector_file_start:=sector_file_end;
end;
edit2.Text:=inttostr( sector_file_start);
end;
procedure TForm1.Edit4Change(Sender: TObject);
var
temp:int64;
begin
sector_file_end:=sector_mmc_end;
temp:=strtoint(edit4.Text);
sector_file_end:=temp;
if (temp>=sector_mmc_end) then
begin
sector_file_end:=sector_mmc_end;
end;
if (temp<=sector_file_start) then
begin
sector_file_end:=sector_file_start;
end;
edit4.Text:=inttostr( sector_file_end);
end;
procedure TForm1.getescapetime(Sender: TObject);
begin
tickcount2:=gettickcount;
timeescaped:=tickcount2-tickcount1;
memo2.Lines.Add( '总共耗时 '+inttostr(timeescaped));
Button8.Enabled:=false;
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
sectonum:=strtoint(ComboBox1.Items[ComboBox1.ItemIndex] );
end;
procedure TForm1.Button3Click(Sender: TObject);
var
I: Integer;
pbuff, pbuff2: pchar;
temp, temp1, temp2,temp3,temp4: integer;
str: string;
s: string;
k, j, m: integer;
finded:boolean;
handle22:THandle;
begin
temp3:=0;
temp4:=0;
findpass := false;
finded:=false;
//读取零扇区判断是否为正确MM卡
QSectorCount := 1; //读写扇区数
QSectorStart := 0; //起始扇区数
pbuff := allocmem(QSectorCount * QBytesPerSector); // 必须是新申请的内存或全局变量,不能是局部变量
if CheckBox2.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('好像不是mmc卡文件!!继续操作可能问题.选择退出');
exit;
end else memo1.Lines.Add('好像不是mmc卡文件!!继续操作可能问题.选择继续');
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]);
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
begin
findpass := true;
finded:=true;
pbuff[j * 16 + 0] := char($00);
pbuff[j * 16 + 1] := char($00) ;
handle22 := CreateFile(Qdiskname,
GENERIC_ALL,
FILE_SHARE_write ,
nil,
OPEN_EXISTING,
0,
0 );
FileSeek(handle22, QSectorStart * QBytesPerSector, 0) ;
if (handle22 = INVALID_HANDLE_VALUE) then
begin
memo1.Lines.Add('创建设备错误:'+SysErrorMessage(GetLastError));
exit;
end;
// 清除密码
if Filewrite(handle22, pbuff[0], QSectorCount * QBytesPerSector) <> QSectorCount * QBytesPerSector then//读扇区
begin
memo1.Lines.Add('文件写入错误 非整扇区'+SysErrorMessage(GetLastError));
raise Exception.Create('Read Error!');
exit;
end ;
CloseHandle(handle22);
memo1.Lines.Add('清除完成') ;
end;
end; // for j *)
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
begin
findpass := true;
finded:=true;
pbuff[j * 16 + 0] := char($00);
pbuff[j * 16 + 1] := char($00) ;
handle22 := CreateFile(Qdiskname,
GENERIC_ALL,
FILE_SHARE_write ,
nil,
OPEN_EXISTING,
0,
0 );
FileSeek(handle22, QSectorStart * QBytesPerSector, 0) ;
if (handle22 = INVALID_HANDLE_VALUE) then
begin
memo1.Lines.Add('创建设备错误:'+SysErrorMessage(GetLastError));
exit;
end;
清除密码
if Filewrite(handle22, pbuff[0], QSectorCount * QBytesPerSector) <> QSectorCount * QBytesPerSector then//读扇区
begin
memo1.Lines.Add('文件写入错误 非整扇区'+SysErrorMessage(GetLastError));
raise Exception.Create('Read Error!');
exit;
end ;
CloseHandle(handle22);
memo1.Lines.Add('清除完成') ;
end;
end; // for j
FreeMem(pbuff, QSectorCount * QBytesPerSector); // 使用完后需要释放内存
end; // for k *)
if (not finded) then
memo1.Text := memo1.Text + ' 没有找到' ;
finded:=false;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -