Results 1 to 19 of 19

Thread: [2008] How to open HEX file

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    11

    Question [2008] How to open HEX file

    I have problem, how I can import HEX file to my program in VB .NET? And I have question if I can import, What size of file I can import? I have 200MB - 400MB HEX files?? Can I import so huge files? Thanks for all yours replays.

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2008] How to open HEX file

    do you want to read the file, or add it as part of the project. btw - all files are stored as binary, therefore they are all hex, since hex is just a representation of binary.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: [2008] How to open HEX file

    If you want to view a file in Hex goto, File > Open File, select your file, click the little arrow on the open button, select Open with, and select Binary editor, and hit OK.
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    11

    Re: [2008] How to open HEX file

    I write programe. It work that:
    1. You chose Hex file
    2. Program open hex file and save as string.
    3. Program search in Hex some text
    4. Program save this string in text file.

    I have problem with open file. I want do string function on this hex file, like left, right, mid, replace. Can I do It, If yes How??

    So my problem is import HEX as String to VB .NET

  5. #5
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: [2008] How to open HEX file

    1. Research open file dialog
    2. Research io.binaryreader
    3. Research binary to hex conversion
    4. Research io.binarywriter
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    11

    Re: [2008] How to open HEX file

    Quote Originally Posted by wild_bill
    1. Research open file dialog
    2. Research io.binaryreader
    3. Research binary to hex conversion
    4. Research io.binarywriter
    1. I know how to do it.
    2,3,4. Can you write code whitch open hex file like aaa.hex and convert it into string?

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2008] How to open HEX file

    Quite possibly no. A string can be either ASCII (one byte per character), Unicode (two bytes per character), or something else (encoded or compressed). If you know that the string is either ASCII or Unicode, then you can convert it easily, as you would be converting a byte array to a string. However, if you don't know how the string is represented in the file, it won't be quite so easy. I suppose you could try it in ASCII and see whether or not it is readable, and if it isn't, then try it in unicode, but it would be best if you knew which it was to start with, and if it is neither ASCII nor Unicode, you may well have a very difficult time converting it.
    My usual boring signature: Nothing

  8. #8

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    11

    Re: [2008] How to open HEX file

    Do you see any hex editor. I want have somethink like in all editors window in string.
    I want have this:

    in string.

  9. #9

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    11

    Re: [2008] How to open HEX file

    Any one can help me?

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2008] How to open HEX file

    Oh, so you actually want to see the byte values rather than trying to interpret the byte values as text?
    My usual boring signature: Nothing

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] How to open HEX file

    vb.net Code:
    1. Dim builder As New System.Text.StringBuilder
    2.  
    3. Using reader As IO.FileStream = IO.File.OpenRead("file path here")
    4.     Dim length As Long = reader.Length
    5.  
    6.     Do Until reader.Position = length
    7.         If reader.Position > 0L Then
    8.             builder.Append(" "c)
    9.         End If
    10.  
    11.         builder.Append(reader.ReadByte().ToString("X2"))
    12.     Loop
    13. End Using
    14.  
    15. MessageBox.Show(builder.ToString())
    Adjust as required.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  12. #12

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    11

    Re: [2008] How to open HEX file

    Quote Originally Posted by jmcilhinney
    vb.net Code:
    1. Dim builder As New System.Text.StringBuilder
    2.  
    3. Using reader As IO.FileStream = IO.File.OpenRead("file path here")
    4.     Dim length As Long = reader.Length
    5.  
    6.     Do Until reader.Position = length
    7.         If reader.Position > 0L Then
    8.             builder.Append(" "c)
    9.         End If
    10.  
    11.         builder.Append(reader.ReadByte().ToString("X2"))
    12.     Loop
    13. End Using
    14.  
    15. MessageBox.Show(builder.ToString())
    Adjust as required.

    Big thx. This is what I want. But I have one requied. I want have this string with out spaces after all pars of binary. If the code is "31 32 32", I want "313232". What i must do??

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] How to open HEX file

    What you must do is read the code. You may be new but it shouldn't be very hard to work out where the spaces are being added. You can then simply remove the code that does it. Think first, ask questions later.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  14. #14
    New Member
    Join Date
    Jan 2012
    Posts
    4

    Re: [2008] How to open HEX file

    I am using this code that you posted
    Code:
        Dim builder As New System.Text.StringBuilder
        Using reader As IO.FileStream = IO.File.OpenRead("file path here")
            Dim length As Long = reader.Length
            Do Until reader.Position = length
                If reader.Position > 0L Then
                    builder.Append(" "c)
                End If
                builder.Append(reader.ReadByte().ToString("X2"))
            Loop
        End Using
        MessageBox.Show(builder.ToString())
    How would i now save the file?

  15. #15
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] How to open HEX file

    Quote Originally Posted by Sutton2k9 View Post
    I am using this code that you posted
    Code:
        Dim builder As New System.Text.StringBuilder
        Using reader As IO.FileStream = IO.File.OpenRead("file path here")
            Dim length As Long = reader.Length
            Do Until reader.Position = length
                If reader.Position > 0L Then
                    builder.Append(" "c)
                End If
                builder.Append(reader.ReadByte().ToString("X2"))
            Loop
        End Using
        MessageBox.Show(builder.ToString())
    How would i now save the file?
    As you can see from reading and running the code, 'builder.ToString()' returns a String containing the hex data. A String is a String. How would you usually save a String to a file?

    http://www.google.com.au/search?q=sa...ient=firefox-a
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  16. #16
    New Member
    Join Date
    Jan 2012
    Posts
    4

    Re: [2008] How to open HEX file

    Quote Originally Posted by jmcilhinney View Post
    As you can see from reading and running the code, 'builder.ToString()' returns a String containing the hex data. A String is a String. How would you usually save a String to a file?

    http://www.google.com.au/search?q=sa...ient=firefox-a
    This is what the first line of file looks like in hex editor
    Code:
    CON ...e.(aX853932-001..
    After i have opened it then saved it with out making any changes this is what it looks like
    Code:
    43 4F 4E 20 01 A8 03 65
    The code needs to be change from hex before saving it.
    Do you see what i mean?

  17. #17
    New Member
    Join Date
    Jan 2012
    Posts
    4

    Re: [2008] How to open HEX file

    I know how to save it as a string i want to open it change a hex value then save it not as a string.
    I think it has to be changed back into bytes
    This is what the first line of file looks like in hex editor
    Code:
    CON ...e.(aX853932-001..
    After i have opened it then saved it with out making any changes this is what it looks like
    Code:
    43 4F 4E 20 01 A8 03 65
    The code needs to be change from hex before saving it.
    Do you see what i mean?

  18. #18
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] How to open HEX file

    Quote Originally Posted by Sutton2k9 View Post
    I know how to save it as a string i want to open it change a hex value then save it not as a string.
    I think it has to be changed back into bytes
    This is what the first line of file looks like in hex editor
    Code:
    CON ...e.(aX853932-001..
    After i have opened it then saved it with out making any changes this is what it looks like
    Code:
    43 4F 4E 20 01 A8 03 65
    The code needs to be change from hex before saving it.
    Do you see what i mean?
    Either it's a hex file or it's not. If you open it in Notepad do you see pairs of hex characters? If so then it's a hex file and you already have your answer. If not then it's not a hex file.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  19. #19
    New Member
    Join Date
    Jan 2012
    Posts
    4

    Re: [2008] How to open HEX file

    Don't worry i have fixed it i was after a way to change the hex back to bytes so i could save them again but i worked it out

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width