import 'dart:ffi'; import 'package:ffi/ffi.dart'; // Windows API'lerini kullanacak olan kernel32 kütüphanesini açıyoruz final kernel32 = DynamicLibrary.open('kernel32.dll'); // GetVolumeInformationW fonksiyonunu yükleyelim final getVolumeInformation = kernel32.lookupFunction lpRootPathName, Pointer lpVolumeNameBuffer, Uint32 nVolumeNameSize, Pointer lpVolumeSerialNumber, Pointer lpMaximumComponentLength, Pointer lpFileSystemFlags, Pointer lpFileSystemNameBuffer, Uint32 nFileSystemNameSize), int Function(Pointer lpRootPathName, Pointer lpVolumeNameBuffer, int nVolumeNameSize, Pointer lpVolumeSerialNumber, Pointer lpMaximumComponentLength, Pointer lpFileSystemFlags, Pointer lpFileSystemNameBuffer, int nFileSystemNameSize)>('GetVolumeInformationW'); // İlk sürücüyü bulma fonksiyonu String getFirstDriveLetter() { final drivesBitMask = getLogicalDrives(); for (int i = 0; i < 26; i++) { if ((drivesBitMask & (1 << i)) != 0) { return '${String.fromCharCode(65 + i)}:\\'; } } throw Exception('No logical drives found.'); } // GetLogicalDrives fonksiyonunu yükleyelim final getLogicalDrives = kernel32.lookupFunction('GetLogicalDrives'); // Cihaz ID'sini almak için fonksiyon String getDeviceId() { final drivePath = getFirstDriveLetter().toNativeUtf16(); final volumeName = calloc(256); // Pointer ayarlıyoruz final serialNumber = calloc(); final maxComponentLength = calloc(); final fileSystemFlags = calloc(); final fileSystemName = calloc(256); // Pointer ayarlıyoruz try { final result = getVolumeInformation( drivePath, volumeName, 256, serialNumber, maxComponentLength, fileSystemFlags, fileSystemName, 256, ); if (result != 0) { // Cihaz seri numarasını döndür return serialNumber.value.toRadixString(16).toUpperCase(); } else { throw Exception('GetVolumeInformation failed.'); } } finally { // Bellek temizliği calloc.free(drivePath); calloc.free(volumeName); calloc.free(serialNumber); calloc.free(maxComponentLength); calloc.free(fileSystemFlags); calloc.free(fileSystemName); } }