Results 1 to 19 of 19

Thread: [RESOLVED] really hard

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2009
    Posts
    54

    Resolved [RESOLVED] really hard

    hi people again

    I am trying it somethink like 1 hour ago,

    but i cant!

    i am trying to read a file by BYTE position -> image = Mid("C:\file.exe", 13, 14)
    it must show me the byte 13 and byte 14, right?

    but, when I do it, I dont see the byte 13 and not the byte 14, like in the image:



    my result must be: 2003, but I cant!

    can someone helps me?

  2. #2

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2009
    Posts
    54

    Re: really hard

    but can you explain? it returns me: ack. when I use Mid("C:\file.exe", 13, 4)

  4. #4
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: really hard

    The data you are reading from *ISN'T* in the format you're trying to read, ASCII is the format the data is in (a char of ASCII value 0-255) while you want hex (two chars of ASCII value 0-15). You need to read two bytes of data in and convert it to hex.
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  5. #5
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: really hard

    TheMarks

    Per Marty's suggestion, please note that the 3rd parameter of
    the Mid function specifies the number of characters to be read
    from the starting position (which is the 2nd parameter).

    So, your Mid("C:\file.exe", 13, 14) will read 14 characters, starting
    at character 13.

    If you only want byte 13 and byte 14, you could alternatively put
    the file into a byte array, say aaBYTE. Then just look at the contents of
    aaBYTE(13) and aaBYTE(14). It should be 20 and 03 respectively.

    Spoo

  6. #6

    Thread Starter
    Member
    Join Date
    Oct 2009
    Posts
    54

    Re: really hard

    ok

    in the imagem we can see the byte 13 and 14 selected right?

    why when I use

    image = Mid(globalfile, 13, 4)
    msgbox image

    I get {L{L ..

    look the image:



    I just want to get into a text box the numbers : 20 03
    just it!

  7. #7
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: really hard

    TheMarks

    Probably because hex(20) and hex(03) are non-printable
    characters. The Mid function is for character strings, NOT
    for reading hex. I think you ought to give the byte array
    idea a look-see

    Spoo

  8. #8
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: really hard

    Quote Originally Posted by smUX View Post
    The data you are reading from *ISN'T* in the format you're trying to read, ASCII is the format the data is in (a char of ASCII value 0-255) while you want hex (two chars of ASCII value 0-15). You need to read two bytes of data in and convert it to hex.
    My last post on the matter (and any thread asking for help from you)...the data you want is stored as an ASCII value and Hex Workshop converts this to HEX format...mid() isn't going to get you HEX values no matter how many times you use it if the file it is taking the data from isn't IN HEX FORMAT
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  9. #9

    Thread Starter
    Member
    Join Date
    Oct 2009
    Posts
    54

    Re: really hard

    so HOW can I read the HEX part of the file?

  10. #10
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: really hard

    Quote Originally Posted by Spoo View Post
    TheMarks

    Probably because hex(20) and hex(03) are non-printable
    characters. The Mid function is for character strings, NOT
    for reading hex. I think you ought to give the byte array
    idea a look-see
    Although technically your idea isn't quite right, if done right it won't return 20 and 03 because it's returning the ASCII value for the byte rather than the two-byte hex value he's looking for :-P
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  11. #11
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: really hard

    Quote Originally Posted by TheMarKs View Post
    so HOW can I read the HEX part of the file?
    There's no such thing as a "HEX part" of the file...the file is in ASCII format, that's how it is, deal with it...and you deal with it by getting the relevant ASCII section and converting it to HEX...

    ...Or explain what you're trying to actually achieve and maybe someone can suggest a better method that doesn't require hexadecimal data...not me though, I'm outta here.
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  12. #12

    Thread Starter
    Member
    Join Date
    Oct 2009
    Posts
    54

    Re: really hard

    Thats a image header, from a gamesystem ..

    If i can read the 20 03, I can invert to 03 20 = 800, then I have the width of the image, understand?

    in ALL the files I want to read, this information is allocated into byte 13 and 14 .. because that I need to read this bytes ..

  13. #13
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: really hard

    See, now you've said it, much easier to hopefully help...

    Code:
    tx = "            " & Chr(3) & Chr(32) & "    " 'byte 13 and 14 match the info needed
    hx = Format$(Hex$(Asc(Mid(tx, 14, 1))), "00") & Format$(Hex$(Asc(Mid(tx, 13, 1))), "00")
    tx is just temporary to test it...if you replace the tx in the second line with the variable you're using for the data it'll take the bytes from the relevant part and convert them...

    ...HOWEVER if you just want to convert the two bytes to the value 800 there's no need to do any hex conversion at all...replace that second line with:

    Code:
    hx = Asc(Mid(tx, 14, 1)) + (Asc(Mid(tx, 13, 1)) * 256):
    and you will find that hx = 800 or whatever the value is supposed to be (assumedly it'll change from file to file)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  14. #14
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: really hard

    Quote Originally Posted by smUX View Post
    Although technically your idea isn't quite right, if done right it won't return 20 and 03 because it's returning the ASCII value for the byte rather than the two-byte hex value he's looking for :-P
    Yes.. after I posted, it struck me that I had taken some, ahem,
    artistic liberties with my post .. thanks for pointing it out.

    Spoo

  15. #15

    Thread Starter
    Member
    Join Date
    Oct 2009
    Posts
    54

    Re: really hard

    smux, using it:

    Dim image As String
    image = Asc(Mid(globalfile, 14, 1)) + (Asc(Mid(globalfile, 13, 1)) * 256)
    txt1.Text = image

    remember: byte 13 = 20, byte 14 = 03

    i got txt1.text = 19579

    and when use txt1.Text = dec2hex(image) i got 7b4c, and 7b4c isnt the byte 13 and 14 ..

    what do you suggest?
    Last edited by TheMarKs; Jan 21st, 2010 at 04:38 PM.

  16. #16
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: really hard

    TheMarks, can you upload the txt file you are using. Probably only need the first 30 bytes or so if it is quite large. Also, what value are you expecting?

    Note: Hex 20 = decimal 32 & Hex 03 = decimal 3
    So depending on how you read it and multiply, you get 2 different values:
    32 * 256 + 3 = 8195 whereas 3 * 256 + 32 = 800 & is probably the answer you need

    How you got 19579 is beyond me at the moment; this is where a sample text file would be useful.
    Edited: 19579 = Hex 4C * 256 + Hex 7B; now I see where you got that; you were reading another section of the file.
    Last edited by LaVolpe; Jan 21st, 2010 at 04:51 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  17. #17

    Thread Starter
    Member
    Join Date
    Oct 2009
    Posts
    54

    Re: really hard

    ye, the files is here http://www.sendspace.com/file/0gjfvy

    and look the value is 20 03, if you invert to 03 20, its 800, understand?
    Last edited by TheMarKs; Jan 21st, 2010 at 04:55 PM.

  18. #18
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: really hard

    Ok, this was made far much more difficult than necessary.

    1. The file you linked us to is in binary format, not ASCII. It is not a text file.
    2. If you know the byte offset into the file that you need to read and the number of bytes...
    Code:
    ' integer is 2 bytes, since you only want to read two bytes
    ' and you know what offsets into the file....
        Dim iWidth As Integer, iHeight As Integer
        Dim fnr As Integer
        fnr = FreeFile
        Open yourfilename For Binary As #fnr
        Get #fnr, 13, iWidth
        Get #fnr, 17, iHeight
        Close #fnr
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  19. #19

    Thread Starter
    Member
    Join Date
    Oct 2009
    Posts
    54

    Re: really hard

    woow thank you lavolpe and thanks to every1 who tryies to help me!

    the code is working:

    Private Sub Form_Load()
    ' integer is 2 bytes, since you only want to read two bytes
    ' and you know what offsets into the file....
    Dim iWidth As Integer, iHeight As Integer
    Dim fnr As Integer
    fnr = FreeFile
    Open "C:\avatar_back.img" For Binary As #fnr
    Get #fnr, 13, iWidth
    Get #fnr, 17, iHeight
    Text1.Text = iWidth & "x" & iHeight
    Close #fnr
    End Sub

    img:

    thank you!

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