⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jmain.pas

📁 Delphi Source for work with Siemens Mobile phones
💻 PAS
📖 第 1 页 / 共 4 页
字号:
   end;
   Top := IniFile.ReadInteger('Setup','Top',100);
   Left := IniFile.ReadInteger('Setup','Left',100);
//   SpeedBFB := IniFile.ReadInteger('System','SpeedBFB',115200);
   if Screen.DesktopHeight <= Top then Top := Screen.DesktopHeight shr 1;
   if Screen.DesktopWidth <= Left then Left := Screen.DesktopWidth shr 1;
   CheckBoxIgnitionMode.Checked:=IniFile.ReadBool('Setup','IType',CheckBoxIgnitionMode.Checked);
   iComNum := IniFile.ReadInteger('Setup','ComPort',iComNum);
   debug := IniFile.ReadBool('System','Debug',False);
   RadioGroupComPort.ItemIndex:=iComNum-1;
   RadioGroupBaud.ItemIndex := IniFile.ReadInteger('Setup','Baud',0);
   RadioGroupTelType.ItemIndex := IniFile.ReadInteger('Setup','Mobile',1);
   Model:=RadioGroupTelType.ItemIndex;
   CheckBoxSaveSecBlkEEP.Checked := IniFile.ReadBool('Setup','SBlkEEP',False);
   CheckBoxSaveSecBlkOTP.Checked := IniFile.ReadBool('Setup','SBlkOTP',False);
   CheckBoxBcorePr.Checked := IniFile.ReadBool('Setup','BCProt',True);
   CheckBoxReCalcKeys.Checked := IniFile.ReadBool('Setup','ReCalc',False);
   CheckBoxSrvCreateBlk.Checked := IniFile.ReadBool('Setup','SrvCrBlk',True);
   CheckBoxBkEEP.Checked := IniFile.ReadBool('Setup','BkEEP',True);
   CheckBoxPrFacEEP.Checked := IniFile.ReadBool('Setup','PrFEEP',True);
   CheckBoxClrBC.Checked := IniFile.ReadBool('Setup','ClrBC',False);
   MaskEditAddr.Text:=IntToHex(IniFile.ReadInteger('Setup','Addr',$A0),2);
   MaskEditSize.Text:=IntToHex(IniFile.ReadInteger('Setup','Size',$004),3);
//   for i:=0 to 5 do Mkey[i]:=IniFile.ReadInteger('System','Mkey'+IntToStr(i),12345678);
   IMEI:=IniFile.ReadString('Setup','Imei','123456789012347');
   ReadIniImeiKeys;
   EditJImei.Text:=IniFile.ReadString('Setup','EImei','123456789012347');
   EditJImei.Enabled:=CheckBoxExtIMEI.Checked;
   RadioGroupBootType.ItemIndex := IniFile.ReadInteger('Setup','BootType',0);
   RadioGroupFlash.ItemIndex := IniFile.ReadInteger('Setup','FlashBlk',nManual);
   if IniFile.ReadBool('System','LogFileOn',True) then begin
    LogFileName:=IniFile.ReadString('System','DirLogs','.\Logs');
//    if RepairFileName(LogFileName) then LogFileName:='.\Logs';
    if not DirectoryExists(LogFileName) then begin
     LogFileName:='.\Logs';
     if not CreateDir(LogFileName) then begin
      LogFileName:='.\';
      IniFile.WriteString('System','DirLogs',LogFileName);
     end;
    end;
    if LogFileName[Length(LogFileName)]<>'\' then LogFileName:=LogFileName+'\';
    LogFileName:=LogFileName+'Joker'+FormatDateTime('yymmddhhnnss',Now)+'.log';
    LogFile:=FileCreate(LogFileName);
   end;
   if LogFile>0 then begin
    FileSeek(LogFile,0,2);
    s:='****** '+Caption +' opened. ******'+#13+#10+'****** '+FormatDateTime('dddd, mmmm d, yyyy, " at " hh:mm:ss',Now)+' ******'+#13+#10;
    FileWrite(LogFile, s[1],Length(s));
   end;
end;

procedure TFormMain.FormClose(Sender: TObject; var Action: TCloseAction);
var
s : string;
begin
   if IniFile <> nil then begin
     IniFile.WriteBool('Setup','IType',CheckBoxIgnitionMode.Checked);
     IniFile.WriteInteger('Setup','Top',Top);
     IniFile.WriteInteger('Setup','Left',Left);
     IniFile.WriteInteger('Setup','ComPort',RadioGroupComPort.ItemIndex+1);
     IniFile.WriteInteger('Setup','Baud',RadioGroupBaud.ItemIndex);
     IniFile.WriteInteger('Setup','BootType',RadioGroupBootType.ItemIndex);
     IniFile.WriteInteger('Setup','Mobile',RadioGroupTelType.ItemIndex);
     IniFile.WriteBool('Setup','SBlkEEP',CheckBoxSaveSecBlkEEP.Checked);
     IniFile.WriteBool('Setup','SBlkOTP',CheckBoxSaveSecBlkOTP.Checked);
     IniFile.WriteBool('Setup','BCProt',CheckBoxBcorePr.Checked);
     IniFile.WriteBool('Setup','ReCalc',CheckBoxReCalcKeys.Checked);
     IniFile.WriteBool('Setup','BkEEP',CheckBoxBkEEP.Checked);
     IniFile.WriteBool('Setup','PrFEEP',CheckBoxPrFacEEP.Checked);
     IniFile.WriteBool('Setup','SrvCrBlk',CheckBoxSrvCreateBlk.Checked);
     IniFile.WriteBool('Setup','ClrBC',CheckBoxClrBC.Checked);
     IniFile.WriteInteger('Setup','Addr',StrToIntDef('$'+MaskEditAddr.Text,$A0));
     IniFile.WriteInteger('Setup','Size',StrToIntDef('$'+MaskEditSize.Text,$004));
     IniFile.WriteInteger('Setup','FlashBlk',RadioGroupFlash.ItemIndex);
     IniFile.WriteString('Setup','Imei',IMEI);
     IniFile.WriteString('Setup','EImei',EditJImei.Text);
     IniFile.UpdateFile;
     IniFile.Free;
     if LogFile>0 then begin
      FileSeek(LogFile,0,2);
      s:='****** '+Caption +' closed. ******'+#13+#10+'****** '+FormatDateTime('dddd, mmmm d, yyyy, " at " hh:mm:ss',Now)+' ******'+#13+#10;
      FileWrite(LogFile, s[1],Length(s));
      FileClose(LogFile);
     end;
     ComClose;
   end;
end;

procedure TFormMain.AddLinesLog(s: string);
begin
  MemoInfo.Lines.Add(s);
  if LogFile>0 then begin
   s:=s+#13+#10;
   FileWrite(LogFile, s[1],Length(s));
  end;
end;

function TFormMain.Ignition : boolean;
begin
       result:=False;
        Application.ProcessMessages;
        if (Not flgBootLoad) or flgBFBExit then exit;
        if Terminatel55Boot then AddLinesLog('Boots terminated!');
        ComClose;
        Application.ProcessMessages;
        if (Not flgBootLoad) or flgBFBExit then exit;
        Sleep(75);
        Application.ProcessMessages;
        if (Not flgBootLoad) or flgBFBExit then exit;
        Sleep(75);
        Application.ProcessMessages;
        if (Not flgBootLoad) or flgBFBExit then exit;
        if not ComOpen then begin
         AddLinesLog('No open Com'+IntToStr(iComNum)+'!');
         exit;
        end;
        Application.ProcessMessages;
       result:=True;
end;

function TFormMain.ComOpen : boolean;
begin
  flgBFBExit:=False;
  sBFBExit:='';
  result:=OpenCom(CheckBoxIgnitionMode.Checked);
end;

procedure TFormMain.ComClose;
begin
  if flgBFBExit then begin
   AddLinesLog('The phone was switched off on an error:');
   AddLinesLog(sBFBExit);
   flgBFBExit:=False;
   sBFBExit:='';
  end;
  CloseCom;
end;


function TFormMain.ReadHWID : boolean;
begin
    result:=False;
    if Not BFB_GetHWID(HWID) then begin
     HWID:=0;
    end
    else begin
     AddLinesLog('HWID: '+IntToStr(HWID)+' ('+HwIDToStr(HWID)+')');
     result:=True;
    end;
    if HWID=HW_A50 then CryptModel:=A50
    else CryptModel:=C55;
end;

function TFormMain.InfoBFB : boolean;
var
b : byte;
w : word;
s : string;
i : integer;
buf : array[0..15] of byte;
begin
    result:=False;
    if BFB_GetMobileMode(w) then begin
     case w of
      $03: s:='Charge';
      $80: s:='Normal';
      $07: s:='Service';
//      $07: s:='BurnIn';
//      $FE: s:='Format FFS?';
     else s:='Unknown (0x'+IntToHex(w,4)+')';
     end;
     AddLinesLog('MobileMode: '+s);
    end;
    ReadHWID;
    s:=BFB_PhoneModel;
    s:=s+' '+BFB_GetLg;
    b:=BFB_PhoneFW;
    if b<>$FF then s:=s+' Sw'+IntToHex(b,2);
    if CmdBFB($0E,[$08],1)=BFB_OK then begin
     b:=ibfb.code.datab[8];
     ibfb.code.datab[8]:=0;
     s:=s+' '+pchar(@ibfb.code.datab[0]);
     ibfb.code.datab[8]:=b;
     ibfb.code.datab[16]:=0;
     s:=s+' '+pchar(@ibfb.code.datab[8]);
    end;
    AddLinesLog(s);
//    if BFB_ReadSensors(dword(i)) then begin
//     AddLinesLog('Sensors: '+IntToStr(i shr 16)+', '+IntToStr(i and $FFFF));
//    end;
    IMEI:=BFB_GetImei;
    AddLinesLog('IMEI: '+IMEI);
 //   if BFB_Error=BFB_OK then
    ReadIniImeiKeys;
//    EditJImei.Text:=IMEI;
//    AddLinesLog('FlagStatus: '+IntToStr(BFB_FlagStatus));
    if BFB_GetDisplayType(b) then begin
     if b<=63 then i:=b
     else i:=0;
     AddLinesLog('DisplayID: '+IntToStr(b)+', '+sDisplayController[i]);
    end;
    if BFB_GetSecurityMode(SecMode) and ((SecMode<=2) or (SecMode=$FE)) then begin
     BFB_GetESN(FSN);
     AddLinesLog('FSN: '+IntToHex(FSN,8));
     if BFBReadMem($87FE26,16,buf[0])
     and (dword((@buf[0])^)<>$FFFFFFFF) then begin
       s:='SW FlashID: '+IntToHex(word((@buf[0])^),4)+'/'+IntToHex(word((@buf[2])^),4);
       if (dword((@buf[12])^)<>$FFFFFFFF)
       and (dword((@buf[12])^)<>$00000000) then
        s:=s+' ('+IntToHex(word((@buf[12])^),4)+'/'+IntToHex(word((@buf[14])^),4)+')';
       AddLinesLog(s);
     end;
    end;
    s:='';
    if (CmdBFB($0E,[$0B,$08],2)=BFB_OK)
    and(ibfb.code.cmdb = $0B)
    then begin
     i:=0;
     while i<ibfb.code.datab[0] do begin
      case ibfb.code.datam[i] of
      $04: s:='OTP open';
      $05: s:='OTP closed';
      $08: s:='BootKEY is unknown';
      $09: s:='BootKEY is written in EEPROM';
      $0A: s:='BootKEY misses in EEPROM';
      $0C: s:='Keys miss in BCORE (CleanBCORE)';
      $0D: s:='Keys are registered in BCORE ';
      $0E: s:='Absence of the reference table on commands';

      $10: s:='Minimal access to BFB';
      $11: s:='Service access to BFB';
      $12: s:='Complete access to BFB';
      $13: s:='Complete access to BFB'; //A55="X"
      $15: s:='Complete condition';
      $16: s:='Partial access to BFB';

      $18: s:='Block 76 empty';
      $19: s:='Monitoring is switched on';
      $1A: s:='Block 76 is accessible';
      $1B: s:='Block 76 is not found';
      $1C: s:='Block 5123 is not found';
      $1D: s:='Blocks 5121,5122,5123 are present';
      $1E: s:='Block 5121 is not found';
      $20,$21 : break;
      else s:='?';
      end;
      AddLinesLog('Code('+IntToHex(ibfb.code.datam[i],2)+'): '+s);
      inc(i);
     end;
    end;
    if not BFB_GetBatteryVoltage(w) then AddLinesLog('Error Get Battery Voltage!')
    else begin
     if w < 3700 then begin
      AddLinesLog('Battery Voltage very low! '+IntToStr(w)+' mV!');
      beep;
     end
     else if w > 4275 then begin
      AddLinesLog('Incorrect Battery Voltage! '+IntToStr(w)+' mV!');
     end
     else AddLinesLog('Battery Voltage '+IntToStr(w)+' mV.');
    end;
    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);
    if (BFB_Error=BFB_OK) and (SecMode<>$FF) then result:=True;
end;

var
FlgOTPImeiErr : boolean = True;

function TFormMain.GetFlashInfo : boolean;
begin
       result:=False;
       FlgOTPImeiErr:=True;
       if GetFlashInfol55Boot(FlashInfo) then begin
        ProgressBar.StepIt;
        AddLinesLog(sBootErr);
        FSN := FlashInfo.FSN;
        BCD2IMEI(FlashInfo.BCDIMEI[0],OTPIMEI); // 8 徉轵
        SetLength(OTPIMEI,15);
        if CalcImei15(OTPIMEI,OTPIMEI[15]) then begin
         FlgOTPImeiErr:=False;
         AddLinesLog('OTP IMEI: '+OTPIMEI)
        end
        else AddLinesLog('Error IMEI in OTP!');
        result:=True;
        exit;
       end;
       AddLinesLog(sBootErr);
end;

function TFormMain.StartBoot( mode : tBootsMode) : boolean;
var
b : byte;
i : integer;
begin
      result:=False;
      flgalready := False;
      flgBootLoad := True;
      HWID:=0;
      i := 115200;
      if mode=BootsMode then begin
       i := 57600;
       case RadioGroupBaud.ItemIndex of
        1 : i := 115200;
        2 : i := 460800;
        3 : i := 921600;
       end;
       case Model of
        MA70,MA75,MAX75 : if i>460800 then i:=460800;
       end;
      end;
      iComBaud:=i;
      ProgressBar.Position:=0;
      iComNum := RadioGroupComPort.ItemIndex+1;
      if not ComOpen then begin
       AddLinesLog('No open Com'+IntToStr(iComNum)+' Baud Rate '+IntToStr(i)+'!');
       exit;
      end;
      AddLinesLog('Start...');
      SetComRxTimeouts(50,1,50);
      Application.ProcessMessages;
      if (Not flgBootLoad) or flgBFBExit then exit;
      Sleep(50);
      PurgeCom(PURGE_TXCLEAR or PURGE_RXCLEAR);
//      if (i<>57600) then begin
      if Ackl55Boot and Ackl55Boot then begin
       if mode=BootsMode then begin
        SetComRxTimeouts(20,1,200);
        AddLinesLog('Boots Already loaded!');
        flgalready := True;
        result:=True;
        exit;
       end
       else begin
        if Terminatel55Boot then begin
         AddLinesLog('Boots terminated!');
         exit;
        end
       end;
      end;
      ChangeComSpeed(115200);
      if BFB_Ping then begin
       if mode=BootsMode then begin
        if BFB_PhoneOff then begin
         AddLinesLog('Phone off!');
//         exit;
        end;
       end
       else begin
        SetComRxTimeouts(20,1,200);
        AddLinesLog('Already BFB mode!');
        flgalready := True;
        result:=True;
        exit;
        end;
      end;
      iComBaud:=57600;
      ChangeComSpeed(iComBaud);
      Application.ProcessMessages;
      if (Not flgBootLoad) or flgBFBExit then exit;
//      while ReadCom(@b,1) do;
      SetComRxTimeouts(50,1,75);
      While (flgBootLoad and (not flgBFBExit)) do begin
       if ProgressBar.Position>=ProgressBar.Max then begin
        ProgressBar.Position:=0;
        if not Ignition then exit;
        SetComRxTimeouts(50,1,75);
       end;
       ProgressBar.StepIt;
       Application.ProcessMessages;
       if (Not flgBootLoad) or flgBFBExit then exit;
       b:=$55;
       if not WriteCom(@b,1) then begin
        AddLinesLog('Not write Com'+IntToStr(iComNum)+'!');
        ComClose;
        exit;
       end;
       ProgressBar.StepIt;
       while ReadCom(@b,1) do begin
        if(Not flgBootLoad) or flgBFBExit then exit;
        if b=$A0 then begin
         SetComRxTimeouts(20,1,200);
         flgalready := False;
         result:=True;
         exit;
        end;
       end;
      end;
end;

function TFormMain.StartServiceMode(mode : byte) : boolean;
var
//b : byte;
i,x : integer;
begin
 //     result:=False;
{      if flgBootLoad then begin
       flgBootLoad:=False;
       Sleep(250);
       ComClose;
       result:=True;
       exit;
      end; }
      result:=StartBoot(BFBMode);
      if result and (Not flgalready) then begin
       result:=False;
       AddLinesLog('Loading ServiceBoot...');
       ProgressBar.Position:=0;
       if Not Sendl55ServiceBoot(mode) then begin
        AddLinesLog(sBootErr);
        ComClose;
        exit;
       end;
       AddLinesLog(sBootErr);
       for x:=0 to 17 do begin
        ProgressBar.StepBy(2);
        Application.ProcessMessages;
        if (Not flgBootLoad) or flgBFBExit then exit;
        Sleep(50);
       end;
       for x:=0 to 33 do begin
        if BFB_Ping then begin
         for i:=0 to 4 do begin
          ProgressBar.StepBy(1);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -