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.)
MCode4GCC -- C/C++ to MCode Generator
Re: MCode4GCC -- C/C++ to MCode Generator
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
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: MCode4GCC -- C/C++ to MCode Generator
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...
So the script seems to be breaking somewhere else...
EDIT: StringToBinary() broken for XP...
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'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.
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
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: MCode4GCC -- C/C++ to MCode Generator
@joedf . Nice script! Thanks. I'm studying it extensively
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.
But compilers do write either a 32bit or 64bit exejoedf wrote: ↑13 Dec 2018, 22:02well here's what it does currentlyhttps://github.com/joedf/MCode4GCC/blob/master/MCode4GCC.ahk#L334-L341Code: 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
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;
}
Let me know if you need a parser for assembly listing file.
Re: MCode4GCC -- C/C++ to MCode Generator
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.
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.
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 don't use GitHub (or know how that stuff works)joedf wrote:If you make a pull request, I would be honored to incorporate any changes and any improvements you make.
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
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
Thanks SKAN
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
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
Hello, can a DllCall be converted? Like a dllcall to postmessage, or sendinput
Re: MCode4GCC -- C/C++ to MCode Generator
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...
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]
-
- Posts: 934
- Joined: 30 Sep 2017, 03:59
- Location: Romania
- Contact:
Re: MCode4GCC -- C/C++ to MCode Generator
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.
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.
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;
}
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.
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.
Re: MCode4GCC -- C/C++ to MCode Generator
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?
Otherwise, perhaps some of other mcode-gurus here could explain?
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
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).
*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.
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;
}
-
- Posts: 934
- Joined: 30 Sep 2017, 03:59
- Location: Romania
- Contact:
Re: MCode4GCC -- C/C++ to MCode Generator
@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.
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.
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.
Re: MCode4GCC -- C/C++ to MCode Generator
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.
It does look possible, however. See the MCode tutorial by @nnnik where he talks about function pointers.
-
- Posts: 934
- Joined: 30 Sep 2017, 03:59
- Location: Romania
- Contact:
Re: MCode4GCC -- C/C++ to MCode Generator
@boiler .thank you. That seems indeed like a good solution and not too hard to implement.
Best regards, Marius.
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.
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.
Re: MCode4GCC -- C/C++ to MCode Generator
Is it possible to use it to encrypt ahk source code and how to do it?
Re: MCode4GCC -- C/C++ to MCode Generator
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
I think -Os is the size optimisation flag for gcc
Re: MCode4GCC -- C/C++ to MCode Generator
@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
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
Return to “Scripts and Functions (v1)”
Who is online
Users browsing this forum: SimmoF and 263 guests