iPA解压后显示应用文件内容,打开exec显示我的本地路径
Show Content of app file after unzipping the iPA, and opening exec shows my local path
我开发了一个应用程序,我需要从生成的 iPA 文件中删除我的计算机本地路径。
我做了以下操作:
- 正在解压缩 iPA 文件。
- 点击显示包内容。
- 用文本编辑器打开 exec(appname.exec) 文件。
现在我可以看到一些二进制内容,以及带有我的计算机本地路径(带有我的 mac 名称)的字符串。
由于安全问题,我必须从 exec 文件中删除这些路径。我该怎么做?
你不能这样做。首先它会破坏代码签名,其次它既耗时又容易出错。
正确的方法是不要在代码中使用完整路径,而是使用 NSSearchPathForDirectoriesInDomains
之类的方法来获取 Documents 文件夹或您要使用的任何目录。
正如Accessing Files and Directories所说:
Although you can open any file and read its contents as a stream of bytes, doing so is not always the right choice. OS X and iOS provide built-in support that makes opening many types of standard file formats (such as text files, images, sounds, and property lists) much easier. For these standard file formats, you should use the higher-level options for reading and writing the file contents. Table 2-1 lists the common file types supported by the system along with information about how you access them.
您有多种保存数据的方法:
- 指定文件或目录的路径
- 在您的 App Bundle 中定位项目
- 在标准目录中查找项目
- 使用书签定位文件
您已选择 Specifying the Path to a File or Directory
,正如@Droppy 所说
Firstly it will break the code signature and secondly it's time consuming and error prone.
你最好选择Locating Items in the Standard Directories
以下是您应该选择这种方式的原因:
Locating Items in the Standard Directories
When you need to locate a file in one of the standard directories, use the system frameworks to locate the directory first and then use the resulting URL to build a path to the file. The Foundation framework includes several options for locating the standard system directories. By using these methods, the paths will be correct whether your app is sandboxed or not:
The URLsForDirectory:inDomains: method of the NSFileManager class returns a directory’s location packaged in an NSURL object. The directory to search for is an NSSearchPathDirectory constant. These constants provide URLs for the user’s home directory, as well as most of the standard directories.
The NSSearchPathForDirectoriesInDomains function behaves like the URLsForDirectory:inDomains: method but returns the directory’s location as a string-based path. You should use the URLsForDirectory:inDomains: method instead.
The NSHomeDirectory function returns the path to either the user’s or app’s home directory. (Which home directory is returned depends on the platform and whether the app is in a sandbox.) When an app is sandboxed the home directory points to the app’s sandbox, otherwise it points to the User’s home directory on the file system. If constructing a file to a subdirectory of a user’s home directory, you should instead consider using the URLsForDirectory:inDomains: method instead.
You can use the URL or path-based string you receive from the preceding routines to build new objects with the locations of the files you want. Both the NSURL and NSString classes provide path-related methods for adding and removing path components and making changes to the path in general. Listing 2-1 shows an example that searches for the standard Application Support directory and creates a new URL for a directory containing the app’s data files.
我开发了一个应用程序,我需要从生成的 iPA 文件中删除我的计算机本地路径。
我做了以下操作:
- 正在解压缩 iPA 文件。
- 点击显示包内容。
- 用文本编辑器打开 exec(appname.exec) 文件。
现在我可以看到一些二进制内容,以及带有我的计算机本地路径(带有我的 mac 名称)的字符串。
由于安全问题,我必须从 exec 文件中删除这些路径。我该怎么做?
你不能这样做。首先它会破坏代码签名,其次它既耗时又容易出错。
正确的方法是不要在代码中使用完整路径,而是使用 NSSearchPathForDirectoriesInDomains
之类的方法来获取 Documents 文件夹或您要使用的任何目录。
正如Accessing Files and Directories所说:
Although you can open any file and read its contents as a stream of bytes, doing so is not always the right choice. OS X and iOS provide built-in support that makes opening many types of standard file formats (such as text files, images, sounds, and property lists) much easier. For these standard file formats, you should use the higher-level options for reading and writing the file contents. Table 2-1 lists the common file types supported by the system along with information about how you access them.
您有多种保存数据的方法:
- 指定文件或目录的路径
- 在您的 App Bundle 中定位项目
- 在标准目录中查找项目
- 使用书签定位文件
您已选择 Specifying the Path to a File or Directory
,正如@Droppy 所说
Firstly it will break the code signature and secondly it's time consuming and error prone.
你最好选择Locating Items in the Standard Directories
以下是您应该选择这种方式的原因:
Locating Items in the Standard Directories When you need to locate a file in one of the standard directories, use the system frameworks to locate the directory first and then use the resulting URL to build a path to the file. The Foundation framework includes several options for locating the standard system directories. By using these methods, the paths will be correct whether your app is sandboxed or not:
The URLsForDirectory:inDomains: method of the NSFileManager class returns a directory’s location packaged in an NSURL object. The directory to search for is an NSSearchPathDirectory constant. These constants provide URLs for the user’s home directory, as well as most of the standard directories. The NSSearchPathForDirectoriesInDomains function behaves like the URLsForDirectory:inDomains: method but returns the directory’s location as a string-based path. You should use the URLsForDirectory:inDomains: method instead. The NSHomeDirectory function returns the path to either the user’s or app’s home directory. (Which home directory is returned depends on the platform and whether the app is in a sandbox.) When an app is sandboxed the home directory points to the app’s sandbox, otherwise it points to the User’s home directory on the file system. If constructing a file to a subdirectory of a user’s home directory, you should instead consider using the URLsForDirectory:inDomains: method instead.
You can use the URL or path-based string you receive from the preceding routines to build new objects with the locations of the files you want. Both the NSURL and NSString classes provide path-related methods for adding and removing path components and making changes to the path in general. Listing 2-1 shows an example that searches for the standard Application Support directory and creates a new URL for a directory containing the app’s data files.