• Stars
    star
    112
  • Rank 312,240 (Top 7 %)
  • Language
    C++
  • License
    Other
  • Created over 11 years ago
  • Updated over 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A managed wrapper to use FASM compiler from .NET applications.

Fasm.NET

A managed wrapper to use FASM compiler from .NET applications.

This library is written in C++/CLI and embeds FASM compiler as a linkable Microsoft COFF object.
As FASM compiler is built in 32-bit, the managed assembly can only be used within a 32-bit development.

The branches match with the current versions of FASM compiler as published on the official website.

  • The branch master contains the latest tested version: 1.70.03 (2012-06-29)
  • The branch development contains the latest development snapshot version: None

Features

Fasm.NET offers the following features:

  • Assemble mnemonics on the fly
  • Assemble a file
  • Assemble multiple files
  • Create a instance of the class to assemble your mnemonics code with ease
  • Throw managed and detailed exceptions when compilation errors occur
  • Customize the memory size and the number of pass
  • Get the version of the FASM compiler

Examples

Here are some examples written in C# showing how the library can be used.

Assemble 32-bit inline mnemonics

var asm = FasmNet.Assemble("use32\nretn");

The variable asm is an array of bytes containing the assembly code.

Assemble 64-bit mnemonics using an array

string[] mnemonics =
	{
		"use64",
		"mov rax, 1",
		"retn"
	};

var asm = FasmNet.Assemble(mnemonics, 1000, 10);

Here is used an overloaded definition of the method to specify the memory size (1000 bytes) and the number of pass (10).
The variable asm is an array of bytes containing the assembly code.

Assemble two files

var files = new[] {"constants.inc", "main.asm"};
var asm = FasmNet.AssembleFiles(files);

The variable files is an array containing the files to assemble and asm is an array of bytes containing the assembly code.

Handle managed exceptions

var oops = "wrong";

try
{
	FasmNet.Assemble(oops);
}
catch (FasmAssemblerException ex)
{
	Debug.WriteLine("Error definition: {0}; Error code: {1}; Error line: {2}; Error offset: {3}; Mnemonics: {4}",
		ex.ErrorCode, (int)ex.ErrorCode, ex.ErrorLine, ex.ErrorOffset, ex.Mnemonics);
}

In this example, the assembling operation fails and an error is thrown.
The variable ex contains what, where and why the assembling operation couldn't terminate properly.

Use an instance of the class for more ease

IntPtr loadLibraryPtr = [...];
IntPtr start = new IntPtr(0x1000);
var fasm = new FasmNet();

fasm.AddLine("use32");
fasm.AddLine("mov eax,{0}", loadLibraryPtr);
fasm.AddLine("call eax");
fasm.AddLine("retn");

var asm = fasm.Assemble();
var rebased = fasm.Assemble(start);

The variable asm is an array of bytes containing the assembly code.
The variable rebased is an array of bytes containing the assembly code with a specified origin (given by the variable start).

Credits

I would thank Tomasz Grysztar, the author of FASM assembler and Shynd, who has done a similar job and gave me the idea to make this wrapper in C++/CLI.

Author

License

Fasm.NET is licensed under the MIT License (as of v2.0.0). Dependencies are under their respective (different) licenses. Please respect all license agreements.

More Repositories

1

MemorySharp

A C# based memory editing library targeting Windows applications, offering various functions to extract and inject data and codes into remote processes to allow interoperability.
C#
631
star
2

unine-twine

TWINE: An Embedded Trusted Runtime for WebAssembly. This is the repository that contains the source code of Twine and the related benchmarks.
C++
38
star
3

unine-watz

WaTZ: A Trusted WebAssembly Runtime Environment with Remote Attestation for TrustZone.
C
22
star
4

BenchShark

A lightweight library for benchmarking performance of your .NET applications.
C#
9
star
5

Matrix.NET

A .NET implementation of matrices and their operations in linear algebra.
C#
6
star
6

LatexCompendium

A comprehensive summary of the most used functionalities of LaTeX.
TeX
4
star
7

cmake-cpp-minimalistic-template

A minimalistic well-designed template for C/C++ project built using CMake.
CMake
3
star
8

CSharpCompendium

A summary of the most used features of C#.
C#
3
star
9

Tree.NET

A simplistic Tree implementation in .NET.
C#
2
star
10

PhysicsCompendium

Formulaire de physique rédigé en français.
1
star
11

DesignPatterns

A simplistic implementation of some well-known design pattern in C#.
C#
1
star
12

Complex.NET

A simplistic Complex data type implementation in .NET.
C#
1
star
13

DoublyLinkedList.NET

A simple and concise implementation of a doubly linked list in .NET.
C#
1
star
14

unine-opodis2023

The code and benchmarks of the OPODIS 2023 paper "A Holistic Approach for Trustworthy Distributed Systems with WebAssembly and TEEs".
C
1
star
15

rust-multipackages-template

A minimalistic template for compiling multiple packages in Rust.
Rust
1
star
16

polybench-c

The benchmark PolyBench/C that evaluates the performance using *nix `clock` function.
C
1
star
17

CTF-writeups

Writeups repository of the challenges I have solved during CTF competitions.
C
1
star
18

webassembly-polybench-c

The benchmark PolyBench/C made available for WebAssembly/WASI with ahead-of-time capabilities, provided by clang and WAMR.
C
1
star
19

hesso-bigdata-analytics

Master's project of Big Data Analytics for the University of Applied Sciences and Arts Western Switzerland.
Jupyter Notebook
1
star