我如何通过c#解析.cat(Windows系统目录)文件

时间:2015-11-11 13:43:21

标签: c# winapi cryptography

我正在通过c#尝试解析.cat文件。为此,我使用winapi的CRYPTOCAT函数。但是这种方法对我来说非常难:(而且我无法反映它的一些结构和方法。你能帮助我吗?我需要使用什么,这个过程会更简单。

那是我的代码:

static IntPtr WrapperUse(string fileName)
        {
            var hCatalog = CryptCATOpen(fileName.ToCharArray(), 2, 0, 0x200, 0x00000001);
            unsafe
            {
                var storePtr = CryptCATStoreFromHandle(hCatalog);
                var store = Marshal.PtrToStructure(storePtr, typeof(CRYPTCATSTORE));
                IntPtr pMemberPtr = IntPtr.Zero;
                var pMember = CryptCATEnumerateMember(hCatalog, pMemberPtr);


            }
            return hCatalog;
        }

        [DllImport("Wintrust.dll")]
        private static extern IntPtr CryptCATOpen(char[] pwszFileName, uint fdwOpenFlags, uint hProv,
            uint dwPublicVersion, uint dwEncodingType);

        [DllImport("Wintrust.dll")]
        private unsafe static extern IntPtr CryptCATStoreFromHandle(IntPtr hCatalog);

        [DllImport("Wintrust.dll")]
        [return: MarshalAs(UnmanagedType.Struct)]
        private static extern unsafe CRYPTCATMEMBER CryptCATEnumerateMember(IntPtr hCatalog,
            IntPtr pPrevMember);

    }
    [StructLayout(LayoutKind.Sequential)]
    public unsafe struct CRYPTCATSTORE
    {
        public UInt32 cbStruct;
        public UInt32 dwPublicVersion;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string pwszP7File;
        public UIntPtr hProv;
        public uint dwEncodingType;
        public uint fdwStoreFlags;
        public IntPtr hReserved;
        public IntPtr hAttrs;
        public IntPtr hCryptMsg;
        public IntPtr hSorted;

    }

    [StructLayout(LayoutKind.Sequential)]
    public unsafe struct CRYPTCATMEMBER
    {
        public uint cbStruct;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string pwszReferenceTag;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string pwszFileName;

        //fixed byte gSubjectType[16]; //GUID
        [MarshalAs(UnmanagedType.Struct)]
        public GUID gSubjectType;
        public uint fdwMemberFlags;
        public IntPtr pIndirectData;
        public uint dwCertVersion;
        public uint dwReserved;
        public IntPtr hReserved;
        [MarshalAs(UnmanagedType.Struct)]
        public CRYPT_ATTR_BLOB sEncodedIndirectData;
        [MarshalAs(UnmanagedType.Struct)]
        public CRYPT_ATTR_BLOB sEncodedMemberInfo;
    }

    [StructLayout(LayoutKind.Sequential)]
    public unsafe struct GUID 
    {
        public UInt32 Data1;
        public ushort Data2;
        public ushort Data3;
        public fixed byte Data4[8];
    }


    [StructLayout(LayoutKind.Sequential)]
    public unsafe struct CRYPT_ATTR_BLOB
    {
        public uint cbData;
        //[MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
        //[MarshalAs(UnmanagedType.AsAny)]
        public byte[] pbData;

    }

由于

0 个答案:

没有答案