Python-based folder comparison method and device, medium and equipment

The Python-based folder comparison method automates the process of identifying and comparing folders, addressing inefficiencies in traditional methods by providing detailed results, thus enhancing efficiency and accuracy in software development and testing.

CN119938614APending Publication Date: 2025-05-06成都安易迅科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411769229.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-04
Publication Date
2025-05-06

AI Technical Summary

Technical Problem

In software development and testing, ensuring version consistency and integrity between modified files and online versions is crucial but is hindered by the inefficiency and risk of manual tool switching in traditional file comparison methods, which require high skill levels and increase the likelihood of errors.

Method used

A Python-based folder comparison method and device that automatically identifies folders for comparison, extracts information at predefined dimensions, and generates detailed comparison results, eliminating the need for manual tool switching and reducing human error.

Benefits of technology

This approach simplifies the folder comparison process, enhances efficiency, and improves accuracy by providing comprehensive comparison information in a single operation, thereby reducing the time and effort required for file verification.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119938614A_ABST
    Figure CN119938614A_ABST
Patent Text Reader

Abstract

The invention discloses a python-based folder comparison method and device, a storage medium and computer equipment, and the method comprises the steps: responding to a folder comparison instruction, determining a to-be-compared folder, and carrying out the comparison of the to-be-compared folder on the basis of a directory where the to-be-compared folder is located, searching a folder with the same name as the folder to be compared from the directory as a target reference folder; respectively obtaining each first file in the to-be-compared folder and each second file in the target reference folder, respectively carrying out information extraction on each first file and each second file according to a preset dimension to obtain first dimension information corresponding to each first file, and sending the first dimension information to the target reference folder; obtaining second dimension information corresponding to each second file; and obtaining a folder comparison result between the folder to be compared and the target reference folder according to the first dimension information corresponding to each first file and the second dimension information corresponding to each second file.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a Python-based folder comparison method and device, a storage medium, and a computer device. Background Art

[0002] In the software development and testing process, it is crucial to ensure the consistency and integrity of the product version. Especially in the comparison phase before the product goes online, testers need to carefully check the differences between the modified files and the online version, including but not limited to the file version number, signature verification, and file content verification. This link is not only related to product quality, but also directly affects the stability and security of the system.

[0003] Traditionally, testers rely on multiple independent tools to complete these comparisons, such as BeyondCompare for detailed comparison of file contents and signature verification tools for verifying whether the digital signature of a file is legitimate. However, frequently switching between different tools is not only time-consuming and laborious, but also increases the risk of operational errors and reduces work efficiency. In addition, each tool may have its own specific usage method and output format, which requires testers to have a high level of skills and experience to accurately interpret the comparison results and make corresponding processing. Summary of the invention

[0004] In view of this, the present application provides a python-based folder comparison method and device, storage medium, and computer equipment, which can respond to the folder comparison command issued by the tester and automatically determine the folder to be compared and the target reference folder. Subsequently, the files in the two folders are compared and detailed comparison results are generated. In this way, the tester can obtain all key comparison information at one time without manual switching and using multiple tools, thereby simplifying the folder comparison process and greatly improving work efficiency and comparison accuracy.

[0005] According to one aspect of the present application, a python-based folder comparison method is provided, comprising:

[0006] In response to the folder comparison instruction, a folder to be compared is determined, and based on the directory where the folder to be compared is located, an online folder is searched from the directory, and a folder with the same name as the folder to be compared is searched under the online folder as a target reference folder;

[0007] Respectively obtaining each first file in the folder to be compared and each second file in the target reference folder, and extracting information from each of the first files and each of the second files according to preset dimensions to obtain first dimensional information corresponding to each of the first files and second dimensional information corresponding to each of the second files;

[0008] According to the first dimension information corresponding to each of the first files and the second dimension information corresponding to each of the second files, a folder comparison result between the folder to be compared and the target reference folder is obtained.

[0009] According to another aspect of the present application, a folder comparison device based on Python is provided, comprising:

[0010] A folder determination module, for determining a folder to be compared in response to a folder comparison instruction, and based on a directory where the folder to be compared is located, searching for an online folder from the directory, and searching for a folder with the same name as the folder to be compared under the online folder as a target reference folder;

[0011] An information extraction module, used to respectively obtain each first file in the folder to be compared and each second file in the target reference folder, and extract information from each of the first files and each of the second files according to a preset dimension to obtain first dimensional information corresponding to each of the first files and second dimensional information corresponding to each of the second files;

[0012] The folder comparison module is used to obtain the folder comparison result between the folder to be compared and the target reference folder according to the first dimension information corresponding to each of the first files and the second dimension information corresponding to each of the second files.

[0013] According to another aspect of the present application, a storage medium is provided, on which a computer program is stored, and when the program is executed by a processor, the above-mentioned Python-based folder comparison method is implemented.

[0014] According to another aspect of the present application, a computer device is provided, including a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, wherein the processor implements the above-mentioned Python-based folder comparison method when executing the program.

[0015] By means of the above technical scheme, the present application provides a folder comparison method and device based on Python, a storage medium, and a computer device. In response to a folder comparison instruction, the folder to be compared selected by the user is determined, and based on the directory where the folder to be compared is located, an online folder is searched in the directory, and a folder corresponding to the previous version that has been released is stored in the online folder. After that, a folder with the same name as the folder to be compared can be found from the online folder as the target reference folder. Then, each first file in the folder to be compared and each second file in the target reference folder can be obtained. For each file obtained, information can be extracted according to a preset dimension. For the first file in the folder to be compared, the extracted information is called the first dimension information; for the second file in the target reference folder, the extracted information is called the second dimension information. With the first dimension information of each first file and the second dimension information of the second file, the contents of the two folders are compared, and finally a folder comparison result can be generated. The embodiment of the present application can respond to the folder comparison instruction issued by the tester and automatically determine the folder to be compared and the target reference folder. Subsequently, the files in the two folders are compared and a detailed comparison result is generated. In this way, testers can obtain all key comparison information at one time without having to manually switch and use multiple tools, thereby simplifying the folder comparison process and greatly improving work efficiency and comparison accuracy.

[0016] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0018] Figure 1 A schematic diagram of a Python-based folder comparison method provided in an embodiment of the present application is shown;

[0019] Figure 2 A schematic diagram of a window for determining a folder to be compared provided in an embodiment of the present application is shown;

[0020] Figure 3 A schematic diagram of the structure of a folder comparison device based on Python provided in an embodiment of the present application is shown;

[0021] Figure 4A schematic diagram of the device structure of a computer device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0022] The present application will be described in detail below with reference to the accompanying drawings and in combination with embodiments. It should be noted that the embodiments and features in the embodiments of the present application can be combined with each other without conflict.

[0023] In this embodiment, a folder comparison method based on Python is provided, such as Figure 1 As shown, the method includes:

[0024] Step 101, in response to a folder comparison instruction, determine a folder to be compared, and based on the directory where the folder to be compared is located, search for an online folder from the directory, and search for a folder with the same name as the folder to be compared under the online folder as a target reference folder.

[0025] The embodiment of the present application provides a python-based folder comparison method, which can quickly confirm the multi-dimensional differences between two folders of a new revised version and a previously released version of a certain software. Specifically, the folder corresponding to the new revised version can be called the folder to be compared, and the folder corresponding to the previously released version can be called the target reference folder. Through the method of the embodiment of the present application, it can be quickly confirmed which files have been deleted, which files have been added, and which files have been modified in the folder to be compared compared with the target reference folder. The embodiment of the present application is implemented in the python programming language. Among them, when the user wants to compare the files under the folder to be compared and the target reference folder, the folder to be compared can be determined first, and then the corresponding icon or button of the "folder comparison" function is triggered, and the folder comparison instruction can be generated accordingly. Specifically, the folder to be compared can be obtained by Figure 2 The window shown in the figure shows that the user can first click the "Select Folder" button to jump to the default location, and then the user can find the folder to be compared step by step from this location. After determining the folder to be compared, click "Start Comparison" to generate a folder comparison instruction. After receiving the instruction, the instruction can be responded to, and the folder to be compared selected by the user is determined from the window, and based on the directory where the folder to be compared is located, an online folder is searched in the directory, and the folder corresponding to the previous version released is stored in the online folder. In another embodiment, the online folder can be a folder named "online". For example, if the folder to be compared is located in / path / to / , the system will look for a folder named online in the / path / to / directory. Afterwards, a folder with exactly the same name as the folder to be compared can be found in the online folder as the target reference folder.

[0026] Step 102, respectively obtain each first file in the folder to be compared and each second file in the target reference folder, extract information from each first file and each second file according to preset dimensions, and obtain first dimensional information corresponding to each first file and second dimensional information corresponding to each second file.

[0027] In this embodiment, then, each first file in the folder to be compared and each second file in the target reference folder can be obtained. For each file obtained, information can be extracted according to preset dimensions (such as file name, file size, file version, MD5, signature information, etc.). For the first file in the folder to be compared, the extracted information is called first dimension information; for the second file in the target reference folder, the extracted information is called second dimension information. It should be noted that the first file and the second file can be each file in the folder to which they belong, or they can be files of a specified type in the folder to which they belong.

[0028] Step 103: Obtain a folder comparison result between the folder to be compared and the target reference folder according to the first dimension information corresponding to each of the first files and the second dimension information corresponding to each of the second files.

[0029] In this embodiment, after obtaining the first dimension information of each first file and the second dimension information of the second file, the contents of the two folders are compared. The comparison can be judged based on the preset dimension, such as whether the files with the same name in the same path have the same file size, file version, MD5, signature information, etc. Based on these comparison results, the folder comparison results can be generated, which may include which files exist in both folders but have different dimension information, which files exist only in one folder, and the dimension information of these files.

[0030] In addition, the folder comparison results can also be output in some form (such as text report, graphical interface display, etc.) for users to view.

[0031] By applying the technical solution of this embodiment, in response to the folder comparison instruction, the folder to be compared selected by the user is determined, and based on the directory where the folder to be compared is located, an online folder is searched in the directory, and the folder corresponding to the previous version that has been released is stored in the online folder. After that, a folder with the same name as the folder to be compared can be found from the online folder as the target reference folder. Then, each first file in the folder to be compared and each second file in the target reference folder can be obtained. For each file obtained, information can be extracted according to a preset dimension. For the first file in the folder to be compared, the extracted information is called the first dimension information; for the second file in the target reference folder, the extracted information is called the second dimension information. With the first dimension information of each first file and the second dimension information of the second file, the contents of the two folders are compared, and finally the folder comparison result can be generated. The embodiment of the present application can respond to the folder comparison instruction issued by the tester and automatically determine the folder to be compared and the target reference folder. Subsequently, the files in the two folders are compared and a detailed comparison result is generated. In this way, testers can obtain all key comparison information at one time without having to manually switch and use multiple tools, thereby simplifying the folder comparison process and greatly improving work efficiency and comparison accuracy.

[0032] In an embodiment of the present application, optionally, the preset dimension includes signature information; when information extraction is performed according to the signature information, the first file and the second file are PE files in the folder to which they belong, and the "information extraction for each of the first files and each of the second files is performed according to the preset dimension to obtain the first dimension information corresponding to each of the first files and the second dimension information corresponding to each of the second files" in step 102 includes: for the PE files in each folder, performing the following operations to extract information to obtain the first signature information corresponding to each of the first files and the second signature information corresponding to each of the second files: extracting the signature data address and the number of signature data bytes from the PE file, reading the target signature data according to the signature data address and the number of signature data bytes, The target signature data is parsed to obtain a target certificate information set, and it is determined whether the data type of the target certificate information set is the target data type; when the data type of the target certificate information set is the target data type, the holder common name is extracted from the certificate contained in the target certificate information set through a holder common name extraction function to obtain the holder common name corresponding to the certificate, and the signature algorithm is extracted from the certificate contained in the target certificate information set through a signature algorithm extraction function to obtain the signature algorithm corresponding to the certificate; based on a preset root certificate issuer list, the holder common name is filtered, and the target signer information is obtained based on the filtering result; according to the target signer information and the signature algorithm corresponding to the target signer information, the signature information corresponding to the PE file is obtained.

[0033] In this embodiment, the preset dimension can be a file version, MD5, signature information, etc. When the preset dimension includes signature information, since the basic API (Application Programming Interface) of python does not directly give the final signature information, but provides a collection of certificates, it is necessary to further screen and process the collection information to obtain the final desired signature information. Therefore, when the preset dimension includes signature information, the embodiment of the present application determines the signature information of each first file and each second file by the following method. It should be noted that when extracting the signature information, only the signature information of the PE files under the comparison folder and the target reference folder is extracted. At this time, the first file and the second file are PE files under the corresponding folders, and the first dimension information corresponding to the first file includes the first signature information, and the second dimension information corresponding to the second file includes the second signature information.

[0034] Before extracting the signature information, you can first use pefile.PE to read the file data from the file to be compared and the target reference folder respectively to obtain the first file and the second file, where the first file and the second file are both PE (Portable Executable) files. PE files are a common file format and are widely used in Windows operating systems. In order to ensure that the source of PE files is reliable and has not been tampered with, the files are usually digitally signed. The digital signature contains certificate information that can prove the authenticity and integrity of the file. It should be noted that whether the signature information is extracted from the first file or the second file, the signature information extraction process is the same. The signature information extraction process can be as follows:

[0035] First, the address of the signature data (i.e., the storage location of the signature data in the file) and the number of bytes of the signature data (i.e., the size of the signature data) can be extracted from the metadata or specific area of ​​the PE file. In one embodiment, the address (VirtualAddress) and number of bytes (Size) of the signature data can be obtained using IMAGE_DIRECTORY_ENTRY_SECURITY. Then, according to the extracted signature data address and number of bytes, the target signature data is read from the PE file, and the target signature data is parsed using an appropriate parsing function. For example, the cms.ContentInfo.load function can be used for parsing. After parsing, a target certificate information set can be generated. This set contains all certificate information related to the signature, such as the holder of the certificate, the signature algorithm, etc. After the parsing is completed, it is further determined whether the data type of the target certificate information set is the target data type. Here, the target certificate information set can be obtained based on the signature['content']['certificates'] structure, and the target data type can be ans1crypto.cms.CertificateSet type. If

[0036] The data type of signature['content']['certificates'] is ans1crypto.cms.CertificateSet type, then the holder common name extraction function can be used to extract the holder's common name (common_name) from the certificate contained in the target certificate information set. The holder common name is a field in the certificate used to identify the certificate holder. In addition, the signature algorithm extraction function can be used to extract the signature algorithm (algorithm) from the above certificate. The signature algorithm is an algorithm used to verify the validity of the signature, which determines how to encrypt and verify the signature data. The holder common name extraction function and the signature algorithm extraction function can be existing functions and are not limited here.

[0037] Since the common names of the holders extracted above often contain the root certificate issuer, and the root certificate issuer does not belong to the signer name, it is necessary to filter the extracted common names of the holders. Specifically, the common names of the holders can be filtered based on a preset root certificate issuer list (this list contains the information of all trusted root certificate issuers), and the root certificate issuers contained therein are removed to obtain the target signer information. Finally, the signature information corresponding to the PE file can be generated according to the target signer information obtained after filtering and the signature algorithm corresponding to each target signer information. Through the above method, the embodiment of the present application can effectively and successfully extract the target signer information and the corresponding signature algorithm in the python environment, which is simple and convenient.

[0038] It should be noted that if the data type of the target certificate information set is not the target data type, the holder's common name and signature algorithm are not directly extracted from the target certificate information set, but are subsequently extracted through other methods.

[0039] In an embodiment of the present application, optionally, the "extracting the signature data address and the number of signature data bytes from the PE file" includes: obtaining a data directory entry corresponding to the PE file, accessing the data directory entry, and searching for the signature address data and the number of signature data bytes from the data directory entry.

[0040] In this embodiment, the signature data address and signature data bytes can be extracted from the PE file in the following manner. First, the header information of the PE file can be parsed, especially its data directory part. The data directory is an important part of the PE file header, which contains pointers and size information pointing to various important data in the file. After obtaining the data directory items, these items can be traversed to find items related to the signature data. In the data directory items of the PE file, there is a specific item for storing information about the signature data, which is usually called "Strong Name Signature" or "Digital Signature". After finding the data directory item related to the signature data, read the "Virtual Address" and "Size" fields in the item. The virtual address refers to the relative position of the signature data in the file (relative to the offset of the file header), and the size field indicates the size of the signature data (in bytes). By reading these two fields, the address of the signature data (i.e., the virtual address) and the number of bytes of the signature data can be obtained.

[0041] In an embodiment of the present application, optionally, after the "obtaining the target certificate information set", the method further includes: identifying a signature content encapsulation field from the target certificate information set, determining signature content encapsulation information based on the signature content encapsulation field, and judging whether there is a generation time field in the signature content encapsulation information; when there is a generation time field in the signature content encapsulation information, formatting the timestamp indicated by the generation time field, and using the formatted timestamp as the timestamp corresponding to the target signer information, and updating the signature information corresponding to the PE file according to the timestamp corresponding to the target signer information; when there is no generation time field in the signature content encapsulation information, identifying a signature information field from the target certificate information set, determining a signature information list based on the signature information field, traversing the signature information list to determine multiple signer information, as well as the signature algorithm corresponding to each signer information and the timestamp indicated by the generation time field, formatting the timestamp to obtain the formatted timestamp, and obtaining the signature information corresponding to the PE file according to the multiple signer information, the signature algorithm corresponding to each signer information, and the formatted timestamp.

[0042] In this embodiment, after obtaining the target certificate information set, the signature content encapsulation field can be further located from the target certificate information set, the signature content encapsulation field can be parsed, and the signature content encapsulation information can be obtained. Specifically, the signature content encapsulation information can be read according to the pointer of the signature content encapsulation field. The signature content encapsulation information may include information such as the signer, signature algorithm, hash value, and timestamp. In one embodiment, the signature content encapsulation field can be

[0043] signture['content']['encap_content_info'], the corresponding signature content encapsulation information can be obtained according to the signature content encapsulation field. Afterwards, check whether the signature content encapsulation information contains the generation time field. For example, the signature content encapsulation information can be traversed to find the field related to the generation time. The generation time field can be a timestamp field, etc., which is used to record the time when the signature is generated. In one embodiment, the generation time field can be gen_time.

[0044] If it is found through traversal that the signature content encapsulation information includes a generation time field, then the timestamp corresponding to the generation time field can be converted to the required format, for example, taking into account the time zone information and time accuracy, and then the formatted timestamp is used as the timestamp corresponding to the aforementioned target signer information, and the signature information of the PE file is updated. That is, the signature information corresponding to the aforementioned PE file only includes the target signer information and the corresponding signature algorithm, and the timestamp corresponding to the target signer information is obtained here, and the timestamp is added to the signature information of the PE file, further enriching the content of the signature information.

[0045] If it is found through traversal that the signature content encapsulation information does not include the generation time field, then the signature information field can be identified from the target certificate information set, and then the signature information list can be determined based on the signature information field. By traversing the signature information list, the signer information contained therein can be obtained, and at the same time, the signature algorithm corresponding to each signer information and the timestamp corresponding to the generation time field can also be obtained. In one embodiment, the signature information field can be signature['content']['signer_infos'], through which the signature information list can be found, wherein the signature information list includes both the common name (common_name) of the holder corresponding to each certificate in a multi-certificate environment, and the signature algorithm (algorithm) and timestamp (gen_time) corresponding to each holder common name. Among them, for the holder common name, it can also be filtered using the preset root certificate issuer list to obtain the target signer information corresponding to each certificate; for the timestamp, it can also be formatted to obtain the processed timestamp. It should be noted that the holder common name can also be extracted using the aforementioned holder common name extraction function; the signature algorithm can also be extracted using the aforementioned signature algorithm extraction function. Finally, the target signer information, signature algorithm and formatted timestamp corresponding to each certificate can be obtained, and then the complete signature information corresponding to the PE file can be obtained. That is, the signature information corresponding to the PE file can include the target signer information, signature algorithm and timestamp corresponding to multiple certificates.

[0046] It should be noted that when the signature content encapsulation information does not include the generation time field, the data type of the aforementioned target certificate information set is not the target data type, that is, the aforementioned target signer information and signature algorithm cannot be obtained, and the signature information of multiple certificates is directly determined by identifying the signature information field from the target certificate information set in this embodiment. The embodiment of the present application can quickly and accurately extract the signature information of the PE file in the Python environment.

[0047] In an embodiment of the present application, optionally, the method further includes: sending root certificate issuer query information to the big model according to a preset period, and updating the current preset root certificate issuer list based on the feedback result of the big model each time to obtain an updated preset root certificate issuer list.

[0048] In this embodiment, the preset root certificate issuer list may be regularly updated in the following manner:

[0049] The root certificate issuer query information can be sent to the big model according to the preset cycle. By setting a fixed query cycle, it can be ensured that the information of the root certificate issuer is updated in time to reflect the latest security situation. Among them, the length of the preset cycle can be determined according to specific needs and security policies, such as daily, weekly, monthly, etc. The big model refers to a machine learning model or an artificial intelligence system that has the ability to process and analyze large amounts of data. In this application, the big model is used to receive a query request from the root certificate issuer, analyze the public data source, security announcement, certificate revocation list (CRL) or online certificate status protocol (OCSP) response, etc. according to the query request, to provide the latest root certificate issuer information, and return relevant information. Afterwards, the feedback result returned by the big model can be received, and the feedback result contains all the root certificate issuers as of the query time, and the previous version of the root certificate issuer list can be updated according to these root certificate issuers. The embodiment of the present application obtains the latest root certificate issuer information by periodically querying the big model, and updates the preset root certificate issuer list based on this information, which helps to improve the accuracy of subsequent signature information extraction.

[0050] Additionally, the initial list of pre-set root certificate issuers can be determined as follows:

[0051] Initialize a dict and place common root certificate issuer information, such as SymantecSHA256TimeStamping Signer-G3, DigiCert SHA2 Assured ID Code Signing CA, and Microsoft Windows Third Party Component CA2012, to get the initial preset root certificate issuer list.

[0052] In an embodiment of the present application, optionally, step 103 includes: for each first file, determining a first file path of the first file in the folder to be compared, and searching the target reference folder for a second file path that is identical to the first file path, and determining whether there is a target second file with the same name as the first file under the second file path; when there is a target second file with the same name as the first file under the second file path, judging whether there is a modification to the first file based on first dimensional information corresponding to the first file and second dimensional information corresponding to the target second file, and when there is a modification, determining that the first file is a modified file; when there is no target second file with the same name as the first file under the second file path, When there is a target second file with the same name as the first file, the first file is determined to be a newly added file; for each second file, the third file path of the second file in the target reference folder is determined, and a fourth file path with the same name as the third file path is searched from the folder to be compared to determine whether there is a target first file with the same name as the second file under the fourth file path; when there is no target first file with the same name as the second file under the fourth file path, the second file is determined to be a deleted file; according to each modified file, each newly added file and each deleted file, and the dimensional information corresponding to each file, the folder comparison result between the folder to be compared and the target reference folder is obtained.

[0053] In this embodiment, the folder comparison result shows which files in the folder to be compared are modified files, which files are newly added files, and which files are deleted files compared to the target reference folder. Among them, modified files refer to files modified from files in the target reference folder; newly added files refer to files that were not originally in the target reference folder and are newly added this time; deleted files refer to files that were originally in the target reference folder but not in the folder to be compared. These three types of files can be specifically determined in the following ways:

[0054] For each first file in the folder to be compared:

[0055] First, determine the first file path of the first file in the folder to be compared. After that, search for the second file path that is the same as the first file path in the target reference folder, and find the second file in the target reference folder through the second file path that is the same as the file position of the first file in the folder to be compared. If there is a second file with the same file name as the first file in this position (referred to as the target second file), then compare the dimension information of the two files (the first file and the target second file). Here, the dimension information may include file version, signature information, MD5 information, etc. If the comparison result based on the dimension information shows that the first file has changed, the first file is determined to be a modified file.

[0056] On the contrary, if the second file having the same file name as the first file is not found under the second file path, the first file is determined as a newly added file.

[0057] For each secondary file in the target reference folder:

[0058] First, determine the third file path of the second file in the target reference folder. Then, search for the fourth file path that is the same as the third file path in the folder to be compared, and find the first file in the folder to be compared that is the same as the file position of the second file in the target reference folder through the fourth file path. If there is no first file with the same file name as the second file in this location (referred to as the target first file), the second file is determined to be a deleted file, indicating that the file has been deleted in the folder to be compared.

[0059] Finally, the folder comparison result between the folder to be compared and the target reference folder can be generated based on all modified, added and deleted files and the dimensional information corresponding to these files. Specifically, the results of all modified files can be displayed together, the results of all added files can be displayed together, and the results of all deleted files can be displayed together, so that the user can intuitively see the comparison results between the two folders.

[0060] The embodiment of the present application performs file comparison between two folders through the above method, and can quickly determine the modified files, newly added files and deleted files, and at the same time intuitively display the comparison results to the user, which can further enhance the user experience.

[0061] In an embodiment of the present application, optionally, before step 101, the method further includes: in response to a folder comparison tool startup instruction, requesting administrator privileges from the target operating system, and after being assigned administrator privileges, adding a new registry entry corresponding to the target operating system, and adding a fifth file path of the target dynamic link library file and a menu item text displayed when the user right-clicks in the new registry entry; accordingly, the method further includes: in response to a right-click instruction of any folder, displaying a right-click menu page, wherein the right-click menu page includes the menu item text corresponding to the folder comparison tool; based on a click operation on the menu item text corresponding to the folder comparison tool, generating a folder comparison instruction, so as to call the target dynamic link library file through the fifth file path based on the folder comparison instruction, and determining the folder to be compared and the target reference folder through the target dynamic link library file.

[0062] In this embodiment, before comparing the folders, a folder comparison tool can be started first, and the above-mentioned folder comparison method based on Python is implemented by the folder comparison tool. When the user starts the folder comparison tool, the tool can first request administrator privileges from the target operating system. Once the administrator privileges are assigned, the tool can create a new registry entry in the registry of the operating system. The registry is a database used to store system and application configuration information in the Windows operating system (and some other operating systems).

[0063] After the new registry entry is created, the folder comparison tool can add the fifth file path of the target dynamic link library file (DLL) to the new registry entry. The target dynamic link library file is an executable file containing code and data that can be used by multiple programs at the same time. In this embodiment, the target dynamic link library file contains the function code required to perform the folder comparison.

[0064] In addition to the fifth file path, a menu item text can be added to the newly created registry key, which will be displayed in the right-click menu when the user right-clicks the folder. For example, the menu item text can be "Folder Compare", etc. After the above modification, the user is allowed to quickly access the folder comparison tool through the right-click menu without having to launch it through other means (such as desktop icons or start menu).

[0065] Afterwards, when the user wants to perform a folder comparison, he can right-click on a folder. At this time, the operating system can display a right-click menu containing multiple options. Since the folder comparison tool has been correctly integrated into the system at this time, the right-click menu will contain the menu item text previously added to the registry. When the user clicks on the menu item corresponding to the folder comparison tool in the right-click menu, a folder comparison instruction can be generated, which is a signal indicating the execution of the folder comparison operation. At this time, in response to the folder comparison instruction, the target dynamic link library file can be called through the fifth file path stored in the registry, thereby executing the functions and codes required for the folder comparison.

[0066] The embodiment of the present application seamlessly integrates the folder comparison tool into the user's daily operations by requesting administrator privileges from the operating system, modifying the registry, integrating the right-click menu, etc. The user only needs to right-click on the folder and then select the menu item to quickly start the folder comparison function and determine the folder to be compared. This method improves the usability and convenience of the tool, allowing users to manage and compare folders more easily.

[0067] Further, as Figure 1 The specific implementation of the method, the embodiment of the present application provides a folder comparison device based on Python, such as Figure 3 As shown, the device comprises:

[0068] A folder determination module, for determining a folder to be compared in response to a folder comparison instruction, and based on a directory where the folder to be compared is located, searching for an online folder from the directory, and searching for a folder with the same name as the folder to be compared under the online folder as a target reference folder;

[0069] An information extraction module, used to respectively obtain each first file in the folder to be compared and each second file in the target reference folder, and extract information from each of the first files and each of the second files according to a preset dimension to obtain first dimensional information corresponding to each of the first files and second dimensional information corresponding to each of the second files;

[0070] The folder comparison module is used to obtain the folder comparison result between the folder to be compared and the target reference folder according to the first dimension information corresponding to each of the first files and the second dimension information corresponding to each of the second files.

[0071] Optionally, the preset dimension includes signature information; when information extraction is performed according to the signature information, the first file and the second file are PE files in corresponding folders, and the information extraction module is used to:

[0072] For the PE files in each folder, perform the following operations to extract information, so as to obtain the first signature information corresponding to each of the first files and the second signature information corresponding to each of the second files:

[0073] Extracting the signature data address and the number of signature data bytes from the PE file, reading the target signature data according to the signature data address and the number of signature data bytes, parsing the target signature data to obtain a target certificate information set, and determining whether the data type of the target certificate information set is the target data type;

[0074] When the data type of the target certificate information set is the target data type, extracting the holder common name of the certificate contained in the target certificate information set through a holder common name extraction function to obtain the holder common name corresponding to the certificate, and extracting the signature algorithm of the certificate contained in the target certificate information set through a signature algorithm extraction function to obtain the signature algorithm corresponding to the certificate;

[0075] Based on a preset root certificate issuer list, filtering the holder's common name, and obtaining target signer information based on the filtering result;

[0076] The signature information corresponding to the PE file is obtained according to the target signer information and the signature algorithm corresponding to the target signer information.

[0077] Optionally, the information extraction module is further used to:

[0078] Obtain a data directory entry corresponding to the PE file, access the data directory entry, and search for the signature address data and the number of bytes of the signature data from the data directory entry.

[0079] Optionally, the information extraction module is further used to:

[0080] After obtaining the target certificate information set, identifying the signature content encapsulation field from the target certificate information set, determining the signature content encapsulation information based on the signature content encapsulation field, and judging whether there is a generation time field in the signature content encapsulation information;

[0081] When there is a generation time field in the signature content encapsulation information, formatting the timestamp indicated by the generation time field, and using the formatted timestamp as the timestamp corresponding to the target signer information, and updating the signature information corresponding to the PE file according to the timestamp corresponding to the target signer information;

[0082] When the generation time field does not exist in the signature content encapsulation information, the signature information field is identified from the target certificate information set, a signature information list is determined based on the signature information field, the signature information list is traversed to determine multiple signer information, as well as a signature algorithm corresponding to each signer information and a timestamp indicated by the generation time field, the timestamp is formatted to obtain a formatted timestamp, and the signature information corresponding to the PE file is obtained according to the multiple signer information, the signature algorithm corresponding to each signer information and the formatted timestamp.

[0083] Optionally, the device further comprises a list updating module; the list updating module is used to:

[0084] The root certificate issuer query information is sent to the large model according to a preset period, and based on the feedback result of the large model each time, the current preset root certificate issuer list is updated to obtain an updated preset root certificate issuer list.

[0085] Optionally, the folder comparison module is used to:

[0086] For each first file, determine a first file path of the first file in the folder to be compared, and search the target reference folder for a second file path that is the same as the first file path, and determine whether there is a target second file with the same name as the first file in the second file path;

[0087] When there is a target second file with the same name as the first file under the second file path, judging whether the first file has been modified based on the first dimension information corresponding to the first file and the second dimension information corresponding to the target second file, and determining that the first file is a modified file if it has been modified;

[0088] When there is no target second file with the same name as the first file under the second file path, determining that the first file is a newly added file;

[0089] For each second file, determine a third file path of the second file in the target reference folder, and search the folder to be compared for a fourth file path that is the same as the third file path, and determine whether there is a target first file with the same name as the second file under the fourth file path;

[0090] When there is no target first file with the same name as the second file under the fourth file path, determining that the second file is a deleted file;

[0091] According to each modified file, each newly added file, each deleted file, and the dimension information corresponding to each file, a folder comparison result between the folder to be compared and the target reference folder is obtained.

[0092] Optionally, the device further includes a right-click expansion module; the right-click expansion module is used to:

[0093] In response to the folder comparison instruction, before determining the folder to be compared, in response to the folder comparison tool startup instruction, requesting administrator privileges from the target operating system, and after being assigned the administrator privileges, adding a new registry entry to the registry corresponding to the target operating system, and adding a fifth file path of the target dynamic link library file and a menu item text displayed when the user right-clicks in the new registry entry;

[0094] Accordingly, the device further comprises an instruction generation module; the instruction generation module is used to:

[0095] In response to a right-click instruction of any folder, display a right-click menu page, wherein the right-click menu page includes menu item text corresponding to the folder comparison tool;

[0096] Based on a click operation on the menu item text corresponding to the folder comparison tool, a folder comparison instruction is generated, and based on the folder comparison instruction, the target dynamic link library file is called through the fifth file path, and the folder to be compared and the target reference folder are determined through the target dynamic link library file.

[0097] It should be noted that for other corresponding descriptions of the functional units involved in the python-based folder comparison device provided in the embodiment of the present application, please refer to Figure 1 to Figure 2 The corresponding description in the method will not be repeated here.

[0098] The present application also provides a computer device, which may be a personal computer, a server, a network device, etc. Figure 4 As shown, the computer device includes a bus, a processor, a memory and a communication interface, and may also include an input and output interface and a display 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, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store location information. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, the steps in each method embodiment are implemented.

[0099] Those skilled in the art will understand that Figure 4 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0100] In one embodiment, a computer-readable storage medium is provided. The computer-readable storage medium may be non-volatile or volatile, and stores a computer program thereon. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.

[0101] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.

[0102] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.

[0103] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and 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 embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.

[0104] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, 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, they should be considered to be within the scope of this specification.

[0105] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be construed as limiting the scope of the present application. It should be noted that, for a person of ordinary skill in the art, several modifications and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A folder comparison method based on Python, characterized in that: include: In response to the folder comparison instruction, a folder to be compared is determined, and based on the directory where the folder to be compared is located, an online folder is searched from the directory, and a folder with the same name as the folder to be compared is searched under the online folder as a target reference folder; Respectively obtaining each first file in the folder to be compared and each second file in the target reference folder, and extracting information from each of the first files and each of the second files according to preset dimensions to obtain first dimensional information corresponding to each of the first files and second dimensional information corresponding to each of the second files; According to the first dimension information corresponding to each of the first files and the second dimension information corresponding to each of the second files, a folder comparison result between the folder to be compared and the target reference folder is obtained.

2. The method according to claim 1, characterized in that The preset dimension includes signature information; when information extraction is performed according to the signature information, the first file and the second file are PE files in the folder to which they belong, and information extraction is performed on each of the first files and each of the second files according to the preset dimension to obtain first dimension information corresponding to each of the first files and second dimension information corresponding to each of the second files, including: For the PE files in each folder, perform the following operations to extract information, so as to obtain the first signature information corresponding to each of the first files and the second signature information corresponding to each of the second files: Extracting the signature data address and the number of signature data bytes from the PE file, reading the target signature data according to the signature data address and the number of signature data bytes, parsing the target signature data to obtain a target certificate information set, and determining whether the data type of the target certificate information set is the target data type; When the data type of the target certificate information set is the target data type, extracting the holder common name of the certificate contained in the target certificate information set through a holder common name extraction function to obtain the holder common name corresponding to the certificate, and extracting the signature algorithm of the certificate contained in the target certificate information set through a signature algorithm extraction function to obtain the signature algorithm corresponding to the certificate; Based on a preset root certificate issuer list, filtering the holder's common name, and obtaining target signer information based on the filtering result; The signature information corresponding to the PE file is obtained according to the target signer information and the signature algorithm corresponding to the target signer information.

3. The method according to claim 2, characterized in that The step of extracting the signature data address and the number of signature data bytes from the PE file includes: Obtain a data directory entry corresponding to the PE file, access the data directory entry, and search for the signature address data and the number of bytes of the signature data from the data directory entry.

4. The method according to claim 2, characterized in that: After obtaining the target certificate information set, the method further includes: Identify a signature content encapsulation field from the target certificate information set, determine signature content encapsulation information based on the signature content encapsulation field, and determine whether there is a generation time field in the signature content encapsulation information; When there is a generation time field in the signature content encapsulation information, formatting the timestamp indicated by the generation time field, and using the formatted timestamp as the timestamp corresponding to the target signer information, and updating the signature information corresponding to the PE file according to the timestamp corresponding to the target signer information; When the generation time field does not exist in the signature content encapsulation information, the signature information field is identified from the target certificate information set, a signature information list is determined based on the signature information field, the signature information list is traversed to determine multiple signer information, as well as a signature algorithm corresponding to each signer information and a timestamp indicated by the generation time field, the timestamp is formatted to obtain a formatted timestamp, and the signature information corresponding to the PE file is obtained according to the multiple signer information, the signature algorithm corresponding to each signer information and the formatted timestamp.

5. The method according to claim 2, characterized in that: The method further comprises: The root certificate issuer query information is sent to the large model according to a preset period, and based on the feedback result of the large model each time, the current preset root certificate issuer list is updated to obtain an updated preset root certificate issuer list.

6. The method according to claim 1, characterized in that The obtaining, according to the first dimension information corresponding to each of the first files and the second dimension information corresponding to each of the second files, a folder comparison result between the folder to be compared and the target reference folder includes: For each first file, determine a first file path of the first file in the folder to be compared, and search the target reference folder for a second file path that is the same as the first file path, and determine whether there is a target second file with the same name as the first file in the second file path; When there is a target second file with the same name as the first file under the second file path, judging whether the first file has been modified based on the first dimension information corresponding to the first file and the second dimension information corresponding to the target second file, and determining that the first file is a modified file if it has been modified; When there is no target second file with the same name as the first file under the second file path, determining that the first file is a newly added file; For each second file, determine a third file path of the second file in the target reference folder, and search the folder to be compared for a fourth file path that is the same as the third file path, and determine whether there is a target first file with the same name as the second file under the fourth file path; When there is no target first file with the same name as the second file under the fourth file path, determining that the second file is a deleted file; According to each modified file, each newly added file, each deleted file, and the dimension information corresponding to each file, a folder comparison result between the folder to be compared and the target reference folder is obtained.

7. The method according to claim 1, characterized in that Before determining the folder to be compared in response to the folder comparison instruction, the method further includes: In response to the folder comparison tool start instruction, request administrator privileges from the target operating system, and after being assigned the administrator privileges, add a new registry entry corresponding to the registry of the target operating system, and add a fifth file path of the target dynamic link library file and a menu item text displayed when the user right-clicks the new registry entry; Accordingly, the method further comprises: In response to a right-click instruction of any folder, display a right-click menu page, wherein the right-click menu page includes menu item text corresponding to the folder comparison tool; Based on a click operation on the menu item text corresponding to the folder comparison tool, a folder comparison instruction is generated, and based on the folder comparison instruction, the target dynamic link library file is called through the fifth file path, and the folder to be compared and the target reference folder are determined through the target dynamic link library file.

8. A folder comparison device based on Python, characterized in that: include: A folder determination module, for determining a folder to be compared in response to a folder comparison instruction, and based on a directory where the folder to be compared is located, searching for an online folder from the directory, and searching for a folder with the same name as the folder to be compared under the online folder as a target reference folder; An information extraction module, used to respectively obtain each first file in the folder to be compared and each second file in the target reference folder, and extract information from each of the first files and each of the second files according to a preset dimension to obtain first dimensional information corresponding to each of the first files and second dimensional information corresponding to each of the second files; The folder comparison module is used to obtain the folder comparison result between the folder to be compared and the target reference folder according to the first dimension information corresponding to each of the first files and the second dimension information corresponding to each of the second files.

9. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

10. A computer device comprising a storage medium, a processor, and a computer program stored in the storage medium and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 7 is implemented.