Project Description

ArchAssembler is a .net (c#) library providing the functionalities of an assembler. Target architecture is x86/x64 with streaming SIMD extensions. Target executable file format is Windows Portable Executable (PE).

Project Status

Under active developpement as of may 2011.

What is done:
  • Assembler framework.
  • Portable Executable file format is almost fully implemented. PE32 (32bits) and PE32+ (64bits).
  • X86 instruction set is ok (except system instructions).

What is not done yet:
  • X64 instruction set.
  • SSE instruction set.
  • Program Database (.pdb) file support.
  • Documentation and example code.

Quick example

This little program build an executable file that greets the world.

using System.IO;
using ArchAssembler.PortableExecutable;
using ArchAssembler.Elements;
using ArchAssembler.X86;

public static class Program
{
    public static void Main()
    {
        // image
        var image = new Image32();
        image.Subsystem = ImageSubsystem.Windows;

        // code section
        var codeSection = new ImageSection(".text", ImageSectionType.Code);
        image.Sections.Add(codeSection);
        
        // readonly data section
        var dataSection = new ImageSection(".data", ImageSectionType.ReadonlyData);
        image.Sections.Add(dataSection);

        // import table
        var importTable = new ImportTableElement();
        dataSection.Elements.Add(importTable);
        image.Directories[ImageDirectory.Import] = importTable;

        // imported functions
        var exitProcessFunction = importTable.Import("KERNEL32.DLL", "ExitProcess");
        var messageBoxFunction = importTable.Import("USER32.DLL", "MessageBoxA");

        // strings
        var message = dataSection.VariableSizeString("Hello, world!");
        var caption = dataSection.VariableSizeString("Hum...");

        // main
        var main = codeSection.ElementCollection();
        image.EntryPoint = main;

        main.Push32(0x00000040);
        main.Push32(caption);
        main.Push32(message);
        main.Push32(0);
        main.Call32(new EffectiveAddress(messageBoxFunction));
        main.Push32(0);
        main.Call32(new EffectiveAddress(exitProcessFunction));

        // let's do it!
        Stream stream = new FileStream("hello.exe", FileMode.Create, FileAccess.Write);
        image.Assemble(new BinaryWriter(stream));
        stream.Close();
    }
}

Last edited May 18, 2011 at 8:13 AM by OddCode, version 6