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

📄 jmain.pas

📁 Delphi Source for work with Siemens Mobile phones
💻 PAS
📖 第 1 页 / 共 4 页
字号:
     Dword((@buffer[4])^):=xskey;
     for i:=0 to 7 do buffer[i+8]:=buffer[i] xor buffer[i+3];
     MD5Init;
     MD5Transform(@buffer);
//     AddLinesLog('BOOTKEY: '+BufToHexStr(@MD5buf,16));
     Move(MD5buf,BootKey,16);
//     AddLinesLog('SKEY: '+IntToStr(xskey));
//     EditSkey.Text:=IntToStr(xskey);
     SKey:=xskey;
     result:=True;
     ProgressBar.Position:=100;
     exit;
    end
    else begin
     inc(xskey);
     inc(sss);
     if sss>1000000 then begin
       ProgressBar.StepBy(1);
       Application.ProcessMessages;
       if (Not flgBootLoad) or flgBFBExit then exit;
       sss:=0;
     end;
    end;
   end
   until (xskey>=100000000) or (xskey=0);
//   until (xskey=0);
end;

procedure TFormMain.CalcHashAndBkey(xskey,xesn:Dword);
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);
    Dword((@buffer[0])^):=MD5buf[0];
    Dword((@buffer[4])^):=MD5buf[1];
    Dword((@buffer[8])^):=MD5buf[2];
    Dword((@buffer[12])^):=MD5buf[3];
    Move(MD5buf,BootKey,16);
    MD5Init;
    MD5Transform(@buffer);
    Move(MD5buf,HASH,16);
end;

function TFormMain.TestAndCalcSkey : boolean;
var
xBkey : array[0..15] of byte;
begin
        result:=False;
        AddLinesLog('Test and Calc Skey...');
        ReadIniImeiKeys;
        if Not TestSkey(SKEY,FSN,True) then begin
         if TestSkey(SKEY,FSN,False) then begin
          CalcHashAndBkey(SKEY,FSN);
          HexTopByte(@IniFile.ReadString(IMEI,'BKEY','00000000000000000000000000000000')[1],16,@xBKey);
          if ((Dword((@xBkey[0])^)=Dword((@BootKey[0])^))
          and (Dword((@xBkey[4])^)=Dword((@BootKey[4])^))
          and (Dword((@xBkey[8])^)=Dword((@BootKey[8])^))
          and (Dword((@xBkey[12])^)=Dword((@BootKey[12])^))) then begin
           AddLinesLog('BOOTKEY: '+BufToHexStr(@BootKey[0],16));
           WriteIniImeiKeys(True);
          end
          else begin
           if (Dword((@xBkey[0])^) or Dword((@xBkey[4])^) or Dword((@xBkey[8])^) or Dword((@xBkey[12])^)) = 0 then begin
            AddLinesLog('BOOTKEY: '+BufToHexStr(@BootKey[0],16));
            WriteIniImeiKeys(True);
           end
           else begin
            AddLinesLog('Warning: BOOTKEY not valid in Joker.ini!');
            AddLinesLog('Real BOOTKEY: '+BufToHexStr(@BootKey[0],16)+'! Write correct BOOTKEY?');
            if MessageDlg('Warning: BOOTKEY not valid in Joker.ini!'#13#10
            +'Real BOOTKEY: '+BufToHexStr(@BootKey[0],16)+'!'#13#10
            +'Write correct BOOTKEY?'
            ,mtConfirmation, [mbYes, mbNo], 0) = mrYes
            then begin
             AddLinesLog('BOOTKEY: '+BufToHexStr(@BootKey[0],16));
             WriteIniImeiKeys(True);
            end
            else begin
             AddLinesLog('Cancel.');
             WriteIniImeiKeys(False);
            end;
          end;
          end;
         end
         else if CalcSkey(FSN,0) then begin
          WriteIniImeiKeys(True);
          AddLinesLog('BOOTKEY: '+BufToHexStr(@BootKey[0],16));
         end
         else begin
          AddLinesLog('Skey not found! BCORE HASH incorrect for this phone FSN!');
          AddLinesLog('Use ReCalc Keys in BCORE!');
          Exit;
         end;
        end else begin
         AddLinesLog('BOOTKEY: '+BufToHexStr(@BootKey[0],16));
         WriteIniImeiKeys(True);
        end;
        AddLinesLog('SKEY: '+IntToStr(SKEY));
        result:=True;
end;

function TFormMain.StartBootAndInfo : boolean;
var
buf : array[0..$3F] of byte;
s : string;
addr : dword;
begin
      result:=False;
      if Model=MA50 then CryptModel:=A50
      else CryptModel:=C55;
      if SendAllBoot then begin
       if RadioGroupBaud.ItemIndex<>0 then begin
        if Not SetBaudl55Boot(RadioGroupBaud.ItemIndex) then begin
         AddLinesLog(sBootErr);
         Stop;
         exit;
        end;
        AddLinesLog(sBootErr);
       end;
       ProgressBar.StepBy(10);
       Application.ProcessMessages;
       flgHASH:=False;
       if Not ReadFlashl55Boot($800800,4,buf[0]) then begin
        AddLinesLog(sBootErr);
        Stop;
        exit;
       end;
       if Not ReadFlashl55Boot($800300,4,buf[4]) then begin
        AddLinesLog(sBootErr);
        Stop;
        exit;
       end;
       addr:=$800330;
       if Model=MA50 then addr:=$80032E;
       if Not ReadFlashl55Boot(addr,16,HASH) then begin
        AddLinesLog(sBootErr);
        Stop;
        exit;
       end;
       if (dword((@HASH[0])^)+dword((@HASH[4])^)<>$FFFFFFFE)
       and (dword((@buf[0])^)<>$A5A55AA5)
       and (dword((@buf[4])^)=$534C0100)
       then flgHASH:=True
       else begin
        AddLinesLog('Warning: HASH data error!');
        beep;
       end;
       ProgressBar.StepIt;
       Application.ProcessMessages;
       if Not ReadFlashl55Boot($87FF50,$40,buf[0]) then begin
        AddLinesLog(sBootErr);
        Stop;
        exit;
       end;
       buf[$1f]:=0; // lgXX
       buf[$2f]:=0; // X55
       buf[$3f]:=0; // SIEMENS
       if buf[$30]<>$FF // SIEMENS
       then s:=pchar(@buf[$30])
       else s:='';
       ProgressBar.StepIt;
       Application.ProcessMessages;
       if buf[$20]<>$FF then begin // S55
        s:=s+' '+pchar(@buf[$20]);
        PhoneName:=pchar(@buf[$20]);
       end
       else begin
        s:=s+' ?';
        PhoneName:=sBootModel[Model]+'!';
       end;
       ProgressBar.StepIt;
       if buf[$10]<>$FF then begin // LgXX
        s:=s+' '+pchar(@buf[$10]);
        PhoneName:=PhoneName+pchar(@buf[$10]);
       end;
       ProgressBar.StepIt;
       Application.ProcessMessages;
       if buf[$00]<>$FF then begin  // SW num
        s:=s+' Sw'+IntToHex(buf[$00],2);
        PhoneName:=PhoneName+'Sw'+IntToHex(buf[$00],2);
       end
       else s:=s+' ?';
       AddLinesLog(s);
       if Not ReadFlashl55Boot($87FE26,16,buf[0]) then begin
        AddLinesLog(sBootErr);
        Stop;
        exit;
       end;
       if (dword((@buf[0])^)<>$FFFFFFFF) then begin
        s:='Soft FlashID: '+IntToHex(word((@buf[0])^),4)+'/'+IntToHex(word((@buf[2])^),4);
        if (dword((@buf[12])^)<>$FFFFFFFF)
        and (dword((@buf[12])^)<>$00000000) then begin
         s:=s+' ('+IntToHex(word((@buf[12])^),4)+'/'+IntToHex(word((@buf[14])^),4)+')';
        end;
        AddLinesLog(s);
       end;
       RepairFileName(PhoneName);
       ProgressBar.StepIt;
       Application.ProcessMessages;
       if (Not flgBootLoad) or flgBFBExit then begin Stop; exit; end;
       if Not GetFlashInfo then begin  Stop; exit; end;
       if (dword((@buf[0])^)<>$FFFFFFFF) then begin
        if (FlashInfo.Flash1IM<>word((@buf[0])^))
        and ((Not( (FlashInfo.Flash1IM=1) and (FlashInfo.Flash2ID=word((@buf[2])^)) ))
          or (Not( (FlashInfo.Flash1IM<>1) and (FlashInfo.Flash1ID=word((@buf[2])^)) )))
        then begin
         AddLinesLog('Warning: The software of the telephone does not correspond to FlashID!');
         beep;
        end;
       end;
       AddLinesLog('HASH: '+BufToHexStr(@HASH[0],16));
       result:=True;
      end; // if SendAllBoot
end;


procedure TFormMain.ButtonSkeyClick(Sender: TObject);
var
ch : char;
//ver : byte;
err : boolean;
//i : integer;
//s : string;
begin
      if flgBootLoad then begin
       flgBootLoad := False;
       Sleep(200);
       Stop;
       AddLinesLog('Cancel.');
       exit;
      end;
      AllKeyDisable;
      ButtonSkey.Caption :='Cancel';
      ButtonSkey.Enabled:=True;
      Model:=RadioGroupTelType.ItemIndex;
      err := False;
      if StartBootAndInfo then begin
       if Not flgHASH then begin
        AddLinesLog('Calc Skey Error: HASH data error!');
        Stop;
        exit;
       end;
       if CheckBoxSaveSecBlkEEP.Checked then begin
        if Not ReadEEPl55Boot(5009,SizeOf(EEP5009),byte(ch),EEP5009[0]) then begin
         AddLinesLog(sBootErr);
//         AddLinesLog('EEP5009 not found!');
         err:=True;
        end
        else begin
         AddLinesLog(sBootErr);
         ProgressBar.StepIt;
         Application.ProcessMessages;
         if (Not flgBootLoad) or flgBFBExit then begin Stop; exit; end;
         Decode5009(EEP5009,CryptModel);
         BCD2IMEI(EEP5009,IMEI);
         if Length(IMEI)>=16 then IMEI[15]:=IMEI[16];
         SetLength(IMEI,15);
         AddLinesLog('EEP IMEI: ' + IMEI);
         if Not CalcImei15(IMEI,ch) then begin
          AddLinesLog('Error IMEI in EEP5009!');
          err:=True;
         end
         else begin
          if ch<>IMEI[15] then begin
           AddLinesLog('Error('+ch+','+Char(IMEI[15])+') CRC IMEI!');
           err:=True;
          end;
//          else EditJImei.Text:=IMEI;
//          AddLinesLog(sBootErr); // FSN=...
          if debug then begin
           IMEI2xBCD(IMEI);
           AddLinesLog('EEP5008:');
           DeCrypt5008blk(FSN,EEP5008);
           AddLinesLog(BufToHex_Str(@EEP5008,8));
           AddLinesLog(BufToHex_Str(@EEP5008[8],24));
           AddLinesLog(BufToHex_Str(@EEP5008[32],8));
           AddLinesLog(BufToHex_Str(@EEP5008[40],176));
           AddLinesLog(BufToHex_Str(@EEP5008[216],8));
           DeCrypt5077blk(FSN,EEP5077);
           AddLinesLog('EEP5077:');
           AddLinesLog(BufToHex_Str(@EEP5077,8));
           AddLinesLog(BufToHex_Str(@EEP5077[8],216));
           AddLinesLog(BufToHex_Str(@EEP5077[224],8));
          end;
         end;
        end; // if ReadEEPl55Boot(FSN)
       end; // if CheckBoxSaveSecBlkEEP.Checked
       ProgressBar.StepIt;
       Application.ProcessMessages;
       if (Not flgBootLoad) or flgBFBExit then begin Stop; exit; end;
       Terminatel55Boot;
       AddLinesLog(sBootErr);
///////////////////
       ProgressBar.StepIt;
       Application.ProcessMessages;
       if (Not flgBootLoad) or flgBFBExit then begin Stop; exit; end;
       if Not CheckBoxSaveSecBlkEEP.Checked and FlgOTPImeiErr then err:=True;
       if err then begin
        AddLinesLog('Data Error!');
        Beep;
       end
       else begin
        if Not CheckBoxSaveSecBlkEEP.Checked then  IMEI:=OTPIMEI;
        if TestAndCalcSkey then begin
         if CheckBoxSaveSecBlkEEP.Checked or CheckBoxSaveSecBlkOTP.Checked then SaveNewSecBlocks;
         ProgressBar.Position:=100;
        end;
       end;
       Terminate;
       exit;
      end; // if StartBootAndInfo
      Stop;
end;

procedure TFormMain.ButtonSendSkeyClick(Sender: TObject);
var
i : integer;
err : boolean;
oldSecMode : byte;
s : string;
begin
    if flgBootLoad then begin
       Sleep(200);
       ChangeComSpeed(115200);
       if BFB_PhoneOff then AddLinesLog('Phone Off.');
       Stop;
       AddLinesLog('Cancel.');
       exit;
    end;
    err:=True;
    oldSecMode:=$FF;
    AllKeyDisable;
    ButtonSendSkey.Caption :='Cancel';
    ButtonSendSkey.Enabled:=True;
    if StartServiceMode($07) then begin
     if InfoBFB then begin
      SKey:=IniFile.ReadInteger(IMEI,'SKEY',0);
      oldSecMode:=SecMode;
      if SKey=0 then begin
       AddLinesLog('Skey not found in Joker.ini!')
      end
      else FormNewSkey.SpinEditSkey.Value:=SKey;
      Case SecMode of
       00: s:='Repair';
       01: s:='Developer';
       02: s:='Factory';
       03: s:='Customer';
      else  s:='Unknown('+IntToHex(SecMode,2)+')';
      end;
      FormNewSkey.Top:=Top+240;
      FormNewSkey.Left:=Left+200;
      FormNewSkey.LabelImei.Caption:='IMEI: '+IMEI;
      FormNewSkey.LabelSecMode.Caption:='SecurityMode: '+s;
      if FormNewSkey.ShowModal <> mrOk then begin
//       AddLinesLog('Use "Calc Skey"!');
       AddLinesLog('Cancel.');
//       beep;
       err:=True;
      end
      else begin
       SKey:=FormNewSkey.SpinEditSkey.Value;
       AddLinesLog('Send SKey('+Int2Digs(SKEY,8)+')...');
       ibfb.code.cmdb:=0;
       ibfb.code.datab[1]:=1;
//       if NOT BFB_SendSkey(SKEY) then
       BFB_SendSkey(SKEY);
//       EditJImei.Text:=IMEI;
       i:=15;
       if ibfb.code.cmdb=$57 then begin
        i:=ibfb.code.datab[0]*10;
//        if i>100 then i:=100;
       end;
       while i>0 do begin
        if ProgressBar.Position>=100 then ProgressBar.Position:=1
        else ProgressBar.StepBy(2);
        Application.ProcessMessages;
        if (Not flgBootLoad) or flgBFBExit then exit;
        Sleep(100);
        dec(i);
       end;
       if BFB_GetSecurityMode(SecMode) then err:=False;
      end;
     end
     else err:=True;
     if BFB_Phoneoff then AddLinesLog('Phone Off.');
     ComClose;
     if err then AddLinesLog('Send SKey: Error!')
     else begin
      if (SecMode=2) then begin
       if (oldSecMode<>2) then begin
        AddLinesLog('SKey Send: Ok! All Open.');
        IniFile.WriteInteger(IMEI,'SKEY',SKey);
       end
       else AddLinesLog('SKey Send: Ok! All Close.');
      end
      else AddLinesLog('SKey Send: Ok! - Please Check up!');
     end;
    end;
    Stop;
    ProgressBar.Position:=100;
end;
{
procedure TFormMain.ButtonReadClick(Sender: TObject);
var
addr,size : dword;
buf : array[0..65535] of byte;
begin
    with SaveDialog do begin
     FilterIndex:=1;
     FileName := IniFile.ReadString('Setup','NewBinFile','xxx.bin');
     InitialDir := ExtractFilePath(FileName);
     FileName := ChangeFileExt(ExtractFileName(OpenDialog.FileName),'.bin');
     if InitialDir = '' then IniFile.ReadString('Setup','DirOld','.\');
     if not DirectoryExists(InitialDir) then
      InitialDir := IniFile.ReadString('Setup','DirOld','.\');
     DefaultExt := 'bin';
     Filter := 'Bin files (*.bin)|*.bin|All files (*.*)|*.*';
     Options:=Options+[ofFileMustExist]-[ofHideReadOnly]
        +[ofNoChangeDir]-[ofNoLongNames]-[ofNoNetworkButton]-[ofHideReadOnly]
        -[ofOldStyleDialog]-[ofOverwritePrompt]+[ofPathMustExist]
        -[ofReadOnly]-[ofShareAware]-[ofShowHelp];
     Title:='蔓徼痂蝈 桁

⌨️ 快捷键说明

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