Page 1 of 1
Structor - Get the Offsets of Structures
Posted: 13 May 2017, 04:25
by Alguimist
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)
Download (AutoGUI tools)
EDIT: postimg.org changed domain to postimg.cc.
Re: Structor - Get the Offsets of Structures
Posted: 13 May 2017, 07:53
by evilC
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.
Re: Structor - Get the Offsets of Structures
Posted: 13 May 2017, 08:15
by evilC
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.
Re: Structor - Get the Offsets of Structures
Posted: 14 May 2017, 03:44
by Alguimist
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.
Re: Structor - Get the Offsets of Structures
Posted: 02 Aug 2017, 04:21
by sancarn
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.
Re: Structor - Get the Offsets of Structures
Posted: 02 Aug 2017, 15:49
by Alguimist
sancarn wrote:rextester.com RESTful API
Set the compiler to VC x64 (LanguageChoice 29) with CompilerArgs
source_file.c -o a.exe.
Re: Structor - Get the Offsets of Structures
Posted: 02 Aug 2017, 19:38
by sancarn
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!
Re: Structor - Get the Offsets of Structures
Posted: 06 Aug 2018, 03:49
by tmplinshi
Thanks!
Re: Structor - Get the Offsets of Structures
Posted: 06 Dec 2019, 03:02
by jNizM
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
Re: Structor - Get the Offsets of Structures
Posted: 11 Jun 2020, 15:16
by Alguimist
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.
Re: Structor - Get the Offsets of Structures
Posted: 02 Feb 2022, 18:00
by JMPSequeira
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
Re: Structor - Get the Offsets of Structures
Posted: 03 Feb 2022, 09:59
by SOTE
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.
Re: Structor - Get the Offsets of Structures
Posted: 03 Feb 2022, 10:15
by JMPSequeira
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
Re: Structor - Get the Offsets of Structures
Posted: 06 Feb 2022, 09:47
by neogna2
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
Re: Structor - Get the Offsets of Structures
Posted: 15 Apr 2022, 12:14
by Qriist
Hiya! I'm having some difficulty compiling, well, anything.
Here's one of the example structs from the first post:
- image.png (63.22 KiB) Viewed 7901 times
I have set the file paths (I set a custom directory, but these are correct)
- image.png (45.95 KiB) Viewed 7901 times
I have confirmed these directories are in my path
- image.png (95.42 KiB) Viewed 7901 times
So... what troubleshooting steps can I take to try to fix this? Please and thank you!
Re: Structor - Get the Offsets of Structures
Posted: 19 Apr 2022, 02:43
by tuzi
hi everyone.
i create a
Modified Version.
The difference between original and modified is
- 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!