Jump to content
Tuts 4 You

[Help] Making a patcher using VB 2008


mafia_hitman

Recommended Posts

mafia_hitman
Posted

Hey Guys,

I am having some trouble with patching a file in Visual Basic 2008.

The idea is like that ..

1-Store File In The Program Using "Resources" ..

2- If The Program Is Runned .. My Program Should Show This Message "Please Close The Program" Or Making My Program Close The Program That I want To Patch ..

3-If The Program That I want to patch is closed ..Then When you click the button .. the file dialogue opened and give to user the ability to choose the file that i whant to modify "Replace or patched" after that the file will copied from resourse and replaced the old file "Patched" after when this operation finished ..

4- show this message "Your Program Is Patched .. Enjoy" ..

Waiting The Solution

Posted

1 - What do you mean by "Store using resources" ?

Can't you just get the handle of the file ? CreateFile (OPEN_EXISTING)

2 - Check for HWND Handle (I suggest using FindWindow and getting its Class) or Check for the process (Process Status API)

3 - Not sure how it's in VB.NET, but try googling "OpenDialog VB.NET"

Create a buffer that holds the modifications from the modified file (View them with a HEX Editor) and use WriteFile on it, AssignFile to get the handle

as i said, i'm not sure how it would look like in VB.NET, but I released a patcher source code in the programming section.

4 - MessageBox.Show(?) on success ?

mafia_hitman
Posted

1 - What do you mean by "Store using resources" ?

Can't you just get the handle of the file ? CreateFile (OPEN_EXISTING)

2 - Check for HWND Handle (I suggest using FindWindow and getting its Class) or Check for the process (Process Status API)

3 - Not sure how it's in VB.NET, but try googling "OpenDialog VB.NET"

Create a buffer that holds the modifications from the modified file (View them with a HEX Editor) and use WriteFile on it, AssignFile to get the handle

as i said, i'm not sure how it would look like in VB.NET, but I released a patcher source code in the programming section.

4 - MessageBox.Show(?) on success ?

Thank U Very much ..

'sorry my english is not the best :D'

1-I mean that i store a file in my program ..

2-yes .. a U said .. that i mean :P

3-huum .. i mean that i replace the file .. (copiyng file from resources to a target) ..

4- Yes, message box on success :D

Thank U :D

Office Jesus
Posted (edited)

Here's some code from a guy named Hagenees:

I'm not sure how well it works since I don't use VB.

The comments are my own, and they are probably inaccurate.

As a last resort, look at rotem's source.


' Button clicked
Private Sub Command1_Click()' Variables
Dim f As Long ' File
Dim a As Byte ' Byte to patch
Dim b As Byte ' Byte to patch
Dim c As Byte ' Byte to patch
Dim d As Byte ' Byte to patch
Dim e As Byte ' Byte to patch' Open file
f = FreeFile()
Open "c:\Program Files\VirtualDJ\virtualdj_trial.exe" For Binary As #f' Looking at addresses?
Get #f, 327734, a
Get #f, 327735, b
Get #f, 327736, c
Get #f, 327737, d
Get #f, 327738, e' Check if bytes already patched
If a = 144 And b = 144 And c = 144 And d = 144 And e = 144 Then' Error message
MsgBox "Program already patched!"' Bytes are not patched . . .
Else' Bytes are not what they are supposed to be
If a <> 232 Or b <> 230 Or c <> 58 Or d <> 255 Or e <> 255 Then' Error message
MsgBox "File not found, The file must be located in C:\Program Files\VirtualDJ"' Patch bytes . . .
Else' Not sure what goes where the "" are
Put #f, 327734, ""
Put #f, 327735, ""
Put #f, 327736, ""
Put #f, 327737, ""
Put #f, 327738, ""' Close the file
Close #f' Patching done
MsgBox "Patching Done!"End IfEnd IfEnd Sub

That is his conversion of his original Delphi source:

(This version is my modified version + comments)

{ Hagenees Patching Routine - Modified by Office Jesus }
procedure TForm1.Button1Click(Sender: TObject);
{ Declaring Constant values }
Const
{ FileN = File Name }
FileN : String = 'Flow';
{ FileExt = File Extension (e.g., .exe) }
FileExt : String = '.exe';
{ BytesToChange = # of bytes to be patched }
BytesToChange : Integer = 4;
{ FileS = File Size (Look under the General tab in File Properties for 'Size') }
FileS : LongInt = 3301376;
{ A = Record of Offsets and Bytes to patch }
A : Array[1..4] of record
{ A = Offset to patch }
A : Longint;
{ B = New patch byte }
B : Byte;
End =
(
(A: $0013F2EC; B: $B0), { A = Offset; B = Patch byte }
(A: $0013F2ED; B: $01), { A = Offset; B = Patch byte }
(A: $0013F2EE; B: $90), { A = Offset; B = Patch byte }
(A: $0013F2EF; B: $90) { A = Offset; B = Patch byte }
);
{ Declaring Variable values }
Var
{ F = The File to be patched }
F : File;
{ Ch = The patched byte as Char }
Ch : Char;
{ i = Loop counter / index }
i : LongInt;
begin
{ fichier = OpenDialog }
{ fichier.FileName = Set the default File Name in the OpenDialog }
fichier.FileName := FileN + FileExt;
{ fichier.Filter = Set the default Filter in the OpenDialog }
fichier.Filter := FileN + FileExt;
{ Execute the OpenDialog }
if fichier.execute then
begin
{ Make F hold the file that is opened with the OpenDialog }
AssignFile(F, fichier.filename);
{ Make a .bak (backup) of the original file }
CopyFile(PChar(FileN + FileExt), PChar(FileN + '.bak'), False);
{ Open the File for reading / writing }
Reset(F, 1);
{ Compare the Size of F to the Const FileS }
{ or }
{ Check the existence of the Original Const File }
{ If either check fails, then execute the following . . . }
if (FileSize(F) <> FileS) or (FileExists(FileN + FileExt) = False) then
begin
{ Error MessageBox }
MessageBox(handle, 'The file is wrong!', 'Error!',
MB_OK or MB_ICONERROR or MB_TASKMODAL);
{ Free F }
CloseFile(F);
{ Jump to the end of the procedure }
exit;
end
{ Otherwise, patch the file }
else
begin
{ Loop for 1 to BytesToChange }
for i := 1 to BytesToChange do
begin
{ Find the Offset A[i].A in the File (F) }
Seek(F, A[i].A);
{ Assign Ch the new Byte to patch (A[i]. }
Ch := Char(A[i].;
{ Write the patch byte to the File (F) 1 time }
BlockWrite(F, Ch, 1);
end;
{ File successfully patched }
MessageBox(handle, 'The file has been patched!', 'Success!',
MB_OK or MB_ICONINFORMATION or MB_TASKMODAL);
end;
{ Free F }
CloseFile(F);
end;
end;
Edited by Office Jesus

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...