diff --git a/README.md b/README.md index b2022d6..b77c33d 100644 --- a/README.md +++ b/README.md @@ -78,3 +78,5 @@ cmake --build build -j 8 --config Release # Windows MinGW / Linux / macOS cmake --build build -j 8 ``` + +你可以在 `build` 文件夹下找到编译好的二进制文件,以及一个可供其它项目使用的动态库(Windows Only),使用方法见仓库的 `example` 文件夹 diff --git a/example/csharp/NeteaseCrypt.cs b/example/csharp/NeteaseCrypt.cs new file mode 100644 index 0000000..f3cc68e --- /dev/null +++ b/example/csharp/NeteaseCrypt.cs @@ -0,0 +1,61 @@ +using System; +using System.Runtime.InteropServices; + +namespace libncmdump_demo_cli +{ + /// + /// NeteaseCrypt C# Wrapper + /// + class NeteaseCrypt + { + const string DLL_PATH = "libncmdump.dll"; + + [DllImport(DLL_PATH, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr CreateNeteaseCrypt(IntPtr path); + + [DllImport(DLL_PATH, CallingConvention = CallingConvention.Cdecl)] + private static extern int Dump(IntPtr NeteaseCrypt); + + [DllImport(DLL_PATH, CallingConvention = CallingConvention.Cdecl)] + private static extern void FixMetadata(IntPtr NeteaseCrypt); + + [DllImport(DLL_PATH, CallingConvention = CallingConvention.Cdecl)] + private static extern void DestroyNeteaseCrypt(IntPtr NeteaseCrypt); + + private IntPtr NeteaseCryptClass = IntPtr.Zero; + + /// + /// 创建 NeteaseCrypt 类的实例。 + /// + /// 网易云音乐 ncm 加密文件路径 + public NeteaseCrypt(string FileName) + { + NeteaseCryptClass = CreateNeteaseCrypt(Marshal.StringToHGlobalAnsi(FileName)); + } + + /// + /// 启动转换过程。 + /// + /// 返回一个整数,指示转储过程的结果。如果成功,返回0;如果失败,返回1。 + public int Dump() + { + return Dump(NeteaseCryptClass); + } + + /// + /// 修复音乐文件元数据。 + /// + public void FixMetadata() + { + FixMetadata(NeteaseCryptClass); + } + + /// + /// 销毁 NeteaseCrypt 类的实例。 + /// + public void Destroy() + { + DestroyNeteaseCrypt(NeteaseCryptClass); + } + } +} diff --git a/example/csharp/Program.cs b/example/csharp/Program.cs new file mode 100644 index 0000000..8665adb --- /dev/null +++ b/example/csharp/Program.cs @@ -0,0 +1,26 @@ +using System; +using System.Threading.Tasks; + +namespace libncmdump_demo_cli +{ + internal class Program + { + static void Main(string[] args) + { + // 文件名 + string filePath = "test.ncm"; + + // 创建 NeteaseCrypt 类的实例 + NeteaseCrypt neteaseCrypt = new NeteaseCrypt(filePath); + + // 启动转换过程 + int result = neteaseCrypt.Dump(); + + // 修复元数据 + neteaseCrypt.FixMetadata(); + + // [务必]销毁 NeteaseCrypt 类的实例 + neteaseCrypt.Destroy(); + } + } +}