CN110058861B - Source code processing method and device, storage medium and electronic equipment - Google Patents

Source code processing method and device, storage medium and electronic equipment Download PDF

Info

Publication number
CN110058861B
CN110058861B CN201910319622.3A CN201910319622A CN110058861B CN 110058861 B CN110058861 B CN 110058861B CN 201910319622 A CN201910319622 A CN 201910319622A CN 110058861 B CN110058861 B CN 110058861B
Authority
CN
China
Prior art keywords
replaced
name
random
intermediate language
function
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
CN201910319622.3A
Other languages
Chinese (zh)
Other versions
CN110058861A (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.)
Tongdun Network Technology Co.,Ltd.
Original Assignee
Tongdun Holdings 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 Tongdun Holdings Co Ltd filed Critical Tongdun Holdings Co Ltd
Priority to CN201910319622.3A priority Critical patent/CN110058861B/en
Publication of CN110058861A publication Critical patent/CN110058861A/en
Application granted granted Critical
Publication of CN110058861B publication Critical patent/CN110058861B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The embodiment of the invention relates to a source code processing method and device, a storage medium and electronic equipment, belonging to the technical field of software, wherein the method comprises the following steps: compiling a source code to be processed into an intermediate language, and traversing the intermediate language to obtain a function name to be replaced and/or a global variable name to be replaced; generating a random function name corresponding to the function name to be replaced and/or a random variable name corresponding to the global variable name to be replaced; replacing the function name to be replaced and/or the global variable name to be replaced in the intermediate language by using the random function name and/or the random variable name; and recompiling the replaced intermediate language to obtain an object code file. The method improves the efficiency of replacing the function name to be replaced and/or the global variable name to be replaced, and saves labor cost and time cost.

Description

Source code processing method and device, storage medium and electronic equipment
Technical Field
The embodiment of the invention relates to the technical field of software, in particular to a source code processing method, a source code processing device, a computing node readable storage medium and electronic equipment.
Background
With the development of the mobile internet, the speed of various software development and update iterations is also faster and faster. In the existing software development process, in order to improve the writing speed of software, when a developer writes a function or a variable, most of the functions or the variables are named through easily understood words.
However, since the function or the variable is named by a word which is easy to understand, after the function or the variable is compiled into the target file and is decompiled by the decompilation tool, an attacker can easily guess what function the function realizes and what meaning the variable represents according to the named meaning of the function or the variable, and therefore, the risk of source code leakage exists to a certain extent.
In order to solve the above problems, most of the prior art is solved by manually renaming the function or variable name by a developer. However, this method has the following drawbacks: on one hand, because the developers are required to rename manually, the efficiency is low, and much labor cost and time cost are wasted; on the other hand, the result of renaming is low in accuracy due to missed or wrong naming caused by objective reasons; meanwhile, an attacker can easily guess the function according to the meaning of missed naming or wrong naming, and further the problems of source code leakage and the like are caused.
Therefore, a new source code processing method and apparatus are needed.
It is to be noted that the information invented in the above background section is only for enhancing the understanding of the background of the present invention, and therefore, may include information that does not constitute prior art known to those of ordinary skill in the art.
Disclosure of Invention
The invention aims to provide a source code processing method, a source code processing device, a computing node readable storage medium and electronic equipment, and further to overcome the problem of low accuracy of renaming results caused by the limitations and defects of the related technology at least to a certain extent.
According to an aspect of the present disclosure, there is provided a source code processing method, including: compiling a source code to be processed into an intermediate language, and traversing the intermediate language to obtain a function name to be replaced and/or a global variable name to be replaced; generating a random function name corresponding to the function name to be replaced and/or a random variable name corresponding to the global variable name to be replaced; replacing the function name to be replaced and/or the global variable name to be replaced in the intermediate language by using the random function name and/or the random variable name; and recompiling the replaced intermediate language to obtain an object code file.
In an exemplary embodiment of the present disclosure, traversing the intermediate language to obtain a name of a function to be replaced and/or a name of a global variable to be replaced includes: compiling an open source code of the LLVM to obtain a dynamic library of the LLVM; and analyzing the intermediate language by using the dynamic library, and traversing the analyzed intermediate language to obtain the name of the function to be replaced and/or the name of the global variable to be replaced.
In an exemplary embodiment of the present disclosure, generating a random function name corresponding to the function name to be replaced, and/or generating a random variable name corresponding to the global variable name to be replaced includes: configuring a random generating function; and calling the random generation function, and generating a random function name corresponding to the function name to be replaced and/or a random variable name corresponding to the global variable name to be replaced by utilizing the random generation function.
In an exemplary embodiment of the present disclosure, after generating a random function name corresponding to the function name to be replaced, and/or a random variable name corresponding to the global variable name to be replaced, the source code processing method further includes: establishing a first mapping relation between the function name to be replaced and the random function name; and/or establishing a second mapping relation between the global variable name to be replaced and the random variable name; and storing the first mapping relation and/or the second mapping relation.
In an exemplary embodiment of the present disclosure, recompiling the replaced intermediate language to obtain the object code file includes: traversing the replaced intermediate language again, and judging whether the replaced intermediate language comprises a function name to be replaced and/or a global variable name to be replaced; and if the replaced intermediate language does not comprise the function name to be replaced and/or the global variable name to be replaced, recompiling the replaced intermediate language to obtain the object code file.
In an exemplary embodiment of the present disclosure, after recompiling the replaced intermediate language to obtain the object code file, the source code processing method further includes: searching whether the next intermediate language corresponding to the intermediate language comprises the same function name to be replaced and/or global variable name to be replaced; if the same function name to be replaced and/or the global variable name to be replaced are included, judging whether the random function name and/or the random variable name replacing the same function name to be replaced and/or the global variable name to be replaced in the next replaced intermediate language is the same; and if the random function name and/or the random variable name replacing the same function name to be replaced and/or the global variable name to be replaced are/is the same, recompiling the replaced next intermediate language to obtain a next object code file.
In an exemplary embodiment of the present disclosure, generating a random function name corresponding to the function name to be replaced, and/or generating a random variable name corresponding to the global variable name to be replaced further includes: searching whether a random function name corresponding to the function name to be replaced exists in the first mapping relation and/or searching whether a random variable name corresponding to the global variable name to be replaced exists in the second mapping relation; and if the global variable name does not exist, generating a random function name corresponding to the function name to be replaced and/or a random variable name corresponding to the global variable name to be replaced.
According to an aspect of the present disclosure, there is provided a source code processing apparatus including: the intermediate language traversal module is used for compiling the source code to be processed into an intermediate language and traversing the intermediate language to obtain a function name to be replaced and/or a global variable name to be replaced; the generating module is used for generating a random function name corresponding to the function name to be replaced and/or a random variable name corresponding to the global variable name to be replaced; the replacing module is used for replacing the function name to be replaced and/or the global variable name to be replaced in the intermediate language by using the random function name and/or the random variable name; and the compiling module is used for recompiling the replaced intermediate language to obtain the object code file.
According to an aspect of the present disclosure, there is provided a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements a source code processing method as described in any one of the above.
According to an aspect of the present disclosure, there is provided an electronic device including: a processor; and
a memory for storing executable instructions of the processor; wherein the processor is configured to perform any one of the above-described source code processing methods via execution of the executable instructions.
The embodiment of the invention provides a source code processing method, which comprises the steps of obtaining a function name to be replaced and/or a global variable name to be replaced by traversing an intermediate language; generating a random function name corresponding to the function name to be replaced and/or a random variable name corresponding to the global variable name to be replaced; then, replacing the function name to be replaced and/or the global variable name to be replaced in the intermediate language by using the random function name and/or the random variable name; finally, recompiling the replaced intermediate language to obtain an object code file; on one hand, the names of the functions to be replaced and/or the names of the global variables to be replaced are obtained by traversing the intermediate language; generating a random function name corresponding to the function name to be replaced and/or a random variable name corresponding to the global variable name to be replaced; then, the random function name and/or the random variable name are/is used for replacing the function name to be replaced and/or the global variable name to be replaced in the intermediate language, so that the problems that in the prior art, due to the fact that a developer needs to rename manually, the efficiency is low, much labor cost and time cost need to be wasted are solved, the efficiency of replacing the function name to be replaced and/or the global variable name to be replaced is improved, and meanwhile, the labor cost and the time cost are saved; on the other hand, the problem that renaming result accuracy is low due to missed naming or wrong naming caused by objective reasons in the prior art is solved, and the accuracy of replacing the function name to be replaced and/or the global variable name to be replaced is improved; on the other hand, the problem that an attacker guesses the function according to the missed or wrong naming meaning due to missed or wrong naming caused by objective reasons in the prior art, source code leakage is further caused, and the like is solved, and the safety of the source code is improved.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the invention, as claimed.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and together with the description, serve to explain the principles of the invention. It is obvious that the drawings in the following description are only some embodiments of the invention, and that for a person skilled in the art, other drawings can be derived from them without inventive effort.
Fig. 1 schematically shows a flow chart of a source code processing method according to an example embodiment of the present disclosure.
Fig. 2 schematically shows a flow chart of another source code processing method according to an example embodiment of the present disclosure.
Fig. 3 schematically illustrates a flowchart of a method for generating a random function name corresponding to the function name to be replaced, and/or a random variable name corresponding to the global variable name to be replaced, according to an example embodiment of the present disclosure.
Fig. 4 schematically illustrates a flow chart of another source code processing method according to an example embodiment of the present disclosure.
Fig. 5 schematically shows a flow chart of another source code processing method according to an example embodiment of the present disclosure.
Fig. 6 schematically shows a block diagram of a source code processing apparatus according to an exemplary embodiment of the present disclosure.
Fig. 7 schematically illustrates an electronic device for implementing the above-described source code processing method according to an exemplary embodiment of the present disclosure.
Fig. 8 schematically illustrates a computer-readable storage medium for implementing the above-described source code processing method according to an exemplary embodiment of the present disclosure.
Detailed Description
Example embodiments will now be described more fully with reference to the accompanying drawings. Example embodiments may, however, be embodied in many different forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the concept of example embodiments to those skilled in the art. The described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to provide a thorough understanding of embodiments of the invention. One skilled in the relevant art will recognize, however, that the invention may be practiced without one or more of the specific details, or with other methods, components, devices, steps, and so forth. In other instances, well-known technical solutions have not been shown or described in detail to avoid obscuring aspects of the invention.
Furthermore, the drawings are merely schematic illustrations of the invention and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and thus their repetitive description will be omitted. Some of the block diagrams shown in the figures are functional entities and do not necessarily correspond to physically or logically separate entities. These functional entities may be implemented in the form of software, or in one or more hardware modules or integrated circuits, or in different networks and/or processor devices and/or microcontroller devices.
In the present exemplary embodiment, a source code processing method is first provided, where the method may be run in a server, a server cluster, a cloud server, or the like, and may also be run in an equipment terminal; of course, those skilled in the art may also operate the method of the present invention on other platforms as needed, and this is not particularly limited in this exemplary embodiment. Referring to fig. 1, the source code processing method may include the steps of:
step S110, compiling the source code to be processed into an intermediate language, and traversing the intermediate language to obtain a function name to be replaced and/or a global variable name to be replaced.
And S120, generating a random function name corresponding to the function name to be replaced and/or a random variable name corresponding to the global variable name to be replaced.
And S130, replacing the function name to be replaced and/or the global variable name to be replaced in the intermediate language by using the random function name and/or the random variable name.
And S140, recompiling the replaced intermediate language to obtain an object code file.
In the source code processing method, on one hand, the function name to be replaced and/or the global variable name to be replaced are obtained by traversing the intermediate language; generating a random function name corresponding to the function name to be replaced and/or a random variable name corresponding to the global variable name to be replaced; then, the random function name and/or the random variable name are/is used for replacing the function name to be replaced and/or the global variable name to be replaced in the intermediate language, so that the problems that in the prior art, due to the fact that a developer needs to rename manually, the efficiency is low, much labor cost and time cost need to be wasted are solved, the efficiency of replacing the function name to be replaced and/or the global variable name to be replaced is improved, and meanwhile, the labor cost and the time cost are saved; on the other hand, the problem that renaming result accuracy is low due to missed naming or wrong naming caused by objective reasons in the prior art is solved, and the accuracy of replacing the function name to be replaced and/or the global variable name to be replaced is improved; on the other hand, the problem that an attacker guesses the function according to the missed or wrong naming meaning due to missed or wrong naming caused by objective reasons in the prior art, source code leakage is further caused, and the like is solved, and the safety of the source code is improved.
Hereinafter, each step in the above-described source code processing method in the present exemplary embodiment will be explained and explained in detail with reference to the drawings.
In step S110, the source code to be processed is compiled into an intermediate language, and the intermediate language is traversed to obtain a name of a function to be replaced and/or a name of a global variable to be replaced.
In the present exemplary embodiment, first, LLVM is explained and/or illustrated. LLVM is a framework system that constructs a compiler (compiler), which can be used as a background for multi-language compilers. Moreover, the method can also carry out compile time optimization, link optimization, online compile optimization and code generation of the program language. Furthermore, the source code to be processed can be compiled into an intermediate language by using the LLVM, and then the intermediate language is traversed to obtain the name of the function to be replaced and/or the name of the global variable to be replaced.
Specifically, traversing the intermediate language to obtain a name of a function to be replaced and/or a name of a global variable to be replaced may include: firstly, compiling an open source code of an LLVM (Linked virtual machine) to obtain a dynamic library of the LLVM; and then, analyzing the intermediate language by using the dynamic library, and traversing the analyzed intermediate language to obtain the function name to be replaced and/or the global variable name to be replaced. In detail:
firstly, compiling an open source code of the LLVM to generate a libLLVM.dylib dynamic library; then, finding out a compiling source file generation in a compiling project, and generating a compiling command of o; finally, modifying the compiling command, adding a compiling parameter-emit-llvm to generate an intermediate language (for example, bc file) of the source code to be processed; further, after the intermediate language is generated, the libllvm, dylib dynamic library may be integrated to parse the intermediate language, and then traverse all function names and/or global variable names (to-be-replaced function names and/or global variable names) in the parsed intermediate language that need to be obfuscated.
It should be noted that, if only a function name to be replaced exists in a certain source code or only a global variable name to be replaced exists, only a random function name or a random variable name corresponding to the function name or the global variable name to be replaced needs to be generated, and similar processing is performed if similar conditions exist below, and therefore, description is omitted.
In step S120, a random function name corresponding to the function name to be replaced and/or a random variable name corresponding to the global variable name to be replaced is generated.
In the present exemplary embodiment, first, a random generation function is configured; and then, calling the random generation function, and generating a random function name corresponding to the function name to be replaced and/or a random variable name corresponding to the global variable name to be replaced by using the random generation function. It should be added that, in order to further improve the security of the source code, and avoid that an attacker guesses the function according to the meaning of missed naming or wrong naming due to missed naming or wrong naming caused by objective reasons, and further cause problems such as source code leakage, a random generation function may be configured; when the random function name and/or the random variable name need to be generated, the random generation function can be used for generating the random function name corresponding to the function name to be replaced and/or the random variable name corresponding to the global variable name to be replaced.
In step S130, replacing the function name to be replaced and/or the global variable name to be replaced in the intermediate language with the random function name and/or the random variable name.
In this example embodiment, after the random function name and/or the random variable name are obtained, the random function name corresponding to each function name to be replaced and/or the random variable name corresponding to each global variable name to be replaced may be used to replace the function name to be replaced and/or the global variable name to be replaced in the intermediate language. Through the mode, the problems that in the prior art, due to the fact that a developer needs to rename manually, efficiency is low, more labor cost and time cost need to be wasted are solved, efficiency of replacing the function names to be replaced and/or the global variable names to be replaced is improved, and labor cost and time cost are saved.
In step S140, the replaced intermediate language is recompiled to obtain an object code file.
In the present exemplary embodiment, first, the replaced intermediate language is traversed again, and it is determined whether the replaced intermediate language includes a function name to be replaced and/or a global variable name to be replaced; secondly, if the replaced intermediate language does not comprise the name of the function to be replaced and/or the name of the global variable to be replaced, recompiling the replaced intermediate language to obtain the object code file. By the method, the function name and/or the global variable name which are not replaced are ensured to be not included in the intermediate language, and the safety of the source code is further improved.
Further, after obtaining the object code file, the source code processing method may further include: and linking the target code files to obtain a file to be operated. For example, the unmarked code file may be an o file; when all the processing source codes with processing in the whole project are processed, a plurality of obtained o files can be linked to obtain a target file; the target file is an obfuscated file.
Fig. 2 schematically illustrates another source code processing method according to an example embodiment of the present disclosure. Referring to fig. 2, the source code processing method may further include step S210, step S220, and step S230, which will be described in detail below.
In step S210, a first mapping relationship between the function name to be replaced and the random function name is established. And/or
In step S220, a second mapping relationship between the global variable name to be replaced and the random variable name is established.
In step S230, the first mapping relationship and/or the second mapping relationship are stored.
Next, steps S210 to S230 will be explained and explained. Firstly, after the random function name and/or the random variable name are/is obtained, a first mapping relation between each function to be replaced and the random function name corresponding to the function to be replaced can be respectively established; and establishing a second mapping relation between the global variable names to be replaced and the random variable names corresponding to the global variable names to be replaced, and then storing the first mapping relation and/or the second mapping relation. By the method, when the same function name to be replaced and/or the global variable name to be replaced are/is met in the same project, the existing random function name and/or the existing random variable name can be directly used for replacing the same function name and/or the existing random variable name according to the mapping relation, and on one hand, the problem of low efficiency caused by the need of regeneration is avoided; on the other hand, the random function names and/or the random variable names used by the same function name to be replaced and/or the random variable name to be replaced in the same project can be ensured to be the same, the uniqueness of one variable name can be kept, and the accuracy of replacing the function name to be replaced and/or the global variable name to be replaced is improved.
Fig. 3 schematically illustrates a flowchart of a method for generating a random function name corresponding to the function name to be replaced, and/or a random variable name corresponding to the global variable name to be replaced, according to an example embodiment of the present disclosure. Referring to fig. 3, generating a random function name corresponding to the function name to be replaced, and/or generating a random variable name corresponding to the global variable name to be replaced may include step S310 and step S320, which will be described in detail below.
In step S310, it is searched whether a random function name corresponding to the function name to be replaced exists in the first mapping relationship, and/or whether a random variable name corresponding to the global variable name to be replaced exists in the second mapping relationship.
In step S320, if not, a random function name corresponding to the function name to be replaced and/or a random variable name corresponding to the global variable name to be replaced are generated.
Further, in the example embodiment shown in fig. 3, if a random function corresponding to the function name to be replaced exists in the first mapping relationship and/or a random variable name corresponding to the global variable name to be replaced exists in the second mapping relationship, the random function and the random variable name may be directly obtained from the first mapping relationship and/or the second mapping relationship. Specifically, the query may be performed based on the first mapping relationship and/or the second mapping relationship. By the method, the efficiency of replacing the function name to be replaced and/or the global variable name to be replaced is further improved.
Fig. 4 schematically illustrates another source code processing method flow diagram according to an example embodiment of the present disclosure. Referring to fig. 4, the source code processing method may further include step S410, step S420, and step S430, which will be described in detail below.
In step S410, it is searched whether the next intermediate language corresponding to the intermediate language includes the same function name to be replaced and/or global variable name to be replaced.
In step S420, if the same function name to be replaced and/or global variable name to be replaced are included, it is determined whether the random function name and/or random variable name replacing the same function name to be replaced and/or global variable name in the next intermediate language after replacement are the same.
In step S430, if the random function name and/or the random variable name replacing the same function name and/or global variable name to be replaced are/is the same, recompiling the replaced intermediate language to obtain the next object code file.
In the example embodiment shown in fig. 4, if the random function name and/or the random variable name replacing the same replacement function name and/or the global variable name to be replaced are not the same, they need to be modified. Moreover, the same project can comprise a plurality of source codes to be processed and further can comprise a plurality of intermediate languages; therefore, the same function name to be replaced and/or the random function name and/or the random variable name used by the random variable name to be replaced in the intermediate language of the same source code to be processed can be judged to be the same through the method; and, it is also necessary to determine that the same function name to be replaced and/or the random function name and/or the random variable name used by the random variable name to be replaced in the intermediate language of other source codes to be processed are the same.
Further, when replacing the name of the function to be replaced and/or the name of the global variable to be replaced of one of the intermediate files, the function to be replaced and/or the global variable to be replaced having the same name in the other intermediate files need to be searched, and then the searched function to be replaced and/or global variable to be replaced having the same name are replaced together. By the method, the same function name to be replaced and/or the random function name and/or the random variable name used by the random variable name to be replaced in the same item can be ensured to be the same, and the uniqueness of the variable name can be kept. It should be added here that, in order to further improve the security of the source code, the random function names and/or random variable names corresponding to the same function name to be replaced and/or global variable name to be replaced in different items are different.
Fig. 5 schematically illustrates another source code processing method according to an example embodiment of the present disclosure. Referring to fig. 5, the source code processing method may include the steps of:
step S510, compiling a source file to be processed into an intermediate language;
step S520, analyzing the intermediate language by integrating a libLLVM-dylib dynamic library, and traversing all function names and global variable names which need to be confused in the analyzed intermediate language;
step S530, judging whether a random function name corresponding to a function name needing to be confused and/or a random variable name corresponding to a global variable name exist in the first mapping relation and/or the second mapping relation; if yes, jumping to step S550; if not, jumping to step S540;
step S540, calling a random function, and generating a random function name corresponding to a function name needing to be confused and/or a random variable name corresponding to a global variable name by using the random function;
step S550, replacing the function name and/or the global variable name to be obfuscated by using the random function name and/or the random variable name;
step S560, compiling the replaced intermediate language to generate an o file; and linking the plurality of o files to form the target file.
The present disclosure also provides a source code processing apparatus. Referring to fig. 6, the source code processing apparatus may include an intermediate language traversal module 610, a generation module 620, a replacement module 630, and a compilation module 640. Wherein:
the intermediate language traversal module 610 may be configured to compile a source code to be processed into an intermediate language by using LLVM, and traverse the intermediate language to obtain a name of a function to be replaced and/or a name of a global variable to be replaced.
The generating module 620 may be configured to generate a random function name corresponding to the function name to be replaced, and/or a random variable name corresponding to the global variable name to be replaced.
The replacing module 630 may be configured to replace the function name to be replaced and/or the global variable name to be replaced in the intermediate language with the random function name and/or the random variable name.
The compiling module 640 may be configured to recompile the replaced intermediate language to obtain an object code file.
In an exemplary embodiment, the generation module 620 may be further configured to: configuring a random generating function; and calling the random generation function, and generating a random function name corresponding to the function name to be replaced and/or a random variable name corresponding to the global variable name to be replaced by utilizing the random generation function.
In an exemplary embodiment, the source code processing apparatus may further include a first mapping relationship establishing module and/or a second mapping relationship establishing module, and a storage module. The first mapping relation establishing module is used for establishing a first mapping relation between the function name to be replaced and the random function name. The second mapping relation establishing module is used for establishing a second mapping relation between the global variable name to be replaced and the random variable name. The storage module is used for storing the first mapping relation and/or the second mapping relation.
In an exemplary embodiment, the compiling module 640 may be further configured to: traversing the replaced intermediate language again, and judging whether the replaced intermediate language comprises a function name to be replaced and/or a global variable name to be replaced; and if the replaced intermediate language does not comprise the function name to be replaced and/or the global variable name to be replaced, recompiling the replaced intermediate language to obtain the object code file.
In an exemplary embodiment, the source code processing apparatus may further include: the searching module can be used for searching whether the next intermediate language corresponding to the intermediate language comprises the same function name to be replaced and/or a global variable name to be replaced; the judging module may be configured to judge whether the random function name and/or the random variable name replacing the same function name and/or global variable name to be replaced in the replaced next intermediate language is the same if the function name and/or the global variable name to be replaced are the same; and the processing module can be used for recompiling the replaced intermediate language to obtain the next object code file if the random function name and/or the random variable name replacing the same function name and/or global variable name to be replaced are the same.
In an exemplary embodiment, the generation module 620 may be further configured to: searching whether a random function name corresponding to the function name to be replaced exists in the first mapping relation and/or searching whether a random variable name corresponding to the global variable name to be replaced exists in the second mapping relation; and if the global variable name does not exist, generating a random function name corresponding to the function name to be replaced and/or a random variable name corresponding to the global variable name to be replaced.
The details of each module in the source code processing apparatus have been described in detail in the corresponding source code processing method, and therefore are not described herein again.
It should be noted that although in the above detailed description several modules or units of the device for action execution are mentioned, such a division is not mandatory. Indeed, the features and functionality of two or more modules or units described above may be embodied in one module or unit, according to embodiments of the invention. Conversely, the features and functions of one module or unit described above may be further divided into embodiments by a plurality of modules or units.
Moreover, although the steps of the methods of the present invention are depicted in the drawings in a particular order, this does not require or imply that the steps must be performed in this particular order, or that all of the depicted steps must be performed, to achieve desirable results. Additionally or alternatively, certain steps may be omitted, multiple steps combined into one step execution, or one step broken down into multiple step executions, etc.
Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein may be implemented by software, or by software in combination with necessary hardware. Therefore, the technical solution according to the embodiment of the present invention can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a usb disk, a removable hard disk, etc.) or on a network, and includes several instructions to make a computing device (which can be a personal computer, a server, a mobile terminal, or a network device, etc.) execute the method according to the embodiment of the present invention.
In an exemplary embodiment of the present invention, there is also provided an electronic device capable of implementing the above method.
As will be appreciated by one skilled in the art, aspects of the present invention may be embodied as a system, method or program product. Thus, various aspects of the invention may be embodied in the form of: an entirely hardware embodiment, an entirely software embodiment (including firmware, microcode, etc.) or an embodiment combining hardware and software aspects that may all generally be referred to herein as a "circuit," module "or" system.
An electronic device 700 according to this embodiment of the invention is described below with reference to fig. 7. The electronic device 700 shown in fig. 7 is only an example and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 7, electronic device 700 is embodied in the form of a general purpose computing device. The components of the electronic device 700 may include, but are not limited to: the at least one processing unit 710, the at least one memory unit 720, and a bus 730 that couples various system components including the memory unit 720 and the processing unit 710.
Wherein the storage unit stores program code that is executable by the processing unit 710 such that the processing unit 710 performs the steps according to various exemplary embodiments of the present invention as described in the above section "exemplary method" of the present specification. For example, the processing unit 710 may perform the steps as shown in fig. 1: step S110, compiling a source code to be processed into an intermediate language, and traversing the intermediate language to obtain a function name to be replaced and/or a global variable name to be replaced; s120, generating a random function name corresponding to the function name to be replaced and/or a random variable name corresponding to the global variable name to be replaced; s130, replacing the function name to be replaced and/or the global variable name to be replaced in the intermediate language by using the random function name and/or the random variable name; and S140, recompiling the replaced intermediate language to obtain an object code file.
The storage unit 720 may include readable media in the form of volatile memory units, such as a random access memory unit (RAM)7201 and/or a cache memory unit 7202, and may further include a read only memory unit (ROM) 7203.
The storage unit 720 may also include a program/utility 7204 having a set (at least one) of program modules 7205, such program modules 7205 including, but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which, or some combination thereof, may comprise an implementation of a network environment.
Bus 730 may be any representation of one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
The electronic device 700 may also communicate with one or more external devices 770 (e.g., keyboard, pointing device, bluetooth device, etc.), with one or more devices that enable a user to interact with the electronic device 700, and/or with any devices (e.g., router, modem, etc.) that enable the electronic device 700 to communicate with one or more other computing devices. Such communication may occur via an input/output (I/O) interface 750. Also, the electronic device 700 may communicate with one or more networks (e.g., a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network such as the internet) via the network adapter 760. As shown, the network adapter 760 communicates with the other modules of the electronic device 700 via the bus 730. It should be appreciated that although not shown in the figures, other hardware and/or software modules may be used in conjunction with the electronic device 700, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, among others.
Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein may be implemented by software, or by software in combination with necessary hardware. Therefore, the technical solution according to the embodiment of the present invention can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a usb disk, a removable hard disk, etc.) or on a network, and includes several instructions to make a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) execute the method according to the embodiment of the present invention.
In an exemplary embodiment of the present invention, there is also provided a computer-readable storage medium having stored thereon a program product capable of implementing the above-described method of the present specification. In some possible embodiments, aspects of the invention may also be implemented in the form of a program product comprising program code means for causing a terminal device to carry out the steps according to various exemplary embodiments of the invention described in the above section "exemplary methods" of the present description, when said program product is run on the terminal device.
Referring to fig. 8, a program product 800 for implementing the above method according to an embodiment of the present invention is described, which may employ a portable compact disc read only memory (CD-ROM) and include program code, and may be run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited in this regard and, in the present document, a 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.
The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, 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 (a non-exhaustive list) of the readable storage medium include: an electrical connection having one or more wires, a portable disk, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
A computer readable signal medium may include a propagated data signal with 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 readable signal medium may also be any readable medium that is not a 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 readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, C + + or the like 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 computing device, partly on the user's device, as a stand-alone software package, partly on the user's computing device and partly on a remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., through the internet using an internet service provider).
Furthermore, the above-described figures are merely schematic illustrations of processes involved in methods according to exemplary embodiments of the invention, and are not intended to be limiting. It will be readily understood that the processes shown in the above figures are not intended to indicate or limit the chronological order of the processes. In addition, it is also readily understood that these processes may be performed synchronously or asynchronously, e.g., in multiple modules.
Other embodiments of the invention will be apparent to those skilled in the art from consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the invention following, in general, the principles of the invention and including such departures from the present disclosure as come within known or customary practice within the art to which the invention pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the invention being indicated by the following claims.

Claims (8)

1. A method for processing source code, comprising:
compiling a source code to be processed into an intermediate language, and traversing the intermediate language to obtain a function name to be replaced and/or a global variable name to be replaced; wherein the intermediate language comprises a compiling parameter;
generating a random function name corresponding to the function name to be replaced and/or a random variable name corresponding to the global variable name to be replaced;
replacing the function name to be replaced and/or the global variable name to be replaced in the intermediate language by using the random function name and/or the random variable name;
recompiling the replaced intermediate language to obtain an object code file; linking a plurality of target code files to obtain a file to be operated;
searching whether the next intermediate language corresponding to the intermediate language comprises the same function name to be replaced and/or global variable name to be replaced;
if the same function name to be replaced and/or the global variable name to be replaced are included, judging whether the random function name and/or the random variable name replacing the same function name to be replaced and/or the global variable name to be replaced in the next replaced intermediate language is the same;
if the random function name and/or the random variable name replacing the same function name and/or global variable name to be replaced are/is the same, recompiling the replaced next intermediate language to obtain a next object code file;
traversing the intermediate language to obtain a name of a function to be replaced and/or a name of a global variable to be replaced comprises:
compiling an open source code of the LLVM to obtain a dynamic library of the LLVM;
and analyzing the intermediate language by using the dynamic library, and traversing the analyzed intermediate language to obtain the name of the function to be replaced and/or the name of the global variable to be replaced.
2. The source code processing method according to claim 1, wherein generating a random function name corresponding to the function name to be replaced, and/or a random variable name corresponding to the global variable name to be replaced comprises:
configuring a random generating function;
and calling the random generation function, and generating a random function name corresponding to the function name to be replaced and/or a random variable name corresponding to the global variable name to be replaced by utilizing the random generation function.
3. The source code processing method according to claim 1, wherein after generating a random function name corresponding to the function name to be replaced, and/or a random variable name corresponding to the global variable name to be replaced, the source code processing method further comprises:
establishing a first mapping relation between the function name to be replaced and the random function name; and/or
Establishing a second mapping relation between the global variable name to be replaced and the random variable name;
and storing the first mapping relation and/or the second mapping relation.
4. The source code processing method of claim 1, wherein recompiling the replaced intermediate language to obtain the object code file comprises:
traversing the replaced intermediate language again, and judging whether the replaced intermediate language comprises a function name to be replaced and/or a global variable name to be replaced;
and if the replaced intermediate language does not comprise the function name to be replaced and/or the global variable name to be replaced, recompiling the replaced intermediate language to obtain the object code file.
5. The source code processing method according to claim 3, wherein generating a random function name corresponding to the function name to be replaced, and/or a random variable name corresponding to the global variable name to be replaced further comprises:
searching whether a random function name corresponding to the function name to be replaced exists in the first mapping relation and/or searching whether a random variable name corresponding to the global variable name to be replaced exists in the second mapping relation;
and if the global variable name does not exist, generating a random function name corresponding to the function name to be replaced and/or a random variable name corresponding to the global variable name to be replaced.
6. A source code processing apparatus, comprising:
the intermediate language traversal module is used for compiling the source code to be processed into an intermediate language and traversing the intermediate language to obtain a function name to be replaced and/or a global variable name to be replaced; wherein the intermediate language comprises a compiling parameter;
the generating module is used for generating a random function name corresponding to the function name to be replaced and/or a random variable name corresponding to the global variable name to be replaced;
the replacing module is used for replacing the function name to be replaced and/or the global variable name to be replaced in the intermediate language by using the random function name and/or the random variable name;
the compiling module is used for recompiling the replaced intermediate language to obtain an object code file; linking a plurality of target code files to obtain a file to be operated;
the searching module can be used for searching whether the next intermediate language corresponding to the intermediate language comprises the same function name to be replaced and/or a global variable name to be replaced;
the judging module may be configured to judge whether the random function name and/or the random variable name replacing the same function name and/or global variable name to be replaced in the replaced next intermediate language is the same if the function name and/or the global variable name to be replaced are the same;
the processing module can be used for recompiling the replaced intermediate language to obtain a next object code file if the random function name and/or the random variable name replacing the same function name and/or global variable name to be replaced are the same;
traversing the intermediate language to obtain a name of a function to be replaced and/or a name of a global variable to be replaced comprises:
compiling an open source code of the LLVM to obtain a dynamic library of the LLVM;
and analyzing the intermediate language by using the dynamic library, and traversing the analyzed intermediate language to obtain the name of the function to be replaced and/or the name of the global variable to be replaced.
7. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the source code processing method of any one of claims 1 to 5.
8. An electronic device, comprising:
a processor; and
a memory for storing executable instructions of the processor;
wherein the processor is configured to perform the source code processing method of any of claims 1-5 via execution of the executable instructions.
CN201910319622.3A 2019-04-19 2019-04-19 Source code processing method and device, storage medium and electronic equipment Active CN110058861B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910319622.3A CN110058861B (en) 2019-04-19 2019-04-19 Source code processing method and device, storage medium and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910319622.3A CN110058861B (en) 2019-04-19 2019-04-19 Source code processing method and device, storage medium and electronic equipment

Publications (2)

Publication Number Publication Date
CN110058861A CN110058861A (en) 2019-07-26
CN110058861B true CN110058861B (en) 2020-11-10

Family

ID=67319836

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910319622.3A Active CN110058861B (en) 2019-04-19 2019-04-19 Source code processing method and device, storage medium and electronic equipment

Country Status (1)

Country Link
CN (1) CN110058861B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110688320B (en) * 2019-09-30 2023-05-23 潍柴动力股份有限公司 Global variable detection method and device and terminal equipment
CN114461216B (en) * 2021-12-22 2022-11-11 科东(广州)软件科技有限公司 File compiling method and device, electronic equipment and storage medium
CN114546480B (en) * 2022-04-26 2022-08-19 天津所托瑞安汽车科技有限公司 Code automatic integration method, device and readable storage medium
CN116501332B (en) * 2023-06-30 2023-09-29 牛芯半导体(深圳)有限公司 Language conversion method, device, equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103218433A (en) * 2013-04-15 2013-07-24 北京邮电大学 Method and module for managing metadata applied to random access
CN103218549A (en) * 2012-01-19 2013-07-24 阿里巴巴集团控股有限公司 Method and device for encrypting and decrypting Java source code
CN105005718A (en) * 2015-06-23 2015-10-28 电子科技大学 Method for implementing code obfuscation by Markov chain
CN107908933A (en) * 2017-11-08 2018-04-13 北京顶象技术有限公司 A kind of character string encryption method based on intermediate language

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR101987048B1 (en) * 2017-09-15 2019-06-10 주식회사 티맥스 소프트 Easy-to-use type of compile-time dependency injection method and device in the java platform

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103218549A (en) * 2012-01-19 2013-07-24 阿里巴巴集团控股有限公司 Method and device for encrypting and decrypting Java source code
CN103218433A (en) * 2013-04-15 2013-07-24 北京邮电大学 Method and module for managing metadata applied to random access
CN105005718A (en) * 2015-06-23 2015-10-28 电子科技大学 Method for implementing code obfuscation by Markov chain
CN107908933A (en) * 2017-11-08 2018-04-13 北京顶象技术有限公司 A kind of character string encryption method based on intermediate language

Also Published As

Publication number Publication date
CN110058861A (en) 2019-07-26

Similar Documents

Publication Publication Date Title
CN110058861B (en) Source code processing method and device, storage medium and electronic equipment
US11151018B2 (en) Method and apparatus for testing a code file
CN112100072B (en) Static detection method, device, equipment and medium for application program code
US9928156B2 (en) Missing include suggestions for external files
CN105335137A (en) Method and device used for processing source file
CN110059456B (en) Code protection method, code protection device, storage medium and electronic equipment
CN111338925A (en) Applet test method, device and system, electronic equipment and storage medium
US8458679B2 (en) May-constant propagation
US9886251B2 (en) Optimized compiling of a template function
CN108304164B (en) Business logic development method and development system
CN109558121A (en) Development approach, device, equipment and the storage medium of interface drive program
EP3738028B1 (en) Reduced instructions to generate global variable addresses
US9135027B1 (en) Code generation and execution for dynamic programming languages
US10521206B2 (en) Supporting compiler variable instrumentation for uninitialized memory references
CN114174983B (en) Method and system for optimized automatic verification of advanced constructs
CN115080113A (en) Item code detection method and device, readable storage medium and electronic equipment
CN112882698A (en) Development environment generation method and device, computer storage medium and electronic device
CN113260976A (en) Techniques for scheduling instructions in compiled source code
CN111258910B (en) Static link library function verification method and device, electronic equipment and storage medium
US20240061764A1 (en) Stack Frame Generation for Source Code Enclosed by Macros
US11615014B2 (en) Using relocatable debugging information entries to save compile time
CN117539492A (en) Method and device for deleting redundant sentences in codes, electronic equipment and storage medium
US10359998B2 (en) Runstream generator
CN114691131A (en) Frame code file generation method and device for user interface UI file
CN113721975A (en) File construction method, system, device, electronic equipment and storage 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
GR01 Patent grant
GR01 Patent grant
TR01 Transfer of patent right

Effective date of registration: 20210913

Address after: 311121 room 607-609, building 18, No. 998, Wenyi West Road, Wuchang Street, Yuhang District, Hangzhou City, Zhejiang Province

Patentee after: Tongdun Network Technology Co.,Ltd.

Address before: Room 704, building 18, No. 998, Wenyi West Road, Wuchang Street, Yuhang District, Hangzhou City, Zhejiang Province

Patentee before: TONGDUN HOLDINGS Co.,Ltd.

TR01 Transfer of patent right