ASM: ASM (assembly language) to machine code via FASM (flat assembler)

Discuss other programming languages besides AutoHotkey
User avatar
jeeswg
Posts: 4994
Joined: 19 Dec 2016, 01:58
Location: UK

ASM: ASM (assembly language) to machine code via FASM (flat assembler)

26 May 2018, 16:56

tl;dr 1 when the ASM is converted to an exe, how do I tell where the relevant machine code starts and ends
tl;dr 2 how to convert the example ASM below from x32 to x64
tl;dr 3 people are welcome to comment generally about AutoHotkey, machine code, and FASM

- I have seen one example on the forums so far of ASM to machine code.
InBuf function currently 32-bit only (machine code binary buffer searching) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=28393
- Do share any others.
- ASM code is converted to machine code, and the machine code is used with DllCall to perform an action. For this particular example, it searches binary data for a binary needle, in a similar way to the InStr function.
- This example works on AHK x32 only:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


- How to generate the machine code used in the function:
- First we copy the ASM code to a file, let's call it InBuf.asm.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


- We then use FASM to create an exe file based on the asm file.
flat assembler
http://flatassembler.net/
- (When I first tried to compile the asm to exe, it said that is was missing include files, I moved FASM.EXE to the INCLUDE folder and it worked.)
- I compiled simply by doing: Run, "%vPathFASM%" "%vPathAsm%"
- I read the contents of the exe file as a hex string. The required hex string used in the function was in the exe file, however I would not have known which bytes to copy and paste into the function.
- The resulting exe was 2048 bytes in size: 1074+224+750, the required code of 224 bytes began at 1074 bytes.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


- Two things I don't know:
- How to identify where the machine code starts/ends.
- How to convert the asm above to 64-bit.

Links:
- There are various links here. There is also a note re. converting exe to asm via OllyDbg.
InBuf function currently 32-bit only (machine code binary buffer searching) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=28393&p=219717#p219717
User avatar
nnnik
Posts: 3236
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: ASM: ASM (assembly language) to machine code via FASM (flat assembler)

26 May 2018, 22:46

Assembly code is different for 32 and 64 bit PCs.
I tried with Assembler before - in one of my encryptions - but it didn't work out.
Also its very difficult to load the function from an .exe if you use an Assembly compiler try to get some debugging format to do the work for you.
Recommends AHK Studio
YMP2
Posts: 43
Joined: 20 Apr 2014, 06:55

Re: ASM: ASM (assembly language) to machine code via FASM (flat assembler)

28 May 2018, 06:35

jeeswg wrote:1 when the ASM is converted to an exe, how do I tell where the relevant machine code starts and ends

You don't have to know that. Let the exe do all the work for you. That is, you compile it, then run it and it converts the machine code of your function into hex and puts in on the clipboard or saves it to a file. That's how I've done it in GoAsm. Unfortunately I am not familiar with FASM and can't write the conversion and output code in it.

The start of the machine code will be your function's label, and you can put another label right after its end. So the exe will read all that's between them.

Return to “Other Programming Languages”

Who is online

Users browsing this forum: No registered users and 2 guests