recreating SystemInfo.deviceUniqueIdentifier

Hello All,

I’m looking to recreate (or duplicate) SystemInfo.deviceUniqueIdentifier in the same manner that Unity creates them. This is purely so that they match between our code bases. They come from the SystemInfo.deviceUniqueIdentifier api in C#.

I’d like to recreate them in c++ or native on the following platforms:
Android (done)
Windows exe
Windows Browser
Mac OS X app (done)
Mac Browser (done)
iOS (done)

Android (may not be correct on all devices):

		if( g_strSecureAndroidId == null ){
			g_strSecureAndroidId = Settings.Secure.getString(MainActivity.sInstance.getContentResolver(), Settings.Secure.ANDROID_ID);
		   try {
		        java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
		        byte[] array = md.digest(g_strSecureAndroidId.getBytes());
		        StringBuffer sb = new StringBuffer();
		        for (int i = 0; i < array.length; ++i) {
		          sb.append(Integer.toHexString((array[i]  0xFF) | 0x100).substring(1,3));
		        }
		        g_strSecureAndroidId = sb.toString();
		        
		    } catch (java.security.NoSuchAlgorithmException e) {
		    	// do nothing if no such algorithm
		    }
		}
		
		return g_strSecureAndroidId;

Mac Implementation:

    CFUUIDBytes uuidBytes;
    const struct timespec spec = {0, 0};
    gethostuuid((unsigned char *)&uuidBytes, &spec);
    CFUUIDRef uuid = CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, uuidBytes);
    CFStringRef uuidString = CFUUIDCreateString(kCFAllocatorDefault, uuid);
    NSString * uuidNSString = (NSString* ) uuidString;
    if (uuid) CFRelease(uuid);
    std::string temp = std::string([uuidNSString UTF8String]);
    return temp;

For windows, it looks like sha1 but of what? Also it uses the same number that the browsers builds use.

Now for iOS, you can look at the stickie on the forums for this one. Easiest method is to build for iOS and copy unity methods into your objective-c.

1 Like

well i found out that mac and mac browser were from the hardware ID of the system…

Just wanted to drop in and bump the thread.
Only windows is needed now, we’ve figured out the other platforms on the list above.

bumping the thread again.

Bumping the thread again.
Still looking for a way to duplicate Windows device ID. I suspect this is a UUID from the registry but I don’t have the time to try every possible guess for something that might match on there. I’m hoping a unity dev might jump in (or someone else that has a similar desire).

I put implementations in case someone else DOES want a similar thing i’m looking for. This could save you the time of googleing around for a day or so.