Page 6 of 7
Re: MCode4GCC -- C/C++ to MCode Generator
Posted: 25 Nov 2019, 11:05
by jeeswg
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.)
Re: MCode4GCC -- C/C++ to MCode Generator
Posted: 25 Nov 2019, 15:58
by joedf
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...
EDIT: StringToBinary() broken for XP...
Re: MCode4GCC -- C/C++ to MCode Generator
Posted: 25 Nov 2019, 16:52
by jeeswg
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.
Re: MCode4GCC -- C/C++ to MCode Generator
Posted: 10 Apr 2020, 05:47
by SKAN
@joedf . Nice script! Thanks. I'm studying it extensively
But compilers do write either a 32bit or 64bit exe
Check the target exe instead of the compiler exe
To suppress the error
<Error ignored: undefined reference to 'WinMain'>, I use WinMain() in my c file
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.
Re: MCode4GCC -- C/C++ to MCode Generator
Posted: 10 Apr 2020, 11:53
by joedf
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.
This was the result of a collaborative effort, including code from you.
Re: MCode4GCC -- C/C++ to MCode Generator
Posted: 11 Apr 2020, 19:36
by SKAN
joedf wrote:If you make a pull request, I would be honored to incorporate any changes
and any improvements you make.
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.
Re: MCode4GCC -- C/C++ to MCode Generator
Posted: 12 Apr 2020, 18:58
by joedf
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
Re: MCode4GCC -- C/C++ to MCode Generator
Posted: 12 Apr 2020, 19:11
by SOTE
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.
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.
Re: MCode4GCC -- C/C++ to MCode Generator
Posted: 02 May 2020, 06:10
by kyuuuri
Hello, can a DllCall be converted? Like a dllcall to postmessage, or sendinput
Re: MCode4GCC -- C/C++ to MCode Generator
Posted: 03 May 2020, 14:56
by joedf
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...
Re: MCode4GCC -- C/C++ to MCode Generator
Posted: 03 Jul 2020, 11:15
by robodesign
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.
Re: MCode4GCC -- C/C++ to MCode Generator
Posted: 03 Jul 2020, 15:59
by joedf
Hmmm... since
main() is the entrypoint function in C. perhaps it'll work if you use a different name?
Otherwise, perhaps some of other mcode-gurus here could explain?
Re: MCode4GCC -- C/C++ to MCode Generator
Posted: 03 Jul 2020, 16:29
by boiler
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.
Re: MCode4GCC -- C/C++ to MCode Generator
Posted: 03 Jul 2020, 16:57
by robodesign
@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.
Re: MCode4GCC -- C/C++ to MCode Generator
Posted: 03 Jul 2020, 17:42
by boiler
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.
Re: MCode4GCC -- C/C++ to MCode Generator
Posted: 04 Jul 2020, 07:05
by robodesign
@boiler .thank you. That seems indeed like a good solution and not too hard to implement.
Best regards, Marius.
Re: MCode4GCC -- C/C++ to MCode Generator
Posted: 16 Nov 2020, 11:15
by afe
Is it possible to use it to encrypt ahk source code and how to do it?
Re: MCode4GCC -- C/C++ to MCode Generator
Posted: 18 Mar 2022, 21:45
by iseahound
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.
Re: MCode4GCC -- C/C++ to MCode Generator
Posted: 19 Mar 2022, 08:32
by Helgef
I think -Os is the size optimisation flag for gcc
Re: MCode4GCC -- C/C++ to MCode Generator
Posted: 19 Mar 2022, 09:42
by iseahound
@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