procedure TForm1.btngetUniClick(Sender: TObject);
var
  datalen:Integer;
  a:string;
  outfile:tfilestream;
begin
  SetBuzy;
  with SaveDialog do begin
       Options:=Options+[ofFileMustExist]-[ofHideReadOnly]
        +[ofNoChangeDir]-[ofNoLongNames]-[ofNoNetworkButton]-[ofHideReadOnly]
        -[ofOldStyleDialog]+[ofOverwritePrompt]+[ofPathMustExist]
        -[ofReadOnly]-[ofShareAware]-[ofShowHelp];
       FilterIndex:=1;
       FileName :=StatusBar.Panels.Items[0].Text+'_'+StatusBar.Panels.Items[2].Text ;
       InitialDir := '.\';
       DefaultExt := '.WD2pb';
       Filter := 'WD2pb(*.WD2pb)|*.WD2pb';
       Title:='Save WD2phonebook to ...';
       end;

         if SaveDialog.Execute then begin
  setbuzy;
  wd2fsize:=0;
  _msg('Searching for phonebook...');
  _msg('Initialising FS...');
  _msg('Skip check FS...');
  _msg('Search in progress, please, wait...');
  datalen:=WD2listdir('C:\system\Data');
  if datalen>0 then begin
  _msg('PhoneBook found!');
  _msg('SizeOf PB is : '+inttostr(datalen)+' bytes...');
  _msg('SleepUp... Wait for phone....');
  Application.ProcessMessages;
  Sleep(50);
  _msg('Prepare done...');
  _msg('Wait for phone...');
  Application.ProcessMessages;
  _msg('Init data...');
  Wd2fsize:=datalen;
  _msg('Phone Ready for eXtract :)');
  _msg('Initialise Reading...');
  Application.ProcessMessages;
    Sleep(200);
           outfile:=TFileStream.Create(SaveDialog.FileName,fmCreate);
          if not fbusgetfileWd2nd(outfile,'C:\system\DataContacts.cdb',wd2fsize) then begin

          _msg('Error');
          outfile.Free;
          end
          else begin
           outfile.Free;
           _msg('Saved to '+savedialog.filename);
           _msg('Done!');
           end;
        end
         else begin
  _msg('Error! Try again few times, please');
  _msg('If still no luck - Repower phone and try restart pocedure....');
  _msg('If still no luck - looks like FS damaged... :(');
  _msg('Anyway if PhoneBook needed - contact with support.');
  setready;
  _msg('');
  end;
  setready;
   end;

 SetReady;
 end;
 
 
 //FbusMain
function WD2listdir(path:string):integer;
var
  s,s2,hider:string;
  framelen,pathlen:Word;
  datalen:DWORD;
  i:Integer;
  data,data2:string;
begin
  result:=0;
  Form1.pb1.MaxValue:=45;
  Form1.pb1.progress:=0;
s:='';hider:='';s2:=''; data2:='';
hider:=chr($1E)+chr(0)+chr($10)+chr($58)+chr(0)+chr(0)+chr(0)+chr($11)+chr($06)+chr($0B)+chr(0)+chr($01)+chr($07)+chr($14)+chr(Length(path))+chr($00);
s:=hider+path+chr(0)+chr(0)+chr($01)+Chr($40);
framelen:=Length(s)-6;
word((@s[5])^):=framelen;
WordSwap(@s[5]);
i:=1;
 FbusRunCommand(@s[1], Length(s));
 data:=BufToHexStr(@fbusstr[1],Length(FbusStr));
 if Length(data)<10 then begin
   result:=0;
   Exit;
   end;
 repeat
   begin
   fbusstr:='';
    if not FbusSendAsk then begin
     if data2<>'' then begin
     result:=hextoint(Copy(data2,21,8));
      end
     else result:=0;
     exit;
    end;
    if not FbusAck then begin
     if data2<>'' then begin
     result:=hextoint(Copy(data2,21,8));
      end
     else result:=0;
     exit;
    end;
    if not FbusAns then begin
     if data2<>'' then begin
     result:=hextoint(Copy(data2,21,8));
      end
     else result:=0;
     exit;

    end;
   data:=BufToHexStr(@fbusstr[1],Length(FbusStr));
  Application.ProcessMessages;
  Form1.pb1.progress:=Form1.pb1.progress+1;
  ///form1.lst1.items.add(data);
  i:=i+1;
  if Pos('436F6E74616374732E636462',data)>0 then data2:=data;
   end;
    //Form1._msg(Byte2Str(FbusAnsB[10]));
 until FbusAnsB[10]=$0F ;
 Form1._msg('Scan done, processing data...');
 if data2<>'' then begin
   Form1._msg('Some data found, wait, checking...');
   Form1.pb1.progress:=0;
   Form1.pb1.MaxValue:=100;
   result:=hextoint(Copy(data2,21,8));
   end
   else result:=0;
 end;
 
function fbusgetfileWd2nd(F:TFileStream;fullpath:string;len:Integer):boolean;
var
  s,s2,hider:string;
  framelen,pathlen:Word;
  datalen:DWORD;
  i,i2:Integer;
  instr:string;
  curlen:word;
  blkcount:Integer;
  ostlen:word;
begin
blkcount:=Len div $3D4;
ostlen:=len mod $3D4;
form1.lst1.items.add('Block count : '+inttostr(blkcount));
Form1.pb1.maxvalue:=blkcount;
s:='';hider:='';s2:=''; instr:=''; i:=0;
hider:=chr($1E)+chr($00)+chr($10)+chr($58)+chr($00)+chr($00)+chr($00)+chr($11)+chr($0E)+chr($0D)+chr($10)+chr($01)+chr($07)+chr($20)+chr($0E)+chr($0C);
//hider:=chr($1E)+chr(0)+chr($10)+chr($58)+chr(0)+chr(0)+chr(0)+chr($10)+chr($0C)+chr($0B)+chr(0)+chr($01)+chr($07)+chr($14)+chr($0E)+chr($0C);
s:=hider+fullpath+chr(0)+chr(0)+chr($01)+Chr($40);
framelen:=Length(s)-6;
word((@s[5])^):=framelen;
WordSwap(@s[5]);
  if blkcount>1 then begin
try
 FbusRunCommand(@s[1], Length(s));
 Sleep(20);
 F.Write(FbusStr[19],$3D4);
 Application.ProcessMessages;
 form1.lst1.Items.Add('1st blk OK....');
 datalen:=0;
 DWord((@WD2readcycle[16])^):=0;
 i:=1;
 Form1.pb1.progress:=1;
 Sleep(20);
 for i2:=1 to blkcount-1 do
  begin
 FbusRunCommand(@WD2readcycle, Length(WD2readcycle));
    datalen:=datalen+$3D4;
    curlen:=hextoint(BufToHexStr(@FbusStr[13],2));
   if curlen<>$3D4 then begin
    form1.lst1.items.Add('Error, CS bricked!');
    result:=false;
    Form1.pb1.MaxValue:=100;
    Form1.pb1.progress:=0;
    Exit;
    end; 
    F.Write(FbusStr[19],$3D4);
    i:=i+1;
    DWord((@WD2readcycle[16])^):=datalen;
    DWordSwap(@WD2readcycle[16]);
    Application.ProcessMessages;
   // form1.lst1.Items.Add('Next '+inttostr(i)+' blk OK....');
    Form1.pb1.progress:=Form1.pb1.progress+1;
    //Sleep(50);
  end;
  if ostlen>0 then begin
  form1.lst1.Items.Add('Last blk Ok... Reading done...');
   FbusRunCommand(@WD2readcycle, Length(WD2readcycle));
    F.Write(FbusStr[19],ostlen);
   end
  else begin
  form1.lst1.Items.Add('Last blk Ok... Reading done...');
  end;
 Form1.pb1.MaxValue:=100;
    Form1.pb1.progress:=0;
   Result:=True;
except
begin
    Form1.pb1.MaxValue:=100;
    Form1.pb1.progress:=0;
   result:=False;
end;
  end;
end
else begin
  Form1.lst1.Items.add('Nothing to read! :( ');
 result:=false;
end;
end;


///Fboots.pas

WD2readcycle : array [0..21] of Byte =
($1E, $00, $10, $58, $00, $10, $00, $11, $0E, $0D, $20, $01, $F0, $08, $20, $00, $00, $00, $00, $00, $01, $40);