Coder Social home page Coder Social logo

assemblysharp's Introduction

AssemblySharp

Implementation of C/C++ __asm or __asm__ keywords as closely as possible in C#. Standard Intel syntax used in Microsoft Micro Assembler (MASM) assembler is supported.

Works on .Net core 2.1

Usage

int a = 200;
int result = (int)X86Assembly.ExecuteScript(
    ASM.MOV, REG.EAX, 100,
    ASM.ADD, REG.EAX, a,
    ASM.RET);
Console.WriteLine(result); // 300
int i = 100;
result = X86Assembly.ExecuteScript(
    ASM.mov, REG.EAX, 0,
    ASM.mov, REG.ECX, i,
    new Label("myloop"),
    ASM.add, REG.EAX, REG.ECX,
    ASM.loop, "myloop",
    ASM.ret));
Console.WriteLine(result); // 5050

Requirements

Should be installed gcc, objdump. You need to set your PATH environment variable to include directory of them.

The MIT License (MIT) Copyright (c) 2019 20chan

assemblysharp's People

Contributors

20chan avatar jvitkauskas avatar kashif-at-tandem avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

assemblysharp's Issues

Pass reference of operand to instruction

In AssemblySharp currently(894ebaa), registers are like

public dwordop EAX => _vm.EAX;
public dwordop EBX => _vm.EBX;
public dwordop ECX => _vm.ECX;
public dwordop EDX => _vm.EDX;

(I made type dwordop, wordop, byteop but it's useless)

And what I want to do is make this code work.

vm.Instrucment.MOV(vm.Registers.EAX, 3);

Type of EAX is Register, and it's same as uint type. That means, there's no way to know what is that operand. It's not problem only in registers, all of operands like segments and memory, etc.

Type of delegate in RunMachineCode

Before 7cab4db X86Assembly.RunMachineCode was like this.

T RunMachineCode<T>(...)

In the issue #1 I was trying to declare delegate type of T in runtime, and use it as generic parameter of Marshal.GetDelegateForFunctionPointer but I gave up as you can see at d113692.

But all the types of returned value is not integer. This will make code more messy casting types.

Add VM

Allocating memory and executing machine code is dangerous, and sometimes not working because CLR manages memory. VM executing machine code can do anything! 😄

AccessViolationException when using register or memory

In current version, System.AccessViolationException throwed when I use register ebx or push something.
I thought it's problem allocating memory using VirtualAlloc, so I changed that part like this.

var buffer = Marshal.AllocCoTaskMem(bytecode.Length);
// var buffer = WinAPI.VirtualAlloc(IntPtr.Zero, (uint)bytecode.Length, WinAPI.AllocationType.Commit, WinAPI.MemoryProtection.ExecuteReadWrite);

I tried to use Marshal.AllocCoTaskMem instead of VirtualAlloc, and I ran some test cases. When I access ANY of registers it throwed AccessViolationException. It was much worse.

Is there any way to use " unsafe " memory/register accessing?

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.