CN110737637B - Function expansion method and device, electronic equipment and computer readable storage medium - Google Patents

Function expansion method and device, electronic equipment and computer readable storage medium Download PDF

Info

Publication number
CN110737637B
CN110737637B CN201910920216.2A CN201910920216A CN110737637B CN 110737637 B CN110737637 B CN 110737637B CN 201910920216 A CN201910920216 A CN 201910920216A CN 110737637 B CN110737637 B CN 110737637B
Authority
CN
China
Prior art keywords
function
target
target function
extended
namespace
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
CN201910920216.2A
Other languages
Chinese (zh)
Other versions
CN110737637A (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 CN201910920216.2A priority Critical patent/CN110737637B/en
Publication of CN110737637A publication Critical patent/CN110737637A/en
Application granted granted Critical
Publication of CN110737637B publication Critical patent/CN110737637B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/17Details of further file system functions
    • G06F16/1734Details of monitoring file system events, e.g. by the use of hooks, filter drivers, logs
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code

Abstract

The embodiment of the disclosure discloses a function expansion method, a device, an electronic device and a computer readable storage medium, which can improve the safety of function expansion, and comprise: when the target function is expanded, an expanded function is established in a first naming space, the name of the expanded function is the same as that of the target function, the target function is a function to be expanded, and the name of the target function is in a second naming space; in the extended function, calling a copy function of the target function, extending a calling result of the copy function of the target function, and completing method setting of the extended function, wherein the method setting of the copy function of the target function is calling of the target function, and the copy function of the target function is visible to a first name space; and when the name of the target function is read in the first naming space, executing a method set in the extended function correspondingly to realize the extension of the target function.

Description

Function expansion method and device, electronic equipment and computer readable storage medium
Technical Field
The present disclosure relates to the field of software engineering, and in particular, to a method and an apparatus for function extension, and a computer-readable storage medium.
Background
Currently, hook programming (hooking) is a technique for modifying or extending the behavior of an operating system, application program, or other software component by intercepting function calls, message passing, event passing between software modules. In hook programming, the code that handles intercepted function calls, events, messages is called a hook (hook). However, when hook programming is performed in a static language, such as the Swift language, since the memory address of the static method function in the Swift language is usually determined at the compile time, forcibly modifying the memory address for the target function to expand the memory address is likely to cause system crash, and there is a problem that the function expansion is not safe.
Disclosure of Invention
The embodiment of the disclosure provides a function expansion method and device, electronic equipment and a computer-readable storage medium.
In a first aspect, an embodiment of the present disclosure provides a function extension method, including:
when a target function is expanded, an expanded function is established in a first naming space, the name of the expanded function is the same as that of the target function, the target function is a function to be expanded, and the name of the target function is in a second naming space;
in the extended function, calling a copy function of a target function, and extending a calling result of the copy function of the target function to complete the method setting of the extended function, wherein the method setting of the copy function of the target function is calling of the target function, and the copy function of the target function is visible to the first namespace;
and when the name of the target function is read in the first namespace, correspondingly executing a method set in the extended function to realize the extension of the target function.
In the foregoing solution, when the name of the target function is read in the first namespace, the method set in the extended function is correspondingly executed to implement the extension of the target function, including:
when the name of the target function is read in the first naming space, the extended function with the same name as the target function in the first naming space is called preferentially; and executing the method for setting the extended function to obtain the execution result of the extended function, thereby realizing the extension of the target function.
In the above solution, the making a copy function of the target function visible to the first namespace includes:
creating a copy function of a target function inside the first namespace, the internally created function of the first namespace being visible to the first namespace by default.
In the above solution, the making a copy function of the target function visible to the first namespace includes:
creating a copy function of the target function in a third namespace;
the names of all functional functions contained in the third namespace are made visible to the first namespace.
In the above solution, the creating an extended function in the first namespace includes:
creating the extended function of the type of the target function in the first namespace, and naming the extended function with the name of the target function.
In the foregoing solution, the calling a copy function of a target function in the extended function, and extending a calling result of the copy function of the target function to complete the method setting of the extended function, includes:
calling a copy function of the target function in the method for expanding the function to obtain a return result of the copy function of the target function;
and continuously executing a preset method on the return result of the copy function of the target function to complete the expansion of the running result of the copy function of the target function, wherein the preset method is a method preset for achieving the expansion target on the basis of the return result of the copy function of the target function.
In the above solution, the creating the extended function of the type of the target function in the first namespace includes:
extending the type of the target function in the form of extension;
and adding the extended function in the function contained in the type of the target function.
In a second aspect, an embodiment of the present disclosure provides a function extension apparatus, including a creating unit, a calling unit, and an executing unit, where:
the creating unit is configured to create an extended function in a first namespace when a target function is extended, where a name of the extended function is the same as a name of the target function, the target function is a function to be extended, and the name of the target function is in a second namespace;
the calling unit is used for calling a copy function of a target function in the extended function, expanding a calling result of the copy function of the target function and completing the method setting of the extended function, wherein the method setting of the copy function of the target function is calling of the target function, and the copy function of the target function is visible to the first namespace;
and the execution unit is used for correspondingly executing the method set in the extended function when the name of the target function is read in the first namespace so as to realize the extension of the target function.
In the foregoing solution, the extension unit is specifically configured to, when the name of the target function is read in the first namespace, preferentially call the extended function having the same name as the target function in the first namespace; and executing the method for setting the extended function to obtain the execution result of the extended function, thereby realizing the extension of the target function.
In the foregoing solution, the calling unit is specifically configured to create a copy function of the target function inside the first namespace, where the function created inside the first namespace is visible to the first namespace by default.
In the foregoing solution, the calling unit is specifically configured to create a copy function of the target function in a third namespace; the names of all functional functions contained in the third namespace are made visible to the first namespace.
In the foregoing solution, the creating unit is specifically configured to create the extended function of the type of the target function in the first namespace, and name the extended function by using a name of the target function.
In the foregoing solution, the calling unit is specifically configured to call a copy function of the target function in the method for extending a function, so as to obtain a return result of the copy function of the target function; and continuously executing a preset method on the return result of the copy function of the target function to complete the expansion of the running result of the copy function of the target function, wherein the preset method is a method preset for achieving the expansion target on the basis of the return result of the copy function of the target function.
In the foregoing solution, the creating unit is specifically configured to extend the type of the target function in the form of extension; and adding the extended function in the function contained in the type of the target function.
In a third aspect, an embodiment of the present disclosure provides an electronic device, including: a processor, a memory and a communication bus, the memory communicating with the processor through the communication bus, the memory storing one or more programs executable by the processor, the processor performing the function expansion method as in any one of the above when the one or more programs are executed.
In a fourth aspect, the disclosed embodiments provide a computer-readable storage medium storing one or more programs, the one or more programs being executable by one or more processors to implement the function expansion method as described in any one of the above.
The embodiment of the disclosure has the following beneficial effects:
when the function extension device calls the name of the target function in the first name space, the method set in the extension function with the same name as the target function in the first name space is actually called, in the method setting of the extension function, the copy function of the target function is called, and the return result of the copy function of the target function is extended and modified, so that the target function is extended on the basis of not changing the memory address of the target function, and the safety of function extension is improved.
Drawings
The above and other features, advantages and aspects of various embodiments of the present disclosure will become more apparent by referring to the following detailed description when taken in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numbers refer to the same or similar elements. It should be understood that the drawings are schematic and that elements and features are not necessarily drawn to scale.
Fig. 1 is a schematic structural diagram of an electronic device 100 implementing an embodiment of the present disclosure;
FIG. 2 is a schematic diagram of an alternative structure of a function expanding device 200 according to an embodiment of the disclosure;
fig. 3 is a first alternative flow chart of the function expansion method according to the embodiment of the present disclosure;
fig. 4 is a second optional flowchart of the function expansion method according to the embodiment of the 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 are shown in the 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 rather are provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the disclosure are for illustration purposes only and are not intended to limit the scope of the disclosure.
It should be understood that the various steps recited in method embodiments of the present disclosure may be performed in a different order, and/or performed in parallel. Moreover, 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 "include" and variations thereof as used herein are 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". Relevant definitions for other terms will be given in the following description.
It should be noted that the terms "first", "second", and the like in the present disclosure are only used for distinguishing different devices, modules or units, and are not used for limiting the order or interdependence of the functions performed by the devices, modules or units.
It is noted that references to "a" or "an" in this disclosure are intended to be illustrative rather than limiting, and that those skilled in the art will appreciate that references to "one or more" are intended to be exemplary and not limiting unless the context clearly indicates otherwise.
The names of messages or information exchanged between devices in the embodiments of the present disclosure are for illustrative purposes only, and are not intended to limit the scope of the messages or information.
Referring now to fig. 1, fig. 1 is a schematic diagram of an electronic device 100 implementing an embodiment of the present disclosure. The electronic device may be various terminals including a mobile terminal such as a mobile phone, a notebook computer, a Digital broadcast receiver, a Personal Digital Assistant (PDA), a tablet computer (PAD), a Portable Multimedia Player (PMP), a vehicle mounted terminal (e.g., a car navigation terminal), etc., and a fixed terminal such as a Digital Television (TV), a desktop computer, etc. The electronic device shown in fig. 1 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 1, the electronic device 100 may include a processing device (e.g., a central processing unit, a graphics processor, etc.) 110, which may perform various suitable actions and processes according to a program stored in a Read-Only Memory (ROM) 120 or a program loaded from a storage device 180 into a Random Access Memory (RAM) 130. In the RAM 130, various programs and data necessary for the operation of the electronic apparatus 100 are also stored. The processing device 110, the ROM 120, and the RAM 130 are connected to each other through a bus 140. An Input/Output (I/O) interface 150 is also connected to bus 140.
Generally, the following devices may be connected to the I/O interface 150: input devices 160 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; an output device 170 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; a storage device 180 including, for example, a magnetic tape, a hard disk, or the like; and a communication device 190. The communication device 190 may allow the electronic device 100 to communicate wirelessly or by wire with other devices to exchange data. While fig. 1 illustrates an electronic device 100 having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided.
In particular, the processes described by the provided flowcharts may be implemented as computer software programs according to embodiments of the present disclosure. For example, the disclosed embodiments include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication device 190, or installed from the storage device 180, or installed from the ROM 120. The computer program, when executed by the processing device 110, performs the functions in the methods of the embodiments of the present disclosure.
It should be noted that the computer readable medium described above in the embodiments of the present disclosure may be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may include, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination 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 RAM, a ROM, an Erasable Programmable Read-Only Memory (EPROM), a 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 disclosed embodiments, 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 contrast, in the disclosed embodiments, a computer readable signal medium may comprise a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may 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 electrical wiring, fiber optic cable, radio Frequency (RF), etc., or any suitable combination of the preceding.
The computer readable medium may be included in the electronic device 100; or may be separate and not incorporated into the electronic device 100.
The computer readable medium carries one or more programs, which when executed by the electronic device 100, cause the electronic device to perform the function expansion method provided by the embodiment of the present disclosure.
Computer program code for carrying out operations for embodiments of the present disclosure may be written in any combination of one or more programming languages, including 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 type of Network, including a Local Area Network (LAN) and a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams provided by the embodiments of the present disclosure 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 units described in the embodiments of the present disclosure may be implemented by software or hardware. Where the name of a unit does not in some cases constitute a definition of the unit itself, for example, a create unit may also be described as a "unit that creates an extended function within a first namespace".
The functions described in the embodiments of the present disclosure 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: field-Programmable Gate arrays (FPGAs), application Specific Integrated Circuits (ASICs), application Specific Standard Parts (ASSPs)), systems on a chip (SOCs), complex Programmable Logic Devices (CPLDs), and the like.
In the context of embodiments of the present 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. A 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 compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
The following provides units and/or modules in the function expanding device in combination with the disclosed embodiment. It is understood that the units or modules in the function expansion apparatus can be implemented in the electronic device shown in fig. 1 by using software (for example, the computer program stored in the computer software program) and can also be implemented in the electronic device shown in fig. 1 by using the hardware logic components (for example, FPG a, ASIC, ASSP, SOC, and CPLD) described above.
Referring to fig. 2, fig. 2 is an alternative structural diagram of a function expanding device 200 for implementing the embodiment of the disclosure, and illustrates the following modules:
a creation unit 210, a calling unit 220, and an execution unit 230, wherein,
the creating unit 210 is configured to create an extended function in a first namespace when a target function is extended, where a name of the extended function is the same as a name of the target function, the target function is a function to be extended, and the name of the target function is in a second namespace;
the calling unit 220 is configured to call a copy function of a target function in the extended function, and expand a calling result of the copy function of the target function to complete method setting of the extended function, where the method setting of the copy function of the target function is call of the target function, and the copy function of the target function is visible to the first namespace;
the executing unit 230 is configured to, when the name of the target function is read in the first namespace, correspondingly execute the method set in the extended function, so as to implement extension of the target function.
In the above solution, the executing unit 230 is specifically configured to, when the name of the target function is read in the first namespace, preferentially call the extended function having the same name as the target function in the first namespace; and executing the method for setting the extended function to obtain the execution result of the extended function, thereby realizing the extension of the target function.
In the foregoing solution, the invoking unit 220 is specifically configured to create a copy function of the target function inside the first namespace, where the function created inside the first namespace is visible to the first namespace by default.
In the foregoing solution, the invoking unit 220 is specifically configured to create a copy function of the target function in the third namespace; the names of all functional functions contained in the third namespace are made visible to the first namespace.
In the foregoing solution, the creating unit 210 is specifically configured to create the extended function of the type of the target function in the first namespace, and name the extended function by using the name of the target function.
In the foregoing solution, the invoking unit 220 is specifically configured to invoke the copy function of the target function in the method for extending a function, so as to obtain a return result of the copy function of the target function; and continuously executing a preset method on the return result of the copy function of the target function to complete the expansion of the running result of the copy function of the target function, wherein the preset method is a method preset for achieving the expansion target on the basis of the return result of the copy function of the target function.
In the above solution, the creating unit 210 is specifically configured to extend the type of the target function in the form of extension; and adding the extended function in the function contained in the type of the target function.
It should be noted that the above-mentioned classification of units does not constitute a limitation of the electronic device itself, for example, some units may be split into two or more sub-units, or some units may be combined into a new unit.
Note that the names of the units do not limit the units themselves in some cases, and for example, the execution unit 230 may also be described as a unit that "implements an extension to the target function in response to a method set in executing the extended function".
For the same reason, the units and/or modules not described in detail in the electronic device do not represent defaults of the corresponding units and/or modules, and all operations performed by the electronic device can be implemented by the corresponding units and/or modules in the electronic device.
In the following description, reference is made to "some embodiments" which describe a subset of all possible embodiments, but it is understood that "some embodiments" may be the same subset or different subsets of all possible embodiments, and may be combined with each other without conflict.
With continuing reference to fig. 3, fig. 3 is an alternative flowchart of the function expanding method according to the embodiment of the disclosure, for example, when the processing device 801 loads the program in the Read Only Memory (ROM) 102 or loads the program in the storage device 180 into the Random Access Memory (RAM), the function expanding method shown in fig. 3 may be implemented when executing the program, and the steps shown in fig. 3 are described below.
S101, when the target function is expanded, an expanded function is created in a first name space, the name of the expanded function is the same as that of the target function, the target function is a function to be expanded, and the name of the target function is in a second name space.
The function extension method provided by the embodiment of the disclosure is suitable for a hook programming technology which modifies or extends an operating system, an application program or other software components by intercepting function calls, message passing and event passing among software modules in a static language.
In some embodiments, the static language in embodiments of the present disclosure may be a Swift language.
In the embodiment of the present disclosure, the target function is a function to be expanded, and in some embodiments, the target function may be a static method native to the Swift language. For the static method, the memory address corresponding to the target function is determined in the compile time, so that the target function cannot be expanded by modifying the memory address corresponding to the target function.
In the embodiments of the present disclosure, the name space is a visible range of the function name, and different name spaces are independent and isolated from each other, so that the same function name can be defined in different name spaces.
In some embodiments, the target function is a self-contained lowercase conversion method in the native character structure, method name a, the function is to convert the incoming character to a lowercase character. Illustratively, when the target function a is called to print the character string "ABCDEFG", the print result is returned as "ABCDEFG". When the target function is expanded, the name a of the target function is in the second namespace, so the function expansion device may also name the name of the expanded function in the first namespace as a, and the function expansion device may obtain the target function a and the expanded function a.
It can be understood that, in the embodiment of the present disclosure, the name of the target function is in the second namespace, and therefore, when the extended function is named in the first namespace, the extended function and the target function can be named as the same name without a duplicate name conflict.
S102, in the extended function, calling a copy function of the target function, extending a calling result of the copy function of the target function, and completing method setting of the extended function, wherein the method setting of the copy function of the target function is calling of the target function, and the copy function of the target function is visible to the first namespace.
In the embodiment of the present disclosure, after the function extension apparatus creates the extended function in the first namespace, the function extension apparatus calls the copy of the target function, and the method of the copy function of the target function is set to call the target function.
In the embodiment of the disclosure, the first namespace, the second namespace and the third namespace are three namespaces which are isolated from each other and are independent from each other.
In the embodiment of the present disclosure, the method for copying the target function is set to call the target function, and by calling the target function in the copy function of the target function, the function extension apparatus may indirectly access the target function by accessing the memory address of the copy function of the target function.
In some embodiments, to avoid circular references, the name of the copy of the target function is a different name than the name of the target function.
In some embodiments, the function extension apparatus may obtain the copy function of the target function by creating a function of the same type as the target function and calling the target function in its function method setting. The function extension device may create a target function in the first namespace, and all function functions created in the first namespace may be visible to the first namespace by default, or create a target function in the third namespace, and then make names of all function functions included in the third namespace visible to the first namespace.
In some embodiments, the target function a is as described in S101, when the target function a is extended, an interception module may be created in the code engineering as a third namespace, and a copy function A1 of the target function may be created in the interception module; the steps of creating the function A1 and implementing the specific method are as follows:
1. adding an expansion statement in front of the native character structure to expand the native character structure;
2. and establishing a public member function A1 in the expanded character structure, calling the target function A and returning the calling result of the target function A in the specific implementation of the function A1 method, and taking the function A1 as a copy function of the target function by the function expansion device. The copy function A1 of the target function and the target function a correspond to different memory addresses, respectively, and the memory address of the copy function A1 of the target function includes a pointer pointing to the memory address of the target function a.
It can be understood that, when the copy function A1 of the target function is called, the function extension apparatus will first find the memory address where A1 is located, and then find the target function a according to the pointer included in the memory address of A1, and the memory address of the target function a can be obtained without memory offset addressing, thereby increasing the speed of finding the target function, and further, because the copy function A1 of the target function is called for the target function a, the method in A1 can be extended and modified to achieve the extension and modification of the target function a without forcibly modifying the memory address of the target function a, thereby increasing the safety of function extension.
In the embodiment of the present disclosure, the function extension device extends the call result of the copy function of the target function to complete the method setting of the extended function.
In the embodiment of the present disclosure, in order to achieve the objective of function extension, the function extension apparatus may add another method to achieve the objective on the basis of the call result of the copy function of the objective function, so that the final return result of the extended function may achieve the objective of extension.
In some embodiments, the target function may be a native character case conversion program of the operating system, and the extension target of the function extension device is to change the native character case conversion program of the operating system to perform sorting after character case conversion; in the method setting of the extended function, firstly, a target function copy function can be called, and then the native target function of the operating system is called through the copy function of the target function; carrying out case conversion on input characters, namely an exemplary ACDB to obtain a calling result of a target function copy function, namely a calling result acbd of a system native target function; and then the function expansion device adds specific method setting of sequencing after the calling result of the copy function of the target function, sequences acbd to obtain abcd, completes the method setting of the expansion function, and takes the abcd obtained after the final case and case conversion and sequencing as the return result of the expansion function.
In some embodiments, the copy function of the target function is the function A1 created in the interception module in S102, the extended function is the function a created in the first namespace in S101, the function extension apparatus continues to execute the preset method on the return result of the copy function of the target function, and the completion of the extension of the running result of the copy function of the target function may be as follows:
1. importing an interception module into a first name space, and making a copy function A1 of a target function in the interception module visible to the first name space;
2. adding an expansion statement in front of the native character structure to expand the native character structure;
3. creating an extended function A in the extended character structure, wherein the extended function A is the same as a target function A in the native String structure;
4. in the specific implementation of the extended function a, the copy function A1 of the target function in the third namespace is called, and a "- - > > HOOK" character string is added after the return result of A1, so as to complete the extension of the running result of the copy function of the target function.
When the extended function a is called, the function extension apparatus will call the copy function A1 of the target function in the third namespace interception module, and the copy function A1 of the target function will call the target function a, and finally, the extended function a will add the "- - > > HOOK" character string after the return result of the target function a, as the final return result of the extended function a.
It can be understood that, in the embodiment of the present disclosure, since the target function is called in the copy function of the target function, and the return result of the copy function of the target function is the same as the return result of the target function, the extension of the copy function of the target function by the extended function is equivalent to the indirect extension of the target function, and the return result of the extended function is equivalent to the return result after the target function is extended.
S103, when the name of the target function is read in the first name space, a method set in the extended function is executed correspondingly, and the extension of the target function is achieved.
In the embodiment of the disclosure, in the method setting of the extended function, after the operation result of the copy of the target function is extended, when the name of the target function is read in the first namespace, the function extension device correspondingly executes the method in the extended function, so as to implement the extension of the target function.
In the embodiment of the present disclosure, the function extension apparatus calls the extended function correspondingly according to the name of the target function, and performs the method setting for the extended function in S102 correspondingly, thereby implementing the extension of the target function.
In some embodiments, the method set in the extended function is the extended function a set in S102, and when the function extension apparatus calls the lower case conversion method in the first namespace through the name a and prints the "ABCDEFG" character string, and the name a is read in the first namespace, the method set in the extended function a is correspondingly executed, so that the return result "ABCDEFG- - > > HOOK" of the extended function a is obtained, instead of the "ABCDEFG" returned by the target function a, and the extension of the target function is implemented.
It is understood that, in the embodiment of the present disclosure, since the first namespace and the second namespace are isolated from each other and the name of the target function is contained in the second namespace, when the name of the target function is called in the first namespace, the extended function having the same name as the name of the target function in the first namespace is actually called, and not the target function.
It can be understood that, due to the isolation of the name space, the calling of the target function can be intercepted through the extended function with the same name as the target function in the first name space, and the method set in the extended function is executed, so that the return result of calling the name of the target function is extended to the return result set by the method in executing the extended function, and the target function is extended on the basis of not changing the memory address of the target function, and the safety of function extension is improved.
With continuing reference to fig. 4, fig. 4 is an alternative flow chart diagram of a method for implementing the function expansion according to the embodiment of the disclosure, and the steps shown in fig. 4 are explained below.
S201, when the target function is expanded, an expanded function of the type of the target function is created in a first name space, the name of the expanded function is named by the name of the target function, the name of the expanded function is the same as that of the target function, the target function is a function to be expanded, and the name of the target function is in a second name space.
In the embodiment of the present disclosure, when the function extension apparatus creates an extended function, the target function is created according to the type of the extended function, and the name of the target function is named as the extended function.
In this embodiment of the present disclosure, the creating, by the function extension apparatus, an extended function of the type of the target function in the first namespace may specifically include S2011-S2012, as follows:
s2011, the type of the target function is extended in the form of extension.
In the embodiment of the present disclosure, the function extension apparatus may add an extension prefix before the type of the target function, which indicates that the type of the target function is extended, so that the type of the target function includes a new extended function to be added.
It is understood that since the extended function is also added in the type of the objective function, the extended function is of the same type as the objective function.
S2012, add the extended function to the function included in the type of the target function.
In the embodiment of the present disclosure, after the type of the target function is extended, the function extension apparatus may add an extended function to the type of the target function.
In the embodiment of the present application, a method for adding an extended function to a function included in the type of the target function by the function extension apparatus is the same as S101, and details are not described here again.
S202, a copy function of the target function is created in the first name space, and the function created in the first name space is visible to the first name space by default.
In the embodiment of the present disclosure, the function extension apparatus may create a copy function of the target function inside the first namespace, and it is understood that, since the copy function of the target function is created inside the first namespace, the copy function of the target function is visible to the first namespace by default.
And S203, creating a copy function of the target function in the third name space.
In the embodiment of the present disclosure, the function extension apparatus may also create a copy of the target function in the third namespace.
In this embodiment of the present disclosure, a method for the function extension apparatus to create a copy of the target function in the third namespace is the same as that in S102, and details are not repeated here.
And S204, making the names of all the function functions contained in the third namespace visible to the first namespace.
In the embodiment of the present disclosure, since the third namespace is isolated from the first namespace, after the third namespace creates the copy of the target function, the function extension apparatus needs to make the names of all function functions included in the third namespace visible to the first namespace, so that the extended function in the first namespace can normally call the copy function of the target function created in the third namespace.
In some embodiments, the third namespace interception module can be imported into the first namespace using an import form, making the function functions in the interception module visible to the first namespace.
It should be noted that S202 and S203-S204 are two parallel implementation manners after S201, and the embodiment of the present disclosure may perform different branch execution according to actual situations, and the embodiment of the present disclosure is not limited. In the embodiment of the present disclosure, the copy function of the target function and the target function correspond to different memory addresses in the memory, and since the copy function of the target function is a call to the target function, the functions and the return results of the two functions are completely the same.
It can be understood that, when a third-party function calls the copy of the target function, the copy function of the target function returns the memory address corresponding to the copy function and the call result of the target function, so that the third-party function can modify and expand the call result of the target function by modifying the memory address of the copy function of the target function.
S205, calling the copy function of the target function in the method for expanding the function to obtain a return result of the copy function of the target function.
In the embodiment of the present disclosure, after the function extension apparatus acquires the copy function of the target function from the third namespace, the function extension apparatus may call the copy function of the target function in the method for extending the function.
In some embodiments, the target function is a lower case conversion method carried by itself in a native character structure, the method name is a, the copy function of the target function is a copy function A1 of the target function created in the interception module in the third namespace, the function extension apparatus creates an extension function a with the same name in the first namespace, and calls the copy function A1 of the target function in the extension function a to obtain a return result of the copy function A1 of the target function.
It is understood that, in the embodiment of the present disclosure, after the function extension apparatus calls the copy function of the target function, the function extension apparatus may obtain a return result of the copy function of the target function, and since the copy function of the target function is a call to the target function, the return result of the copy function of the target function is the same as the return result of the target function being directly called.
S206, continuously executing a preset method on the return result of the copy function of the target function to complete the expansion of the running result of the copy function of the target function, wherein the preset method is a method preset for achieving the expansion target on the basis of the return result of the copy function of the target function.
In the embodiment of the present disclosure, in order to complete the extension of the target function, after the function extension device calls the copy function of the target function in the method for extending the function, the function extension device also extends the return result of the copy function of the target function.
And S207, when the name of the target function is read in the first namespace, preferentially calling the extended function with the same name as the target function in the first namespace.
In the embodiment of the present disclosure, when the function extension apparatus reads the name of the target function in the first namespace, because the namespace has isolation, the function extension apparatus preferentially executes the extended function having the same name as the target function in the first namespace, instead of the target function itself.
In some embodiments, when the function extension apparatus reads the function name a in the first namespace, the extended function a set and implemented in the first namespace through S202-S206 is executed instead of the target function a carried by the native character structure.
And S208, executing the method for setting the extended function to obtain the execution result of the extended function, and realizing the extension of the target function.
In the embodiment of the present disclosure, after selecting to execute the extended function in the first namespace, the function extension apparatus may execute a specific method setting of the extended function, thereby obtaining an execution result of the extended function and implementing extension of the target function.
In some embodiments, when the function expanding apparatus calls the expanded function a in the first namespace to print the string "ABCDEFG", the actual output is "ABCDEFG" plus "- - > > HOOK", instead of "ABCDEFG" output by the system native target function a.
It can be understood that, when the name of the target function is called in the first namespace, a method in the extended function having the same name as the target function is actually called, and in the method for extending the function, the copy function of the target function in the third namespace is extended and modified by calling the copy function of the target function, so that the target function is not changed, and the safety of function extension is improved.
The embodiment of the present disclosure provides a computer-readable storage medium, which stores one or more programs, the one or more programs being executable by one or more processors 110, and the programs, when executed by the processors 110, implement the function extension method according to the embodiment of the present disclosure.
The above description is only an example of the present disclosure and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the disclosure herein is not limited to the particular combination of features described above, but also encompasses other combinations of features described above or equivalents thereof without departing from the spirit of the disclosure. For example, the above features and (but not limited to) the features disclosed in this disclosure having similar functions are replaced with each other to form the technical solution.
Further, while 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. Under 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 limitations on the scope of the 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 disclosed as example forms of implementing the claims.

Claims (11)

1. A method for extending functionality, comprising:
when a target function is expanded, an expanded function is created in a first naming space, the name of the expanded function is the same as that of the target function, the target function is a function to be expanded, and the name of the target function is in a second naming space;
creating a copy function of a target function inside the first namespace or a third namespace, the internally created function of the first namespace being visible to the first namespace by default; and names of all function functions contained in the third namespace are visible to the first namespace;
the first namespace, the second namespace and the third namespace are three namespaces which are independent and isolated from each other;
in the extended function, calling a copy function of a target function, and extending a calling result of the copy function of the target function to complete the method setting of the extended function, wherein the method setting of the copy function of the target function is calling of the target function; when the name of the target function is read in the first naming space, the extended function with the same name as the target function in the first naming space is called preferentially, the method set in the extended function is executed correspondingly, the execution result of the extended function is obtained, and the extension of the target function is realized.
2. The method of claim 1, wherein creating an extended function within the first namespace comprises:
creating the extended function of the type of the target function in the first namespace, and naming the extended function with the name of the target function.
3. The method according to claim 1, wherein the calling a copy function of a target function in the extended function and extending a calling result of the copy function of the target function to complete the method setting of the extended function comprises:
calling a copy function of the target function in the method for expanding the function to obtain a return result of the copy function of the target function;
and continuously executing a preset method on the return result of the copy function of the target function to complete the expansion of the running result of the copy function of the target function, wherein the preset method is a method preset for achieving the expansion target on the basis of the return result of the copy function of the target function.
4. The method of claim 2, wherein creating the extended function of the type of the target function in the first namespace comprises:
extending the type of the target function in the form of extension;
and adding the extended function in the function contained in the type of the target function.
5. A function extension apparatus, characterized in that the function extension apparatus includes a creation unit, a calling unit, and an execution unit, wherein:
the creating unit is used for creating an extended function in a first naming space when a target function is extended, wherein the name of the extended function is the same as that of the target function, the target function is a function to be extended, and the name of the target function is in a second naming space; the first naming space and the second naming space are independent and isolated from each other;
the calling unit is configured to call a copy function of a target function in the extended function, and extend a calling result of the copy function of the target function to complete method setting of the extended function, where the method of the copy function of the target function is set to call the target function, a copy function of the target function is created inside the first namespace, and the function created inside the first namespace is visible to the first namespace by default;
and the execution unit is used for calling the extended function with the same name as the target function in the first naming space preferentially when the name of the target function is read in the first naming space, and executing the method set in the extended function correspondingly to obtain the execution result of the extended function so as to realize the extension of the target function.
6. The apparatus of claim 5,
the calling unit is specifically configured to create a copy function of the target function in a third namespace; the names of all functional functions contained in the third namespace are made visible to the first namespace.
7. The apparatus of claim 5,
the creating unit is specifically configured to create the extended function of the type of the target function in the first namespace, and name the extended function by using a name of the target function.
8. The apparatus of claim 5,
the calling unit is specifically configured to call a copy function of the target function in the method for extending a function, so as to obtain a return result of the copy function of the target function; and continuously executing a preset method on the return result of the copy function of the target function to complete the expansion of the running result of the copy function of the target function, wherein the preset method is a method preset for achieving the expansion target on the basis of the return result of the copy function of the target function.
9. The apparatus of claim 7,
the creation unit is specifically configured to extend the type of the target function in the form of extension; and adding the extended function in the function contained in the type of the target function.
10. An electronic device, wherein the function expanding means comprises: a processor, a memory and a communication bus, the memory communicating with the processor through the communication bus, the memory storing one or more programs executable by the processor, the processor performing the function expanding method of any one of claims 1-4 when the one or more programs are executed.
11. A computer-readable storage medium, characterized in that the computer-readable storage medium stores one or more programs which are executable by one or more processors to implement the function expanding method according to any one of claims 1 to 4.
CN201910920216.2A 2019-09-26 2019-09-26 Function expansion method and device, electronic equipment and computer readable storage medium Active CN110737637B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910920216.2A CN110737637B (en) 2019-09-26 2019-09-26 Function expansion method and device, electronic equipment and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910920216.2A CN110737637B (en) 2019-09-26 2019-09-26 Function expansion method and device, electronic equipment and computer readable storage medium

Publications (2)

Publication Number Publication Date
CN110737637A CN110737637A (en) 2020-01-31
CN110737637B true CN110737637B (en) 2022-12-16

Family

ID=69269601

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910920216.2A Active CN110737637B (en) 2019-09-26 2019-09-26 Function expansion method and device, electronic equipment and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN110737637B (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102929638A (en) * 2012-11-07 2013-02-13 广州市动景计算机科技有限公司 Method and system for expanding Web application (App) functions
CN104615496A (en) * 2015-01-30 2015-05-13 上海交通大学 Parallel expansion method of reconfigurable framework based on multi-layer heterogeneous architecture
CN106919458A (en) * 2015-12-25 2017-07-04 腾讯科技(深圳)有限公司 The method and device of Hook target kernel functions
CN108536434A (en) * 2018-01-09 2018-09-14 武汉斗鱼网络科技有限公司 A kind of method and device for realizing Hook Function based on high-level programming language
CN109814948A (en) * 2018-12-29 2019-05-28 360企业安全技术(珠海)有限公司 Based on xposed frame native layer functions are carried out with the method, apparatus and electronic device of hook
CN110704134A (en) * 2019-09-12 2020-01-17 杭州秘猿科技有限公司 Method and device for performing function expansion on block chain

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102929638A (en) * 2012-11-07 2013-02-13 广州市动景计算机科技有限公司 Method and system for expanding Web application (App) functions
CN104615496A (en) * 2015-01-30 2015-05-13 上海交通大学 Parallel expansion method of reconfigurable framework based on multi-layer heterogeneous architecture
CN106919458A (en) * 2015-12-25 2017-07-04 腾讯科技(深圳)有限公司 The method and device of Hook target kernel functions
CN108536434A (en) * 2018-01-09 2018-09-14 武汉斗鱼网络科技有限公司 A kind of method and device for realizing Hook Function based on high-level programming language
CN109814948A (en) * 2018-12-29 2019-05-28 360企业安全技术(珠海)有限公司 Based on xposed frame native layer functions are carried out with the method, apparatus and electronic device of hook
CN110704134A (en) * 2019-09-12 2020-01-17 杭州秘猿科技有限公司 Method and device for performing function expansion on block chain

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
《MG --Swift扩展 命名空间》;Mg明明就是你;《简书》;20190402;正文第1-2页 *

Also Published As

Publication number Publication date
CN110737637A (en) 2020-01-31

Similar Documents

Publication Publication Date Title
CN110046021B (en) Page display method, device, system, equipment and storage medium
WO2020119800A1 (en) List display method, apparatus and device, and storage medium
US11856152B2 (en) Video special effect configuration file generation method and apparatus, and video rendering method and apparatus
CN111581555B (en) Document loading method, device, equipment and storage medium
CN111400068B (en) Interface control method and device, readable medium and electronic equipment
CN111273985A (en) Page rendering method and device, electronic equipment and computer readable storage medium
CN112905220B (en) Thermal restoration method, device, equipment and storage medium
CN112416303B (en) Software development kit hot repair method and device and electronic equipment
CN111581664B (en) Information protection method and device
CN111324376B (en) Function configuration method, device, electronic equipment and computer readable medium
CN110737637B (en) Function expansion method and device, electronic equipment and computer readable storage medium
CN112306685A (en) Task isolation method and device, electronic equipment and computer readable medium
CN111752644A (en) Interface simulation method, device, equipment and storage medium
CN116644089A (en) Query statement generation method, device, equipment and storage medium
CN113343259B (en) SM 2-based joint signature realization method and device, electronic equipment and storage medium
CN110618772B (en) View adding method, device, equipment and storage medium
CN112835671A (en) Application page scene switching method, device and equipment
CN111753238A (en) Data mapping method and device and electronic equipment
CN111459893A (en) File processing method and device and electronic equipment
CN112445820A (en) Data conversion method and device
CN113391860A (en) Service request processing method and device, electronic equipment and computer storage medium
CN111552469B (en) File processing method and device in application engineering and electronic equipment
CN113010064B (en) Information prompting method and device and electronic equipment
CN115114051B (en) Node communication method, device, equipment and storage medium
CN112346728B (en) Device adaptation method, apparatus, device and computer readable medium

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

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.

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.

CB02 Change of applicant information
GR01 Patent grant
GR01 Patent grant