Results 1 to 6 of 6

Thread: Reading .bin file with HexViewer (Be.Hexbox) Converted to VB? *URGENT*

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2020
    Posts
    23

    Question Reading .bin file with HexViewer (Be.Hexbox) Converted to VB? *URGENT*

    As some may seen in my previous threads I'm creating some software for my Automotive chip tuning shop. I'm stuck on a problem that I cant fix.
    When opening files the hexbox reads them in 8BIT (example: 00 C8 01 90 02 BC 03 E8 04 E2 05 DC 06 D6 07 D0) but I Want to read them as:
    51200 36865 48130 59395 . I'm currently not sure if It is even possible with the converted project I'm using and with its dll's. Note that I'm not a professional and I may be saying something wrong.
    I've sourced the source code for the project I'm working on (basically the be.hexbox project converted to vbnet and changed so that you open a file with opnfldialog and a few changes more.)
    For some stupid things with my other acc people helped me in 5mins, but with this serious problem no one has came forward to atleast point me in the right direction, I'm wiling to pay if somebody won't help me for free, cause
    It's not some stupid project I'm doing for fun.
    Every help is gratelly appreciated. Thank you.

    The code that fills the hexbox with the opened file: (if it means something to anybody)
    Code:
    Dim bytes() As Byte
                bytes = File.ReadAllBytes(Main.Label3.Text) ' location of the file that's going to be opened
                Dim bytes1 As Byte() = bytes
                Dim dbp As New DynamicByteProvider(bytes1)
                Main.hexBox.ByteProvider = dbp

    source: http://www.mediafire.com/file/lesgx6...etest.rar/file


    Name:  ss.jpg
Views: 148
Size:  37.6 KB
    Last edited by vargaperformance; Oct 25th, 2020 at 07:12 AM.

  2. #2
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,726

    Re: Reading .bin file with HexViewer (Be.Hexbox) Converted to VB? *URGENT*

    51200 in base10 = 0xC800 so to go from what you have to what you want requires you to read the bytes you have in pairs, reorder those pairs, combine the pairs into a single hex value and convert that value to a base ten number.

    Something like this free hand code would do it

    Code:
    Dim decValues as new list(of string)
    for i as integer = 0 to bytes.Lenght-1 Step 2
    
    'read the pair
       dim b0 as Byte = bytes(i)
       dim b1 as Byte = bytes(i+1)
    
    'combine the pairs in reverse order
       dim hexString as string = $"{b1}{b0}"
    
    'convert the hex and add it to the list
       dim decValue = Convert.ToInt32(hexString  , 16)
       decValues.Add(decValue)
    next
    It's not tested, but that's the gist of what you need to do. Once that loop completes, you should have your decimal values in the decValues list to do with whatever you need.

    Whether or not you can implement that depends on your project and your level of programming knowledge.
    HTH
    Kevin
    Last edited by kebo; Oct 25th, 2020 at 08:30 AM.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2020
    Posts
    23

    Re: Reading .bin file with HexViewer (Be.Hexbox) Converted to VB? *URGENT*

    I can't seem to make it work. Or rather I maybe don't know how to make it work. Everytime I end up with a result: "2445909"

    Link for file I'm trying: http://www.mediafire.com/file/3c6s6c..._file.bin/file

    Code:

    Code:
      Dim bytes() As Byte
            bytes = File.ReadAllBytes(Label3.Text) ' label3 is the location of the opened file using openfiledialog
            Dim b As Byte() = bytes
            Dim decValues As New List(Of String)
            For i As Integer = 0 To bytes.Length - 1 Step 2
                'read the pair
                Dim b0 As Byte = bytes(i)
                Dim b1 As Byte = bytes(i + 1)
                'combine the pairs in reverse order
                Dim hexString As String = $"{b1}{b0}"
                'convert the hex and add it to the list
                Dim decValue = Convert.ToInt32(hexString, 16)
                TextBox1.Text = decValue
            Next

  4. #4
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,304

    Re: Reading .bin file with HexViewer (Be.Hexbox) Converted to VB? *URGENT*

    Use a break point and step through your code, examining the values of the variables as you go.

    When you start off, b0 and b1 will both be set to 255 (Hex FF). So Dim hexString As String = $"{b1}{b0}" is going to produce the string value "255255" which you treat as Hex for the purposes of creating a decimal value. 0x255255 is 2445909 decimal.

    Instead of converting byte values to strings, concatenating the strings and then converting the resulting string to an integer, it would be more efficient to multiply b1 by 256 and add to b0:
    Code:
    'read the pair
    Dim b0 As Byte = bytes(i)
    Dim b1 As Byte = bytes(i + 1)
    Dim decValue = b1 * 256 + b0
    TextBox1.Text = decValue.ToString
    You are also overwriting the contents of the TextBox every time through the loop, so you'll only ever see one value displayed; the value of the last pair of bytes.

    And always work with Option Strict turned On to minimize errors arising from implicit Type conversions.

  5. #5
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,726

    Re: Reading .bin file with HexViewer (Be.Hexbox) Converted to VB? *URGENT*

    Quote Originally Posted by Inferrd View Post
    So Dim hexString As String = $"{b1}{b0}" is going to produce the string value "255255"
    Good catch. I wasn't even thinking we were dealing with numbers not strings. That's what I get for freehand code.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  6. #6
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,318

    Re: Reading .bin file with HexViewer (Be.Hexbox) Converted to VB? *URGENT*

    why not using bitconverter?

    try this:
    Code:
    Dim bytes() As Byte
    bytes = File.ReadAllBytes(Main.Label3.Text) ' location of the file that's going to be opened
    dim Integers() as int16=enumerable.range(0,bytes.length\2).Select(function(i) bitconverter.Toint16(bytes,i*2)).toarray
    TextBox1.Text=string.join(",",integers)

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