From 75e3899551f933d0290adc33bb72f7e09ccb7e17 Mon Sep 17 00:00:00 2001 From: Fu Diwei Date: Wed, 26 Feb 2025 16:40:15 +0800 Subject: [PATCH] =?UTF-8?q?chore(work):=20=E8=B0=83=E6=95=B4=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExtendedSDK/Finance/WechatWorkFinanceClient.cs | 7 ++++--- .../[Internal]/MarshalHelper.cs} | 7 +++++-- 2 files changed, 9 insertions(+), 5 deletions(-) rename src/SKIT.FlurlHttpClient.Wechat.Work/{ExtendedSDK/Finance/InteropServices/MarshalerHelper.cs => Utilities/[Internal]/MarshalHelper.cs} (83%) diff --git a/src/SKIT.FlurlHttpClient.Wechat.Work/ExtendedSDK/Finance/WechatWorkFinanceClient.cs b/src/SKIT.FlurlHttpClient.Wechat.Work/ExtendedSDK/Finance/WechatWorkFinanceClient.cs index ba41aa36..8f0d152e 100644 --- a/src/SKIT.FlurlHttpClient.Wechat.Work/ExtendedSDK/Finance/WechatWorkFinanceClient.cs +++ b/src/SKIT.FlurlHttpClient.Wechat.Work/ExtendedSDK/Finance/WechatWorkFinanceClient.cs @@ -10,6 +10,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work.ExtendedSDK.Finance using SKIT.FlurlHttpClient.Primitives; using SKIT.FlurlHttpClient.Wechat.Work.ExtendedSDK.Finance.InteropServices; using SKIT.FlurlHttpClient.Wechat.Work.ExtendedSDK.Finance.Settings; + using SKIT.FlurlHttpClient.Wechat.Work.Utilities; /// /// 一个企业微信会话内容存档 API HTTP 客户端。 @@ -159,7 +160,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work.ExtendedSDK.Finance IsRunOnWindows() ? FinanceDllWindowsPInvoker.GetContentFromSlice(dataPtr) : IsRunOnLinux() ? FinanceDllLinuxPInvoker.GetContentFromSlice(dataPtr) : throw new PlatformNotSupportedException(); - string dataContent = MarshalerHelper.PtrToStringUTF8(dataContentPtr)!; + string dataContent = MarshalHelper.PtrToStringUTF8(dataContentPtr)!; response = JsonSerializer.Deserialize(dataContent); response._InternalRawBytes = Encoding.UTF8.GetBytes(dataContent); @@ -253,7 +254,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work.ExtendedSDK.Finance IsRunOnWindows() ? FinanceDllWindowsPInvoker.GetContentFromSlice(dataPtr) : IsRunOnLinux() ? FinanceDllLinuxPInvoker.GetContentFromSlice(dataPtr) : throw new PlatformNotSupportedException(); - string dataContent = MarshalerHelper.PtrToStringUTF8(dataContentPtr)!; + string dataContent = MarshalHelper.PtrToStringUTF8(dataContentPtr)!; try { @@ -357,7 +358,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work.ExtendedSDK.Finance Marshal.Copy(dataContentPtr, bytes, 0, bytes.Length); response._InternalRawBytes = bytes; - response.NextBufferIndex = MarshalerHelper.PtrToStringAnsi(dataNextBufferIndex); + response.NextBufferIndex = MarshalHelper.PtrToStringAnsi(dataNextBufferIndex); response.IsFinished = dataIsFinishFlag != 0; } diff --git a/src/SKIT.FlurlHttpClient.Wechat.Work/ExtendedSDK/Finance/InteropServices/MarshalerHelper.cs b/src/SKIT.FlurlHttpClient.Wechat.Work/Utilities/[Internal]/MarshalHelper.cs similarity index 83% rename from src/SKIT.FlurlHttpClient.Wechat.Work/ExtendedSDK/Finance/InteropServices/MarshalerHelper.cs rename to src/SKIT.FlurlHttpClient.Wechat.Work/Utilities/[Internal]/MarshalHelper.cs index c45c994c..b38169c9 100644 --- a/src/SKIT.FlurlHttpClient.Wechat.Work/ExtendedSDK/Finance/InteropServices/MarshalerHelper.cs +++ b/src/SKIT.FlurlHttpClient.Wechat.Work/Utilities/[Internal]/MarshalHelper.cs @@ -1,11 +1,13 @@ using System; using System.Runtime.InteropServices; +using System.Security; using System.Text; -namespace SKIT.FlurlHttpClient.Wechat.Work.ExtendedSDK.Finance.InteropServices +namespace SKIT.FlurlHttpClient.Wechat.Work.Utilities { - internal static class MarshalerHelper + internal static class MarshalHelper { + [SecurityCritical] public static string? PtrToStringAnsi(IntPtr ptr) { if (ptr == IntPtr.Zero) @@ -14,6 +16,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work.ExtendedSDK.Finance.InteropServices return Marshal.PtrToStringAnsi(ptr)!; } + [SecurityCritical] public static string? PtrToStringUTF8(IntPtr ptr) { if (ptr == IntPtr.Zero)