|
Web design and Programming Discuss website creation and other programming topics. |
![]() |
|
Thread Tools | Search this Thread | Display Modes |
#1
|
||
|
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
__________________
Delta Force 2 Enhanced Modding Site, new and improved with forum. |
#2
|
||
|
![]()
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. ![]() |
#3
|
||
|
![]()
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. ![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
![]() |
||||
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 |