Skip to content
This repository was archived by the owner on Feb 24, 2026. It is now read-only.

Commit 41e5cf2

Browse files
committed
Update interop buffer params from byte* to void*
Refactored all P/Invoke and delegate signatures to use void* instead of byte* for unmanaged memory buffers. Updated all related usages, fixed blocks, and callbacks to match. This improves type generality, reduces unnecessary casts, and aligns with modern C# interop best practices. Applies to memory, process, registry, VFS, and utility APIs.
1 parent 113f079 commit 41e5cf2

4 files changed

Lines changed: 66 additions & 66 deletions

File tree

src/VmmSharpEx/Internal/Lci.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ internal static partial class Lci
3434

3535
[LibraryImport("leechcore.dll", EntryPoint = "LcRead")]
3636
[return: MarshalAs(UnmanagedType.Bool)]
37-
public static unsafe partial bool LcRead(IntPtr hLC, ulong pa, uint cb, byte* pb);
37+
public static unsafe partial bool LcRead(IntPtr hLC, ulong pa, uint cb, void* pb);
3838

3939
[LibraryImport("leechcore.dll", EntryPoint = "LcReadScatter")]
4040
public static unsafe partial void LcReadScatter(IntPtr hLC, uint cMEMs, IntPtr ppMEMs);
4141

4242
[LibraryImport("leechcore.dll", EntryPoint = "LcWrite")]
4343
[return: MarshalAs(UnmanagedType.Bool)]
44-
public static unsafe partial bool LcWrite(IntPtr hLC, ulong pa, uint cb, byte* pb);
44+
public static unsafe partial bool LcWrite(IntPtr hLC, ulong pa, uint cb, void* pb);
4545

4646
[LibraryImport("leechcore.dll", EntryPoint = "LcGetOption")]
4747
[return: MarshalAs(UnmanagedType.Bool)]
@@ -53,7 +53,7 @@ internal static partial class Lci
5353

5454
[LibraryImport("leechcore.dll", EntryPoint = "LcCommand")]
5555
[return: MarshalAs(UnmanagedType.Bool)]
56-
public static unsafe partial bool LcCommand(IntPtr hLC, LcCmd fOption, uint cbDataIn, byte* pbDataIn, out IntPtr ppbDataOut, out uint pcbDataOut);
56+
public static unsafe partial bool LcCommand(IntPtr hLC, LcCmd fOption, uint cbDataIn, void* pbDataIn, out IntPtr ppbDataOut, out uint pcbDataOut);
5757

5858
[StructLayout(LayoutKind.Sequential)]
5959
public struct LC_CONFIG_ERRORINFO

src/VmmSharpEx/Internal/Vmmi.cs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public unsafe struct VMMDLL_VFS_FILELIST
5757
{
5858
public uint dwVersion;
5959
public uint _Reserved;
60-
public delegate* unmanaged<IntPtr, byte*, ulong, IntPtr, int> pfnAddFile;
61-
public delegate* unmanaged<IntPtr, byte*, IntPtr, int> pfnAddDirectory;
60+
public delegate* unmanaged<IntPtr, void*, ulong, IntPtr, int> pfnAddFile;
61+
public delegate* unmanaged<IntPtr, void*, IntPtr, int> pfnAddDirectory;
6262
public IntPtr h;
6363
}
6464

@@ -957,7 +957,7 @@ public static unsafe partial bool VMMDLL_VfsList(
957957
public static unsafe partial uint VMMDLL_VfsRead(
958958
IntPtr hVMM,
959959
[MarshalAs(UnmanagedType.LPUTF8Str)] string wcsFileName,
960-
byte* pb,
960+
void* pb,
961961
uint cb,
962962
out uint pcbRead,
963963
ulong cbOffset);
@@ -966,7 +966,7 @@ public static unsafe partial uint VMMDLL_VfsRead(
966966
public static unsafe partial uint VMMDLL_VfsWrite(
967967
IntPtr hVMM,
968968
[MarshalAs(UnmanagedType.LPUTF8Str)] string wcsFileName,
969-
byte* pb,
969+
void* pb,
970970
uint cb,
971971
out uint pcbRead,
972972
ulong cbOffset);
@@ -993,7 +993,7 @@ public static unsafe partial bool VMMDLL_MemReadEx(
993993
IntPtr hVMM,
994994
uint dwPID,
995995
ulong qwA,
996-
byte* pb,
996+
void* pb,
997997
uint cb,
998998
out uint pcbReadOpt,
999999
VmmFlags flags);
@@ -1004,14 +1004,14 @@ public static unsafe partial bool VMMDLL_MemReadPage(
10041004
IntPtr hVMM,
10051005
uint dwPID,
10061006
ulong qwA,
1007-
byte* pbPage);
1007+
void* pbPage);
10081008

10091009
[LibraryImport("vmm.dll", EntryPoint = "VMMDLL_MemPrefetchPages")]
10101010
[return: MarshalAs(UnmanagedType.Bool)]
10111011
public static unsafe partial bool VMMDLL_MemPrefetchPages(
10121012
IntPtr hVMM,
10131013
uint dwPID,
1014-
byte* pPrefetchAddresses,
1014+
void* pPrefetchAddresses,
10151015
uint cPrefetchAddresses);
10161016

10171017
[LibraryImport("vmm.dll", EntryPoint = "VMMDLL_MemWrite")]
@@ -1020,7 +1020,7 @@ public static unsafe partial bool VMMDLL_MemWrite(
10201020
IntPtr hVMM,
10211021
uint dwPID,
10221022
ulong qwA,
1023-
byte* pb,
1023+
void* pb,
10241024
uint cb);
10251025

10261026
[LibraryImport("vmm.dll", EntryPoint = "VMMDLL_MemVirt2Phys")]
@@ -1086,7 +1086,7 @@ public static unsafe partial bool VMMDLL_Scatter_Clear(
10861086

10871087
[LibraryImport("vmm.dll", EntryPoint = "VMMDLL_PidList")]
10881088
[return: MarshalAs(UnmanagedType.Bool)]
1089-
public static unsafe partial bool VMMDLL_PidList(IntPtr hVMM, byte* pPIDs, ref ulong pcPIDs);
1089+
public static unsafe partial bool VMMDLL_PidList(IntPtr hVMM, void* pPIDs, ref ulong pcPIDs);
10901090

10911091
[LibraryImport("vmm.dll", EntryPoint = "VMMDLL_PidGetFromName")]
10921092
[return: MarshalAs(UnmanagedType.Bool)]
@@ -1103,7 +1103,7 @@ public static unsafe partial bool VMMDLL_Scatter_Clear(
11031103
public static unsafe partial bool VMMDLL_ProcessGetInformation(
11041104
IntPtr hVMM,
11051105
uint dwPID,
1106-
byte* pProcessInformation,
1106+
void* pProcessInformation,
11071107
ref ulong pcbProcessInformation);
11081108

11091109
[LibraryImport("vmm.dll", EntryPoint = "VMMDLL_ProcessGetInformationAll")]
@@ -1115,7 +1115,7 @@ out uint pcProcessInformation
11151115
);
11161116

11171117
[LibraryImport("vmm.dll", EntryPoint = "VMMDLL_ProcessGetInformationString")]
1118-
public static unsafe partial byte* VMMDLL_ProcessGetInformationString(
1118+
public static unsafe partial void* VMMDLL_ProcessGetInformationString(
11191119
IntPtr hVMM,
11201120
uint dwPID,
11211121
uint fOptionString);
@@ -1126,15 +1126,15 @@ public static unsafe partial bool VMMDLL_ProcessGetDirectories(
11261126
IntPtr hVMM,
11271127
uint dwPID,
11281128
[MarshalAs(UnmanagedType.LPUTF8Str)] string uszModule,
1129-
byte* pData);
1129+
void* pData);
11301130

11311131
[LibraryImport("vmm.dll", EntryPoint = "VMMDLL_ProcessGetSectionsU")]
11321132
[return: MarshalAs(UnmanagedType.Bool)]
11331133
public static unsafe partial bool VMMDLL_ProcessGetSections(
11341134
IntPtr hVMM,
11351135
uint dwPID,
11361136
[MarshalAs(UnmanagedType.LPUTF8Str)] string uszModule,
1137-
byte* pData,
1137+
void* pData,
11381138
uint cData,
11391139
out uint pcData);
11401140

@@ -1146,15 +1146,15 @@ public static unsafe partial bool VMMDLL_PdbLoad(
11461146
IntPtr hVMM,
11471147
uint dwPID,
11481148
ulong vaModuleBase,
1149-
byte* pModuleMapEntry);
1149+
void* pModuleMapEntry);
11501150

11511151
[LibraryImport("vmm.dll", EntryPoint = "VMMDLL_PdbSymbolName")]
11521152
[return: MarshalAs(UnmanagedType.Bool)]
11531153
public static unsafe partial bool VMMDLL_PdbSymbolName(
11541154
IntPtr hVMM,
11551155
[MarshalAs(UnmanagedType.LPStr)] string szModule,
11561156
ulong cbSymbolAddressOrOffset,
1157-
byte* szSymbolName,
1157+
void* szSymbolName,
11581158
out uint pdwSymbolDisplacement);
11591159

11601160
[LibraryImport("vmm.dll", EntryPoint = "VMMDLL_PdbSymbolAddress")]
@@ -1367,17 +1367,17 @@ public static unsafe partial bool VMMDLL_Map_GetServices(
13671367
[return: MarshalAs(UnmanagedType.Bool)]
13681368
public static unsafe partial bool VMMDLL_Map_GetPfn(
13691369
IntPtr hVMM,
1370-
byte* pPfns,
1370+
void* pPfns,
13711371
uint cPfns,
1372-
byte* pPfnMap,
1372+
void* pPfnMap,
13731373
ref uint pcbPfnMap);
13741374

13751375
// REGISTRY FUNCTIONALITY BELOW:
13761376
[LibraryImport("vmm.dll", EntryPoint = "VMMDLL_WinReg_HiveList")]
13771377
[return: MarshalAs(UnmanagedType.Bool)]
13781378
public static unsafe partial bool VMMDLL_WinReg_HiveList(
13791379
IntPtr hVMM,
1380-
byte* pHives,
1380+
void* pHives,
13811381
uint cHives,
13821382
out uint pcHives);
13831383

@@ -1387,7 +1387,7 @@ public static unsafe partial bool VMMDLL_WinReg_HiveReadEx(
13871387
IntPtr hVMM,
13881388
ulong vaCMHive,
13891389
uint ra,
1390-
byte* pb,
1390+
void* pb,
13911391
uint cb,
13921392
out uint pcbReadOpt,
13931393
VmmFlags flags);
@@ -1398,7 +1398,7 @@ public static unsafe partial bool VMMDLL_WinReg_HiveWrite(
13981398
IntPtr hVMM,
13991399
ulong vaCMHive,
14001400
uint ra,
1401-
byte* pb,
1401+
void* pb,
14021402
uint cb);
14031403

14041404
[LibraryImport("vmm.dll", EntryPoint = "VMMDLL_WinReg_EnumKeyExU")]
@@ -1407,7 +1407,7 @@ public static unsafe partial bool VMMDLL_WinReg_EnumKeyEx(
14071407
IntPtr hVMM,
14081408
[MarshalAs(UnmanagedType.LPUTF8Str)] string uszFullPathKey,
14091409
uint dwIndex,
1410-
byte* lpName,
1410+
void* lpName,
14111411
ref uint lpcchName,
14121412
out ulong lpftLastWriteTime);
14131413

@@ -1417,10 +1417,10 @@ public static unsafe partial bool VMMDLL_WinReg_EnumValue(
14171417
IntPtr hVMM,
14181418
[MarshalAs(UnmanagedType.LPUTF8Str)] string uszFullPathKey,
14191419
uint dwIndex,
1420-
byte* lpValueName,
1420+
void* lpValueName,
14211421
ref uint lpcchValueName,
14221422
out uint lpType,
1423-
byte* lpData,
1423+
void* lpData,
14241424
ref uint lpcbData);
14251425

14261426
[LibraryImport("vmm.dll", EntryPoint = "VMMDLL_WinReg_QueryValueExU")]
@@ -1429,7 +1429,7 @@ public static unsafe partial bool VMMDLL_WinReg_QueryValueEx(
14291429
IntPtr hVMM,
14301430
[MarshalAs(UnmanagedType.LPUTF8Str)] string uszFullPathKeyValue,
14311431
out uint lpType,
1432-
byte* lpData,
1432+
void* lpData,
14331433
ref uint lpcbData);
14341434

14351435
// MEMORY SEARCH FUNCTIONALITY BELOW:
@@ -1446,10 +1446,10 @@ public static unsafe partial bool VMMDLL_MemSearch(
14461446
[LibraryImport("vmm.dll", EntryPoint = "VMMDLL_UtilFillHexAscii")]
14471447
[return: MarshalAs(UnmanagedType.Bool)]
14481448
public static unsafe partial bool VMMDLL_UtilFillHexAscii(
1449-
byte* pb,
1449+
void* pb,
14501450
uint cb,
14511451
uint cbInitialOffset,
1452-
byte* sz,
1452+
void* sz,
14531453
ref uint pcsz);
14541454

14551455
[LibraryImport("vmm.dll", EntryPoint = "VMMDLL_Log")]

src/VmmSharpEx/LeechCore.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ private void Dispose(bool disposing)
188188
public unsafe byte[]? Read(ulong pa, uint cb)
189189
{
190190
var arr = new byte[cb];
191-
fixed (byte* pb = arr)
191+
fixed (void* pb = arr)
192192
{
193193
if (!Lci.LcRead(_handle, pa, cb, pb))
194194
{
@@ -205,15 +205,15 @@ private void Dispose(bool disposing)
205205
/// <param name="pa">Physical address to read.</param>
206206
/// <param name="result">Receives the value read from memory on success.</param>
207207
/// <returns><see langword="true"/> if successful; otherwise <see langword="false"/>.</returns>
208-
/// <seealso cref="Lci.LcRead(IntPtr, ulong, uint, byte*)"/>
208+
/// <seealso cref="Lci.LcRead(IntPtr, ulong, uint, void*)"/>
209209
public unsafe bool ReadValue<T>(ulong pa, out T result)
210210
where T : unmanaged, allows ref struct
211211
{
212212
uint cb = (uint)sizeof(T);
213213
result = default;
214214
fixed (void* pb = &result)
215215
{
216-
return Lci.LcRead(_handle, pa, cb, (byte*)pb);
216+
return Lci.LcRead(_handle, pa, cb, pb);
217217
}
218218
}
219219

@@ -236,7 +236,7 @@ public unsafe bool ReadValue<T>(ulong pa, out T result)
236236
uint cb = checked((uint)sizeof(T) * (uint)count);
237237
fixed (T* pb = arr)
238238
{
239-
if (!Lci.LcRead(_handle, pa, cb, (byte*)pb))
239+
if (!Lci.LcRead(_handle, pa, cb, pb))
240240
{
241241
return null;
242242
}
@@ -260,7 +260,7 @@ public unsafe bool ReadValue<T>(ulong pa, out T result)
260260
uint cb = checked((uint)sizeof(T) * (uint)count);
261261
fixed (T* pb = arr.Span)
262262
{
263-
if (!Lci.LcRead(_handle, pa, cb, (byte*)pb))
263+
if (!Lci.LcRead(_handle, pa, cb, pb))
264264
{
265265
arr.Dispose();
266266
return null;
@@ -282,7 +282,7 @@ public unsafe bool ReadSpan<T>(ulong pa, Span<T> span)
282282
uint cb = checked((uint)sizeof(T) * (uint)span.Length);
283283
fixed (T* pb = span)
284284
{
285-
return Lci.LcRead(_handle, pa, cb, (byte*)pb);
285+
return Lci.LcRead(_handle, pa, cb, pb);
286286
}
287287
}
288288

@@ -300,7 +300,7 @@ public unsafe bool WriteSpan<T>(ulong pa, Span<T> span)
300300
uint cb = checked((uint)sizeof(T) * (uint)span.Length);
301301
fixed (T* pb = span)
302302
{
303-
return Lci.LcWrite(_handle, pa, cb, (byte*)pb);
303+
return Lci.LcWrite(_handle, pa, cb, pb);
304304
}
305305
}
306306

@@ -326,7 +326,7 @@ public unsafe bool Read(ulong pa, IntPtr pb, uint cb)
326326
/// <returns><see langword="true"/> on success; otherwise <see langword="false"/>.</returns>
327327
public unsafe bool Read(ulong pa, void* pb, uint cb)
328328
{
329-
if (!Lci.LcRead(_handle, pa, cb, (byte*)pb))
329+
if (!Lci.LcRead(_handle, pa, cb, pb))
330330
{
331331
return false;
332332
}
@@ -390,7 +390,7 @@ public unsafe bool WriteValue<T>(ulong pa, T value)
390390
{
391391
_parent?.ThrowIfMemWritesDisabled();
392392
uint cb = (uint)sizeof(T);
393-
return Lci.LcWrite(_handle, pa, cb, (byte*)&value);
393+
return Lci.LcWrite(_handle, pa, cb, &value);
394394
}
395395

396396
/// <summary>
@@ -407,7 +407,7 @@ public unsafe bool WriteArray<T>(ulong pa, T[] data)
407407
uint cb = checked((uint)sizeof(T) * (uint)data.Length);
408408
fixed (T* pb = data)
409409
{
410-
return Lci.LcWrite(_handle, pa, cb, (byte*)pb);
410+
return Lci.LcWrite(_handle, pa, cb, pb);
411411
}
412412
}
413413

@@ -434,7 +434,7 @@ public unsafe bool Write(ulong pa, IntPtr pb, uint cb)
434434
public unsafe bool Write(ulong pa, void* pb, uint cb)
435435
{
436436
_parent?.ThrowIfMemWritesDisabled();
437-
return Lci.LcWrite(_handle, pa, cb, (byte*)pb);
437+
return Lci.LcWrite(_handle, pa, cb, pb);
438438
}
439439

440440
/// <summary>
@@ -488,7 +488,7 @@ public unsafe bool ExecuteCommand(LcCmd fOption, ReadOnlySpan<byte> dataIn, out
488488
}
489489
else
490490
{
491-
fixed (byte* pbDataIn = dataIn)
491+
fixed (void* pbDataIn = dataIn)
492492
{
493493
if (!Lci.LcCommand(_handle, fOption, (uint)dataIn.Length, pbDataIn, out pbDataOut, out cbDataOut))
494494
{

0 commit comments

Comments
 (0)