A method, device and electronic device for recovering deleted NTFS files
By searching and sorting the record items of the $Logfile file in the NTFS file system, identifying deletion transactions and extracting relevant information, it solves the problem of incomplete searches in the NTFS file system and achieves comprehensive recovery of deleted files.
Patent Information
- Application Number
- CN202011502957.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-17
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2040-12-17
AI Technical Summary
The existing technology has the problem of incomplete search when searching and recovering deleted files in the NTFS file system, and the repeated use of $MFT files makes recovery difficult.
By searching the $Logfile file in the NTFS volume header information, parsing and sorting record items, dividing them into transactions, identifying deletion transactions and extracting file or folder information and storage information based on redo and undo operations.
It achieves comprehensive search and recovery of deleted files in the NTFS file system, improving the integrity and accuracy of file recovery.
Smart Images

Figure CN112486734B
Abstract
Description
Technical Field
[0001] One or more embodiments of the present specification relate to the technical field of NTFS deleted file recovery, and more particularly to a method, device and electronic device for recovering NTFS deleted files. Background Art
[0002] NTFS is the mainstream file system on Windows. Under this file system, if you need to retrieve deleted files, you currently mostly use the $MFT file of the file system to find them. However, the $MFT file is reused. After a file is deleted, the corresponding $MFT file may be assigned to a new file placed on the disk, making it difficult to recover the deleted file. Therefore, in the prior art, there is a problem of incomplete search when searching and recovering deleted files through the $MFT file. Summary of the invention
[0003] In view of this, the purpose of one or more embodiments of the present specification is to provide an NTFS deleted file recovery method, device and electronic device, which can comprehensively search and recover deleted files in the NTFS file system.
[0004] Based on the above purpose, one or more embodiments of this specification provide a method for recovering deleted NTFS files, including:
[0005] Find the $Logfile file based on the NTFS volume header information;
[0006] Parsing the $Logfile file, obtaining the record items therein, and sorting the record items based on the sequence numbers of the record items;
[0007] Dividing the sorted record items into a plurality of transactions;
[0008] For each transaction, find whether there is a record entry whose redo operation is DeallocateFileRecordSegmen in the transaction. If yes, the transaction is a delete transaction.
[0009] For each record item in the deletion transaction, extract the deleted file or folder information from the record items whose redo operation is DeleteIndexEntryAllocation and whose undo operation is AddIndexEntryAllocation;
[0010] For each record item in the deletion transaction, the storage information of the deleted file is extracted from the record item whose redo operation is ClearBitsInNonResidentBitmap and whose undo operation is SetBitsInNonResidentBitmap.
[0011] As an optional implementation manner, searching for the $Logfile file according to the volume header information of NTFS includes:
[0012] Locate the $MFT file based on the NTFS volume header information;
[0013] Search the $Logfile file through the $MFT file.
[0014] As an optional implementation, the serial number consists of the first 8 bytes of the record item.
[0015] As an optional implementation manner, the ordering the record items based on the sequence numbers of the record items includes:
[0016] The record items are sorted in ascending order of the sequence numbers.
[0017] As an optional implementation, the record item sequence is divided into multiple transactions, wherein the first record item of each transaction is a record item with a previous sequence number of 0, and the last record item is a record item with a redo operation of ForgetTransaction.
[0018] As an optional implementation, the integer consisting of 8 bytes starting from the offset 8 bytes of each record item is the previous sequence number, and the integer value consisting of 2 bytes at the offset 0x30 position of each record item is the redo operation.
[0019] As an optional implementation, the 2-byte integer value at the offset 0x32 position of each record item is the undo operation value, and in the content area of the undo operation value, the name of the deleted file or folder starts at the offset 0x52 position.
[0020] As a second aspect of the present invention, there is provided an NTFS deleted file recovery device, comprising:
[0021] The first search unit is used to search for the $Logfile file according to the volume header information of NTFS;
[0022] A parsing and sorting unit, used for parsing the $Logfile file, obtaining the record items therein, and sorting the record items based on the sequence numbers of the record items;
[0023] A division unit, used for dividing the sorted record items into a plurality of transactions;
[0024] The second search unit is used to search, for each transaction, whether there is a record entry whose redo operation is DeallocateFileRecordSegmen in the transaction, and if so, the transaction is a delete transaction;
[0025] A first extraction unit is used to extract deleted file or folder information from the record items whose redo operation is DeleteIndexEntryAllocation and whose undo operation is AddIndexEntryAllocation for each record item in the deletion transaction;
[0026] The second extraction unit is used to extract the storage information of the deleted file from the record items whose redo operation is ClearBitsInNonResidentBitmap and whose undo operation is SetBitsInNonResidentBitmap for each record item in the deletion transaction.
[0027] As an optional implementation manner, the first searching unit is used to:
[0028] Locate the $MFT file based on the NTFS volume header information;
[0029] Search the $Logfile file through the $MFT file.
[0030] As a third aspect of the present invention, there is also provided an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method described above when executing the program.
[0031] From the above description, it can be seen that an NTFS deleted file recovery method, device and electronic device provided by one or more embodiments of the present specification searches for the $Logfile file in the file system, sorts the record items in the found $Logfile file, divides the sorted record items into multiple transactions, finds the deleted transaction therein, and extracts the file or folder information and the storage information of the file based on the redo operation and the undo operation for the record items in the deleted transaction, thereby realizing comprehensive search and recovery of deleted files in the NTFS file system. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] In order to more clearly illustrate one or more embodiments of the present specification or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only one or more embodiments of the present specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0033] Figure 1 A logical diagram of a method for recovering deleted NTFS files according to one or more embodiments of the present specification;
[0034] Figure 2 A logical schematic diagram of an NTFS deleted file recovery device according to one or more embodiments of the present specification;
[0035] Figure 3 A schematic diagram of an electronic device according to one or more embodiments of the present specification. DETAILED DESCRIPTION
[0036] In order to make the objectives, technical solutions and advantages of the present disclosure more clearly understood, the present disclosure is further described in detail below in combination with specific embodiments and with reference to the accompanying drawings.
[0037] To achieve the above-mentioned object of the invention, the present invention provides a method for recovering deleted NTFS files, comprising:
[0038] Find the $Logfile file based on the NTFS volume header information;
[0039] Parsing the $Logfile file, obtaining the record items therein, and sorting the record items based on the sequence numbers of the record items;
[0040] Dividing the sorted record items into a plurality of transactions;
[0041] For each transaction, find whether there is a record entry whose redo operation is DeallocateFileRecordSegmen in the transaction. If yes, the transaction is a delete transaction.
[0042] For each record item in the deletion transaction, extract the deleted file or folder information from the record items whose redo operation is DeleteIndexEntryAllocation and whose undo operation is AddIndexEntryAllocation;
[0043] For each record item in the deletion transaction, the storage information of the deleted file is extracted from the record item whose redo operation is ClearBitsInNonResidentBitmap and whose undo operation is SetBitsInNonResidentBitmap.
[0044] In an embodiment of the present invention, by searching for the $Logfile file in the file system and sorting the record items in the found $Logfile file, the sorted record items are divided into multiple transactions, and the deletion transaction is found. For the record items in the deletion transaction, the file or folder information and the storage information of the file are extracted based on the redo operation and the undo operation, thereby realizing comprehensive search and recovery of deleted files in the NTFS file system.
[0045] like Figure 1 As shown, the present invention provides a method for recovering deleted NTFS files, comprising:
[0046] S100. Search for the $Logfile file according to the NTFS volume header information.
[0047] Optionally, searching for the $Logfile file according to the volume header information of NTFS includes:
[0048] Locate the $MFT file based on the NTFS volume header information;
[0049] Search the $Logfile file through the $MFT file.
[0050] S200, parsing the $Logfile file, obtaining the record items therein, and sorting the record items based on the sequence numbers lsn of the record items.
[0051] The serial number lsn is composed of the first 8 bytes of the record item.
[0052] The record items are sorted in ascending order of the sequence numbers.
[0053] Among them, the record item: record is an operation on the NTFS metafile.
[0054] S300: Divide the sorted record items into multiple transactions.
[0055] Transaction: A transaction consists of multiple record items.
[0056] Applications can use Transactional NTFS to group a series of changes to files into a transaction. Transactions ensure that all changes are either effective or invalidated at the same time, and that external applications cannot be notified of any changes until the transaction is committed.
[0057] The first record item of each transaction is the record item with the previous sequence number pre lsn being 0, and the last record item is the record item with the redo operation being ForgetTransaction (value being 27).
[0058] Among them, the Redo operation is the operation performed on the current record item.
[0059] Each record item stores the serial number lsn of the current record item and the serial number of the record item immediately before the current record item, recorded as the previous serial number pre lsn.
[0060] For the first record item of each transaction, there is no previous record item, so the previous sequence number pre lsn of the first record item is 0.
[0061] The integer consisting of 8 bytes starting from the offset of 8 bytes of each record item is the previous sequence number pre lsn, and the integer value consisting of 2 bytes at the offset of 0x30 of each record item is the redo operation.
[0062] S400. For each transaction, find out whether there is a record entry whose redo operation is DeallocateFileRecordSegmen (value is 3) in the transaction. If yes, the transaction is a delete transaction.
[0063] S500 . For each record item in the deletion transaction, extract the deleted file or folder information from the record items whose redo operation is DeleteIndexEntryAllocation (value is 15) and whose undo operation is AddIndexEntryAllocation (value is 14).
[0064] Among them, the undo operation is to withdraw the operation of the current record item. The 2 bytes at the offset 0x38 of each record item represent the offset of the undo operation content, and the 2 bytes at the position 0x40 represent the length of the undo operation content.
[0065] The 2-byte integer value at the offset 0x32 position of each record item is the undo operation value. In the content area of the undo operation value, the name of the deleted file or folder starts at the offset 0x52 position.
[0066] S600 . For each record item in the deletion transaction, extract the storage information of the deleted file from the record item whose redo operation is ClearBitsInNonResidentBitmap (value is 22) and whose undo operation is SetBitsInNonResidentBitmap (value is 21).
[0067] The first 4 bytes of the undo content area in the record are the starting cluster number of the file, and the following 4 bytes are the number of clusters used.
[0068] In addition, it should be noted that files are not stored continuously, and there will be multiple record items. Each record item represents a storage block. Only by combining multiple storage blocks together can the file storage area be obtained, so as to recover the deleted files.
[0069] It should be noted that the method of one or more embodiments of this specification can be performed by a single device, such as a computer or server. The method of this embodiment can also be applied in a distributed scenario and completed by multiple devices cooperating with each other. In the case of such a distributed scenario, one of the multiple devices can only perform one or more steps in the method of one or more embodiments of this specification, and the multiple devices will interact with each other to complete the described method.
[0070] It should be noted that the above is a description of a specific embodiment of the present specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0071] Corresponding to the NTFS deleted file recovery method, the present invention also provides an NTFS deleted file recovery device, such as Figure 2 As shown, including:
[0072] The first search unit 10 is used to search for the $Logfile file according to the volume header information of NTFS;
[0073] A parsing and sorting unit 20, configured to parse the $Logfile file, obtain the record items therein, and sort the record items based on the sequence numbers of the record items;
[0074] A division unit 30, configured to divide the sorted record items into a plurality of transactions;
[0075] The second search unit 40 is used to search, for each transaction, whether there is a record entry whose redo operation is DeallocateFileRecordSegmen in the transaction, and if so, the transaction is a delete transaction;
[0076] The first extraction unit 50 is used to extract the deleted file or folder information from the record items whose redo operation is DeleteIndexEntryAllocation and whose undo operation is AddIndexEntryAllocation for each record item in the deletion transaction;
[0077] The second extraction unit 60 is used to extract the storage information of the deleted file from the record items whose redo operation is ClearBitsInNonResidentBitmap and whose undo operation is SetBitsInNonResidentBitmap for each record item in the deletion transaction.
[0078] In an embodiment of the present invention, by searching for the $Logfile file in the file system and sorting the record items in the found $Logfile file, the sorted record items are divided into multiple transactions, and the deletion transaction is found. For the record items in the deletion transaction, the file or folder information and the storage information of the file are extracted based on the redo operation and the undo operation, thereby realizing comprehensive search and recovery of deleted files in the NTFS file system.
[0079] As an optional implementation manner, the first searching unit is used to:
[0080] Locate the $MFT file based on the NTFS volume header information;
[0081] Search the $Logfile file through the $MFT file.
[0082] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in one or more embodiments of this specification should be understood by people with ordinary skills in the field to which this disclosure belongs. The words "first", "second" and similar words used in one or more embodiments of this specification do not indicate any order, quantity or importance, but are only used to distinguish different components. "Include" or "comprises" and similar words mean that the elements or objects appearing before the word include the elements or objects listed after the word and their equivalents, without excluding other elements or objects.
[0083] For the convenience of description, the above devices are described in terms of functions divided into various modules. Of course, when implementing one or more embodiments of this specification, the functions of each module can be implemented in the same or multiple software and / or hardware.
[0084] Based on the same inventive concept, corresponding to any of the above-mentioned embodiments and methods, one or more embodiments of this specification also provide an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the NTFS deleted file recovery method described in any of the above embodiments is implemented.
[0085] Figure 3 A more specific schematic diagram of the hardware structure of an electronic device provided in this embodiment is shown, and the device may include: a processor 1010, a memory 1020, an input / output interface 1030, a communication interface 1040, and a bus 1050. The processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040 are connected to each other through the bus 1050 in the device.
[0086] The processor 1010 can be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification.
[0087] The memory 1020 may be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 1020 may store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program codes are stored in the memory 1020 and are called and executed by the processor 1010.
[0088] The input / output interface 1030 is used to connect the input / output module to realize information input and output. The input / output module can be configured in the device as a component (not shown in the figure), or it can be externally connected to the device to provide corresponding functions. The input device may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output device may include a display, a speaker, a vibrator, an indicator light, etc.
[0089] The communication interface 1040 is used to connect a communication module (not shown) to realize communication interaction between the device and other devices. The communication module can realize communication through a wired mode (such as USB, network cable, etc.) or a wireless mode (such as mobile network, WIFI, Bluetooth, etc.).
[0090] The bus 1050 includes a path that transmits information between the various components of the device (eg, the processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040).
[0091] It should be noted that, although the above device only shows the processor 1010, the memory 1020, the input / output interface 1030, the communication interface 1040 and the bus 1050, in the specific implementation process, the device may also include other components necessary for normal operation. In addition, it can be understood by those skilled in the art that the above device may also only include the components necessary for implementing the embodiments of the present specification, and does not necessarily include all the components shown in the figure.
[0092] The electronic device of the above embodiment is used to implement the corresponding NTFS deleted file recovery method in any of the above embodiments, and has the beneficial effects of the corresponding method embodiment, which will not be repeated here.
[0093] Those skilled in the art should understand that the discussion of any of the above embodiments is merely illustrative and is not intended to imply that the scope of the present disclosure (including the claims) is limited to these examples. In line with the present disclosure, the technical features in the above embodiments or different embodiments may be combined, the steps may be implemented in any order, and there are many other variations of different aspects of one or more embodiments of the present specification as described above, which are not provided in detail for the sake of simplicity.
[0094] One or more embodiments of this specification are intended to cover all such substitutions, modifications and variations that fall within the broad scope of the appended claims. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of this specification should be included in the scope of protection of this disclosure.
Claims
1. A method for recovering deleted NTFS files, characterized in that: include: Find the $Logfile file based on the NTFS volume header information; Parsing the $Logfile file, obtaining the record items therein, and sorting the record items based on the sequence numbers of the record items; Dividing the sorted record items into a plurality of transactions; For each transaction, find whether there is a record entry whose redo operation is DeallocateFileRecordSegmen in the transaction. If yes, the transaction is a delete transaction. For each record item in the deletion transaction, extract the deleted file or folder information from the record items whose redo operation is DeleteIndexEntryAllocation and whose undo operation is AddIndexEntryAllocation; For each record item in the deletion transaction, extract the storage information of the deleted file from the record item whose redo operation is ClearBitsInNonResidentBitmap and whose undo operation is SetBitsInNonResidentBitmap; Applications use transactional NTFS to group a series of changes to a file into a single transaction; Transactions ensure that all changes take effect and are invalidated at the same time, and ensure that external applications cannot be notified of any changes before the transaction is committed. The sorted record items are divided into multiple transactions, wherein the first record item of each transaction is a record item with a previous sequence number of 0, and the last record item is a record item with a redo operation of ForgetTransaction; the integer consisting of 8 bytes starting from the offset 8 bytes of each record item is the previous sequence number, and the integer value consisting of 2 bytes at the offset 0x30 position of each record item is the redo operation value; each record item stores the sequence number lsn of the current record item and the sequence number of the previous record item next to the current record item, recorded as the previous sequence number pre lsn; The sequence number is composed of the first 8 bytes of the record item; The step of sorting the record items based on the serial numbers of the record items comprises: sorting the record items in ascending order of the serial numbers; The 2-byte integer value at the offset 0x32 position of each record item is the undo operation value. In the content area of the undo operation value, the name of the deleted file or folder starts at the offset 0x52 position.
2. The NTFS deleted file recovery method according to claim 1, characterized in that: The step of searching the $Logfile file according to the NTFS volume header information includes: Locate the $MFT file based on the NTFS volume header information; Search the $Logfile file through the $MFT file.
3. A device for recovering deleted NTFS files, characterized in that: include: The first search unit is used to search for the $Logfile file according to the volume header information of NTFS; A parsing and sorting unit, used for parsing the $Logfile file, obtaining the record items therein, and sorting the record items based on the sequence numbers of the record items; A division unit, used for dividing the sorted record items into a plurality of transactions; The second search unit is used to search, for each transaction, whether there is a record entry whose redo operation is DeallocateFileRecordSegmen in the transaction, and if so, the transaction is a delete transaction; A first extraction unit is used to extract deleted file or folder information from the record items whose redo operation is DeleteIndexEntryAllocation and whose undo operation is AddIndexEntryAllocation for each record item in the deletion transaction; A second extraction unit is used to extract the storage information of the deleted file from the record items whose redo operation is ClearBitsInNonResidentBitmap and whose undo operation is SetBitsInNonResidentBitmap for each record item in the deletion transaction; Applications use transactional NTFS to group a series of changes to a file into a single transaction; Transactions ensure that all changes take effect and are invalidated at the same time, and ensure that external applications cannot be notified of any changes before the transaction is committed. The sorted record items are divided into multiple transactions, wherein the first record item of each transaction is a record item with a previous sequence number of 0, and the last record item is a record item with a redo operation of ForgetTransaction; the integer consisting of 8 bytes starting from the offset 8 bytes of each record item is the previous sequence number, and the integer value consisting of 2 bytes at the offset 0x30 position of each record item is the redo operation value; each record item stores the sequence number lsn of the current record item and the sequence number of the previous record item next to the current record item, recorded as the previous sequence number pre lsn; The sequence number is composed of the first 8 bytes of the record item; The step of sorting the record items based on the serial numbers of the record items comprises: sorting the record items in ascending order of the serial numbers; The 2-byte integer value at the offset 0x32 position of each record item is the undo operation value. In the content area of the undo operation value, the name of the deleted file or folder starts at the offset 0x52 position.
4. The NTFS deleted file recovery device according to claim 3, characterized in that: The first searching unit is used for: Locate the $MFT file based on the NTFS volume header information; Search the $Logfile file through the $MFT file.
5. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the method according to any one of claims 1 to 2 is implemented.
