Structor - Get the Offsets of Structures

Old Topics related to the original "AutoGUI" ahk script editor.
User avatar
Alguimist
Posts: 428
Joined: 05 Oct 2015, 16:41
Contact:

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 Compile 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

typedef struct {
  int       iBitmap;
  int       idCommand;
  BYTE      fsState;
  BYTE      fsStyle;
#ifdef _WIN64
  BYTE      bReserved[6];
#else 
#if defined(_WIN32)
  BYTE      bReserved[2];
#endif 
#endif 
  DWORD_PTR dwData;
  INT_PTR   iString;
} TBBUTTON, *PTBBUTTON, *LPTBBUTTON;
The generated code for NumPut is:

Code: Select all

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

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

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)

EDIT: postimg.org changed domain to postimg.cc.
Last edited by Alguimist on 19 Aug 2019, 19:43, edited 2 times in total.
User avatar
evilC
Posts: 4822
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: 4822
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 ... s.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: 428
Joined: 05 Oct 2015, 16:41
Contact:

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

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: 224
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

LanguageChoiceWrapper:6
EditorChoiceWrapper:1
Program:`//gcc 5.4.0

#include  <stdio.h>

int main(void)
{
    printf("Hello, world!\n");
    return 0;
}`
CompilerArgs:-Wall -std=gnu99 -O2 -o a.out source_file.c
Input:
ShowWarnings:false
Privacy:
PrivacyUsers:
Title:
SavedOutput:
WholeError:
WholeWarning:
StatsToSave:
CodeGuid:
IsInEditMode:False
IsLive:False
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

{
  "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

$.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: 428
Joined: 05 Oct 2015, 16:41
Contact:

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: 224
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!
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: Structor - Get the Offsets of Structures

06 Dec 2019, 03:02

Hey Alguimist,

in e.g. Structor you use the old Gradient function (ApplyGradient / CreateDIB), but it is broken on Windows 10.

You should use the rewritten (thx to 'just me') function CreateGradient for Windows 7 - Windows 10.

Code: Select all

CreateGradient(handle, width, height, colors*) 
{
	size := VarSetCapacity(bits, (ClrCnt := colors.MaxIndex()) * 2 * 4, 0)
	addr := &bits
	for each, color in colors
		addr := NumPut(color, NumPut(color, addr + 0, "uint"), "uint")
	hBitmap := DllCall("CreateBitmap", "int", 2, "int", ClrCnt, "uint", 1, "uint", 32, "ptr", 0, "ptr")
	hBitmap := DllCall("CopyImage", "ptr", hBitmap, "uint", 0, "int", 0, "int", 0, "uint", 0x2008, "ptr")
	DllCall("SetBitmapBits", "ptr", hBitmap, "uint", size, "ptr", &bits)
	hBitmap := DllCall("CopyImage", "ptr", hBitmap, "uint", 0, "int", width, "int", height, "uint", 0x2008, "ptr")
	DllCall("SendMessage", "ptr", handle, "uint", 0x0172, "ptr", 0, "ptr", hBitmap, "ptr")
	return true
}
Sample usage

Code: Select all

Gui, Add, Text, xm ym w151 h27 0xE hwndhGrad
CreateGradient(hGrad, 151, 27, 0x6A6A6A, 0x141414)
greets
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
User avatar
Alguimist
Posts: 428
Joined: 05 Oct 2015, 16:41
Contact:

Re: Structor - Get the Offsets of Structures

11 Jun 2020, 15:16

Hello, jNizM :)

I tested Structor on Windows 10 and the gradient function is working fine. The function you posted, on the other hand, doesn't seem to be working as expected: it simply creates a bitmap with the two colors as separate blocks, without the gradient transition between them.
JMPSequeira
Posts: 7
Joined: 08 Nov 2021, 19:04

Re: Structor - Get the Offsets of Structures

02 Feb 2022, 18:00

Hey,

I'm a noob when talking about c++ and the likes, I'm writing here to ask any of you to which files should I point the 64 compilation.

I've downloaded tmd-gcc-64 and installed it but I'm clueless as to which files do what.

Thanks
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Structor - Get the Offsets of Structures

03 Feb 2022, 09:59

JMPSequeira wrote:
02 Feb 2022, 18:00
I'm a noob when talking about c++ and the likes, I'm writing here to ask any of you to which files should I point the 64 compilation.

I've downloaded tmd-gcc-64 and installed it but I'm clueless as to which files do what.
You should have 2 folders; TDMGCC32 and TDMGCC64. In both folders you will have; bin (a folder where gcc.exe is at) and mingwvars.bat.
In the settings of Structor you would input both locations (compiler path and batch file) to the files.
JMPSequeira
Posts: 7
Joined: 08 Nov 2021, 19:04

Re: Structor - Get the Offsets of Structures

03 Feb 2022, 10:15

SOTE wrote:
03 Feb 2022, 09:59
JMPSequeira wrote:
02 Feb 2022, 18:00
I'm a noob when talking about c++ and the likes, I'm writing here to ask any of you to which files should I point the 64 compilation.

I've downloaded tmd-gcc-64 and installed it but I'm clueless as to which files do what.
You should have 2 folders; TDMGCC32 and TDMGCC64. In both folders you will have; bin (a folder where gcc.exe is at) and mingwvars.bat.
In the settings of Structor you would input both locations (compiler path and batch file) to the files.
Worked Like a charm. Many thanks
neogna2
Posts: 586
Joined: 15 Sep 2016, 15:44

Re: Structor - Get the Offsets of Structures

06 Feb 2022, 09:47

Worth giving an example of the paths the settings expects. This worked for me for TDM-GCC x64
Compiler path: C:\TDM-GCC-64\bin\gcc.exe
Batch file path: C:\TDM-GCC-64\mingwvars.bat

The converted AHK output is for v1 only. But it seems like we can add in v2 output support with these changes. It would be good if someone who knows this better checks my suggested changes below and points out any errors.

L39, L296 and so on is the line number of Structor.ahk from Adventure-3.0.4.zip before making any edits to the file.

add after L39

Code: Select all

Gui Add, CheckBox, vV2 x308 y225 w46 h23 +Checked%V2%, &V2
GuiControl % "Enable", V2
change L296 to

Code: Select all

if !V2
    Cap .= "VarSetCapacity(" . StructName . ", " . Condition . StructSize . ", 0)"
else
    Cap .= StructName . " := Buffer(" Condition . StructSize . ", 0)"
change L365 to

Code: Select all

if !V2
    Put .= u . "NumPut(" . Prefix . A_LoopField . ", " . StructName . ", " . Offset . ", ""Int"")`r`n"
else
    Put .= u . "NumPut(""Int"", " . Prefix . A_LoopField . ", " . StructName . ", " . Offset . ")`r`n"
change L392 to

Code: Select all

if !V2
    Put .= "StrPut(" . Member . ", &" . StructName . " + " . Offset . ", " . Length . ", ""UTF-16"")`r`n"
else
    Put .= "StrPut(" . Member . ", " . StructName . "Ptr + " . Offset . ", ""UTF-16"")`r`n"
change L394 to

Code: Select all

if !V2
    Put .= u . "NumPut(" . Member . ", " . StructName ", " . Offset . ", """ . AHKType . """)`r`n"
else
    Put .= u . "NumPut(""" . AHKType . """, " . Member . ", " . StructName ", " . Offset . ")`r`n"
edit: fixed v2 StrPut line to use syntax StructName.Ptr + Offset
Qriist
Posts: 81
Joined: 11 Sep 2016, 04:02

Re: Structor - Get the Offsets of Structures

15 Apr 2022, 12:14

Hiya! I'm having some difficulty compiling, well, anything.

Here's one of the example structs from the first post:
image.png
image.png (63.22 KiB) Viewed 4951 times
I have set the file paths (I set a custom directory, but these are correct)
image.png
image.png (45.95 KiB) Viewed 4951 times
I have confirmed these directories are in my path
image.png
image.png (95.42 KiB) Viewed 4951 times
So... what troubleshooting steps can I take to try to fix this? Please and thank you! :)
tuzi
Posts: 223
Joined: 27 Apr 2016, 23:40

Re: Structor - Get the Offsets of Structures

19 Apr 2022, 02:43

hi everyone.
i create a Modified Version.

The difference between original and modified is
  • Fix some bugs.
  • Enhanced type recognition.
  • DO NOT NEED install VS2022 and WINDOWS SDK!
    DO NOT NEED setting by yourself.
    It is portable and easy to use now!
and always thanks Alguimist! :D :D :D

Return to “Old Topics”

Who is online

Users browsing this forum: No registered users and 18 guests