BytecodeApi

1.4.5
2021
BSD
CC BS-SA 4.0 (for GeoLite2 database)
bytecode-api
BytecodeApi 1.4.5.zip
Online Documentation

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

Especially, boilerplate code that is common ground for any C# project is covered by BytecodeApi. 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 and patterns. The code style resembles the patterns we know from .NET Framework. 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.

Examples

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

  • Advanced conversion
  • CSV parsing
  • Advanced File I/O
  • HTTP Client
  • Thread-safe access
  • WMI wrapper
  • Compression
  • Cryptography
  • DLL injection
  • ViewModel base class
// 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);
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);
// 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.
// HttpClient implements GET, POST and multipart requests
string str = new HttpClient()
	.CreatePostRequest("http://example.com/")
	.AddQueryParameter("id", "123")          // GET parameter for URL
	.AddPostValue("submit", "on")            // POST value (e.g.: The Submit button)
	.ReadString();
//              ^- Complete the request and get the result as string or byte[]
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;
	}
}
// Read WMI objects using the BytecodeApi.IO.Wmi namespace:
WmiObject[] processes = new WmiNamespace("CIMV2")
	.GetClass("Win32_Process")
	.GetObjects()
	.ToArray();
byte[] file = File.ReadAllBytes(@"C:\test.txt");

// Easily compress and decompress binary data:
byte[] compressed = Compression.Compress(file);
byte[] decompressed = Compression.Decompress(compressed);
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);
Process process = ProcessEx.GetSessionProcessesByName("TaskMgr").First();

// Inject my wonderful ring-3 rootkit into your task manager.
process.LoadLibrary(@"C:\r77.dll");

// Project r77: https://bytecode77.com/r77-rootkit
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.

  • BytecodeApi.dll
    • BytecodeApi.Comparers
    • BytecodeApi.Data
    • BytecodeApi.Extensions
    • BytecodeApi.IO
    • BytecodeApi.IO.Cli
    • BytecodeApi.IO.Debugging
    • BytecodeApi.IO.FileSystem
    • BytecodeApi.IO.Http
    • BytecodeApi.IO.Interop
    • BytecodeApi.IO.SystemInfo
    • BytecodeApi.IO.Wmi
    • BytecodeApi.Mathematics
    • BytecodeApi.Text
    • BytecodeApi.Threading
  • BytecodeApi.Cryptography.dll
    • BytecodeApi.Cryptography
  • BytecodeApi.FileFormats.dll
    • BytecodeApi.FileFormats.Coff
    • BytecodeApi.FileFormats.Csv
    • BytecodeApi.FileFormats.Ini
    • BytecodeApi.FileFormats.ResourceFile
  • BytecodeApi.FileIcons.dll
    • BytecodeApi.FileIcons
  • BytecodeApi.GeoIP.dll
    • BytecodeApi.GeoIP
  • BytecodeApi.GeoIP.ASN.dll
    • BytecodeApi.GeoIP.ASN
  • BytecodeApi.GeoIP.City.dll
    • BytecodeApi.GeoIP.City
  • BytecodeApi.UI.dll
    • BytecodeApi.UI
    • BytecodeApi.UI.Controls
    • BytecodeApi.UI.Converters
    • BytecodeApi.UI.Data
    • BytecodeApi.UI.Dialogs
    • BytecodeApi.UI.Effects
    • BytecodeApi.UI.Extensions
    • BytecodeApi.UI.Markup
    • BytecodeApi.UI.Mathematics

This is a brief overview of the assemblies and namespaces.

Click on a namespace to start exploring.

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

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.

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.

This namespace provides classes for I/O and data processing.

Exampless: ProcessEx is an extension library for the Process class, or Compression, which is a helper class for GZip related I/O.

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

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

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.

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

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").

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

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

Wrapper classes for read access to WMI.

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.

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.

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.

Hashes, Encryption and AsymmetricEncryption wrap up basic cryptographic algorithms.

ContentEncryption and AsymmetricContentEncryption provide more abstract encryption methods.

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

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.

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.

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

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.

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)

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)

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)

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

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.

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

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

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

Classes for WPF message boxes and file dialogs.

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

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

Marup extension classes for all datatypes.

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

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