.NET Memory Tools

This is a collection of tools that I have developed over time to work in Visual Basic .NET.  They will, of course, work fine if they are referenced in C# projects.

The release package is only a serving suggestion.  If you really want the best available version, please download it from the source tree. The test project is now included in the Windows System API in Visual Basic source tree. Download both projects to compile the test project.  

.NET Memory Tools does not, itself, require any other projects to compile, it simply requires that you have IL Support installed.

Note: When working with hardware APIs in p/Invoke, your executable files need to be set to the architecture of your system (x64 vs. x86) or they will not run.

The Downloadable Zip comes with an example WPF application to enumerate network devices (includes example code for grabbing a shell icon with p/Invoke and converting it to a BitmapSource). Right-clicking on a device in the list will give you a context menu to open various device dialogs, including Device Properties, Network Properties and Network Status. Also, opening the Network Properties dialog will throw the UAC.

New For Beta v2.3.1: Massive overhaul of the MemPtr.vb backend. Most functions have been modified to use dynamically generated methods via delegate, written in IL opcodes, to transfer memory to and from unmanaged memory buffers. Speed increase over p/Invoke is dramatic.

A new experimental library is now included, DTIL, which is MemPtr implemented with many functions coded in pure IL (and ForwardRef'd from the VB source), instead of calling via delegate. This method adds further performance increases. Note: Compiling this library requires the free Visual Studio add-in 'IL Support' to be installed.  

Also included in the Interop library is the new VirtualDisk class. Built on top of the raw C-based Windows API, this is a completely new .NET-based implementation of all VHD/VHDX functionality, including creating, mounting and unmounting volumes, as well as providing access to the backing file. There is no demonstration of this feature, yet, but one will be forth-coming.

New For Beta 2.2.2: MemPtr now has functions to work with virtual memory. VirtualAlloc, VirtualFree and VirtualLength. Refer to the comments in the MemPtr.vb source file for more information.

New For Beta 2: The Example App has a new menu item under the File menu, "Show File Association Window." This demonstrates a new collection of classes and functions I've added to the API since the last release, for retrieving the list of all file associations on the system with their respective icons and organizing them by both program and file type.

Feedback is welcomed! 

 

Namespaces

DataTools.Memory

MemPtr
(Structure)
A drop-in replacement for IntPtr and the most important object in this namespace.

A multipurpose unmanaged memory object. 

Because it is a structure that contains exactly one instance field (an IntPtr), MemPtr can actually be used directly in place of IntPtr for p/Invoke function calls.

Functions provided including allocating memory on the process heap, private heaps, NetApi or virtual memory, grabbing and setting strings, arrays of primitives, Guids, colors, Decimals, arrays of strings (MULTISZ), etc...

Remember to free the resources!  This is completely for unmanaged code.
SafePtr
(Class)
An analog to MemPtr, this class based on the special SafeHandle class. Functions provided including allocating memory on the process heap, private heaps, NetApi or virtual memory, grabbing and setting strings, arrays of primitives, Guids, colors, Decimals, arrays of strings (MULTISZ), etc... Experimental.
Mem A multipurpose, managed  memory representation object using the process heap as a storage backing.
Blob A multipurpose and exhaustive data transformation object using a Mem object as a storage backing.
StringBlob An unmanaged string collection structure using a Mem object as a storage backing.
StructPtr
(Structure)
An unmanaged structure marshaling structure. No storage backing.
ByteWorm A multipurpose data recorder⁄rewind object using a Mem object as a storage backing.

DataTools.ByteOrderMark

BOM Represents a collection of Byte Order Marks for several different code pages including all Unicode formats and EBCDIC.  Can automatically detect text types.
SafeTextRead
SafeTextWrite
Uses some simple methods to attempt to automatically determine the encoding of an array of bytes and convert them into a String, or to encode a string into an array of bytes using one of several encoding options.

DataTools

TextTools A collection of text-processing tools that work better than built-in tools, including string splitting (e.g. BatchParse) and pre-processing (e.g. SpaceOperators), NoSpace, OneSpace, etc...
Crc32 ISO-3309 CRC-32 implementation. Contains 2 shared, overloaded functions, Calculate, to calculate the CRC-32 of an array of bytes or a block of unmanaged memory, and Validate to validate an array of bytes or a block of memory against an existing CRC-32 calculation.

DataTools.IL.Memory

MemPtr Experimental implementation of the MemPtr class with many functions rewritten in pure CIL (intermediate language, a form of assembly language for .NET).

This namespace is located in the DTIL project. It requires a free Visual Studio add-in called IL Support to be installed. Installing this add-in in Visual Studio 2013 requires a bit of hackery. Please drop me a line if you have trouble getting it working.

Last edited May 1 at 11:42 PM by nmoschkin, version 104