FASM in C# menu

User Tag List

Thread: FASM in C#

Results 1 to 5 of 5
  1. #1
    Jens's Avatar Contributor
    Reputation
    179
    Join Date
    Sep 2006
    Posts
    251
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    FASM in C#

    I recently decided that copy / pasting memory patches to use in my framework was really tedious, so I decided to get FASM to work in C# since i could not be bothered to use fasm_managed, since it is in C++/CLI and therefore the devil.

    This is a just a simple .cs file, containing the necessary code to call fasm_assemble from the FASM library (less than 30 lines of code)

    The only purpose of this code was to assemble asm to bytes, it does not contain code to write the bytes to memory or call asm procedures, it is all trivial to implement though.

    Have a look at it here.

    Usage:
    Code:
    string asm = @"push ebp
    	       mov ebp, esp
    
    	       mov esp, ebp
    	       pop ebp
    
    	       ret";
    
    try
    {
    	byte[] bytes = Asm.Assemble(asm);
    
    	foreach (var b in bytes)
    	{
    		Console.Write(b.ToString("X2") + " ");
    	}
    }
    catch (Exception e)
    {
    	Console.WriteLine(e.Message);
    }
    
    Console.Read();
    Error examples:
    Code:
    Assembling failed!
    State:  FASM_ERROR
    Error:  FASMERR_ILLEGAL_INSTRUCTION
    line:   5
    
    Assembling failed!
    State:  FASM_ERROR
    Error:  FASMERR_INVALID_OPERAND
    line:   4
    Remember to include the FASM library in your output directory, or wherever you decide to call it from, otherwise bad things will happen.

    If you would like to get FASM library yourself, you can get it here, remember to change the DllImport according to the name of the assembly.


    Credits:
    - Shynd for fasm_managed, the C++/CLI wrapper for FASM
    - Tomasz Grysztar for FASM


    Enjoy.

    FASM in C#
  2. #2
    nableng's Avatar Private
    Reputation
    1
    Join Date
    May 2012
    Posts
    5
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    c# and asm... srsly?

  3. #3
    Jens's Avatar Contributor
    Reputation
    179
    Join Date
    Sep 2006
    Posts
    251
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by nableng View Post
    c# and asm... srsly?
    Everything (!) should be done in C#

  4. #4
    berlinermauer's Avatar Master Sergeant
    Reputation
    3
    Join Date
    Mar 2010
    Posts
    89
    Thanks G/R
    0/0
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hint: Let the first line be "use32" or else you will expecting Problems as all your addresses and registers are considered 16bits

  5. #5
    Jens's Avatar Contributor
    Reputation
    179
    Join Date
    Sep 2006
    Posts
    251
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by berlinermauer View Post
    Hint: Let the first line be "use32" or else you will expecting Problems as all your addresses and registers are considered 16bits
    Is added automatically, since it's a bother to do that every time you want to assemble something.

Similar Threads

  1. Blackmagic / FASM
    By peterwurst in forum WoW Memory Editing
    Replies: 7
    Last Post: 03-27-2009, 02:33 PM
  2. Be sure you always have FASM.dll
    By luciferc in forum WoW Memory Editing
    Replies: 5
    Last Post: 12-27-2008, 12:23 AM
All times are GMT -5. The time now is 09:30 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search