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'); // 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'); // Tüm disklerin seri numaralarını tek bir string olarak almak String getDeviceDiskId() { StringBuffer diskIds = StringBuffer(); // StringBuffer kullanıyoruz final drivesBitMask = getLogicalDrives(); for (int i = 0; i < 26; i++) { if ((drivesBitMask & (1 << i)) != 0) { final driveLetter = '${String.fromCharCode(65 + i)}:\\'; final drivePath = driveLetter.toNativeUtf16(); final volumeName = calloc.allocate(256); // Pointer ayarlıyoruz final serialNumber = calloc(); final maxComponentLength = calloc(); final fileSystemFlags = calloc(); final fileSystemName = calloc.allocate(256); // Pointer ayarlıyoruz try { final result = getVolumeInformation( drivePath, volumeName, 256, serialNumber, maxComponentLength, fileSystemFlags, fileSystemName, 256, ); if (result != 0) { // Seri numarasını StringBuffer'a ekle if (diskIds.isNotEmpty) { diskIds.write('-'); // Araya tire koyuyoruz } diskIds.write(serialNumber.value.toRadixString(16).toUpperCase()); } } finally { // Bellek temizliği calloc.free(drivePath); calloc.free(volumeName); calloc.free(serialNumber); calloc.free(maxComponentLength); calloc.free(fileSystemFlags); calloc.free(fileSystemName); } } } if (diskIds.isEmpty) { throw Exception('No logical drives found.'); } return diskIds.toString(); // StringBuffer'dan string olarak dönüyoruz }