MattyD Posted February 21, 2010 Posted February 21, 2010 Hey all, Iv'e been getting pretty tired of dredging through msdn doumentation, trying to find that particular string in a struct with a gazillion elements. So I wrote something to help me basing the look on the debug dump command. Anyway for what it's worth I thought I'd share. Pretty straight forward - $pPointer -> Struct pointer $iLength -> Struct Size $fANSI -> Set to True when the string in the struct is ANSI $iGrouping -> Blocks the data into groups of 8, 16 or 32 bits $fANSI is treated as True when $iGrouping is set to 8. $fForceByte -> uses a byte array when pulling data from a struct (rather than word or dword). (does not correct for little endian) $sNonPrinting -> use something other than "." as a placeholder for non printing characters. The first 3 or 4 lines are a sample - you'll figure it out Hope it's helpful, Matt expandcollapse popup;21/02/2010 - By MattyD Local $MyStruct = DllStructCreate("byte[4096]") DllCall("Iphlpapi.dll", "int", "GetAdaptersAddresses", "int", 2, "ulong", 0, "int", 0, "ptr", DllStructGetPtr($MyStruct), "ulong*", DllStructGetSize($MyStruct)) _StructHelper(DllStructGetPtr($MyStruct), DllStructGetSize($MyStruct), False, 16) Func _StructHelper($pPointer, $iLength, $fANSI = False, $iGrouping = 32, $fForceByte = False, $sNonPrinting = ".") Local $tStruct, $sSeg, $sCHR, $sChrString, $iCHRLen = 4, $iByteCount If $fANSI == -1 Or $fANSI == Default Then $fANSI = False If $iGrouping == -1 Or $iGrouping == Default Then $iGrouping = 32 If $fForceByte == -1 Or $fForceByte == Default Then $fForceByte = False If $sNonPrinting == -1 Or $sNonPrinting == Default Then $sNonPrinting = "." If $fANSI Or $iGrouping = 8 Then $iCHRLen = 2 Select Case $iGrouping = 8 Or $fForceByte $tStruct = DllStructCreate("byte[" & $iLength & "]", $pPointer) Case $iGrouping = 16 $tStruct = DllStructCreate("word[" & $iLength / 2 & "]", $pPointer) Case $iGrouping = 32 $tStruct = DllStructCreate("dword[" & $iLength / 4 & "]", $pPointer) Case Else Return 0 EndSelect For $i = 1 To $iLength * 8 / $iGrouping If $fForceByte Then $sSeg = "" For $j = $iByteCount + 1 To $iByteCount + $iGrouping / 8 $sSeg &= Hex(DllStructGetData($tStruct, 1, $j), 2) Next $iByteCount += $iGrouping / 8 Else $sSeg = Hex(DllStructGetData($tStruct, 1, $i), $iGrouping / 4) EndIf If Not Mod($i - 1, 8) Then If $i <> 1 Then ConsoleWrite(" | " & $sChrString) ConsoleWrite(@CRLF & $pPointer + ($i - 1) * ($iGrouping / 8) & " | ") $sChrString = "" EndIf ConsoleWrite($sSeg & " ") For $j = 1 To $iGrouping / 4 Step $iCHRLen If $iCHRLen = 4 Then $sCHR = ChrW(Dec(StringMid($sSeg, $j, 4))) Else $sCHR = Chr(Dec(StringMid($sSeg, $j, 2))) EndIf If StringRegExp($sCHR, "[[:print:]]") Then $sChrString &= $sCHR Else $sChrString &= $sNonPrinting EndIf Next $sChrString &= " " Next ConsoleWrite(" | " & $sChrString & @CRLF & @CRLF) EndFunc
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now