public AutoDestList(DestListEntry destEntry, LnkFile lnk) { Hostname = destEntry.Hostname; VolumeDroid = destEntry.VolumeDroid; VolumeBirthDroid = destEntry.VolumeBirthDroid; FileDroid = destEntry.FileDroid; FileBirthDroid = destEntry.FileBirthDroid; EntryNumber = destEntry.EntryNumber; CreatedOn = destEntry.CreationTime; LastModified = destEntry.LastModified; Pinned = destEntry.PinStatus != -1; Path = destEntry.Path; MacAddress = destEntry.MacAddress; Lnk = lnk; }
public LnkFile GetLnkFromDirectoryName(string dirName) { var dirItem = _oleContainer.Directory.SingleOrDefault( t => string.Equals(t.DirectoryName, dirName, StringComparison.InvariantCultureIgnoreCase)); if (dirItem != null) { var sfn = $"{SourceFile}_Directory name_{dirItem.DirectoryName:X}"; var p = _oleContainer.GetPayloadForDirectory(dirItem); var dlnk = new LnkFile(p, sfn); return(dlnk); } return(null); }
public AutomaticDestination(byte[] rawBytes, string sourceFile) { if (rawBytes.Length == 0) { throw new Exception("Empty file"); } SourceFile = sourceFile; var appid = Path.GetFileName(sourceFile).Split('.').FirstOrDefault(); if (appid != null) { var aid = new AppIdInfo(appid); AppId = aid; } else { AppId = new AppIdInfo("Unable to determine AppId"); } _oleContainer = new OleCfFile(rawBytes, sourceFile); Directory = _oleContainer.Directory; var destList = _oleContainer.Directory.SingleOrDefault(t => t.DirectoryName.ToLowerInvariant() == "destlist"); if (destList != null && destList.DirectorySize > 0) { var destBytes = _oleContainer.GetPayloadForDirectory(destList); DestList = new DestList(destBytes); } DestListEntries = new List <AutoDestList>(); if (DestList != null) { DestListCount = DestList.Header.NumberOfEntries; DestListVersion = DestList.Header.Version; LastUsedEntryNumber = DestList.Header.LastEntryNumber; foreach (var entry in DestList.Entries) { var dirItem = _oleContainer.Directory.SingleOrDefault( t => string.Equals(t.DirectoryName, entry.EntryNumber.ToString("X"), StringComparison.InvariantCultureIgnoreCase)); if (dirItem != null) { var sfn = $"{sourceFile}_Directory name_{dirItem.DirectoryName:X}"; var p = _oleContainer.GetPayloadForDirectory(dirItem); var dlnk = new LnkFile(p, sfn); var dle = new AutoDestList(entry, dlnk); DestListEntries.Add(dle); } else { var dleNull = new AutoDestList(entry, null); DestListEntries.Add(dleNull); } } } }
public Entry(byte[] rawBytes, int entryOffset) { LnkFiles = new List <LnkFile>(); lnkBytes = new Dictionary <string, byte[]>(); Unknown0 = BitConverter.ToInt32(rawBytes, 0); Rank = BitConverter.ToSingle(rawBytes, 4); Unknown2 = BitConverter.ToInt32(rawBytes, 8); HeaderType = BitConverter.ToInt32(rawBytes, 12); Name = string.Empty; if (HeaderType == 0) { var nameLen = BitConverter.ToInt16(rawBytes, 16); Name = Encoding.Unicode.GetString(rawBytes, 18, nameLen * 2).Split('\0').First(); } var lnkOffsets = new List <int>(); var index = 0; var footerPos = CustomDestination.ByteSearch(rawBytes, footerBytes, index); while (index < rawBytes.Length) { var lo = CustomDestination.ByteSearch(rawBytes, lnkHeaderBytes, index); if (lo == -1) { break; } lnkOffsets.Add(lo); index = lo + 1; //add length so we do not hit on it again } // Debug.WriteLine($"Link offsets contains {lnkOffsets.Count} offsets: {string.Join(", ", lnkOffsets)}"); // Debug.WriteLine($"Footer pos: {footerPos}"); var counter = 0; var max = lnkOffsets.Count - 1; foreach (var lnkOffset in lnkOffsets) { var start = 0; var end = 0; if (counter == max) { //last one, so we need to use footerpos start = lnkOffset; end = footerPos; } else { start = lnkOffset; end = lnkOffsets[counter + 1]; } var bytes = new byte[end - start]; Buffer.BlockCopy(rawBytes, start, bytes, 0, bytes.Length); var name = $"Offset_0x{entryOffset + lnkOffset:X}.lnk"; lnkBytes.Add(name, bytes); var l = new LnkFile(bytes, name); LnkFiles.Add(l); counter += 1; } }