Self-Modification Program in VB.Net

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi Everyone,
I have created a program with vb.net which can modify itself.
This is a specific property which can enables you for making changes in your own file run time
It basic use which i am doing is to make SubOS with VB.net
You can make it as You want
To Make your own Self Modifier Do these steps:
1)Open Visual Studio and Select Empty Project
2)Add these references:System.dll ,system.drawing.dll,System.core.dll ,system.windows.forms.dll
3)Add a vb class file and name it MForm
4)Select all data in class and paste following code in that class
<pre class="prettyprint lang-vb Imports System.Windows.Forms
Imports System.Drawing
Imports System.CodeDom.Compiler
Imports System.Diagnostics
Imports Microsoft.VisualBasic
Public Class MForm : Inherits Form
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents r As System.Windows.Forms.TextBox
Friend WithEvents t As System.Windows.Forms.RichTextBox
WithEvents tmr As New Timer With {.Enabled = False, .Interval = 10}
Dim xer As String = ""
Sub New()
InitializeComponent()
Application.EnableVisualStyles()
End Sub
Private Sub InitializeComponent()
Me.t = New System.Windows.Forms.RichTextBox()
Me.Button1 = New System.Windows.Forms.Button()
Me.r = New System.Windows.Forms.TextBox()
Me.SuspendLayout()

t

Me.t.Location = New System.Drawing.Point(12, 12)
Me.t.Name = "t"
Me.t.Size = New System.Drawing.Size(760, 525)
Me.t.TabIndex = 0
Me.t.Text = Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText("t")

Button1

Me.Button1.Location = New System.Drawing.Point(690, 543)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(82, 27)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Modify Me"
Me.Button1.UseVisualStyleBackColor = True

r

Me.r.Location = New System.Drawing.Point(12, 543)
Me.r.Name = "r"
Me.r.Size = New System.Drawing.Size(672, 20)
Me.r.TabIndex = 2
Me.r.Text = "System.dll-|-system.drawing.dll-|-system.windows.forms.dll-|-system.core.dll-|-Mi" & _
"crosoft.visualBasic.dll"

MForm

Me.ClientSize = New System.Drawing.Size(784, 582)
Me.ControlBox = False
Me.Controls.Add(Me.t)
Me.Controls.Add(Me.r)
Me.Controls.Add(Me.Button1)
Me.Name = "MForm"
Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
Me.Text = "Self Modifier"
Me.ResumeLayout(False)
Me.PerformLayout()

End Sub
Private Sub CreateEXEFile(Code As String, MainClass As String, Target As String, ref() As String)
Dim Provider As CodeDomProvider = CodeDomProvider.CreateProvider("VisualBasic")
Dim cp As CompilerParameters = New CompilerParameters()
cp.GenerateExecutable = True
cp.GenerateInMemory = False
cp.CompilerOptions = " /target:winexe /m:" + MainClass
cp.MainClass = MainClass
cp.ReferencedAssemblies.AddRange(ref)
cp.OutputAssembly = Target
cp.TreatWarningsAsErrors = False
Dim Result As CompilerResults = Provider.CompileAssemblyFromSource(cp, Code)
If Result.Errors.HasErrors Then
Dim ErrorString As String = "Compiler error:"
For Each Err As CompilerError In Result.Errors
ErrorString += Err.ToString + Chr(13)
Next
MessageBox.Show(ErrorString)
Else

End If
End Sub
Private Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
If Microsoft.VisualBasic.FileIO.Filesystem.FileExists("app2.exe") = True Then
Microsoft.VisualBasic.FileIO.FileSystem.WriteAllText("d ", "app2.exe", False)
xer = "app1.exe"
ElseIf Microsoft.VisualBasic.FileIO.Filesystem.FileExists("app1.exe") = True Then
Microsoft.VisualBasic.FileIO.FileSystem.WriteAllText("d", "app1.exe", False)
xer = "app2.exe"
End If
CreateEXEFile(t.Text, "MForm", xer, Split(r.Text, "-|-"))
tmr.Enabled = True
End Sub
Private Sub MForm_Load(sender As Object, e As System.EventArgs) Handles MyBase.Load
If Microsoft.VisualBasic.FileIO.Filesystem.FileExists("d") Then
If Microsoft.VisualBasic.FileIO.FileSystem.FileExists(Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText("d")) Then Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText("d"))
Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile("d")
End If
t.Text = Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText("t")
End Sub
Sub tmr_tick() Handles tmr.Tick
If Microsoft.VisualBasic.FileIO.FileSystem.FileExists("d") = True Then
Process.Start(xer)
Microsoft.VisualBasic.FileIO.FileSystem.WriteAllText("t", t.Text, False)
tmr.Enabled = False
Me.Close()
End If
End Sub
End Class[/code]
5)Build Project
6)Go to build path
7)create text file named "t" not "t.txt"
8)Write all the above code in that file
9)Now name the your exe file as app1.exe
and then run that file you will be able to modify your exe file
Try it and give your comments <hr class="sig Do the Impossible

View the full article
 
Back
Top