Structor - Get the Offsets of Structures

Discuss the AutoGUI IDE with a GUI designer and a script editor.
User avatar
Alguimist
Posts: 135
Joined: 05 Oct 2015, 16:41

Structor - Get the Offsets of Structures

13 May 2017, 04:25

Image

Structor retrieves the 32 and 64-bit offsets of structures and generates AHK code. It was inspired on Lexicos' StructParser.

The Parse button (F9) performs the following actions: parse the structure, generate C code, compile, run and get the offsets from stdout.

The Copy button generates the AHK code and copy it to the clipboard.

Given the input:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


The generated code for NumPut is:

Code: [Select all] [Download] GeSHi © Codebox Plus

VarSetCapacity(TBBUTTON, A_PtrSize == 8 ? 32 : 20, 0)

NumPut(iBitmap, TBBUTTON, 0, "Int")
NumPut(idCommand, TBBUTTON, 4, "Int")
NumPut(fsState, TBBUTTON, 8, "UChar")
NumPut(fsStyle, TBBUTTON, 9, "UChar")
NumPut(bReserved, TBBUTTON, 10, "UChar")
;NumPut(bReserved, TBBUTTON, 10, "UChar")
NumPut(dwData, TBBUTTON, A_PtrSize == 8 ? 16 : 12, "UPtr")
NumPut(iString, TBBUTTON, A_PtrSize == 8 ? 24 : 16, "Ptr")

Another example:

Code: [Select all] [Download] GeSHi © Codebox Plus

typedef struct _SHFILEINFO {
HICON hIcon;
int iIcon;
DWORD dwAttributes;
TCHAR szDisplayName[MAX_PATH];
TCHAR szTypeName[80];
} SHFILEINFO;

Hold Shift while pressing the Copy button for a short 32/64-bit ternary.

Code: [Select all] [Download] GeSHi © Codebox Plus

x64 := A_PtrSize == 8
VarSetCapacity(SHFILEINFO, x64 ? 696 : 692, 0)

hIcon := NumGet(SHFILEINFO, 0, "Ptr")
iIcon := NumGet(SHFILEINFO, x64 ? 8 : 4, "Int")
dwAttributes := NumGet(SHFILEINFO, x64 ? 12 : 8, "UInt")
szDisplayName := StrGet(&SHFILEINFO + (x64 ? 16 : 12), 260, "UTF-16")
szTypeName := StrGet(&SHFILEINFO + (x64 ? 536 : 532), 80, "UTF-16")

Requirements
♦ Microsoft C/C++ compiler (Visual Studio, Windows SDK) or GCC (MinGW, TDM-GCC)

:arrow: Download (AutoGUI tools)
User avatar
evilC
Posts: 3546
Joined: 27 Feb 2014, 12:30

Re: Structor - Get the Offsets of Structures

13 May 2017, 07:53

Awesome, I tried to do basically the same thing with AHK-SizeOf-Checker, but it was nowhere near as good as this.
Those auto-generated 32/64 bit ternarys are so sweet :)

This needs to be linked from the DllCall docs page IMHO, it won't get the exposure it deserves buried away in here.

By the way, I see no integration with AutoGui - I have to launch it by just running Structor.ahk. Is this normal?
Not a huge issue for me, I like being able to launch it directly.
User avatar
evilC
Posts: 3546
Joined: 27 Feb 2014, 12:30

Re: Structor - Get the Offsets of Structures

13 May 2017, 08:15

I cannot get it to work properly with the various RAWINPUT structs
https://msdn.microsoft.com/en-us/librar ... 62(v=vs.85).aspx
I added winuser.h, but compilation still fails
It is a struct of structs, I just wanted to see if it could handle it...

RAWINPUTHEADER, RAWKEYBOARD, RAWMOUSE, RAWHID all seem to fail compilation for 32 or 64-bit.

It may be worth noting that my settings do not have a "batch file" setting for 64-bit. I do not appear to have a 64-bit equivalent to vcvars32.bat on my disk.
User avatar
Alguimist
Posts: 135
Joined: 05 Oct 2015, 16:41

Re: Structor - Get the Offsets of Structures

14 May 2017, 03:44

evilC wrote:I see no integration with AutoGui - I have to launch it by just running Structor.ahk.

This tool (and Size Checker) will not be added to the default Tools.ini because they are not ready-to-use for most users. But they can be easily configured in Add/Remove Tools (last item of the Tools menu).

evilC wrote:I cannot get it to work properly with the various RAWINPUT structs

It works with similar structures such as INPUT and RID_DEVICE_INFO, but not with RAWINPUT. I couldn't determine the reason. As a workaround, modify the declaration of RAWINPUT to use the name of the union as member:

Code: [Select all] [Download] GeSHi © Codebox Plus

typedef struct tagRAWINPUT {
RAWINPUTHEADER header;
RAWMOUSE data;
} RAWINPUT, *PRAWINPUT, *LPRAWINPUT;

And then check the offsets of the nested structures individually.

evilC wrote:It may be worth noting that my settings do not have a "batch file" setting for 64-bit. I do not appear to have a 64-bit equivalent to vcvars32.bat on my disk.

Try the file vcvarsx86_amd64.bat from the x86_amd64 folder.
sancarn
Posts: 189
Joined: 01 Mar 2016, 14:52

Re: Structor - Get the Offsets of Structures

02 Aug 2017, 04:21

Would be cool if such a tool didn't require installing GCC on your computer. Some of us have to deal with IT policies...

As a work around one can use the following website

I ran a test example and the headers default headers are:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



This message is sent to the URL http://rextester.com/rundotnet/Run via a POST request.

The response is a JSON string.

Code: [Select all] [Download] GeSHi © Codebox Plus

{
"Warnings": null,
"Errors": null,
"Result": "Hello, world!\n",
"Stats": "Compilation time: 0.13 sec, absolute running time: 0.09 sec, cpu time: 0.03 sec, memory peak: 3 Mb, absolute service time: 0,23 sec",
"Files": null
}


I've been trying to intergrate it into the script for the past hour but currently to no success. I have found that the site itself runs the code with the following:

Code: [Select all] [Download] GeSHi © Codebox Plus

$.post('/rundotnet/Run', $("#mainForm").serialize(),function(s){console.log(s)})


But we should be able to make the HTTP Request directly from AHK.
User avatar
Alguimist
Posts: 135
Joined: 05 Oct 2015, 16:41

Re: Structor - Get the Offsets of Structures

02 Aug 2017, 15:49

sancarn wrote:rextester.com RESTful API

Set the compiler to VC x64 (LanguageChoice 29) with CompilerArgs source_file.c -o a.exe.
sancarn
Posts: 189
Joined: 01 Mar 2016, 14:52

Re: Structor - Get the Offsets of Structures

02 Aug 2017, 19:38

Alguimist wrote:
sancarn wrote:rextester.com RESTful API

Set the compiler to VC x64 (LanguageChoice 29) with CompilerArgs source_file.c -o a.exe.


Thanks for that,

I finally figured out how to use WinHttp.WinHttpRequest COM Object... If you need sample code to integrate it with your program I have the code I used here:

https://github.com/sancarn/Small_AHK_Pr ... e-c-online

You can probably come up with better code though... For now I'm just happy I cracked it. Now, i need sleep!

Return to “AutoGUI”

Who is online

Users browsing this forum: No registered users and 1 guest