Method, device and medium for hiding system function calls in program core code
By parsing import tables, filtering system functions, creating code segments and modifying call instructions, hiding system function calls, the problem of system functions being easily perceived in the existing technology is solved, and the security and functional concealment of the program are improved.
Patent Information
- Application Number
- CN202110346962.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-31
- Publication Date
- 2024-11-08
- Estimated Expiration
- 2041-03-31
AI Technical Summary
Existing programs are easily perceived by hook functions or other methods when calling system functions, resulting in low security and a method is needed to hide system function calls.
By parsing the import table, obtaining and filtering system functions, modifying the import table to avoid importing system functions, creating code segments and copying system function code, modifying the calling instructions to call system functions in the code segment, thereby hiding system function calls.
It realizes that all functions are completed in the program module without exposing system function calls, improves program security, reduces package size, and ensures that no system functions are directly called in the core code.
Smart Images

Figure CN115145571B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of computer technology, and in particular to a method, apparatus, device and storage medium for hiding system function calls in core program codes. Background Art
[0002] For program development, the functions of the program are implemented through code logic and system function calls. Because system functions are fixed in the process memory, they are easily detected by hook functions or other means. Once the called system function is known, the function of the developed program will be known, thus having lower security. For example, for the function of the program to implement the registry or file data input, the registry-related functions provided by the system will be called. Once the registry-related system function is known, the call of the system function will also appear in the import table, and the function of the program will be known.
[0003] From this we can see that a solution is needed to hide system function calls. Summary of the invention
[0004] In response to the problems existing in the prior art, an embodiment of the present invention provides a method for hiding system function calls in core program codes, which can directly call system functions from a created code segment. All functions are completed in the program module, and the system function calls will not be exposed to the outside, thereby hiding the system function calls.
[0005] In a first aspect, an embodiment of the present invention provides a method for hiding system function calls in a program core code, comprising:
[0006] Obtain any system function by parsing the import table;
[0007] Traverse the program module, obtain any function and the memory address of calling any function, and filter out the system function in any function;
[0008] Modify the import table so that the import table does not import any system function;
[0009] and creating a code segment in the program, and copying the code of any system function to the code segment;
[0010] And the instruction for calling the system function is modified into an instruction for calling any system function in the created code segment, so as to achieve hiding of the system function call.
[0011] Preferably, it also includes:
[0012] According to any of the import functions, create an import function list;
[0013] Establish multiple structure objects to store import items corresponding to each import function; wherein the import items include the module name of the system and the function name of the module, and the memory address of the import function;
[0014] A first array is established to store the structure object.
[0015] Preferably, the traversal program module acquires any function and acquires the memory address of calling any function, specifically including:
[0016] Traversing the traversal program module, finding any function according to the function header assembly code features and the function tail assembly code features;
[0017] A function address of any one of the functions is obtained, and a second array is established to store the function address of any one of the functions.
[0018] Preferably, the step of selecting a system function from any of the functions specifically includes:
[0019] Mark any call instruction in any function and obtain a memory address, wherein the memory address is the address code contained in the call instruction
[0020] Calculate the real function address according to the memory address;
[0021] Traversing the second array, if the memory address matches the function address in the second array, determining that the corresponding function is a system function;
[0022] Establishing a third array to record the real function address of the screened system function, the system module name corresponding to the system function and the function name of the module;
[0023] The real function address calculation formula is:
[0024] Real dwoffset = dwoffset - DWORD dwoffset;
[0025] Among them, Real dwoffset is the real function address, dwoffset is the memory address, DWORD dwoffset =*(DWORD*)(call_address + 1); DWORD dwoffset is the offset byte, *(DWORD*)(call_address +1) is the byte length occupied by the address of the current instruction in the memory.
[0026] Preferably, modifying the import table so that the import table does not import any system function specifically includes:
[0027] Obtaining DOS header data of the program PE import table, and obtaining NT header data of the program PE import table;
[0028] According to the NT header data of the program PE import table, obtaining the starting address of the program PE import table;
[0029] The result data of the program PE import table is traversed, and the dwFileOriFirstThunk data value in the result data of the program PE import table is cleared to zero.
[0030] Preferably, the step of creating a code segment in the program and copying the code of any system function to the created code segment specifically includes:
[0031] Traversing the third array to obtain the code lengths of all system functions;
[0032] Based on the code length of all system functions, obtain the code length of all system functions;
[0033] The length of the newly added code segment is obtained by summing up the code length of all system functions;
[0034] Creating a code segment according to the length of the newly added code;
[0035] Traverse the array, obtain system module names and function names and load corresponding modules;
[0036] And obtain the memory address and starting address of all system functions in the module through the system function, and then obtain the offset of the system function in the module;
[0037] And the assembly code length of the function is calculated through the assembly code features of the function header and the assembly code features of the function tail;
[0038] Copy the assembly code of all system functions to the created code segment.
[0039] Preferably, the step of modifying the instruction for calling the system function into an instruction for calling any system function in the created code segment specifically includes:
[0040] Read the relocation data in the relocation table;
[0041] Searching for a relocation item of the assembly code of the system function in the relocation data;
[0042] Copy the found relocation item to the code segment, and convert the address data in the relocation item into data in the code segment;
[0043] If the global data or global table of the introduced system module exists in the relocation item, the global data or global table of the introduced system module is copied to the code segment, and the address data in the relocation item is converted into data in the code segment;
[0044] The instruction for calling the system function in the code segment is modified to call the system function copied in the newly added code segment.
[0045] In the second aspect, an embodiment of the present invention provides a device for implementing hidden system function calls in the core code of a program, including: an acquisition module, which is used to obtain any system import function by parsing the program import table; a traversal module, which is used to traverse the program, obtain any function and the memory address of calling any function, and filter out system functions in any function; a modification module, which is used to modify the import table so that the import table does not import any system function; a creation module, which is used to create a code segment in the program and copy the code of any system function to the created code segment; a calling module, which is used to modify the instruction of calling the system function to the instruction of calling any system function in the created code segment, so as to achieve hiding of the system function call.
[0046] In a third aspect, an embodiment of the present invention provides an electronic device, including an application processor and a memory, wherein the processor is used to implement the steps of the method for hiding system function calls as described above when a computer management program is stored in the memory.
[0047] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer management program stored thereon, wherein the computer management program, when executed by a processor, implements the steps of the method for hiding system function calls as described above.
[0048] Beneficial Effects
[0049] The method and related devices for hiding system function calls provided by the embodiments of the present invention create a code segment by traversing an array to obtain the length of a newly added code segment, copy the system function assembly code to the created code segment, and directly call the system function from the created code segment after modifying the calling instruction. For functions such as registry operations that must be implemented by calling system functions, all functions are completed in the program module and the calls to system functions will not be exposed to the outside world, thereby sacrificing the size of the program package in exchange for security, and implementing the system function call without call in the core code. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0051] Figure 1 A flowchart of an embodiment of a method for hiding system function calls in a program core code according to the present invention;
[0052] Figure 2 The flowchart of establishing the first array according to the present invention is shown in FIG.
[0053] Figure 3 This is a flowchart of screening out system functions from any function according to the present invention.
[0054] Figure 4 This is a flow chart of modifying the import table according to the present invention.
[0055] Figure 5 This is a flowchart of copying the code of any system function to a code segment according to the present invention.
[0056] Figure 6 This is a flowchart of modifying the system function call instruction described in the present invention.
[0057] Figure 7 A module diagram of an embodiment of a device for hiding system function calls of the present invention;
[0058] Figure 8 A schematic diagram of the hardware structure of a device with a hidden system function call function provided by an embodiment of the present invention;
[0059] Fig. 9 A schematic diagram of a possible electronic device provided by an embodiment of the present invention;
[0060] Fig.10 A schematic diagram of an embodiment of a possible computer-readable storage medium provided for an embodiment of the present invention. DETAILED DESCRIPTION
[0061] The following is a description of the implementation of the present invention by specific embodiments. People familiar with the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0062] It should be noted that in the description of the present invention, the terms "middle", "upper", "lower", "lateral", "inner", etc. indicating directions or positional relationships are based on the directions or positional relationships shown in the drawings, which are only for the convenience of description, and do not indicate or imply that the device or element must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first" and "second" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance.
[0063] In addition, it should be noted that in the description of the present invention, unless otherwise clearly specified and limited, the terms "set", "install", "connect", and "connect" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two elements. For those skilled in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0064] Figure 1 Flow chart of a method embodiment of hiding system function calls of the present invention, such as Figure 1 As shown, including:
[0065] Step S110, obtaining any system import function by parsing the program import table;
[0066] like Figure 2 As shown, specifically, all functions in the module provided by this embodiment, including system functions and non-system functions, have their calling positions when called. To facilitate subsequent steps, the calling positions of system functions and system functions are stored in an array. Specifically, the following steps are included:
[0067] Step S111, creating an import function list according to any import function;
[0068] Furthermore, for the program in the embodiment of the present invention, the compiled program software is parsed using a PE file. The PE file, which stands for Portable Executable, means a portable executable file. The PE file is a program file on the Windows operating system.
[0069] Use the PE file parser PE import table to obtain all imported functions, and the imported functions are all system functions.
[0070] Step S112, establishing a plurality of structure objects to store the import items corresponding to each import function; wherein the import items include the module name of the system and the function name of the module;
[0071] The embodiment of the present invention uses a structure to store import items, and the specific computer language description is as follows:
[0072] strcut ImportItem{
[0073] string moduleName;
[0074] String functionName;}
[0075] Among them, moduleName indicates the module name of the storage system, and functionName indicates the function name of the storage module.
[0076] Step S113, establishing a first array to store structure objects;
[0077] Specifically, for each structure instance in the above computer language, an import entry of the PE import table is stored. In the embodiment of the present invention, all import entries are stored in the first array, which is described in the computer language as a vector. <importitem>importlist;
[0078] When parsing the PE import table, an instance ImportItem object is created for each import item and stored in the first array importlist.
[0079] It should be noted that, in this embodiment, step S110 uses the first array to store all system functions obtained from the PE import table, thereby achieving the beneficial effect of facilitating subsequent acquisition of assembly codes of all system functions.
[0080] like Figure 3 As shown, step S120, traversing the program, obtaining any function and the memory address of calling any function, and filtering out the system function in any function, specifically, includes the following steps:
[0081] Step S121, traverse the program module, and find out any function code according to the function header assembly code features and the function tail assembly code features.
[0082] The following is a further introduction to the function header assembly code features and function tail assembly code features:
[0083] Function header assembly code features: save the stack register and allocate the stack space size. The function header assembly code features are described in computer language as follows:
[0084] {push ebp;
[0085] mov ebp,esp
[0086] sub esp,xx
[0087] push
[0088] }
[0089] Among them, push ebp; means pushing the value of the ebp register into the stack. mov ebp,esp means copying the current top value of the stack esp to ebp, that is, using ebp to save the current stack pointer. sub esp,xx means allocating the stack space size of the function. Here, the xx identifier is a specific value. The stack space size required for each function is different, and the corresponding xx value is different. push refers to the data of the general register value pushed into the stack register. It should be noted that the register is a general register. It is different for each function, but it must be a general register, including eax, ebx, ecx and other general registers. The number of instructions here changes according to the function, so the feature here is one or more.
[0090] Function tail assembly code features: restore register operations and restore previously saved registers, corresponding to the function header assembly code features. The corresponding registers are the reverse of the function header assembly code features, and the number of restore operations is consistent with the number saved by the function header assembly code features.
[0091] The function tail assembly code feature computer language description is as follows:
[0092] pop
[0093] Refers to the general registers that restore the register values saved by the function header assembly code features from the stack. The number of instructions restored here is the same as the number saved previously. At the same time, the order in which the function header assembly code features were saved is the opposite of the order restored here.
[0094] Examples of function header and function tail assembly code features are as follows:
[0095] Function header assembly code features: push eax;
[0096] Push ebx;
[0097] Push ecx;
[0098] Corresponding function header assembly code features
[0099] Pop ecx;
[0100] Pop ebx;
[0101] Pop eax;
[0102] Based on the assembly code features of each function header and the corresponding assembly code features of the function tail, all functions are parsed.
[0103] In the embodiment of the present invention, the extraction of function header assembly code features and function tail assembly code features is completed through the stack register. The function header assembly code features and function tail assembly code features are obtained based on the stack register, achieving the beneficial effect of finding all function code features.
[0104] Filter out system functions in any function, including:
[0105] Step S122: Mark any call instruction in the function code to obtain a memory address, wherein the memory address is an address code included in the call instruction.
[0106] After all functions are obtained, the memory address of each calling function in all functions is calculated by the formula. It should be noted that the memory address in the embodiment of the present invention refers to the absolute address in the memory, the start address refers to the relative start address in the memory, and the end address refers to the relative end address in the memory, that is, the start address with offset and the end address with offset.
[0107] Specifically, for all functions, all calling functions are obtained by marking all call instructions. The callxxxx instruction indicates calling a function, and xxxx here indicates the memory offset address of the called function.
[0108] It should be particularly noted that the embodiment of the present invention obtains the memory addresses of all calling functions by marking all call instructions, thereby achieving the beneficial effect of effectively identifying system functions in all function codes.
[0109] Step S123, calculating the real function address according to the memory address; establishing a second array to store the real function address, wherein the real function address calculation formula is:
[0110] Real dwoffset = dwoffset - DWORD dwoffset;
[0111] Among them, Real dwoffset is the real function address, dwoffset is the memory address, DWORD dwoffset = *(DWORD*)(call_address + 1); DWORD dwoffset is the offset byte, *(DWORD*)(call_address +1) is the byte length occupied by the address of the current instruction in the memory
[0112] Specifically, the memory address of each calling function in all functions is calculated by the formula as follows:
[0113] DWORD dwoffset = *(DWORD*)(call_address + 1);
[0114] Read the data of the calling function after the call instruction, call_address, which indicates the offset address of the current instruction in the memory. In call_address + 1, +1 is because the call address instruction is 5 bytes long, call occupies one byte, and the following offset data occupies 4 bytes. dwoffset indicates that it is a relative offset memory address.
[0115] dwoffset = dwoffset - 5
[0116] The instruction itself is 5 bytes long. The call xxxx instruction indicates the memory offset address of the called function. Subtracting 5 is the real function address, that is, the memory address in the embodiment of the present invention.
[0117] It should be particularly noted that the real function address calculation formula provided in this embodiment obtains the offset memory address according to the bytes of the call instruction, thereby achieving the beneficial effect of accurate calculation.
[0118] Step S124, traverse the second array, and if the real function address matches the system function address, determine that the corresponding function is a system function;
[0119] Furthermore, all system functions are stored in the second array. The embodiment of the present invention stores the memory addresses of all system functions in the first array, and then searches the first array for the memory address of each calling function obtained by the above formula. If a calling function finds the same memory address in the first array, then the function is the called system function. If not, then the function is not the called system function. All called system functions are found, and the calling locations of all called system functions are recorded.
[0120] It should be particularly noted that the search method provided in this embodiment achieves the beneficial effect of effectively identifying the system function based on the address of the system function established in the matching search step S123.
[0121] Step S125, establishing a third array to record the calling position of the screened system function, the system module name corresponding to the system function and the function name of the module;
[0122] Specifically, the calling position, name and module name of each called system function are stored in a SystemCall instance object. The data structure is described in computer language as follows:
[0123] Struct SystemCall{
[0124] string moduleName;
[0125] string functionName;
[0126] DWORD offset;
[0127] }
[0128] Among them, moduleName refers to the name of the module where the called system function is located, functionName refers to the name of the called system function, and DWORD offset refers to the offset address of the called system function in this module.
[0129] After finding all the called system functions, fill in the corresponding SystemCall instance object data and store all the SystemCall instance objects of the called system functions into the second array. The computer language description of the second array is as follows:
[0130] Vector <systemcall>systemcalllist;
[0131] The second array stores the names of all called system functions, the corresponding calling locations and the names of the modules they are located in.
[0132] It should be noted that this step achieves the beneficial effect of facilitating the subsequent creation of code segments and copying of codes by storing all called system functions, corresponding calling locations and module names in the second array.
[0133] like Figure 4 As shown, step S130, modifying the import table so that the import table does not import any system function; further, modifying the program PE import table, specifically including: based on the DOS header data of the program PE import table, obtaining the NT header data of the program PE import table; based on the NT header data of the program PE import table, obtaining the starting address of the program PE import table; based on the starting address of the program PE import table, clearing all file mapping initial priority form-to-real conversion programs of the program PE import table, specifically including the following steps:
[0134] Step S131, obtaining DOS header data of the program PE import table, and obtaining NT header data of the program PE import table;
[0135] Specifically, the module is first parsed to obtain the DOS header data of the program PE import table, namely the PIMAGE_DOS_HEADER header data. Then, the NT header data of the program PE import table, namely the PIMAGE_NT_HEADERS header data, is obtained based on the PIMAGE_DOS_HEADER header data.
[0136] Step S132, according to the NT header data of the program PE import table, obtain the starting address of the program PE import table; specifically, the program PE import table of the existing module is modified based on the PIMAGE_NT_HEADERS header data to obtain the starting address of the program PE import table in this module, which is described in computer language as follows: OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress; wherein VirtualAddress is the starting address of the program PE import table.
[0137] It should be noted that in this step, the starting address of the import table is obtained through the DOS header data and the NT header data, thereby achieving the beneficial effect of accurate search.
[0138] Step S133, traversing the result data of the program PE import table, and clearing the dwFileOriFirstThunk data value in the result data of the program PE import table to zero;
[0139] Specifically, all file mapping initial priority form-to-physical conversion programs in the program PE import table are cleared, that is, the dwFileOriFirstThunk data in the data result of the program PE import table is cleared. Since there are multiple dwOriFirstThunks in the program PE import table, each dwOriFirstThunk data contains multiple dwFileOriFirstThunks. When traversing, it is determined whether the current value of dwFileOriFirstThunk is 0. The embodiment of the present invention clears all dwFileOriFirstThunk data in the program PE import table to 0. The embodiment of the present invention does not clear the entire program PE import table or directly modify the dwOriFirstThunk data, otherwise the system will determine that the module is an illegal module when loading the module.
[0140] It should be noted that this step clears all dwFileOriFirstThunk data to 0, so that when the program parses the PE import table, it will not parse and fill each import item if it finds that the dwFileOriFirstThunk data is empty. This makes the import table not import any system functions, so that the import table will not reveal that this module calls the system function, thus achieving the beneficial effect of hiding the system function call at the level of the PE import table.
[0141] like Figure 5 As shown, step S140, create a code segment in the program, and copy the code of any system function to the created code segment; further, after obtaining the above-mentioned first array and second array, the embodiment of the present invention traverses the arrays, creates a code segment based on the assembly code of the system function and copies the assembly code of all system functions to the created code segment.
[0142] Next, the process of obtaining the length of the newly added code segment is further explained.
[0143] Traverse the array and sum the length of the assembly code of all system functions to obtain the length of the newly added code segment. Specifically, the steps are as follows:
[0144] Step S141, traverse the first array to obtain the code lengths of all system functions; based on the code lengths of all system functions, obtain the code lengths of all system functions; sum the code lengths of all system functions to obtain the length of the newly added code segment;
[0145] Specifically, the first array stores all system functions, the corresponding function names, and the module names they are in; the second array stores the calling locations of all system functions, all called system functions, the corresponding calling locations, and the module names they are in. Based on the above arrays, the codes of all system functions can be obtained, so that the assembly codes of all system functions can be known.
[0146] Assembly code is code written in assembly language. Assembly language is a low-level language used in electronic computers, microprocessors, microcontrollers or other programmable devices, also known as symbolic language. In assembly language, mnemonics are used to replace the opcodes of machine instructions, and address symbols or labels are used to replace the addresses of instructions or operands. In different devices, assembly language corresponds to different machine language instruction sets, which are converted into machine instructions through the assembly process.
[0147] Furthermore, the array is traversed, and the assembly code lengths of all system functions are summed to obtain the length of the newly added code segment, specifically including: traversing the first array to obtain the code lengths of all system functions; based on the code lengths of all system functions, obtaining the assembly code lengths of all system functions; summing the assembly code lengths of all system functions to obtain the length of the newly added code segment.
[0148] Traverse the first array, obtain the code length of all system functions in the module, and obtain the assembly code length of all system functions according to the code length in the module. Code and assembly code are different. Code is written in a high-level computer language in the module, and assembly code is written in a low-level language in the memory.
[0149] The lengths of the assembly codes of all the obtained system functions are summed up, and the sum of the assembly code lengths obtained is the length of the newly added code segment.
[0150] It should be noted that this step is based on the assembly language length of all system functions and the length of the newly added code segment, thereby achieving the beneficial effect of facilitating subsequent copying operations.
[0151] Step S142, traverse the second array to obtain the memory address and start address of all system functions;
[0152] According to the memory addresses and starting addresses of all system functions, the end addresses of all system functions are obtained through the assembly code features of the function header and the assembly code features of the function tail;
[0153] Specifically, first traverse the first array, that is, the importlist created in the above embodiment, to obtain all system functions, and obtain all system functions, corresponding function names and module names through the instance object ImportItem stored in the array. The specific computer language description is as follows:
[0154] The module is loaded through the system function handle = LoadLibrary("moduleName");, and the system function is obtained through the system function address = GetProcAddress(handle, "functionName");. Based on the above description, the memory addresses of all system functions in this module are obtained. Based on the memory addresses of all system functions in this module, the starting addresses of all system functions are obtained. The specific calculation formula is as follows:
[0155] Offset = address - handle;
[0156] Among them, offset represents the relative offset of the system function in this module, address represents the memory address of the system function, and handle represents the starting address of the system function loaded into the memory.
[0157] Secondly, based on the memory address and starting address of all system functions, the end address of all system functions is located correspondingly through the function header assembly code features and function tail assembly code features described in the above embodiment. It should be noted that based on the starting address and end address of all system functions, the assembly code length of each system function can be calculated by the following formula:
[0158] Length = address_end - Address;
[0159] Among them, Length is the assembly code length of the system function, address_end represents the end address of the system function, and Address represents the starting address of the system function.
[0160] It should be noted that based on the memory address and start address of all system functions,
[0161] The beneficial effect of the relative offset of each system function in this module is obtained by calculation.
[0162] Step S143: Based on the start address and end address of all system functions, copy from each system function header to the system function tail, obtain the assembly code of all system functions and copy it to the created code segment.
[0163] Further, the assembly codes of all system functions are copied to the created code segment, specifically including: traversing the first array to obtain the memory addresses and start addresses of all system functions; based on the memory addresses and start addresses of all system functions, correspondingly obtaining the end addresses of all system functions through the function header assembly code features and the function tail assembly code features; based on the start addresses and end addresses of all system functions, obtaining the assembly codes of all system functions and copying them to the created code segment;
[0164] A code segment is created in the program of the module, and the length of the created code segment is the length of the newly added code segment obtained in the above embodiment, thereby achieving the beneficial effect of providing an effective length of the newly added code segment and avoiding increasing the system occupancy.
[0165] like Figure 6 As shown, step S150, modify the instruction for calling the system function into an instruction for calling any system function in the created code segment, so as to achieve hiding of the system function call.
[0166] Step S151, reading the relocation data in the relocation table;
[0167] Based on the relocation data of all system functions in the read relocation table, the updated relocation data is obtained and added to the created code segment. In the above embodiment, the length of the newly added code segment is obtained. Next, the process of hiding the system function call based on the length of the newly added code segment is described.
[0168] Step S152, searching for the relocation item of the assembly code of the system function in the relocation data;
[0169] Specifically, for some system functions, there are some relocation data, and there are corresponding relocation data items in the system module relocation table. If you only copy all system functions without copying the updated relocation data, you cannot directly call the system functions in the created code segment, and you need to add the updated relocation data in the created code segment;
[0170] It should be particularly noted that step S152 provided in this embodiment achieves the beneficial effect of forming a corresponding relationship between the assembly code of the system function and the relocation table by searching for the relocation item of the assembly code of the system function in the relocation data.
[0171] Step S153, copying the found relocation item to the code segment, and converting the address data in the relocation item into data in the code segment;
[0172] Specifically, first read any relocation data in the relocation table, then check whether there is corresponding relocation data in each system function copied to the created code segment, and if so, add updated relocation data to the created code segment, where the updated relocation data is the relocation data that has undergone address conversion operations.
[0173] Further, based on the relocation data of any system function, updated relocation data of any system function is obtained. Specifically, for the relocation data of any system function, its position in the original system module needs to be converted into the position of the created code segment, which is implemented by the following computer language:
[0174] Offset = Address - startAddress;
[0175] Where, offset indicates the relocation data of any system function. Address indicates the offset of the relocation data of any system function in the current code of the system module in the file. startAddress indicates the starting address of the current file of the system module.
[0176] NewOffset = NewBaseAddress - NewHopeAddress + Offset;
[0177] The updated relocation data NewOffset of any system function is the actual loading start address of the module to which the created code segment belongs, and NewHopeAddress indicates that the module to which the created code segment belongs defaults to the loaded module base address.
[0178] It should be particularly noted that this embodiment provides a conversion formula between the relocation data and the data in the code segment, thereby achieving the beneficial effect of modifying the relocation data and writing it into the code segment.
[0179] Step S154: if the global data or global table of the introduced system module exists in the relocation item, the global data or global table of the introduced system module is copied to the code segment, and the address data in the relocation item is converted into the data in the code segment;
[0180] Specifically, it is determined whether there is global data or a global table. If there is, the global data or the global table is updated according to the above formula, and the updated global data or the updated global table is copied and added to the created code segment, and the updated relocation data of any system function obtained by the above formula is also added to the created code segment. If there is global data or a global table introduced into the system module in the relocation item, the global data or the global table introduced into the system module is copied into the code segment, and the address data in the relocation item is converted into data in the code segment.
[0181] It should be particularly noted that, in this embodiment, the global data or global table of the introduced system module is present in the relocation item, the global data or global table of the introduced system module is copied to the code segment, and the address data in the relocation item is converted into the data in the code segment, thereby achieving the beneficial effect of copying all system functions into the module.
[0182] Step S155: modify the instruction for calling the system function in the code segment to call the system function copied in the newly added code segment.
[0183] Specifically, after the assembly code of all system functions and the updated relocation data are added to the created code segment, the call instruction needs to be modified. Specifically, modifying the call instruction includes: modifying the instruction of the program calling the system function to the instruction of calling all system functions in the created code segment.
[0184] In the above embodiment, it is explained that the instruction for a program to call a system function is Call xxxx, which is to directly call a system function by calling the call instruction. In the embodiment of the present invention, the function address of xxxx in the call instruction is modified to be the memory address of the system function in the created code segment.
[0185] It should be particularly noted that the present invention, by modifying the calling instruction call, will not directly call the system function in the original system module, but realizes calling the system function in the created code segment, so that all functions are completed in this module, achieving the beneficial effect of effectively hiding the system function call.
[0186] It should be noted that the program developer develops the program according to the existing mode, and if the system function needs to be called, the system function is still called in the existing way. After the development is completed, the method of hiding the system function call described in the embodiment of the present invention is implemented, and the program is compiled to obtain the final released program software. Therefore, the embodiment of the present invention does not cause trouble to the development programmer, and the method of hiding the system function call described in the embodiment of the present invention is transparent to the program developer.
[0187] The above describes the method for setting a hidden system function call in the embodiment of the present application. The following describes the device with the hidden system function call function in the embodiment of the present application.
[0188] Figure 7 Module diagram of an embodiment of a device for hiding system function calls of the present invention, such as Figure 7 As shown, an embodiment of the present invention also provides an embodiment of a device with a function of hiding system function calls, and the device includes: an acquisition module 210, a traversal module 220, a modification module 230, a creation module 240 and a call module 250. The acquisition module 210 is used to obtain any system import function by parsing the program import table; the traversal module 220 is used to traverse the program, obtain any function and the memory address of calling any function, and filter out the system function in any function; the modification module 230 is used to modify the import table so that the import table does not import any system function; the creation module 240 is used to create a code segment in the program, and copy the code of any system function to the created code segment; the call module 250 is used to modify the instruction of calling the system function to the instruction of calling any system function in the created code segment, so as to achieve the hiding of the system function call.
[0189] Figure 7 The device for hiding the system function call function in the embodiment of the present application is described from the perspective of modular functional entities. The device for hiding the system function call function in the embodiment of the present application is described in detail from the perspective of hardware processing. Figure 8 A schematic diagram of the hardware structure of a device with a hidden system function call function provided by an embodiment of the present invention; see Figure 8 The device 300 recommended in the embodiment of the present invention with a hidden system function call function is an embodiment, comprising:
[0190] An input device 301, an output device 302, a processor 303 and a memory 304 (the number of the processor 303 can be one or more, Figure 3 In some embodiments of the present invention, the input device 301, the output device 302, the processor 303 and the memory 304 may be connected via a bus or other means, wherein: Figure 3 The example of connecting through bus is taken in the following.
[0191] Wherein, by calling the operation instruction stored in the memory 304, the processor 303 is used to perform the following steps:
[0192] Obtain any system function by parsing the import table;
[0193] Traverse the program module, obtain any function and the memory address of calling any function, and filter out the system function in any function;
[0194] Modify the import table so that the import table does not import any system function;
[0195] and creating a code segment in the program, and copying the code of any system function to the code segment;
[0196] And the instruction for calling the system function is modified into an instruction for calling any system function in the created code segment, so as to achieve hiding of the system function call.
[0197] By calling the operation instructions stored in the memory 304, the processor 303 is also used to execute Figure 1 Any method in the corresponding embodiment.
[0198] Fig. 9 A schematic diagram of a possible electronic device provided by an embodiment of the present invention is shown in FIG. Fig. 9 shown.
[0199] In another embodiment, the present invention further provides an electronic device, including a memory 410, a processor 420, and a computer program 411 stored in the memory 410 and executable on the processor 420, and the processor 420 implements the following steps when executing the computer program 411.
[0200] Obtain any system function by parsing the import table;
[0201] Traverse the program module, obtain any function and the memory address of calling any function, and filter out the system function in any function;
[0202] Modify the import table so that the import table does not import any system function;
[0203] and creating a code segment in the program, and copying the code of any system function to the code segment;
[0204] And the instruction for calling the system function is modified into an instruction for calling any system function in the created code segment, so as to achieve hiding of the system function call.
[0205] In the specific implementation process, when the processor 420 executes the computer program 411, it can achieve Figure 1 Any implementation manner in the corresponding embodiments.
[0206] Since the electronic device introduced in this embodiment is a device used to implement a device with a hidden system function call function in the embodiment of the present invention, based on the method introduced in the embodiment of the present invention, technical personnel in this field can understand the specific implementation method of the electronic device of this embodiment and its various variations. Therefore, how the electronic device implements the method in the embodiment of the present invention is not introduced in detail here. As long as the equipment used by technical personnel in this field to implement the method in the embodiment of the present invention is within the scope of protection of this application.
[0207] Fig.10 For a possible computer-readable storage medium embodiment provided by the present invention, please refer to Fig.10 .
[0208] like Figure 5 As shown, this embodiment provides a computer-readable storage medium 500, on which a computer program 511 is stored. When the computer program 511 is executed by a processor, the following steps are implemented:
[0209] Obtain any system function by parsing the import table;
[0210] Traverse the program module, obtain any function and the memory address of calling any function, and filter out the system function in any function;
[0211] Modify the import table so that the import table does not import any system function;
[0212] and creating a code segment in the program, and copying the code of any system function to the code segment;
[0213] And the instruction for calling the system function is modified into an instruction for calling any system function in the created code segment, so as to achieve hiding of the system function call.
[0214] In the specific implementation process, when the computer program 511 is executed by the processor, Figure 1 Any implementation manner in the corresponding embodiments.
[0215] It should be noted that in the above embodiments, the description of each embodiment has its own emphasis, and for parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0216] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0217] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded computer, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0218] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0219] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0220] The embodiment of the present invention also provides a computer program product, which includes computer software instructions. When the computer software instructions are executed on a processing device, the processing device executes the following Figure 1 The process in the method of hiding system function calls in the corresponding embodiment.
[0221] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from one website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid state disk (SSD)), etc.
[0222] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0223] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0224] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0225] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0226] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc., various media that can store program codes.
[0227] The method and related devices for hiding system function calls provided by the embodiments of the present invention have the following beneficial effects: a code segment is created by traversing an array to obtain the length of a newly added code segment, the system function assembly code is copied to the created code segment, and the system function can be directly called from the created code segment after the calling instruction is modified. For functions such as registry operations that must be implemented by calling system functions, all functions are completed in the program module and the calls to the system functions will not be exposed to the outside world, thereby sacrificing the size of the program package in exchange for security, and implementing the system function call without call in the core code.
[0228] As described above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.< / systemcall> < / importitem>
Claims
1. A method for hiding system function calls in program core code, characterized in that: include: Get any imported function by parsing the import table; Traverse the program module, obtain any function and the memory address of calling any function, and filter out the system function in any function; Modify the import table so that the import table does not import any system function; and creating a code segment in the program, and copying the code of any system function to the code segment; and modifying the instruction for calling the system function into an instruction for calling any system function in the created code segment, so as to achieve hiding of the system function call; Also includes: According to any of the import functions, create an import function list; Establish multiple structure objects to store import items corresponding to each import function; wherein the import items include the module name of the system and the function name of the module, and the memory address of the import function; Establishing a first array to store the structure object; The traversal program module obtains any function and calls the memory address of any function, specifically including: Traversing the program module, finding any function according to the function header assembly code features and the function tail assembly code features; Obtaining a function address of any one of the functions, and establishing a second array to store the function address of any one of the functions; The step of selecting a system function from any of the functions specifically includes: Mark any call instruction in any function and obtain a memory address, wherein the memory address is an address code included in the call instruction; Calculate the real function address according to the memory address; Traversing the second array, if the memory address matches the function address in the second array, determining that the corresponding function is a system function; Establishing a third array to record the real function address of the screened system function, the module name corresponding to the system function and the function name of the module; The real function address calculation formula is: Real dwoffset = dwoffset - DWORD dwoffset; Among them, Real dwoffset is the real function address, dwoffset is the memory address, DWORD dwoffset = *(DWORD*)(call_address + 1); DWORD dwoffset is the offset byte, *(DWORD*)(call_address+1) is the byte length of the address of the current instruction in the memory; call_address, represents the offset address of the current instruction in the memory, in call_address+1, +1 is because the call address instruction is 5 bytes long, call occupies one byte, and the following offset data occupies 4 bytes; The modifying the import table so that the import table does not import any system function specifically includes: Obtaining DOS header data of the import table, and obtaining NT header data of the import table; According to the NT header data of the import table, obtaining the starting address of the import table; Traverse the result data of the import table, and clear the dwFileOriFirstThunk data value in the result data of the import table to zero; The code segment is created in the program, and the code of any system function is copied to the created code segment, specifically including: Traversing the third array to obtain the code lengths of all system functions; Based on the code length of all system functions, obtain the code length of all system functions; The length of the newly added code segment is obtained by summing up the code length of all system functions; Creating a code segment according to the length of the newly added code; Traverse the first array, obtain system module names and function names and load corresponding modules; And obtain the memory address and starting address of all system functions in the module through the system function, and then obtain the offset of the system function in the module; And the assembly code length of the function is calculated through the assembly code features of the function header and the assembly code features of the function tail; Copy the assembly code of all system functions to the creation code segment; The step of modifying the instruction for calling the system function into an instruction for calling any system function in the created code segment specifically includes: Read the relocation data in the relocation table; Searching for a relocation item of the assembly code of the system function in the relocation data; Copy the found relocation item to the code segment, and convert the address data in the relocation item into data in the code segment; If the global data or global table of the introduced system module exists in the relocation item, the global data or global table of the introduced system module is copied into the code segment, and the address data in the relocation item is converted into data in the code segment; The instruction for calling the system function in the code segment is modified to call the system function copied in the newly added code segment.
2. A device for hiding system function calls in program core code, characterized in that: The method for implementing the method of hiding system function calls as claimed in claim 1 comprises: Get module, which is used to get any imported function by parsing the import table; A traversal module, which is used to traverse the program, obtain any function and the memory address of calling any function, and filter out system functions in any function; A modification module, used for modifying the import table so that the import table does not import any system function; Create a module, which is used to create a code segment in the program and copy the code of any system function to the created code segment; The calling module is used to modify the instruction of calling the system function into the instruction of calling any system function in the created code segment, so as to achieve hiding of the system function call.
3. An electronic device, comprising an application processor and a memory, characterized in that: The processor is used to implement the steps of the method for hiding system function calls as claimed in claim 1 when implementing the computer management program stored in the memory.
4. A computer-readable storage medium having a computer management program stored thereon, characterized in that: When the computer management program is executed by the processor, the steps of the method for hiding system function calls as claimed in claim 1 are implemented.
