jmain.pas
来自「Delphi Source for work with Siemens Mobi」· PAS 代码 · 共 1,729 行 · 第 1/4 页
PAS
1,729 行
Application.ProcessMessages;
if (Not flgBootLoad) or flgBFBExit then exit;
Sleep(50);
end;
if (Not flgBootLoad) or flgBFBExit then exit;
if mode=$02 then begin
for i:=0 to 33 do begin
ProgressBar.StepBy(1);
Application.ProcessMessages;
if (Not flgBootLoad) or flgBFBExit then exit;
Sleep(50);
end;
end;
if RadioGroupBaud.ItemIndex<>0 then begin
if SetSpeedBFB(115200) then begin
AddLinesLog('BFB Speed 115200 Baud - Ok.');
iComBaud:=115200;
end;
end;
Application.ProcessMessages;
if (Not flgBootLoad) or flgBFBExit then exit;
if BFB_Ping or BFB_Ping or BFB_Ping then begin
result:=True;
exit;
end;
if GetComDCB then iComBaud:=dcb.BaudRate;
CloseCom;
if Not OpenCom(CheckBoxIgnitionMode.Checked) then begin
AddLinesLog('No reopen Com'+IntToStr(iComNum)+'!');
exit;
end;
SetComRxTimeouts(100,2,200);
end
else if x=30 then begin
if GetComDCB then iComBaud:=dcb.BaudRate;
CloseCom;
if Not OpenCom(CheckBoxIgnitionMode.Checked) then begin
AddLinesLog('No reopen Com'+IntToStr(iComNum)+'!');
exit;
end;
SetComRxTimeouts(100,2,200);
end;
ProgressBar.StepBy(1);
Application.ProcessMessages;
if (Not flgBootLoad) or flgBFBExit then exit;
Sleep(50);
if mode=$02 then begin
ProgressBar.StepBy(1);
Application.ProcessMessages;
if (Not flgBootLoad) or flgBFBExit then exit;
Sleep(75);
end;
end;
AddLinesLog('No Ping Mobile!');
end;
end;
function TFormMain.SendAllBoot : boolean;
var
i : integer;
begin
if flgBootLoad then begin
flgBootLoad:=False;
Sleep(200);
ComClose;
result:=True;
exit;
end;
{
result:=StartBoot;
AddLinesLog('Loading ParamBoot...');
// ProgressBar.Position:=0;
if result and (Not flgalready) then begin
result:=False;
if Not SendSBPl55Boot($88,nil) then begin
AddLinesLog(sBootErr);
ComClose;
exit;
end;
end;
ComClose;
Sleep(200);
}
ProgressBar.Position:=0;
result:=StartBoot(BootsMode);
if result and (Not flgalready) then begin
result:=False;
i:=RadioGroupBootType.ItemIndex;
// AddLinesLog('Loading PapameterBoot...');
if TBootType(i)=Boot_BootKey then begin
AddLinesLog('BootKey: '+BufToHexStr(@BootKey,16));
if Not SendSBPl55Boot($01,@BootKey[0]) then begin
// if Not SendSBPl55Boot($88,Nil) then begin
AddLinesLog(sBootErr);
ComClose;
exit;
end;
AddLinesLog(sBootErr);
ProgressBar.StepBy(10);
end;
AddLinesLog('Loading BootsModel('+sBootModel[Model]+')...');
if Not SendStartl55Boot(TBootType(i)) then begin
AddLinesLog(sBootErr);
ComClose;
exit;
end;
AddLinesLog(sBootErr);
ProgressBar.StepBy(10);
Application.ProcessMessages;
if (Not flgBootLoad) or flgBFBExit then exit;
{ if Not Sendl55Boot2 then begin
AddLinesLog(sBootErr);
ComClose;
exit;
end;
AddLinesLog(sBootErr);
ProgressBar.StepBy(10);
Application.ProcessMessages;
if Not flgBootLoad then exit;
if Not Sendl55Boot3 then begin
AddLinesLog(sBootErr);
ComClose;
exit;
end;
AddLinesLog(sBootErr); }
ProgressBar.StepBy(10);
Application.ProcessMessages;
if (Not flgBootLoad) or flgBFBExit then exit;
if Not SendMainl55Boot then begin
AddLinesLog(sBootErr);
ComClose;
exit;
end;
AddLinesLog(sBootErr);
ProgressBar.StepBy(10);
Application.ProcessMessages;
if (Not flgBootLoad) or flgBFBExit then exit;
// AddLinesLog('Load all Boots - Ok.');
result:=True;
exit;
end;
end;
procedure TFormMain.AllKeyDisable;
begin
ButtonSendSkey.Enabled:=False;
ButtonBFEEP.Enabled:=False;
ButtonSkey.Enabled:=False;
// ButtonBoot.Enabled:=False;
ButtonRead.Enabled:=False;
ButtonWrite.Enabled:=False;
ButtonSrvm.Enabled:=False;
ButtonSrvm1.Enabled:=False;
ButtonSrvm2.Enabled:=False;
ButtonNormMode.Enabled:=False;
ButtonReCalcKey.Enabled:=False;
ButtonNameCh.Enabled:=False;
end;
procedure TFormMain.Terminate;
begin
ComClose;
ButtonSendSkey.Caption :='Send Skey';
// ButtonUnlock.Caption :='Joker';
ButtonSkey.Caption := 'Calc Skey';
// ButtonBoot.Caption := 'Boot';
ButtonRead.Caption := 'Read';
ButtonWrite.Caption := 'Write';
ButtonSrvm.Caption :='Service Mode';
ButtonSrvm1.Caption :='Service Mode';
ButtonSrvm2.Caption :='Service Mode';
ButtonNormMode.Caption :='Normal Mode';
ButtonReCalcKey.Caption :='ReCalc All Keys';
ButtonBFEEP.Caption :='Read F.EEP';
ButtonNameCh.Caption :='Name change';
ButtonSrvm.Enabled:=True;
ButtonSrvm1.Enabled:=True;
ButtonSrvm2.Enabled:=True;
ButtonSendSkey.Enabled:=True;
// ButtonUnlock.Enabled:=True;
ButtonSkey.Enabled:=True;
// ButtonBoot.Enabled:=True;
ButtonRead.Enabled:=True;
ButtonWrite.Enabled:=True;
ButtonNormMode.Enabled:=True;
ButtonReCalcKey.Enabled:=True;
ButtonDefragEEP.Enabled:=True;
ButtonBFEEP.Enabled:=True;
PanelMain.Enabled:=True;
ButtonNameCh.Enabled:=True;
flgBootLoad := False;
end;
procedure TFormMain.Stop;
begin
Terminatel55Boot;
Terminate;
end;
function TFormMain.TestSecurityMode : boolean;
var
s : string;
begin
result:=False;
if not BFB_GetSecurityMode(SecMode) then AddLinesLog('Error GetSecurityMode!');
if SecMode>2 then begin
Case SecMode of
// 00: s:='Repair';
// 01: s:='Developer';
// 02: s:='Factory';
03: s:='Customer';
$FE: s:='Not Read!';
$FF: s:='Error!';
else
s:='Unknown('+IntToHex(SecMode,2)+')';
end;
AddLinesLog('SecurityMode: '+s);
AddLinesLog('Work only in FactoryMode! Use Skey!');
if SecMode<>$FE then exit;
end;
result:=True;
end;
function TFormMain.GreateFileNameBackup(s : string) : string;
begin
result := IniFile.ReadString('System','DirBackup','.\Backup');
// if RepairFileName(result) then result:='.\Backup';
if not DirectoryExists(result) then begin
result := '.\Backup';
if not CreateDir(result) then begin
result := '.\';
IniFile.WriteString('System','DirBackup',result);
end;
end;
if result[length(result)]<>'\' then result:=result+'\';
result := result+PhoneName + '_' + s + FormatDateTime('yymmddhhnnss',Now);
end;
function TFormMain.BootBackupEEP : boolean;
var
ver : byte;
//i : integer;
sBlkFile : string;
begin
result:=False;
FlgBkEEP:=0;
ClearEEPBufAndTab;
if ReadEEPl55Boot(0067,SizeOf(EEP0067),ver,EEP0067[0]) then begin
AddEEPBlk(0067,ver,SizeOf(EEP0067),EEP0067[0]);
AddLinesLog(sBootErr);
FlgBkEEP:=BitEEP0067;
end else AddLinesLog(sBootErr);
ProgressBar.StepIt;
if ReadEEPl55Boot(0076,SizeOf(EEP0076),ver,EEP0076[0]) then begin
AddEEPBlk(0076,ver,SizeOf(EEP0076),EEP0076[0]);
AddLinesLog(sBootErr);
FlgBkEEP:=FlgBkEEP or BitEEP0076;
end else AddLinesLog(sBootErr);
ProgressBar.StepIt;
if ReadEEPl55Boot(5005,64,ver,EEP5005[0]) then begin
AddEEPBlk(5005,ver,64,EEP5005[0]);
AddLinesLog(sBootErr);
ver:=0;
if (EEP5005[$0B]=$FF) or (EEP5005[$0C]=$FF) then ver:=1;
if (EEP5005[$12]=$FF) then ver:=ver or 2;
case ver of
0 : FlgBkEEP:=FlgBkEEP or BitEEP5005;
1 : AddLinesLog('EEP5005 uses incorrect date!');
2 : AddLinesLog('EEP5005 uses incorrect wariant!');
3 : AddLinesLog('EEP5005 uses incorrect wariant and date!');
end;
end else AddLinesLog(sBootErr);
ProgressBar.StepIt;
if ReadEEPl55Boot(5007,10,ver,EEP5007[0]) then begin
AddEEPBlk(5007,ver,10,EEP5007[0]);
AddLinesLog(sBootErr);
FlgBkEEP:=FlgBkEEP or BitEEP5007;
end else
if ReadEEPl55Boot(5007,4,ver,EEP5007[0]) then begin
AddEEPBlk(5007,ver,4,EEP5007[0]);
AddLinesLog(sBootErr);
FlgBkEEP:=FlgBkEEP or BitEEP5007;
end else
if ReadEEPl55Boot(5007,12,ver,EEP5007[0]) then begin
AddEEPBlk(5007,ver,12,EEP5007[0]);
AddLinesLog(sBootErr);
FlgBkEEP:=FlgBkEEP or BitEEP5007;
end else AddLinesLog(sBootErr);
ProgressBar.StepIt;
if ReadEEPl55Boot(5008,SizeOf(EEP5008),ver,EEP5008[0]) then begin
AddEEPBlk(5008,ver,SizeOf(EEP5008),EEP5008[0]);
AddLinesLog(sBootErr);
FlgBkEEP:=FlgBkEEP or BitEEP5008;
end else AddLinesLog(sBootErr);
ProgressBar.StepIt;
if ReadEEPl55Boot(5009,SizeOf(EEP5009),ver,EEP5009[0]) then begin
AddEEPBlk(5009,ver,SizeOf(EEP5009),EEP5009[0]);
AddLinesLog(sBootErr);
FlgBkEEP:=FlgBkEEP or BitEEP5009;
end else AddLinesLog(sBootErr);
ProgressBar.StepIt;
if ReadEEPl55Boot(5012,12,ver,EEP5012[0]) then begin
AddEEPBlk(5012,ver,12,EEP5012[0]);
AddLinesLog(sBootErr);
FlgBkEEP:=FlgBkEEP or BitEEP5012;
end else
if ReadEEPl55Boot(5012,SizeOf(EEP5012),ver,EEP5012[0]) then begin
AddEEPBlk(5012,ver,SizeOf(EEP5012),EEP5012[0]);
AddLinesLog(sBootErr);
FlgBkEEP:=FlgBkEEP or BitEEP5012;
end else AddLinesLog(sBootErr);
ProgressBar.StepIt;
if ReadEEPl55Boot(5077,SizeOf(EEP5077),ver,EEP5077[0]) then begin
AddEEPBlk(5077,ver,SizeOf(EEP5077),EEP5077[0]);
AddLinesLog(sBootErr);
FlgBkEEP:=FlgBkEEP or BitEEP5077;
end else AddLinesLog(sBootErr);
ProgressBar.StepIt;
if ReadEEPl55Boot(5093,SizeOf(EEP5093),ver,EEP5093[0]) then begin
AddEEPBlk(5093,ver,SizeOf(EEP5093),EEP5093[0]);
AddLinesLog(sBootErr);
FlgBkEEP:=FlgBkEEP or BitEEP5093;
end else
if ReadEEPl55Boot(5093,32,ver,EEP5093[0]) then begin
AddEEPBlk(5093,ver,32,EEP5093[0]);
AddLinesLog(sBootErr);
FlgBkEEP:=FlgBkEEP or BitEEP5093;
end else
if ReadEEPl55Boot(5093,64,ver,EEP5093[0]) then begin
AddEEPBlk(5093,ver,64,EEP5093[0]);
AddLinesLog(sBootErr);
FlgBkEEP:=FlgBkEEP or BitEEP5093;
end else AddLinesLog(sBootErr);
ProgressBar.StepIt;
if ReadEEPl55Boot(5121,SizeOf(EEP5121),ver,EEP5121[0]) then begin
AddEEPBlk(5121,ver,SizeOf(EEP5121),EEP5121[0]);
AddLinesLog(sBootErr);
FlgBkEEP:=FlgBkEEP or BitEEP5121;
end else AddLinesLog(sBootErr);
ProgressBar.StepIt;
if ReadEEPl55Boot(5122,SizeOf(EEP5122),ver,EEP5122[0]) then begin
AddEEPBlk(5122,ver,SizeOf(EEP5122),EEP5122[0]);
AddLinesLog(sBootErr);
FlgBkEEP:=FlgBkEEP or BitEEP5122;
end else AddLinesLog(sBootErr);
ProgressBar.StepIt;
if ReadEEPl55Boot(5123,12,ver,EEP5123[0]) then begin
AddEEPBlk(5123,ver,12,EEP5123[0]);
AddLinesLog(sBootErr);
FlgBkEEP:=FlgBkEEP or BitEEP5123;
end else
if ReadEEPl55Boot(5123,14,ver,EEP5123[0]) then begin
AddEEPBlk(5123,ver,14,EEP5123[0]);
AddLinesLog(sBootErr);
FlgBkEEP:=FlgBkEEP or BitEEP5123;
end else AddLinesLog(sBootErr);
ProgressBar.StepIt;
if idx_eeptab<>0 then begin
sBlkFile:=GreateFileNameBackup('Backup')+'.eep';
if SaveAllEEP(sBlkFile,HWID) then begin
AddLinesLog('EEPROM blocks is written in "'+sblkFile+ '" file.');
result:=True;
end
else AddLinesLog(sEep_Err);
end
else result:=True;
ProgressBar.StepIt;
end;
function TFormMain.TestSkey(xskey,xesn: dword; flgTstBkey:boolean): boolean;
var
i : integer;
buffer : array[0..63] of byte;
begin
buffer[16]:=$80;
FillChar(buffer[17], 64-17, 0);
buffer[56]:=$80;
Dword((@buffer[0])^):=xesn;
Dword((@buffer[4])^):=xskey;
for i:=0 to 7 do buffer[i+8]:=buffer[i] xor buffer[i+3];
MD5Init;
MD5Transform(@buffer);
if flgTstBkey then
if not((Dword((@BootKey[0])^)=MD5buf[0])
and (Dword((@BootKey[4])^)=MD5buf[1])
and (Dword((@BootKey[8])^)=MD5buf[2])
and (Dword((@BootKey[12])^)=MD5buf[3])) then begin
result:=False;
exit;
end;
Dword((@buffer[0])^):=MD5buf[0];
Dword((@buffer[4])^):=MD5buf[1];
Dword((@buffer[8])^):=MD5buf[2];
Dword((@buffer[12])^):=MD5buf[3];
MD5Init;
MD5Transform(@buffer);
if ((Dword((@HASH[0])^)=MD5buf[0])
and (Dword((@HASH[4])^)=MD5buf[1])
and (Dword((@HASH[8])^)=MD5buf[2])
and (Dword((@HASH[12])^)=MD5buf[3])) then result:=True
else result:=False;
end;
function TFormMain.CalcSkey(xesn,xskey:dword): boolean;
var
i,sss : integer;
buffer : array[0..63] of byte;
begin
ProgressBar.Position:=0;
sss:=0;
result:=False;
repeat begin
buffer[16]:=$80;
FillChar(buffer[17], 64-17, 0);
buffer[56]:=$80;
Dword((@buffer[0])^):=xesn;
Dword((@buffer[4])^):=xskey;
for i:=0 to 7 do buffer[i+8]:=buffer[i] xor buffer[i+3];
MD5Init;
MD5Transform(@buffer);
Dword((@buffer[0])^):=MD5buf[0];
Dword((@buffer[4])^):=MD5buf[1];
Dword((@buffer[8])^):=MD5buf[2];
Dword((@buffer[12])^):=MD5buf[3];
MD5Init;
MD5Transform(@buffer);
if ((Dword((@HASH[0])^)=MD5buf[0])
and (Dword((@HASH[4])^)=MD5buf[1])
and (Dword((@HASH[8])^)=MD5buf[2])
and (Dword((@HASH[12])^)=MD5buf[3])) then begin
Dword((@buffer[0])^):=xesn;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?