?
Solved

How to Open File In HEX in VB6.0 and Re-Write HEX to File?

Posted on 2010-11-29
17
Medium Priority
?
3,566 Views
Last Modified: 2012-05-10
Hello experts.. !
I hope this time also you would like to solve my programing problems.

In vb6.0, I wanna get the HEX values of any selected file and wanna display those HEX values on a Textbox of my project..
Also wanna Write those HEX values in to a File..

I have seen few source codes of Hex Editors in vb6, but they are very complicated.. Please may you tell me the simplest codings to easy understand, I am a newbie on vb6.0

-Thanks in advance..
0
Comment
Question by:appinities
  • 8
  • 4
  • 3
  • +2
17 Comments
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 34229740
You could read the file and convert the characters to Hex...
but I want to make sure I understand what you need.
Is the file already in Hex or you want to convert it to Hex...

Precede your values with &H to convert from Hex

&HFF = 255

&H41 = 65
CHR(65) = "A"

0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 34230620
This will show the first 10 characters of a filein a text box as Hex.
Dim f As Integer
Dim i As Integer
Dim b As Byte
Dim strText As String

f = FreeFile
Open "C:\MyFolder\MyFile.dat" For Binary As #f
For i = 1 To 10
    Get #f, i, b
    strText = strText & Right("0" & Hex$(b), 2) & " "
    
Next i
Text1.Text = strText
'...

Open in new window

0
 
LVL 27

Expert Comment

by:tliotta
ID: 34234444
Because this is also in one of the AS/400 zones, is this a DB2 file you're trying to read? Or is it a streamfile from the IFS on an AS/400?

If this is a file from an AS/400, there will likely be network encoding translations (EBCDIC<->ASCII) somewhere involved.

Tom
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 

Author Comment

by:appinities
ID: 34238020
Thanks everybody !

Its a Normal Exe file. you may consider it as default calc.exe file of windows XP.. I want to open its Hex values in a Textbox and after editing any value of those Hex values, want to re-save it with EXE extension..
0
 

Author Comment

by:appinities
ID: 34238103
Thanks Everyone I have tried your solutions, but not satisfied.. coz

This is the Hex value of a normal "calc.exe" i opened in a Hex editir "Hexworkshop"
4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000F00000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A240000000000000087451664C3247837C3247837C324783739073837C624783719076437C8247837C3247837C2247837C32479374424783739076137CE24783754073D37C224783719076537DF24783739074537C224783752696368C3247837000000000000000000000000000000000000000000000000504500004C01030010847D3B00000000

Open in new window



And Following are the Hex values I found by using "GrahamSkan" snippets:
4D 5A 90 00 03 00 00 00 04 00 00 00 FF FF 00 00 B8 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 F0 00 00 00 0E 1F BA 0E 00 B4 09 CD 21 B8 01 4C CD 21 54 68 69 73 20 70 72 6F 67 72 61 6D 20 63 61 6E 6E 6F 74 20 62 65 20 72 75 6E 20 69 6E 20 44 4F 53 20 6D 6F 64 65 2E 0D 0D 0A 24 00 00 00 00 00 00 00 87 45 16 64 C3 24 78 37 C3 24 78 37 C3 24 78 37 39 07 38 37 C6 24 78 37 19 07 64 37 C8 24 78 37 C3 24 78 37 C2 24 78 37 C3 24 79 37 44 24 78 37 39 07 61 37 CE 24 78 37 54 07 3D 37 C2 24 78 37 19 07 65 37 DF 24 78 37 39 07 45 37 C2 24 78 37 52 69 63 68 C3 24 78 37 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 50 45 00 00 4C 01 03 00 10 84 7D 3B 00 00 00 00 00 00 00 00 E0 00 0F 01 0B 01 07 00 00 28 01 00 00 9C 00 00 00 00 00 00 75 24 01 00 00 10 00 00 00 40 01 00 00 00 00 01 00 10 00 00 00 02 00 00 05 00 01 00 05 00 01 00 04 00 00 00 00 00 00 00 00 F0 01 00 00 04 00 00 FC D7 01 00 02 00 00 80 00 00 04 00 00 10 00 00 00 00 10 00 00 10 00 00 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 80 2B 01 00 8C 00 00 00 00 60 01 00 60 89 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 12 00 00 1C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 60 02 00 00 80 00 00 00 00 10 00 00 28 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2E 74 65 78 74 00 00 00 B0 26 01 00 00 10 00 00 00 28 01 00 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 00 00 60 2E 64 61 74 61 00 00 00 1C 10 00 00 00 40 01 00 00 0A 00 00 00 2C 01 00 00 00 00 00 00 00 00 00 00 00 00 00 40 00 00 C0 2E 72 73 72 63 00 00 00 60 89 00 00 00 60 01 00 00 8A 00 00 00 36 01 00 00 00 00 00 00 00 00 00 00 00 00 00 40 00 00 40 0F FE 7D 3B 38 00 00 00 0E FE 7D 3B 44 00 00 00 0E FE 7D 3B 4F 00 00 00 0E FE 7D 3B 5C 00 00 00 0E FE 7D 3B 69 00 00 00 0E FE 7D 3B 73 00 00 00 00 00 00 00 00 00 00 00 53 48 45 4C 4C 33 32 2E 64 6C 6C 00 6D 73 76 63 72 74 2E 64 6C 6C 00 41 44 56 41 50 49 33 32 2E 64 6C 6C 00 4B 45 52 4E 45 4C 33 32 2E 64 6C 6C 00 47 44 49 33 32 2E 64 6C 6C 00 55 53 45 52 33 32 2E 64 6C 6C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 EA 22 DD 77 D7 23 DD 77 9A 18 DD 77 00 00 00 00 2E 1E C7 77 83 1D C7 77 FF 1E C7 77 00 00 00 00 93 9F E7 77 D8 05 E8 77 FD A5 E7 77 AD A9 E9 77 A3 36 E7 77 03 38 E7 77 41 E3 E6 77 60 8D E7 77 E6 1B E6 77 2B 2A E7 77 7A 17 E6 77 79 C8 E6 77 14 1B E7 77 C1 30 E7 77 37 AC E7 77 69 4A E7 77 5E F6 E6 77 3B 4A E7 77 5B 9D E7 77 63 79 E7 77 40 36 E7 77 F1 7E E7 77 58 34 E7 77 45 9A E7 77 81 98 E7 77 D7 7F E6 77 6F 16 E7 77 DB C9 E7 77 79 36 E7 77 D5 41 E6 77 00 00 00 00 DB E3 49 77 00 00 00 00 10 BC D5 77 97 26 D7 77 31 A3 D4 77 4A FF D4 77 7F 81 D4 77 1F 74 D4 77 C3 76 D4 77 65 B7 D6 77 16 B8 D4 77 50 64 D4 77 CD 81 D4 77 EF 0F D7 77 4D 5A D4 77 09 D2 D5 77 B3 C1 D4 77 26 63 D7 77 92 7E D4 77 10 E3 D5 77 8C E3 D5 77 EC 72 D4 77 03 E3 D5 77 2A 43 D4 77 CE 29 D5 77 CB F5 D4 77 E6 EA D5 77 C8 C0 D4 77 1C 51 D6 77 C9 61 D4 77 37 81 D4 77 0D 63 D4 77 16 A2 D4 77 98 B8 D4 77 93 79 D4 77 EF 48 D4 77 C4 A0 D4 77 0C 59 D4 77 B6 7C D4 77 27 7D D4 77 37 5E D4 77 2D FE D4 77 8C C9 D5 77 60 ED D6 77 25 95 D4 77 B5 5E D4 77 48 60 D4 77 23 5F D4 77 6D 81 D4 77 DC C5 D4 77 3B 99 D4 77 58 41 D4 77 0E 4B D5 77 A8 8A D4 77 8D 9B D4 77 11 9A D4 77 C8 F3 D5 77 74 5F D4 77 29 A5 D4 77 C5 3D D4 77 D3 3D D4 77 24 40 D4 77 FF 78 D4 77 18 85 D4 77 BF 40 D4 77 40 0D D5 77 4C AE D4 77 39 88 D7 77 8C 71 D4 77 E6 E3 D8 77 A0 EE D6 77 00 00 00 00 D8 1A C2 77 F5 19 C2 77 F9 D7 C1 77 E6 C7 C1 77 CE 3C C4 77 50 31 C4 77 BC 3D C4 77 40 2B C4 77 11 7B C3 77 EE 7A C3 77 69 12 C3 77 00 7B C3 77 DC 7A C3 77 A8 C7 C5 77 09 E9 C1 77 DB 79 C3 77 60 8F C4 77 88 D3 C5 77 4A EB C1 77 68 EB C1 77 32 36 C3 77 33 89 C2 77 5B 0C C2 77 58 A6 C4 77 B0 3E C3 77 7B 19 C2 77 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 84 7D 3B 00 00 00 00 02 00 00 00 19 00 00 00 0C 16 00 00 0C 0A 00 00 53 00 43 00 00 00 00 00 20 00 4D 00 00 00 00 00 73 00 47 00 72 00 6F 00 75 00 70 00 69 00 6E 00 67 00 00 00 33 00 3B 00 30 00 00 00 73 00 54 00 68 00 6F 00 75 00 73 00 61 00 6E 00 64 00 00 00 2C 00 00 00 69 00 6E 00 74 00 6C 00 00 00 00 00 73 00 44 00 65 00 63 00 69 00 6D 00 61 00 6C 00 00 00 00 00 2E 00 00 00 55 00 73 00 65 00 53 00 65 00 70 00 00 00 00 00 6C 00 61 00 79 00 6F 00 75 00 74 00 00 00 00 00 45 00 44 00 49 00 54 00 00 00 00 00 43 00 61 00 6C 00 63 00 4D 00 73 00 67 00 50 00 75 00 6D 00 70 00 57 00 6E 00 64 00 00 00 00 00 30 00 00 00 28 00 3D 00 00 00 00 00 41 00 6E 00 20 00 75 00 6E 00 6B 00 6E 00 6F 00 77 00 6E 00 20 00 65 00 72 00 72 00 6F 00 72 00 20 00 68 00 61 00 73 00 20 00 6F 00 63 00 63 00 75 00 72 00 65 00 64 00 2E 00 00 00 45 00 72 00 72 00 6F 00 72 00 00 00 20 00 00 00 30 00 00 00 7C 00 00 00 31 00 00 00 7D 00 00 00 32 00 00 00 7E 00 00 00 33 00 00 00 7F 00 00 00 34 00 00 00 80 00 00 00 35 00 00 00 81 00 00 00 36 00 00 00 82 00 00 00 37 00 00 00 83 00 00 00 38 00 00 00 84 00 00 00 39 00 00 00 85 00 00 00 41 00 00 00 86 00 00 00 42 00 00 00 87 00 00 00 43 00 00 00 88 00 00 00 44 00 00 00 89 00 00 00 45 00 00 00 8A 00 00 00 46 00 00 00 8B 00 00 00 21 00 00 00 6A 00 00 00 53 00 00 00 62 00 00 00 4F 00 00 00 63 00 00 00 54 00 00 00 64 00 00 00 52 00 00 00 6B 00 00 00 59 00 00 00 5F 00 00 00 23 00 00 00 69 00 00 00 40 00 00 00 68 00 00 00 4D 00 00 00 3A 01 00 00 4E 00 00 00 65 00 00 00 4C 00 00 00 66 00 00 00 56 00 00 00 6E 00 00 00 58 00 00 00 75 00 00 00 49 00 00 00 8C 00 00 00 48 00 00 00 8D 00 00 00 50 00 00 00 6F 00 00 00 2F 00 00 00 5A 00 00 00 2A 00 00 00 5B 00 00 00 25 00 00 00 5E 00 00 00 2D 00 00 00 5D 00 00 00 3D 00 00 00 70 00 00 00 2B 00 00 00 5C 00 00 00 26 00 00 00 56 00 00 00 7C 00 00 00 57 00 00 00 5E 00 00 00 58 00 00 00 7E 00 00 00 61 00 00 00 3B 00 00 00 60 00 00 00 3C 00 00 00 59 00 00 00 28 00 00 00 7A 00 00 00 29 00 00 00 7B 00 00 00 5C 00 00 00 79 00 00 00 51 00 00 00 51 00 00 00 D1 00 00 00 51 00 00 00 D3 00 00 00 54 00 00 00 CD 00 00 00 73 00 00 00 D0 00 00 00 74 00 00 00 C3 00 00 00 71 00 00 00 D2 00 00 00 72 00 00 00 C1 00 00 00 76 00 00 00 D4 00 00 00 77 00 00 00 C4 00 00 00 78 00 00 00 B2 00 00 00 37 01 00 00 B3 00 00 00 3B 01 00 00 B4 00 00 00 3C 01 00 00 B5 00 00 00 32 01 00 00 B6 00 00 00 33 01 00 00 B7 00 00 00 34 01 00 00 B8 00 00 00 35 01 00 00 B9 00 00 00 50 00 00 00 BC 00 00 00 36 01 00 00 30 00 00 00 31 00 00 00 63 00 6F 00 6C 00 6F 00 72 00 73 00 00 00 00 00 68 68 63 74 72 6C 2E 6F 63 78 00 00 00 00 00 00 43 4C 53 49 44 5C 7B 41 44 42 38 38 30 41 36 2D 44 38 46 46 2D 31 31 43 46 2D 39 33 37 37 2D 30 30 41 41 30 30 33 42 37 41 31 31 7D 5C 49 6E 70 72 6F 63 53 65 72 76 65 72 33 32 00 00 00 00 00 FF FF FF FF 02 26 01 01 16 26 01 01 76 26 01 01 FF FF FF FF 47 28 01 01 6B 28 01 01 00 00 00 00 FF FF FF FF 00 00 00 00 BE 28 01 01 4E 42 31 30 00 00 00 00 10 84 7D 3B 01 00 00 00 63 61 6C 63 2E 70 64 62 00 00 00 00 00 00 00 00 00 00 00 00 8B 44 24 04 56 33 F6 EB 19 66 83 F9 39 77 1C 0F B7 C9 8D 14 B6 50 8D 74 51 D0 FF 15 1C 11 00 01 33 C9 66 8B 08 66 83 F9 30 73 DE 8B 4C 24 0C 89 31 5E C2 08 00 56 57 FF 15 8C 10 00 01 8B 35 1C 11 00 01 EB 0F 66 83 F9 20 74 06 66 83 F9 09 75 0B 50 FF D6 66 8B 08 66 85 C9 75 E9 66 8B 08 33 FF 66 85 C9 0F 84 28 01 00 00 85 FF 75 0C 66 83 F9 20 74 20 66 83 F9 09 74 1A 66 83 F9 22 75 09 33 C9 85 FF 0F 94 C1 8B F9 50 FF D6 66 8B 08 66 85 C9 75 D6 66 8B 08 66 85 C9 0F 84 F2 00 00 00 6A 02 5F 0F B7 C9 83 E9 50 0F 84 AB 00 00 00 2B CF 74 5C 83 E9 05 74 2A 83 E9 19 0F 84 99 00 00 00 2B CF 74 4A 83 E9 05 0F 85 B5 00 00 00 EB 12 66 83 F9 3A 74 0C 66 83 F9 20 74 06 66 83 F9 09 75 0B 50 FF D6 66 8B 08 66 85 C9 75 E3 68 14 40 01 01 50 E8 08 FF FF FF E9 86 00 00 00 66 83 F9 3A 74 0C 66 83 F9 20 74 06 66 83 F9 09 75 0B 50 FF D6 66 8B 08 66 85 C9 75 E3 68 10 40 01 01 50 E8 DB FE FF FF 8B 0D 10 40 01 01 83 F9 10 7E 0C C7 05 10 40 01 01 10 00 00 00 EB 47 3B CF 7D 43 89 3D 10 40 01 01 EB 3B 66 83 F9 3A 74 0C 66 83 F9 20 74 06 66 83 F9 09 75 0B 50 FF D6 66 8B 08 66 85 C9 75 E3 68 08 40 01 01 50 E8 90 FE FF FF 83 3D 08 40 01 01 40 7E 0A C7 05 08 40 01 01 40 00 00 00 50 FF D6 66 8B 08 66 85 C9 0F 85 11 FF FF FF 5F 5E C2 04 00 55 8B EC 83 EC 30 56 33 F6 39 75 08 75 70 A1 48 4A 01 01 68 5C 12 00 01 50 C7 45 D0 30 00 00 00 89 75 D4 C7 45 D8 18 61 00 01 89 75 DC C7 45 E0 1E 00 00 00 89 45 E4 FF 15 2C 11 00 01 68 00 7F 00 00 56 89 45 E8 FF 15 28 11 00 01 6A 0F 89 45 EC FF 15 24 11 00 01 89 45 F0 8D 45 D0 50 C7 45 F4 6A 00 00 00 C7 45 F8 18 40 01 01 89 75 FC FF 15 20 11 00 01 66 85 C0 75 04 33 C0 EB 03 33 C0 40 5E C9 C2 04 00 53 56 57 68 C0 4D 01 01 E8 A5 09 00 00 FF 35 90 4D 01 01 C7 05 B8 4D 01 01 01 00 00 00 E8 62 63 00 00 33 DB 89 1D 90 4D 01 01 E8 AA 63 00 00 A3 90 4D 01 01 FF 30 E8 39 63 00 00 A1 90 4D 01 01 89 18 A1 84 4F 01 01 8B 00 FF 70 04 E8 5D 63 00 00 8B 0D 90 4D 01 01 89 01 A1 84 4F 01 01 8B 30 8B 4E 04 A1 90 4D 01 01 8B 38 8D 0C 8D 0C 00 00 00 8B C1 C1 E9 02 F3 A5 8B C8 83 E1 03 F3 A4 A1 90 4D 01 01 FF 70 04 E8 E8 62 00 00 A1 90 4D 01 01 89 58 04 A1 84 4F 01 01 8B 40 04 FF 70 04 E8 0A 63 00 00 8B 0D 90 4D 01 01 89 41 04 A1 84 4F 01 01 8B 70 04 8B 4E 04 A1 90 4D 01 01 8B 78 04 8D 0C 8D 0C 00 00 00 8B C1 C1 E9 02 F3 A5 8B C8 83 E1 03 F3 A4 FF 35 98 4D 01 01 E8 A4 62 00 00 89 1D 98 4D 01 01 E8 EE 62 00 00 A3 98 4D 01 01 FF 30 E8 7D 62 00 00 A1 98 4D 01 01 89 18 A1 84 4F 01 01 8B 00 FF 70 04 E8 A1 62 00 00 8B 0D 98 4D 01 01 89 01 A1 84 4F 01 01 8B 30 8B 4E 04 A1 98 4D 01 01 8B 38 8D 0C 8D 0C 00 00 00 8B C1 C1 E9 02 F3 A5 8B C8 83 E1 03 F3 A4 A1 98 4D 01 01 FF 70 04 E8 2C 62 00 00 A1 98 4D 01 01 89 58 04 A1 84 4F 01 01 8B 40 04 FF 70 04 E8 4E 62 00 00 8B 0D 98 4D 01 01 89 41 04 A1 84 4F 01 01 8B 70 04 8B 4E 04 A1 98 4D 01 01 8B 78 04 8D 0C 8D 0C 00 00 00 8B C1 C1 E9 02 F3 A5 8B C8 83 E1 03 F3 A4 6A 19 59 33 C0 6A 19 BF 08 4C 01 01 F3 AB 59 6A 04 BF 70 4C 01 01 6A 40 F3 AB FF 15 80 10 00 01 5F 5E 3B C3 A3 B0 4D 01 01 5B 74 0C 68 44 40 01 01 50 FF 15 90 10 00 01 C3 55 8B EC 81 EC 80 00 00 00 53 56 33 F6 57 89 75 FC 89 75 D0 89 75 D4 89 75 D8 89 75 DC E8 14 FE FF FF A1 2C 40 01 01 6A 05 68 2C 40 01 01 89 45 F0 A1 38 40 01 01 68 C0 12 00 01 89 45 F4 A1 00 40 01 01 68 AC 12 00 01 89 35 B8 4D 01 01 8B 35 84 10 00 01 BB A0 12 00 01 53 89 45 F8 FF D6 6A 05 68 38 40 01 01 68 9C 12 00 01 68 88 12 00 01 53 FF D6 6A 10 59 33 C0 6A 20 8D 7D 80 F3 AB 8D 45 80 50 68 80 12 00 01 68 6C 12 00 01 53 FF D6 8D 45 80 50 E8 A9 29 00 00 33 F6 46 3B 45 F8 A3 00 40 01 01 74 03 89 75 FC 66 8B 45 F4 66 39 05 38 40 01 01 74 03 89 75 FC A1 2C 40 01 01 66 3B 45 F0 74 18 8B F8 57 68 C0 4D 01 01 E8 AF 0A 00 00 A1 64 4A 01 01 66 89 38 89 75 FC 6A 0C 58 33 FF 57 8D 4D E4 51 50 6A 42 89 45 E4 FF 15 84 11 00 01 85 C0 74 15 8B 45 E8 23 C6 3B 05 9C 4D 01 01 74 08 A3 9C 4D 01 01 89 75 FC 39 7D 08 0F 84 02 03 00 00 A1 6C 4D 01 01 3B C7 8B 1D 80 11 00 01 89 7D FC 74 3A FF 35 80 4D 01 01 50 FF 15 7C 11 00 01 8D 45 D0 50 FF 35 6C 4D 01 01 89 75 FC FF D3 FF 35 6C 4D 01 01 FF 15 78 11 00 01 FF 35 7C 4D 01 01 FF 15 74 11 00 01 89 3D 7C 4D 01 01 39 3D 48 4D 01 01 8B 35 70 11 00 01 57 57 57 74 52 6A 66 FF 35 48 4A 01 01 FF 15 6C 11 00 01 50 A3 6C 4D 01 01 FF 15 A4 10 

Open in new window

Still above code is not the complete Hex values.. and it takes a long time to calculate a complete Hex values of a 500 KB file..



Hence, I want to open it Like it shows on hexworkshop...

See the following snapshots:

In Hexworkshop:
Hexworkshop
In My form:
 Vb6 form
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 34238288
Obviously we have only shown you the method of interpreting each byte in Hex format. The whole thing is more of a project than a question (in the EE sense of the word).

VB is inevitably slower than the writers of commercial Hex editors who probably use C++.


I suggest the you use a grid to display the data, though I would make it display 16, rather than 17 bytes per row, so that you would need 18 columns altogether. To ensure good alignment, you should use a fixed-width font such as Courier New or FixedSys.

I don't think that any of the grids that come with VB6 will do different coloured text, so you may have to search for a third-party component.
0
 

Author Comment

by:appinities
ID: 34242357
Sorry Graham, May be you have not got me xactly.. I am not asking for its arrangement.. I mean In Hexeditor..values are quite different than the Hex values generated by the Code you told me..

In HexEditor Software, values are not lengthy... and by your codes..Hex values are very lengthy and the process is taking long time to generate Hex values (with ur code)..

That what i want to ask dear, How can I got Hex values of any EXE in few secs (like Hex Workshop)..
Another thing, I want to save those Hex values back to the File..

-Thanks again !
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 34243855
they may only display part of the file

you can also read part of file by using

Dim f As Integer
Dim i As long
dim j as long
Dim b(1000000) As Byte
Dim strText As String

f = FreeFile
Open "C:\MyFolder\MyFile.dat" For Binary As #f
For i = 1 To lof(f)
    Get #f, i, b
for j = 0 to 999999
    strText = strText & Right("0" & Hex$(b(j)), 2) & " "   ' this willl be slow

next
    i = i + 999999
Next i
Text1.Text = strText
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 34244441
As EDDYKT suggests, it will be faster if only part of the file is read.

This code starts a byte number (e.g. 4) and reads a number of bytes (e.g. 10) and then displays them in the text box as before.

Code in a second button checks that the text it still valid. If so, it is written back to the file.


Option Explicit
Const StartByte = 4
Const ByteCount = 10

Private Sub Command1_Click()
    Dim f As Integer
    Dim i As Integer
    Dim b As Byte
    Dim strText As String
    
    f = FreeFile
    Open "C:\MyFolder\alpha.txt" For Binary As #f
    For i = StartByte To StartByte + ByteCount - 1
        Get #f, i, b
        strText = strText & Right("0" & Hex$(b), 2) & " "
    Next i
    Text1.Text = Trim$(strText)
    Close #f
End Sub

Private Sub Command2_Click()
    Dim f As Integer
    Dim i As Integer
    Dim j As Integer
    Dim b As Byte
    Dim strHexBytes() As String
    Dim bInvalid As Boolean
    
    f = FreeFile
    strHexBytes = Split(Text1.Text, " ")
    If UBound(strHexBytes) <> ByteCount - 1 Then
        bInvalid = True
    Else
        For i = 0 To ByteCount - 1
            If Len(strHexBytes(i)) <> 2 Then
                bInvalid = True
                Exit For
            End If
            For j = 1 To 2
                Select Case Mid$(strHexBytes(i), j, 1)
                    Case "0" To "9", "A" To "F", "a" To "f"
                    Case Else
                        bInvalid = True
                End Select
            Next j
        Next i
    End If
            
    If Not bInvalid Then
        Open "C:\MyFolder\alpha.txt" For Binary As #f
        For i = 0 To ByteCount - 1
            b = "&h" & strHexBytes(i)
            Put #f, StartByte + i, b
                    Next i
        Close #f
    Else
        MsgBox "Text should be " & ByteCount & " space-separated Hex pairs."
    End If
End Sub

Open in new window

0
 

Author Comment

by:appinities
ID: 34256456
I want to read the complete part of the File :(
What codes these Proffesional HexEditors using to Open Complete file in few secs?
I want to get such codes.. It's my school Project, I will be failed :(

Please check a project on PSC:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=38674&lngWId=1

In this project file is opening completely in few secs, But i am unable to get the exact code of this project by which file is opening..

Please can you extract that code for me?

-thanks alot
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 34256540
the routine is READFILE.

They take a file in 1 shot so it is faster. Like my example, I read 999999 bytes at one shot and it will take around a second to read 700M file.

0
 

Author Comment

by:appinities
ID: 34259844
Thanks EDDYKT ..Lemme try your codes once and I will accept you as a Genius..
0
 

Author Comment

by:appinities
ID: 34264349
Sorry EDDYKT, I have tried your Codes and Grahams Codes also, but both are working very slow... I am opening "calc.exe" (112 KB) and it's taking arround 5 mins to opening this Little file..
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 34265057
If this is a school project, it would come under the heading of homework, helping with such is against the policy of this site.

However, as a hint, you can open and read the whole of the file very quickly. It is the converting into the Hex display format that is slow. So for best performance, you should only convert the part of the file that is currently being edited.
0
 

Accepted Solution

by:
appinities earned 0 total points
ID: 34265705
I want to create a Simplest HEX Editing tool. But should be work fast... Even I have given you an external link of a Project which is fast working, but you again told me same code but in different format. Yes it's my school project and you are not my headmaster that you informing its my "homework". It's better for me to accept that you are not getting the solution.. Hence i am closing this question.....

-Thanks for all the effort you have tried, I really learnt something from them..
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 34282556
You can read the file really fast by using

Dim b() As Byte
Dim ff As Integer, Filename As String, s As String
   
Filename = "C:\winnt\system32\calc.exe"
ff = FreeFile
Open Filename For Binary Access Read Lock Read Write As #ff
s = Space$(LOF(ff))
Get #ff, , s
Close ff

b = StrConv(s, vbFromUnicode)


However, I already state in my code that display is really slow except you have something fast to display all the byte.

Anyways happy programming
0
 

Author Closing Comment

by:appinities
ID: 34299287
There codes are not working fastly, Hence i am gonna close this topic..
0

Featured Post

Automating Your MSP Business

The road to profitability.
Delivering superior services is key to ensuring customer satisfaction and the consequent long-term relationships that enable MSPs to lock in predictable, recurring revenue. What's the best way to deliver superior service? One word: automation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
This article covers the basics of data encryption, what it is, how it works, and why it's important. If you've ever wondered what goes on when you "encrypt" data, you can look here to build a good foundation for your personal learning.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses
Course of the Month16 days, 7 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question