C# Code to Parse *.automaticDestinations-ms Files on Windows 10
{"using System; \nusing System.IO; \nusing System.Runtime.InteropServices; \n\nclass Program \n{ \n [DllImport("propsys.dll", SetLastError = true, CharSet = CharSet.Unicode)] \n static extern int PSGetPropertyKeyFromName( \n [In] string pszName, \n out PropertyKey pkey \n ); \n\n [StructLayout(LayoutKind.Sequential, Pack = 4)] \n public struct PropertyKey \n { \n public Guid fmtid; \n public uint pid; \n\n public PropertyKey(Guid guid, uint id) \n { \n fmtid = guid; \n pid = id; \n } \n } \n\n static void Main() \n { \n string filePath = "@C:\Path\To\automaticDestinations-ms\file.automaticDestinations-ms"; \n\n try \n { \n // Parse the PropertyKey for the PKEY_AppUserModel_ID property \n PropertyKey appUserModelIdKey; \n int result = PSGetPropertyKeyFromName("System.AppUserModel.ID", out appUserModelIdKey); \n\n if (result != 0) \n { \n Console.WriteLine("Failed to get the PropertyKey for System.AppUserModel.ID."); \n return; \n } \n\n // Read the automaticDestinations-ms file as a binary file \n byte[] fileBytes = File.ReadAllBytes(filePath); \n\n // Find the offset of the PKEY_AppUserModel_ID property \n int offset = FindPattern(fileBytes, BitConverter.GetBytes(appUserModelIdKey.fmtid.ToByteArray())); \n\n if (offset != -1) \n { \n // Extract the value of PKEY_AppUserModel_ID \n byte[] idValueBytes = new byte[256]; // Assuming the maximum length of the value is 256 \n Array.Copy(fileBytes, offset, idValueBytes, 0, idValueBytes.Length); \n\n string idValue = System.Text.Encoding.Unicode.GetString(idValueBytes).Trim('\0'); \n\n Console.WriteLine("PKEY_AppUserModel_ID value: " + idValue); \n } \n else \n { \n Console.WriteLine("PKEY_AppUserModel_ID not found in the file."); \n } \n } \n catch (Exception ex) \n { \n Console.WriteLine("Error: " + ex.Message); \n } \n } \n\n // Helper method to find a byte pattern in a byte array \n static int FindPattern(byte[] data, byte[] pattern) \n { \n int patternLength = pattern.Length; \n int totalLength = data.Length - patternLength; \n\n for (int i = 0; i <= totalLength; i++) \n { \n bool found = true; \n\n for (int j = 0; j < patternLength; j++) \n { \n if (data[i + j] != pattern[j]) \n { \n found = false; \n break; \n } \n } \n\n if (found) \n return i; \n } \n\n return -1; \n } \n}
原文地址: https://www.cveoy.top/t/topic/p5hu 著作权归作者所有。请勿转载和采集!