MCode4GCC -- C/C++ to MCode Generator

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: MCode4GCC -- C/C++ to MCode Generator

25 Nov 2019, 11:05

I tried the new version (with 2 edits) and it worked great. Thanks!

The 2 edits were to undo the 2 changes to Base64enc (which uses CryptBinaryToString), old script: 1, new script: (0x40000000|0x01).
I would use 1 because: (0x40000000|0x01) would potentially make the script fail on Windows XP and earlier, and 1 is sufficient since the new removeWhitespaceChars function has been added.

(Maybe on Windows XP and earlier, the 0x40000000 is accepted, but has no effect, or maybe it causes an error, it would be good if someone could test it.)
Last edited by jeeswg on 25 Nov 2019, 16:50, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
joedf
Posts: 8962
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: MCode4GCC -- C/C++ to MCode Generator

25 Nov 2019, 15:58

So I've just tested it under XP SP3: no crash or error with either or flag values. However, the base64 is always blank...
So the script seems to be breaking somewhere else... :think:
EDIT: StringToBinary() broken for XP...
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
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: MCode4GCC -- C/C++ to MCode Generator

25 Nov 2019, 16:52

I've updated my post above. So perhaps: replace (0x40000000|0x01) with 1, in 2 places, as it was in the original script.

And/or, StringToBinary, uses CryptStringToBinary. StringToBinary specifies a default value of CRYPT_STRING_HEXRAW := 0xC, which is not supported by Windows XP.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: MCode4GCC -- C/C++ to MCode Generator

10 Apr 2020, 05:47

@joedf . Nice script! Thanks. I'm studying it extensively :P

joedf wrote:
13 Dec 2018, 22:02
well here's what it does currently

Code: Select all

Get_CompilerType(cp) {
	if !FileExist(cp)
		cp:=get_where_Path(cp)
	if Is64BitAssembly(cp)
		return "64"
	else
		return "32"
}
https://github.com/joedf/MCode4GCC/blob/master/MCode4GCC.ahk#L334-L341

But it isnt the most reliable because it seems that some compilers with 32bit exe's to make 64bit exe.... weird :b
But compilers do write either a 32bit or 64bit exe :)
Check the target exe instead of the compiler exe

Code: Select all

Is64BitAssembly(tmpf_b)

To suppress the error <Error ignored: undefined reference to 'WinMain'>, I use WinMain() in my c file

Code: Select all

int WinMain()
{
  return 0; 
}
If I do that, machine code for WinMain() is included in the result.
Let me know if you need a parser for assembly listing file.
My Scripts and Functions: V1  V2
User avatar
joedf
Posts: 8962
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: MCode4GCC -- C/C++ to MCode Generator

10 Apr 2020, 11:53

Thanks, SKAN! Yes, you are correct! I haven't taken time to look into these issues and fix them.
If you make a pull request, I would be honored to incorporate any changes and any improvements you make. :+1:

This was the result of a collaborative effort, including code from you. :dance:
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
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: MCode4GCC -- C/C++ to MCode Generator

11 Apr 2020, 19:36

joedf wrote:If you make a pull request, I would be honored to incorporate any changes and any improvements you make. :+1:
I don't use GitHub (or know how that stuff works) :(
I am writing a heavily customized GUI for my needs and it will be awkward to share it.
My parser for GAS file (GCC Assembly Listing with .S extension) has come out well.
It will detect if assembly is x86 or x64 from the GCC GAS file itself.
I will share it Scripts and Functions.

I will put the link in this post in case you or anybody else can put it to good use.

Thanks to you and the other person who is providing the online version.

:)
My Scripts and Functions: V1  V2
User avatar
joedf
Posts: 8962
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: MCode4GCC -- C/C++ to MCode Generator

12 Apr 2020, 18:58

No worries! Post the relevant links and material here when you can. And I'll try to integrate it in my spare time.
Thanks SKAN :D :+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]
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: MCode4GCC -- C/C++ to MCode Generator

12 Apr 2020, 19:11

SKAN wrote:
11 Apr 2020, 19:36
joedf wrote:If you make a pull request, I would be honored to incorporate any changes and any improvements you make. :+1:
I don't use GitHub (or know how that stuff works) :(
There is Pastebin (https://pastebin.com/) and GitHub Gist (https://gist.github.com/discover- GitHub's version of Pastebin). Much easier to deal with, if someone doesn't want to go full GitHub. Possibly you could throw code up on there and share the link with people. In addition to here of course. Just saying, there are options.
kyuuuri
Posts: 340
Joined: 09 Jan 2016, 19:20

Re: MCode4GCC -- C/C++ to MCode Generator

02 May 2020, 06:10

Hello, can a DllCall be converted? Like a dllcall to postmessage, or sendinput
User avatar
joedf
Posts: 8962
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: MCode4GCC -- C/C++ to MCode Generator

03 May 2020, 14:56

You can call winAPI functions with c/c++ then use mcode yes, but for simple postmessage or sendinput, this may not be worth the effort... :think:
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]
robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: MCode4GCC -- C/C++ to MCode Generator

03 Jul 2020, 11:15

How do I go about compiling functions that rely on other functions?

I wrote one function, it works... but if I add a secondary C/C++ function, AHK invokes the wrong one, not the main one.

Code: Select all

int subtraction(int a, int b) {
  int r;
  r=a-b;
  return r;
}

int main(int x, int y) {
  int z;
  z = subtraction(x,y);
  return z;
}
This is just an illustrative code to show what I mean. When i invoke the mcode substraction() is invoked, not main(). I want it to call main().

Thank you .

Best regards, Marius.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.
User avatar
joedf
Posts: 8962
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: MCode4GCC -- C/C++ to MCode Generator

03 Jul 2020, 15:59

Hmmm... since main() is the entrypoint function in C. perhaps it'll work if you use a different name? :think:
Otherwise, perhaps some of other mcode-gurus here could explain? :ugeek: :mrgreen:
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
boiler
Posts: 16963
Joined: 21 Dec 2014, 02:44

Re: MCode4GCC -- C/C++ to MCode Generator

03 Jul 2020, 16:29

What are you doing to try to call main? Naming the variable with the address to the MCode "main"? There is really just one entry point into the code, which is given by the address (see *note below). The name of the variable you use for that address is independent of what the functions inside it are named. You can call it "Hello" or "Bob" and It's still going to call "subtraction" no matter what you name the variable on the outside. Since subtraction is first, that's where the address is pointing to so it calls that.

If I change the order of things and put main first (and have main add 10 to the result so we could see if it really called subtraction and added 10), I get no result. So it seems that you can't call other functions in this manner. If main is the first function and I have it not call the other function, then it does return the expected result. It basically just calls whatever is first and doesn't allow calling other functions (unless someone knows a trick to get it to do that, which would be great).

Code: Select all

int main(int x, int y) {
  int z;
  z = subtraction(x,y);
  return z + 10;
}

int subtraction(int a, int b) {
  int r;
  r=a-b;
  return r;
}
*Note: I'm guessing that if you could figure out the exact memory address where the second function starts, you could call that by adding the right offset to the address, but I still don't think that would allow one function to call the other. It doesn't seem like it's set up to do that.
robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: MCode4GCC -- C/C++ to MCode Generator

03 Jul 2020, 16:57

@boiler .thank you for your reply. Yes, I'm aware I can call the functions any way I want.

It's a weird situation. If I put the secondary function in the code after the main one , such that the main function is the entry point... I get compilation error, saying it's not declared. Hence, to have it compile, I have to put it first. And then, as you said, it becomes the entry point.... Basically, the main (entry point) function cannot call any other function. Am I correct?

Best regards, Marius.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.
User avatar
boiler
Posts: 16963
Joined: 21 Dec 2014, 02:44

Re: MCode4GCC -- C/C++ to MCode Generator

03 Jul 2020, 17:42

Well, I use the online MCode generator, and while it also showed a similar error, it did produce code, unlike other compilation errors that keep it from compiling. But the code didn’t work anyway.

It does look possible, however. See the MCode tutorial by @nnnik where he talks about function pointers.
robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: MCode4GCC -- C/C++ to MCode Generator

04 Jul 2020, 07:05

@boiler .thank you. That seems indeed like a good solution and not too hard to implement.

Best regards, Marius.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.
afe
Posts: 615
Joined: 06 Dec 2018, 04:36

Re: MCode4GCC -- C/C++ to MCode Generator

16 Nov 2020, 11:15

Is it possible to use it to encrypt ahk source code and how to do it?
iseahound
Posts: 1445
Joined: 13 Aug 2016, 21:04
Contact:

Re: MCode4GCC -- C/C++ to MCode Generator

18 Mar 2022, 21:45

Hi @joedf do you have any tips on making the smallest base64 strings? One thing I've noticed is that I name the exact same function myFunc vs main, the myFunc one is generally smaller, even though nothing changes! I think you're stripping out the main part in the asm, which I like. Anyways, thanks for this project. I do wish there was an even more portable version without the gui.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: MCode4GCC -- C/C++ to MCode Generator

19 Mar 2022, 08:32

I think -Os is the size optimisation flag for gcc
iseahound
Posts: 1445
Joined: 13 Aug 2016, 21:04
Contact:

Re: MCode4GCC -- C/C++ to MCode Generator

19 Mar 2022, 09:42

@Helgef

Yes, that seems to do the trick. Haven't seen you around for a while, how have you been?

https://godbolt.org/z/Tfxjnfarn - This is the compiler output I'm seeing after setting the -Os flag. I've had some issues with the compiler flags messing up my code before, so I didn't think to use it. The asm instruction offsets are a bit different on my computer, but it works! Thanks :superhappy:

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: SimmoF and 263 guests