Code Monkey home page Code Monkey logo

interactiveassembler64's Introduction

basic_use

InteractiveAssembler64

#inasm64

This project is Work-In-Progress, but the end goal is pretty clear; a simple command line interactive Intel® 64 assembler inspired by the old DOS debug.exe. With it you can interatively enter and run Intel® 64 64-bit Long Mode assembly for Intel CPUs.

Why?

Because I think it's nice to be able to just write some lines of assembly and see them execute immediately. There are a lot of instructions available on modern CPUs and being able to try them out and see the effect interactively is nice. It's also an interesting project because it involves writing a small debugger using the Windows Debug APIs, and interacting with an assembler.

When?

It's a pet project, and with a full time job and two kids it's not going to be finished quickly! If you're interested then please come back occasionally to check up on progress, I'll be using twitter @psjarlo to post updates now and then too.

How to Build

  • Clone this repo and Intel XED so that you get this structure:
- root \
       |- InteractiveAssembler64
       |- xed
  • Build XED according to instructions (straight forward, but requires Python27) as a library (not shared).
  • Open up inasm64.sln and you're good to go.

Running Inasm64

This is WIP, many of the commands are not finished yet, but the most basic use is;

  • a to start assembling.
  • empty line to finish assembling.
  • p to start single stepping from the first assembled instruction.
  • r to dump registers.
  • q to quit.

Code

Structure

The project is broken down into three main components living under the root namespace, inasm64

  • The runtime
  • The assembler
  • The CLI (Command Line Interface)

Runtime inasm64::runtime

The runtime takes binary Intel® 64 instructions as input and lets you execute them, one by one. At the core of the runtime is a debugger (using the Windows DebugAPI) which single-steps the code to run. It also provides access to the execution context (registers, flags).

Assembler inasm64::assembler

The assembler consists of a front end and a back end where the front end (in assembler.cpp) is responsible for parsing single line (NASM syntax) assembly statements and converting these to a generic tokenised format (a Statement). The Statement structure encodes information like the operands, instruction, width prefixes (like dword), and the operand types (register, immediate, or memory). This format is then used by the back end "assembler driver" to generate instruction bytes, using Intel XED as the back end. Note that there is no optimisation step in the assembler, what you type in is what you get. This is important to keep in mind if you are comparing the generated instruction bytes with the output of a different assembler, for example NASM, which often make small changes to optimise for size. For example, using NASM 2.13, the statement

mov rax, 42

generates the instruction bytes B82A000000 which is equivalent to mov eax,42. As the high dword of rax is cleared in this operation the result is the same, but with fewer instruction bytes than the "correct" sequence 48B82A0000000000, which is what Inasm64 generates.

CLI inasm64::cli

The CLI provides a simple command line interface for driving the runtime and assembler. It takes commands modelled on the old debug.exe and the modern Windbg. In architectural terms the CLI provides a sort of "presentation layer", binding and controlling the runtime and assembler.

Tools used

interactiveassembler64's People

Contributors

jarlostensen avatar

Stargazers

Johan avatar Thomas Leary avatar Henk van der Spek avatar  avatar Octavian avatar Scott Perham avatar Matthew Bettcher avatar  avatar Alexandre Larouche avatar Westerbly Snaydley avatar  avatar Xceno avatar rodrigo figueroa avatar Krzysztof Kondrak avatar  avatar Andre Weissflog avatar

Watchers

 avatar Octavian avatar

interactiveassembler64's Issues

Assembler should error if instructions being assembled don't work

I.e. trying to assemble AVX512 instructions on hardware that doesn't support it should raise an error (instead of causing an exception when the instruction is executed.)
This will require detection of instruction classes, or could use registers (xmm,ymm,zmm) for some types of instructions, or perhaps blacklisting?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.