Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

HexView 3.1 for StdLib


  • Please log in to reply
48 replies to this topic
majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006

HexView
Hex data display and structs anylizer

Download:

https://code.google..../trunk/HexView/

 

 

Features:

Hexa, ascii & struct display of input data
Synchronized scrolling
Customizable GUI
More then 1000 Win API structures included and you can define your own
Your last settings are remembered
Reverse interpretation of structures using - in front of structure name
Status bar containing offset and number of bytes of selection
Many small but important things here and there[/list]

pVar - Input data address
pByteNo - Optional number of bytes to show, by default StrLen(pVar)
pActiveTab - Optional tab name to activate upon startup. This overrides saved registry setting.

Example:

s := "123456789ABCDEF0 This is some very nice binary data"
s := s s s s s s s s s
HexView(&s, 1024)
return
[/code]
This is something very handy for debuging. Its not made to preview files, but AHK variables and API structures. Don't pass more then 50KB data.
You have some other useful functions in this package.


History
 

v3.11 

* Changes so it works with latest AHK_L

* Modules update to latest versions
* Titan's anchor replaced with Attach confused.png

v3.1
- Synchronised selection of hex and ascii edits reimplemented using subclassing instead of timer. HexView doesn't create timer anymore and selection sync is real time.
* Anchor in archive updated to latest version

v3.0
- StdLib adaptation: InsertExtract Integer removed, Dependencies set as stdlib modules (Anchor, Mem), API_xxx replaced with DllCalls.
- Structures.str will be searched in Lib folder also.
- To use, save each dependency module in the Lib directory.

v2.0
- Width can be changed now. Your last width is saved
- Active selection is saved on exit and returned on next load.
- Changed first parameter to be address instead variable
- Double left click at the struct row copies row to clipbord
- New Option: copy entire row or just a value
- Double right click at the struct row displays text at the address

v2.0 rc2
- Includes merged so you can include HexView easier. Package now includes:
HexView.ahk - contains hexview include
Structures.str - contains default structure list
EXAMPLE.ahk - example of usage- You can override struct list that is by default taken from the Structures.str file. If you don't want to use this file, or if you just want to override it in some situations, define HexView_structList global variable before calling HexView. The variable should contain struct definitions the same way like in file. For example:
HexView_structList = [SIZE]- Some minor improvements.


v2.0 rc1
- Interface redesigned to add space for more tabs and options.
- Sync scrolling now works in ascii. If you move cursor in asci edit appropriate byte will be selected in hexa view. If you have tooltip ON you can see the decimal value of the byte that will be automaticaly selected by cursor moving.
- Options to set hex format for struct members and/or offset
- Show or hide header in struct list view (enable it to sort and move columns)
- Last active tab is now saved and restored on next run. You can override this by using pActiveTab parameter

v2.0 b1
- Reverse struct interpretation. Add - infront of struct name, for instance "-RECT"
- Tooltip to show struct members when current tab is not struct tab. You can toogle it in setup tab.
- Bug fix (inproper selection count)
- Some minor improvements of struct tab.

NOTE: Example removed from the include file. You can't see it by executing HexView.ahk any more.

v1.95
- structs tab

v1.91
- hexa cursor moving bug fix
- sync scroll bug fix
- badly calculated offset fixed
- code is commented and polished
- added third optional parameter to start with specific tab open

v1.9
- major gui redesign
- customization
- position and size saving; now you can extend the height of the GUI.

v1.0
Initial release



Notes:
- You can make HexView window modal if you put following code at the end of the HexView funcion:

loop {
sleep 200
IfWinNotExist ahk_id %HexView_hwnd%
break
}

I wont add this to the function until some modality thing is included natively in AHK, as above solution is workaround for missing AHK feature and make window movement glitchy. Sleep -1 solves glitches but introduces around 20% of CPU burn on my system.

Thx goes to:PhiLho, Laszlo


Posted Image

olfen
  • Members
  • 115 posts
  • Last active: Dec 25 2012 09:48 AM
  • Joined: 04 Jun 2005
I use WinHex for looking into AHK's memory.
If your script could display the number of bytes marked, offsets and an ExtractInteger() equivalent of the bytes marked I would be tempted to change.

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006
No, it doesn't display number of bytes marked, but it will.
Offset is trivial to add and will be done. I used original PhiLhos function DumpDWORDS that I renamed to Dump. This one doesn't have offset, but I will add it for next verions of HexView.

btw, winhex is nice I use it, but its not made to be called from AHK.

I am always accepting good suggestions, but you will have to be more formal about it.
Posted Image

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
Hey, I am happy to see my code re-used. This sure is better than plain MsgBox, even more with large set of data!
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006
O yeah, its much better then msgbox which I was using so far. It has synchronised scrolling and selection and I will add some new things in the feature.

About large set of data, you can test how much it can take being decently fast. 100KB crushed AHK here, but 50KB works fine.

To be able to support files and larger data structures, gui must be aware of your current "file view" in order to convert only data you currently look at. This can be done too, but I leave this to ppl who want to create full faetured Hex Viewer out of this. I made it for debuging purposes for which it doesn't have to accept big quontities of data.
Posted Image

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006
New version:

- Bug fixes
- number of selected bytes and offset
- better look and feel
- ExtractInteger on selected number of bytes, (1,2 or 4)
- Hex2Bin & Bin2Hex added to package, check out the doc.
Posted Image

olfen
  • Members
  • 115 posts
  • Last active: Dec 25 2012 09:48 AM
  • Joined: 04 Jun 2005
Thanks a lot for the update!
I now use it in lieu of WinHex.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Nice work!

A couple of minor problems:
- My display fonts are 25% magnified, which make the text longer than the widths of the controls (they are continued in the next line). It would be nicer if the widths were automatically adjusted.
- In my Windows setup the offset value does not show up, if it is larger than 9. I guess there is not enough room left for it (test with large selections).

It would be nice to be able to see structures. In a menu, the user selects items to be collected to a list, like {int32,uint32,int16,uint8,uint8,float}, and the members are shown in another window. See here some code for floats. We could even have "skip32" in the list, to ignore 32 bits or bytes.

Elevator_Hazard
  • Members
  • 297 posts
  • Last active: Feb 07 2011 12:10 AM
  • Joined: 28 Oct 2006
:D what editor are you using in the picture up top?
Changed siggy at request of ahklerner :D

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006
Thx guys

2 Laszlo

- My display fonts are 25% magnified, which make the text longer than the widths of the controls (they are continued in the next line). It would be nicer if the widths were automatically adjusted.

I was aware of that from the beginning. I already tried to calculate font size but I failed. I did this number of times in other projects and DrawText API function with uFormat=DT_CALCRECT was able to always precisely give me text width and height depending on dc settings. However, it always returns the same values for my ahk gui, regardless font that is choosen. Other ways I know are not reliable so if you or anybody else can think some precise solution I will certanly update the code with extended options, like your own Gui background color, text color, font, etc... I planned originaly those options to be set from the HexView gui itself and saved into registry so you don't have to specify them on eatch call.

For now you can fix the thing by manualy changing those lines:
guiw := [color=brown]630[/color],
...
Gui, %HexView_Gui%:Add, Edit,	h%iY% [color=brown]w440[/color]   section -VScroll readonly HWNDHexView_eHexa 0x100, %hexa%

Or just change font size in this line:
Gui, %HexView_Gui%:Font,[color=yellow]s10,[/color] Courier New

Your other problem with offset is of similar nature. Just change the
Gui, %HexView_Gui%:Add, Text,	right [color=orange]w200[/color] ys+2 x+38

I will make sure that in future releases those changes can be tweaked with single value, if they are not automatic.


It would be nice to be able to see structures. In a menu, the user selects items to be collected to a list, like {int32,uint32,int16,uint8,uint8,float}, and the members are shown in another window. See here some code for floats. We could even have "skip32" in the list, to ignore 32 bits or bytes.

I was planning this but somehow I choosed not to implement it for beginning, as I wanted the hexviewer with basic capabilities really fast. There will probably be option to save your structs in similar format and to set "as" filed manualy. I even planned snapshots together with selection so you can do A|B with previous things you watched.... skip32 is really good idea; its better to use SkipNNNN though

2 Elevator_Hazard
Its edit plus with custom colors for enitre environment, including syntax higlighting of AHK source code. You can see more screenshots on Isense page and here
Posted Image

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

Other ways I know are not reliable

Have you tried GetTextExtentPoint32? I once succeeded to obtain the text extent using it.
<!-- m -->http://msdn2.microso...y/ms534223.aspx<!-- m -->

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006
I got the same results. It always returns 344 here. I used this code:


Gui, %HexView_Gui%:Font,s14, Courier New
Gui, %HexView_Gui%:Add, Edit,	h%iY% w540   section -VScroll readonly [color=green]HWNDHexView_eHexa[/color] 0x100, %hexa%

...

s := "11 12 13 14   21 22 23 24   31 32 33 34   41 42 43 44 "
VarSetCapacity(size, 8)
r:=DllCall("GetTextExtentPoint32A", "uint", API_GetDc(HexView_eHexa), "str", s, "int", StrLen(s), "uint", &size)
msgbox % ExtractInteger(size, 0)


There is no difference if GUI is shown or not.
It seems that func works but it doesn't account Fonts. I get the same results using Desktop's dc.

Maybe this requires dc to be created manualy, then SelectObject used with appropriate Font.

BTW, I don't remember now what is the difference between DrawText and this function. I was using both and finaly realised that DT offers more functionality if i recall correctly...
Posted Image

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006
Hm... I was right... This procedure seems to work good. It will not be so simple, but I simplified it here :


  ;show the window, must be done first or font handles are zero
	Gui, %HexView_Gui%:Show, w%guiw% h%guih%, Hex Viewer %ver% 

;calc size

	s := "11 12 13 14   21 22 23 24   31 32 33 34   41 42 43 44 "
	VarSetCapacity(size, 8)

	hwnd := WinExist()
	SendMessage, 0x31, 0, 0, Edit1, ahk_id %hwnd%      ;send the message to get font handle, win must be visible
	hFont := ErrorLevel   ;this will get the Font handle of HEX edit

	dc := API_GetDc(hwnd)       
	API_SelectObject(dc, hFont)       ;without this, it doesn't work
	r:=DllCall("GetTextExtentPoint32A", "uint", dc, "str", s, "int", StrLen(s), "uint", &size)
	msgbox % ExtractInteger(size, 0) . " | " . ExtractInteger(size, 4)

Getting the font handle here is simplified as it requires window to be shown. I can "FIX" this window after it is shown with initial coordinates, but as that will flicker I must get the font handle using another dummy window or I should do it by protocol of Win API wich is pain as very large structures are involved.

There might be one non-flickering solution without additional dummy windows:

;show the window	
	Gui, %HexView_Gui%:Show, [color=orange]w0 h0[/color], Hex Viewer %ver%


Yeah, this seems nice. Show the window with zero dimension, in which case everything works. Then fix it, then make it visible....

Anyway, if any of you have already a method to load a font using API and obtain handle to it, I would use it as only real solution.

I tested the returned value with different font sizes and it works like a charm.
Posted Image

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

Hm... I was right... This procedure seems to work good. It will not be so simple, but I simplified it here

You seem to figure out your own way. Anyway, here is the one I used. Sceen DC will be used here.

#NoEnv

sString := "This is a test."
sFaceName := "Courier New"
nHeight := 9
bBold := 0

MsgBox, % GetTextExtentPoint(sString, sFaceName, nHeight, bBold)

GetTextExtentPoint(sString, sFaceName, nHeight = 9, bBold = False, bItalic = False, bUnderline = False, bStrikeOut = False, nCharSet = 0)
{
	hDC := DllCall("GetDC", "Uint", 0)
	nHeight := -DllCall("MulDiv", "int", nHeight, "int", DllCall("GetDeviceCaps", "Uint", hDC, "int", 90), "int", 72)

	hFont := DllCall("CreateFont", "int", nHeight, "int", 0, "int", 0, "int", 0, "int", 400 + 300 * bBold, "Uint", bItalic, "Uint", bUnderline, "Uint", bStrikeOut, "Uint", nCharSet, "Uint", 0, "Uint", 0, "Uint", 0, "Uint", 0, "str", sFaceName)
	hFold := DllCall("SelectObject", "Uint", hDC, "Uint", hFont)

	DllCall("GetTextExtentPoint32", "Uint", hDC, "str", sString, "int", StrLen(sString), "int64P", nSize)

	DllCall("SelectObject", "Uint", hDC, "Uint", hFold)
	DllCall("DeleteObject", "Uint", hFont)
	DllCall("ReleaseDC", "Uint", 0, "Uint", hDC)

	nWidth  := nSize & 0xFFFFFFFF
	nHeight := nSize >> 32 & 0xFFFFFFFF

	Return "Width: " . nWidth . "`n" . "Height: " . nHeight
}


majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006
Thx for this function Sean. I thought creating a font is complicated then that ...
Posted Image