Click here to Skip to main content
11,703,505 members (75,480 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hi, I have a file opened in HexEdit program, and it shows only these values in HEX:
56 47 7B 3F 3F 51 00 3F 3F 3F 3F 7A 23 3F 4D

So i want to save this value to a Text file for each files ( like this )
Code1= 56 47 7B 3F 3F 51 00 3F 3F 3F 3F 7A 23 3F 4D
Code2= 45 3F 39 3F 3F 70 04 3F 04 00 3F 1F 71 02 1A

Then write each code to a file using Hex, so it will look exactly like when it has been opened in HexEdit program.

Note: I have over 100 files, and i don't like to have many files.
So i want to save all these value to one text ( code1, code2 etc. )
Then when i need any of this code my program will export it to a file.

Any help will be really appreciated.
thanks
Posted 27-Jan-13 14:11pm
Comments
Leecherman at 30-Jan-13 6:53am
   
When i read the file it returned mismatch values:

Original Value that opened in HxD program:
56 47 7B FA 81 51 00 AF A7 AA CE 9C 7A 23 DA 4D

Returned value from this code:
56 47 7B FA 81 51 0 AF A7 AA CE 9C 7A 23 DA 4D

Original Value that opened and copied from HxD program:
Dim rawData As Byte() = { _
&H56, &H47, &H7B, &HFA, &H81, &H51, &H00, &HAF, &HA7, &HAA, &HCE, &H9C, _
&H7A, &H23, &HDA, &H4D _
}

So any solution please?

Edit: After looking into the output value, i determined the problem that It returned 0 instead of 00 if it's empty

Also after getting the hex values, can i convert it back to byte and write it to a file?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Read File as bytearray then convert them into hex:
Private Function GetBytes(ByVal filename As String) As Byte()
    Dim fs As New FileStream(filename, FileMode.Open, FileAccess.Read)
    
    ' Create a byte array of file stream length
    Dim ImageData As Byte() = New Byte(fs.Length - 1) {}
    
    'Read block of bytes from stream into the byte array
    fs.Read(ImageData, 0, System.Convert.ToInt32(fs.Length))
    
    'Close the File Stream
    fs.Close()
        'return the byte data
    Return ImageData
End Function
 
Private Function Bytes_To_Hex(ByVal bytes_Input As Byte()) As String
        Dim strTemp As New StringBuilder(bytes_Input.Length * 2)
        For Each b As Byte In bytes_Input
            strTemp.Append(Conversion.Hex(b))
        Next
        Return strTemp.ToString()
End Function
You can use another stringbuilder to store hex strings from each file-in the pattern you like- and then write stringbuilder to files.
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 550
1 OriginalGriff 460
2 Sergey Alexandrovich Kryukov 400
3 Andy Lanng 159
4 Matt T Heffron 115
0 OriginalGriff 8,519
1 Sergey Alexandrovich Kryukov 7,667
2 CPallini 4,987
3 Maciej Los 4,686
4 Mika Wendelius 3,566


Advertise | Privacy | Mobile
Web02 | 2.8.150819.1 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100