Results 1 to 19 of 19

Thread: bytes

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Location
    USA - Michigan
    Posts
    94

    Resolved bytes

    is vb capable of going to cetrain offsets in a file and editing single bytes?

    if so wht do i need to know?
    Last edited by Hacker; Oct 27th, 2004 at 03:20 PM.
    --Semper Fi--

    --Area 61 Admin--

  2. #2
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457
    Not really. You can load an array of bytes and access them using the array index though. Does that help?
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Sure it can. The following code opens a file, gets the byte at position 87, checks if it is the letter A and if it isn't sets it to the letter A. Check out these I/O functions in your help file - Open, Get, Put, Seek (statement), Seek (function), LOC, LOF, Close

    VB Code:
    1. Dim lngFileNo as Long
    2. Dim bytData as Byte
    3.  
    4. lngFileNo = FreeFile
    5.  
    6. Open FileName For Binary As lngFileNo
    7.  
    8. Get lngFileNo, 87, bytData
    9.  
    10. If bytData <> Asc("A") then
    11.    Put lngFileNo, 87, asc("A")
    12. End If
    13.  
    14. Close lngFileNo

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Location
    USA - Michigan
    Posts
    94
    ok i need to get to offset 0x3A7E3

    and chnage it from 0D to 00

    how would i do this?

    cuz that way didn't work
    --Semper Fi--

    --Area 61 Admin--

  5. #5

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Location
    USA - Michigan
    Posts
    94
    no i did not...i guess i'll have to find my hex calc
    --Semper Fi--

    --Area 61 Admin--

  7. #7

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Location
    USA - Michigan
    Posts
    94
    thanks for that...it will help..not sure if this is resolved cuz i havn't tried it...still gotta another project to get done

    btw is there an equation for this....or wht...hex calc?
    --Semper Fi--

    --Area 61 Admin--

  9. #9
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989
    Windows calculator can do that

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Location
    USA - Michigan
    Posts
    94
    plz expand on this
    --Semper Fi--

    --Area 61 Admin--

  11. #11
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989
    attached
    Attached Images Attached Images  

  12. #12
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    There is no conversion necessary, VB will handle everything. In VB, you represent hexadecimal numbers directly by using the prefix &H instead of 0x.

    VB Code:
    1. Dim lngFileNo As Long
    2. Dim bytData As Byte
    3.  
    4. lngFileNo = FreeFile
    5.  
    6. Open FileName For Binary As lngFileNo
    7.  
    8. Get lngFileNo, &H3A7E3, bytData
    9.  
    10. If bytData <> &HD Then
    11.    Put lngFileNo, &H3A7E3, &H0
    12. End If
    13.  
    14. Close lngFileNo

  13. #13
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457
    Opps - misread the original request. I thought hacker was refering to memory blocks (assembler background kicked in) not files. Apologies for the bum steer.
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  14. #14
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457
    But actually, I am wrong again. This explains the first steps of even doing that (using StrPtr, VarPtr and ObjPtr). You live and learn.
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Location
    USA - Michigan
    Posts
    94
    alright thats awesome thanks alot to all who helped
    --Semper Fi--

    --Area 61 Admin--

  16. #16
    Junior Member
    Join Date
    Dec 2006
    Posts
    29

    Re: bytes

    First off, I am terribly sorry for bringing up a topic thats been buried for 3 years. But I couldn't find any others on my question.
    My question is that is there a way to select a region like &H420 to &H430 and check for the things in there and edit it at once? Along the lines of something like:
    Code:
    Dim lngFileNo As Long
          Dim bytData As Byte
          lngFileNo = FreeFile
           Open FileName For Binary As lngFileNo
          Get lngFileNo, &H3A7E3, bytData
          If bytData <> &HD Then
             Put lngFileNo, &H3A7E3, &H0
          End If
                 Close lngFileNo

  17. #17
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: bytes

    Get all the bytes in the range and put them into an array.

    Code:
    Dim bytData() as Byte
    Redim bytData(&H430 - &H420)
    Get lngFileNo, &H3A7E3, bytData
    'code to check and change bytData array
    'now overwrite the existing data in the file
    Put lngFileNo, &H3A7E3, bytData
    Just be careful when working with binary files at the byte level. If anything is incorrect the file could become "corrupt"...

  18. #18
    Junior Member
    Join Date
    Dec 2006
    Posts
    29

    Re: bytes

    ah thank you so much for the quick reply
    but i have 1 more question, is there a way to put together &H and a variable i want to do &H & var & but it just wont work :S

  19. #19
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: bytes

    Quote Originally Posted by majin
    First off, I am terribly sorry for bringing up a topic thats been buried for 3 years. But I couldn't find any others on my question.
    My question is that is there a way to select a region like &H420 to &H430 and check for the things in there and edit it at once? Along the lines of something like:
    Code:
    Dim lngFileNo As Long
          Dim bytData As Byte
          lngFileNo = FreeFile
           Open FileName For Binary As lngFileNo
          Get lngFileNo, &H3A7E3, bytData
          If bytData <> &HD Then
             Put lngFileNo, &H3A7E3, &H0
          End If
                 Close lngFileNo
    Next time we'd prefer if you started a new thread.

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