@@ -284,7 +284,7 @@ public bool ConfigSet(VmmOption fOption, ulong qwValue)
284284 /// <param name="outputFile">If non-<see langword="null"/>, writes the memory map to disk at the specified output location.</param>
285285 /// <returns>Memory map ptr in string format.</returns>
286286 /// <exception cref="VmmException">Thrown if the memory map cannot be retrieved or applied.</exception>
287- public string ? GetMemoryMap (
287+ public string GetMemoryMap (
288288 bool applyMap = false ,
289289 string ? outputFile = null )
290290 {
@@ -684,12 +684,12 @@ public unsafe bool MemWriteSpan<T>(uint pid, ulong va, Span<T> span)
684684 /// </summary>
685685 /// <param name="pid">Process ID (PID) this operation will take place within.</param>
686686 /// <param name="va">Virtual address to translate from.</param>
687- /// <returns>Physical address if successful; otherwise 0 on failure.</returns>
687+ /// <param name="pa">Translated physical address if successful, otherwise 0.</param>
688+ /// <returns>True if successful, otherwise False.</returns>
688689 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
689- public ulong MemVirt2Phys ( uint pid , ulong va )
690+ public bool MemVirt2Phys ( uint pid , ulong va , out ulong pa )
690691 {
691- _ = Vmmi . VMMDLL_MemVirt2Phys ( _handle , pid , va , out var pa ) ;
692- return pa ;
692+ return Vmmi . VMMDLL_MemVirt2Phys ( _handle , pid , va , out pa ) ;
693693 }
694694
695695 /// <summary>
@@ -865,56 +865,51 @@ public bool VfsList(string path, VfsContext ctx, VfsCallBack_AddFile callbackFil
865865 /// VFS list files and directories in a virtual file system path.
866866 /// </summary>
867867 /// <param name="path">Virtual path to enumerate.</param>
868- /// <returns>A list with file and directory entries on success; an empty list on failure.</returns>
869- public List < VfsEntry > VfsList ( string path )
868+ /// <returns>A list with file and directory entries on success; a null list on failure.</returns>
869+ public List < VfsEntry > ? VfsList ( string path )
870870 {
871871 using var ctx = new VfsContext ( ) ;
872- VfsList ( path , ctx , VfsList_AddFileCB , VfsList_AddDirectoryCB ) ;
872+ if ( ! VfsList ( path , ctx , VfsList_AddFileCB , VfsList_AddDirectoryCB ) )
873+ return null ;
873874 return ctx . Entries ;
874875 }
875876
876877 /// <summary>
877878 /// VFS read data from a virtual file.
878879 /// </summary>
879880 /// <param name="fileName">The file name/path within the VFS.</param>
880- /// <param name="ntStatus">Receives the NTSTATUS value of the operation ( success = 0) .</param>
881+ /// <param name="data">The data read from the operation on success; otherwise null .</param>
881882 /// <param name="size">The maximum number of bytes to read. 0 = default = 16MB.</param>
882883 /// <param name="offset">Optional offset within the file to start reading at.</param>
883- /// <returns>The data read on success. Zero-length data on failure. NB! Data read may be shorter than <paramref name="size"/> .</returns>
884- public unsafe byte [ ] VfsRead ( string fileName , out uint ntStatus , uint size = 0 , ulong offset = 0 )
884+ /// <returns>The NTSTATUS value of the operation (success = 0) .</returns>
885+ public unsafe uint VfsRead ( string fileName , out byte [ ] ? data , uint size = 0 , ulong offset = 0 )
885886 {
886887 uint cbRead = 0 ;
887888 if ( size == 0 )
888889 {
889890 size = 0x01000000 ; // 16MB
890891 }
891892
892- var data = new byte [ size ] ;
893- fixed ( byte * pb = data )
893+ var dataLocal = new byte [ size ] ;
894+ fixed ( byte * pb = dataLocal )
894895 {
895- ntStatus = Vmmi . VMMDLL_VfsRead ( _handle , fileName . Replace ( '/' , '\\ ' ) , pb , size , out cbRead , offset ) ;
896- var pbData = new byte [ cbRead ] ;
897- if ( cbRead > 0 )
896+ uint ret = Vmmi . VMMDLL_VfsRead ( _handle , fileName . Replace ( '/' , '\\ ' ) , pb , size , out cbRead , offset ) ;
897+ if ( ret == 0 ) // STATUS_SUCCESS
898+ {
899+ if ( cbRead < size )
900+ {
901+ Array . Resize ( ref dataLocal , ( int ) cbRead ) ;
902+ }
903+ data = dataLocal ;
904+ }
905+ else
898906 {
899- data . AsSpan ( 0 , pbData . Length ) . CopyTo ( pbData ) ;
907+ data = null ;
900908 }
901-
902- return pbData ;
909+ return ret ;
903910 }
904911 }
905912
906- /// <summary>
907- /// VFS read data from a virtual file.
908- /// </summary>
909- /// <param name="fileName">The file name/path within the VFS.</param>
910- /// <param name="size">The maximum number of bytes to read. 0 = default = 16MB.</param>
911- /// <param name="offset">Optional offset within the file to start reading at.</param>
912- /// <returns>The data read on success. Zero-length data on failure. NB! Data read may be shorter than <paramref name="size"/>.</returns>
913- public byte [ ] VfsRead ( string fileName , uint size = 0 , ulong offset = 0 )
914- {
915- return VfsRead ( fileName , out _ , size , offset ) ;
916- }
917-
918913 /// <summary>
919914 /// VFS write data to a virtual file.
920915 /// </summary>
@@ -989,7 +984,7 @@ public bool PidGetFromName(string sProcName, out uint pdwPID)
989984 /// Get all process IDs (PIDs) for a given process name.
990985 /// </summary>
991986 /// <param name="sProcName">Name of the process to look up.</param>
992- /// <returns>Array of PIDs that match; null array if no matches .</returns>
987+ /// <returns>Array of PIDs that match, or null if failed .</returns>
993988 public uint [ ] ? PidGetAllFromName ( string sProcName )
994989 {
995990 var pids = new List < uint > ( ) ;
@@ -1005,7 +1000,8 @@ public bool PidGetFromName(string sProcName, out uint pdwPID)
10051000 pids . Add ( procInfo [ i ] . dwPID ) ;
10061001 }
10071002 }
1008- return pids . ToArray ( ) ;
1003+ return pids . Count > 0 ?
1004+ pids . ToArray ( ) : null ;
10091005 }
10101006
10111007 /// <summary>
@@ -1729,7 +1725,7 @@ public unsafe bool Map_GetHeap(uint pid, out HeapMap result)
17291725 /// Get the user-mode path of the process image.
17301726 /// </summary>
17311727 /// <param name="pid">Process ID (PID) for this operation.</param>
1732- /// <returns>A string path on success; otherwise null.</returns>
1728+ /// <returns>A string path on success; otherwise a null string .</returns>
17331729 public string ? GetProcessPathUser ( uint pid )
17341730 {
17351731 return GetProcessInformationString ( pid , VMMDLL_PROCESS_INFORMATION_OPT_STRING_PATH_USER_IMAGE ) ;
@@ -1739,7 +1735,7 @@ public unsafe bool Map_GetHeap(uint pid, out HeapMap result)
17391735 /// Get the kernel-mode path of the process image.
17401736 /// </summary>
17411737 /// <param name="pid">Process ID (PID) for this operation.</param>
1742- /// <returns>A string path on success; otherwise null.</returns>
1738+ /// <returns>A string path on success; otherwise a null string .</returns>
17431739 public string ? GetProcessPathKernel ( uint pid )
17441740 {
17451741 return GetProcessInformationString ( pid , VMMDLL_PROCESS_INFORMATION_OPT_STRING_PATH_KERNEL ) ;
@@ -1749,7 +1745,7 @@ public unsafe bool Map_GetHeap(uint pid, out HeapMap result)
17491745 /// Get the process command line.
17501746 /// </summary>
17511747 /// <param name="pid">Process ID (PID) for this operation.</param>
1752- /// <returns>The command line string on success; otherwise null.</returns>
1748+ /// <returns>The command line string on success; otherwise a null string .</returns>
17531749 public string ? GetProcessCmdline ( uint pid )
17541750 {
17551751 return GetProcessInformationString ( pid , VMMDLL_PROCESS_INFORMATION_OPT_STRING_CMDLINE ) ;
@@ -1760,18 +1756,24 @@ public unsafe bool Map_GetHeap(uint pid, out HeapMap result)
17601756 /// </summary>
17611757 /// <param name="pid">Process ID (PID) for this operation.</param>
17621758 /// <param name="fOptionString">A VMMDLL_PROCESS_INFORMATION_OPT_* flag indicating which string to fetch.</param>
1763- /// <returns>The string value on success; otherwise null.</returns>
1759+ /// <returns>The string value on success; otherwise a null string .</returns>
17641760 public unsafe string ? GetProcessInformationString ( uint pid , uint fOptionString )
17651761 {
17661762 var pb = Vmmi . VMMDLL_ProcessGetInformationString ( _handle , pid , fOptionString ) ;
1767- if ( pb == null )
1763+ try
17681764 {
1769- return null ;
1770- }
1765+ if ( pb is null )
1766+ {
1767+ return null ;
1768+ }
17711769
1772- var s = Marshal . PtrToStringAnsi ( ( IntPtr ) pb ) ;
1773- Vmmi . VMMDLL_MemFree ( pb ) ;
1774- return s ;
1770+ var s = Marshal . PtrToStringAnsi ( ( IntPtr ) pb ) ;
1771+ return s ;
1772+ }
1773+ finally
1774+ {
1775+ Vmmi . VMMDLL_MemFree ( pb ) ;
1776+ }
17751777 }
17761778
17771779 /// <summary>
@@ -2285,8 +2287,8 @@ public struct ThreadEntry
22852287 public ulong vaStackLimitUser ;
22862288 public ulong vaStackBaseKernel ;
22872289 public ulong vaStackLimitKernel ;
2288- public ulong vaImpersonationToken ;
22892290 public ulong vaTrapFrame ;
2291+ public ulong vaImpersonationToken ;
22902292 public ulong vaRIP ;
22912293 public ulong vaRSP ;
22922294 public ulong qwAffinity ;
@@ -2793,6 +2795,7 @@ public struct PfnEntry
27932795 public uint dwPfn ;
27942796 public PfnType tp ;
27952797 public PfnTypeExtended tpExtended ;
2798+ public ulong va ;
27962799 public ulong vaPte ;
27972800 public ulong OriginalPte ;
27982801 public uint dwPID ;
@@ -3240,7 +3243,7 @@ public struct PfnEntry
32403243 uint cbPfns ;
32413244 var cbMAP = Marshal . SizeOf < Vmmi . VMMDLL_MAP_PFN > ( ) ;
32423245 var cbENTRY = Marshal . SizeOf < Vmmi . VMMDLL_MAP_PFNENTRY > ( ) ;
3243- if ( pfns . Length == 0 )
3246+ if ( pfns . IsEmpty )
32443247 {
32453248 return null ;
32463249 }
@@ -3283,7 +3286,7 @@ public struct PfnEntry
32833286 } ;
32843287 if ( e . tp == PfnType . Active && ! e . fPrototype )
32853288 {
3286- e . vaPte = n . va ;
3289+ e . va = n . va ;
32873290 e . dwPID = n . dwPfnPte [ 0 ] ;
32883291 }
32893292
@@ -3304,11 +3307,11 @@ public struct PfnEntry
33043307 /// </summary>
33053308 /// <param name="pid">Process ID (PID) whose module the symbols belong to.</param>
33063309 /// <param name="vaModuleBase">Module base address.</param>
3307- /// <param name="szModuleName">Receives the module name if successful.</param>
3310+ /// <param name="szModuleName">Receives the module name if successful, otherwise null .</param>
33083311 /// <returns><see langword="true"/> if the PDB was loaded successfully; otherwise <see langword="false"/>.</returns>
3309- public unsafe bool PdbLoad ( uint pid , ulong vaModuleBase , out string szModuleName )
3312+ public unsafe bool PdbLoad ( uint pid , ulong vaModuleBase , out string ? szModuleName )
33103313 {
3311- szModuleName = "" ;
3314+ szModuleName = null ;
33123315 var data = new byte [ 260 ] ;
33133316 fixed ( byte * pb = data )
33143317 {
@@ -3330,12 +3333,12 @@ public unsafe bool PdbLoad(uint pid, ulong vaModuleBase, out string szModuleName
33303333 /// </summary>
33313334 /// <param name="szModule">Module name.</param>
33323335 /// <param name="cbSymbolAddressOrOffset">Symbol address or module-relative offset.</param>
3333- /// <param name="szSymbolName">Receives the symbol name.</param>
3336+ /// <param name="szSymbolName">Receives the symbol name if succesful, otherwise null .</param>
33343337 /// <param name="pdwSymbolDisplacement">Receives the displacement from the symbol.</param>
33353338 /// <returns><see langword="true"/> on success; otherwise <see langword="false"/>.</returns>
3336- public unsafe bool PdbSymbolName ( string szModule , ulong cbSymbolAddressOrOffset , out string szSymbolName , out uint pdwSymbolDisplacement )
3339+ public unsafe bool PdbSymbolName ( string szModule , ulong cbSymbolAddressOrOffset , out string ? szSymbolName , out uint pdwSymbolDisplacement )
33373340 {
3338- szSymbolName = "" ;
3341+ szSymbolName = null ;
33393342 pdwSymbolDisplacement = 0 ;
33403343 var data = new byte [ 260 ] ;
33413344 fixed ( byte * pb = data )
@@ -3452,7 +3455,7 @@ public delegate void VMMDLL_LOG_CALLBACK_PFN(
34523455 /// </summary>
34533456 /// <param name="pfnCB">The callback function to register, or <see langword="null"/> to unregister an existing callback.</param>
34543457 /// <returns><see langword="true"/> if the callback was successfully registered/unregistered, otherwise <see langword="false"/>.</returns>
3455- public bool LogCallback ( VMMDLL_LOG_CALLBACK_PFN pfnCB )
3458+ public bool LogCallback ( VMMDLL_LOG_CALLBACK_PFN ? pfnCB )
34563459 {
34573460 return Vmmi . VMMDLL_LogCallback ( _handle , pfnCB ) ;
34583461 }
0 commit comments