EDN Admin
Well-known member
So I have a script that runs once a button is clicked in my windows form application. The script involves three separate processes that need to act sequentially or else it will not work. The initial process decompiles a file into a temporary directory, Once it is done the replace command is used to modify two strings in a single ASCII file (this is where the problem lies). This process works, but I need a way to make sure that it is entirely finished before proceeding to recompiling the script and deleting the temporary directory.
Does anyone know a way to attach the replace command to a process like WaitForExit() or make it run for every line in the file? I have been browsing and I have not found a good solution. Here is some of my codeublic Class Form3
Private Sub Button7_Click(sender As System.Object, e As System.EventArgs) Handles Button7.Click
If TextBox4.Text = "" Then
MessageBox.Show("Please select a directory")
Else
Dim fd As OpenFileDialog = New OpenFileDialog()
Dim strFileName As String
fd.Title = "Open File Dialog"
fd.InitialDirectory = TextBox1.Text
fd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
fd.FilterIndex = 2
fd.RestoreDirectory = True
If fd.ShowDialog() = DialogResult.OK Then
strFileName = fd.FileName
If InStr(strFileName, ".swf") <> 0 Then
TextBox2.Text = strFileName
Else
MessageBox.Show("You have to pick a .swf silly...")
End If
End If
End If
End Sub
Private Sub Button8_Click(sender As System.Object, e As System.EventArgs) Handles Button8.Click
Me.Close()
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim Folder = TextBox4.Text & "HEXED"
If TextBox2.Text = "" Then
MessageBox.Show("You have to pick a .swf silly...")
Else
If My.Computer.FileSystem.DirectoryExists(Folder) Then
My.Computer.FileSystem.DeleteDirectory(Folder, FileIO.DeleteDirectoryOption.DeleteAllContents)
End If
My.Computer.FileSystem.CopyDirectory("C:UsersMattDocumentsMy_GamesROTMGShadyGamerWindowsApplication1WindowsApplication1RABCDasm", Folder)
My.Computer.FileSystem.CopyFile(TextBox2.Text, Folder & "client.swf", True)
Dim FILE_NAME As String = Folder & "decompile.bat"
Dim i As Integer
Dim aryText(4) As String
aryText(0) = "cd " & Folder
aryText(1) = "swfdecompress client.swf"
aryText(2) = "abcexport client.swf"
aryText(3) = "rabcdasm client-1.abc"
Dim objWriter As New System.IO.StreamWriter(FILE_NAME, False)
For i = 0 To 3
objWriter.WriteLine(aryText(i))
Next
objWriter.Close()
Dim Process1 As New System.Diagnostics.Process
Dim psi As New ProcessStartInfo(Folder & "decompile.bat")
psi.RedirectStandardError = True
psi.RedirectStandardOutput = True
psi.CreateNoWindow = False
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.UseShellExecute = False
Process1.StartInfo = psi
Process1.Start()
Process1.WaitForExit()
Const quote As String = """"
Dim MyFile As String = Folder & "client-1comcompanyassembleegameclientparametersParameters.class.asasm"
Dim str_new, str_old
str_old = MyFile.ToString
str_new = Replace(str_old, quote & TextBox1.Text & quote, quote & TextBox3.Text & quote, 1, 2)
Dim objWriter3 As New System.IO.StreamWriter(MyFile, False)
objWriter3.Write(str_new)
Dim FILE_NAME2 As String = Folder & "recompile.bat"
Dim j As Integer
Dim aryText2(4) As String
aryText2(0) = "cd " & Folder
aryText2(1) = "rabcasm client-1client-1.main.asasm"
aryText2(2) = "abcreplace client.swf 1 client-1client-1.main.abc"
Dim objWriter2 As New System.IO.StreamWriter(FILE_NAME2, False)
For j = 0 To 2
objWriter2.WriteLine(aryText2(j))
Next
objWriter2.Close()
Dim Process2 As New Process
Dim ps As New ProcessStartInfo(Folder & "recompile.bat")
ps.RedirectStandardError = True
ps.RedirectStandardOutput = True
ps.CreateNoWindow = False
ps.WindowStyle = ProcessWindowStyle.Hidden
ps.UseShellExecute = False
Dim recompile As Process = Process.Start(ps)
Process2.StartInfo = ps
Process2.Start()
Process2.WaitForExit()
My.Computer.FileSystem.CopyFile(Folder & "client.swf", TextBox4.Text & "Hexed.swf", True)
My.Computer.FileSystem.DeleteDirectory(Folder, FileIO.DeleteDirectoryOption.DeleteAllContents)
MessageBox.Show("Client has been hexed and named Hexed.swf")
End If
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim MyFolderBrowser As New System.Windows.Forms.FolderBrowserDialog
MyFolderBrowser.Description = "Select the Folder"
MyFolderBrowser.ShowNewFolderButton = False
Dim dlgResult As DialogResult = MyFolderBrowser.ShowDialog()
If dlgResult = Windows.Forms.DialogResult.OK Then
TextBox4.Text = MyFolderBrowser.SelectedPath
End If
End Sub
End Class
This is the code for the entire form. The part I that is not working is under Button1_Click
View the full article
Does anyone know a way to attach the replace command to a process like WaitForExit() or make it run for every line in the file? I have been browsing and I have not found a good solution. Here is some of my codeublic Class Form3
Private Sub Button7_Click(sender As System.Object, e As System.EventArgs) Handles Button7.Click
If TextBox4.Text = "" Then
MessageBox.Show("Please select a directory")
Else
Dim fd As OpenFileDialog = New OpenFileDialog()
Dim strFileName As String
fd.Title = "Open File Dialog"
fd.InitialDirectory = TextBox1.Text
fd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
fd.FilterIndex = 2
fd.RestoreDirectory = True
If fd.ShowDialog() = DialogResult.OK Then
strFileName = fd.FileName
If InStr(strFileName, ".swf") <> 0 Then
TextBox2.Text = strFileName
Else
MessageBox.Show("You have to pick a .swf silly...")
End If
End If
End If
End Sub
Private Sub Button8_Click(sender As System.Object, e As System.EventArgs) Handles Button8.Click
Me.Close()
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim Folder = TextBox4.Text & "HEXED"
If TextBox2.Text = "" Then
MessageBox.Show("You have to pick a .swf silly...")
Else
If My.Computer.FileSystem.DirectoryExists(Folder) Then
My.Computer.FileSystem.DeleteDirectory(Folder, FileIO.DeleteDirectoryOption.DeleteAllContents)
End If
My.Computer.FileSystem.CopyDirectory("C:UsersMattDocumentsMy_GamesROTMGShadyGamerWindowsApplication1WindowsApplication1RABCDasm", Folder)
My.Computer.FileSystem.CopyFile(TextBox2.Text, Folder & "client.swf", True)
Dim FILE_NAME As String = Folder & "decompile.bat"
Dim i As Integer
Dim aryText(4) As String
aryText(0) = "cd " & Folder
aryText(1) = "swfdecompress client.swf"
aryText(2) = "abcexport client.swf"
aryText(3) = "rabcdasm client-1.abc"
Dim objWriter As New System.IO.StreamWriter(FILE_NAME, False)
For i = 0 To 3
objWriter.WriteLine(aryText(i))
Next
objWriter.Close()
Dim Process1 As New System.Diagnostics.Process
Dim psi As New ProcessStartInfo(Folder & "decompile.bat")
psi.RedirectStandardError = True
psi.RedirectStandardOutput = True
psi.CreateNoWindow = False
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.UseShellExecute = False
Process1.StartInfo = psi
Process1.Start()
Process1.WaitForExit()
Const quote As String = """"
Dim MyFile As String = Folder & "client-1comcompanyassembleegameclientparametersParameters.class.asasm"
Dim str_new, str_old
str_old = MyFile.ToString
str_new = Replace(str_old, quote & TextBox1.Text & quote, quote & TextBox3.Text & quote, 1, 2)
Dim objWriter3 As New System.IO.StreamWriter(MyFile, False)
objWriter3.Write(str_new)
Dim FILE_NAME2 As String = Folder & "recompile.bat"
Dim j As Integer
Dim aryText2(4) As String
aryText2(0) = "cd " & Folder
aryText2(1) = "rabcasm client-1client-1.main.asasm"
aryText2(2) = "abcreplace client.swf 1 client-1client-1.main.abc"
Dim objWriter2 As New System.IO.StreamWriter(FILE_NAME2, False)
For j = 0 To 2
objWriter2.WriteLine(aryText2(j))
Next
objWriter2.Close()
Dim Process2 As New Process
Dim ps As New ProcessStartInfo(Folder & "recompile.bat")
ps.RedirectStandardError = True
ps.RedirectStandardOutput = True
ps.CreateNoWindow = False
ps.WindowStyle = ProcessWindowStyle.Hidden
ps.UseShellExecute = False
Dim recompile As Process = Process.Start(ps)
Process2.StartInfo = ps
Process2.Start()
Process2.WaitForExit()
My.Computer.FileSystem.CopyFile(Folder & "client.swf", TextBox4.Text & "Hexed.swf", True)
My.Computer.FileSystem.DeleteDirectory(Folder, FileIO.DeleteDirectoryOption.DeleteAllContents)
MessageBox.Show("Client has been hexed and named Hexed.swf")
End If
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim MyFolderBrowser As New System.Windows.Forms.FolderBrowserDialog
MyFolderBrowser.Description = "Select the Folder"
MyFolderBrowser.ShowNewFolderButton = False
Dim dlgResult As DialogResult = MyFolderBrowser.ShowDialog()
If dlgResult = Windows.Forms.DialogResult.OK Then
TextBox4.Text = MyFolderBrowser.SelectedPath
End If
End Sub
End Class
This is the code for the entire form. The part I that is not working is under Button1_Click
View the full article