ironfede / openmcdf

Microsoft Compound File .net component - pure C# - netstandard 2.0
Mozilla Public License 2.0
295 stars 72 forks source link

Work incorrect with '.automaticDestinations-ms' #127

Closed shanxing2 closed 2 months ago

shanxing2 commented 2 months ago

Hi,i use openmcdf to modify '.automaticDestinations-ms' file in C:\Users\username\AppData\Roaming\Microsoft\Windows\Recent\AutomaticDestinations.I want to modify the username in the file, but I have encountered some issues. If i modify it use same length data it work good but not same length work incorrect.After modify,if the data length is the same,both StructuredStorageXplorer 2.3.1.0 and JumpListExplorer V2.0.0.0 can be read normally.However, if the data length is different, StructuredStorageXplorer can read it normally, but JumpListExplorer cannot read it properly, and the Windows system cannot recognize this file properly.

00 01

for example,file 'f01b4d95cf55d32a.automaticDestinations-ms',username is 'pty',i replace it to 'abc',it work good.However,if i replace it to 'abchhh',StructuredStorageXplorer and the Windows system cannot recognize this file properly. The error prompted by a is ‘Offest and length were out of bounds for the arrya or count is greater than the number of elements from index to the end of the source collection.

Here is my code in vb.net.

Dim action = Sub(target As CFItem)
                         Debug.Print($"entry {target.Name}({If(target.IsStream, target.Size & " bytes", "")})")
                         Dim cfstream  = TryCast(target, CFStream)
                         Dim oldBytes = cfstream.GetData
                         Dim newBytes= some code to replace 'pty' to 'pty233' in oldBytes
                         cfstream.SetData(newBytes)
                     End Sub

Using fs = New FileStream(file, FileMode.Open, FileAccess.ReadWrite, FileShare.Read)
    Using cf = New CompoundFile(fs, CFSUpdateMode.Update, CFSConfiguration.Default)       
        cf.RootStorage.VisitEntries(action, False)

        cf.Commit(True)
    End Using
ironfede commented 2 months ago

Hi @shanxing2 , what happens (only for test) if you change data in a single entry and not in a loop for all entries? I would understand if issue is action-loop related or if there's some problem in the single write/commit operation. Thank you

shanxing2 commented 2 months ago

Yes, I have tested it and there are also issues when changing only a single entry.

Last comment,misoperation,I don't know how to undo the close operation.

shanxing2 commented 2 months ago

I found that the length did not change after the modification. image