12-05-2017, Saat: 14:07
(Son Düzenleme: 12-05-2017, Saat: 14:19, Düzenleyen: TescilsizUzman.)
Android ADB USB üzeri cihaz bilgilerini okuma
[Ars=delphi]function IsWinNT: boolean;
var
OSV: OSVERSIONINFO;
begin
OSV.dwOSVersionInfoSize := sizeof(osv);
GetVersionEx(OSV);
result := OSV.dwPlatformId = VER_PLATFORM_WIN32_NT;
end;
function Shell(Cmd: string): string;
var
Buffer: array[0..10096] of Char;
si: STARTUPINFO;
sa: SECURITY_ATTRIBUTES;
sd: SECURITY_DESCRIPTOR;
pi: PROCESS_INFORMATION;
newstdin, newstdout, read_stdout, write_stdin: THandle;
exitcod, bread, avail: Cardinal;
Str: string;
begin
Result:= '';
SetCurrentDir(ExtractFilePath(Application.ExeName));
if IsWinNT then
begin
InitializeSecurityDescriptor(@sd, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(@sd, true, nil, false);
sa.lpSecurityDescriptor := @sd;
end
else sa.lpSecurityDescriptor := nil;
sa.nLength := sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle := TRUE;
if CreatePipe(newstdin, write_stdin, @sa, 0) then
begin
if CreatePipe(read_stdout, newstdout, @sa, 0) then
begin
GetStartupInfo(si);
with si do
begin
dwFlags := STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW;
wShowWindow := SW_HIDE;
hStdOutput := newstdout;
hStdError := newstdout;
hStdInput := newstdin;
end;
Fillchar(Buffer, SizeOf(Buffer), 0);
GetEnvironmentVariable('COMSPEC', @Buffer, SizeOf(Buffer) - 1);
StrCat(@Buffer,PChar(' /c ' + cmd));
if CreateProcess(nil, @Buffer, nil, nil, TRUE, CREATE_NEW_CONSOLE, nil, nil, si, pi) then
begin
Str:= #13;
WriteFile(write_stdin,PChar(Str)^,Length(Str),bread,nil);
repeat
PeekNamedPipe(read_stdout, @Buffer, SizeOf(Buffer) - 1, @bread, @avail, nil);
if bread > 0 then
begin
Fillchar(Buffer, SizeOf(Buffer), 0);
ReadFile(read_stdout, Buffer, bread, bread, nil);
Result:= Result + String(PChar(@Buffer));
end;
GetExitCodeProcess(pi.hProcess, exitcod);
until (exitcod <> STILL_ACTIVE) and (bread = 0);
end;
CloseHandle(read_stdout);
CloseHandle(newstdout);
end;
CloseHandle(newstdin);
CloseHandle(write_stdin);
end;
end;
//*********************************************************************************
Function getbeetwen( text, ilk, son:String ): String;
begin
Delete(Text, 1, pos(ilk, Text) + Length(ilk)-1);
Result := Copy(Text, 1, Pos(Son, Text)-1);
end;
//****************************************************************************
procedure TForm1.readinfo;
var devicetype , imei, chk, cihaz_ara : String;
begin
begin
txtlog('Cihaz Aranıyor... ');
txtlog.Clear;
cihaz_ara :=(Shell('adb get-state'));
if pos('unknown',cihaz_ara)>0 then begin
txtlog('Cihaz bulunmadı !');
end
else
txtlog('Cihaz Bulundu !');
txtlog('Reading Info............');
txtlog(AnsiUpperCase(Trim('Manufacturer : '+(Shell('adb shell getprop ro.product.brand')))));
txtlog(AnsiUpperCase(Trim('Hardware : '+(Shell('adb shell getprop ro.hardware')))));
txtlog(AnsiUpperCase(Trim('Model : '+(Shell('adb shell getprop ro.product.model')))));
txtlog(AnsiUpperCase(Trim('BaseBand : '+(Shell('adb shell getprop ro.boot.baseband')))));
txtlog(AnsiUpperCase(Trim('Board : '+(Shell('adb shell getprop ro.product.board')))));
txtlog(AnsiUpperCase(Trim('Version : '+(Shell('adb shell getprop ro.build.version.release')))));
chk:=Shell('adb shell dumpsys iphonesubinfo');
devicetype:=getbeetwen(chk, 'Type =', 'Device');
imei:=copy(chk,62,15);
txtlog(AnsiUpperCase(Trim('Device Type : '+devicetype)));
txtlog(AnsiUpperCase(Trim('Country Code : '+(Shell('adb shell getprop ro.build.target_country')))));
txtlog(AnsiUpperCase(Trim('Connection Mode : '+(Shell('adb shell getprop sys.usb.config')))));
txtlog(AnsiUpperCase(Trim('IMEI : '+imei)));
end;
procedure TForm1.txtlog(s: string);
begin
Memo1.Lines.Add(s);
end;
//*********************************************************************************
procedure TForm1.Button1Click(Sender: TObject);
begin
readinfo;
end;[/ars]
[Ars=delphi]function IsWinNT: boolean;
var
OSV: OSVERSIONINFO;
begin
OSV.dwOSVersionInfoSize := sizeof(osv);
GetVersionEx(OSV);
result := OSV.dwPlatformId = VER_PLATFORM_WIN32_NT;
end;
function Shell(Cmd: string): string;
var
Buffer: array[0..10096] of Char;
si: STARTUPINFO;
sa: SECURITY_ATTRIBUTES;
sd: SECURITY_DESCRIPTOR;
pi: PROCESS_INFORMATION;
newstdin, newstdout, read_stdout, write_stdin: THandle;
exitcod, bread, avail: Cardinal;
Str: string;
begin
Result:= '';
SetCurrentDir(ExtractFilePath(Application.ExeName));
if IsWinNT then
begin
InitializeSecurityDescriptor(@sd, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(@sd, true, nil, false);
sa.lpSecurityDescriptor := @sd;
end
else sa.lpSecurityDescriptor := nil;
sa.nLength := sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle := TRUE;
if CreatePipe(newstdin, write_stdin, @sa, 0) then
begin
if CreatePipe(read_stdout, newstdout, @sa, 0) then
begin
GetStartupInfo(si);
with si do
begin
dwFlags := STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW;
wShowWindow := SW_HIDE;
hStdOutput := newstdout;
hStdError := newstdout;
hStdInput := newstdin;
end;
Fillchar(Buffer, SizeOf(Buffer), 0);
GetEnvironmentVariable('COMSPEC', @Buffer, SizeOf(Buffer) - 1);
StrCat(@Buffer,PChar(' /c ' + cmd));
if CreateProcess(nil, @Buffer, nil, nil, TRUE, CREATE_NEW_CONSOLE, nil, nil, si, pi) then
begin
Str:= #13;
WriteFile(write_stdin,PChar(Str)^,Length(Str),bread,nil);
repeat
PeekNamedPipe(read_stdout, @Buffer, SizeOf(Buffer) - 1, @bread, @avail, nil);
if bread > 0 then
begin
Fillchar(Buffer, SizeOf(Buffer), 0);
ReadFile(read_stdout, Buffer, bread, bread, nil);
Result:= Result + String(PChar(@Buffer));
end;
GetExitCodeProcess(pi.hProcess, exitcod);
until (exitcod <> STILL_ACTIVE) and (bread = 0);
end;
CloseHandle(read_stdout);
CloseHandle(newstdout);
end;
CloseHandle(newstdin);
CloseHandle(write_stdin);
end;
end;
//*********************************************************************************
Function getbeetwen( text, ilk, son:String ): String;
begin
Delete(Text, 1, pos(ilk, Text) + Length(ilk)-1);
Result := Copy(Text, 1, Pos(Son, Text)-1);
end;
//****************************************************************************
procedure TForm1.readinfo;
var devicetype , imei, chk, cihaz_ara : String;
begin
begin
txtlog('Cihaz Aranıyor... ');
txtlog.Clear;
cihaz_ara :=(Shell('adb get-state'));
if pos('unknown',cihaz_ara)>0 then begin
txtlog('Cihaz bulunmadı !');
end
else
txtlog('Cihaz Bulundu !');
txtlog('Reading Info............');
txtlog(AnsiUpperCase(Trim('Manufacturer : '+(Shell('adb shell getprop ro.product.brand')))));
txtlog(AnsiUpperCase(Trim('Hardware : '+(Shell('adb shell getprop ro.hardware')))));
txtlog(AnsiUpperCase(Trim('Model : '+(Shell('adb shell getprop ro.product.model')))));
txtlog(AnsiUpperCase(Trim('BaseBand : '+(Shell('adb shell getprop ro.boot.baseband')))));
txtlog(AnsiUpperCase(Trim('Board : '+(Shell('adb shell getprop ro.product.board')))));
txtlog(AnsiUpperCase(Trim('Version : '+(Shell('adb shell getprop ro.build.version.release')))));
chk:=Shell('adb shell dumpsys iphonesubinfo');
devicetype:=getbeetwen(chk, 'Type =', 'Device');
imei:=copy(chk,62,15);
txtlog(AnsiUpperCase(Trim('Device Type : '+devicetype)));
txtlog(AnsiUpperCase(Trim('Country Code : '+(Shell('adb shell getprop ro.build.target_country')))));
txtlog(AnsiUpperCase(Trim('Connection Mode : '+(Shell('adb shell getprop sys.usb.config')))));
txtlog(AnsiUpperCase(Trim('IMEI : '+imei)));
end;
procedure TForm1.txtlog(s: string);
begin
Memo1.Lines.Add(s);
end;
//*********************************************************************************
procedure TForm1.Button1Click(Sender: TObject);
begin
readinfo;
end;[/ars]