Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

project.pbxproj hashing for files - what hash is used and how?

Tags:

xcode

ios

hash

If you look into project.pbxproj, you shall see that every file in the project has a hash

For example

1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };

1D60589F0D05DD5A006BFB54 is the hash for the linked foundation framework.

I wonder how these are calculated i.e. what function is used and what meta information besides the file name goes into the input for the hash.

like image 589
inteist Avatar asked Mar 25 '14 23:03

inteist


2 Answers

Objective-C:

uuid_t uuid;
uuid_generate(uuid);
NSString *UUID = @"";
    for (int i = 0; i < 12; i++) UUID = [UUID stringByAppendingFormat:@"%02X", uuid[i]];

Python:

def GenerateId(cls):
        return ''.join(str(uuid.uuid4()).upper().split('-')[1:])
like image 162
Sergey Nikitin Avatar answered Nov 01 '22 07:11

Sergey Nikitin


Sergey's solution is (actually very) good, but I think it might deserve some explanation: the only reason why XCode is using that inhuman format for project.pbxproj is likely to ensure that each key is unique.

As a matter of fact, I did some tests before reading Sergey's solution and, as long as the hash is unique and the file is consistent (no dangling files or the like...), you can put as hash pretty much what you want (if UUID-like, at least, I didn't try with shorter strings or non HEX digits...).

The accepted answer also confirm this, since UUID4 is a purely random identifier, as stated here:

UUID4 explanation on Wikipedia

which implies that XCode cannot possibly cross-check the resource with the key (as it could do if the keys where MD5 hashes, for instance).

Hope this will help

like image 20
Rick77 Avatar answered Nov 01 '22 08:11

Rick77