Disclosure of Invention
In view of this, embodiments of the present invention provide a method, a system, and a storage medium for dynamically modifying a read-only attribute of an android system, which are simple to operate and high in reliability.
In a first aspect, an embodiment of the present invention provides a method for dynamically modifying a read-only attribute of an android system, including the following steps:
detecting the access authority of a target file through an init process, and acquiring the memory address of a target code segment with read-only authority;
calculating the length of a target code segment, and creating an array memory of the length;
acquiring memory data of a target code segment, and storing the memory data into the array memory;
traversing the array memory, judging whether the memory data in the array memory can be matched with the identification byte of the read-only permission, if so, recording a matching address corresponding to the memory data capable of being matched with the identification byte, and executing the next step; otherwise, the feedback attribute modification fails;
modifying the memory data in the matched address;
wherein, the target file is/proc/1/maps file
Further, the step of obtaining the memory data of the target code segment and storing the memory data into the array memory includes the following steps:
attaching the connection parameter to the init process through a process tracking function; the connection parameter is a PTRACE _ ATTACH connection parameter;
retrieving memory data of a target code segment of the init process by configuring a memory reading parameter value in the process tracking function;
storing the retrieved memory data into the applied array memory;
wherein the memory read parameter is PTRACE _ PEEKTEXT.
Further, the memory data includes data content and an address corresponding to the data content.
Further, the step of determining whether the memory data in the array memory can match the identification byte of the read-only permission specifically includes:
comparing and matching the memory data in the array memory with the identification bytes of the read-only permission;
wherein the identification byte is "ro".
Further, the step of modifying the memory data in the matching address includes the following steps:
attaching the connection parameter to the init process through a process tracking function; the connection parameter is a PTRACE _ ATTACH connection parameter;
modifying the memory data on the matched address by configuring the memory write-in parameter value in the process tracking function;
wherein, the memory write parameter is PTRACE _ postext.
Further, the method also comprises the following steps:
and writing the modified memory data into the memory address of the target code segment.
Further, the method also comprises the following steps:
and acquiring the modified memory data in a command line mode.
In a second aspect, an embodiment of the present invention further provides a system for dynamically modifying read-only properties of an android system, where the system includes:
the permission query module is used for detecting the access permission of the target file through the init process and acquiring the memory address of the target code segment with the read-only permission;
the array memory allocation module is used for calculating the length of the target code segment and creating an array memory of the length;
the acquisition module is used for acquiring the memory data of the target code segment and storing the memory data into the array memory;
the matching module is used for traversing the array memory, judging whether the memory data in the array memory can be matched with the identification byte of the read-only permission, if so, recording a matching address corresponding to the memory data capable of being matched with the identification byte, and executing the dynamic modification module; otherwise, the feedback attribute modification fails;
the dynamic modification module is used for modifying the memory data in the matched address;
wherein, the target file is/proc/1/maps file
In a third aspect, an embodiment of the present invention further provides a system for dynamically modifying read-only attributes of an android system, where the system includes:
at least one processor;
at least one memory for storing at least one program;
when the at least one program is executed by the at least one processor, the at least one processor is enabled to implement the method for dynamically modifying the read-only property of the android system.
In a fourth aspect, the embodiment of the present invention further provides a storage medium, in which processor-executable instructions are stored, and when executed by a processor, the processor-executable instructions are configured to perform the method for dynamically modifying the read-only property of the android system.
One or more of the above-described embodiments of the present invention have the following advantages: the embodiment of the invention firstly detects the access authority of a target file through an init process, then calculates the length of a target code segment of read-only authority, then judges whether the memory data in the array memory can be matched with the identification byte of the read-only authority, and finally modifies the memory data which can be matched with the identification byte to realize the authority modification of read-only attribute; according to the method, the attribute in the system mirror image or the root mirror image does not need to be frequently modified, the Android system does not need to be restarted, the access authority of the attribute can be dynamically modified only through the init process, and the method is simple to operate and high in reliability.
Detailed Description
The invention will be further explained and explained with reference to the drawings and the embodiments in the description. The step numbers in the embodiments of the present invention are set for convenience of illustration only, the order between the steps is not limited at all, and the execution order of each step in the embodiments can be adaptively adjusted according to the understanding of those skilled in the art.
Referring to fig. 1, an embodiment of the present invention provides a method for dynamically modifying a read-only attribute of an android system, including the following steps:
detecting the access authority of a target file through an init process, and acquiring the memory address of a target code segment with read-only authority;
calculating the length of a target code segment, and creating an array memory of the length;
acquiring memory data of a target code segment, and storing the memory data into the array memory;
traversing the array memory, judging whether the memory data in the array memory can be matched with the identification byte of the read-only permission, if so, recording a matching address corresponding to the memory data capable of being matched with the identification byte, and executing the next step; otherwise, the feedback attribute modification fails;
and modifying the memory data in the matched address.
Further, as a preferred embodiment, the step of obtaining the memory data of the target code segment and storing the memory data into the array memory includes the following steps:
attaching the connection parameter to the init process through a process tracking function; the connection parameter is a PTRACE _ ATTACH connection parameter;
retrieving memory data of a target code segment of the init process by configuring a memory reading parameter value in the process tracking function;
storing the retrieved memory data into the applied array memory;
wherein the memory read parameter is PTRACE _ PEEKTEXT.
Further, as a preferred embodiment, the memory data includes data content and an address corresponding to the data content.
Further, as a preferred embodiment, the step of determining whether the memory data in the array memory can match the identification byte of the read-only permission specifically includes:
comparing and matching the memory data in the array memory with the identification bytes of the read-only permission;
wherein the identification byte is "ro".
Further as a preferred embodiment, the step of modifying the memory data in the matching address includes the following steps:
attaching the connection parameter to the init process through a process tracking function; the connection parameter is PTRACE _ ATTACH connection
A parameter;
modifying the memory data on the matched address by configuring the memory write-in parameter value in the process tracking function;
wherein, the memory write parameter is PTRACE _ postext.
Further as a preferred embodiment, the method further comprises the following steps:
and writing the modified memory data into the memory address of the target code segment.
Further as a preferred embodiment, the method further comprises the following steps:
and acquiring the modified memory data in a command line mode.
Corresponding to the method in fig. 1, an embodiment of the present invention further provides a system for dynamically modifying read-only attributes of an android system, where the system includes:
the permission query module is used for detecting the access permission of the target file through the init process and acquiring the memory address of the target code segment with the read-only permission;
the array memory allocation module is used for calculating the length of the target code segment and creating an array memory of the length;
the acquisition module is used for acquiring the memory data of the target code segment and storing the memory data into the array memory;
the matching module is used for traversing the array memory, judging whether the memory data in the array memory can be matched with the identification byte of the read-only permission, if so, recording a matching address corresponding to the memory data capable of being matched with the identification byte, and executing the dynamic modification module; otherwise, the feedback attribute modification fails;
and the dynamic modification module is used for modifying the memory data in the matched address.
Referring to fig. 1, the overall implementation steps of the embodiment of the present invention are described in detail below:
according to the technical scheme, the read-only attribute is modified without frequently modifying the mirror image and restarting the mobile phone or the simulator.
In the Android platform, when the attribute value is accessed, access authority control is added, so that the access security is enhanced. All running processes in the system can access the attribute values, but only the init process can modify the attribute values. When other processes modify the attribute values, requests must be made to the init process (initialization process), and the init process is finally responsible for modifying the attribute values. In the process, the init process checks the access authority of each attribute and modifies the attribute value. Therefore, the technical scheme of the set modifies the access authority of the attribute checked by the init to achieve the aim of dynamic modification.
In this embodiment, a layout mode of a virtual machine space of an init process is first obtained, a code segment whose memory right is read-only execution is found, the length of the memory segment is calculated, an array memory with a corresponding length char (one byte) is first applied for storing data of the init process which is then obtained, a system function PTRACE (process tracking function) is attached to the init process, and by setting a PTRACE function parameter value PTRACE _ PEEKTEXT (memory read parameter), the memory read parameter is used for reading contents of the memory, the contents of the code segment of the init process are retrieved byte by byte, and a retrieval result is stored in the array memory which is previously applied, so that all contents and addresses stored in the code of the init process are obtained.
As is well known, the init process determines whether the attribute right is read only by comparing whether the first 4 bytes of the key value are 'r', 'o', 'lambda', '0'. If there is a match, the modification of the value of the attribute is allowed. Then, only the content corresponding to the 4 bytes of memory needs to be modified, and the desired effect can be achieved. By continuously comparing whether the content in the array is equal to the corresponding integer of 'ro.' (0x2e6f72), if the content in the array is matched with the corresponding integer, the memory address which needs to be changed is recorded.
After the memory address is found through matching, the PTRACE function needs to be called again, and a parameter PTRACE _ POKETEXT (memory write parameter) is set, where the memory write parameter is used for writing content, where only 0x2e6f72 needs to be changed to another value, for example, to another character such as "rp.", and the corresponding integer value is 0x2e6f 73. The new value is written to the previously corresponding memory address.
In this embodiment, the read-only property may be set through the system property API __ system _ property _ set (set system property) function, and finally, the modified content is obtained through __ system _ property _ get (obtain system property) or the command line "getprop + property name".
In conclusion, the invention reduces unnecessary machine changing operation and reduces the risk brought by machine changing. The attribute of the mobile device can be modified by cooperating with development of a third party App, such as modifying the model, setting the model to a debugging mode and the like, so that the test scene is convenient to apply.
Corresponding to the method in fig. 1, an embodiment of the present invention further provides a system for dynamically modifying read-only attributes of an android system, where the system includes:
at least one processor;
at least one memory for storing at least one program;
when the at least one program is executed by the at least one processor, the at least one processor is enabled to implement the method for dynamically modifying the read-only property of the android system.
The contents in the above method embodiments are all applicable to the present system embodiment, the functions specifically implemented by the present system embodiment are the same as those in the above method embodiment, and the beneficial effects achieved by the present system embodiment are also the same as those achieved by the above method embodiment.
Furthermore, an embodiment of the present invention further provides a storage medium, in which processor-executable instructions are stored, and when the processor-executable instructions are executed by a processor, the storage medium is used for executing the data processing method.
In alternative embodiments, the functions/acts noted in the block diagrams may occur out of the order noted in the operational illustrations. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality/acts involved. Furthermore, the embodiments presented and described in the flow charts of the present invention are provided by way of example in order to provide a more thorough understanding of the technology. The disclosed methods are not limited to the operations and logic flows presented herein. Alternative embodiments are contemplated in which the order of various operations is changed and in which sub-operations described as part of larger operations are performed independently.
Furthermore, although the present invention is described in the context of functional modules, it should be understood that, unless otherwise stated to the contrary, one or more of the described functions and/or features may be integrated in a single physical device and/or software module, or one or more functions and/or features may be implemented in a separate physical device or software module. It will also be appreciated that a detailed discussion of the actual implementation of each module is not necessary for an understanding of the present invention. Rather, the actual implementation of the various functional modules in the apparatus disclosed herein will be understood within the ordinary skill of an engineer, given the nature, function, and internal relationship of the modules. Accordingly, those skilled in the art can, using ordinary skill, practice the invention as set forth in the claims without undue experimentation. It is also to be understood that the specific concepts disclosed are merely illustrative of and not intended to limit the scope of the invention, which is defined by the appended claims and their full scope of equivalents.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The logic and/or steps represented in the flowcharts or otherwise described herein, e.g., an ordered listing of executable instructions that can be considered to implement logical functions, can be embodied in any computer-readable medium for use by or in connection with an instruction execution system, apparatus, or device, such as a computer-based system, processor-containing system, or other system that can fetch the instructions from the instruction execution system, apparatus, or device and execute the instructions. For the purposes of this description, a "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device.
More specific examples (a non-exhaustive list) of the computer-readable medium would include the following: an electrical connection (electronic device) having one or more wires, a portable computer diskette (magnetic device), a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disc read-only memory (CDROM). Additionally, the computer-readable medium could even be paper or another suitable medium upon which the program is printed, as the program can be electronically captured, via for instance optical scanning of the paper or other medium, then compiled, interpreted or otherwise processed in a suitable manner if necessary, and then stored in a computer memory.
It should be understood that portions of the present invention may be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, the various steps or methods may be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, any one or combination of the following techniques, which are known in the art, may be used: a discrete logic circuit having a logic gate circuit for implementing a logic function on a data signal, an application specific integrated circuit having an appropriate combinational logic gate circuit, a Programmable Gate Array (PGA), a Field Programmable Gate Array (FPGA), or the like.
In the description herein, references to the description of the term "one embodiment," "some embodiments," "an example," "a specific example," or "some examples," etc., mean that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the invention. In this specification, the schematic representations of the terms used above do not necessarily refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.
While the preferred embodiments of the present invention have been illustrated and described, it will be understood by those skilled in the art that various changes in form and details may be made therein without departing from the spirit and scope of the invention as defined by the appended claims.