preface
This article continues the other basics of reverse preparation π apply re-signing. The concepts are first introduced, and then tools and scripts are used to automate the process of re-signing once, combined with examples.
First, re-signature
In brief, signature is a security mechanism of Apple inc., which allows apps to be executed by iOS system only when the signature is valid.
1.1 Concepts of re-signatures
Re-signature means replacing the original signature with the existing one on the basis of the original APP.
1.2 Why do I need to Re-sign
- in
No source code
In the case of an application that you’ve already doneResources to modify
(Such as modifiedStart the figure
oricon
, etc.). After the modification, if you want to makeAPP
canNormal use
theAPP
Be sure toThe signature again
Then compress it into an IPA file. - If you want your
APP
It’s not reviewed by Apple, you canTo release
toHTTPS server
On,Don’t escapeCan also beThe installation
And,There is no limit on the number of devicesSo you have toPersonal Developer signature
To replaceEnterprise developer in-house certificate signature
After,OTA release
Will do. A developer
The application needs to be inAnother developer
Post toApp Store
. Uploaded IPA package, yesHeavy signature
After the package.Expired or invalid
Signature applications are required for normal useThe signature again
.
Second, re-signature tool -CodeSign
Codesign installs Xcode, and Xcode also uses this tool to complete the signing process. The signature file contains π
- Resource file
- Macho file
- framework
- . other
2.1 Terminal Commands
Before re-signing using the CoDesign tool, let’s take a look at some terminal instructions for signing π 1. Viewing Signature Information
codesign -vv -d xxx.app
Copy the code
2. List the signable certificates in your keychain
security find-identity -v -p codesigning
Copy the code
3. Otool analyzes macho file information and exports it to a specified file
otool -l xxx > ~/Desktop/machoMessage.txt
Copy the code
Cryptid 0 indicates that no encryption algorithm is used (i.e., shelled), while others indicate encryption.
Can also be directly filtered to see whether to crack π
otool -l xxx | grep cryptid
Copy the code
4. Forcibly replace the signature
Codesign -fs Certificate string file name
codesign -fs "Apple Development: [email protected] (9AN9M5S786)" andromeda.framework
Copy the code
5. Add permission to the file
Chmod +x executable fileCopy the code
6. View the description file
security cms -D -i .. /embedded.mobileprovisionCopy the code
7. Macho signature
Codesign-fs "certificate string" --no-strict -- Entitlements = Permission file. Plist APP packageCopy the code
8. Compress input files into output files
Zip -ry Output file Input fileCopy the code
2.2 Re-signing the codesign command
Take wechat (7.0.8) as an example. Re-sign wechat using a free developer account and install it on a non-jailbroken phone. (wechat (7.0.8) IPA package will be attached at the end of the article)
- unzip
.ipa
Package,Payload
Found in the.app
Right,Display package contents
.
To decompress π, change the suffix. Ipa to. Zip
β οΈ Since the free certificate does not have the ability to sign PlugIns and Watch, delete these two folders directly π
- Signature Frameworks
Sign Frameworks one by one in the Frameworks directory (using your own native free certificate) π
codesign -fs "Apple Development: [email protected] (9AN9M5S786)" andromeda.framework
Copy the code
- Make sure you sign it
app
theMacho file
theExecutable permission
β WeChat.app ls -l WeChat
Copy the code
- Obtain the description file of the free account
Create air project use free account & real machine compile and run to get description file.
Trust the description file in Settings – General – Description file.
Then copy the obtained description file to the WeChat APP package.
- Modify the
bundleId
Find the WeChat info.plist to modify BundleId for our generated description file BundleIdπ
- Gets the permission to the description file
security cms -D -i embedded.mobileprovision
Copy the code
Find the corresponding Entitlements Entitlements Entitlementsπ
<dict>
<key>application-identifier</key>
<string>J7C267M8SE.com.xl.-XFAlgorithmPrj.testWeChat</string>
<key>keychain-access-groups</key>
<array>
<string>J7C267M8SE.*</string>
</array>
<key>get-task-allow</key>
<true/>
<key>com.apple.developer.team-identifier</key>
<string>J7C267M8SE</string>
</dict>
Copy the code
Then create an Entitlements. Plist file, paste the permissions content into π
Copy Entitlements file (Entitlements. Plist) to the same directory as Payload, WeChat. App π
- The signature
Wechat
codesign -fs "Apple Development: [email protected] (9AN9M5S786)" --no-strict --entitlements=entitlements.plist WeChat.app
Copy the code
Then check the signature information of WeChat. App, it has been replaced with π
At this time, install the WeChat. App package to the mobile phone through Xcode, and it should be able to install π normally
Then debug->attach to process->WeChat to debug WeChat π
β οΈ Note: at this time do not use your common account login re-signed wechat (may be blocked).
summary
The above steps for re-signing π
- Remove plug-ins and.app packages with plug-ins
PlugIns
andWatch
folder
- right
Frameworks
Libraries in folders are re-signedcodesign -fs "Apple Development: [email protected] (xxxxxxxxxx)" andromeda.framework
- +X (executable) permissions on executable files
chmod +x WeChat
- add
Description file
- create
shell
Project, real machine run, will describe the file installed to the phone - System Settings
trust
The description file
- create
- replace
WeChat.app
In the packageinfo.plist
BundleId (the BundleId must be the same as in the description file) - Re-sign the.app package by entitlments
security cms -D -i embedded.mobileprovision
Gets the permission to the description file- new
Entitlements.plist
File, will permissionsDict part
Pasted in - Sign the App package with the permission file:
codesign -fs "Apple Development: [email protected] (xxxxxxxxxx)" --no-strict --entitlements=entitlements.plist WeChat.app
- XCode installation
WeChat.app
Package,debug->attach to process->WeChat
Debug wechat.
And you’re done! πΊ πΊ πΊ πΊ πΊ πΊ πΊ πΊ πΊ πΊ πΊ πΊ πΊ πΊ
3. Debug tripartite applications with Xcode re-signature
The above is the way of attaching to process to debug wechat, can we directly debug joint adjustment as we usually develop? Of course can! See the steps below at π
- New project with the same name as wechat
WeChat
Real machine operation
The empty project- Decompress wechat
.ipa
Package, and deleteWatch
andPlugIns
folder - Heavy signature
Frameworks
- Modify the
BundleId
- Will be modified
WeChat.app
Replace the empty projectProducts
In theWeChat.app
- run
At this time, there is WeChat. App in the Products project, Xcode thinks there is, so it directly uses this. At this point you can debug (no need for attach)
Note: β οΈ in some systems, there will be a black screen on wechat for re-signing. It is recommended to re-sign by script.
SHELL script
The shell is a special interactive tool that provides users with a way to launch programs, manage files in the file system, and processes running on the system. A Shell generally refers to a command-line tool. It allows you to enter a text command, then interpret the command and execute it in the kernel. A Shell script is a script file that uses various commands in a text file for one-time execution. The most commonly used related directive is π
4.1 Script Switchover
chsh -s /bin/zsh
Copy the code
4.2 Methods of Executing scripts
Start by creating a shell script file shell. Sh and enter the terminal command π
You can create a.txt file and change the suffix to.sh
mkdir shell1
cd shell1
touch test.txt
Copy the code
π is shown in the figure above
bash FileName
,zsh FileName
- What it does: Recreate one
Subshell (process)
Execute the sentences in the script in the subshell. The currentThe environment has not changed
.
- What it does: Recreate one
source FileName
- Role:
Current Shell environment
Read and execute the command in FileName - Features: Commands can force a script to immediately affect the current environment (typically used to load configuration files).
- Role:
The command forces all commands in the script, regardless of file permissions. 3../FileName * Function: Reads and executes commands in a file. However, the script file must have executable permissions.
4.3 MAC Shell Types
cd /private/etc
cat shells
Copy the code
bash
π macOSThe default
Shell (The old system
),The new system
Switch to azsh
.csh
π wastcsh
To replace thedash
π thanbash
Much smaller and more efficient.ksh
π compatiblebash
sh
π has beenbash
To replace thetcsh
π integratescsh
More features are providedzsh
π replaced thebash
User groups & text permissions
Chmod +x: shell. Sh: chmod +x: shell.
Unix and Linux are multi-user, multi-task systems, so the concept of users and groups is built into such systems. Then the same file permissions also have the corresponding owner of the user and group. Unlike Windows, Unix, Linux, and macOS are multi-user systems π
5.1 Mac File Properties
On a Mac, you can run the ls -l command to view the properties of all files in the current file directory, for example, π
The red box on the far left is [Permission], and the right is [Link] [Owner] [Group] [file size] [Last modified date] [file name].
5.2 permissions
The permission has 10 digits π
In the figure above π
-
Bit 1 file type D /-
d
π Directory-
π file
-
Last 9 bits, file permissions:
[r]
π read, read[w]
π write, write[x]
π execute
β οΈ the positions of the three permissions remain unchanged and are RWX in sequence. Present – The corresponding position indicates that this permission is not available.
- The full permissions of a file are divided into three groups:
- The first group π file owner permissions
- The second group π this group of other user permissions
- Third group π Permissions of users who are not in this group
5.3 chmod
File permissions are changed
usechmod
Command.- There are two Settings: π
Numeric types
Change andsymbols
Change. - File permissions can be divided into π
- Three kinds of
identity
π[user][group][other]
- three
permissions
π[read] [write] [execute]
- Three kinds of
5.3.1 Number Types
Each permission number comparison: R :4 (0100) W :2 (0010) x:1 (0001), the advantage of this design is that it can be by bit or. Same with displacement enumeration in our development.
For example, if the permission of a file is [! – rwxr-xr-x], π User π 4+2+1 = 7 Group π 4+0+1 = 5 Other π 4+0+1 = 5 Then the command is π chmod 755 file name
The corresponding table of numbers and permissions π
Where 0 indicates no permission.
5.3.2 Symbol types
Chmod [u (User), g (Group), o (Other), a (All)], [+ (join), – (minus), = (set)] [r, w, x] file name
For example π
chmod a+x test.txt
Copy the code
The default is all.
6. Automatic re-signing of shell scripts
The script implementation logic is the same as coDesign logic. The full script is at π
${SRCROOT}/Temp ="${SRCROOT}/Temp" ASSETS_PATH="${SRCROOT}/APP" # target ipA package path TARGET_IPA_PATH="${ASSETS_PATH}/*. Ipa TEMP_PATH mkdir -p TEMP_PATH # 1. Unzip -oqq "$TARGET_IPA_PATH" -d "$TEMP_PATH" # Retrieve the temporary APP path TEMP_APP_PATH=$(set --) "$TEMP_PATH/Payload/"*.app; Echo "$1") #2. Echo "$1") #2 $TARGET_APP_PATH ="$BUILT_PRODUCTS_DIR/$target_name. app" echo "app path:$TARGET_APP_PATH" Rm -rf "$TARGET_APP_PATH" mkdir -p "$TARGET_APP_PATH" cp -rf "$TEMP_APP_PATH/" "$TARGET_APP_PATH" # 3. Rm -rf "$TARGET_APP_PATH/PlugIns" rm -rf "$TARGET_APP_PATH/Watch" # 4. Update info. Plist file CFBundleIdentifier # Set :"Set: KEY Value" "target file path" PlistBuddy is shipped with Apple. /usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier $PRODUCT_BUNDLE_IDENTIFIER" "$TARGET_APP_PATH/Info.plist" /usr/libexec/plistbuddy -c "Delete :UISupportedDevices" "$TARGET_APP_PATH/Info.plist" # 5. To execute permissions on MachO file # to MachO file name APP_BINARY = ` plutil - convert xml1 - o - $TARGET_APP_PATH/Info. The plist | grep - A1 Exec | tail - n1 | the cut - f2 - d \ > | the cut - f1 - d \ < # ` executable permissions chmod + x "$TARGET_APP_PATH / $APP_BINARY" # 6. $frameworks_path ="$frameworks_path/FrameWorks "if [-d "$TARGET_APP_FRAMEWORKS_PATH"]; Then for FRAMEWORK in "$TARGET_APP_FRAMEWORKS_PATH/"* do # sign --force --sign -- fs /usr/bin/codesign --force --sign "$EXPANDED_CODE_SIGN_IDENTITY" "$FRAMEWORK" done fiCopy the code
use
- create
An empty project
(e.g.shellTestWeChat
), compile and run the empty project toA:
(trust
Certificate). - will
appResign.sh
Copy the script toProject Root directory
(beThe executable
Permissions). - in
Project Root directory
createThe APP folder
And willWeChat. Ipa
Copy toThe APP folder
. - The configuration script
- Run the project
Ps: How to debug an arbitrary app?
1. Obtain the corresponding IPA package
Dump ipA packages π using jailbroken mobile phones
Download the old ipA package, you can change the version number by grabbing the download link in iTunes (the suffix is the app version, directly change the version).
iTunes
2. Hit a shell
After breaking the shell, you need to delete the UISupportedDevices supported in info.plist because it dumps the genuine package on the jailbroken phone. Of course you can write it in the script π
/usr/libexec/plistbuddy -c "Delete :UISupportedDevices" "$TARGET_APP_PATH/Info.plist"Copy the code
Save the deletion and repackage ipA π
zip -ry WeChat1.ipa Payload/
Copy the code
conclusion
Application of re-signature can be said to be the first step in reverse preparation, I hope you can follow the order of this article, practical operation again, all say that practice is the only criterion for testing truth, this is very important!
- Codesign heavy signature
delete
Documents that cannot be signed:PlugIns
andWatch
(Includes Extension)- Re-sign the library in Frameworks
- Add MachO
Executable permission
- Modify the
Info.plist
File (BundleID
) - copy
Description file
(This description file must be trusted in iOS real machine) - Use the permission file in the description file
Sign the entire App package
- Xcode heavy signature
delete
Documents that cannot be signed:PlugIns
andWatch
(Includes Extension)- Re-sign the library in Frameworks
- Add MachO
Executable permission
- Modify the
Info.plist
File (BundleID
) - copy
Description file
(This description file must be trusted in iOS real machine) - Copy the App package in
Xcode project directory
Leave the rest to meXcode
)
- A Shell script
- Switch shell
$CHSH -s Shell path
- Shell default is now available in macOS
zsh
(earlybash
) - The configuration file
zsh
π.zshrc
bash
π.bash_profile
- File permissions & user groups
- Each file has its own
Users, groups, and others
- File permissions
attribution
π Users, groups, and otherspermissions
π Write, read, and execute
- Example Change the permission chmod
- The Numbers:
r:4 w:2 x:1
- chmod
751
The file nameuser
π 4 + 2 + 1 = 7group
π 4 + 0 + 1 = 5other
π 0 + 0 + 1 = 1
- character
- Attribution π
u
(user)g
(group)o
(other)a
(all) +
(add)-
(take out)=
(set)- The default
a
πchmod + x
- Attribution π
- The Numbers:
- Each file has its own