superlazy way of finding struct sizes and offsets

Put simple Tips and Tricks that are not entire Tutorials in this forum
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

superlazy way of finding struct sizes and offsets

Post by swagfag » 22 Jan 2022, 15:39

no ahk required, no downloads required, no external tools required

  • goto compiler explorer www.godbolt.org
  • select the latest available msvc compiler of ur desired bitness
  • paste ur whole struct definition or include the header that contains it(if its a windows/c/c++ standard one)
  • add the compiler switch /d1reportSingleClassLayoutname_of_ur_struct_here
  • check the compiler output logs

    Code: Select all

    example.cpp
    
    class _devicemodeW	size(220):
    	+---
     0	| dmDeviceName
    64	| dmSpecVersion
    66	| dmDriverVersion
    68	| dmSize
    70	| dmDriverExtra
    72	| dmFields
    76	| dmOrientation
    78	| dmPaperSize
    80	| dmPaperLength
    82	| dmPaperWidth
    84	| dmScale
    86	| dmCopies
    88	| dmDefaultSource
    90	| dmPrintQuality
    76	| _POINTL dmPosition
    84	| dmDisplayOrientation
    88	| dmDisplayFixedOutput
    92	| dmColor
    94	| dmDuplex
    96	| dmYResolution
    98	| dmTTOption
    100	| dmCollate
    102	| dmFormName
    166	| dmLogPixels
    168	| dmBitsPerPel
    172	| dmPelsWidth
    176	| dmPelsHeight
    180	| dmDisplayFlags
    180	| dmNup
    184	| dmDisplayFrequency
    188	| dmICMMethod
    192	| dmICMIntent
    196	| dmMediaType
    200	| dmDitherType
    204	| dmReserved1
    208	| dmReserved2
    212	| dmPanningWidth
    216	| dmPanningHeight
    	+---
    Compiler returned: 0

cons: doesnt fare too well with byvalue included nested structs, so ull have to crunch some numbers in ur head. also, cant use aliased struct names, need to specify the true name(alternatively, dump everything with /d1reportAllClassLayout and ctrl+f the name of some field and ull probably find it, but it takes longer for the output to be generated so it may timeout)
Last edited by swagfag on 23 Jan 2022, 07:57, edited 1 time in total.

iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: superlazy way of finding struct sizes and offsets

Post by iseahound » 22 Jan 2022, 23:23

sample code to paste into the compiler? Also this is really nice for viewing the assembly instructions, I'll stop decompiling now LOL

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: superlazy way of finding struct sizes and offsets

Post by swagfag » 23 Jan 2022, 07:56

eg

Code: Select all

#include "Windows.h"
and /d1reportSingleClassLayout_devicemode
https://www.godbolt.org/z/so7x1K7cb

iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: superlazy way of finding struct sizes and offsets

Post by iseahound » 26 Jan 2022, 11:35

Excellent. I see that the class name is case sensitive and has to be exactly identical to what's behind typedef struct i.e. tagDIBSECTION instead of DIBSECTION

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: superlazy way of finding struct sizes and offsets

Post by swagfag » 26 Jan 2022, 11:40

yeah, aliases wont do, u need to use the structs true name(or at the very least some exact beginning part of it)

User avatar
cyruz
Posts: 346
Joined: 30 Sep 2013, 13:31

Re: superlazy way of finding struct sizes and offsets

Post by cyruz » 14 Dec 2022, 17:49

Cool. This is a timesaver :beer:
ABCza on the old forum.
My GitHub.

Post Reply

Return to “Tips and Tricks”