Add-Type@" using System; using System.Runtime.InteropServices; public class Win32Cred { [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct CREDENTIAL { public int Flags; public int Type; public IntPtr TargetName; public IntPtr Comment; public System.Runtime.InteropServices.ComTypes.FILETIME LastWritten; public int CredentialBlobSize; public IntPtr CredentialBlob; public int Persist; public int AttributeCount; public IntPtr Attributes; public IntPtr TargetAlias; public IntPtr UserName; } [DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)] public static extern bool CredReadW( string target, int type, int reservedFlag, out IntPtr credentialPtr); [DllImport("advapi32.dll", SetLastError = true)] public static extern void CredFree(IntPtr buffer); public static string CredRead(string targetName, int type = 1) { IntPtr credPtr; if (CredReadW(targetName, type, 0, out credPtr)) { CREDENTIAL cred = (CREDENTIAL)Marshal.PtrToStructure( credPtr, typeof(CREDENTIAL)); string pass = Marshal.PtrToStringAnsi( cred.CredentialBlob, cred.CredentialBlobSize); CredFree(credPtr); return pass; } throw new System.ComponentModel.Win32Exception( Marshal.GetLastWin32Error()); } } "@
在文章将公牛智家设备接入 Home Assistant 中,笔者介绍了通过抓包分析将公牛智能开关接入 Home Assistant 的方法。最近,家里的菲斯曼(Viessmann)壁炉也需要接入智能家居系统,以便更灵活地控制暖气和热水温度。虽然菲斯曼官方提供了 ViCare App,但其对第三方集成的支持主要集中在欧洲服务器,而中国区的设备使用的是独立的服务器和 API,现有的开源插件无法直接使用。因此,笔者再次通过抓包分析,实现了对菲斯曼中国区设备的接入。