Skip to content

Commit 6fc2ca5

Browse files
committed
[NativeAPI] 修复 Keystore 在接受调用方时转换不当问题
1 parent 43734eb commit 6fc2ca5

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

Lagrange.Core.NativeAPI/NativeModel/Common/BotKeystoreStruct.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ namespace Lagrange.Core.NativeAPI.NativeModel.Common
55
{
66
public struct BotKeystoreStruct
77
{
8-
public BotKeystoreStruct() { }
8+
public BotKeystoreStruct()
9+
{ }
910

1011
public long Uin = 0;
1112

@@ -105,7 +106,8 @@ public static implicit operator BotKeystoreStruct(BotKeystore keystore)
105106
{
106107
bytePsKey[i++] = new ByteArrayKVPNative
107108
{
108-
Key = Encoding.UTF8.GetBytes(kvp.Key), Value = Encoding.UTF8.GetBytes(kvp.Value)
109+
Key = Encoding.UTF8.GetBytes(kvp.Key),
110+
Value = Encoding.UTF8.GetBytes(kvp.Value)
109111
};
110112
}
111113

@@ -143,7 +145,8 @@ public BotKeystore ToKeystoreWithoutFree()
143145
var psKey = new Dictionary<string, string>();
144146
foreach (var kvp in (ByteArrayKVPNative[])PsKey)
145147
{
146-
psKey[Encoding.UTF8.GetString(kvp.Key)] = Encoding.UTF8.GetString(kvp.Value);
148+
// psKey[Encoding.UTF8.GetString(kvp.Key)] = Encoding.UTF8.GetString(kvp.Value); Oh shit, are u okay?
149+
psKey[Encoding.UTF8.GetString(kvp.Key.ToByteArrayWithoutFree())] = Encoding.UTF8.GetString(kvp.Value.ToByteArrayWithoutFree());
147150
}
148151

149152
return new BotKeystore()
@@ -178,4 +181,4 @@ public BotKeystore ToKeystoreWithoutFree()
178181
};
179182
}
180183
}
181-
}
184+
}

Lagrange.Core.NativeAPI/NativeModel/Common/ByteArrayDictNative.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public struct ByteArrayDictNative
66
{
77
public int Length;
88
public IntPtr Data;
9-
9+
1010
public static implicit operator ByteArrayDictNative(ByteArrayKVPNative[] dict)
1111
{
1212
int size = Marshal.SizeOf<ByteArrayKVPNative>();
@@ -15,26 +15,26 @@ public static implicit operator ByteArrayDictNative(ByteArrayKVPNative[] dict)
1515
{
1616
Marshal.StructureToPtr(dict[i], ptr + i * size, false);
1717
}
18-
18+
1919
return new ByteArrayDictNative { Length = dict.Length, Data = ptr };
2020
}
21-
21+
2222
public static implicit operator ByteArrayKVPNative[](ByteArrayDictNative dict)
2323
{
2424
if (dict.Data == IntPtr.Zero || dict.Length == 0)
2525
{
2626
return [];
2727
}
28-
28+
2929
ByteArrayKVPNative[] result = new ByteArrayKVPNative[dict.Length];
3030
int size = Marshal.SizeOf<ByteArrayKVPNative>();
3131
for (int i = 0; i < dict.Length; i++)
3232
{
3333
result[i] = Marshal.PtrToStructure<ByteArrayKVPNative>(dict.Data + i * size);
3434
}
35-
36-
Marshal.FreeHGlobal(dict.Data);
37-
35+
36+
// Marshal.FreeHGlobal(dict.Data); Why release here?
37+
3838
return result;
3939
}
4040
}

0 commit comments

Comments
 (0)