MCode Tutorial (Compiled Code in AHK)

Helpful script writing tricks and HowTo's
tic
Posts: 92
Joined: 03 Nov 2014, 03:10

Re: MCode Tutorial (Compiled Code in AHK)

25 Mar 2015, 14:40

Which compiler are you using? I was just wanting to test this application so downloaded

x86_64-w64-mingw32-gcc-4.9.2.exe
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: MCode Tutorial (Compiled Code in AHK)

25 Mar 2015, 14:45

I use an assembly compiler for all tasks I'm doing in MCode.
Its not quite comfortable but useable.
Recommends AHK Studio
guest3456
Posts: 3454
Joined: 09 Oct 2013, 10:31

Re: MCode Tutorial (Compiled Code in AHK)

20 Nov 2019, 00:40

nnnik wrote:
30 Sep 2013, 12:00
3. an MCode Function:
I use this one:

Code: Select all

MCode(mcode)
{
  static e := {1:4, 2:1}, c := (A_PtrSize=8) ? "x64" : "x86"
  if (!regexmatch(mcode, "^([0-9]+),(" c ":|.*?," c ":)([^,]+)", m))
    return
  if (!DllCall("crypt32\CryptStringToBinary", "str", m3, "uint", 0, "uint", e[m1], "ptr", 0, "uint*", s, "ptr", 0, "ptr", 0))
    return
  p := DllCall("GlobalAlloc", "uint", 0, "ptr", s, "ptr")
  if (c="x64")
    DllCall("VirtualProtect", "ptr", p, "ptr", s, "uint", 0x40, "uint*", op)
  if (DllCall("crypt32\CryptStringToBinary", "str", m3, "uint", 0, "uint", e[m1], "ptr", p, "uint*", s, "ptr", 0, "ptr", 0))
    return p
  DllCall("GlobalFree", "ptr", p)
}
are you sure VirtualProtect is only needed on AHKx64?

paulpma
Posts: 65
Joined: 08 Sep 2018, 22:05

Re: MCode Tutorial (Compiled Code in AHK)

20 Nov 2019, 13:38

Hi all,

I am a bit new to MCODE, but I have managed to install compiler TDM-GCC-64\bin\gcc.exe and was able to generate MCODE. However, I have been searching for at least couple hours but can't find a way to set compiler to generate MCODE encoding in hexadecimal vs base64(the default). The function is writeen in C.
Any help is appreciated, thank you.
paulpma
Posts: 65
Joined: 08 Sep 2018, 22:05

Re: MCode Tutorial (Compiled Code in AHK)

20 Nov 2019, 23:38

Someone helped me.. thank you..
You have to change it under "Settings" here :thumbup: :
"Laszlo Style" for Hex
"Bentschi Style" for Base64
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: MCode Tutorial (Compiled Code in AHK)

21 Nov 2019, 04:12

Which compiler did you use? Also why do you want to use Hex instead of base64?
Recommends AHK Studio
robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: MCode Tutorial (Compiled Code in AHK)

16 Jun 2020, 18:23

What does 1 or 2 stand for before x64/x86? I've seen machine codes using these. For example, in this one : " 2,x86:aipYww==,x64:uCoAAADD ".

Thank you.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: MCode Tutorial (Compiled Code in AHK)

16 Jun 2020, 18:38

its stupid way of passing CRYPT_STRING_HEX(1) / CRYPT_STRING_BASE64(2) to CryptStringToBinary(), depending on whose mcode functions ure using
robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: MCode Tutorial (Compiled Code in AHK)

16 Jun 2020, 18:55

Thank you.... So, if it's bentschi mode /edition , it's in base 64, right ?
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: MCode Tutorial (Compiled Code in AHK)

16 Jun 2020, 19:06

i dont know what betchis looks like
in the one 3 posts above me, yes.
just follow the code
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: MCode Tutorial (Compiled Code in AHK)

16 Jun 2020, 19:38

Yes, base64. :+1:
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
User avatar
RaptorX
Posts: 371
Joined: 06 Dec 2014, 14:27
Contact:

Re: MCode Tutorial (Compiled Code in AHK)

22 Jul 2023, 09:47

Sorry to bump this code after so long but I see a lot of examples showing code like this that contain x86 and x64 code:

Code: Select all

MCode("2,x86:i0wkBItEJAiFyXQKjWQkAA+vwUl1+sM=,x64:hcl0Bw+v0f/JdfmLwsM=")
But when I compile code it always shows only the x64 version of it, is there any settings that I should set?
Projects:
AHK-ToolKit
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: MCode Tutorial (Compiled Code in AHK)

22 Jul 2023, 12:36

If you mean MCode4GCC, I havent updated in a while so not sure if everything's working fully... but for GCC can specify 32bit or 64bit with the -m32 and -m64 flags
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
User avatar
RaptorX
Posts: 371
Joined: 06 Dec 2014, 14:27
Contact:

Re: MCode Tutorial (Compiled Code in AHK)

22 Jul 2023, 13:01

joedf wrote:
22 Jul 2023, 12:36
If you mean MCode4GCC, I havent updated in a while so not sure if everything's working fully... but for GCC can specify 32bit or 64bit with the -m32 and -m64 flags
I thought about the flags but where can I put them in MCode4GCC? after the path to the compiler I would assume right?
Projects:
AHK-ToolKit
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: MCode Tutorial (Compiled Code in AHK)

22 Jul 2023, 16:19

Yes, that should work. At least, that's what I did in the past. You could also maybe make a small modification in the script for this. I'm thinking about it, but might not get it to it for a while... :P
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: MCode Tutorial (Compiled Code in AHK)

22 Sep 2023, 22:26

@joedf

In what world would Mcodeforgcc produce outputs ending like this:

Code: Select all

...8D65F45B5E5F5DC3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
I tried to truncate the code up to c3, and the code still crashes.

It's absolutely bizarre, and I can't figure out why. I asked the AI, as well as looked around at stack overflow.

Specs:
* gcc 13.20 downloaded from https://winlibs.com/ winlibs personal build version gcc-13.2.0-mingw-w64ucrt-11.0.1-r2
* Running 32-bit compiler

The same exact code works fine when I compile using 64-bit.
https://godbolt.org/z/x1sMP8cGW
iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: MCode Tutorial (Compiled Code in AHK)

22 Sep 2023, 22:45

Of course, now that I made a post about it, it suddenly works. Looks like trimming the excess bytes is the solution.
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: MCode Tutorial (Compiled Code in AHK)

25 Sep 2023, 10:49

@iseahound Wow ahah, I'm glad it worked out. :+1:
I am not entirely sure why, but it seems we can get some junk towards the end. :think: There's a attempt to truncate some of that, but obviously not all is caught/removed...
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]

Return to “Tutorials (v1)”

Who is online

Users browsing this forum: No registered users and 48 guests