File processing method, device, computer equipment and storage medium
By replacing and compressing obfuscation processing inline code blocks in web projects, the problems of js code security and resource size in traditional web projects are solved, which improves processing efficiency and ensures the normal operation of the code.
Patent Information
- Application Number
- CN202111313454.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-08
- Publication Date
- 2025-06-24
- Estimated Expiration
- 2041-11-08
AI Technical Summary
The js code in html files in traditional web projects has security problems and large resources, and the traditional compression obfuscation processing is relatively low.
By reading the target file in the front-end project, replacing the inline code block with a preset placeholder code block, performing compression obfuscation processing, and then filling the processed file to its original position.
It improves the efficiency of web project compression obfuscation processing, ensures the normal operation of the original code, is easy to operate, and is not prone to errors.
Smart Images

Figure CN114065703B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technologies, and in particular, to a file processing method, apparatus, computer device, and storage medium. Background Art
[0002] A front-end project (Web project) is, generally speaking, a project that runs on a server, and the page is the result obtained through program operations on the server. In a traditional Web project, the html file contains js code, and this front-end js code containing business logic is directly exposed on the web page, presenting security issues. At the same time, the code is not compressed, resulting in a relatively large size of the Web project resources. Therefore, it is necessary to perform compression and obfuscation processing on the html file.
[0003] In traditional technologies, mainly the code that needs to be compressed and obfuscated in each html file is manually copied for tool compression processing, and then the compressed code is pasted into the html file to obtain the compressed and obfuscated html file.
[0004] However, the traditional compression and obfuscation processing method has the problem of low efficiency. Summary of the Invention
[0005] Based on this, in view of the above technical problems, it is necessary to provide a file processing method, apparatus, computer device, and storage medium that can improve the compression and obfuscation processing efficiency of traditional web projects.
[0006] A file processing method, the method comprising:
[0007] Reading a target file in a front-end project to obtain at least one inline code block in the target file;
[0008] Replacing each of the inline code blocks with a preset placeholder code block to obtain a replaced target file;
[0009] Performing compression and obfuscation processing on the inline code blocks of the replaced target file to obtain a compressed and obfuscated file;
[0010] Filling the compressed and obfuscated file into the corresponding positions of each of the inline code blocks to obtain a processed target file.
[0011] In one of the embodiments, the reading a target file in a front-end project to obtain at least one inline code block in the target file includes:
[0012] Reading the content of the target file in the form of a file stream to obtain a string corresponding to the target file;
[0013] The strings corresponding to the target file are searched by using a method of string matching to find features, and at least one inline code block in the target file is obtained.
[0014] In one embodiment, the step of searching the strings corresponding to the target file by using a method of string matching to find features, and obtaining at least one inline code block in the target file, includes:
[0015] Search for features in the strings corresponding to the target file by using a method of string matching to find features, and obtain at least one inline code block in the target file; wherein, the inline code block is a module identified by script features.
[0016] In one embodiment, before the step of replacing each inline code block with a preset placeholder code block to obtain a replaced target file, the method further includes:
[0017] Generate a placeholder code block for each inline code block; the placeholder code block is unique and non-repeating.
[0018] In one embodiment, the step of performing compression and obfuscation processing on the inline code blocks of the replaced target file to obtain a compressed and obfuscated file includes:
[0019] Perform compression and obfuscation processing on the inline code blocks of the replaced target file by using a preset obfuscation library to obtain the compressed and obfuscated file.
[0020] In one embodiment, the step of filling the compressed and obfuscated file into the corresponding positions of each inline code block to obtain a processed target file includes:
[0021] Perform matching and backfilling according to the file name of the compressed and obfuscated file to obtain the processed target file.
[0022] In one embodiment, the method further includes:
[0023] Obtain the target file from a preset disk directory according to the directory where the front-end project is located.
[0024] A file processing device, the device includes:
[0025] A reading module, configured to read a target file in a front-end project to obtain at least one inline code block in the target file;
[0026] A replacement module, configured to replace each inline code block with a preset placeholder code block to obtain a replaced target file;
[0027] The first processing module is used to perform compression and obfuscation processing on the inline code blocks of the replaced target file to obtain a compressed and obfuscated file;
[0028] The second processing module is used to fill the compressed and obfuscated file into the corresponding positions of each of the inline code blocks to obtain a processed target file.
[0029] A computer device includes a memory and a processor. The memory stores a computer program. When the processor executes the computer program, the following steps are implemented:
[0030] Read the target file in the front-end project to obtain at least one inline code block in the target file;
[0031] Replace each of the inline code blocks with a preset placeholder code block to obtain a replaced target file;
[0032] Perform compression and obfuscation processing on the inline code blocks of the replaced target file to obtain a compressed and obfuscated file;
[0033] Fill the compressed and obfuscated file into the corresponding positions of each of the inline code blocks to obtain a processed target file.
[0034] A computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the following steps are implemented:
[0035] Read the target file in the front-end project to obtain at least one inline code block in the target file;
[0036] Replace each of the inline code blocks with a preset placeholder code block to obtain a replaced target file;
[0037] Perform compression and obfuscation processing on the inline code blocks of the replaced target file to obtain a compressed and obfuscated file;
[0038] Fill the compressed and obfuscated file into the corresponding positions of each of the inline code blocks to obtain a processed target file.
[0039] The above file processing method, device, computer device, and storage medium replace the inline code block in the target file with a preset placeholder code block without changing the structure of the target file in the front-end project, generate an intermediate processed file, i.e., the replaced target file, perform compression and obfuscation processing on the inline code block of the replaced target file, and then fill the compressed and obfuscated file into the position of the inline code block in the target file. In this process, only the inline code block in the target file is compressed and obfuscated, without destroying the original project structure of the target file, ensuring the normal operation of the original code, being easy to operate and not prone to errors, thereby improving the efficiency of compression and obfuscation processing of the target file. Brief Description of the Drawings
[0040] Figure 1 It is an application environment diagram of the file processing method in an embodiment;
[0041] Figure 2 It is a flowchart of the file processing method in an embodiment;
[0042] Figure 3 It is a flowchart of the file processing method in another embodiment;
[0043] Figure 4 It is a flowchart of the file processing method in another embodiment;
[0044] Figure 5 It is a structural block diagram of the file processing device in an embodiment. Detailed Embodiments
[0045] In order to make the objectives, technical solutions, and advantages of the present application clearer, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0046] The file processing method provided by the embodiments of the present application can be applicable to, for example Figure 1The computer device shown. The computer device includes a processor and a memory connected by a system bus. A computer program is stored in the memory. When the processor executes the computer program, it can execute the steps of the following method embodiments. Optionally, the computer device may further include a network interface, a display screen, and an input device. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal through a network connection. Optionally, the computer device may be a server, a personal computer, a personal digital assistant, or other terminal devices, such as a tablet computer, a mobile phone, etc., or it may be a cloud or a remote server. The specific form of the computer device in the embodiments of the present application is not limited.
[0047] In one embodiment, as Figure 2 shown, a file processing method is provided. Taking the computer device in Figure 1 as an example, the method includes the following steps:
[0048] S201, Read the target file in the front-end project to obtain at least one inline code block in the target file.
[0049] In a specific embodiment, the above front-end project includes a web project. Usually, there is a large amount of html code in the files of the web project that inline references js code. Therefore, it is necessary to compress and obfuscate these js codes to reduce the size of the front-end web project resources and improve the security of the front-end code at the same time. Among them, the above front-end project is usually a web project. The extension of the above target file is.html, or.js,.css,.js,.png. The target file includes js code blocks, css code blocks, etc.; among them, the inline code block in this embodiment can be a js code block. Optionally, in this embodiment, the computer device can sequentially read the target files in the front-end project, read the content of the target file into the memory in the form of a file stream, process the content of the target file as a string, and obtain at least one inline code block in the target file. That is to say, the computer device can sequentially read the target files with the extension.html in the front-end project and obtain at least one js code block in the target file.
[0050] S202, Replace each inline code block with a preset placeholder code block to obtain a replaced target file.
[0051] Among them, the preset placeholder code block can be a placeholder or a placeholder feature value, etc., as long as it can be used to replace the inline code block in the target file. Optionally, the computer device can first obtain placeholder code blocks with the same number as the inline code blocks in the target file, and use these placeholder code blocks to sequentially replace the inline code blocks in the target file to obtain the replaced target file. Alternatively, the obtained placeholder code blocks can be used to simultaneously replace the inline code blocks in the target file to obtain the replaced target file. It can be understood that the other structures of the replaced target file remain unchanged, except that the inline code blocks are replaced with the preset placeholder code blocks.
[0052] S203. Perform compression and obfuscation processing on the inline code blocks of the replaced target file to obtain a compressed and obfuscated file.
[0053] Among them, performing compression on the inline code blocks of the replaced target file means removing comments, extra spaces, simplifying identifiers, etc. from the inline code blocks. Performing obfuscation on the inline code blocks of the replaced target file means making the inline code blocks difficult to read while ensuring that the execution results of the inline code blocks are not damaged. Common obfuscation rules include splitting strings, splitting arrays, adding redundant code, etc. Optionally, the computer device can simultaneously perform compression and obfuscation processing on the inline code blocks of the replaced target file, or first perform compression processing on the inline code blocks of the replaced target file and then perform obfuscation processing, or first perform obfuscation processing on the inline code blocks of the replaced target file and then perform compression processing. This embodiment does not limit the order of performing compression and obfuscation processing on the inline code blocks of the replaced target file, as long as it can perform compression and obfuscation processing on the inline code blocks of the replaced target file to obtain a compressed and obfuscated file.
[0054] S204. Fill the compressed and obfuscated file into the corresponding positions of each inline code block to obtain a processed target file.
[0055] It can be understood that the inline code blocks in the compressed and obfuscated file have undergone compression and obfuscation processing. Filling the compressed and obfuscated file into the corresponding positions of each inline code block in the target file means replacing the inline code blocks in the original target file with the compressed and obfuscated inline code blocks. The obtained processed target file is the target file with the inline code blocks having undergone compression and obfuscation processing.
[0056] Furthermore, after obtaining at least one inline code block in the target file, the computer device can also flexibly add other task flows for additional processing. For example, during the process of string processing, some additional tasks can be added to optimize the html code standardization and compress the css code.
[0057] In the above file processing method, without changing the structure of the target file in the front-end project, a preset placeholder code block is used to replace the inline code block in the target file to generate an intermediate processed file, i.e., the replaced target file. The inline code block of the replaced target file is compressed and obfuscated, and then the compressed and obfuscated file is filled into the position of the inline code block in the target file. In this process, only the inline code block in the target file is compressed and obfuscated, without destroying the original project structure of the target file, ensuring the normal operation of the original code, with simple operation and low error rate, thus improving the efficiency of compressing and obfuscating the target file.
[0058] Further, in the scenario of reading the target file in the front-end project and obtaining at least one inline code block in the target file, in one embodiment, as Figure 3 shown, the above S201 includes:
[0059] S301, read the content of the target file in the form of a file stream to obtain the string corresponding to the target file.
[0060] Among them, the target file is a file generated by the corresponding string. Optionally, the above file stream can be a character stream or a byte stream. That is to say, the computer device can read the content of the target file in the form of a character stream to obtain the string corresponding to the target file, or can also read the content of the target file in the form of a byte stream to obtain the string corresponding to the target file.
[0061] S302, use the method of string matching to find features to search for the string corresponding to the target file to obtain at least one inline code block in the target file.
[0062] Specifically, when the computer device obtains the string corresponding to the target file, the computer device uses the method of string matching to find features to search for the string corresponding to the target file to obtain at least one inline code block in the target file. Optionally, in this embodiment, the computer device can use the method of string matching to find features to search for the string corresponding to the target file to obtain at least one inline code block in the target file, where the inline code block is a module identified by script features. For example, the inline code block can be a module identified by <script>*< / script> script features. It should be noted here that <script>*< / script> the * part of the content in the module identified by features is the part that needs to be replaced with a preset placeholder code block.
[0063] In this embodiment, the computer device can quickly read the content of the target file in the form of a file stream to obtain the string corresponding to the target file, improving the efficiency of obtaining the string corresponding to the target file. Since the efficiency of obtaining the string corresponding to the target file is improved, and the inline code blocks in the target file are obtained by searching for the string corresponding to the target file in the way of string matching to find features, the efficiency of obtaining the inline code blocks in the target file is also improved, thus improving the efficiency of the compression and obfuscation process for the inline code blocks in the target file.
[0064] In the scenario of replacing each inline code block in the target file with a preset placeholder code block to obtain the replaced target file, it is necessary to first generate the placeholder code block. On the basis of the above embodiment, in one embodiment, the above S202 includes: generating a placeholder code block for each inline code block; the placeholder code blocks are unique and non-repetitive.
[0065] Specifically, in order to avoid the situation of replacement errors caused by duplicate naming of the placeholder code blocks during the process of replacing the inline code blocks in the target file with the placeholder code blocks, before replacing each inline code block in the target file with the preset placeholder code block to obtain the replaced target file, the computer device can first generate a placeholder code block for each inline code block in the target file using an algorithm, and the generated placeholder code blocks are unique and non-repetitive.
[0066] In this embodiment, the computer device generates a placeholder code block for each inline code block in the target file, and the generated placeholder code blocks are unique and non-repetitive, which can avoid the situation of replacement errors caused by duplicate naming of the placeholder code blocks during the process of replacing the inline code blocks in the target file with the placeholder code blocks, and improve the accuracy of replacing the inline code blocks in the target file with the preset placeholder code block.
[0067] In the scenario of performing compression and obfuscation processing on the inline code blocks of the replaced target file to obtain the compressed and obfuscated file, on the basis of the above embodiment, in one embodiment, the above S203 includes: performing compression and obfuscation processing on the inline code blocks of the replaced target file using a preset obfuscation library to obtain the compressed and obfuscated file.
[0068] Among them, the preset obfuscation library can be the uglifyjs compression and obfuscation open source library. Specifically, in this embodiment, the computer device can use an open source library such as the uglifyjs compression and obfuscation library to perform compression and obfuscation processing on the inline code blocks of the replaced target file to obtain the compressed and obfuscated file.
[0069] In this embodiment, the computer device performs compression and obfuscation processing on the inlined code blocks of the replaced target file using a preset obfuscation library. The preset obfuscation library can ensure the reliability of the obtained compression and obfuscation result. That is, using the preset obfuscation library to perform compression and obfuscation processing on the inlined code blocks of the replaced target file improves the reliability of the obtained compressed and obfuscated file.
[0070] In the scenario of filling the compressed and obfuscated file into the corresponding positions of each inlined code block of the target file to obtain the processed target file as described above, based on the above embodiment, in one embodiment, the above S204 includes: performing matching backfilling according to the file name of the compressed and obfuscated file to obtain the processed target file.
[0071] Among them, backfilling refers to the process of replacing each inlined code block in the target file with the compressed and obfuscated file. Specifically, in this embodiment, the computer device matches the file name of the compressed and obfuscated file with each inlined code block in the target file, and fills the content of all compressed and obfuscated files as a string into the positions of each inlined code block in the previous target file to obtain the processed target file.
[0072] In this embodiment, the computer device can accurately perform matching backfilling according to the file name of the compressed and obfuscated file, so that the compressed and obfuscated file can be accurately filled into the corresponding positions of each inlined code block in the target file to obtain the processed target file, improving the accuracy of the obtained processed target file.
[0073] In the scenario of reading the target file in the front-end project as described above, the target file needs to be obtained first. Based on the above embodiment, in one embodiment, the above method further includes: obtaining the target file from a preset disk directory according to the directory where the front-end project is located.
[0074] Specifically, in this embodiment, the computer device can scan with the root directory of the web project source code as the entry, and recursively search for all files with the.html suffix under this entry from the preset disk directory according to the directory where the front-end project is located, and confirm them as the target files.
[0075] In this embodiment, the computer device can quickly and accurately obtain the target file from the preset disk directory according to the directory where the front-end project is located, thereby improving the efficiency and accuracy of the computer device in obtaining the target file.
[0076] For the convenience of understanding by those skilled in the art, the following provides a detailed introduction to the file processing method provided by this application. Please refer to Figure 4 , this method may include:
[0077] S1. Obtain a target file from a preset disk directory according to the directory where the front-end project is located.
[0078] S2. Read the content of the target file in the form of a file stream to obtain the string corresponding to the target file.
[0079] S3. Perform feature search on the string corresponding to the target file by using the method of string matching to find features, and obtain at least one inline code block in the target file; wherein, the inline code block is a module identified by <script>*< / script> features.
[0080] S4. Generate unique and non-repeating placeholder code blocks for each inline code block.
[0081] S5. Replace each inline code block with a placeholder code block to obtain the replaced target file.
[0082] S6. Perform compression and obfuscation processing on the inline code blocks of the replaced target file by using a preset obfuscation library to obtain the compressed and obfuscated file.
[0083] S7. Perform matching and backfilling according to the file name of the compressed and obfuscated file, and fill the compressed and obfuscated file into the corresponding positions of each inline code block to obtain the processed target file.
[0084] It should be noted that for the descriptions in S1 - S7 above, reference can be made to the relevant descriptions in the above embodiments, and their effects are similar, so they will not be elaborated in this embodiment.
[0085] It should be understood that although Figures 2-4 the steps in the flowchart are shown in sequence according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise clearly stated in this article, the execution of these steps has no strict order limit, and these steps can be executed in other orders. Moreover, Figures 2-4 at least a part of the steps in
[0086] In one embodiment, as Figure 5 shown, a file processing device is provided, including: a reading module, a replacement module, a first processing module, and a second processing module, wherein:
[0087] The reading module is used to read the target file in the front-end project to obtain at least one inline code block in the target file.
[0088] A replacement module, which is used to replace each inline code block with a preset placeholder code block to obtain a target file after replacement.
[0089] A first processing module, which is used to perform compression and obfuscation processing on the inline code blocks of the target file after replacement to obtain a file after compression and obfuscation.
[0090] A second processing module, which is used to fill the file after compression and obfuscation into the corresponding positions of each inline code block to obtain a processed target file.
[0091] The file processing device provided in this embodiment can execute the above method embodiment, and its implementation principle and technical effect are similar, which will not be elaborated here.
[0092] Based on the above embodiment, optionally, the above reading module includes: a reading unit and a searching unit, where:
[0093] The reading unit is used to read the content of the target file in the form of a file stream to obtain a string corresponding to the target file.
[0094] The searching unit is used to search for the string corresponding to the target file by means of string matching to find features, so as to obtain at least one inline code block in the target file.
[0095] The file processing device provided in this embodiment can execute the above method embodiment, and its implementation principle and technical effect are similar, which will not be elaborated here.
[0096] Based on the above embodiment, optionally, the above searching unit is used to search for features of the string corresponding to the target file by means of string matching to find features, so as to obtain at least one inline code block in the target file; wherein, the inline code block is a module identified by a script feature.
[0097] The file processing device provided in this embodiment can execute the above method embodiment, and its implementation principle and technical effect are similar, which will not be elaborated here.
[0098] Based on the above embodiment, optionally, the above device further includes: a generating module, where:
[0099] The generating module is used to generate a placeholder code block for each inline code block; the placeholder code block is unique and non-repeating.
[0100] The file processing device provided in this embodiment can execute the above method embodiment, and its implementation principle and technical effect are similar, which will not be elaborated here.
[0101] Based on the above embodiment, optionally, the above first processing module includes: a first processing unit, where:
[0102] A first processing unit, configured to perform compression and obfuscation processing on the inline code blocks of the replaced target file by using a preset obfuscation library, so as to obtain a compressed and obfuscated file.
[0103] The file processing device provided in this embodiment can execute the above method embodiment, and its implementation principle and technical effect are similar, which will not be elaborated here.
[0104] Based on the above embodiment, optionally, the above second processing module includes: a second processing unit, where:
[0105] The second processing unit is configured to perform matching and backfilling according to the file name of the compressed and obfuscated file, so as to obtain a processed target file.
[0106] The file processing device provided in this embodiment can execute the above method embodiment, and its implementation principle and technical effect are similar, which will not be elaborated here.
[0107] Based on the above embodiment, optionally, the above device further includes: an acquisition module, where:
[0108] The acquisition module is configured to obtain a target file from a preset disk directory according to the directory where the front-end project is located.
[0109] The file processing device provided in this embodiment can execute the above method embodiment, and its implementation principle and technical effect are similar, which will not be elaborated here.
[0110] For the specific limitation of the file processing device, reference can be made to the limitation of the file processing method in the above text, which will not be elaborated here. Each module in the above file processing device can be implemented in whole or in part by software, hardware, and their combination. The above modules can be embedded in the processor of the computer device in hardware form or be independent of it, or can be stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to the above respective modules.
[0111] In one embodiment, a computer device is provided, including a memory and a processor. A computer program is stored in the memory. When the processor executes the computer program, the following steps are implemented:
[0112] Read the target file in the front-end project to obtain at least one inline code block in the target file;
[0113] Replace each inline code block with a preset placeholder code block to obtain a replaced target file;
[0114] Perform compression and obfuscation processing on the inline code blocks of the replaced target file to obtain a compressed and obfuscated file;
[0115] Fill the compressed and obfuscated file into the corresponding positions of each inline code block to obtain the processed target file.
[0116] The computer device provided in the above embodiment has the same implementation principle and technical effects as the above method embodiment, which will not be elaborated here.
[0117] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented:
[0118] Read the target file in the front-end project to obtain at least one inline code block in the target file;
[0119] Replace each inline code block with a preset placeholder code block to obtain the replaced target file;
[0120] Perform compression and obfuscation processing on the inline code blocks of the replaced target file to obtain the compressed and obfuscated file;
[0121] Fill the compressed and obfuscated file into the corresponding positions of each inline code block to obtain the processed target file.
[0122] The computer-readable storage medium provided in the above embodiment has the same implementation principle and technical effects as the above method embodiment, which will not be elaborated here.
[0123] Those of ordinary skill in the art can understand that all or part of the processes in the above method embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the above method embodiments. Among them, any reference to a memory, storage, database, or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memories. The non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, or optical memory, etc. The volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc.
[0124] The technical features of the above embodiments can be combined arbitrarily. For the sake of concise description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope described in this specification.
[0125] The above-described embodiments merely represent several implementation manners of the present application. The description is relatively specific and detailed, but it should not be construed as a limitation on the scope of the invention patent. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present application, several modifications and improvements can still be made, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the appended claims.
Claims
1. A file processing method, characterized in that, The method includes: Reading a target file in a front-end project to obtain at least one inline code block in the target file; the inline code block is a module identified by script features; Generating a corresponding placeholder code block for each of the inline code blocks; the placeholder code blocks are unique and non-repeating; Using each of the placeholder code blocks to replace the intermediate content identified by script features in the corresponding inline code block to obtain a replaced target file; Performing compression and obfuscation processing on the inline code blocks of the replaced target file to obtain a compressed and obfuscated file; Filling the compressed and obfuscated file into the corresponding positions of each of the inline code blocks to obtain a processed target file; Wherein, the reading of the target file in the front-end project to obtain at least one inline code block in the target file includes: Reading the content of the target file in the form of a file stream to obtain a string corresponding to the target file; Searching for the string corresponding to the target file by using the method of string matching to search for features to obtain at least one inline code block in the target file; The filling of the compressed and obfuscated file into the corresponding positions of each of the inline code blocks to obtain a processed target file includes: Performing matching and backfilling according to the file name of the compressed and obfuscated file to obtain the processed target file.
2. The method according to claim 1, wherein The searching for the string corresponding to the target file by using the method of string matching to search for features to obtain at least one inline code block in the target file includes: Searching for features of the string corresponding to the target file by using the method of string matching to search for features to obtain at least one inline code block in the target file.
3. The method according to any one of claims 1 to 2, characterized in that The performing of compression and obfuscation processing on the inline code blocks of the replaced target file to obtain a compressed and obfuscated file includes: Performing compression and obfuscation processing on the inline code blocks of the replaced target file by using a preset obfuscation library to obtain the compressed and obfuscated file.
4. The method according to claim 1, wherein The method further includes: Obtaining the target file from a preset disk directory according to the directory where the front-end project is located.
5. A file processing device, characterized in that, The device includes: A reading module for reading a target file in a front-end project to obtain at least one inline code block in the target file; the inline code block is a module identified by script features; A generating module for generating a corresponding placeholder code block for each of the inline code blocks; the placeholder code blocks are unique and non-repeating; A replacing module for using each of the placeholder code blocks to replace the intermediate content identified by script features in the corresponding inline code block to obtain a replaced target file; A first processing module for performing compression and obfuscation processing on the inline code blocks of the replaced target file to obtain a compressed and obfuscated file; A second processing module for filling the compressed and obfuscated file into the corresponding positions of each of the inline code blocks to obtain a processed target file; Wherein, the reading module includes: A reading unit for reading the content of the target file in the form of a file stream to obtain a string corresponding to the target file; A search unit, configured to search for the string corresponding to the target file by using a method of searching for features through string matching, so as to obtain at least one inline code block in the target file; The second processing module includes: A second processing unit, configured to perform matching backfilling according to the file name of the compressed and obfuscated file, so as to obtain the processed target file.
6. The device according to claim 5, wherein The search unit is configured to search for features of the string corresponding to the target file by using a method of searching for features through string matching, so as to obtain at least one inline code block in the target file.
7. The device according to any one of claims 5 to 6, characterized in that The first processing module includes: A first processing unit, configured to perform compression and obfuscation processing on the inline code block of the replaced target file by using a preset obfuscation library, so as to obtain the compressed and obfuscated file.
8. The device according to claim 5, characterized in that, The device further includes: An acquisition module, configured to acquire the target file from a preset disk directory according to the directory where the front-end project is located.
9. A computer device, comprising a memory and a processor, the memory storing a computer program, characterized in that, When the processor executes the computer program, the steps of the method according to any one of claims 1 to 4 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, the steps of the method according to any one of claims 1 to 4 are implemented.
Citation Information
Patent Citations
Compression / decompression method
US20020073116A1