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

📄 unit1.pas

📁 Components for Delphi for work with phones Motorola.
💻 PAS
字号:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, MotoATMode, StdCtrls, MotoFlashMode, MotoP2KMode, ExtCtrls, ShellApi;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Button3: TButton;
    GroupBox5: TGroupBox;
    Memo3: TMemo;
    MotoFlashMode1: TMotoFlashMode;
    MotoP2KMode1: TMotoP2KMode;
    GroupBox4: TGroupBox;
    Memo2: TMemo;
    Button4: TButton;
    Button6: TButton;
    Button5: TButton;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    Button10: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    Bevel1: TBevel;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    Edit3: TEdit;
    Edit4: TEdit;
    Label5: TLabel;
    Label6: TLabel;
    Bevel2: TBevel;
    Button11: TButton;
    Edit6: TEdit;
    Bevel3: TBevel;
    Button12: TButton;
    Label8: TLabel;
    Button13: TButton;
    CheckBox3: TCheckBox;
    ComboBox1: TComboBox;
    Button14: TButton;
    Edit5: TEdit;
    Edit7: TEdit;
    Bevel4: TBevel;
    Label7: TLabel;
    Label9: TLabel;
    Button15: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure MotoATMode1Debug(const AItem: TMotoATModemItem;
      const ADebugText: String; const ADebugType: TDebugType;
      const ASubError: Boolean);
    procedure Button4Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure Button12Click(Sender: TObject);
    procedure MotoFlashMode1Debug(const AItem: TMotoFlashModemItem;
      const ADebugText: String; const ADebugType: TDebugType;
      const ASubError: Boolean);
    procedure MotoFlashMode1Arrival(Sender: TObject);
    procedure Button13Click(Sender: TObject);
    procedure Button14Click(Sender: TObject);
    procedure MotoP2KMode1Arrival(Sender: TObject);
    procedure Button15Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure AddDebug(AText:string);
begin
 Form1.Memo3.Lines.Append(AText);
end;

procedure GetDevises;
var i   : integer;
    Dev : TMotoFlashModemItem;
begin
 with Form1 do begin
  ListBox1.Clear;
  MotoFlashMode1.DeviceList.Update;
  for i:=0 to MotoFlashMode1.DeviceList.Count-1 do begin
   Dev := MotoFlashMode1.DeviceList.Items[i];
   if Dev=nil then continue;
   ListBox1.Items.Add(Dev.ModemInfo.LocationInfo);
  end;
  AddDebug(Format('I Found Phone Flash Mode count: %d',[MotoFlashMode1.DeviceList.Count]));
 end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 GetDevises;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 GetDevises;
end;

procedure TForm1.ListBox1Click(Sender: TObject);
var item : TMotoFlashModemItem;
begin
 Memo1.Lines.Clear;
 Label2.Caption := 'DisConnect';
 if (ListBox1.ItemIndex<0) and (ListBox1.ItemIndex>=ListBox1.Count) then exit;
 // Get
 item := MotoFlashMode1.DeviceList.Items[ListBox1.ItemIndex];
 if item=nil then exit;
  // Info
  with item.ModemInfo do begin
   Memo1.Lines.Add(Format('DeviceID %d',[DeviceID]));
   Memo1.Lines.Add(Format('DevicePath %s',[DevicePath]));
   Memo1.Lines.Add(Format('Capabilities %d',[Capabilities]));
   Memo1.Lines.Add(Format('ClassDescr %s',[ClassDescr]));
   Memo1.Lines.Add(Format('ClassGUID %s',[ClassGUID]));
   Memo1.Lines.Add(Format('CompatibleIDs %s',[CompatibleIDs]));
   Memo1.Lines.Add(Format('ConfigFlags %d',[ConfigFlags]));
   Memo1.Lines.Add(Format('LowerFilters %s',[LowerFilters]));
   Memo1.Lines.Add(Format('Mfg %s',[Mfg]));
   Memo1.Lines.Add(Format('UpperFilters %s',[UpperFilters]));
   Memo1.Lines.Add(Format('Address %s',[Address]));
   Memo1.Lines.Add(Format('BusNumber %d',[BusNumber]));
   Memo1.Lines.Add(Format('Driver %s',[Driver]));
   Memo1.Lines.Add(Format('BusType %s',[BusType]));
   Memo1.Lines.Add(Format('Characteristics %s',[Characteristics]));
   Memo1.Lines.Add(Format('DevType %s',[DevType]));
   Memo1.Lines.Add(Format('Exclusive %d',[Exclusive]));
   Memo1.Lines.Add(Format('LegacyBusType %s',[LegacyBusType]));
   Memo1.Lines.Add(Format('LocationInfo %s',[LocationInfo]));
   Memo1.Lines.Add(Format('PhysDevObjName %s',[PhysDevObjName]));
   Memo1.Lines.Add(Format('Security %s',[Security]));
   Memo1.Lines.Add(Format('Service %s',[Service]));
   Memo1.Lines.Add(Format('UINumber %d',[UINumber]));
   Memo1.Lines.Add(Format('UINumberFormat %s',[UINumberFormat]));
  end;
  // Status
  if item.IsOpened then
   Label2.Caption := 'Connect'
  else
   Label2.Caption := 'DisConnect';
  //
  Edit3.Text     := IntToHex(item.BaseAddr,8);
  Edit4.Text     := IntToHex(item.EntryAddr,8);
end;

procedure TForm1.Button2Click(Sender: TObject);
var item : TMotoFlashModemItem;
begin
 if (ListBox1.ItemIndex<0) and (ListBox1.ItemIndex>=ListBox1.Count) then exit;
 item := MotoFlashMode1.DeviceList.Items[ListBox1.ItemIndex];
 if item=nil then exit;
 item.Open;
 ListBox1.OnClick(nil);
end;

procedure TForm1.Button3Click(Sender: TObject);
var item : TMotoFlashModemItem;
begin
 if (ListBox1.ItemIndex<0) and (ListBox1.ItemIndex>=ListBox1.Count) then exit;
 item := MotoFlashMode1.DeviceList.Items[ListBox1.ItemIndex];
 if item=nil then exit;
 item.Close;
 ListBox1.OnClick(nil);
end;

procedure TForm1.FormDestroy(Sender: TObject);
var i:integer;
begin
 for i:=0 to MotoFlashMode1.DeviceList.Count-1 do
  if MotoFlashMode1.DeviceList.items[i].IsOpened then
    MotoFlashMode1.DeviceList.items[i].Close
end;

procedure TForm1.MotoATMode1Debug(const AItem: TMotoATModemItem;
  const ADebugText: String; const ADebugType: TDebugType;
  const ASubError: Boolean);
var S:string;
begin
 if ADebugType=dtError then
  S := '[E] '
 else
  S := '[I] ';
 if ASubError then
  S := S+' + ';
 S := S + ADebugText;
 AddDebug(S);
end;

procedure TForm1.Button4Click(Sender: TObject);
var item : TMotoFlashModemItem;
    info:TFlexInfo;
begin
 Memo2.Clear;
 if (ListBox1.ItemIndex<0) and (ListBox1.ItemIndex>=ListBox1.Count) then exit;
 item := MotoFlashMode1.DeviceList.Items[ListBox1.ItemIndex];
 if item=nil then exit;
 if item.IsOpened then
  if item.GetInfoFlex(info) then
   Memo2.Text := Format('Model: %s'+#13#10+'FlexName: %s',[Info.FlexName,info.Firmware]);
end;

procedure TForm1.Button6Click(Sender: TObject);
var item : TMotoFlashModemItem;
begin
 if (ListBox1.ItemIndex<0) and (ListBox1.ItemIndex>=ListBox1.Count) then exit;
 item := MotoFlashMode1.DeviceList.Items[ListBox1.ItemIndex];
 if item=nil then exit;
 if item.IsOpened then
  item.Restart;
end;

procedure TForm1.Button5Click(Sender: TObject);
var i:integer;
begin
 for i:=0 to MotoP2KMode1.DeviceList.Count-1 do begin
  MotoP2KMode1.DeviceList.Items[i].Open;
  if MotoP2KMode1.DeviceList.Items[i].IsOpened then
   MotoP2KMode1.DeviceList.Items[i].SwitchFlash;
  MotoP2KMode1.DeviceList.Items[i].Close;
 end;
end;

procedure TForm1.Button7Click(Sender: TObject);
var item : TMotoFlashModemItem;
begin
 if (ListBox1.ItemIndex<0) and (ListBox1.ItemIndex>=ListBox1.Count) then exit;
 item := MotoFlashMode1.DeviceList.Items[ListBox1.ItemIndex];
 if item=nil then exit;
 if item.IsOpened then
  item.PowerOff;
end;

procedure TForm1.Button8Click(Sender: TObject);
var item : TMotoFlashModemItem;
    info : TBootInfo;
begin
 Memo2.Clear;
 if (ListBox1.ItemIndex<0) and (ListBox1.ItemIndex>=ListBox1.Count) then exit;
 item := MotoFlashMode1.DeviceList.Items[ListBox1.ItemIndex];
 if item=nil then exit;
 if item.IsOpened then
  if item.GetInfoBoot(info) then
   Memo2.Text := Format('Boot: %s'+#13#10+'Reserv: %s',[Info.Boot,info.Reserv]);
end;

procedure TForm1.Button9Click(Sender: TObject);

 procedure Progress(const position,max:integer);
 begin
  Form1.Caption := Format('Send Loader: progress %.2f/%.2f kB',[position/1024,max/1024]);
  Application.ProcessMessages;
 end;

var item : TMotoFlashModemItem;
begin
 if (ListBox1.ItemIndex<0) and (ListBox1.ItemIndex>=ListBox1.Count) then exit;
 item := MotoFlashMode1.DeviceList.Items[ListBox1.ItemIndex];
 if item=nil then exit;
 if item.IsOpened then begin
  Form1.Caption  := 'Send Loader: ...';
  OpenDialog1.Filter := 'RamLdr by Flash mode|LdrBy*.bin|All Files (*.*)|*.*';
  if OpenDialog1.Execute then begin
   item.BaseAddr  := StrToIntDef('$'+Edit3.Text,item.BaseAddr);
   item.EntryAddr := StrToIntDef('$'+Edit4.Text,item.EntryAddr);
   item.SendLoader(OpenDialog1.FileName,TLoaderType(ComboBox1.ItemIndex),@Progress);
  end;
  Form1.Caption := 'Flash Mode';
 end;
end;

procedure TForm1.Button10Click(Sender: TObject);

 procedure Progress(const position,max:integer);
 begin
  Form1.Caption := Format('Save Mem: progress %.2f/%.2f kB',[position/1024,max/1024]);
  Application.ProcessMessages;
 end;

const Rar='C:\Progra~1\WinRar\WinRar.exe';

var item : TMotoFlashModemItem;
    AAddr: TMemPoint;
    FileName:string;
    RarParam:string;
    Time : Cardinal;
begin
 if (ListBox1.ItemIndex<0) and (ListBox1.ItemIndex>=ListBox1.Count) then exit;
 item := MotoFlashMode1.DeviceList.Items[ListBox1.ItemIndex];
 if item=nil then exit;
 if item.IsOpened then begin
  AAddr.StartAddr    := StrToInt('$'+Edit1.Text);
  AAddr.EndAddr      := StrToInt('$'+Edit2.Text);
  Form1.Caption      := 'Save Mem: ...';
  SaveDialog1.Filter := 'Bin files (*.bin)|*.bin';
  if SaveDialog1.Execute then begin
   FileName := SaveDialog1.FileName;
   if ExtractFileExt(FileName)='' then
     FileName := FileName + '.bin';
   Time := GetTickCount;
   item.LSaveMem(AAddr,FileName,@Progress);
   Time := (GetTickCount-Time) div 1000;
   ShowMessage(Format('Finished! Create Backup Time: %d minutes %d second',[Time div 60,Time mod 60]));
   if CheckBox1.Checked then
    item.Restart;
   if CheckBox2.Checked then
    if FileExists(Rar) then begin
     FileName := ExtractShortPathName(FileName);
     SetCurrentDir(ExtractFileDir(FileName));
     FileName := ExtractFileName(FileName);
     RarParam := Format('a -df -ep -m5 %s %s',[ChangeFileExt(FileName,'.rar'),FileName]);
     ShellExecute(Handle,'Open',Rar,PChar(RarParam),nil,Sw_Show);
    end;
  end;
  Form1.Caption := 'Flash Mode';
 end;
end;

procedure TForm1.Button11Click(Sender: TObject);
var item : TMotoFlashModemItem;
begin
 if (ListBox1.ItemIndex<0) and (ListBox1.ItemIndex>=ListBox1.Count) then exit;
 item := MotoFlashMode1.DeviceList.Items[ListBox1.ItemIndex];
 if item=nil then exit;
 Form1.Caption := 'Erase Memory - This process don`t view';
 if item.IsOpened then
  item.LErase;
 Form1.Caption := 'Flash Mode';
end;

procedure TForm1.Button12Click(Sender: TObject);

 procedure Progress(const position,max:integer);
 begin
  Form1.Caption := Format('Send Binary: progress %.2f/%.2f kB',[position/1024,max/1024]);
  Application.ProcessMessages;
 end;

var item : TMotoFlashModemItem;
begin
 if (ListBox1.ItemIndex<0) and (ListBox1.ItemIndex>=ListBox1.Count) then exit;
 item := MotoFlashMode1.DeviceList.Items[ListBox1.ItemIndex];
 if item=nil then exit;
 if item.IsOpened then begin
  Form1.Caption  := 'Send Binary: ...';
  OpenDialog1.Filter := 'BIN Files (*.bin)|*.bin|All Files (*.*)|*.*';
  if OpenDialog1.Execute then begin
   item.StartBinary  := StrToIntDef('$'+Edit6.Text,item.StartBinary);
   item.LSendBinary(OpenDialog1.FileName,@Progress);
  end;
  Form1.Caption := 'Flash Mode';
 end;
end;

procedure TForm1.MotoFlashMode1Debug(const AItem: TMotoFlashModemItem;
  const ADebugText: String; const ADebugType: TDebugType;
  const ASubError: Boolean);
var S:string;
begin
 if not CheckBox3.Checked and ASubError then exit;
 if ADebugType=dtError then
  S := '[E] '
 else
  S := '[I] ';
 if ASubError then
  S := S+' + ';
 S := S + ADebugText;
 AddDebug(S);
end;

procedure TForm1.MotoFlashMode1Arrival(Sender: TObject);
begin
 GetDevises;
end;

procedure TForm1.Button13Click(Sender: TObject);
var item : TMotoFlashModemItem;
begin
 Memo2.Clear;
 if (ListBox1.ItemIndex<0) and (ListBox1.ItemIndex>=ListBox1.Count) then exit;
 item := MotoFlashMode1.DeviceList.Items[ListBox1.ItemIndex];
 if item=nil then exit;
 if item.IsOpened then
  Memo2.Text := 'IMEI: '+item.LGetInfoImei;
end;

procedure TForm1.Button14Click(Sender: TObject);
var item : TMotoFlashModemItem;
begin
 Memo2.Clear;
 if (ListBox1.ItemIndex<0) and (ListBox1.ItemIndex>=ListBox1.Count) then exit;
 item := MotoFlashMode1.DeviceList.Items[ListBox1.ItemIndex];
 if item=nil then exit;
 if item.IsOpened then
  Memo2.Text := 'Serial Number: '+item.GetSerialNumber;
end;

procedure TForm1.MotoP2KMode1Arrival(Sender: TObject);
var i:integer;
begin
 for i:=0 to MotoP2KMode1.DeviceList.Count-1 do
  with MotoP2KMode1.DeviceList.Items[i] do begin
   Open;
   if IsOpened then
    SwitchFlash;
   Close;
  end;
end;

procedure TForm1.Button15Click(Sender: TObject);
var item : TMotoFlashModemItem;
       r : string;
begin
 if (ListBox1.ItemIndex<0) and (ListBox1.ItemIndex>=ListBox1.Count) then exit;
 item := MotoFlashMode1.DeviceList.Items[ListBox1.ItemIndex];
 if item=nil then exit;
 Form1.Caption := 'Send Command';
 if item.IsOpened then begin
  r := item.SendCommand(Edit5.Text,Edit6.Text);
  AddDebug(Format('[I] Read Command >> "%s"',[r]));
 end;
 Form1.Caption := 'Flash Mode';
end;

end.

⌨️ 快捷键说明

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