CN112559394B - System library access method and device and electronic equipment - Google Patents

System library access method and device and electronic equipment Download PDF

Info

Publication number
CN112559394B
CN112559394B CN202011398970.3A CN202011398970A CN112559394B CN 112559394 B CN112559394 B CN 112559394B CN 202011398970 A CN202011398970 A CN 202011398970A CN 112559394 B CN112559394 B CN 112559394B
Authority
CN
China
Prior art keywords
address
system library
instruction
function
main call
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202011398970.3A
Other languages
Chinese (zh)
Other versions
CN112559394A (en
Inventor
朴英敏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Douyin Vision Co Ltd
Original Assignee
Douyin Vision Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Douyin Vision Co Ltd filed Critical Douyin Vision Co Ltd
Priority to CN202011398970.3A priority Critical patent/CN112559394B/en
Publication of CN112559394A publication Critical patent/CN112559394A/en
Application granted granted Critical
Publication of CN112559394B publication Critical patent/CN112559394B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/25Integrating or interfacing systems involving database management systems
    • G06F16/252Integrating or interfacing systems involving database management systems between a Database Management System and a front-end application
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/14Protection against unauthorised use of memory or access to memory
    • G06F12/1458Protection against unauthorised use of memory or access to memory by checking the subject access rights
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Computer Security & Cryptography (AREA)
  • Storage Device Security (AREA)

Abstract

The disclosure provides a system library access method, a system library access device and electronic equipment. The method comprises the following steps: when an access instruction aiming at a system library is detected, a main call function is operated, and the main call function is used for jumping to a called function; running a called function, and executing the following operations through the called function: acquiring an address of a preconfigured connection register; the address of the connection register is the address of the system library area; acquiring access rights of a system library based on the address of the connection register; accessing a system library area corresponding to the address of the connection register based on the access right, and acquiring a prestored target instruction from the system library area; determining a return address of the called function based on the target instruction; based on the return address, the running master function is returned from the called function. The method and the device can ensure normal operation of the major function after accessing the system library.

Description

System library access method and device and electronic equipment
Technical Field
The disclosure relates to the technical field of computers, and in particular relates to a system library access method, a system library access device and electronic equipment.
Background
Many optimizations and debuggers in the development process of the application program need to depend on the system library, so the application program often calls a function to access the system library, but not all application programs have the access right to the system library, and for the application program without the access right to the system library, the application program needs to access the system library in a special mode.
At present, an application program without access authority to a system library can conveniently and freely access the system library by configuring an address of a connection register (LR) in a called function which is mobilized, wherein the address of the connection register configured in this way is generally an address of a data segment, and the address of the connection register also indicates an execution position of a main call function when the called function returns to run the main call function, so that the address of the connection register in the current scheme indicates a data segment according to which the application program cannot normally return to run the main call function, and the operation of the main call function is abnormal.
Disclosure of Invention
This summary is provided to introduce a selection of concepts in a simplified form that are further described below in the detailed description. This summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter.
A first aspect of the present disclosure provides a system library access method, including:
when an access instruction aiming at a system library is detected, a main call function is operated, and the main call function is used for jumping to a called function;
Running a called function, and executing the following operations through the called function: acquiring an address of a preconfigured connection register; the address of the connection register is the address of the system library area; acquiring access rights of a system library based on the address of the connection register; accessing a system library area corresponding to the address of the connection register based on the access right, and acquiring a prestored target instruction from the system library area;
determining a return address of the called function based on the target instruction;
based on the return address, the running master function is returned from the called function.
A second aspect of the present disclosure provides an access device for a system library, including:
the first operation module is used for operating a main call function when an access instruction aiming at the system library is detected, wherein the main call function is used for jumping to a called function;
the second operation module is used for operating the called function, and the following operations are executed through the called function: acquiring an address of a preconfigured connection register; the address of the connection register is the address of the system library area; acquiring access rights of a system library based on the address of the connection register; accessing a system library area corresponding to the address of the connection register based on the access right, and acquiring a prestored target instruction from the system library area;
A first determining module for determining a return address of the called function based on the target instruction;
and the third operation module is used for returning to operate the main call function from the called function based on the return address.
In a third aspect of the present disclosure, there is provided an electronic device including:
the electronic device includes a memory and a processor;
a memory having a computer program stored therein;
a processor for performing the method of the first aspect when the computer program is run.
In a fourth aspect of the present disclosure, there is provided a computer readable medium having stored thereon a computer program which when executed by a processor performs the method of the first aspect.
The beneficial effects that this disclosure provided technical scheme brought are:
in this embodiment, when an access instruction to the system library is detected, a master function may be executed, which is used to jump to a tuned function, so that a tuned function may be executed, through which the following operations may be performed: acquiring an address of a preconfigured connection register; acquiring access rights of a system library based on the address of the connection register; based on the access authority to access the system library area corresponding to the address of the connection register, the method and the device can realize free access to the system library through the address of the preconfigured connection register, meanwhile, the method and the device can acquire a prestored target instruction from the system library area corresponding to the address of the connection register, and based on the target instruction, the return address of the modulated function can be determined, so that the modulated function can be returned to operate the main modulation function based on the return address, and compared with the prior scheme, after the method and the device access the system library, the main modulation function can be returned to operate the main modulation function based on the return address, so that the normal operation of the main modulation function is ensured, and the abnormal and other conditions of SIGSEGV are avoided.
Drawings
The above and other features, advantages, and aspects of embodiments of the present disclosure will become more apparent by reference to the following detailed description when taken in conjunction with the accompanying drawings. The same or similar reference numbers will be used throughout the drawings to refer to the same or like elements. It should be understood that the figures are schematic and that elements and components are not necessarily drawn to scale.
FIG. 1 is a schematic diagram of one embodiment of a system library access method of the present disclosure;
FIG. 2 is a schematic diagram of an instruction execution flow of the present disclosure;
FIG. 3 is an indication of pointers in a stack of the present disclosure;
FIG. 4 is a schematic diagram of another embodiment of a system library access method of the present disclosure;
FIG. 5 is a schematic diagram of a system library access device of the present disclosure;
fig. 6 is a schematic structural diagram of an electronic device of the present disclosure.
Detailed Description
Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While certain embodiments of the present disclosure have been shown in the accompanying drawings, it is to be understood that the present disclosure may be embodied in various forms and should not be construed as limited to the embodiments set forth herein, but are provided to provide a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are for illustration purposes only and are not intended to limit the scope of the present disclosure.
It should be understood that the various steps recited in the method embodiments of the present disclosure may be performed in a different order and/or performed in parallel. Furthermore, method embodiments may include additional steps and/or omit performing the illustrated steps. The scope of the present disclosure is not limited in this respect.
The term "including" and variations thereof as used herein are intended to be open-ended, i.e., including, but not limited to. The term "based on" is based at least in part on. The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments. Related definitions of other terms will be given in the description below.
It should be noted that the terms "first," "second," and the like in this disclosure are used merely to distinguish one from another device, module, or unit, and are not intended to limit the device, module, or unit to the particular device, module, or unit or to limit the order or interdependence of functions performed by the devices, modules, or units.
It should be noted that references to "one", "a plurality" and "a plurality" in this disclosure are intended to be illustrative rather than limiting, and those of ordinary skill in the art will appreciate that "one or more" is intended to be understood as "one or more" unless the context clearly indicates otherwise.
The names of messages or information interacted between the various devices in the embodiments of the present disclosure are for illustrative purposes only and are not intended to limit the scope of such messages or information.
In the following, several technical terms referred to in the present disclosure will be explained first.
The system library, which may also be referred to as a dynamic link library or so dynamic library, is a dynamic library in the Linux system.
The address of the connection register, i.e., the R14 register, of the present disclosure has two roles: 1. return address as a function of the call. When the main call function calls the called function, the return address of the called function is stored in an R14 register, and when the main call function is returned, the return of the called function can be realized by assigning the address in the R14 register to a PC (program counter). 2. An object used to indicate access to a system library may indicate, for example, whether an application call called function accessed the system library or whether other objects (e.g., system library) call called functions accessed the system library.
In this embodiment, the address of a certain register indicates an address stored in the register, and assigning a certain address to the register indicates storing the address in the register.
The address of the program register is the address of the next instruction to be executed, for example, the first instruction is in the execution stage, the second instruction is in the decoding stage, and the third instruction is in the instruction fetching stage, and the address of the program register points to the third instruction when the first instruction is executed.
As described above, after the system library is accessed by configuring the address of the connection register in the existing solution, because the address of the connection register is the address of a data segment, the normal operation of the master function cannot be returned from the tuned function based on the data segment, which may cause abnormal operation of the master function and trigger the phenomena such as SIGSEGV abnormality, etc., in order to solve the above technical problem, please refer to fig. 1, the disclosure provides a system library access method, which may be executed by a terminal device, specifically by an application program on the terminal device, and specifically includes the following steps:
step S101, when an access instruction aiming at a system library is detected, a main call function is operated, and the main call function is used for jumping to a called function;
when an application detects an access instruction to a system library, a major function is run. The access instruction for the system library can be input by a user through operating the application program, can be generated by the application program, and can be sent to the application program from other modules or devices.
An application generally refers to an application without system library access rights, although an application with system library access rights may also access a system library using the system library access method of the disclosed system.
The main call function comprises a function jump instruction, the function jump instruction comprises information of a called function to be jumped to, and the function jump instruction in the main call function operated by the application program can jump to the called function. A major function refers to a function that calls other functions, and a called function refers to a called function.
Step S102, running a called function, and executing the following operations through the called function: acquiring an address of a preconfigured connection register; the address of the connection register is the address of the system library area; acquiring access rights of a system library based on the address of the connection register; accessing a system library area corresponding to the address of the connection register based on the access right, and acquiring a prestored target instruction from the system library area;
after the application program jumps to the called function, starting to run the called function, and the application program runs the called function to execute the following operations:
as described above, the address of the connection register may indicate an object accessing the system library, then:
The application program running the called function can obtain the address of the preconfigured connection register, and the address of the preconfigured connection register is preconfigured by the following modes: the application program determines the address of the system library area and takes the address of the system library area as the address of the connection register.
In this embodiment, the system library includes a plurality of libraries (the system library area belongs to one of the plurality of libraries, that is, the system library area is a partial area of the system library), each library has an address space mapped thereto, and the address of the system library area is within the address space range corresponding to the system library area, so it is seen that, because the system library area is a part of the system library, the address of the system library area is an address that allows access to the system library.
After the address of the connection register is obtained, the application program can send the address of the connection register to the system library by running the called function, so that the system library can grant the application program access to the system library based on the address of the connection register.
After the access right of the system library is obtained, the application program can access the system library based on the access right by running the tuned function. The application program accesses the system library specifically as follows: the application program accesses the system library area corresponding to the address based on the address of the connection register.
It can be seen that, in this embodiment, if the application program does not have the access authority of the system library, the address of the connection register may be configured to be the address of the system library region through pre-configuring the address of the connection register, so that the application program may access the system library based on the address of the pre-configured connection register, and the application program without the access authority of the system library may break through the limitation of the access authority of the system library and freely access the system library.
As described above, the address of the connection register may also indicate the return address of the called function, then:
in this embodiment, the connection register address points to the system library area, and the system library area is not an executable instruction as the data segment in the existing scheme, so that the host call function can still normally operate after the application program accesses the system library, and the target instruction can be prestored in the system library area, so that the application program can acquire the target instruction from the system library area after accessing the system library area, and the application program can jump to execute the target instruction.
In this embodiment, the modulated function may be a dlopen or dlsym function.
Step S103, determining the return address of the called function based on the target instruction;
Based on the target instruction, the application may determine a return address for the called function.
In this embodiment, the return address indicates the address of an instruction that continues to execute a position in the main call function when the main call function is returned to run after the execution of the called function is skipped from the main call function.
Step S104, returning the operation main call function from the called function based on the return address so that the operation main call function can be normally operated after the operation called function accesses the system library.
When the application program returns to run the main call function from the called function based on the return address, the main call function can be continuously run downwards from the instruction corresponding to the return address in the main call function, so that the application program can still normally run the main call function after the system library is accessed by the run called function.
It can be seen that in this embodiment, when an access instruction to the system library is detected, a main call function may be executed, and the main call function is used to jump to a called function, so that the called function may be executed, and the following operations may be executed by the called function: acquiring an address of a preconfigured connection register; acquiring access rights of a system library based on the address of the connection register; based on the access authority to access the system library area corresponding to the address of the connection register, the method and the device can realize free access to the system library through the address of the preconfigured connection register, meanwhile, the method and the device can acquire a prestored target instruction from the system library area corresponding to the address of the connection register, and based on the target instruction, the return address of the modulated function can be determined, so that the modulated function can be returned to operate the main modulation function based on the return address, and compared with the prior scheme, after the method and the device access the system library, the main modulation function can be returned to operate the main modulation function based on the return address, so that the normal operation of the main modulation function is ensured, and the abnormal and other conditions of SIGSEGV are avoided.
It can be seen that, in this embodiment, the addresses of the continuous registers may not only point to the system library area to facilitate the application program accessing the system library, but also store legal instructions, such as the above-mentioned target instructions, in the system library area, so that the main call function can be continuously operated at the instruction corresponding to the return address in the main call function based on the jump of the target instructions.
Therefore, the scheme of the embodiment can avoid the phenomena of SIGSEGV abnormality and the like.
Optionally, step S102 accesses, through the tuned function, a system library area corresponding to the address of the connection register based on the access right, including:
assigning the address of the connection register to the program register by the called function so as to take the address of the connection register as the address of the program register;
based on the access authority, accessing the system library area corresponding to the address according to the address of the program register.
In this embodiment, when the called function runs to the last instruction, the instruction means: and assigning an address of a connection register to a program register, wherein the last instruction can be assigned to the program register by the called function, the address of the connection register is used as the address of the program register, if the program register is used for storing the address of the next instruction to be executed of the current instruction (namely the last instruction), after the last instruction is executed, the application program can access a system library area corresponding to the address based on the address of the program register, obtain a prestored target instruction from the area, and execute the target instruction.
Optionally, step S101 runs a major function, which may include:
executing a push instruction in the main call function, and pushing a first instruction address in the push instruction to a stack; the first instruction address is an address corresponding to an instruction of a continuous execution position in the main call function when the main call function is returned from the called function to continue execution;
the target instruction includes a pop instruction, and step S103 determines, based on the target instruction, a return address of the called function, including:
and executing the pop instruction, acquiring a first instruction address from the stack, and taking the first instruction address as a return address.
In this embodiment, the main call function further includes a push instruction, and the push instruction is configured with a program register, where the program register stores a first instruction address, and then the application program runs the push instruction in the main call function, and may obtain the first instruction address stored in the program register and push the first instruction address to the stack.
It should be noted that the first instruction address stored in the program register points to the address of the instruction to be executed next to the current push instruction, that is, the address of the instruction at the execution continuing position in the main function when the main function is returned from the called function to run, and the first instruction address is actually the return address.
In this embodiment, after the target instruction is obtained from the system library area, the target instruction may be a pop instruction, the pop instruction is executed, the first instruction address may be taken out from the stack, and the first instruction address is assigned to the program register, so that the instruction corresponding to the first instruction address may be used as the instruction to be executed next after the pop instruction is executed, and the application program jumps to the instruction corresponding to the first instruction address after the pop instruction is executed, which is equivalent to returning the main call function, and may continue to execute the main call function from the instruction corresponding to the first instruction address in the main call function.
Optionally, the address of the pre-configured connection register is pre-configured by a master function.
In this embodiment, the main call function further includes an address configuration instruction, where the application program runs a connection register address configuration instruction in the main call function, and may assign an address of a system library area to a connection register as an address of the connection register, so that a subsequent called function may directly obtain an address of the connection register preconfigured by the main call function.
As shown in fig. 2, in the present application, the instruction execution flow chart of the main call function includes an initial instruction, an address configuration instruction, a push instruction, a function jump instruction and an instruction corresponding to a first instruction address, and the execution operation sequence of the instructions in the main call function is as follows:
After the main program starts to run, firstly, an initial instruction is run for initialization;
the main function runs to an address configuration instruction, and the address of the system library area is configured as the address of the connection register;
the main call function operates to a push instruction to acquire an address in a first program register, wherein the address in the first program register points to the address added with 8 bytes of the current instruction address, the current instruction address is the address of the push instruction, and the address added with 8 bytes is the first instruction address;
the method comprises the steps that a main calling function is operated to a function jump instruction, an application program jumps from the operation of the main calling function to the operation of a called function, the operation of the called function can firstly acquire the access right of a system library based on the address of a connection register to realize free access to the system library, when the last instruction of the called function is operated, the address in the connection register can be assigned to a program register, so that after the application program executes the last instruction of the called function, a pop instruction can be acquired from the system library area corresponding to the address in the connection register, and the pop instruction is executed;
the application program executing pop instruction can take out the first instruction address from the stack and assign the first instruction address to the program register, so that the application program executing the instruction corresponding to the first instruction address after the pop instruction is executed is completed, and the main function can be returned to run from the tuned function, and meanwhile, the main function can be normally run.
Fig. 3 is a case of pointer indication during instruction operation, where the initial instruction, the tuned function, and the stack top position during instruction operation corresponding to the first instruction address are as shown in fig. 3, and it needs to be emphasized that, when the instruction is operated to the push instruction, the addresses written in the stack are two words (words represent word lengths), the stack top position is as shown in fig. 3, when the instruction is operated to the push instruction, the two words are read in the stack, and the stack top position is consistent with the position of the stack top before and after the main call function calls the tuned function, so that the first instruction address can be accurately extracted, and normal operation of the main call function can be ensured based on the first instruction address.
Optionally, in this embodiment, the system pool area specifically includes at least one of the following:
free memory space for variables in the system library;
free memory space of code segments in the system library;
code region of the system library.
The application program only needs to configure the address of the connection register to the address range corresponding to any one of a plurality of libraries contained in the system library, the system library considers that the address of the connection register points to the system library, and the system library calls the called function to access the system library, so that the system library grants the access authority of the application program to access the system library, therefore, the address of the connection register can be configured as the address corresponding to a system library area, and the system library area comprises at least one possible condition:
The system library comprises a variable, the variable can be a global variable, the variable comprises a free storage space, and the system library area can be the free storage space in the variable;
the system library also comprises a code section, the code section is page-aligned and has a plurality of free storage spaces, and the free storage spaces are generally at the end positions of the code section, so that the system library area can also be the free storage spaces at the end positions of the code section;
the system library region may also be a code region in the system library, which refers to a region in which a large amount of code is stored.
The target instruction is obtained from the system library area, namely the machine code (i.e. the code) of the target instruction is obtained, if the system library area is the code area in the system library, the code area itself comprises the machine code of a plurality of instructions, and an application program can directly scan the code area of the system library to find the machine code of the target instruction, so that the target instruction does not need to be written in the system library area in advance.
If the system library area is the free storage space of the variables in the system library or the free storage space of the end positions of the code segments in the system library, the application program also needs to write the target instruction (i.e. the machine code of the target instruction) into the system library area before accessing the system library, specifically:
Step S102, before obtaining the pre-stored target instruction from the system library area through the tuned function, the method may further include:
determining a system library region from the system library based on the address of the system library region;
adjusting the system library area from a read-only mode to a writable mode;
writing the target instruction into a system library area;
the attributes of the system library regions are adapted to be executable programs to facilitate retrieval of target instructions from the system library regions.
In this embodiment, the application program may determine the address of the system library area, so that the system library area in the system library may be determined based on the address of the system library area, the application program may adjust the system library area from a read-only mode to a writable mode, so that the target instruction is written into the system library area, and the application program may also need to adjust the attribute of the system library area to be an executable program, so that the subsequent application program may only acquire the target instruction from the system library area.
If the system library area is the free storage space of the variable, then: the application may determine that the address of the system library region is determined by parsing the ELF (executable and linkable format, executable and linkable format,) file structure; writing the target instruction into the system library region includes: writing a machine code of a target instruction in the last word in the memory page of the variable; the adjusting of the attribute of the system library area into an executable program specifically comprises: the application program calls the mpprotect function to set the accessible authority of the memory page of the variable, and the ID of the application program is added into the accessible list of the memory page.
Optionally, step S103 returns the running master function from the tuned function based on the return address, including:
determining an instruction corresponding to the return address in the main call function;
returning the main call function from the called function, and running the main call function from the instruction of the main call function.
In this embodiment, the return address points to a certain instruction in the main call function, and the application program can determine the instruction corresponding to the return address in the main call function, so that when the main call function is returned to run from the called function, the main call function can be continuously run from the instruction, and the main function can be normally run.
In summary, referring to fig. 4, the execution flow of the system library access method of the present disclosure is as follows:
s1, starting to run a master function when an access instruction aiming at a system library is detected;
s2, the application program runs a connection register configuration instruction in the master function, and assigns an address corresponding to the system library area to the connection register;
s3, the application program runs a push instruction in the main call function, and pushes the first instruction address to a stack;
s4, the application program runs a function call instruction in the main call function and jumps to the called function;
s5, the application program runs the tuned function, obtains the address of the connection register configured in the main tuning function through the tuned function, and sends the address of the connection register to the system library;
S6, the system library determines that the address of the connection register is the address of a system library area, and the system library grants access rights to the application program;
the system library would be considered to be a system library region call called function to access the system library based on the address of the connection register, and the application would be granted access to the system library instead of the application calling the called function.
S7, the application program can access the system library based on the access authority, and meanwhile, the value of the connection register is assigned to the program register by running the last instruction in the called function, so that the application program can acquire a prestored pop instruction from the system library area corresponding to the address of the connection register and jump to the pop instruction.
S8, the application program executes a pop instruction, a first instruction address is obtained from the stack, and the first instruction address is assigned to a program register so as to take the first instruction address as a return address;
the first instruction address is assigned to the program register, and the application program can jump to execute the instruction corresponding to the first instruction address after the application program executes the pop instruction, and then the first instruction address is used as the return address of the called function.
S9: and returning to an instruction corresponding to the return address in the operation main call function to continue to operate the main call function.
The scheme of this embodiment is substantially the same as the scheme of the embodiment shown in fig. 1, and the specific implementation manner thereof may be shown with reference to fig. 1, and will not be described herein.
Referring to fig. 5, the present disclosure further provides an access device for a system library, including:
a first operation module 501, configured to operate a main call function when an access instruction to a system library is detected, where the main call function is used to jump to a called function;
the second operation module 502 is configured to operate a tuned function, and perform the following operations through the tuned function: acquiring an address of a preconfigured connection register; the address of the connection register is the address of the system library area; acquiring access rights of a system library based on the address of the connection register; accessing a system library area corresponding to the address of the connection register based on the access right, and acquiring a prestored target instruction from the system library area;
a first determining module 503, configured to determine a return address of the called function based on the target instruction;
a third operation module 504 is configured to return an operation master function from the tuned function based on the return address.
Optionally, the first operation module 501 is specifically configured to:
executing a push instruction in the main call function, and pushing a first instruction address in the push instruction to a stack; the first instruction address is an address corresponding to an instruction of a continuous execution position in the main call function when the main call function is returned from the called function to continue execution;
The target instruction includes a pop instruction, and the first determining module 503 is specifically configured to:
and executing the pop instruction, acquiring a first instruction address from the stack, and taking the first instruction address as a return address.
Optionally, when accessing, by the tuned function, the system library area corresponding to the address of the connection register based on the access right, the second operation module 502 is specifically configured to:
assigning the address of the connection register to the program register by the called function so as to take the address of the connection register as the address of the program register;
based on the access authority, accessing the system library area corresponding to the address according to the address of the program register.
Optionally, the device further comprises a second determining module, a first adjusting module, a data writing module and a second adjusting module; before the second running module 502 obtains the pre-stored target instruction from the system library area through the tuned function;
the second determining module is used for determining the system library area from the system library based on the address of the system library area;
the first adjusting module is used for adjusting the system library area from a read-only mode to a writable mode;
the data writing module is used for writing the target instruction into the system library area;
And the second adjusting module is used for adjusting the attribute of the system library area into an executable program so as to obtain the target instruction from the system library area.
Optionally, the system pool area specifically includes at least one of the following:
free memory space for variables in the system library;
free memory space of code segments in the system library;
code region of the system library.
Optionally, the third operation module 504 is specifically configured to:
determining an instruction corresponding to the return address in the main call function;
returning the main call function from the called function, and running the main call function from the instruction of the main call function.
Referring now to fig. 6, a schematic diagram of an electronic device (e.g., the terminal device of fig. 1) 600 suitable for use in implementing embodiments of the present disclosure is shown. The terminal devices in the embodiments of the present disclosure may include, but are not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and the like, and stationary terminals such as digital TVs, desktop computers, and the like. The electronic device shown in fig. 6 is merely an example and should not be construed to limit the functionality and scope of use of the disclosed embodiments.
An electronic device includes: a memory and a processor, where the processor may be referred to as a processing device 601 hereinafter, the memory may include at least one of a Read Only Memory (ROM) 602, a Random Access Memory (RAM) 603, and a storage device 608 hereinafter, as shown in detail below:
as shown in fig. 6, the electronic device 600 may include a processing means (e.g., a central processing unit, a graphics processor, etc.) 601, which may perform various suitable actions and processes according to a program stored in a Read Only Memory (ROM) 602 or a program loaded from a storage means 606 to a Random Access Memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the electronic apparatus 600 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other through a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
In general, the following devices may be connected to the I/O interface 605: input devices 606 including, for example, a touch screen, touchpad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, and the like; an output device 607 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage 606 includes storage 608, e.g., magnetic tape, hard disk, etc.; and a communication device 609. The communication means 609 may allow the electronic device 600 to communicate with other devices wirelessly or by wire to exchange data. While fig. 6 shows an electronic device 600 having various means, it is to be understood that not all of the illustrated means are required to be implemented or provided. More or fewer devices may be implemented or provided instead.
In particular, according to embodiments of the present disclosure, the processes described above with reference to flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a non-transitory computer readable medium, the computer program comprising program code for performing the method shown in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication device 609, or from the storage device 606608, or from the ROM 602. The above-described functions defined in the methods of the embodiments of the present disclosure are performed when the computer program is executed by the processing device 601.
It should be noted that the computer readable medium described in the present disclosure may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this disclosure, a computer-readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present disclosure, however, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with the computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, fiber optic cables, RF (radio frequency), and the like, or any suitable combination of the foregoing.
In some implementations, the clients, servers may communicate using any currently known or future developed network protocol, such as HTTP (HyperText Transfer Protocol ), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), the internet (e.g., the internet), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future developed networks.
The computer readable medium may be contained in the electronic device; or may exist alone without being incorporated into the electronic device.
The computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: when an access instruction aiming at a system library is detected, a main call function is operated, and the main call function is used for jumping to a called function; running a called function, and executing the following operations through the called function: acquiring an address of a preconfigured connection register; the address of the connection register is the address of the system library area; acquiring access rights of a system library based on the address of the connection register; accessing a system library area corresponding to the address of the connection register based on the access right, and acquiring a prestored target instruction from the system library area; determining a return address of the called function based on the target instruction; based on the return address, the running master function is returned from the called function.
Computer program code for carrying out operations of the present disclosure may be written in one or more programming languages, including, but not limited to, an object oriented programming language such as Java, smalltalk, C ++ and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computer (for example, through the Internet using an Internet service provider).
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. 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 involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules or units involved in the embodiments of the present disclosure may be implemented by means of software, or may be implemented by means of hardware. The name of a module or unit is not limited to the unit itself in some cases, and for example, the first execution module may be also described as "a module that executes a host function when an access instruction to a system library is detected".
The functions described above herein may be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: a Field Programmable Gate Array (FPGA), an Application Specific Integrated Circuit (ASIC), an Application Specific Standard Product (ASSP), a system on a chip (SOC), a Complex Programmable Logic Device (CPLD), and the like.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. The machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
According to one or more embodiments of the present disclosure, there is provided a system library access method including:
when an access instruction aiming at a system library is detected, a main call function is operated, and the main call function is used for jumping to a called function;
running a called function, and executing the following operations through the called function: acquiring an address of a preconfigured connection register; the address of the connection register is the address of the system library area; acquiring access rights of a system library based on the address of the connection register; accessing a system library area corresponding to the address of the connection register based on the access right, and acquiring a prestored target instruction from the system library area;
determining a return address of the called function based on the target instruction;
based on the return address, the running master function is returned from the called function.
Optionally, running a major function includes:
executing a push instruction in the main call function, and pushing a first instruction address in the push instruction to a stack; the first instruction address is an address corresponding to an instruction of a continuous execution position in the main call function when the main call function is returned from the called function to continue execution;
the target instruction includes a pop instruction, and determining a return address of the called function based on the target instruction includes:
And executing the pop instruction, acquiring a first instruction address from the stack, and taking the first instruction address as a return address.
Optionally, accessing, by the tuned function, a system library area corresponding to an address of the connection register based on the access right, including:
assigning the address of the connection register to the program register by the called function so as to take the address of the connection register as the address of the program register;
based on the access authority, accessing the system library area corresponding to the address according to the address of the program register.
Optionally, before the pre-stored target instruction is obtained from the system library area through the tuned function, the method further comprises:
determining a system library region from the system library based on the address of the system library region;
adjusting the system library area from a read-only mode to a writable mode;
writing the target instruction into a system library area;
the attributes of the system library regions are adapted to be executable programs to facilitate retrieval of target instructions from the system library regions.
Optionally, the system pool area specifically includes at least one of the following:
free memory space for variables in the system library;
free memory space of code segments in the system library;
code region of the system library.
Optionally, returning the running master function from the called function based on the return address includes:
determining an instruction corresponding to the return address in the main call function;
returning the main call function from the called function, and running the main call function from the instruction of the main call function.
According to one or more embodiments of the present disclosure, there is provided an access device for a system library, including:
the first operation module is used for operating a main call function when an access instruction aiming at the system library is detected, wherein the main call function is used for jumping to a called function;
the second operation module is used for operating the called function, and the following operations are executed through the called function: acquiring an address of a preconfigured connection register; the address of the connection register is the address of the system library area; acquiring access rights of a system library based on the address of the connection register; accessing a system library area corresponding to the address of the connection register based on the access right, and acquiring a prestored target instruction from the system library area;
a first determining module for determining a return address of the called function based on the target instruction;
and the third operation module is used for returning to operate the main call function from the called function based on the return address.
Optionally, the first operation module is specifically configured to:
Executing a push instruction in the main call function, and pushing a first instruction address in the push instruction to a stack; the first instruction address is an address corresponding to an instruction of a continuous execution position in the main call function when the main call function is returned from the called function to continue execution;
the target instruction comprises a pop instruction, and the first determining module is specifically configured to:
and executing the pop instruction, acquiring a first instruction address from the stack, and taking the first instruction address as a return address.
Optionally, the second operation module is specifically configured to, when accessing, through the tuned function, a system library area corresponding to an address of the connection register based on the access right:
assigning the address of the connection register to the program register by the called function so as to take the address of the connection register as the address of the program register;
based on the access authority, accessing the system library area corresponding to the address according to the address of the program register.
Optionally, the device further comprises a second determining module, a first adjusting module, a data writing module and a second adjusting module; before the second operation module obtains a prestored target instruction from a system library area through a tuned function;
the second determining module is used for determining the system library area from the system library based on the address of the system library area;
The first adjusting module is used for adjusting the system library area from a read-only mode to a writable mode;
the data writing module is used for writing the target instruction into the system library area;
and the second adjusting module is used for adjusting the attribute of the system library area into an executable program so as to obtain the target instruction from the system library area.
Optionally, the system pool area specifically includes at least one of the following:
free memory space for variables in the system library;
free memory space of code segments in the system library;
code region of the system library.
Optionally, the third operation module is specifically configured to:
determining an instruction corresponding to the return address in the main call function;
returning the main call function from the called function, and running the main call function from the instruction of the main call function.
The foregoing description is only of the preferred embodiments of the present disclosure and description of the principles of the technology being employed. It will be appreciated by persons skilled in the art that the scope of the disclosure referred to in this disclosure is not limited to the specific combinations of features described above, but also covers other embodiments which may be formed by any combination of features described above or equivalents thereof without departing from the spirit of the disclosure. Such as those described above, are mutually substituted with the technical features having similar functions disclosed in the present disclosure (but not limited thereto).
Moreover, although operations are depicted in a particular order, this should not be understood as requiring that such operations be performed in the particular order shown or in sequential order. In certain circumstances, multitasking and parallel processing may be advantageous. Likewise, while several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of the present disclosure. Certain features that are described in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features that are described in the context of a single embodiment can also be implemented in multiple embodiments separately or in any suitable subcombination.
Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are example forms of implementing the claims.

Claims (9)

1. A system library access method, comprising:
when an access instruction aiming at a system library is detected, a main call function is operated, and the main call function is used for jumping to a called function;
And running the called function, and executing the following operations through the called function: acquiring an address of a preconfigured connection register; the address of the connection register is the address corresponding to any system library region in a plurality of system library regions contained in the system library; sending the address of the connection register to the system library, and acquiring the access right of the system library based on the address of the connection register; accessing a system library area corresponding to the address of the connection register based on the access right, and acquiring a prestored target instruction from the system library area;
determining a return address of the called function based on the target instruction; wherein the return address is a first instruction address; the first instruction address is an address corresponding to an instruction of a continuous execution position in the main call function when the main call function is continuously executed from the called function;
returning to run the main call function from the called function based on the first instruction address;
wherein, before the pre-stored target instruction is obtained from the system library area through the tuned function, the method further comprises:
determining the system library region from the system library based on the address of the system library region in response to the system library region being free storage space for variables in the system library;
Adjusting the system library area from a read-only mode to a writable mode;
writing the machine code of the target instruction in the last word length in the variable memory page;
and adjusting the attribute of the system library region into an executable program so as to acquire the target instruction from the system library region.
2. The method of claim 1, wherein the running a major function comprises:
executing a push instruction in the main call function, and pushing a first instruction address in the push instruction to a stack;
the target instruction includes a pop instruction, and the determining, based on the target instruction, a return address of the called function includes:
executing the pop instruction, acquiring the first instruction address from the stack, and taking the first instruction address as the return address.
3. The method of claim 1, wherein accessing the system library region corresponding to the address of the connection register based on the access rights through the tuned function comprises:
assigning the address of the connection register to a program register through a called function so as to take the address of the connection register as the address of the program register;
Based on the access authority, accessing a system library area corresponding to the address according to the address of the program register.
4. A method according to any one of claims 1 to 3, characterized in that the system library area comprises in particular at least one of the following:
free storage space for variables in the system library;
free memory space of code segments in the system library;
code region of the system library.
5. A method according to any one of claims 1 to 3, wherein the returning from the called function to run the master function based on the return address comprises:
determining an instruction corresponding to the return address in the main call function;
returning the main call function from the called function, and running the main call function from the instruction of the main call function.
6. An access device for a system library, comprising:
the first operation module is used for operating a main call function when an access instruction aiming at the system library is detected, wherein the main call function is used for jumping to a called function;
the second operation module is used for operating the called function and executing the following operations through the called function: acquiring an address of a preconfigured connection register; the address of the connection register is the address corresponding to any system library region in a plurality of system library regions contained in the system library; sending the address of the connection register to the system library, and acquiring the access right of the system library based on the address of the connection register; accessing a system library area corresponding to the address of the connection register based on the access right, and acquiring a prestored target instruction from the system library area;
A first determining module, configured to determine a return address of the called function based on the target instruction; wherein the return address is a first instruction address; the first instruction address is an address corresponding to an instruction of a continuous execution position in the main call function when the main call function is continuously executed from the called function;
the third running module is used for returning to run the main calling function from the called function based on the first instruction address;
wherein, before the pre-stored target instruction is obtained from the system library area through the tuned function, the method further comprises:
determining the system library region from the system library based on the address of the system library region in response to the system library region being free storage space for variables in the system library;
adjusting the system library area from a read-only mode to a writable mode;
writing the machine code of the target instruction in the last word length in the variable memory page;
and adjusting the attribute of the system library region into an executable program so as to acquire the target instruction from the system library region.
7. The device according to claim 6, wherein the first operation module is specifically configured to:
Executing a push instruction in the main call function, and pushing a first instruction address in the push instruction to a stack;
the target instruction comprises a pop instruction, and the first determining module is specifically configured to:
executing the pop instruction, acquiring the first instruction address from the stack, and taking the first instruction address as the return address.
8. An electronic device, comprising:
the electronic device includes a memory and a processor;
the memory stores a computer program;
the processor being adapted to perform the method of any of claims 1-5 when the computer program is run.
9. A computer readable medium, on which a computer program is stored, characterized in that the program, when being executed by a processor, implements the method of any of claims 1-5.
CN202011398970.3A 2020-12-01 2020-12-01 System library access method and device and electronic equipment Active CN112559394B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011398970.3A CN112559394B (en) 2020-12-01 2020-12-01 System library access method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011398970.3A CN112559394B (en) 2020-12-01 2020-12-01 System library access method and device and electronic equipment

Publications (2)

Publication Number Publication Date
CN112559394A CN112559394A (en) 2021-03-26
CN112559394B true CN112559394B (en) 2024-01-12

Family

ID=75047736

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011398970.3A Active CN112559394B (en) 2020-12-01 2020-12-01 System library access method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN112559394B (en)

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109840410A (en) * 2017-12-28 2019-06-04 中国科学院计算技术研究所 The method and system of data isolation and protection in a kind of process

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050044292A1 (en) * 2003-08-19 2005-02-24 Mckeen Francis X. Method and apparatus to retain system control when a buffer overflow attack occurs
US8990546B2 (en) * 2011-10-31 2015-03-24 Freescale Semiconductor, Inc. Data processing system with safe call and return

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109840410A (en) * 2017-12-28 2019-06-04 中国科学院计算技术研究所 The method and system of data isolation and protection in a kind of process

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
赵炯.《Linux操作系统实现原理》.同济大学出版社,2018,第48-49页. *

Also Published As

Publication number Publication date
CN112559394A (en) 2021-03-26

Similar Documents

Publication Publication Date Title
CN111581563B (en) Page response method and device, storage medium and electronic equipment
CN110502357B (en) Stack backtracking method, device, medium and equipment
CN111309304B (en) Method, device, medium and electronic equipment for generating IDL file
CN111857720B (en) User interface state information generation method and device, electronic equipment and medium
CN110865846B (en) Application management method, device, terminal, system and storage medium
CN114637703B (en) Data access device, method, readable medium and electronic equipment
CN110221877B (en) Application program running method and device, electronic equipment and storage medium
CN112416303B (en) Software development kit hot repair method and device and electronic equipment
CN111783010B (en) Webpage blank page monitoring method, device, terminal and storage medium
CN110674050B (en) Memory out-of-range detection method and device, electronic equipment and computer storage medium
CN110545313B (en) Message push control method and device and electronic equipment
CN112559394B (en) System library access method and device and electronic equipment
CN113448585B (en) Compiling method and device of thread pool, electronic equipment and storage medium
CN111309323B (en) Parameter initialization method and device and electronic equipment
CN111625326B (en) Task pipeline execution method and device and electronic equipment
CN113391860B (en) Service request processing method and device, electronic equipment and computer storage medium
CN111460020B (en) Method, device, electronic equipment and medium for resolving message
CN111796865B (en) Byte code file modification method, device, terminal equipment and medium
CN111290812B (en) Display method, device, terminal and storage medium of application control
CN111240738B (en) File processing method, device, equipment and medium
CN110780898B (en) Page data upgrading method and device and electronic equipment
CN110764995B (en) Method, device, medium and electronic equipment for detecting file access abnormality
CN112306683A (en) Function hijacking method, device, medium and electronic equipment
CN112835671A (en) Application page scene switching method, device and equipment
CN112333462A (en) Live broadcast room page jumping method, returning device and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
CB02 Change of applicant information
CB02 Change of applicant information

Address after: 100041 B-0035, 2 floor, 3 building, 30 Shixing street, Shijingshan District, Beijing.

Applicant after: Douyin Vision Co.,Ltd.

Address before: 100041 B-0035, 2 floor, 3 building, 30 Shixing street, Shijingshan District, Beijing.

Applicant before: Tiktok vision (Beijing) Co.,Ltd.

Address after: 100041 B-0035, 2 floor, 3 building, 30 Shixing street, Shijingshan District, Beijing.

Applicant after: Tiktok vision (Beijing) Co.,Ltd.

Address before: 100041 B-0035, 2 floor, 3 building, 30 Shixing street, Shijingshan District, Beijing.

Applicant before: BEIJING BYTEDANCE NETWORK TECHNOLOGY Co.,Ltd.

GR01 Patent grant
GR01 Patent grant