Hiding (or encrypting) app resources?

前端 未结 3 1154
我寻月下人不归
我寻月下人不归 2021-01-02 10:15

I\'ve developing a Cocoa app that has certain resources (images) which I wish to protect, but still display. Normally one would just place these in the resources folder, bu

3条回答
  •  长情又很酷
    2021-01-02 11:08

    Simple solution:

    Merge all files into one big data-file, optionally using 'salts'.
    Then retrieve specific files with something like this:

    NSData *dataFile = [NSData dataWithContentsOfFile:filePath];  
    NSData *theFile = [dataFile subdataWithRange: NSMakeRange(startPos,endPos)];
    

    This does not really protect the files,
    but prevents people simply dragging out the resources.
    At least, the data-file is unusable, certainly with salts.

    Another solution:

    Create NSData object for every resource.
    Add all objects to a NSMutableArray.
    Convert the array to one big NSData object.
    Write the NSData object to a file.
    And add it to the resources folder.

    Your app can then read the data-file.
    And retrieve the array with the resources.

    // Convert array to data
    NSData* data=[NSKeyedArchiver archivedDataWithRootObject:theArray];
    

    Use NSKeyedUnarchiver to retrieve the array again.

提交回复
热议问题