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
SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Dear majkinetor,

The screenshot looks great. Nice work.
Meanwhile, I am not able to run your test code in W2K.
Can you please check it out.

* error dump edited out

Meanwhile, I have a small suggestion to make. It would be nicer if you could implement ExtractInteger() to Extract the integer also in reverse order of the bytes.

I had written something very similar to your HexViewer to view file headers and API Structures ( almost a year ago ). I have the reverse Integer extraction in my version. Most of my understanding of API structures was possible by it.

I find your interface much nicer and want to change to it.

Thanks. :)

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

Thanks your for your time and nice words. :p

Your problem is strange indeed as I don't have 2 HexVIew_slider variables. You should search your own Test.ahk as you probably gave the same name to your own variable (?). ANyway, you can remove thi sfrom the appropriate GUI command as it is used for synchronised scrolling, to see if there is any progress. This is not something related to OS as I see it.

About your suggestion, its trivial, I just have to do operation on Selection.Reverse() (using fictional OO syntax) instead of original. If you can explain me the benefits of such action I will add it to the wish list.


PS: IN the meantime, try to find the problematic part of the code yourself, I think you have enough XP for that. The main part of the code is simple anyway. The hardest was to calculate the F function that translates [a-b] interval of Hexa edit to [c-d] interval of ASCII edits. Other than that, which you can skp is simple ahk code.

If you have further problems with it, we can traverse the code if you happen to be online the same time with me, via some IM.

Thx.
Posted Image

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

You should search your own Test.ahk as you probably gave the same name to your own variable (?).


Test.ahk was actually the example you had given in the title post.
Please include a return in it.

s := "123456789ABCDEF0 This is some very nice binary data" 
s := s s s s s s s s s 
hexview(s, 5*1024) 
[color=red]Return[/color]

#include HexView.ahk

Your version is so simple ( the interface ) and efficient .. Thanks for sharing it. :)

About your suggestion, its trivial, I just have to do operation on Selection.Reverse() (using fictional OO syntax) instead of original. If you can explain me the benefits of such action I will add it to the wish list.

I vaguely remember one particular obsolete API structure that had a word ( 16bit ) stored from right to left... never mind that, but:

A .PNG file stores its Width & Height as DWord in reverse, that is from right to left.
FileRead the first 100 chars from any PNG file and load it in HexViewer. You will see the chars IHDR in the text view of HexViewer. The immediately following eight bytes contain the WxH of the image, that is - Two DWords in reverse.

The webpage ( I googled for PNG header info ) did not state the fact and I plucked out half my hair before I realised that DWord was in reverse. :D

I think, GIF also stores two words ( 16 bit ) in reverse for WxH.

Thanks.. :)

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006
Thx, I added return.

Your version is so simple ( the interface ) and efficient .. Thanks for sharing it.

Thx

About your reverse thingie, I understand, and I will try to add this when time permits me to update HexView.
Posted Image

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

Thx for this function Sean. I thought creating a font is complicated then that ...

It's my pleasure. BTW, I guess you meant CreateFontIndirect. I agree that the logfont struct could be a headache at the first usage.

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

I vaguely remember one particular obsolete API structure that had a word ( 16bit ) stored from right to left...

You mean RtlUshortByteSwap? (: it seems also to be fastcall)
BTW, there also exist similar ones for Ulong and Ulonglong, however, their calling convention is the rare case of fastcall, which is not supported by AHK's DllCall(). Although I succeeded using Cdecl instead, I'm not sure if it's safe to use ...

DllCall("ntdll\RtlUshortByteSwap", "Ushort", 0x1020, "Cdecl Ushort")
DllCall("ntdll\RtlUlongByteSwap", "Uint", 0x10203040, "Cdecl Uint")


Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
The above size calculation functions do not seem to take the magnification factor into account. They react to a font change, or font size change, but the returned values show the un-magnified sizes in my laptop.

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006
HMM..... !
Well, maybe some other factor from system parameters gives magnification size.

I can put for you maginification factor in HexView setup though, its easy, and you can set your maginification manuely if I am not able to get it using API.

It's my pleasure. BTW, I guess you meant CreateFontIndirect. I agree that the logfont struct could be a headache at the first usage.

Oh, its good to know it was pleasure :D
LogFont is indead a headache, but it doesn't have anything to do with first usage, but with AHK not suporting structs.
Posted Image

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006
Ok, I created interface for HexViewer 2.0.
I will post the entire script here so you can play around with fonts and see the problems with GetTextSize function. There is HexView_pCorrection param at the start of the script that shold be adjuced for each font. If font is proportional, like it should be for hex viewer, this value should be fixed for all font sizes. With Courier New it works great and you don't have to touch anything, but with other fonts not.

Other news:

- Major gui redesign
- Setup, real time color changing, non-real time Font changing
- Interpretation in separate tab called structs. Structs tab is not yet implemented. You will be able to define your structs in text file struct. Currently it is hardocoded to read RECT defnition from the file only.
- Customizable height
- Settings are remembered into the registry. Use included reg file to import def settings for now. Your last height will be saved too. Width is autocalculated based on the size of the font for hex control

Download



2 Sean, Lazslo, anybody
If you can figure out the way to calculate with other fonts, besides Courier New, pls let me know. Otherwise, I will hardcode Courier New font face as it works perfect with it, and let you only change style.
Posted Image

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Without first merging HexView.reg to the registry, the GUI does not come up right, but afterwards it looks nice! It would make sense to use meaningful defaults, if the registry entries are not set, or they are in error. If I close HexView with a proportional font selected (like Arial), next time HexView opens up with a screwed up GUI, where the Setup button is not even visible, so the only way to make it work is to re-merge the .reg file. The GUI comes up without a visible Setup button even if I select Courier New, with a font size of 10.

Changing the font shows the new selection in the font box of the GUI, but it does not take effect until I change the colors, too. Then the Font box changes back to showing the name of the selected font in the Windows dialog font. I guess it is by design, but there is no need to show the selected font in the GUI, because the font selection dialog already showed it, and it could take effect immediately, without first going to color selection.

Something is fishy about calling GetTextSize. It is not called after a font change, only twice at startup. The GUI ought to be redrawn, with the new font. I could not find a fix of the calculated size, in a few minutes. It is true, that the size is wrong for most of the fonts.

It would be safer to use a .ini file for the settings, not the registry. If there is a bug, you mess up the registry, which is harder to fix than editing a text file. Also, a user can easily check the saved settings.

The color selection works, fine, but the color of the selection background and font should be selectable, too. Now it does not change, making the color selection less useful.

I guess, the Struct button is only a placeholder for a future functionality. At least it does not do anything useful to me.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Magnification factor: I guess, Windows uses different fonts when there is a DPI selected other than 96. Therefore, multiplying the magnification factor to the text size of the default font is only a rough approximation (except for the fonts, which don't have different versions). Instead, the right version of the fonts has to be selected, but I don't know, how.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
I would try the simple function (with different parameters than the original!)
GetTextSize(pStr, pSize=8, pFont="", pHeight=false) {
   Gui 9:Font, %pSize%, %pFont%
   Gui 9:Add, Text, R1, %pStr%
   GuiControlGet T, 9:Pos, Static1
   Gui 9:Destroy
   Return pHeight ? TW "," TH : TW
}
However, in HexView the GetTextSize function is called with different font parameters, than what the GUI actually uses. Something is not right there.

Also, if proportional fonts are used, the size has to be determined for the possible widest characters, something like
hexW  := GetTextSize("DD DD DD DD   DD DD DD DD   DD DD DD DD   DD DD DD DD ", HexView_pStyle "," HexView_pFont) + HexView_pCorrection
   asciW := GetTextSize("WWWWWWWWWWWWWWWW ", HexView_pStyle "," HexView_pFont ) + HexView_pCorrection
or even
hexW  := GetTextSize("DD DD DD DD   DD DD DD DD   DD DD DD DD   DD DD DD DD D", HexView_pStyle "," HexView_pFont)
   asciW := GetTextSize("WWWWWWWWWWWWWWWW W", HexView_pStyle "," HexView_pFont )


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

Changing the font shows the new selection in the font box of the GUI, but it does not take effect until I change the colors, too

You, I think I wrote it is non realtime. Font determines width of the gui and that is calculated only on startup. Its not something you wanna change all the time anyway.

Also, if proportional fonts are used, the size has to be determined for the possible widest characters, something like

I am aware of that. But I think its the best choice to hard code font to Courier New or to make it work with other fixed-pitch fonts.

I don't know if you saw that, but you have pCorrection at the start of the script. If some font make the hex wrapp, adjust the correction param.

I would try the simple function

I will probably use something like that here. I wanted to create GetTextSize as universal solution, but it seems its not so easy so I will try some workaround like you proposed.


It would be safer to use a .ini file for the settings, not the registry. If there is a bug, you mess up the registry, which is harder to fix than editing a text file. Also, a user can easily check the saved settings.

I know.. but when this works right, user will not be able to screw up its settings that way so he is not able to fix it from setup. This is not something you like to keep additional files. You set it once and use all the time. If you want to move your settings , which you can redefine in 10 seconds, you can import .reg file. Otherwise, I use ini for portability.


The color selection works, fine, but the color of the selection background and font should be selectable, too. Now it does not change, making the color selection less useful.

I don't know is this possible to do set in standard edit. Maybe somebody can enlighten me and I will surely do it.


BTW, when setup and some tabs go away, you can click them if you hover (and probably hold button of) your mouse above visible tab. It is there but covered by asci control. It is possible to use ctrl tab also to change tabs. This is minor thing and easy to fix.
Posted Image

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006
New version 1.9, see first post.


2Laszlo
I added default values in case reg is empty. Your will not be as you already have reg info so in case you wanna see defaults, you should delete the reg key.

I also choosed not to put static string or the widest char when measuring as with proportional fonts it doesn't make good results. I now measure entire hex and ascii strings before starting, and the results are always good. You can test on different fonts real time now.
Posted Image

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
It is pretty, and works! I can hardly wait for the structs, but it is already useful as it is.