Page 1 of 1

superlazy way of finding struct sizes and offsets

Posted: 22 Jan 2022, 15:39
by swagfag
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)

Re: superlazy way of finding struct sizes and offsets

Posted: 22 Jan 2022, 23:23
by iseahound
sample code to paste into the compiler? Also this is really nice for viewing the assembly instructions, I'll stop decompiling now LOL

Re: superlazy way of finding struct sizes and offsets

Posted: 23 Jan 2022, 07:56
by swagfag
eg

Code: Select all

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

Re: superlazy way of finding struct sizes and offsets

Posted: 26 Jan 2022, 11:35
by iseahound
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

Re: superlazy way of finding struct sizes and offsets

Posted: 26 Jan 2022, 11:40
by swagfag
yeah, aliases wont do, u need to use the structs true name(or at the very least some exact beginning part of it)

Re: superlazy way of finding struct sizes and offsets

Posted: 14 Dec 2022, 17:49
by cyruz
Cool. This is a timesaver :beer: