DFBarracks - Forums




Delta Force Barracks Forums - Powered by XMB 1.9.11
Delta Force Barracks Forums
Not logged in [Login - Register]
Go To Bottom

Printable Version  
Author: Subject: Tutorial : Intermediate/Advanced : Read/Write Bytes
bullet magnet
Captain
****


Avatar


Posts: 263
Registered: 6-26-2005
Member Is Offline

Mood: Modding

[*] posted on 12-30-2007 at 04:19 PM
Tutorial : Intermediate/Advanced : Read/Write Bytes


Read/Write Bytes is commonly used for cheating, but that isn't our purpose, this is just to view the bytes. The final result will look as if you are in a hex editor. Thanks to jgalley for help with hexstring to byte array.

Im simply going to give the source code since im too lazy to explain it real in depth right now, but most of it, like all VB, is self-explanatory.

Code:
[size=4] 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 [/size]




View user's profile View All Posts By User
IcIshoot
Captain
****




Posts: 306
Registered: 2-15-2004
Location: Detroit, Mi
Member Is Offline


[*] posted on 12-31-2007 at 02:00 AM


reading and righting bytes isn't just used for cheating - It is a crucial componiant of writing server manager software for games that don't have one. Such as BHD.

Or any application that does stuff with memory :D
View user's profile Visit user's homepage View All Posts By User This user has MSN Messenger
bullet magnet
Captain
****


Avatar


Posts: 263
Registered: 6-26-2005
Member Is Offline

Mood: Modding

[*] posted on 12-31-2007 at 03:51 AM


Right, it can be good, such as name-changers, thats how they are made.



View user's profile View All Posts By User

  Go To Top

Powered by XMB 1.9.11
XMB Forum Software © 2001-2012 The XMB Group
[Queries: 15] [PHP: 79.0% - SQL: 21.0%]












Copyright © 2002 - 2008 All Rights Reserved - DFBarracks.com
Site Design by A.Bullet - ScreamingDemon.com