import 'dart:ffi'; import 'package:ffi/ffi.dart'; final kernel32 = DynamicLibrary.open('kernel32.dll'); // GetLogicalDrives fonksiyonunu yükleyelim final getLogicalDrives = kernel32.lookupFunction('GetLogicalDrives'); // 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.'); } // Cihaz ID'sini almak için fonksiyon String getDeviceDiskId() { final drivePath = getFirstDriveLetter().toNativeUtf16(); final volumeName = calloc(256); final serialNumber = calloc(); final maxComponentLength = calloc(); final fileSystemFlags = calloc(); final fileSystemName = calloc(256); 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); } }