2016 to 2019

Source code can be downloaded on GitHub.

bytecode77 / bytecode-api

See also...

Online Documentation

Full online documentation for all classes and members.

BytecodeApi implements lots of extensions and classes for general purpose use. In addition, specific classes implement more complex logic for both general app development as well as for WPF apps.

Especially, boilerplate code that is known to be part of any Core DLL in a C# project is likely to be already here. In fact, I use this library in many of my own projects. For this reason, each class and method has been reviewed numerous times.

BytecodeApi is highly consistent, particularly in terms of structure, naming conventions, patterns, etc. The entire code style resembles the patterns used in the .NET Framework itself. You will find it intuitive to understand.

Documentation can be taken for granted! All classes and members have XML tags. The online documentation makes it easy to find the class or method you are looking for.


Following examples are a very brief overview over what features you can come to expect. However, the entire framework covers a lot more. Please review the online documentation to get a complete overview.

Example: Advanced conversion

// Additional conversion methods:

byte[] structBytes = ConvertEx.StructureToArray(myStruct);
MyStruct myStruct = ConvertEx.ArrayToStructure<MyStruct>(structBytes);
string excelColumn = ConvertEx.ToExcelColumnString(1); // <-- "A"

string hexString = ConvertEx.ToHexadecimalString(byteArray);

Example: Thread-safe access (Atomic)

Atomic<MyClass> ThreadSafeObj = new Atomic<MyClass>();

// Access an object in a thread-safe manner:
ThreadSafeObj.Value.Foo = 123;

// Or exchange the object:
ThreadSafeObj.Exchange((oldObject) => // <-- The current MyClass instance
	return new MyClass(); // <-- the new MyClass instance to replace "oldObject".

// Call a method, while the object is locked:
int result = ThreadSafeObj.Lock((obj) => obj.GetInteger());

// ...

public class MyClass
	public int Foo;

	public int GetInteger()
		return 0;

Example: CSV parsing

CsvFile file = CsvFile.FromFile(path: @"C:\test.csv", delimiter: null, hasHeaderRow: true);

// delimiter: null means auto-detect!

foreach (CsvRow row in file.Rows)
	int? id = row["A"].Int32Value;
	string name = row["B"].Value;

// And for the fans or victims of "CSV extreme databasing"
// This IEnumerable will iterate over the CSV file
IEnumerable<CsvRow> largeCsv = CsvFile.EnumerateFile(@"C:\very_large_file.csv", null, true);

Example: Advanced File I/O

// Find a string in a file
long index = FileEx.FindSequence(@"C:\test.txt", "search_me".ToUTF8Bytes());
if (index != -1)
	// ...

// FileEx extends the System.IO.File class.

Example: HTTP GET & POST request handling

// HttpClient implements GET, POST and multipart requests
string str = new HttpClient()
	.AddQueryParameter("id", "123")             // GET parameter for URL
	.AddPostValue("submit", "on")               // POST value (e.g.: The Submit button)
//              ^- Complete the request and get the result as string or byte[]

Example: WMI wrapper class

// Read WMI objects using the BytecodeApi.IO.Wmi namespace:
WmiObject[] processes = new WmiNamespace("CIMV2")

Example: Compression

byte[] file = File.ReadAllBytes("C:\\test.txt");

// Easily compress and decompress binary data:
byte[] compressed = Compression.Compress(file);
byte[] decompressed = Compression.Decompress(compressed);

Example: Cryptography

byte[] file = File.ReadAllBytes(@"C:\test.txt");

// Encrypt and decrypt binary content using a password.
byte[] encrypted = ContentEncryption.Encrypt(file, "123456");
byte[] decrypted = ContentEncryption.Decrypt(encrypted, "123456");

// Test using a the byte[] extension method:
if (!encrypted.Compare(decrypted)) throw new Exception();

// The "ContentEncryption" class uses
//     byte[] Encryption.Encrypt(byte[] data, byte[] iv, byte[] key)
// in conjunction with the SHA-256 converted password.

// Hash examples:
string passwordHash = Hashes.Compute("123456", HashType.SHA256);
string fileHash = Hashes.Compute(file, HashType.SHA256);

Example: DLL injection

Process process = ProcessEx.GetSessionProcessesByName("TaskMgr").First();

// Inject my wonderful ring-3 rootkit into your task manager.

// Project r77:

Example: ViewModel base class (INotifyPropertyChanged)

public class MyViewModel : ObservableObject
	// An MVVM property for the ViewModel.
	// Strongly typed and as simple as it gets:
	public string Foo
		get => Get(() => Foo);
		set => Set(() => Foo, value);
		// INotifyPropertyChanged -^

Online Documentation

BytecodeApi is fully documented using XML tags. The online documentation is an up-to-date reference.

Structure & Namespaces

  • BytecodeApi.dll
    • BytecodeApi.Comparers

      Provides comparison classes, such as NaturalStringComparer, that derive from IComparer and IComparer<T>.

    • BytecodeApi.Data

      Provides data objects and classes for generic data storage and manipulation. The Blob class is composed of a string Name and a byte[] Content property. Methods to import and export from/to filesystem are implemented, such as Blob.FromFile.

      The Blob class can be used in a variety of ways, particularly for data abstraction.

    • BytecodeApi.Extensions

      This namespace provides language extensions on classes, such as string, as well as all C# built-in types and some .NET base classes.

      Note, that some classes, such as ByteArrayExtensions or ProcessExtensions implement more complex features. Some extension methods, like IsNullOrEmpty(this string) are there to make building LINQ queries cleaner, while other methods implement more complex logic.

      To get an overview, please review the online documentation.

    • BytecodeApi.IO

      I/O classes for filesystem, operating system, devices and similar entities. "Ex"-Classes typically extend .NET classes, e.g. the FileEx class extends the System.IO.File class.

    • BytecodeApi.IO.Cli

      The OptionSet class parses and handles commandline strings efficiently in an easy-to-use manner.

    • BytecodeApi.IO.Debugging

      The DelegateTraceListener derives from TraceListener and directs trace events to event handlers.

    • BytecodeApi.IO.Http

      The HttpClient class handles HTTP GET and POST requests, including file download and upload.

    • BytecodeApi.IO.Interop

      Classes in this namespace support interoperability with the operating system.

      OutlookDataObject provides support for drag&drop operations from Outlook.

      The DynamicLibrary class allows to execute functions from native DLL's dynamically ("call API by name").

    • BytecodeApi.IO.SystemInfo

      This namespace provides classes to retrieve information from the operating system.

      The TcpViewEntry class provides a TCPView table for IPv4/v6 connections.

    • BytecodeApi.IO.Wmi

      Wrapper classes for read access to WMI.

    • BytecodeApi.Mathematics

      Mathematical functions.

      MathEx extends the System.Math class. Additionally, different angle types are supported (radians, degrees, gradians).

      BitCalculator provides bitwise manipulation of numeric datatypes and byte[] objects.

    • BytecodeApi.Text

      String operations for language related / human readable strings.

      The Wording class provides language related string operations.

      WordGenerator, SentenceGenerator and TextGenerator dynamically generate language-like text, similar to lorem ipsum. Helpful for text automation.

    • BytecodeApi.Threading

      Classes for multithreading operations.

      ThreadFactory is a factory class that creates Thread, DispatcherTimer and related objects.

      Atomic<T> is a thread-safe wrapper for a value that can be accessed by multiple threads.

  • BytecodeApi.Cryptography.dll
    • BytecodeApi.Cryptography

      Hashes, Encryption and AsymmetricEncryption wrap up basic cryptographic algorithms.

      ContentEncryption and AsymmetricContentEncryption provide more abstract encryption methods.

  • BytecodeApi.FileFormats.dll
    • BytecodeApi.FileFormats.Coff

      PEImage parses and exports EXE and DLL (COFF) files.

    • BytecodeApi.FileFormats.Csv

      CsvFile parses CSV files. Large files of any size can be iterated with an enumerator, as alternative to loading the complete file. Automatic separators detection is supported, and error lines are properly handled. This class also supports CSV file writing.

    • BytecodeApi.FileFormats.Ini

      IniFile parses INI files. The IniFileParsingOptions object defines parsing options, as the INI file format varies extensively between implementations. This class also supports INI file writing.

    • BytecodeApi.FileFormats.ResourceFile

      ResourceFileInfo parses a file containing resources, such as EXE or DLL files.

  • BytecodeApi.FileIcons.dll
    • BytecodeApi.FileIcons

      This DLL contains over 100 file icons for known Windows file extensions in 16x16, 32x32 and 48x48 resolution.

      The FileIcon class is used to retrieve the Icon object, or the Bitmap for each resolution of the icon.

      The KnownFileIconImages class is used for XAML binding.

  • BytecodeApi.GeoIP.dll
    • BytecodeApi.GeoIP

      This DLL contains the GeoLite2 database and a class to perform GeoIP lookup operations of IPv4 and IPv6 addresses. Lookup operations are performed on a local database and do not require an online API.

      public static Country Lookup(IPAddress ipAddress)

  • BytecodeApi.GeoIP.ASN.dll
    • BytecodeApi.GeoIP.ASN

      This DLL contains the GeoLite2 database and a class to perform GeoIP ASN lookup operations of IPv4 and IPv6 addresses. Lookup operations are performed on a local database and do not require an online API.

      public static Asn Lookup(IPAddress ipAddress)

  • BytecodeApi.GeoIP.City.dll
    • BytecodeApi.GeoIP.City

      This DLL contains the GeoLite2 database and a class to perform GeoIP city lookup operations of IPv4 and IPv6 addresses. Lookup operations are performed on a local database and do not require an online API.

      public static CityLookupResult Lookup(IPAddress ipAddress)

  • BytecodeApi.UI.dll
    • BytecodeApi.UI

      Namespace for WPF related classes. This library does not implement WindowsForms features.

    • BytecodeApi.UI.Controls

      Controls and helper classes for existing WPF controls.

      ObservableUserControl and ObservableWindow are related to ObservableObject and implement support for MVVM properties (INotifyPropertyChanged). These classes can be used in place of Window or UserControl objects.

    • BytecodeApi.UI.Converters

      Converters based on the ConverterBase<TValue, TResult> implementation.

      The resource dictionary /BytecodeApi.UI;component/Xaml/Converters.xaml can be added to a WPF project.

    • BytecodeApi.UI.Data

      ObservableObject implements support for MVVM properties (INotifyPropertyChanged) and can be used for ViewModel classes.

    • BytecodeApi.UI.Dialogs

      Classes for WPF message boxes and file dialogs.

    • BytecodeApi.UI.Effects

      GrayscaleEffect, when applied to a WPF control, is grayscale color effect.

    • BytecodeApi.UI.Extensions

      This namespace provides language extensions on WPF classes, such as UIElement or FrameworkElement.

    • BytecodeApi.UI.Markup

      Marup extension classes for all datatypes.

      EventBindingExtension can be used to bind events to commands in WPF.

    • BytecodeApi.UI.Mathematics

      Classes that support mathematical operations in a UI context, for example Deferrer and ProgressCalculator.