Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
At present, SO files compiled by codes written in C or C + + languages can be attacked and implanted with viruses, SO that the information security of users is threatened. The embodiment of the invention provides a method for loading an SO file in an application program, aiming at solving the problem.
Fig. 1 is a schematic flowchart of a first embodiment of a method for loading an SO file in an application program according to an embodiment of the present invention. The embodiment can be applied to the situation that the SO file is loaded after the application program runs. The method may be performed by a processor of a terminal device. As shown in fig. 1, the embodiment of the present invention specifically includes the following steps:
step 101: and when an operation instruction of the application program is received, acquiring a shell code in the application program and a current SO file of the application program.
Specifically, the terminal device in this embodiment may be a handheld device, a vehicle-mounted device, a wearable device, a computing device, and various forms of User Equipment (UE), a Mobile Station (MS), a terminal (terminal), and the like, of which an operating system is android. Exemplarily, the terminal device in this embodiment is a mobile phone.
Existing applications can be divided into: different application types such as tool type programs, game type programs, shopping type programs, life type programs and multimedia type programs. The application program in the embodiment of the present invention may be any of the above-described application programs. For example, the application program in the embodiment of the present invention may be an instant messaging program, a video playing program, or an online shopping program.
In this embodiment, the application program has been installed in advance on the terminal device. Installing the application may be accomplished by an APK running the application. In one implementation, the APK of the application may be obtained by the terminal device from an application store via a network. In another implementation manner, the APK of the application may be obtained by the terminal device from another terminal device through a connection signal such as bluetooth. In yet another implementation, the APK of the application program may be pre-stored on the terminal device by the manufacturer of the terminal device at the time of factory shipment.
In this embodiment, the execution main body hardware is a processor of the terminal device, and the software is a main program of the application program.
After the application program is installed, the application program may be executed under the control of a user or other devices, that is, an execution instruction of the application program may be triggered by the user or other devices. In one implementation, the terminal device may determine that the application needs to be run after receiving a running instruction triggered by a user, where the running instruction may be triggered by a touch screen or a microphone. For example, the user clicks on an icon of the application to run the application. In another implementation manner, after receiving an operation instruction sent by the control device, the terminal device determines that the application program needs to be operated, and the operation instruction may be triggered by remote control or a predetermined manner. For example, the control device sends a video to the terminal device, and sets in advance that the terminal device starts to run a video playback program to play the video after receiving the video, in which case, after the terminal device receives the video, it is determined that the application program needs to run.
In this embodiment, the SO file is placed at the program entrance of the application program, and therefore, the SO file is loaded after the application program runs. Therefore, in the embodiment of the present invention, in order to ensure the security of loading the SO file in the application program, after receiving an operation instruction triggered by a user or triggered by another device, a shell code in the application program and a current SO file of the application program need to be acquired to verify the current SO file.
The shell code in the embodiment of the present invention may be a file named ksotp. SO files may be files named libsotpcomm.
The current SO file of the application program in step 101 refers to an SO file in the application program when the operation instruction of the application program is received. When the application program leaves the factory, the application program can be provided with a factory SO file. After the application is installed on the terminal device, the factory SO file may be illegally modified. That is, the current SO file may or may not be the same as the factory SO file. If the SO file is the same as the factory SO file, the current SO file of the application program is not modified; if the SO file is different from the factory SO file, the current SO file of the application program is modified.
The shell code referred to in this embodiment is code written by a developer of the application. The shell code is used for verifying the current SO file.
Step 102: and calling the shell code to encrypt the current SO file by using a first encryption algorithm to obtain a current check value, and calling the shell code to compare whether the current check value is consistent with a factory check value pre-stored in the application program.
The factory check value is the check value of the factory SO file of the application program encrypted by adopting a first encryption algorithm.
Specifically, after the current SO file and the shell code are acquired, the current SO file can be verified through the shell code.
In this embodiment, the application program stores a factory verification value in advance. The factory check value is determined based on a first encryption algorithm and a factory SO file of the application program when the APK of the application program is factory. The factory SO file referred to herein refers to an SO file that is determined by a developer of an application program when developing the SO file and has not been modified by another person without modification authority. The SO file is a binary file formed by compiling codes written in C or C + +.
In this embodiment, whether the current SO file is modified may be determined by calculating a current check value of the current SO file and comparing whether the current check value is the same as the factory check value. Specifically, whether the current check value is the same as the factory check value is determined by calling a shell code.
The shell code in this embodiment functions as: and encrypting the current SO file according to a first encryption algorithm, determining a current check value, and comparing whether the current check value is the same as the factory check value. The first encryption Algorithm may be a Message Digest Algorithm (MD 5), a Secure Hash Algorithm (SHA), a Hash Authentication Code (HMAC), or other encryption algorithms.
Alternatively, the first encryption algorithm may be the national secret SM3 — HMAC algorithm. The SM3-HMAC algorithm generates a hash value through padding and iterative compression, and the length of the hash value is 256 bits. Accordingly, when determining the factory verification value, the SM3-hmac. exe tool may be used to obtain the factory verification value of the factory SO file. Compared with other algorithms, the SM3-HMAC algorithm outputs a longer hash value, and therefore, the security is higher.
In one implementation, the factory check value is directly stored in a storage space in a private directory of the application program in the terminal device, and when the current check value is compared with the factory check value, the factory check value is read from the private directory of the application program in the terminal device and compared.
In another implementation, the factory verification value is stored in the storage space under the private directory of the application program in the terminal device in the form of a verification file. The verification file referred to herein is a file formed by encrypting the factory verification value according to a second encryption algorithm.
Optionally, after the application program is installed and when the application program is run for the first time, a shell code may be called, where the shell code is used to encrypt the factory verification value with the second encryption algorithm to form a verification file, and store the verification file in a storage space in a private directory of the application program in the terminal device. It should be noted that, when the shell code is called and the factory check value is encrypted by the second encryption algorithm, the factory check value may be assigned to a temporary variable, and then the temporary variable is encrypted, the encrypted factory check value is written into the check file, and the check file is stored in the storage space in the private directory of the application program. To further ensure the security of the check file, the value of the temporary variable may be cleared after the check file is stored. Emptying the temporary variable can prevent the temporary variable from remaining in the memory space, thereby avoiding the problem of factory check value leakage.
The format of the check file can be txt, bin and the like. Illustratively, the check file may be a file named SM3-hmac. The second Encryption algorithm may be an SM1 algorithm, an SM4 algorithm, an Advanced Encryption Standard (AES), or a Data Encryption Standard (DES). Illustratively, the second encryption algorithm may be the SM4 algorithm, which is a block cipher algorithm, with a block length of 128 bits and a key length of 128 bits.
Based on the storage mode of the factory check value, when the terminal device calls the shell code to determine whether the current check value is the same as the factory check value, the following two implementation modes are provided:
the first realization mode is as follows: and the shell code determines a factory check value according to the decryption algorithm corresponding to the second encryption algorithm and the check file, and determines whether the current check value is the same as the factory check value. In this implementation manner, after the shell code obtains the check file from the storage space in the private directory of the application program in the terminal device, the content in the check file is decrypted according to the decryption algorithm corresponding to the second encryption algorithm, and after the factory check value is obtained, the current check value is compared with the factory check value to determine whether the current check value is the same as the factory check value.
The second implementation manner is as follows: the shell code encrypts the current check value according to a second encryption algorithm to form an encrypted current check value, and determines whether the encrypted current check value is the same as the value stored in the check file.
It should be noted that, in the terminal device with an android operating system, all data in the application program is private. When an application program is installed in an operating system, a folder is used for storing own data, and only the application program has write authority to the folder. No other application can write data in this folder. The storage path of this folder is the private directory of the application.
The factory check value is stored in the storage space under the private directory of the application program in the terminal equipment, or the factory check value is stored in the storage space under the private directory of the application program in the terminal equipment in the form of a check file, and the storage mode can ensure that other application programs cannot modify the factory check value, so that the running safety of the application program is further improved. Further, the factory check value is stored in a storage space under a private directory of an application program in the terminal device in the form of a check file, and the check file is formed by encrypting the factory check value according to a second encryption algorithm, SO that on one hand, double encryption of the factory SO file is realized, and the security is higher, and on the other hand, the purpose of storing the factory check value by using the check file is to facilitate subsequent monitoring of the check file, SO that a user is reminded when an attacker illegally modifies the factory check value, and the security of loading the SO file is further improved. This implementation will be described in detail in the embodiment shown in fig. 3.
After the main program of the application program calls the shell code, the shell code can return the operation result to the main program after the operation is finished.
Step 103: and if the current check value is consistent with the factory check value, loading the current SO file of the application program according to the operation instruction.
Specifically, when the current check value is determined to be the same as the factory check value, which indicates that the current SO file is the same as the factory SO file, the current SO file is proved to be safe, and at this time, the current SO file is loaded according to the operation instruction to call the method in the SO file.
Optionally, in step 103, the current SO file may be loaded by calling a system. The parameter in the system load method is the path of the SO file in the application.
In one implementation, the operation of the application is terminated if the current check value is inconsistent with the factory check value.
In another implementation manner, this embodiment further includes step 104: and if the current check value is different from the factory check value, outputting first prompt information.
Wherein the first prompt message is used for indicating that the current SO file of the application program has been modified.
Specifically, when the current check value is determined to be different from the factory check value, which indicates that the current SO file is different from the factory SO file, it is proved that the current SO file has been modified and a potential safety hazard may exist, and at this time, first prompt information is output to prompt a user.
In step 104, the first prompt message may be output in an interface display mode, in a vibration mode or in a voice prompt mode.
The following description will be given taking an example in which the first presentation information is output by using an interface display. FIG. 2 is a schematic diagram of a user interface in the embodiment shown in FIG. 1. As shown in fig. 2, in the user interface 201, a prompt message "the application has been illegally modified, an exit is suggested" is output, and a button 202 for determining the exit and a button 203 for canceling the exit are given. The user can select according to the requirement of the user.
The above process is illustrated below with a specific example: after downloading the installation package of the online shopping program, a user installs the online shopping program on a mobile phone, wherein the online shopping program comprises a factory SO file, a factory check value of the factory SO file and a shell code. After the installation is completed and the online shopping program runs for the first time, the main program of the application program calls the shell code, the factory check value of the factory SO file in the online shopping program is encrypted to form a check file, and the check file is stored in the storage space of the private directory of the online shopping program on the terminal equipment. Meanwhile, the factory SO file and the shell code can be stored in the terminal equipment. After the installation is completed, an icon of the online shopping program appears on a mobile phone application program interface. After the first operation, when determining that the online shopping program needs to be operated to perform online shopping, the user can click the icon of the online shopping program, and the click operation can trigger an operation instruction of the application program. At this time, a current SO file (an SO file when an operation instruction of the online shopping program is received, the current SO file may be the same as or different from a factory SO file) in the online shopping program may have been attacked, and loading the modified SO file may threaten information security of the user, for example, loading the SO file may allow an attacker to obtain sensitive information such as an account number and a password of the user. To avoid this risk, the main program of the online shopping program executes steps 101 and 102 to determine whether the current SO file is modified. And selecting to execute the step 103 or the step 104 according to the execution result of the step 102. In the process, if the current SO file in the online shopping program is modified, the first prompt message is output to prompt the user, SO that the information safety of the user can be ensured.
In the method for loading an SO file in an application program provided in this embodiment, when an operation instruction of the application program is received, a shell code in the application program and a current SO file of the application program are obtained, the shell code is called to encrypt the current SO file with a first encryption algorithm to obtain a current check value, and the shell code is called to compare whether the current check value is consistent with a factory check value pre-stored in the application program, where the factory check value is a check value formed after the factory SO file of the application program is encrypted with the first encryption algorithm, and when it is determined that the current check value is the same as the factory check value, the current SO file of the application program is loaded according to an operation instruction to operate the application program, SO that it is achieved that whether the current SO file is the same as the factory SO file is verified with the shell code, and the current SO file is loaded only when it is determined that the current SO file is the same as the factory SO file, the leakage of user information caused by loading the modified SO file is avoided, SO that the safety of loading the SO file in the application program is improved, and further, the information safety of the user is ensured.
Fig. 3 is a flowchart illustrating a second embodiment of a method for loading an SO file in an application according to an embodiment of the present invention. The embodiment of the present invention provides a detailed description of other steps of the method for loading the SO file in the application program based on the embodiment shown in fig. 1. As shown in fig. 3, the method for loading an SO file in an application program provided in the embodiment of the present invention includes:
step 301: and when an operation instruction of the application program is received, acquiring a shell code in the application program and a current SO file of the application program.
Step 301 is similar to the implementation process and technical principle of step 101, and is not described herein again.
Step 302: and calling the shell code to determine whether the verification file exists in the storage space under the private directory of the application program in the terminal equipment.
Step 303: if the verification file does not exist, calling the shell code to encrypt the factory verification value according to a second encryption algorithm, writing the encrypted value into the file to form the verification file, and storing the verification file in a storage space under a private directory of an application program in the terminal equipment.
In the embodiment of the invention, the factory check value is stored in the storage space of the private directory of the application program in the terminal equipment in the form of the check file.
Based on the description in the embodiment shown in fig. 1, the check file is generated and stored in the storage space in the private directory of the application program in the terminal device when the application program is run for the first time. In the embodiment of the invention, before comparing the current check value with the factory check value, whether the check file exists needs to be judged firstly. And when the check file does not exist, calling the shell code to encrypt the factory check value according to a second encryption algorithm, writing the encrypted value into the file to form the check file, and storing the check file in a storage space under a private directory of an application program in the terminal equipment.
Step 304: calling shell code to listen to check whether the file is modified.
The shell code is used for calling a FileObserver method and a service method and monitoring whether the check file is modified.
Specifically, step 304 may be started after it is determined that a check file exists or is created. In this implementation, as long as the check file is created on the terminal device, it can be listened whether the check file is modified.
Optionally, the way of snooping is to call shell code to implement snooping. In other words, in this embodiment, the shell code may call a FileObserver method and a service method, and monitor whether the check file is modified, in addition to determining whether the current SO file of the application program is modified and generating the check file. Once the service for listening to the check file is started, the service is in a listening state during the running of the application program.
It should be noted that before step 304 is executed, it may be determined whether the state of the check file (whether it is modified) has been monitored by calling the shell code, and if so, step 305 is directly executed.
Step 305: and outputting second prompt information when the verification file is determined to be modified.
Wherein the second prompt message is used for indicating that the check file is modified.
Specifically, when it is determined that a value in the check file is changed, it is determined that the check file is modified. At this time, the second prompt message may be output. The output mode of the second prompt message can be an interface display mode, a vibration mode or a sound prompt mode.
It should be noted that the purpose of monitoring the check file is as follows: if the value in the check file is changed by an illegal means and the check of the SO file is passed, but the SO file is loaded even if the check of the SO file is successful because of the function of monitoring the check file, but the check file is modified after monitoring, a prompt is given to indicate that the SO file is tampered, the user is prevented from entering the next operation, and the information safety of the user is further ensured.
Step 306: and calling the shell code to encrypt the current SO file by using a first encryption algorithm to obtain a current check value, and calling the shell code to compare whether the current check value is consistent with a factory check value pre-stored in the application program.
The factory check value is the check value of the factory SO file of the application program encrypted by adopting a first encryption algorithm.
There is no timing relationship between step 306 and step 304. That is, the step of calling the shell code to determine whether the current check value is the same as the factory check value and the step of calling the shell code to monitor whether the check file is modified may be executed simultaneously, or may be executed sequentially in any order. The step 304 is first executed in fig. 3 for illustration.
Step 307: and if the current check value is consistent with the factory check value, loading the current SO file of the application program according to the operation instruction.
Step 308: and if the current check value is different from the factory check value, outputting first prompt information.
The implementation processes and technical principles of step 306 and step 102, step 307 and step 103, and step 308 and step 104 are similar, and are not described herein again.
FIG. 4 is a schematic diagram of a user interface in the embodiment shown in FIG. 3. As shown in fig. 4, in the user interface 401, a prompt message "the file in the application has been illegally modified, the uninstall is recommended" is output, and a button 402 for determining uninstall and a button 403 for canceling uninstall are given. The user can select according to the requirement of the user.
In the method for loading the SO file in the application program provided by this embodiment, a shell code is called to monitor whether the check file is modified, where the shell code is used to call the FileObserver method and the service method, and monitor whether the check file is modified, and when it is determined that the check file is modified, a second prompt message is output, where the second prompt message is used to indicate that the check file is modified, SO that whether the check file is modified is monitored in real time through the shell code, and when the check file is modified, the second prompt message is output to prompt a user, and it is ensured that a factory check value of a factory-leaving SO file is not modified illegally, thereby further improving the security of application program operation.
Fig. 5 is a schematic structural diagram of a first apparatus for loading an SO file in an application according to an embodiment of the present invention. As shown in fig. 5, the apparatus for loading an SO file in an application provided in an embodiment of the present invention includes: an acquisition module 51, a first calling module 52 and a loading module 53.
The obtaining module 51 is configured to obtain a shell code in the application program and a current SO file of the application program when receiving an operation instruction of the application program.
A first calling module 52, configured to call the shell code, encrypt the current SO file with a first encryption algorithm to obtain a current check value, and call the shell code to compare whether the current check value is consistent with a factory check value pre-stored in an application program; and the factory check value is the check value of the factory SO file of the application program encrypted by adopting a first encryption algorithm.
In one implementation, the factory check value is stored in a storage space under a private directory of an application program in the terminal device in the form of a check file, and the check file is a file formed by encrypting the factory check value according to a second encryption algorithm. The first calling module 52 specifically determines whether the current verification value is the same as the factory verification value by calling the shell code in the following two ways: calling the shell code to determine a factory check value according to a decryption algorithm and a check file corresponding to the second encryption algorithm, and determining whether the current check value is the same as the factory check value; or calling the shell code to encrypt the current check value according to a second encryption algorithm to form an encrypted current check value, and determining whether the encrypted current check value is the same as the value stored in the check file.
Optionally, the first encryption algorithm is SM3 — HMAC algorithm, and the second encryption algorithm is SM4 algorithm.
And the loading module 53 is configured to load the current SO file of the application program according to the operation instruction when the factory verification value is consistent with the current verification value.
Optionally, the loading module 53 is specifically configured to call a system load method, and load the current SO file.
Optionally, in this embodiment, the apparatus further includes a first output module (not shown in the figure). The first output module is used for outputting first prompt information when the factory check value is different from the current check value. Wherein the first prompt message is used for indicating that the current SO file of the application program has been modified.
The device for loading the SO file in the application program provided by the embodiment of the invention can execute the method for loading the SO file in the application program provided by the embodiment of the invention shown in FIG. 1, and has corresponding functional modules and beneficial effects of the execution method.
Fig. 6 is a schematic structural diagram of a second apparatus for loading an SO file in an application according to an embodiment of the present invention. As shown in fig. 6, the embodiment of the present invention further includes, on the basis of the embodiment shown in fig. 5: a third calling module 63, a fourth calling module 64, a second calling module 61 and a second output module 62.
And a third calling module 63, configured to call the shell code to determine whether a check file exists in a storage space in the private directory of the application program in the terminal device.
And a fourth calling module 64, configured to, when it is determined that the check file does not exist, call the shell code to encrypt the factory check value according to the second encryption algorithm, write the encrypted value into the file to form a check file, and store the check file in a storage space in a private directory of an application program in the terminal device.
And the second calling module 61 is used for calling the shell code to monitor whether the check file is modified.
The shell code is used for calling a FileObserver method and a service method and monitoring whether the check file is modified.
And a second output module 62, configured to output a second prompt message when it is determined that the check file is modified.
Wherein the second prompt message is used for indicating that the check file is modified.
The device for loading the SO file in the application program provided by the embodiment of the invention can execute the method for loading the SO file in the application program provided by the embodiment of fig. 3 of the invention, and has the corresponding functional modules and beneficial effects of the execution method.
Fig. 7 is a schematic structural diagram of a terminal device according to an embodiment of the present invention. As shown in fig. 7, the terminal device includes a processor 70 and a memory 71. Optionally, an input device 72 and an output device 73 may also be included. The number of the processors 70 in the terminal device may be one or more, and one processor 70 is taken as an example in fig. 7. The processor 70, the memory 71, the input device 72 and the output device 73 in the terminal equipment may be connected by a bus or other means, and the connection by the bus is exemplified in fig. 7.
The memory 71 is used as a computer-readable storage medium, and can be used for storing software programs, computer-executable programs, and modules, such as program instructions and modules corresponding to the method for loading the SO file in the application program in the embodiment of the present invention (for example, the obtaining module 51, the first calling module 52, and the loading module 53 in the device for loading the SO file in the application program). The processor 70 executes various functional applications and data processing of the terminal device by running software programs, instructions and modules stored in the memory 71, that is, implements the method for loading the SO file in the application program.
The memory 71 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data created according to the use of the terminal, and the like. Further, the memory 71 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some examples, the memory 71 may further include memory located remotely from the processor 70, which may be connected to the terminal device via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The input device 72 may be used to receive input numeric or character information and generate key signal inputs related to user settings and function control of the terminal device. The output device 73 may include a display device such as a display screen.
Embodiments of the present invention also provide a storage medium containing computer-executable instructions, which when executed by a computer processor, are used to perform a method for loading an SO file in an application program as described above.
Of course, the storage medium provided by the embodiment of the present invention contains computer-executable instructions, and the computer-executable instructions are not limited to the method operations described above, and may also perform related operations in the method for loading the SO file in the application program provided by any embodiment of the present invention.
From the above description of the embodiments, it is obvious for those skilled in the art that the present invention can be implemented by software and necessary general hardware, and certainly, can also be implemented by hardware, but the former is a better embodiment in many cases. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which can be stored in a computer-readable storage medium, such as a floppy disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a FLASH Memory (FLASH), a hard disk or an optical disk of a computer, and includes several instructions for enabling a computer device (which may be a personal computer, a server, or a network device) to execute the methods according to the embodiments of the present invention.
It should be noted that, in the embodiment of the above search apparatus, each included unit and module are merely divided according to functional logic, but are not limited to the above division as long as the corresponding functions can be implemented; in addition, specific names of the functional units are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present invention.
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.