mcode-generator.com [Domain mcode-generator.com has expired, so online services are no longer available.]
MCode Generator for AHK
2020-03-01, Created Github Repository! Here
Features
-Using GCC
-Use Bentschi Style
-Create easy-to-see MCODE
-Select X86 or X64 to support compilation
-Code Copy Button Support
-Create example script
-Optimization Level Options Support
Online generator made by Benschi are not accessed.
Online is convenient, and simpler!
Lang: C#, ASP.net Core 2.1 MVC(Support docker)
Online MCode Generator(Beta, Tool)
Online MCode Generator(Beta, Tool)
Last edited by BoBo on 23 Feb 2022, 01:53, edited 3 times in total.
Reason: Added disclaimer about outdated 'mcode-generator.com' link.
Reason: Added disclaimer about outdated 'mcode-generator.com' link.
Re: Online MCode Generator(Beta, Tool)
great to have one of these again. benschi used to have one and it went offline. hopefully you will put yours on github open source so other people can continue if yours goes down
Re: Online MCode Generator(Beta, Tool)
Thanks for creating this. Having trouble making it work even with a very simple function. Fixed one of the issues where it shows the following in the AHK code:
Has a bunch of extra spaces and doesn't match anything. Matches as it should when changed to:
Is there something else needing correcting? Getting it to return an address, but when performing a DLL call to that address, not getting a return value.
Code: Select all
if (!regexmatch(mcode, " ^ ([0 - 9] +),(" c ":|.*?," c ":)([^,] +)", m))
Code: Select all
if (!regexmatch(mcode, "^([0-9]+),(" c ":|.*?," c ":)([^,]+)", m))
Re: Online MCode Generator(Beta, Tool)
Since Bentchi released his ahk-code to convert c/c++ code to machinecode with his online converter I post it here for reference
Code: Select all
/*! Adapted by TheGood
http://www.autohotkey.com/forum/viewtopic.php?p=364922
Last updated: August 17th, 2010
Rewrite for AHK 1.1+ Bentschi 2013
*/
installdir := "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\"
;HKCU\HKEY_CURRENT_USER\Software\Microsoft\VCExpress\11.0_Config\Setup\VC
;ProductDir
if (!FileExist(vcvarsall := installdir "vcvarsall.bat"))
ExitApp
opt := { opt: 1, lang: 1, comp: 1, enc: 1, warn: 1 }
pcount = %0%
if (!FileExist(file := AbsolutePath("tmp\test.c"))) ;AbsolutePath(%pcount%)))
ExitApp
fileinfo := SplitPath(file)
Loop % pcount
{
p := %A_Index%
if (p = "-minsize")
opt.opt := 1
else if (p = "-maxspeed")
opt.opt := 2
else if (p = "-c")
opt.lang := 1
else if (p = "-cpp")
opt.lang := 2
else if (p = "-x86")
opt.comp := 1
else if (p = "-x64")
opt.comp := 2
else if (p = "-x86x64")
opt.comp := 3
else if (p = "-hex")
opt.enc := 1
else if (p = "-base64")
opt.enc := 2
else if (RegExMatch(p, "^-warn([1-4])$", m))
opt.warn := m1
}
bat := "@echo off`r`n"
outfiles := {}
for k, v in {1: "x86", 2: "x86_amd64" }
{
if (opt.comp & k)
{
outfiles[v] := fileinfo.dir fileinfo.filename "_" v ".cod"
FileDelete, % fileinfo.dir fileinfo.filename "_" v ".cod"
bat .= "call """ vcvarsall """ " v "`r`n"
bat .= "cl " ((opt.lang=1) ? "/TC" : "/TP") " /c /FAc /Facode.cod /O" opt.opt " /W" opt.warn " """ file """`r`n"
bat .= "echo ERRORLEVEL: %ERRORLEVEL%`r`n"
bat .= "move """ fileinfo.dir "code.cod"" """ fileinfo.dir fileinfo.filename "_" v ".cod""`r`n"
}
}
SetWorkingDir, % fileinfo.dir
batfile := fileinfo.dir fileinfo.filename ".bat"
logfile := fileinfo.dir fileinfo.filename ".log"
FileDelete, % batfile
FileAppend, % bat, % batfile
FileDelete, % logfile
RunWait, % batfile " >> " logfile,, Hide
FileDelete, % fileinfo.dir "code.cod"
err := 0
Loop, read, % logfile
{
if (RegExMatch(A_LoopReadLine, "ERRORLEVEL: (.*)", m))
err += m1
}
if (err)
ExitApp
functions := {}
for k, v in outfiles
{
FileRead, code, % v
f := {}
while (RegExMatch(code, "ms)_?([^\s]+?)\s+PROC\s*(.*?)\s*[^\s]+\s*ENDP(.*)", m))
{
f.name := m1
f.code := RegExReplace(RegExReplace(m2, "m)^[^\t]*\t([^\t]+)[^\r\n]*", "$1"), "\s+")
if (opt.enc != 1)
{
binlength := StringToBinary(4, f.code, bin)
if (opt.enc = 2)
f.code := BinaryToString(1, &bin, binlength)
}
code := m3
}
functions[f.name, k] := f.code
}
out := ""
width := 100
for name, info in functions
{
c := "MCode(" name ", """
d := opt.enc
for comp, code in info
{
if (comp = "x86")
d .= ",x86:"
else if (comp = "x86_amd64")
d .= ",x64:"
else
continue
d .= code
}
if (StrLen(c) + StrLen(d) + 2 < width)
out .= c d """)"
else
{
out .= c "`r`n(LTrim Join`r`n"
while (StrLen(d) > width)
{
out .= SubStr(d, 1, width) "`r`n"
d := SubStr(d, width + 1)
}
if (d)
out .= d "`r`n"
out .= ")"")"
}
}
outfile := fileinfo.dir fileinfo.filename ".mcode"
FileDelete, % outfile
FileAppend, % out, % outfile
ExitApp
SplitPath(filename)
{
if (RegExMatch(filename, "^(.*\\)?([^.\\]*)\.?([^\\]*)$", m))
return { filename: m2, dir: AbsolutePath(m1), ext: m3 }
}
AbsolutePath(filename)
{
if (!DllCall("shlwapi\PathIsRelativeW", "wstr", filename))
return filename
s := DllCall("GetFullPathNameW", "wstr", filename, "uint", 0, "ptr", 0, "ptr", 0)
VarSetCapacity(buf, s * 2, 0)
DllCall("GetFullPathNameW", "wstr", filename, "uint", s, "ptr", &buf, "ptr", 0)
return StrGet(&buf, s, "utf-16")
}
StringToBinary(type, str, byref buf)
{
if (!DllCall("crypt32\CryptStringToBinary", "str", str, "uint", 0, "uint", type, "ptr", 0, "uint*", sout, "ptr", 0, "ptr", 0))
return ""
VarSetCapacity(buf, sout, 0)
if (!DllCall("crypt32\CryptStringToBinary", "str", str, "uint", 0, "uint", type, "ptr", &buf, "uint*", sout, "ptr", 0, "ptr", 0))
return ""
return sout
}
BinaryToString(type, ptr, size)
{
if (!DllCall("crypt32\CryptBinaryToStringW", "ptr", ptr, "uint", size, "uint", type, "ptr", 0, "uint*", sout))
return
VarSetCapacity(bout, sout << 1, 0)
if (!DllCall("crypt32\CryptBinaryToStringW", "ptr", ptr, "uint", size, "uint", type, "ptr", &bout, "uint*", sout))
return
return RegExReplace(StrGet(&bout, sout << 1, "utf-16"), "\s+")
}
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Re: Online MCode Generator(Beta, Tool)
@boiler
There was a problem creating the example script, and so did MCode.
This is a bug, and thank you for letting me know.
Try again.
(Tested in X86, X64.)
Please let me know Github id and I will register as a contributor.
Change log here
No, the code you modified is correct.boiler wrote: ↑01 Mar 2020, 20:52Thanks for creating this. Having trouble making it work even with a very simple function. Fixed one of the issues where it shows the following in the AHK code:Has a bunch of extra spaces and doesn't match anything. Matches as it should when changed to:Code: Select all
if (!regexmatch(mcode, " ^ ([0 - 9] +),(" c ":|.*?," c ":)([^,] +)", m))
Is there something else needing correcting? Getting it to return an address, but when performing a DLL call to that address, not getting a return value.Code: Select all
if (!regexmatch(mcode, "^([0-9]+),(" c ":|.*?," c ":)([^,]+)", m))
There was a problem creating the example script, and so did MCode.
This is a bug, and thank you for letting me know.
Try again.
(Tested in X86, X64.)
Please let me know Github id and I will register as a contributor.
Change log here
Re: Online MCode Generator(Beta, Tool)
Thank you for your comments!jNizM wrote: ↑02 Mar 2020, 05:49Since Bentchi released his ahk-code to convert c/c++ code to machinecode with his online converter I post it here for referenceCode: Select all
/*! Adapted by TheGood http://www.autohotkey.com/forum/viewtopic.php?p=364922 Last updated: August 17th, 2010 Rewrite for AHK 1.1+ Bentschi 2013 */ installdir := "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\" ;HKCU\HKEY_CURRENT_USER\Software\Microsoft\VCExpress\11.0_Config\Setup\VC ;ProductDir if (!FileExist(vcvarsall := installdir "vcvarsall.bat")) ExitApp opt := { opt: 1, lang: 1, comp: 1, enc: 1, warn: 1 } pcount = %0% if (!FileExist(file := AbsolutePath("tmp\test.c"))) ;AbsolutePath(%pcount%))) ExitApp fileinfo := SplitPath(file) Loop % pcount { p := %A_Index% if (p = "-minsize") opt.opt := 1 else if (p = "-maxspeed") opt.opt := 2 else if (p = "-c") opt.lang := 1 else if (p = "-cpp") opt.lang := 2 else if (p = "-x86") opt.comp := 1 else if (p = "-x64") opt.comp := 2 else if (p = "-x86x64") opt.comp := 3 else if (p = "-hex") opt.enc := 1 else if (p = "-base64") opt.enc := 2 else if (RegExMatch(p, "^-warn([1-4])$", m)) opt.warn := m1 } bat := "@echo off`r`n" outfiles := {} for k, v in {1: "x86", 2: "x86_amd64" } { if (opt.comp & k) { outfiles[v] := fileinfo.dir fileinfo.filename "_" v ".cod" FileDelete, % fileinfo.dir fileinfo.filename "_" v ".cod" bat .= "call """ vcvarsall """ " v "`r`n" bat .= "cl " ((opt.lang=1) ? "/TC" : "/TP") " /c /FAc /Facode.cod /O" opt.opt " /W" opt.warn " """ file """`r`n" bat .= "echo ERRORLEVEL: %ERRORLEVEL%`r`n" bat .= "move """ fileinfo.dir "code.cod"" """ fileinfo.dir fileinfo.filename "_" v ".cod""`r`n" } } SetWorkingDir, % fileinfo.dir batfile := fileinfo.dir fileinfo.filename ".bat" logfile := fileinfo.dir fileinfo.filename ".log" FileDelete, % batfile FileAppend, % bat, % batfile FileDelete, % logfile RunWait, % batfile " >> " logfile,, Hide FileDelete, % fileinfo.dir "code.cod" err := 0 Loop, read, % logfile { if (RegExMatch(A_LoopReadLine, "ERRORLEVEL: (.*)", m)) err += m1 } if (err) ExitApp functions := {} for k, v in outfiles { FileRead, code, % v f := {} while (RegExMatch(code, "ms)_?([^\s]+?)\s+PROC\s*(.*?)\s*[^\s]+\s*ENDP(.*)", m)) { f.name := m1 f.code := RegExReplace(RegExReplace(m2, "m)^[^\t]*\t([^\t]+)[^\r\n]*", "$1"), "\s+") if (opt.enc != 1) { binlength := StringToBinary(4, f.code, bin) if (opt.enc = 2) f.code := BinaryToString(1, &bin, binlength) } code := m3 } functions[f.name, k] := f.code } out := "" width := 100 for name, info in functions { c := "MCode(" name ", """ d := opt.enc for comp, code in info { if (comp = "x86") d .= ",x86:" else if (comp = "x86_amd64") d .= ",x64:" else continue d .= code } if (StrLen(c) + StrLen(d) + 2 < width) out .= c d """)" else { out .= c "`r`n(LTrim Join`r`n" while (StrLen(d) > width) { out .= SubStr(d, 1, width) "`r`n" d := SubStr(d, width + 1) } if (d) out .= d "`r`n" out .= ")"")" } } outfile := fileinfo.dir fileinfo.filename ".mcode" FileDelete, % outfile FileAppend, % out, % outfile ExitApp SplitPath(filename) { if (RegExMatch(filename, "^(.*\\)?([^.\\]*)\.?([^\\]*)$", m)) return { filename: m2, dir: AbsolutePath(m1), ext: m3 } } AbsolutePath(filename) { if (!DllCall("shlwapi\PathIsRelativeW", "wstr", filename)) return filename s := DllCall("GetFullPathNameW", "wstr", filename, "uint", 0, "ptr", 0, "ptr", 0) VarSetCapacity(buf, s * 2, 0) DllCall("GetFullPathNameW", "wstr", filename, "uint", s, "ptr", &buf, "ptr", 0) return StrGet(&buf, s, "utf-16") } StringToBinary(type, str, byref buf) { if (!DllCall("crypt32\CryptStringToBinary", "str", str, "uint", 0, "uint", type, "ptr", 0, "uint*", sout, "ptr", 0, "ptr", 0)) return "" VarSetCapacity(buf, sout, 0) if (!DllCall("crypt32\CryptStringToBinary", "str", str, "uint", 0, "uint", type, "ptr", &buf, "uint*", sout, "ptr", 0, "ptr", 0)) return "" return sout } BinaryToString(type, ptr, size) { if (!DllCall("crypt32\CryptBinaryToStringW", "ptr", ptr, "uint", size, "uint", type, "ptr", 0, "uint*", sout)) return VarSetCapacity(bout, sout << 1, 0) if (!DllCall("crypt32\CryptBinaryToStringW", "ptr", ptr, "uint", size, "uint", type, "ptr", &bout, "uint*", sout)) return return RegExReplace(StrGet(&bout, sout << 1, "utf-16"), "\s+") }
Re: Online MCode Generator(Beta, Tool)
Tried again, and it works. Thanks!
My Github id is boilercode, but there is no need to list me as a contributor. I appreciate you creating and sharing this tool.
Re: Online MCode Generator(Beta, Tool)
i use tdm-gcc-32 and it works with joedf's script
i think its good to have an alternative that uses mingw so we can have two different compiler options
Re: Online MCode Generator(Beta, Tool)
Why do you think so?
The current server is running on Linux (Debian) and will be installed for Linux when gcc is installed.
So the machine code that compiles with gcc cannot be used in Windows.
Am I wrong?
I will try again at gcc (not mingw x64) and write a reply.
Re: Online MCode Generator(Beta, Tool)
sorry i wasn't clear. i was saying its good that your online generator uses mingw, because i use tdm-gcc locally on my machine with joedf's script, and so i can compare both mcodes and choose the smaller onePlorence wrote: ↑04 Mar 2020, 00:35Why do you think so?
The current server is running on Linux (Debian) and will be installed for Linux when gcc is installed.
So the machine code that compiles with gcc cannot be used in Windows.
Am I wrong?
I will try again at gcc (not mingw x64) and write a reply.
Re: Online MCode Generator(Beta, Tool)
I see. From what I tested, there is little difference between mingw and tdm-gcc.
Sooner or later, I will make it possible to choose a compilation option.
Thank you for your reply.
-
- Posts: 15
- Joined: 14 Mar 2020, 16:36
Re: Online MCode Generator(Beta, Tool)
Hi folk... Id apreciate if you help me
I can't put mcode-generator.com code to work
is it good still?
========================================================================================================
-------------------------------------------C func---------------------------------------------------------
========================================================================================================
========================================================================================================
-------------------------------------------mcode generator x64 output for C func (funcsoma above)------------------------------
========================================================================================================
========================================================================================================
----------------------------------------------- my script -----------------------------------------------
========================================================================================================
[Mod edit: [code][/code] tags added]
I can't put mcode-generator.com code to work
is it good still?
========================================================================================================
-------------------------------------------C func---------------------------------------------------------
========================================================================================================
Code: Select all
int funcsoma(int Width, int Height)
{
return 3;
}
-------------------------------------------mcode generator x64 output for C func (funcsoma above)------------------------------
========================================================================================================
Code: Select all
MCode := "2,x64:VUiJ5YlNEIlVGLgDAAAAXcOQkJCQ"
_Function := BentschiMCode(MCode)
return
BentschiMCode(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)
}
----------------------------------------------- my script -----------------------------------------------
========================================================================================================
Code: Select all
msgbox % somasoma(1, 3)
return
BentschiMCode(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)
}
somasoma(a,b)
{
MCode := "2,x64:VUiJ5YlNEIlVGLgDAAAAXcOQkJCQ"
;x86 MCode := "2,x86:VYnluAMAAABdww=="
_Function := BentschiMCode(MCode)
E := DllCall( &_Function, "int*", a, "int*", b, "cdecl int")
return E
}
Re: Online MCode Generator(Beta, Tool)
Code: Select all
somasoma(a,b)
{
static _Function:=""
if (!_Function)
{
MCode := "2,x64:VUiJ5YlNEIlVGLgDAAAAXcOQkJCQ,x86:VYnluAMAAABdww=="
_Function := BentschiMCode(MCode)
}
E := DllCall( _Function, "int", a, "int", b, "cdecl int") ; Don't use &_Function
return E
}
Re: Online MCode Generator(Beta, Tool)
Do you know of a way to include math.h?
Re: Online MCode Generator(Beta, Tool)
I'm not sure either.
Please refer to this post.
See: https://www.autohotkey.com/boards/viewtopic.php?t=55647
Re: Online MCode Generator(Beta, Tool)
https://www.autohotkey.com/boards/viewtopic.php?f=7&t=32
I explained this in the basic MCode tutorial
I explained this in the basic MCode tutorial
Recommends AHK Studio
Re: Online MCode Generator(Beta, Tool)
Is there Any OFFLINE solution? I am in middle of coding..
Spoiler
Edit 08-Apr-2020: Works nowRe: Online MCode Generator(Beta, Tool)
I can't access it as well. Would this help: https://github.com/zxc010613/mcode-generator
Remember to use [code]CODE[/code]-tags for your multi-line scripts. Stay safe, stay inside, and remember washing your hands for 20 sec !
Return to “Scripts and Functions (v1)”
Who is online
Users browsing this forum: Bubo_Bubo, metallizer and 116 guests