Application code obfuscation method and device, equipment and storage medium

By parsing and reorganizing the current compiler commands and inserting code obfuscation logic during normal compilation, the problem that traditional methods need to replace the entire Xcode compiler toolchain is solved, efficient code obfuscation is achieved and the difficulty of upgrading and maintenance is reduced.

CN119416181APending Publication Date: 2025-02-11CHINA MERCHANTS BANK
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411402877.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-09
Publication Date
2025-02-11

AI Technical Summary

Technical Problem

The traditional way of obfuscating client applications based on custom Xcode toolchains requires replacing the Xcode default entire compiler toolchains, which are complex in the technical route, which is not conducive to subsequent upgrades and maintenance.

Method used

By obtaining the current compile command and analyzing it, splitting and reorganizing the compile commands based on the parsing results and combining preset obfuscation requirements, generating recombination compile commands, including a preset number of subcompilation commands. Based on these subcompilation commands, the source code is compiled through the Xcode compiler to obtain the executable file.

Benefits of technology

It implements code obfuscation of client applications without replacing the Xcode default compiler toolchain, reducing later upgrade and maintenance work and improving the reliability of code obfuscation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119416181A_ABST
    Figure CN119416181A_ABST
Patent Text Reader

Abstract

The invention discloses a code obfuscation method, device and equipment of an application program and a storage medium, and relates to the technical field of code obfuscation, the method comprises the following steps: obtaining a current compilation command, and analyzing the current compilation command; the current compilation command is split and recombined according to the analysis result in combination with a preset confusion requirement, a recombined compilation command is obtained, and the recombined compilation command comprises a preset number of sub-compilation commands; and based on each compilation sub-command, compiling the source code through an Xcode compiler to obtain an executable file. According to the method, the current compilation command is analyzed and recombined, and the code obfuscation logic is inserted into the normal compilation command, so that compared with the existing mode of directly replacing the whole set of tool chain of the Xcode compiler, the code compilation is still completed based on the original Xcode compiler, and the later upgrade maintenance work is greatly reduced under the condition of realizing the same code obfuscation effect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of code obfuscation technology, and in particular to a method, apparatus, device and storage medium for code obfuscation of an application. Background Art

[0002] Client applications based on the VisionOS system are similar to mature client applications based on the IOS or Android systems. If they are not hardened, they are vulnerable to attacks. That is, attackers can use black and gray tools to disassemble, decompile or dynamically debug client applications that have not been hardened and protected. Client applications are at risk of being cracked and analyzed, which may lead to the leakage of privacy data of application customers.

[0003] Usually, client applications can be reinforced by code obfuscation. At present, the way to obfuscate the source code of client applications based on the VisionOS system is to obfuscate the intermediate code LLVM IR through a custom Xcode tool chain. However, this method requires replacing the entire default compiler tool chain of the Xcode tool. The technical route is relatively complex and is not conducive to subsequent upgrades and maintenance. Summary of the invention

[0004] The main purpose of this application is to provide a method, apparatus, device and storage medium for code obfuscation of an application program, aiming to solve the technical problem that the traditional method of code obfuscating client applications based on a custom Xcode tool chain requires replacing the entire set of Xcode default compilers, which has a complex technical route and is not conducive to subsequent upgrades and maintenance.

[0005] To achieve the above-mentioned purpose, the present application proposes a code obfuscation method, apparatus, device and storage medium for an application program, wherein the code obfuscation method for the application program comprises:

[0006] Obtaining a current compile command and parsing the current compile command;

[0007] Splitting and reorganizing the current compile command according to the parsing result and the preset obfuscation requirement to obtain a reorganized compile command, wherein the reorganized compile command includes a preset number of sub-compile commands;

[0008] Based on each of the sub-compile commands, the source code is compiled by the Xcode compiler to obtain an executable file.

[0009] In one embodiment, the step of splitting and reorganizing the current compile command according to the parsing result and the preset obfuscation requirement to obtain the reorganized compile command includes:

[0010] Splitting the current compilation command according to the parsing result to obtain a plurality of independent compilation units;

[0011] The independent compilation units are reorganized according to preset obfuscation requirements to obtain a preset number of sub-compilation commands, and the sub-compilation commands are integrated into a reorganized compilation command.

[0012] In one embodiment, the sub-compile commands include: a binary representation conversion command, an optimization obfuscation command, and an executable file compilation command;

[0013] The step of compiling the source code by using the Xcode compiler based on each of the sub-compile commands to obtain an executable file includes:

[0014] Based on the binary representation conversion command, convert the source code corresponding file into a binary file through a compiler;

[0015] Based on the optimization and obfuscation command, the binary file is optimized and obfuscated by a preset opt ​​optimizer to obtain an optimized binary file;

[0016] Based on the executable file compilation command, the optimized binary file is compiled by the compiler to obtain an executable file.

[0017] In one embodiment, the preset opt ​​optimizer is the LLVM opt optimizer;

[0018] Before the step of performing optimization and obfuscation processing on the binary file based on the optimization and obfuscation command by using a preset opt ​​optimizer to obtain the optimized binary file, the step includes:

[0019] Creating a target LLVM pass based on the preset obfuscation requirements, and generating a callable obfuscation parameter file according to the target LLVM pass;

[0020] The callable obfuscation parameter file is loaded into the original LLVM opt optimizer to obtain a preset opt ​​optimizer.

[0021] In one embodiment, after the step of compiling the optimized binary file by the compiler based on the executable file compilation command to obtain the executable file, the method further includes:

[0022] The executable file is linked by a linker to generate a current executable file.

[0023] In one embodiment, after the step of linking the executable file through a linker to generate a current executable file, the following steps are included:

[0024] Execute the current executable file to obtain the application running result;

[0025] Performing code analysis on the current executable file by using a code analysis tool to obtain analysis results;

[0026] Generate an obfuscation effect report of the current compile command according to the application running result and the analysis result.

[0027] In one embodiment, the step of obtaining the current compile command includes:

[0028] Determine the source code category corresponding to the current compilation command, the source code category including: clang source code and swift source code;

[0029] When the source code category corresponding to the current compilation command is clang source code, intercepting the current compilation command by using a custom clang interceptor;

[0030] When the source code category corresponding to the current compile command is Swift source code, the current compile command is intercepted by a custom Swift interceptor.

[0031] In addition, to achieve the above-mentioned purpose, the present application proposes a code obfuscation device for an application program, the device comprising:

[0032] A command splitting module is used to obtain a current compile command and parse the current compile command; split and reassemble the current compile command according to the parsing result and a preset obfuscation requirement to obtain a reassembled compile command, wherein the reassembled compile command includes a preset number of sub-compilation commands;

[0033] The code compiling module is used to compile the source code through the Xcode compiler based on each of the sub-compilation commands to obtain an executable file.

[0034] In addition, to achieve the above-mentioned purpose, the present application also proposes a code obfuscation device for an application, the device comprising: a memory, a processor, and a code obfuscation program for the application stored in the memory and executable on the processor, the code obfuscation program for the application being configured to implement the steps of the code obfuscation method for the application as described above.

[0035] In addition, to achieve the above objectives, the present application also proposes a storage medium, on which a code obfuscation program of an application is stored, and when the code obfuscation program of the application is executed by a processor, the steps of the code obfuscation method of the application as described above are implemented.

[0036] The present application discloses a code obfuscation method for an application, which obtains a current compilation command and parses the current compilation command; splits and reorganizes the current compilation command according to the parsing result and preset obfuscation requirements to obtain a reorganized compilation command, wherein the reorganized compilation command includes a preset number of sub-compilation commands; based on each of the sub-compilation commands, the source code is compiled by the Xcode compiler to obtain an executable file. The present application parses and reorganizes the current compilation command, inserts code obfuscation logic into the normal compilation command, and compared with the existing method of directly replacing the entire tool chain of the Xcode compiler, the present application still completes code compilation based on the original Xcode compiler, ensuring the reliability of code obfuscation, and greatly reducing the subsequent upgrade and maintenance work while achieving the same code obfuscation effect. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0038] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0039] Figure 1 This is a flowchart of the first embodiment of the code obfuscation method for the application program of the present application;

[0040] Figure 2 This is a flowchart of the second embodiment of the code obfuscation method for the application program of the present application;

[0041] Figure 3 This is a flowchart of the third embodiment of the code obfuscation method for the application program of the present application;

[0042] Figure 4 A schematic diagram of the code compilation obfuscation process in the code obfuscation method of the application program of this application;

[0043] Figure 5 Workflow diagram for Xcode code obfuscation plug-in;

[0044] Figure 6 This is a schematic diagram of the module structure of the first embodiment of the code obfuscation device for the application program of this application;

[0045] Figure 7 A schematic diagram of the structure of the code obfuscation device for this application.

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

[0047] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.

[0048] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0049] The present application embodiment provides a method for obfuscating code of an application program. Figure 1 , Figure 1 This is a flowchart of the first embodiment of the code obfuscation method for the application program of the present application. In this embodiment, the method includes: Steps S10 to S30:

[0050] Step S10: Obtain the current compile command and parse the current compile command.

[0051] It should be understood that the method of this embodiment can be applied to the scenario of code obfuscation of the source code of the VisionOS system client application, and can also be applied to the scenario of strengthening the client application based on the IOS system. The execution subject of the method of this embodiment can be a computer electronic device that can run the Xcode tool with functions such as data processing and program running, such as a mobile phone, tablet, Mac computer, etc., or other electronic devices that can implement the code obfuscation method of the application of this application. The following takes the code obfuscation device of the application (referred to as "obfuscation device") as an example to explain this implementation and the following embodiments.

[0052] It should be noted that the method of this embodiment can be implemented in the form of an Xcode compiler plug-in. The native Xcode compiler can be packaged and its functions can be expanded through the Xcode compiler plug-in, and the entire default compiler tool chain of the Xcode tool can be retained. Ultimately, the code compilation is still completed based on the native Xcode compiler, which reduces the risks brought by the existing method of compiling completely based on the custom Xcode tool chain when performing code obfuscation, and improves the reliability of code obfuscation.

[0053] It is understandable that the current compile command may be a command generated by a development tool, namely Xcode, for compiling source code into an executable file. The obfuscation device may intercept the command generated by Xcode through a compile interception scheduler to parse it.

[0054] It should be understood that the current compilation command may include file paths, compiler options, macro definitions, etc. Parsing the current compilation command is conducive to subsequent splitting and reorganization of the current compilation command according to the parsing results.

[0055] It should be noted that, since the source code can be the source code of the VisionOS system client application, the source code category of the source code can be clang source code (such as object-c, C, C++, etc., which use the clang compiler) or swift source code (languages ​​that use the swift compiler).

[0056] In a specific implementation, the source code category corresponding to the current compile command can be determined first, and the source code category includes clang source code and swift source code; then, when the source code category corresponding to the current compile command is clang source code, the current compile command is intercepted by a custom clang interceptor; when the source code category corresponding to the current compile command is swift source code, the current compile command is intercepted by a custom swift interceptor. Then, the intercepted current compile command is parsed.

[0057] Step S20: splitting and reorganizing the current compile command according to the analysis result and the preset obfuscation requirement to obtain a reorganized compile command, wherein the reorganized compile command includes a preset number of sub-compile commands.

[0058] It should be understood that the user can determine the splitting and reorganization methods of the current compilation command based on personalized obfuscation requirements, such as adding obfuscation parameters or modifying file paths, etc. In order to illustrate how to split and reorganize the current compilation command, step S20 specifically includes steps S201 to S202:

[0059] Step S201: split the current compilation command according to the parsing result to obtain a plurality of independent compilation units.

[0060] It should be understood that when parsing the key components of the current compilation command: source code file path, compiler options, macro definitions, etc., the current compilation command can be split into several independent compilation units according to the source code dependencies and different compiler options, and the source code can be allocated to the above independent compilation units.

[0061] Step S202: reorganizing the independent compilation units according to a preset obfuscation requirement to obtain a preset number of sub-compilation commands, and integrating the sub-compilation commands into a reorganized compilation command.

[0062] It is understandable that each independent compilation unit can be reorganized according to the user's obfuscation requirements to obtain a preset number of sub-compilation commands, for example, three sub-compilation commands including: a binary representation conversion command, an optimization obfuscation command, and an executable file compilation command.

[0063] It should be understood that in order to facilitate the subsequent sequential execution of the above sub-compile commands, the sub-compile commands can be integrated to obtain a reorganized compile command.

[0064] Step S30: Based on each of the sub-compile commands, the source code is compiled by the Xcode compiler to obtain an executable file.

[0065] It should be understood that the above-mentioned reorganized compilation command can be used to call the Xcode native compiler in the obfuscated device, and then the source code is compiled based on the execution order corresponding to the above-mentioned sub-compilation commands to finally obtain an executable file.

[0066] It should also be noted that the above-mentioned Xcode compiler can be a clang compiler or a swift compiler, and the category of the Xcode compiler can be consistent with the source code category corresponding to the current compilation command.

[0067] It should be noted that during the compilation of the source code by the Xcode compiler, each sub-compilation command can generate an intermediate code, and the above sub-compilation command includes an optimization and obfuscation command. The Xcode compiler can optimize the generated intermediate code by calling a pre-set obfuscation optimization tool, add obfuscation logic, and then return the optimized intermediate code to finally generate an executable file.

[0068] This embodiment obtains the current compile command and parses the current compile command; splits and reorganizes the current compile command according to the parsing result and the preset obfuscation requirement to obtain a reorganized compile command, wherein the reorganized compile command includes a preset number of sub-compilation commands; based on each of the sub-compilation commands, the source code is compiled by the Xcode compiler to obtain an executable file. This embodiment parses and reorganizes the current compile command, inserts code obfuscation logic into the normal compile command, and compared with the existing method of directly replacing the entire tool chain of the Xcode compiler, the code compilation is still completed based on the original Xcode compiler, and the subsequent upgrade and maintenance work is greatly reduced while achieving the same code obfuscation effect.

[0069] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following. Figure 2 , Figure 2This is a flow chart of the second embodiment of the code obfuscation method for the application program of the present application.

[0070] In this embodiment, in order to illustrate the specific process of inserting code obfuscation logic in the normal compilation process, step S30 specifically includes: steps S301 to S303:

[0071] Step S301: Based on the binary representation conversion command, convert the source code corresponding file into a binary file through a compiler.

[0072] It should be understood that, taking the command whose source code category corresponding to the current compilation command is clang source code and specifically in object-c language format as an example, the current compilation command can be expressed as (clang-c am-o am), that is, converting the am file corresponding to the object-c code into a mach-o object file ao.

[0073] Furthermore, the three sub-compilation commands obtained by splitting the above current compilation command (clang-c am-o am) can be expressed as: binary representation conversion command (clang-c am-o a.bc), optimization obfuscation command (opt a.bc-oaa.bc) and executable file compilation command (clang-c aa.bc-o ao).

[0074] It should be noted that the clang compiler can be called through the binary representation conversion command (clang-c am-oa.bc) to convert the am file corresponding to the object-c code into a binary file a.bc corresponding to the intermediate language IR.

[0075] In the specific implementation, the clang compiler first preprocesses the am file, processes macro definitions, including header files, conditional compilation instructions, etc.; then converts the preprocessed code into LLVM IR, where LLVM IR is a low-level programming language that can provide a common intermediate representation for the compiler backend, allowing multiple languages ​​to share the same optimization and code generation technology; finally, the compiled LLVM IR is saved to the binary file a.bc, which is the intermediate code file.

[0076] Step S302: Based on the optimization and obfuscation command, the binary file is optimized and obfuscated by a preset opt ​​optimizer to obtain an optimized binary file.

[0077] In a specific implementation, the clang compiler can call the preset opt ​​optimizer based on the optimization obfuscation command (opt a.bc -o aa.bc), and then optimize the above binary file a.bc through the preset opt ​​optimizer, add obfuscation logic, and finally generate an optimized binary file aa.bc. The optimized binary file aa.bc is the optimized intermediate code file.

[0078] It should also be noted that the preset opt ​​optimizer may be an LLVM optimizer. In order to configure an optimizer that meets the user's personalized obfuscation requirements, a custom obfuscation parameter may be added to the original LLVM opt optimizer. Therefore, before step S302, the following steps are included:

[0079] Step S01: creating a target LLVM pass based on the preset obfuscation requirement, and generating a callable obfuscation parameter file according to the target LLVM pass.

[0080] It should be understood that the preset obfuscation requirements may also include user-configured variable names, function name obfuscation, control flow changes, or other specific obfuscation techniques. Then, a custom LLVM pass, i.e., a target LLVM pass, may be created based on the preset obfuscation requirements. An LVM pass is a plug-in module that can be inserted at a specific point in the compilation process to perform specific optimization or conversion tasks.

[0081] Then you can compile the target LLVM pass into a dynamic library (such as a .so file) so that it can be loaded and used by the subsequent LLVM opt optimizer; finally, you can create a command line parameter to specify how to use the LLVM pass, and then generate a callable obfuscation parameter file based on the target LLVM pass.

[0082] Step S02: Load the callable obfuscation parameter file in the original LLVM opt optimizer to obtain a preset opt ​​optimizer.

[0083] In a specific implementation, the above-mentioned callable parameter file can be loaded in the original LLVM opt optimizer through a command line or a configuration file to ensure that the target LLVM pass is correctly loaded and integrated into the optimization process of the original LLVM opt optimizer to obtain the preset opt ​​optimizer.

[0084] Step S303: Based on the executable file compilation command, the optimized binary file is compiled by the compiler to obtain an executable file.

[0085] It should be understood that, since the source code belongs to the VisionOS system client application, the executable file may be a mach-o object file, which is an intermediate product that is linked into the final executable file.

[0086] It can be understood that the preset opt ​​optimizer returns the above-mentioned optimized binary file aa.bc to the clang compiler, and then the optimized binary file aa.bc is compiled into the mach-o object file ao through the clang compiler based on the executable file compilation command (clang-c aa.bc-o ao).

[0087] Furthermore, in order to finally obtain an executable application file, after step S303, the following steps are further included:

[0088] Step S40: linking the executable file through a linker to generate a current executable file.

[0089] In a specific implementation, the above mach-o object file ao can be linked through a linker Linker, combined with other possible object files, library files and other resources required for runtime, to generate a final executable file, namely the current executable file.

[0090] In this embodiment, based on the binary representation conversion command, the source code corresponding file is converted into a binary file through the compiler; based on the optimization obfuscation command, the binary file is optimized and obfuscated by the preset opt ​​optimizer to obtain the optimized binary file; based on the executable file compilation command, the optimized binary file is compiled by the compiler to obtain the executable file. The preset opt ​​optimizer is the LLVM opt optimizer, so that code obfuscation can be achieved based on the highly open source and lightweight LLVM project. With the upgrade of Xcode, only the LLVM source code needs to be upgraded accordingly and compiled into the corresponding opt optimizer, which is conducive to reducing the difficulty of later upgrades and maintenance.

[0091] Based on the first and second embodiments of the present application, in the third embodiment of the present application, the same or similar contents as those of the first and second embodiments can be referred to the above description, and will not be described in detail later. Figure 3 , Figure 3 This is a flowchart of the third embodiment of the code obfuscation method for an application program of the present application.

[0092] In this embodiment, in order to evaluate the obfuscation effect on the source code so as to continuously improve the obfuscation strategy, after step S40, the following steps are further included: steps S501 to S503:

[0093] Step S501: Execute the current executable file to obtain the application running result.

[0094] In a specific implementation, the current executable file can be run to obtain the running status of the application and collect running data to perform multi-dimensional analysis based on the running data. For example, the following analysis can be performed from the dimensions of verification function, performance testing, and user experience:

[0095] Verify functionality: Ensure that the obfuscated code can still correctly perform the intended functions without introducing new errors or problems.

[0096] Performance testing: Check whether the application's performance is affected by the obfuscation process and ensure that obfuscation does not cause performance degradation.

[0097] User experience: Through actual operation, you can observe the response speed, stability, etc. of the application to ensure that the user experience is not affected.

[0098] Step S502: Perform code analysis on the current executable file using a code analysis tool to obtain analysis results.

[0099] It should be understood that the code analysis tool can be used to check the quality and performance of the compiled file, i.e., the current executable file mentioned above. The code analysis tool may include: static analysis tools for checking code quality (such as clangstatic analyzer, Coverity, etc.), and dynamic analysis tools for analyzing runtime performance and memory usage (such as gdb, valgrind, Profiler, etc.).

[0100] In the specific implementation, by using different code analysis tools, it is possible to identify potential problems in the code, such as memory leaks and uninitialized variables that may be introduced or masked during the obfuscation process; detect whether there are still security vulnerabilities in the obfuscated code to ensure that obfuscation does not reduce the security of the application; and evaluate the effect of obfuscation, such as checking whether all sensitive information is obfuscated and whether all code paths are difficult to reverse engineer.

[0101] Step S503: Generate an obfuscation effect report of the current compile command according to the application running result and the analysis result.

[0102] It is understandable that in order to compare the running results and analysis results before and after obfuscation, and pay attention to changes in performance, functional correctness, code complexity, etc., the aforementioned obfuscation process and the above-mentioned application running results and analysis results can be documented in detail in the form of a report, which is conducive to subsequent code maintenance and auditing, so as to continuously optimize the obfuscation strategy in the future.

[0103] After the executable file is linked by the linker to generate the current executable file, the current executable file is executed to obtain the application running result; the code analysis tool is used to perform code analysis on the current executable file to obtain the analysis result; and the obfuscation effect report of the current compilation command is generated according to the application running result and the analysis result. Thus, the code obfuscation compilation process and the final obfuscation compilation effect are recorded in detail in the form of a report, providing data support for the subsequent continuous optimization and improvement of the obfuscation strategy.

[0104] In addition, here you can Figure 4 Take this as an example to explain the code obfuscation process in this application. Figure 4 This is a schematic diagram of the code compilation obfuscation process in the code obfuscation method of this application.

[0105] exist Figure 4 In the code, Xcode can first generate and send compilation commands (clang source code compilation commands and / or swift compilation commands); then the custom clang interceptor and / or custom swift interceptor intercept the compilation commands of the corresponding categories; then the compilation commands are split and reorganized and executed in sequence (for clang source code compilation commands, "clang-ca.mo a.bc", "opt a.bc-o aa.bc" and "clang-c aa.bc-o ao" are executed in sequence; for swift source code compilation commands, "swift-fronted-c b.swift-ob.bc", "opt b.bc-o bb.bc" and "swift-fronted-c bb.bc-o bo" are executed in sequence) to obtain mach-o object files; finally, the mach-o object files (ao and bo) are linked through the Linker connector to generate the APP executable file.

[0106] Furthermore, since the method of this embodiment can be implemented in the form of an Xcode compiler plug-in, it can be regarded as an Xcode code obfuscation plug-in. Figure 5 Taking the example of Xcode compiler plug-in, the code obfuscation method of the application program of the present application is specifically described. Figure 5 Workflow diagram for the Xcode code obfuscation plugin.

[0107] exist Figure 5 In the Xcode code obfuscation plug-in, the following can be included: compilation interception scheduler, parsing and reorganization tool; the work of the Xcode code obfuscation plug-in also involves external tools such as compiler, opt optimizer and linker that interact with the plug-in.

[0108] Step 1: Xcode sends the Xcode compilation command (Xcode clang compilation command / Xcode swift compilation command) and intercepts it through the corresponding compilation interception scheduler;

[0109] Step 2: Use the parsing and reorganization tool to parse and reorganize the Xcode compilation command, and return the parsed and reorganized compilation command to the compilation interception scheduler;

[0110] Step 3: The compilation interception scheduler calls the compiler (clang compiler or swift compiler) based on the reorganized compilation command to compile;

[0111] Step 4: After the intermediate representation file is compiled, the obfuscation optimization logic is executed, and the compiled intermediate code file is optimized and obfuscated through the opt optimizer, and then the optimized intermediate code file is returned to the compiler;

[0112] Step 5: Use the compiler to compile the optimized intermediate code file to obtain the mach-o object file suitable for the VisionOS system or the IOS system. Finally, use the linker to link the mach-o object file to obtain the executable application file and complete the compilation.

[0113] The method of this application is implemented based on the Xcode code obfuscation plug-in. By intercepting the Xcode compilation command, parsing and reorganizing the compilation command, and inserting the code obfuscation logic during the normal compilation process, the compilation, optimization, linking and packaging functions of the entire VisionOS application source code can be completed. And because the default set of compiler tool chains of the Xcode tool is retained, the code compilation process is still based on the native Xcode compiler, which can reduce the risks brought by the existing method of compiling based entirely on the custom Xcode tool chain when performing code obfuscation, and improve the reliability of code obfuscation.

[0114] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the code obfuscation method of the application program of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.

[0115] In addition, the present application also provides a code obfuscation device for an application program, referring to Figure 6 , Figure 6 This is a schematic diagram of the module structure of the first embodiment of the code obfuscation device for the application program of this application; Figure 6 As shown, the device comprises:

[0116] The command splitting module 601 is used to obtain the current compile command and parse the current compile command; split and reorganize the current compile command according to the parsing result and the preset obfuscation requirement to obtain a reorganized compile command, wherein the reorganized compile command includes a preset number of sub-compilation commands;

[0117] The code compiling module 602 is used to compile the source code through the Xcode compiler based on each of the sub-compiling commands to obtain an executable file.

[0118] Furthermore, the command splitting module 601 is also used to determine the source code category corresponding to the current compilation command, and the source code category includes: clang source code and swift source code; when the source code category corresponding to the current compilation command is clang source code, the current compilation command is intercepted by a custom clang interceptor; when the source code category corresponding to the current compilation command is swift source code, the current compilation command is intercepted by a custom swift interceptor.

[0119] Furthermore, the command splitting module 601 is also used to split the current compilation command according to the parsing result to obtain a number of independent compilation units; reorganize each of the independent compilation units according to the preset obfuscation requirements to obtain a preset number of sub-compilation commands, and integrate each of the sub-compilation commands into a reorganized compilation command.

[0120] The sub-compile commands include: binary representation conversion commands, optimization and obfuscation commands, and executable file compilation commands;

[0121] Furthermore, the code compilation module 602 is also used to convert the source code corresponding file into a binary file through a compiler based on the binary representation conversion command; based on the optimization obfuscation command, optimize and obfuscate the binary file through a preset opt ​​optimizer to obtain an optimized binary file; based on the executable file compilation command, compile the optimized binary file through the compiler to obtain an executable file.

[0122] Wherein, the preset opt ​​optimizer is the LLVM opt optimizer.

[0123] Furthermore, the code compiling module 602 is also used to link the executable file through a linker to generate a current executable file.

[0124] This embodiment obtains the current compile command and parses the current compile command; splits and reorganizes the current compile command according to the parsing result and the preset obfuscation requirements to obtain a reorganized compile command, wherein the reorganized compile command includes a preset number of sub-compilation commands; based on each of the sub-compilation commands, the source code is compiled by the Xcode compiler to obtain an executable file. Since this embodiment inserts code obfuscation logic into the normal compile command by parsing and reorganizing the current compile command, compared with the existing method of directly replacing the entire tool chain of the Xcode compiler, the code compilation is still completed based on the original Xcode compiler, and the subsequent upgrade and maintenance work is greatly reduced while achieving the same code obfuscation effect.

[0125] Based on the first embodiment of the code obfuscation device for the above-mentioned application of the present application, a second embodiment of the code obfuscation device for the application of the present application is proposed.

[0126] In this embodiment, the device further includes: an optimizer initialization module and an execution evaluation module;

[0127] The optimizer initialization module is used to create a target LLVM pass based on the preset obfuscation requirement, and generate a callable obfuscation parameter file according to the target LLVM pass; load the callable obfuscation parameter file in the original LLVM opt optimizer to obtain the preset opt ​​optimizer.

[0128] The execution evaluation module is used to execute the current executable file to obtain the application running result; perform code analysis on the current executable file through a code analysis tool to obtain the analysis result; and generate an obfuscation effect report of the current compilation command according to the application running result and the analysis result.

[0129] In this embodiment, the preset opt ​​optimizer is the LLVM opt optimizer, so that code obfuscation can be implemented based on the highly open source and lightweight LLVM project. With the upgrade of Xcode, it is only necessary to upgrade the LLVM source code accordingly and compile it into the corresponding opt optimizer, which is conducive to reducing the difficulty of subsequent upgrade and maintenance; and further records the code obfuscation compilation process and the final obfuscation compilation effect in detail in the form of a report, providing data support for the subsequent continuous optimization and improvement of the obfuscation strategy.

[0130] Other embodiments or specific implementations of the code obfuscation device for the application described in this application can refer to the above-mentioned method embodiments and will not be described in detail here.

[0131] The present application also provides a code obfuscation device for an application, the code obfuscation device for an application includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the code obfuscation method for the application in the above-mentioned embodiment 1.

[0132] Reference below Figure 7 , Figure 7 The schematic diagram of the structure of the code obfuscation device of the application of the present application. The code obfuscation device of the application in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 7 The code obfuscation device for the application shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0133] like Figure 7As shown, the code obfuscation device for an application may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the code obfuscation device for an application are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the code obfuscation device of the application to communicate with other devices wirelessly or by wire to exchange data. Although the code obfuscation device of the application with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.

[0134] The present application also provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, the computer-readable program instructions being used to execute the code obfuscation method for the application program in the above-mentioned embodiment.

[0135] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.

[0136] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.

Claims

1. A code obfuscation method for an application, characterized in that: The method comprises: Obtaining a current compile command and parsing the current compile command; Splitting and reorganizing the current compile command according to the parsing result and the preset obfuscation requirement to obtain a reorganized compile command, wherein the reorganized compile command includes a preset number of sub-compile commands; Based on each of the sub-compile commands, the source code is compiled by the Xcode compiler to obtain an executable file.

2. The method according to claim 1, characterized in that The step of splitting and reorganizing the current compilation command according to the parsing result and the preset obfuscation requirement to obtain the reorganized compilation command includes: Splitting the current compilation command according to the parsing result to obtain a plurality of independent compilation units; The independent compilation units are reorganized according to preset obfuscation requirements to obtain a preset number of sub-compilation commands, and the sub-compilation commands are integrated into a reorganized compilation command.

3. The method according to claim 2, characterized in that The sub-compile commands include: binary representation conversion commands, optimization and obfuscation commands, and executable file compilation commands; The step of compiling the source code by using the Xcode compiler based on each of the sub-compile commands to obtain an executable file includes: Based on the binary representation conversion command, convert the source code corresponding file into a binary file through a compiler; Based on the optimization and obfuscation command, the binary file is optimized and obfuscated by a preset opt ​​optimizer to obtain an optimized binary file; Based on the executable file compilation command, the optimized binary file is compiled by the compiler to obtain an executable file.

4. The method according to claim 3, characterized in that The preset opt ​​optimizer is the LLVM opt optimizer; Before the step of performing optimization and obfuscation processing on the binary file based on the optimization and obfuscation command by using a preset opt ​​optimizer to obtain the optimized binary file, the step includes: Creating a target LLVM pass based on the preset obfuscation requirements, and generating a callable obfuscation parameter file according to the target LLVM pass; The callable obfuscation parameter file is loaded into the original LLVM opt optimizer to obtain a preset opt ​​optimizer.

5. The method according to claim 3, characterized in that After the step of compiling the optimized binary file by the compiler based on the executable file compilation command to obtain the executable file, the method further includes: The executable file is linked by a linker to generate a current executable file.

6. The method according to claim 5, characterized in that After the step of linking the executable file by the linker to generate the current executable file, the method further comprises: Execute the current executable file to obtain the application running result; Performing code analysis on the current executable file by using a code analysis tool to obtain analysis results; Generate an obfuscation effect report of the current compile command according to the application running result and the analysis result.

7. The method according to claim 1, characterized in that The step of obtaining the current compile command includes: Determine the source code category corresponding to the current compilation command, the source code category including: clang source code and swift source code; When the source code category corresponding to the current compilation command is clang source code, intercepting the current compilation command by using a custom clang interceptor; When the source code category corresponding to the current compile command is Swift source code, the current compile command is intercepted by a custom Swift interceptor.

8. A code obfuscation device for an application, characterized in that: The device comprises: A command splitting module is used to obtain a current compile command and parse the current compile command; split and reassemble the current compile command according to the parsing result and a preset obfuscation requirement to obtain a reassembled compile command, wherein the reassembled compile command includes a preset number of sub-compilation commands; The code compiling module is used to compile the source code through the Xcode compiler based on each of the sub-compilation commands to obtain an executable file.

9. A code obfuscation device for an application, characterized in that: The application code obfuscation device comprises: a memory, a processor, and a code obfuscation program for the application stored in the memory and executable on the processor. When the code obfuscation program for the application is executed by the processor, the steps of the application code obfuscation method according to any one of claims 1 to 7 are implemented.

10. A storage medium, characterized in that: The storage medium stores a code obfuscation program for an application, and when the code obfuscation program for the application is executed by a processor, the steps of the code obfuscation method for an application according to any one of claims 1 to 7 are implemented.