Created
April 19, 2016 22:53
-
-
Save musoftware/10edfbb3978aa627741e76b44905ccf9 to your computer and use it in GitHub Desktop.
Device Fingerprint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| internal static class DeviceFingerprintProvider | |
| { | |
| public static async Task<string> DeviceFingerprintAsync() | |
| { | |
| DeviceFingerprintProvider.DiskSpace diskSpace = await DeviceFingerprintProvider.GetDiskSpaceAsync(); | |
| List<string> appNames = new List<string>(); | |
| string fingerprintFormat = "{{\n dfid: {{\n \"tds\": {0},\n \"fds\": {1},\n \"boot_time\": {2},\n \"apps\": {{\n \"version\": 0,\n \"names\": [{3}]\n }}\n }}\n}}"; | |
| ulong tds = diskSpace.TotalSpace / 1024UL; | |
| ulong fds = diskSpace.FreeSpace / 1024UL; | |
| ulong bootTime = await DeviceFingerprintProvider.UnixBootTimeAsync(); | |
| string appNamesString = appNames.Count > 0 ? "\"" + Enumerable.Aggregate<string>((IEnumerable<string>) appNames, (Func<string, string, string>) ((a, b) => a + "\", \"" + b)) + "\"" : ""; | |
| string fingerprint = string.Format(fingerprintFormat, (object) tds, (object) fds, (object) bootTime, (object) appNamesString); | |
| return fingerprint; | |
| } | |
| private static async Task<DeviceFingerprintProvider.DiskSpace> GetDiskSpaceAsync() | |
| { | |
| DeviceFingerprintProvider.DiskSpace diskSpace = new DeviceFingerprintProvider.DiskSpace(); | |
| try | |
| { | |
| foreach (DriveInfo driveInfo in DriveInfo.GetDrives()) | |
| { | |
| if (driveInfo.IsReady && driveInfo.DriveType == DriveType.Fixed) | |
| { | |
| diskSpace.FreeSpace += (ulong) driveInfo.AvailableFreeSpace; | |
| diskSpace.TotalSpace += (ulong) driveInfo.TotalSize; | |
| } | |
| } | |
| bool flag; | |
| int num = flag ? 1 : 0; | |
| } | |
| catch (Exception ex) | |
| { | |
| } | |
| return diskSpace; | |
| } | |
| private static async Task<ulong> UnixBootTimeAsync() | |
| { | |
| return UnixTimestampConverter.ToUnixTime(DateTime.Now) - (ulong) Environment.TickCount / 1000UL; | |
| } | |
| private struct DiskSpace | |
| { | |
| public ulong TotalSpace; | |
| public ulong FreeSpace; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment