MCode4GCC -- C/C++ to MCode Generator
Re: MCode4GCC -- C/C++ to MCode Generator
This really cool. I didnt know godbolt had an api. This is a great resource then!
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]
Re: MCode4GCC -- C/C++ to MCode Generator
Granted... I didn't even know the API was official/documented (sparsely)... xD While at work I spend a lot of time figuring out how websites work to automate them... Spending a lot of time in the chrome network tabjoedf wrote:I didnt know godbolt had an api.
Anyway, I'm glad people here will find a use for it (when it's eventually implemented )
Re: MCode4GCC -- C/C++ to MCode Generator
Yes, definitely! haha
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]
Re: MCode4GCC -- C/C++ to MCode Generator
tl;dr x32 MCode works but is overly long, x64 no MCode output
- I installed tdm64-gcc-5.1.0-2.exe to C:\TDM-GCC-64.
TDM-GCC : Download
http://tdm-gcc.tdragon.net/download
- I used 'TheAnswerToEverything.c' as the target file. The function returns 42.
- I used an x32 version of AutoHotkey.
- I based my settings on the image in the OP, i.e. I used the Overall option.
- If I specify 'gcc64' I get: [Empty]
- If I specify 'gcc' I get: 2,x86:uCoAAADDkJCQkJCQkJCQkA==
- I was hoping to get this: 2,x86:aipYww==,x64:uCoAAADD
- Or at least this: 2,x86:aipYww==
- The x32 (x86) machine code that I got was different to and longer than what I was hoping for, but it did work:- Any ideas on how I can get the same x32 machine code as in the example, and on how to get any x64 machine code? Thanks.
- [EDIT:] I noticed that the script is adding a trailing linefeed character when you click 'Copy to Clipboard'. And it adds them intermittently throughout long strings.- [EDIT:] Thanks so much for this script. It's been great writing C++ code and testing out the functions in AHK.
- I installed tdm64-gcc-5.1.0-2.exe to C:\TDM-GCC-64.
TDM-GCC : Download
http://tdm-gcc.tdragon.net/download
- I used 'TheAnswerToEverything.c' as the target file. The function returns 42.
- I used an x32 version of AutoHotkey.
- I based my settings on the image in the OP, i.e. I used the Overall option.
- If I specify 'gcc64' I get: [Empty]
- If I specify 'gcc' I get: 2,x86:uCoAAADDkJCQkJCQkJCQkA==
- I was hoping to get this: 2,x86:aipYww==,x64:uCoAAADD
- Or at least this: 2,x86:aipYww==
- The x32 (x86) machine code that I got was different to and longer than what I was hoping for, but it did work:
Code: Select all
q:: ;test machine code
;MyFunction := MCode("2,x86:aipYww==")
MyFunction := MCode("2,x86:aipYww==,x64:uCoAAADD")
MsgBox % DllCall(MyFunction,"cdecl") ;42
MyFunction := MCode("2,x86:uCoAAADDkJCQkJCQkJCQkA==")
MsgBox % DllCall(MyFunction,"cdecl") ;42
return
;==================================================
;GitHub - joedf/MCode4GCC: MCode4GCC is an MCode generator using the GCC Compiler.
;https://github.com/joedf/MCode4GCC
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)
}
- [EDIT:] I noticed that the script is adding a trailing linefeed character when you click 'Copy to Clipboard'. And it adds them intermittently throughout long strings.
Code: Select all
;I replaced this:
Clipboard:=x
;with this:
Clipboard:=Trim(x,"`r`n")
;or this:
Clipboard := Trim(StrReplace(x, "`n", "`r`n"), "`r`n")
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: MCode4GCC -- C/C++ to MCode Generator
I think those are Bentschis examples.
He used Visual C++ to compile the code with some optimisation flags.
He used Visual C++ to compile the code with some optimisation flags.
Recommends AHK Studio
Re: MCode4GCC -- C/C++ to MCode Generator
You can specify -m32 for 32 bit code and -m64 for 64 bit code for gcc tdm. It looks like joedf's script determines the x86/x64 prefix based on the bitness of the compiler executable, this will not be correct for tdm gcc if you use the mentioned flags.I installed tdm64-gcc-5.1.0-2.exe to C:\TDM-GCC-64.
Code: Select all
MyFunction := MCode("2,x86:uCoAAADDkJCQkJCQkJCQkA==,2,x64:uCoAAADDkJCQkJCQkJCQkA==")
Cheers.
Re: MCode4GCC -- C/C++ to MCode Generator
- Hmm, so I used gcc and it produced machine code that works with both x64 and x32. Cf. the examples which were about half as long, and were either x64 or x32 only.
- Do you mean to replace 'gcc' with 'gcc -m64'/'gcc -m32' in the GUI, or to edit the 'flags' variable in the script directly. (Since the machine code wasn't changing when I tried to add flags, I probably presumed that the flag wasn't working.)
- Btw is there some possibility that the machine code I'm producing is actually x64 and x32 machine code concatenated, or is there an issue of junk (unnecessary machine code) being removed? That is somehow two-way compatible.
- Btw also, are people getting the same machine code that I'm getting? How was joedf able to use 'gcc64' and get a different x64 machine code result in the image in the OP? Thanks.
- Do you mean to replace 'gcc' with 'gcc -m64'/'gcc -m32' in the GUI, or to edit the 'flags' variable in the script directly. (Since the machine code wasn't changing when I tried to add flags, I probably presumed that the flag wasn't working.)
- Btw is there some possibility that the machine code I'm producing is actually x64 and x32 machine code concatenated, or is there an issue of junk (unnecessary machine code) being removed? That is somehow two-way compatible.
- Btw also, are people getting the same machine code that I'm getting? How was joedf able to use 'gcc64' and get a different x64 machine code result in the image in the OP? Thanks.
Code: Select all
;joedf:
2,x86:aipYww==,x64:uCoAAADD
;me (same machine code twice):
2,x86:uCoAAADDkJCQkJCQkJCQkA==,x64:uCoAAADDkJCQkJCQkJCQkA==
;base64 as hex:
Tomasz Ostrowski - Base64 decoder
http://tomeko.net/online_tools/base64.php?lang=en
aipYww== ;hex: 6A2A58C3
uCoAAADD ;hex: B82A000000C3
uCoAAADDkJCQkJCQkJCQkA== ;hex: B82A000000C390909090909090909090
;source code (TheAnswerToEverything.c):
int TheAnswerToEverything() {
return 42;
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: MCode4GCC -- C/C++ to MCode Generator
edit the flags set in the script, not in the gui. I think gcc-tdm does 64 by default so you were a bit unlucky that the code worked on 32 bit too.
There is no concatenation.
Cheers.
The trailing 90... are nops (no operation (helgef memory )) which aren't really needed, all compilers will not add these, you can remove them.Code: Select all
uCoAAADD ;hex: B82A000000C3 uCoAAADDkJCQkJCQkJCQkA== ;hex: B82A000000C390909090909090909090
There is no concatenation.
Cheers.
Re: MCode4GCC -- C/C++ to MCode Generator
I've tried to create a stand-alone script for C++ to machine code:
C++: C++ to machine code via TDM-GCC - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 23&t=49554
C++: C++ to machine code via TDM-GCC - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 23&t=49554
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: MCode4GCC -- C/C++ to MCode Generator
What Helgef says here is exactly on point. How I had GCC set up is MinGW x86 and x64 installed and made copies of gcc.exe and renamed them gcc64.exe and gcc32.exe ... or something like that.Helgef wrote:You can specify -m32 for 32 bit code and -m64 for 64 bit code for gcc tdm. It looks like joedf's script determines the x86/x64 prefix based on the bitness of the compiler executable, this will not be correct for tdm gcc if you use the mentioned flags.I installed tdm64-gcc-5.1.0-2.exe to C:\TDM-GCC-64.It works for me on both 32 and 64, I got the same result with -m32 -O3 and -m64 -O3.Code: Select all
MyFunction := MCode("2,x86:uCoAAADDkJCQkJCQkJCQkA==,2,x64:uCoAAADDkJCQkJCQkJCQkA==")
Cheers.
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]
Re: MCode4GCC -- C/C++ to MCode Generator
Did anybody try compiling something that has external calls? Such as this.
Code: Select all
#include <windows.h>
void main()
{
MessageBox(0, "Hello", "Welcome Message", 1);
}
Re: MCode4GCC -- C/C++ to MCode Generator
You can see nnniks mcode tutorial on how to use function pointers.
Re: MCode4GCC -- C/C++ to MCode Generator
The same result, uCoAAADDkJCQkJCQkJCQkA==, with the extra kJCQkJCQkA at the back.jeeswg wrote: ↑24 May 2018, 12:57- Btw also, are people getting the same machine code that I'm getting?
;me (same machine code twice):Code: Select all
2,x86:uCoAAADDkJCQkJCQkJCQkA==,x64:uCoAAADDkJCQkJCQkJCQkA==
Where are you getting your MinGW files? People are referencing them, but not clarifying how they got x86 and x64
Do you mean that your x64 install is from here? https://sourceforge.net/projects/mingw-w64/
And your x86 install is from here? https://sourceforge.net/projects/mingw/
Or are you getting both MinGW x86 and x64 versions in a single download?
Note- for those that choose TDM-GCC, it's 2 different downloads for the x64 and x32 versions. http://tdm-gcc.tdragon.net/download
Re: MCode4GCC -- C/C++ to MCode Generator
@SOTE
Correct
I have used TDM, installation seems much more newbie friendly.
Correct
I have used TDM, installation seems much more newbie friendly.
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]
Re: MCode4GCC -- C/C++ to MCode Generator
You can refer to this:quantum wrote:Did anybody try compiling something that has external calls? Such as this.
Code: Select all
#include <windows.h> void main() { MessageBox(0, "Hello", "Welcome Message", 1); }
https://autohotkey.com/boards/viewtopic ... 413#p89413
Re: MCode4GCC -- C/C++ to MCode Generator
It seems the TDM-GCC is reporting back incorrect information with your script. With my previous downloads of MingGW 32-bit and 64-bit files, your script always reported back x86 or x64 correctly.
But if I download and install the 32-bit and 64-bit versions of TDM-GCC, your script doesn't show the x64 version information correctly. Both versions of TDM-GCC (to include the 64-bit one) will report back as x86. If there is a specific change that needs to be made in the script, perhaps it's best to show the code and location of what needs to be changed. Another way is maybe to recognize that it's a TDM-GCC installation and make the change automatically.
Re: MCode4GCC -- C/C++ to MCode Generator
This is interesting but not sure if this is the same way AutoIt does it.
Why define global functions at all? It seems weird.
Here is an example that works with BinaryCall UDF.
Why define global functions at all? It seems weird.
Here is an example that works with BinaryCall UDF.
Code: Select all
#include <windows.h>
#include <iphlpapi.h>
#pragma comment(lib, "iphlpapi.lib")
BOOL IsConnectedToServer(DWORD dwProcessId)
{
DWORD dwSize = 0;
if (GetExtendedTcpTable(0, &dwSize, TRUE, AF_INET, TCP_TABLE_OWNER_PID_CONNECTIONS, 0) != ERROR_INSUFFICIENT_BUFFER)
return FALSE;
HANDLE hHeap = GetProcessHeap();
LPVOID lpTcpTable = HeapAlloc(hHeap, 0, dwSize);
if (lpTcpTable == NULL)
return FALSE;
if (GetExtendedTcpTable(lpTcpTable, &dwSize, TRUE, AF_INET, TCP_TABLE_OWNER_PID_CONNECTIONS, 0) != NO_ERROR)
{
HeapFree(hHeap, 0, lpTcpTable);
return FALSE;
}
DWORD i;
MIB_TCPROW_OWNER_PID TcpTable;
for (i = 0; i < ((PMIB_TCPTABLE_OWNER_PID)lpTcpTable)->dwNumEntries; i++)
{
TcpTable = ((PMIB_TCPTABLE_OWNER_PID)lpTcpTable)->table[i];
if (TcpTable.dwOwningPid == dwProcessId && TcpTable.dwRemotePort == 0xEF21)
{
HeapFree(hHeap, 0, lpTcpTable);
return TRUE;
}
}
HeapFree(hHeap, 0, lpTcpTable);
return FALSE;
}
Re: MCode4GCC -- C/C++ to MCode Generator
Sure!
How would you recommend identifying TDM? and compiling x86 vs x64 commands?
(I dont have it setup on this PC)
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]
Re: MCode4GCC -- C/C++ to MCode Generator
I think it's probably best to identify the directory or files in TDM that are associated with the 64-bit version. Such as "x86_64-w64-mingw32", "gdb64", or search for strings with 64 in them. Then set to "-m64". That, or specifically have an option on the GUI for TDM or any gcc.exe (future proofing), as a manual setting, that will attempt to give a 64-bit result with the "-m64" setting. So, you could have an "auto" setting where you attempt to identify if gcc.exe is 32-bit or 64-bit, or a manual setting where the person identifies that version of gcc.exe as being such.
Re: MCode4GCC -- C/C++ to MCode Generator
well here's what it does currently
https://github.com/joedf/MCode4GCC/blob ... #L334-L341
But it isnt the most reliable because it seems that some compilers with 32bit exe's to make 64bit exe.... weird :b
Code: Select all
Get_CompilerType(cp) {
if !FileExist(cp)
cp:=get_where_Path(cp)
if Is64BitAssembly(cp)
return "64"
else
return "32"
}
But it isnt the most reliable because it seems that some compilers with 32bit exe's to make 64bit exe.... weird :b
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 “Scripts and Functions (v1)”
Who is online
Users browsing this forum: Google [Bot] and 127 guests