Go Back   Novahq.net Forum > Computers > Web design and Programming

Web design and Programming Discuss website creation and other programming topics.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-18-2009, 03:11 PM
--BulletMagnet-- is offline --BulletMagnet--
--BulletMagnet--'s Avatar
DF2 Forever

Join Date: Jun 2005
Location: USA
Posts: 718

Send a message via MSN to --BulletMagnet--
VB.net Hex Editing

This is a little more difficult.

Code:
Public Class Form1
    Private Shared Function HexStringToByteArray(ByRef strInput As String)
As Byte()
        Dim length As Integer
        Dim bOutput As Byte()
        Dim c(1) As Integer
        length = strInput.Length / 2
        ReDim bOutput(length - 1)
        For i As Integer = 0 To (length - 1)
            For j As Integer = 0 To 1
                c(j) = Asc(strInput.Chars(i * 2 + j))
                If ((c(j) >= Asc("0")) And (c(j) <= Asc("9"))) Then
                    c(j) = c(j) - Asc("0")
                ElseIf ((c(j) >= Asc("A")) And (c(j) <= Asc("F"))) Then
                    c(j) = c(j) - Asc("A") + &HA
                ElseIf ((c(j) >= Asc("a")) And (c(j) <= Asc("f"))) Then
                    c(j) = c(j) - Asc("a") + &HA
                End If
            Next j
            bOutput(i) = (c(0) * &H10 + c(1))
        Next i
        Return (bOutput)
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
        Dim myFile As String = "..\..\Test.jpg"
        Dim myBytes As Byte() =
My.Computer.FileSystem.ReadAllBytes(myFile)
        Dim txtTemp As New System.Text.StringBuilder()
        For Each myByte As Byte In myBytes
            txtTemp.Append(myByte.ToString("X2"))
        Next
        RichTextBox1.Text = txtTemp.ToString()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
        Dim myFile As String = "..\..\Test2.jpg"
        Dim myBytes As Byte() = HexStringToByteArray(RichTextBox1.Text)
        My.Computer.FileSystem.WriteAllBytes(myFile, myBytes, False)
    End Sub
End Class
Copyright (c) 2008 Bullet Magnet. All Wrongs Reserved.
Reply With Quote
  #2  
Old 11-19-2012, 01:37 PM
ghack2k is offline ghack2k
Registered User

Join Date: Nov 2012
Posts: 2

Confused This works very well but...

Hello,

this code works very well but ONLY for files under 2GB...

if we use this in files bigger we will get an "out of memory" exception..

I was digging and searching arround and i did realize that we can read this in chunks to avoid this exception... But i couldn't realize how to use the chunks and add to this code.

Does anyone knows how to do it? How can we read a file bigger than 2GB without giving the "out of memory" exception ?

Thanks in advanced.
Reply With Quote
  #3  
Old 11-19-2012, 02:02 PM
ghack2k is offline ghack2k
Registered User

Join Date: Nov 2012
Posts: 2

Sad This works very well but...

Hello,

this works very well but ONLY for files under 2GB... if we choose any file bigger it will throw an "out of memory" exception

I have digging and searching arround and i know that we can make the file/bytes reading by chunks to avoid the "out of memory" error. However i couldn't realize how to do this or how to adapt this to this code.

Does anyone knows how can we read files bigger that 2GB without errors? Does anyone knows how to adapt the chunks reading here?

Thanks in advanced.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Read .MIS files with Style. (VB.net) --BulletMagnet-- Web design and Programming 9 01-19-2009 07:20 PM
Vb.net!!!! JonM Web design and Programming 16 09-04-2005 06:09 PM
Hex .Simon. Sigs and Graphics 1 02-27-2004 03:30 PM
hex name editor IKILLU Delta Force 5 02-09-2003 12:30 PM
HEX NAME? }{ell}{0uNd*MWF Delta Force 0 05-12-2002 12:38 PM


All times are GMT -5. The time now is 10:36 AM.




Powered by vBulletin®