Sign in to follow this  
Followers 0
Ascend4nt

_DLLStructDisplay - Show Struct in ListView

14 posts in this topic

#1 ·  Posted (edited)

_DLLStructDisplay

Posted Image

While working on debugging a project a while back, I was looking for better ways to debug the code. And voila, here it is.

Anyway, this function displays the contents of your DLLStruct's in a ListView format (placing the items in an array and utilizing _ArrayDisplay).

IMPORTANT: You must supply the string EXACTLY as it was used to set up the structure (although you can add descriptions after the datatypes if they aren't already there). The string requirement might seem like one more extra step, but without it the function wouldn't work (and you're debugging would be much harder).

The code is smart enough to split items into subitems (based on [#]'s found), and will display the description with {sub item #x}).

Also - the behaviour with GINORMOUS pieces of data is unknown - this is best used with smaller structures!

NOTE: One thing you might notice about structures is alignment has alot to do with where items are placed in the structure. The default is '8', which means that everything is aligned on a boundary equally divisible by itself (char being 1 byte is aligned anywhere, int's being 4 bytes, are aligned on offsets divisible by 4, double's and int64's both are aligned on offsets equally divisible by 8)

HOWEVER: a prefix of 'align ##' can change this behavior so that the data can be 'misaligned' so to speak, to the specified alignment # (see AutoIT Help info for DLLStructCreate)

Update Log:

5/27/2011: Small fixes, ability to use multiple 'align' directives

Fixed: initial 'align (##);' check code failed in certain circumstances (align on its own, spaces after #)

Fixed: 'char' & 'byte' can now be part of description of all array objects

Added/Fixed: 'align (##);' can now appear anywhere in a structure, now properly handled (extra ones are reported in display)

5/26/2011: Updated to new structure alignment directives (as of AutoIt v3.3.7.2beta)

Added: Structure size information, End-of-Structure Padding Info

Added: Struct/EndStruct support, these show up in list with C-style curly braces { };

3/18/2010: Updated to all new supported types as of AutoIT v3.3.6.0

Added: Index, Offset, Size Columns, Base Pointer & Alignment Type info (in Title Bar and in 'Offset' column)

Fixed: subitem listings, items with labels, alignment override being read as a type, subitem offsets, fixed case-sensitivity

Adjusted: stripped unnecessary whitespace, added options to display Strings (char[#]/wchar[#]) and Binary string data (ubyte[#],byte[#]) as one concatenated string

Download the ZIP Here

Ascend4nt's AutoIT Code License agreement:

While I provide this source code freely, if you do use the code in your projects, all I ask is that:

  • If you provide source, keep the header as I have put it, OR, if you expand it, then at least acknowledge me as the original author, and any other authors I credit
  • If the program is released, acknowledge me in your credits (it doesn't have to state which functions came from me, though again if the source is provided - see #1)
  • The source on it's own (as opposed to part of a project) can not be posted unless a link to the page(s) where the code were retrieved from is provided and a message stating that the latest updates will be available on the page(s) linked to.
  • Pieces of the code can however be discussed on the threads where Ascend4nt has posted the code without worrying about further linking.
Edited by Ascend4nt

Share this post


Link to post
Share on other sites

#2 ·  Posted (edited)

Heh I made something similar for a long time ago, forgot to post it :(

Anyways, it looks good & useful. However my thoughts:

  • Using for example "align 2;" should not show up as a data type
  • Possible trailing and leading spaces should be removed, it looks funny in the listview.
  • Definitely needs to display the pointer to the struct somewhere, this will serve as a double purpose since it will display '0' of the struct is invalid
  • Maybe show arrays of type byte/char/wchar in binary/string in a single listview element?
Other than that it works fine >_<

Edit:

To calculate correct offset you can use DllStructGetPtr() with the element paramater. Array elements will always be placed next to eachother in the array.

Edited by monoceres

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Excellent learning tool.

I must say thank you, I have learned a lot from your code over the months.

I now understand things I never even learnt.

Share this post


Link to post
Share on other sites

@Monoceres: Thanks for the ideas - I will implement some of them, maybe some as bool parameters. As for calculating the offset, I had tried to use an element index, but then found out there's only a pointer to the element (so pointers to individual items in [#] can't be gotten).

I'm going to just use a type-size translation array or even a string with StringRegExp to see which would be faster to get the actual size of each item (hmm..gotta take into account size differences with @AutoItX64)

@dmob: Thanks for the compliment >_< , I'm glad I've been of help.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Updated! Hopefully this satisfies the needs of most. (This also fixes some issues). Changes (since last time):

Fixes:

  • Fixed items with label descriptions
  • Fixed alignment-override being read as a data-type
  • Fixed subitem offset info
Additions:

  • Added DLL Struct 'Base pointer' info (in Title bar & 'Offset' column description)
  • Added Alignment info (in Title bar & 'Offset' column description)
  • Stripped whitespace from Struct Type/descriptions (except where needed for Labels and subitem info)
  • Added parameter option to display multi-character strings (char[#]/wchar[#]) as one concatenated string (default behavior)
  • Added parameter option to display multi-byte Binary strings (ubyte[#],byte[#]) as one concatenated string (not default behavior)
  • *edit* Also added 'Size' column (which is also properly adjusted for x86 or x64 mode)
Anyways, have a look. Hopefully this should make everyone happy. >_<

Edited by Ascend4nt

Share this post


Link to post
Share on other sites

Okay, last change (I hope!). I've added an 'Index' column, because those sub-items can make it a bit confusing if you're trying to remember which index to use as the base index into the Structure. (the sub-item # is the sub-index)

Th-th-th-thats all >_<

Share this post


Link to post
Share on other sites

Excellent! Very useful thing.

Was missing it and also was too lazy to write it and I knew some day someone would and I'll just say thanks.

So, thanks.

Btw, I see you don't use Opt("MustDeclareVars", 1). Everyone should. And tidy.exe, and #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 4 -w 5 -w 6 and ...actually nothing more >_<


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Excellent! Very useful thing.

Was missing it and also was too lazy to write it and I knew some day someone would and I'll just say thanks.

So, thanks.

You're welcome :( Now someone should create a tool to test, mess around with, and create your own DLLStructs.

:( erm, hey, why are you looking at me. I'm not a GUI guy da*it!

*walks off mumbling about too many projects on my mind* >_<

Share this post


Link to post
Share on other sites

I'm back. Code has been updated, latest edit:

*edits: 3/18/2010: Updated to all new supported types as of AutoIT v3.3.6.0

Share this post


Link to post
Share on other sites

New updates (works with latest beta changes!):

5/26/2011: Updated to new structure alignment directives (as of AutoIt v3.3.7.2beta)

Added: Structure size information, End-of-Structure Padding Info

Added: Struct/EndStruct support, these show up in list with C-style curly braces { };

Share this post


Link to post
Share on other sites

Updated again. Didn't know about the ability to use multiple 'align' directives in a structure, now I do! So here's a version that works with those structures (plus a bugfix or 2):

5/27/2011: Small fixes, ability to use multiple 'align' directives

Fixed: initial 'align (##);' check code failed in certain circumstances (align on its own, spaces after #)

Fixed: 'char' & 'byte' can now be part of description of all array objects

Added/Fixed: 'align (##);' can now appear anywhere in a structure, now properly handled (extra ones are reported in display)

Share this post


Link to post
Share on other sites

I have changed for my personal use:

113 ; $aStDisplay[0][0]="Index"
114 ; $aStDisplay[0][1]="DLL Struct Type + Description (optional)"
115 ; $aStDisplay[0][2]="Value"
116 ; $aStDisplay[0][3]="Offset [Base Ptr="&$iBaseAddress&", Alignment="&$iAlign&" [Base], Size="&$iStrSize&']'
117 ; $aStDisplay[0][4]="Size [Total="&$iStrSize&']'
118
119 $iDispIndex=0
...
224  _ArrayDisplay($aStDisplay,"DLLStruct"&$sStructName&" Contents [Base Ptr="&$iBaseAddress&", Alignment="&$iAlign&", Size="&$iStrSize&']',-1,0,"","|", _
225  "Row|Index|DLL Struct Type + Description (optional)|Value|Offset [Base Ptr="&$iBaseAddress&", Alignment="&$iAlign&" [Base], Size="&$iStrSize&"]|Size [Total="&$iStrSize&']')

AutoIt-Syntaxsheme for Proton & Phase5 * Firefox Addons by me (resizable Textarea 0.1d) (docked JS-Console 0.1.1)

Share this post


Link to post
Share on other sites

Return=False
@Error=0

@Extended=0

using it to read $tSTARTUPINFO struct from the RunBiinary UDF from trancexx

 


What is what? What is what.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • c.haslam
      By c.haslam
      cDebug.au3 includes four main debugging UDFs: _GuiDebug(), _ConsDebug(), _ClipDebug() and _FormatValsForDebug(). They all dump the values of all AutoIt subtypes and expressions, in a structured manner, including nested arrays and slices of them, and even DLL structs and maps. It is an alternative to a graphical debugger, offering GUI output.
      The format for calling the UDFs has been designed to make coding a call as convenient and fast as possible, minimizing coding effort and the chances of errors: the $name argument is often the same as the variables arguments, enclosed in quote marks.
      For DLL structures, if you specify a tag, cDebug checks for differences between it and what it detects. If you only specify a structure variable, it can report the structure it detects, with the values of elements.
      It does its best to avoid hiding your code in SciTE.
      #include cDebug.au3 at the top of your script.
      It is fully documented in cDebug.pdf .  During debugging and development of new features, the current version is used to debug the upcoming version, so there is much testing, even so the may be some bugs, particularly in new features, such as reporting on DLL structures and maps. Bug reports and suggestions are welcome.
      These UDFs have been in regular use for some years. Suggestions and bug reports are most welcome.
      Because cDebug reports maps, it requires AutoIt 3.3.15.0 or later.
      A teaser
      This script:
      #AutoIt3Wrapper_Version=B ; beta 3.3.15.0 or greater is mandatory #include "cDebug devel.au3" Local $seasons[] $seasons.summer = 'May to September' $seasons.spring = 'April' $seasons.fall = 'October to November' $seasons.winter = 'December to March' Local $aCats[3][3] = [['jack','black',3],['suki','grey',4],[$seasons,'','']] Local $i = 1 Local $tStruct = DllStructCreate('uint') DllStructSetData($tStruct,1,2018) _GuiDebug('At line '&@ScriptLineNumber,'$cats,jack is,$cats[..][$i],$i,hex,structure{uint}', _ $aCats,$aCats[0][2],$aCats,$i,Hex(-$i),$tstruct) produces:

       
      Edit history
      See documentation PDF
      Acknowledgements
      Melba23, Kafu, ProgAndy, jchd
    • c.haslam
      By c.haslam
      cDebug.au3 includes four main debugging UDFs: _GuiDebug(), _ConsDebug(), _ClipDebug() and _FormatValsForDebug(). They all dump the values of all AutoIt subtypes and expressions, in a structured manner, including nested arrays and slices of them, and even DLL structs. It is an alternative to a graphical debugger, offering GUI output.
      The format for calling the UDFs has been designed to make coding a call as convenient and fast as possible, minimizing coding effort and the chances of errors: the $name argument is often the same as the variables arguments, enclosed in quote marks.
      For DLL structures, if you specify a tag, cDebug checks for differences between it and what it detects. If you only specify a structure variable, it can report the structure it detects, with the values of elements.
      It does its best to avoid hiding your code in SciTE.
      #include cDebug.au3 at the top of your script.
      It is fully documented.  During development of new features, the current version is used to debug the upcoming version, so there is much testing.
      These UDFs have been in regular use for some years. Suggestions and bug reports are most welcome.
      Get the latest version in Example Scripts
      ##AutoIt3Wrapper_Version=B ; beta 3.3.15.0 or greater is mandatory #include "cDebug devel.au3" Local $seasons[] $seasons.summer = 'May to September' $seasons.spring = 'April' $seasons.fall = 'October to November' $seasons.winter = 'December to March' Local $aCats[3][3] = [['jack','black',3],['suki','grey',4],[$seasons,'','']] Local $i = 1 Local $tStruct = DllStructCreate('uint') DllStructSetData($tStruct,1,2018) _GuiDebug('At line '&@ScriptLineNumber,'$cats,jack is,$cats[..][$i],$i,hex,structure{uint}', _ $aCats,$aCats[0][2],$aCats,$i,Hex(-$i),$tstruct) reports

         
    • c.haslam
      By c.haslam
      At least illogical to me!
      The following script is based on a script jchd wrote. I have changed it so it returns a tag rather than writing the element types and values to the Console. The tag and the values set in the structure are those he used.
      As is, it returns "char;". It should return "char[3]; ...'. With changes in the diagnostic code, I have seem it return "char[3];", but it should return the whole tag.
      I am aware that the script will not differentiate, for example, between an int and a long: it works from the type of what DllStructGetData returns, and calls it an int.
      I am concerned that there may be a memory leak due to a DLLStruct* call, because the code, with minor variations, produces different results.
      I have instrumented it liberally, but @error is 0 everywhere.
      Clues will be most welcome!
      Local $tag = "char a[3];handle b[3];uint c[35];byte d[128];wchar e[190000]; double f[3];int64 g[3];" & _ "char h[3];float i;double j;byte k;ubyte l;short m;ushort n;int o;uint p;char q" Local $struct = DllStructCreate($tag) If @error Then MsgBox(0,@ScriptLineNumber,@error) DllStructSetData($struct, 1, 'sos') If @error Then MsgBox(0,@ScriptLineNumber,@error) DllStructSetData($struct, 2, Ptr(123456789)) If @error Then MsgBox(0,@ScriptLineNumber,@error) DllStructSetData($struct, 3, 8, 1) If @error Then MsgBox(0,@ScriptLineNumber,@error) DllStructSetData($struct, 3, 0x87654321, 2) If @error Then MsgBox(0,@ScriptLineNumber,@error) DllStructSetData($struct, 3, 256, 5) If @error Then MsgBox(0,@ScriptLineNumber,@error) DllStructSetData($struct, 4, Binary('sos')) If @error Then MsgBox(0,@ScriptLineNumber,@error) DllStructSetData($struct, 5, 'gno' & @CRLF & 'ji' & @TAB & 'o') If @error Then MsgBox(0,@ScriptLineNumber,@error) DllStructSetData($struct, 6, 3.1415926, 2) If @error Then MsgBox(0,@ScriptLineNumber,@error) DllStructSetData($struct, 7, 17, 1) If @error Then MsgBox(0,@ScriptLineNumber,@error) DllStructSetData($struct, 7, -1, 2) DllStructSetData($struct, 8, 'end') If @error Then MsgBox(0,@ScriptLineNumber,@error) DllStructSetData($struct, 9, 2.7182818284590452353602874713527) If @error Then MsgBox(0,@ScriptLineNumber,@error) DllStructSetData($struct, 10, 2.7182818284590452353602874713527) If @error Then MsgBox(0,@ScriptLineNumber,@error) DllStructSetData($struct, 11, 107) If @error Then MsgBox(0,@ScriptLineNumber,@error) DllStructSetData($struct, 12, -108) If @error Then MsgBox(0,@ScriptLineNumber,@error) DllStructSetData($struct, 13, 109) If @error Then MsgBox(0,@ScriptLineNumber,@error) DllStructSetData($struct, 14, 110) If @error Then MsgBox(0,@ScriptLineNumber,@error) DllStructSetData($struct, 15, 111) If @error Then MsgBox(0,@ScriptLineNumber,@error) DllStructSetData($struct, 16, 112) If @error Then MsgBox(0,@ScriptLineNumber,@error) _cDebug_DetectStructElements($struct) Func _cDebug_DetectStructElements($tStruct) Local $retTag Local $len = DllStructGetSize($tStruct) Local $ptr = DllStructGetPtr($tStruct) Local $nbElem = 1, $idx, $incr, $data, $type, $oldvalue, $readvalue, $elem $g_CDebug_sStructElementTypes = '' While 1 $data = DllStructGetData($tStruct, $nbElem) If @error And @error<>2 Then MsgBox(0,@ScriptLineNumber,@error) If @error = 2 Then ExitLoop ; if element out of range or unknown $type = VarGetType($data) $idx = 1 $incr = 0 ; determine max index of element While 1 DllStructGetData($tStruct, $nbElem, 2 * $idx) If @error And @error<>3 Then MsgBox(0,@ScriptLineNumber,@error) If @error = 3 Then ExitLoop $incr = $idx $idx *= 2 WEnd ; index is in [$idx, (2 * $idx) - 1] $idx += $incr Do DllStructGetData($tStruct, $nbElem, $idx) If @error And @error<>3 Then MsgBox(0,@ScriptLineNumber,@error) If @error = 3 Then ; if element is out of range ; approach is asymetric (upper bound is too big) $idx -= ($incr = 1) ? 1 : $incr / 2 Else $idx += Int($incr / 2) EndIf $incr = Int($incr / 2) Until $incr = 0 Switch $type Case "Int32", "Int64" $data = DllStructGetData($tStruct, $nbElem, 1) If @error Then MsgBox(0,@ScriptLineNumber,@error) DllStructSetData($tStruct, $nbElem, 0x7777666655554433, 1) $readvalue = DllStructGetData($tStruct, $nbElem, 1) If @error Then MsgBox(0,@ScriptLineNumber,@error) Switch $readvalue Case 0x7777666655554433 $elem = "int64" ; alias: uint64 ; alias: int_ptr(x64), long_ptr(x64), lresult(x64), lparam(x64) ; alias: uint_ptr(x64), ulong_ptr(x64), dword_ptr(x64), wparam(x64) Case 0x55554433 DllStructSetData($tStruct, $nbElem, 0x88887777, 1) If @error Then MsgBox(0,@ScriptLineNumber,@error) $readvalue = DllStructGetData($tStruct, $nbElem, 1) If @error Then MsgBox(0,@ScriptLineNumber,@error) $elem = ($readvalue > 0 ? "uint" : "int") ; int aliases: long, bool, int_ptr(x86), long_ptr(x86), lresult(x86), lparam(x86); ; uint aliases: ulong, dword, uint_ptr(x86), ulong_ptr(x86), dword_ptr(x86), wparam(x86) Case 0x4433 DllStructSetData($tStruct, $nbElem, 0x8888, 1) If @error Then MsgBox(0,@ScriptLineNumber,@error) $readvalue = DllStructGetData($tStruct, $nbElem, 1) If @error Then MsgBox(0,@ScriptLineNumber,@error) $elem = ($readvalue > 0 ? "ushort" : "short") Case 0x33 $elem = "byte" ; alias: ubyte EndSwitch DllStructSetData($tStruct, $nbElem, $data, 1) If @error Then MsgBox(0,@ScriptLineNumber,@error) $retTag &= $elem Case "String" $oldvalue = DllStructGetData($tStruct, $nbElem, 1) DllStructSetData($tStruct, $nbElem, ChrW(0x2573), 1) If @error Then MsgBox(0,@ScriptLineNumber,@error) $readvalue = DllStructGetData($tStruct, $nbElem, 1) DllStructSetData($tStruct, $nbElem, $oldvalue, 1) If @error Then MsgBox(0,@ScriptLineNumber,@error) $retTag = ($readvalue = ChrW(0x2573) ? "wchar" : "char") ;~ If $idx > 1 Then $elem &= "[" & $idx & "]" ; Dosn't work here either!!! Case "Binary" Local $blen = BinaryLen($data) $retTag = "byte" Case "Ptr" $retTag &= "ptr" ; alias: hwnd, handle Case "Double" $oldvalue = DllStructGetData($tStruct, $nbElem, 1) DllStructSetData($tStruct, $nbElem, 10^-15, 1) If @error Then MsgBox(0,@ScriptLineNumber,@error) $readvalue = DllStructGetData($tStruct, $nbElem, 1) DllStructSetData($tStruct, $nbElem, $oldvalue, 1) If @error Then MsgBox(0,@ScriptLineNumber,@error) $retTag &= ($readvalue = 10^-15 ? "double" : "float") EndSwitch If $nbElem=1 Then MsgBox(0,@ScriptLineNumber,'idx '&$idx) If $idx>1 Then If $nbElem=1 Then MsgBox(0,@ScriptLineNumber,'before index') $retTag &= '['&$idx&']' EndIf $retTag &= ';' $nbElem += 1 WEnd MsgBox(0,@ScriptLineNumber,'$retTag "'&$retTag&'"') Return $retTag EndFunc jchd's code is in post 7
       
       
    • careca
      By careca
      Hi, having an issue with an application i did, seems to crash randomly, and can take hours to do so.
      Simply says in the error msgbox:
      AutoIt Error
      Line 16392 (whatevermyapppath.exe)
      Error: The requested action with this object has failed.
       
      Recent changes to the script include this:
       
      ObjGet("winmgmts:\\localhost\root\CIMV2") $oSelect_active_network_cards = $objWMIService.ExecQuery('SELECT ProductName FROM Win32_NetworkAdapter WHERE NetConnectionStatus = 2 OR NetConnectionStatus = 9', "WQL") For $oSelect_active_network_card In $oSelect_active_network_cards $Adapter = $oSelect_active_network_card.ProductName Next Is the only thing i can see that can be related to an "object"
      This lines run only once at the top of the script.
      When i run the script itself and wait for a crash, it doesn't, or at least yet i didn't.
      What do you think this error could be?
      UPDATE: Runing the script eventually output this:
      "C:\script.au3" (894) : ==> The requested action with this object has failed.:
      $oNetwork_cards = $objWMIService.ExecQuery('SELECT BytesReceivedPerSec, BytesSentPerSec FROM Win32_PerfFormattedData_Tcpip_NetworkInterface WHERE name LIKE "' & $Adapter & '"', "WQL")
      $oNetwork_cards = $objWMIService^ ERROR
    • nacerbaaziz
      By nacerbaaziz
      Hi dear
      I have a question
      about the display language of the system
      How can I get the current display language and how can I change it by autoit
      Of course, if this is possible
      Greetings to all and hope you help me