Reinforcement method, electronic device and storage medium based on iOS application

By randomly replacing strings in iOS applications and generating meaningless target strings, the problem in the existing technology that iOS applications are susceptible to reverse analysis and logic recovery is solved, and the security of the application is significantly improved.

CN111695093BActive Publication Date: 2024-10-25PING AN TECH (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010479471.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-05-29
Publication Date
2024-10-25
Estimated Expiration
2040-05-29

AI Technical Summary

Technical Problem

Existing iOS application hardening tools fail to effectively obfuscate the strings in the application. As a result, third parties can still guess the logical process through function names and variable names, thereby intercepting the input and output of the function and restoring the application's business logic.

Method used

By receiving the binary file of the iOS application, using preset regular expressions to filter protocol, class and function strings, randomly replacing characters to generate the target string, and writing it into the file to be compiled, a reinforced iOS application is generated to ensure that functions and the readability of the variables becomes meaningless random strings.

Benefits of technology

It greatly reduces the possibility of third parties guessing business logic through methods and variables to crack the application, and improves the security of the application.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111695093B_ABST
    Figure CN111695093B_ABST
Patent Text Reader

Abstract

The present invention relates to data processing technology, and provides a reinforcement method, electronic device and storage medium based on iOS applications. The method obtains a first string set of a binary file in an iOS application based on a preset regular expression set, and obtains a second string set belonging to the iOS system in the binary file, and obtains a third string set based on the first string set and the second string set. Based on the length of each initial string in the third string set and a preset replacement character set, the characters of the initial string are replaced, and the replaced characters are sequentially spliced ​​to generate a target string corresponding to each initial string, and each target string is written into a preset file to be compiled, and the compiled file is compiled to obtain a reinforced application. The present invention also relates to blockchain technology, and the reinforced iOS application can be stored in a blockchain. The present invention can reduce the risk of a third party cracking an application through methods and variables.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing, and in particular to a reinforcement method, electronic device and storage medium based on iOS applications. Background Art

[0002] iOS applications are often exposed to reverse analysis by third parties to spy on their business logic, so it is necessary to use hardening tools to harden iOS applications. Most existing hardening tools only harden the code logic layer of iOS applications, but do not obfuscate the strings in the application, resulting in the methods and variables in iOS applications still being plain text. Third parties can still guess the logic process based on the function name and variable name, and third parties can also use Hook technology to intercept the input and output of the function to restore the business logic of the application. Summary of the invention

[0003] In view of the above, the present invention provides a reinforcement method, electronic device and storage medium based on iOS applications, which aims to solve the technical problem in the prior art that the business logic of iOS applications can be easily restored by a third party.

[0004] To achieve the above object, the present invention provides a reinforcement method based on iOS application, the method comprising:

[0005] Receiving step: receiving a request for hardening an iOS application from a user, and obtaining a binary file of the iOS application to be hardened carried in the request;

[0006] Screening step: obtaining all protocol strings, class strings and function strings in the binary file as a first string set based on a preset regular expression set, obtaining protocol strings, class strings and function strings belonging to the iOS system in the binary file as a second string set, and obtaining a third string set based on the first string set and the second string set;

[0007] Replacing step: traversing the third character string set, respectively reading the length of each initial character string in the third character string set, randomly performing a replacement operation on the characters of each initial character string based on the length of each initial character string and a preset replacement character set, and sequentially splicing the replaced characters to generate a target character string corresponding to each initial character string; and

[0008] Feedback step: writing each of the target character strings into a preset file to be compiled, performing a compiling operation on the file to be compiled to obtain a reinforced iOS application, and feeding back the reinforced iOS application to the user.

[0009] Preferably, the screening step further comprises:

[0010] The custom class string that implements serialization in the binary file, the custom class string that implements the preset protocol, the class string that stores data in a preset manner, and the keywords reserved by the iOS system are added to the second string set.

[0011] Preferably, the replacing step further comprises:

[0012] The generated target character string is stored in a preset storage path, and it is determined whether there is an identical target character string in the preset storage path. When it is determined that there is an identical target character string in the preset storage path, the replacement operation is re-executed on the identical target character string using the replacement character set until there is no identical target character string in the preset storage path.

[0013] Preferably, after the feedback step, the method further comprises:

[0014] The binary file of the hardened iOS application is parsed based on preset parsing rules to obtain first key data. When it is detected that a user performs an installation operation on the hardened iOS application, the second key data of the binary file of the iOS application after the installation operation is extracted using preset extraction rules, and it is determined whether a preset indicator in the second key data is a preset value. When it is determined that the preset indicator in the second key data is a preset value, the first preset detection result is fed back to the user.

[0015] Preferably, the method further comprises:

[0016] When it is determined that the preset indicator in the second key data is not a preset value, it is determined whether the object of the first key data is the same as the object of the second key data. When it is determined that the object of the first key data is the same as the object of the second key data, the second preset detection result is fed back to the user. If not, the first preset detection result is fed back to the user, wherein the object includes constant string data, method data, dynamic library data, signature data and package name data.

[0017] To achieve the above object, the present invention further provides an electronic device, which includes: a memory and a processor, wherein the memory stores a hardening program based on an iOS application, and the hardening program based on an iOS application is executed by the processor to implement the following steps:

[0018] Receiving step: receiving a request for hardening an iOS application from a user, and obtaining a binary file of the iOS application to be hardened carried in the request;

[0019] Screening step: obtaining all protocol strings, class strings and function strings in the binary file as a first string set based on a preset regular expression set, obtaining protocol strings, class strings and function strings belonging to the iOS system in the binary file as a second string set, and obtaining a third string set based on the first string set and the second string set;

[0020] Replacing step: traversing the third character string set, respectively reading the length of each initial character string in the third character string set, randomly performing a replacement operation on the characters of each initial character string based on the length of each initial character string and a preset replacement character set, and sequentially splicing the replaced characters to generate a target character string corresponding to each initial character string; and

[0021] Feedback step: writing each of the target character strings into a preset file to be compiled, performing a compiling operation on the file to be compiled to obtain a reinforced iOS application, and feeding back the reinforced iOS application to the user.

[0022] Preferably, the replacing step further comprises:

[0023] The generated target character string is stored in a preset storage path, and it is determined whether there is an identical target character string in the preset storage path. When it is determined that there is an identical target character string in the preset storage path, the replacement operation is re-executed on the identical target character string using the replacement character set until there is no identical target character string in the preset storage path.

[0024] Preferably, after the feedback step, the iOS application-based reinforcement program is executed by the processor, and the following steps are further implemented:

[0025] The binary file of the hardened iOS application is parsed based on preset parsing rules to obtain first key data. When it is detected that a user performs an installation operation on the hardened iOS application, the second key data of the binary file of the iOS application after the installation operation is extracted using preset extraction rules, and it is determined whether a preset indicator in the second key data is a preset value. When it is determined that the preset indicator in the second key data is a preset value, the first preset detection result is fed back to the user.

[0026] Preferably, the iOS application-based reinforcement program is executed by the processor, and further implements the following steps:

[0027] When it is determined that the preset indicator in the second key data is not a preset value, it is determined whether the object of the first key data is the same as the object of the second key data. When it is determined that the object of the first key data is the same as the object of the second key data, the second preset detection result is fed back to the user. If not, the first preset detection result is fed back to the user, wherein the object includes constant string data, method data, dynamic library data, signature data and package name data.

[0028] To achieve the above objectives, the present invention also provides a computer-readable storage medium, which includes a reinforcement program based on iOS applications. When the reinforcement program based on iOS applications is executed by a processor, any step in the reinforcement method based on iOS applications as described above is implemented.

[0029] The iOS application-based reinforcement method, electronic device, and storage medium proposed in the present invention obfuscate readable functions and variables in iOS applications, turning readable functions and variables into random strings without any meaning, thereby completing symbol obfuscation and achieving the purpose of reinforcing the security of applications, greatly reducing the possibility of third parties cracking applications by guessing business logic through methods (functions) and variables. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] Figure 1 A schematic diagram of a preferred embodiment of the electronic device of the present invention;

[0031] Figure 2 for Figure 1 A schematic diagram of a module of a preferred embodiment of a reinforcement program based on iOS application;

[0032] Figure 3 It is a flow chart of a preferred embodiment of the reinforcement method based on iOS application of the present invention;

[0033] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0034] In order to make the purpose, technical scheme and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0035] Reference Figure 1 FIG. 1 is a schematic diagram of a preferred embodiment of the electronic device 1 of the present invention.

[0036] The electronic device 1 includes but is not limited to: a memory 11, a processor 12, a display 13 and a network interface 14. The electronic device 1 is connected to a network through the network interface 14 to obtain raw data. The network may be a wireless or wired network such as an intranet, the Internet, a global system of mobile communications (GSM), a wideband code division multiple access (WCDMA), a 4G network, a 5G network, Bluetooth, Wi-Fi, a call network, etc.

[0037] Among them, the memory 11 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 11 can be an internal storage unit of the electronic device 1, such as a hard disk or memory of the electronic device 1. In other embodiments, the memory 11 can also be an external storage device of the electronic device 1, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped with the electronic device 1. Of course, the memory 11 can also include both the internal storage unit of the electronic device 1 and its external storage device. In this embodiment, the memory 11 is generally used to store the operating system and various application software installed on the electronic device 1, such as the program code of the hardening program 10 based on iOS application. In addition, the memory 11 can also be used to temporarily store various types of data that have been output or are to be output.

[0038] In some embodiments, the processor 12 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip. The processor 12 is generally used to control the overall operation of the electronic device 1, such as performing control and processing related to data interaction or communication. In this embodiment, the processor 12 is used to run the program code stored in the memory 11 or process data, such as running the program code of the hardening program 10 based on the iOS application.

[0039] The display 13 may be referred to as a display screen or a display unit. In some embodiments, the display 13 may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an organic light-emitting diode (OLED) touch device. The display 13 is used to display information processed in the electronic device 1 and to display a visual working interface, such as displaying the results of data statistics.

[0040] The network interface 14 may optionally include a standard wired interface or a wireless interface (such as a WI-FI interface). The network interface 14 is generally used to establish a communication connection between the electronic device 1 and other electronic devices.

[0041] Figure 1 Only the electronic device 1 having components 11 - 14 and the iOS application-based hardening program 10 is shown, but it should be understood that it is not required to implement all of the components shown, and more or fewer components may be implemented instead.

[0042] Optionally, the electronic device 1 may further include a user interface, which may include a display, an input unit such as a keyboard, and an optional user interface may further include a standard wired interface and a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an organic light-emitting diode (OLED) touch device. The display may also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the electronic device 1 and to display a visual user interface.

[0043] The electronic device 1 may further include a radio frequency (RF) circuit, a sensor, an audio circuit, etc., which will not be described in detail here.

[0044] In the above embodiment, the processor 12 may implement the following steps when executing the iOS application-based reinforcement program 10 stored in the memory 11:

[0045] Receiving step: receiving a request for hardening an iOS application from a user, and obtaining a binary file of the iOS application to be hardened carried in the request;

[0046] Screening step: obtaining all protocol strings, class strings and function strings in the binary file as a first string set based on a preset regular expression set, obtaining protocol strings, class strings and function strings belonging to the iOS system in the binary file as a second string set, and obtaining a third string set based on the first string set and the second string set;

[0047] Replacing step: traversing the third character string set, respectively reading the length of each initial character string in the third character string set, randomly performing a replacement operation on the characters of each initial character string based on the length of each initial character string and a preset replacement character set, and sequentially splicing the replaced characters to generate a target character string corresponding to each initial character string; and

[0048] Feedback step: writing each of the target character strings into a preset file to be compiled, performing a compiling operation on the file to be compiled to obtain a reinforced iOS application, and feeding back the reinforced iOS application to the user.

[0049] The storage device may be the memory 11 of the electronic device 1 , or may be other storage devices that are communicatively connected to the electronic device 1 .

[0050] For a detailed description of the above steps, please refer to the following Figure 2 Program module diagram of the embodiment of the reinforcement program 10 based on iOS application and Figure 3 Description of a flowchart of an embodiment of a reinforcement method based on iOS applications.

[0051] In other embodiments, the iOS application-based hardening program 10 may be divided into multiple modules, which are stored in the memory 11 and executed by the processor 12 to implement the present invention. The module referred to in the present invention refers to a series of computer program instruction segments that can perform specific functions.

[0052] Reference Figure 2 As shown, Figure 1 FIG. 1 is a program module diagram of an embodiment of a reinforcement program 10 based on iOS application. In this embodiment, the reinforcement program 10 based on iOS application can be divided into: a receiving module 110, a screening module 120, a replacement module 130 and a feedback module 140.

[0053] The receiving module 110 is used to receive a request for hardening an iOS application from a user, and obtain a binary file of the iOS application to be hardened carried in the request.

[0054] In this embodiment, a request for reinforcing an iOS application from a user is received. The request carries a binary file of the iOS application to be reinforced. The binary file in this solution refers to a Mach-O file. The request may include the iOS application to be reinforced, and may also include the storage path of the iOS application to be reinforced and the unique identifier of the iOS application. In other words, the iOS application may be entered by the user when submitting the reinforcement request, or may be obtained from the address specified in the request after the user submits the reinforcement request.

[0055] Mach-O is the abbreviation of Mach Object file format. It is a file format used to record executable files, object codes, shared libraries, dynamically loaded codes, and memory dumps. It is the standard format for programs and libraries on macOS / iOS.

[0056] The screening module 120 is used to obtain all protocol strings, class strings and function strings in the binary file as a first string set based on a preset regular expression set, and obtain the protocol strings, class strings and function strings belonging to the iOS system in the binary file as a second string set, and obtain a third string set based on the first string set and the second string set.

[0057] In this embodiment, the definition of user-defined and iOS system classes, protocols, and functions in the Mach-O file can be written into different files according to different class and protocol names through the command "class-dump-H Mach-O path", which will generate multiple class files, protocol files, and function files. It should be noted that part of the functions implemented by the iOS application are implemented through system strings and part are implemented through user-defined strings, so the strings contained in the extracted class, protocol, and function files are composed of two parts: system strings and user-defined strings. Since operation abnormalities will occur if the system strings are obfuscated and reinforced, it is necessary to filter out user-defined strings for reinforcement.

[0058] All protocol strings, class strings and function strings in the Mach-O file are obtained by using a preset regular expression set as a first string set, and a deduplication operation can also be performed on the protocol strings, class strings and function strings in the first string set. The function strings include function strings with parameters and function strings without parameters.

[0059] The preset regular expression sets include:

[0060] Expression to get the protocol string:

[0061] "s / .*@protocol[\\t]*\\([a-zA-Z_][a-zA-Z0-9_]*\\).* / \\1 / p"

[0062] Get string-like expressions:

[0063] "s / .*@interface[\\t]*\\([a-zA-Z_][a-zA-Z0-9_]*\\).* / \\1 / p"

[0064] Get an expression for a function string containing arguments:

[0065] "[\\+|-]\\s*\\(\\s*([a-zA-Z<>\\s\\*_,]+\\s*\\*?)\\s*\\)\\s*([a-zA-Z_0-9]+)\\s*;"

[0066] Get the expression of the function string without parameters:

[0067] "\\s*([a-zA-Z_0-9]+):(\\s*\\(\\s*[a-zA-Z<>\\s\\*_,]+\\s*\\*?\\s*\\))\\s*([a-zA-Z_0-9]+)"

[0068] The command "class-dump -H system library path" can be used to write the definitions of the classes, protocols, and functions of the iOS system in the Mach-O file into different files according to different class and protocol names, and the protocol string, class string, and function string belonging to the iOS system in the Mach-O file can be obtained as the second string set through the above regular expression set.

[0069] Furthermore, custom class strings for implementing serialization in binary files, custom class strings for implementing preset protocols, class strings for storing data in a preset manner, and keywords reserved by the iOS system may be added to the second string set. The custom class string for implementing the preset protocol may be a custom string for implementing the NSCoder protocol, and the class string for storing data in a preset manner may be a class string for storing data using a CoreData Model.

[0070] The replacement module 130 is used to traverse the third character string set, read the length of each initial character string in the third character string set respectively, randomly perform a replacement operation on the characters of each initial character string based on the length of each initial character string and a preset replacement character set, and sequentially concatenate the replaced characters to generate a target character string corresponding to each initial character string.

[0071] In this embodiment, the third string set is traversed, the length of each initial string in the third string set is read out, and based on the length of the initial character and the preset replacement character set, a character in the preset replacement character set is randomly obtained to replace each character of the initial string, and the replaced characters are spliced ​​in sequence to obtain a target string corresponding to the initial string, wherein the preset replacement character set may include 52 characters in total, including letters az and AZ. For example, the length of the initial string A to be obfuscated and reinforced is 5, and characters need to be randomly obtained 5 times from the preset replacement character set, and the characters obtained from the replacement character set are used to replace the characters of the initial string A. The new string re-spliced ​​after replacement is used as the target string B after obfuscation and reinforcement. The length of the initial string A to the obfuscated and reinforced string B remains unchanged, and the string is replaced. The iOS system is compatible with the standard C language, and a symbol can be defined as a new symbol through macro definition in the C language. In this embodiment, the initial string can be defined as the target string by using macro definition. For example, when the #define AB definition is imported into the file to be compiled, the compiler will dynamically replace A with B during compilation, and the A string cannot be found in the executable file Mach-O compiled at the end, only the B string.

[0072] Furthermore, since the same target character string may appear after the characters of the initial character string are replaced by a preset replacement character set, the generated target character string can also be stored in a preset storage path, and it is determined whether the same target character string exists in the preset storage path. When it is determined that the same target character string exists in the preset storage path, the replacement operation is re-executed on the same target character string using the replacement character set until the same target character string no longer exists in the preset storage path.

[0073] The feedback module 140 is used to write each of the target strings into a preset file to be compiled, perform a compilation operation on the file to be compiled to obtain a reinforced iOS application, and feed back the reinforced iOS application to the user.

[0074] In this embodiment, the target character string is written into a preset file to be compiled (for example, a FILEC file), the file to be compiled is compiled to obtain a reinforced iOS application, and the reinforced iOS application is fed back to the user.

[0075] In one embodiment, it is also possible to detect whether the hardened iOS application has been cracked. The binary file of the hardened iOS application is parsed based on the preset parsing rules to obtain the first key data. When it is detected that the user performs an installation operation on the hardened iOS application, the second key data of the binary file of the iOS application after the installation operation is extracted using the preset extraction rules, and it is determined whether the preset indicator in the second key data is a preset value. When it is determined that the preset indicator in the second key data is a preset value, the first preset detection result is fed back to the user.

[0076] By parsing the Mach-O header, load command and raw segment data of the Mach-O file respectively, the first key data can be obtained. The first key data includes constant string data, method data, dynamic library data, signature data and package name data. Specifically, the Mach-O header parsing of the Mach-O file includes:

[0077] The first part of the Header is composed of a mach_header_64 structure, which is 32 bytes in size and consists of 8 fields, each field is 4 bytes. As long as you read the 32-byte data of the Mach-O file, you can get the mach_header_64 structure data. There are two fields in this structure: ncmds and sizeofcmds, which respectively indicate how many load commands there are and the total size occupied by the load commands.

[0078] Parsing of the load command includes:

[0079] The second part is composed of the Load Command structure, which is 16 bytes in size and consists of two fields: cmdsize and cmd. The cmd field in the structure describes the Command type. Using the ncmds obtained from the above analysis, by looping ncmds times, each time reading data of 16+cmdssize bytes, the load command can be parsed.

[0080] When traversing the load command, if the value of cmd is 0xc, then this Command is the dynamic library information. According to the document, the 24-byte size data is read as the dylib_command structure, and the name field in the structure is the dynamic library name.

[0081] When traversing the load command, if the value of cmd is 0x19, the Segment information is stored in this Command. According to the document, the 72-bit byte size data is read as the segment_command_64 structure, where the field segname represents the Segment name, the field fileoff represents its offset, and the field filesize represents the size of the string constant in the Mach-O file. When segname is __cstring, it represents the Segment segment of the string constant. You can assign fileoff and fizesize to AAA and AAAC respectively, move the file pointer to the AAA position, and read the AAAC byte size data, which is the application constant string information.

[0082] When traversing the load command, if the value of cmd is 0x19, the Segment information is stored in this Command. According to the document, the 72-bit byte size data is read as the segment_command_64 structure, where the field segname represents the Segment name, the field fileoff represents its offset, and the field filesize represents the size of the string constant in the Mach-O file. When segname is __objc_methodname, it represents the Segment segment of the method (function). The fileoff and fizesize can be assigned to BBB and BBBC respectively, the file pointer is moved to the BBB position, and the data of the BBBC byte size is read, which is the application method (function) information.

[0083] When traversing the load command, if the value of cmd is 0x1d, the signature information is stored in this command. According to the document, the 16-bit byte size data is read as the linkedit_data_command structure, where the field dataoff represents its offset and the field datasize represents the size of the string constant in the Mach-O file. The dataoff and datasize at this time can be assigned to CCC and CCCD respectively, the file pointer is moved to the CCC position, and the CCCD byte size data is read, which contains the application signature and package name information.

[0084] When it is detected that the user has performed an installation operation on the hardened iOS application, the second key data of the binary file of the iOS application after the installation operation is extracted using the preset extraction rules, wherein the second key data includes: constant string data, method data, dynamic library data, signature data and package name data, etc. It is determined whether the preset indicator (cryptid value) in the second key data is a preset value (the value is 0). If the cryptid value is 0, it means that the iOS application has been cracked, and the first preset detection result is fed back to the user, and the first preset detection result may be "this application has been cracked".

[0085] Furthermore, when it is determined that the preset indicator in the second key data is not a preset value, it is determined whether the object of the first key data is the same as the object of the second key data. When it is determined that the object of the first key data is the same as the object of the second key data, the second preset detection result is fed back to the user. If not, the first preset detection result is fed back to the user, wherein the object includes constant string data, method data, dynamic library data, signature data and package name data.

[0086] When the preset indicator (cryptid value) in the second key data is not the preset value, the first key data is compared with the second key data. When the constant string data, method data, dynamic library data, signature data and package name data in the first key data are respectively the same as the constant string data, method (function) data, dynamic library data, signature data and package name data in the second key data, it means that the iOS application has not been cracked, and the second preset detection result is fed back to the user, for example: "This application has not been cracked". When any data in the first key data is different from that in the second key data, it means that the iOS application has been cracked, and the first preset detection result is fed back to the user.

[0087] In addition, the present invention also provides a reinforcement method based on iOS applications. Figure 3 , which is a schematic diagram of a method flow of an embodiment of the iOS application-based reinforcement method of the present invention. When the processor 12 of the electronic device 1 executes the iOS application-based reinforcement program 10 stored in the memory 11, the following steps of the iOS application-based reinforcement method are implemented:

[0088] Step S10: receiving a request for reinforcing an iOS application from a user, and obtaining a binary file of the iOS application to be reinforced carried in the request.

[0089] In this embodiment, a request for reinforcing an iOS application from a user is received. The request carries a binary file of the iOS application to be reinforced. The binary file in this solution refers to a Mach-O file. The request may include the iOS application to be reinforced, and may also include the storage path of the iOS application to be reinforced and the unique identifier of the iOS application. In other words, the iOS application may be entered by the user when submitting the reinforcement request, or may be obtained from the address specified in the request after the user submits the reinforcement request.

[0090] Mach-O is the abbreviation of Mach Object file format. It is a file format used to record executable files, object codes, shared libraries, dynamically loaded codes, and memory dumps. It is the standard format for programs and libraries on macOS / iOS.

[0091] Step S20: based on a preset regular expression set, all protocol strings, class strings and function strings in the binary file are obtained as a first string set, and protocol strings, class strings and function strings belonging to the iOS system in the binary file are obtained as a second string set, and a third string set is obtained based on the first string set and the second string set.

[0092] In this embodiment, the definition of user-defined and iOS system classes, protocols, and functions in the Mach-O file can be written into different files according to different class and protocol names through the command "class-dump-H Mach-O path", which will generate multiple class files, protocol files, and function files. It should be noted that part of the functions implemented by the iOS application are implemented through system strings and part are implemented through user-defined strings, so the strings contained in the extracted class, protocol, and function files are composed of two parts: system strings and user-defined strings. Since operation abnormalities will occur if the system strings are obfuscated and reinforced, it is necessary to filter out user-defined strings for reinforcement.

[0093] All protocol strings, class strings and function strings in the Mach-O file are obtained by using a preset regular expression set as a first string set, and a deduplication operation can also be performed on the protocol strings, class strings and function strings in the first string set. The function strings include function strings with parameters and function strings without parameters.

[0094] The preset regular expression sets include:

[0095] Expression to get the protocol string:

[0096] "s / .*@protocol[\\t]*\\([a-zA-Z_][a-zA-Z0-9_]*\\).* / \\1 / p"

[0097] Get string-like expressions:

[0098] "s / .*@interface[\\t]*\\([a-zA-Z_][a-zA-Z0-9_]*\\).* / \\1 / p"

[0099] Get an expression for a function string containing arguments:

[0100] "[\\+|-]\\s*\\(\\s*([a-zA-Z<>\\s\\*_,]+\\s*\\*?)\\s*\\)\\s*([a-zA-Z_0-9]+)\\s*;"

[0101] Get the expression of the function string without parameters:

[0102] "\\s*([a-zA-Z_0-9]+):(\\s*\\(\\s*[a-zA-Z<>\\s\\*_,]+\\s*\\*?\\s*\\))\\s*([a-zA-Z_0-9]+)"

[0103] The command "class-dump -H system library path" can be used to write the definitions of the classes, protocols, and functions of the iOS system in the Mach-O file into different files according to different class and protocol names, and the protocol string, class string, and function string belonging to the iOS system in the Mach-O file can be obtained as the second string set through the above regular expression set.

[0104] Furthermore, custom class strings for implementing serialization in binary files, custom class strings for implementing preset protocols, class strings for storing data in a preset manner, and keywords reserved by the iOS system may be added to the second string set. The custom class string for implementing the preset protocol may be a custom string for implementing the NSCoder protocol, and the class string for storing data in a preset manner may be a class string for storing data using a CoreData Model.

[0105] Step S30: traversing the third character string set, respectively reading the length of each initial character string in the third character string set, randomly performing a replacement operation on the characters of each initial character string based on the length of each initial character string and a preset replacement character set, and sequentially concatenating the replaced characters to generate a target character string corresponding to each initial character string.

[0106] In this embodiment, the third string set is traversed, the length of each initial string in the third string set is read out, and based on the length of the initial character and the preset replacement character set, a character in the preset replacement character set is randomly obtained to replace each character of the initial string, and the replaced characters are spliced ​​in sequence to obtain a target string corresponding to the initial string, wherein the preset replacement character set may include 52 characters in total, including letters az and AZ. For example, the length of the initial string A to be obfuscated and reinforced is 5, and characters need to be randomly obtained 5 times from the preset replacement character set, and the characters obtained from the replacement character set are used to replace the characters of the initial string A. The new string re-spliced ​​after replacement is used as the target string B after obfuscation and reinforcement. The length of the initial string A to the obfuscated and reinforced string B remains unchanged, and the string is replaced. The iOS system is compatible with the standard C language, and a symbol can be defined as a new symbol through macro definition in the C language. In this embodiment, the initial string can be defined as the target string by using macro definition. For example, when the #define AB definition is imported into the file to be compiled, the compiler will dynamically replace A with B during compilation, and the A string cannot be found in the executable file Mach-O compiled at the end, only the B string.

[0107] Furthermore, since the same target character string may appear after the characters of the initial character string are replaced by a preset replacement character set, the generated target character string can also be stored in a preset storage path, and it is determined whether the same target character string exists in the preset storage path. When it is determined that the same target character string exists in the preset storage path, the replacement operation is re-executed on the same target character string using the replacement character set until the same target character string no longer exists in the preset storage path.

[0108] Step S40: writing each of the target character strings into a preset file to be compiled, performing a compiling operation on the file to be compiled to obtain a reinforced iOS application, and feeding back the reinforced iOS application to the user.

[0109] In this embodiment, the target character string is written into a preset file to be compiled (for example, a FILEC file), the file to be compiled is compiled to obtain a reinforced iOS application, and the reinforced iOS application is fed back to the user.

[0110] In one embodiment, it is also possible to detect whether the hardened iOS application has been cracked. The binary file of the hardened iOS application is parsed based on the preset parsing rules to obtain the first key data. When it is detected that the user performs an installation operation on the hardened iOS application, the second key data of the binary file of the iOS application after the installation operation is extracted using the preset extraction rules, and it is determined whether the preset indicator in the second key data is a preset value. When it is determined that the preset indicator in the second key data is a preset value, the first preset detection result is fed back to the user.

[0111] By parsing the Mach-O header, load command and raw segment data of the Mach-O file respectively, the first key data can be obtained. The first key data includes constant string data, method data, dynamic library data, signature data and package name data. Specifically, the Mach-O header parsing of the Mach-O file includes:

[0112] The first part of the Header is composed of a mach_header_64 structure, which is 32 bytes in size and consists of 8 fields, each field is 4 bytes. As long as you read the 32-byte data of the Mach-O file, you can get the mach_header_64 structure data. There are two fields in this structure: ncmds and sizeofcmds, which respectively indicate how many load commands there are and the total size occupied by the load commands.

[0113] Parsing of the load command includes:

[0114] The second part is composed of the Load Command structure, which is 16 bytes in size and consists of two fields: cmdsize and cmd. The cmd field in the structure describes the Command type. Using the ncmds obtained from the above analysis, by looping ncmds times, each time reading data of 16+cmdssize bytes, the load command can be parsed.

[0115] When traversing the load command, if the value of cmd is 0xc, then this Command is the dynamic library information. According to the document, the 24-byte size data is read as the dylib_command structure, and the name field in the structure is the dynamic library name.

[0116] When traversing the load command, if the value of cmd is 0x19, the Segment information is stored in this Command. According to the document, the 72-bit byte size data is read as the segment_command_64 structure, where the field segname represents the Segment name, the field fileoff represents its offset, and the field filesize represents the size of the string constant in the Mach-O file. When segname is __cstring, it represents the Segment segment of the string constant. You can assign fileoff and fizesize to AAA and AAAC respectively, move the file pointer to the AAA position, and read the AAAC byte size data, which is the application constant string information.

[0117] When traversing the load command, if the value of cmd is 0x19, the Segment information is stored in this Command. According to the document, the 72-bit byte size data is read as the segment_command_64 structure, where the field segname represents the Segment name, the field fileoff represents its offset, and the field filesize represents the size of the string constant in the Mach-O file. When segname is __objc_methodname, it represents the Segment segment of the method (function). The fileoff and fizesize can be assigned to BBB and BBBC respectively, the file pointer is moved to the BBB position, and the data of the BBBC byte size is read, which is the application method (function) information.

[0118] When traversing the load command, if the value of cmd is 0x1d, the signature information is stored in this command. According to the document, the 16-bit byte size data is read as the linkedit_data_command structure, where the field dataoff represents its offset and the field datasize represents the size of the string constant in the Mach-O file. The dataoff and datasize at this time can be assigned to CCC and CCCD respectively, the file pointer is moved to the CCC position, and the CCCD byte size data is read, which contains the application signature and package name information.

[0119] When it is detected that the user has performed an installation operation on the hardened iOS application, the second key data of the binary file of the iOS application after the installation operation is extracted using the preset extraction rules, wherein the second key data includes: constant string data, method data, dynamic library data, signature data and package name data, etc. It is determined whether the preset indicator (cryptid value) in the second key data is a preset value (the value is 0). If the cryptid value is 0, it means that the iOS application has been cracked, and the first preset detection result is fed back to the user, and the first preset detection result may be "this application has been cracked".

[0120] Furthermore, when it is determined that the preset indicator in the second key data is not a preset value, it is determined whether the object of the first key data is the same as the object of the second key data. When it is determined that the object of the first key data is the same as the object of the second key data, the second preset detection result is fed back to the user. If not, the first preset detection result is fed back to the user, wherein the object includes constant string data, method data, dynamic library data, signature data and package name data.

[0121] When the preset indicator (cryptid value) in the second key data is not the preset value, the first key data is compared with the second key data. When the constant string data, method data, dynamic library data, signature data and package name data in the first key data are respectively the same as the constant string data, method (function) data, dynamic library data, signature data and package name data in the second key data, it means that the iOS application has not been cracked, and the second preset detection result is fed back to the user, for example: "This application has not been cracked". When any data in the first key data is different from that in the second key data, it means that the iOS application has been cracked, and the first preset detection result is fed back to the user.

[0122] In addition, the embodiment of the present invention further proposes a computer-readable storage medium, which may be any one or any combination of a hard disk, a multimedia card, an SD card, a flash memory card, an SMC, a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a portable compact disk read-only memory (CD-ROM), a USB memory, etc. The computer-readable storage medium includes a hardening program 10 based on an iOS application, and the hardening program 10 based on an iOS application implements the following operations when executed by a processor:

[0123] Receiving step: receiving a request for hardening an iOS application from a user, and obtaining a binary file of the iOS application to be hardened carried in the request;

[0124] Screening step: obtaining all protocol strings, class strings and function strings in the binary file as a first string set based on a preset regular expression set, obtaining protocol strings, class strings and function strings belonging to the iOS system in the binary file as a second string set, and obtaining a third string set based on the first string set and the second string set;

[0125] Replacing step: traversing the third character string set, respectively reading the length of each initial character string in the third character string set, randomly performing a replacement operation on the characters of each initial character string based on the length of each initial character string and a preset replacement character set, and sequentially splicing the replaced characters to generate a target character string corresponding to each initial character string; and

[0126] Feedback step: writing each of the target character strings into a preset file to be compiled, performing a compiling operation on the file to be compiled to obtain a reinforced iOS application, and feeding back the reinforced iOS application to the user.

[0127] In another embodiment, the iOS application-based reinforcement method provided by the present invention can further ensure the privacy and security of all the above data, and all the above data can also be stored in a blockchain node. For example, the iOS application to be reinforced, the preset replacement character set or the target character set, etc., all of these data can be stored in the blockchain node.

[0128] It should be noted that the blockchain referred to in the present invention is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the blockchain underlying platform, platform product service layer, and application service layer.

[0129] The specific implementation of the computer-readable storage medium of the present invention is roughly the same as the specific implementation of the above-mentioned iOS application-based reinforcement method, which will not be repeated here.

[0130] It should be noted that the serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages and disadvantages of the embodiments. And the terms "including", "comprising" or any other variants thereof in this article are intended to cover non-exclusive inclusion, so that a process, device, article or method including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, device, article or method. In the absence of further restrictions, an element defined by the sentence "including a ..." does not exclude the presence of other identical elements in the process, device, article or method including the element.

[0131] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, including a number of instructions for enabling a terminal device (which can be a mobile phone, a computer, an electronic device, or a network device, etc.) to execute the methods described in each embodiment of the present invention.

[0132] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A reinforcement method based on iOS application, applied to electronic devices, characterized in that: The method comprises: Receiving step: receiving a request for hardening an iOS application from a user, and obtaining a binary file of the iOS application to be hardened carried in the request; Screening step: obtaining all protocol strings, class strings and function strings in the binary file as a first string set based on a preset regular expression set, obtaining protocol strings, class strings and function strings belonging to the iOS system in the binary file as a second string set, and obtaining a third string set based on the first string set and the second string set; Replacing step: traversing the third character string set, respectively reading the length of each initial character string in the third character string set, randomly performing a replacement operation on the characters of each initial character string based on the length of each initial character string and a preset replacement character set, and sequentially splicing the replaced characters to generate a target character string corresponding to each initial character string; and Feedback step: writing each of the target character strings into a preset file to be compiled, performing a compiling operation on the file to be compiled to obtain a reinforced iOS application, and feeding back the reinforced iOS application to the user; Parsing the binary file of the hardened iOS application based on a preset parsing rule to obtain first key data, and when detecting that the user performs an installation operation on the hardened iOS application, extracting second key data of the binary file of the iOS application after the installation operation is performed based on the preset parsing rule using a preset extraction rule, determining whether a preset indicator in the second key data is a preset value, and when the preset indicator in the second key data is a preset value, feeding back the first preset detection result to the user; When the preset indicator in the second key data is not a preset value, determine whether the object of the first key data is the same as the object of the second key data, and when the object of the first key data is the same as the object of the second key data, feed back the second preset detection result to the user, if not, feed back the first preset detection result to the user, wherein the object includes constant string data, method data, dynamic library data, signature data and package name data; Among them, the first key data is obtained by parsing the Mach-O header, load command and original segment data of the Mach-O file respectively. The first key data includes constant string data, method data, dynamic library data, signature data and package name data. The Mach-O header is composed of the mach_header_64 structure, and the load command is composed of the Load Command structure.

2. The iOS application-based reinforcement method according to claim 1, characterized in that: The screening step further comprises: The custom class string that implements serialization in the binary file, the custom class string that implements the preset protocol, the class string that stores data in a preset manner, and the keywords reserved by the iOS system are added to the second string set.

3. The iOS application-based reinforcement method according to claim 1 or 2, characterized in that: The replacing step further comprises: The generated target character string is stored in a preset storage path, and it is determined whether there is an identical target character string in the preset storage path. When it is determined that there is an identical target character string in the preset storage path, the replacement operation is re-executed on the identical target character string using the replacement character set until there is no identical target character string in the preset storage path.

4. An electronic device, used to implement the iOS application-based reinforcement method as described in any one of claims 1 to 3, the electronic device comprising a memory and a processor, characterized in that: The memory stores a hardening program based on an iOS application, and the hardening program based on an iOS application is executed by the processor to implement the following steps: Receiving step: receiving a request for hardening an iOS application from a user, and obtaining a binary file of the iOS application to be hardened carried in the request; Screening step: obtaining all protocol strings, class strings and function strings in the binary file as a first string set based on a preset regular expression set, obtaining protocol strings, class strings and function strings belonging to the iOS system in the binary file as a second string set, and obtaining a third string set based on the first string set and the second string set; Replacement step: traversing the third character string set, respectively reading the length of each initial character string in the third character string set, randomly performing a replacement operation on the characters of each initial character string based on the length of each initial character string and a preset replacement character set, and sequentially splicing the replaced characters to generate a target character string corresponding to each initial character string; and Feedback step: writing each of the target character strings into a preset file to be compiled, performing a compiling operation on the file to be compiled to obtain a reinforced iOS application, and feeding back the reinforced iOS application to the user.

5. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a reinforcement program based on an iOS application. When the reinforcement program based on an iOS application is executed by a processor, the reinforcement method based on an iOS application as described in any one of claims 1 to 3 is implemented.