Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System
- Imports System.IO
- Imports System.Net
- Imports System.Text.RegularExpressions
- Imports System.Threading
- Imports System.Threading.Tasks
- Public Class Deobfuscator
- ' Initialize Variables
- Dim Folder As String = Application.StartupPath & "/RABCDasm"
- Dim Trillix As String = Application.StartupPath & "/Trillix"
- Dim swfok As Boolean = False
- ' File Selector
- Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
- Dim fd As OpenFileDialog = New OpenFileDialog()
- Dim strFileName As String
- fd.Title = "Open File Dialog"
- fd.InitialDirectory = Application.StartupPath & "/Clients"
- fd.Filter = "Shockwave Flash Objects (*.swf)|*.*"
- fd.FilterIndex = 2
- fd.RestoreDirectory = True
- If fd.ShowDialog() = DialogResult.OK Then
- strFileName = fd.FileName
- If InStr(strFileName, ".swf") <> 0 Then
- TextBox2.Text = strFileName
- swfok = True
- Else
- MessageBox.Show("You have to pick a .swf silly...")
- End If
- End If
- End Sub
- ' Remove Junk Code
- Private Sub Deobf(sender As System.Object, e As System.EventArgs) Handles Button1.Click
- If TextBox2.Text = "" Then
- MessageBox.Show("You have to pick a .swf...")
- ElseIf swfok = False Then
- MessageBox.Show("You have to pick a .swf...")
- Else
- ' Change Cursor
- Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
- ' Copy over RABCDasm and the swf
- My.Computer.FileSystem.CopyFile(TextBox2.Text, Folder & "\client.swf", True)
- ' Decompile the swf
- Decompile()
- ' Create an Array containing all of the files in the */client-1 directory
- Dim Classes As String() = Directory.GetFiles(Folder, "*.class.asasm", SearchOption.AllDirectories)
- Dim Processed As Integer = 0
- Dim Total As Integer = Classes.Length
- Parallel.For(0, Classes.Length, Sub(i)
- ' Loop Through Every Single file from top to bottom
- ' Create a Streamreader to read through each file
- '' Path to current file in loop
- Dim MyFile As String = Classes(i)
- '' Create Dummy file to be filed, copied in, and deleted
- Dim NewFile As String = Path.GetDirectoryName(MyFile) & "/Temp" & i & ".class.asasm"
- '' Loop Variables
- Dim CurrentLine As String = ""
- Dim LinetoWrite As String = ""
- Dim Count As Integer = 0
- '' Deobf Logic Variables
- Dim BoolArray(2) As String
- Dim LocalArray(2) As String
- Dim InCodeBlock As Boolean = False
- Dim TwoSetLocals As Integer = 0
- Dim HitaLocal As Boolean = False
- Dim LocalHit As Integer = 0
- Dim JumpLine As String = "EMPTY"
- Dim RndFile As String = Path.GetDirectoryName(MyFile) & "/RndFile" & i & ".class.asasm"
- Dim RndWriter As StreamWriter
- Dim RndJump As Boolean = False
- Dim RndLine As String = "EMPTY"
- '' Readerwriter Combo to read and write lines as it goes
- '' Loop 1: Check for Random Jumps
- Using sr As StreamReader = New StreamReader(MyFile)
- Using sw As StreamWriter = New StreamWriter(NewFile, False)
- CurrentLine = sr.ReadLine
- Do While (Not CurrentLine Is Nothing)
- LinetoWrite = CurrentLine
- If CurrentLine.Contains(" code") Then
- ' Begining of Code Body
- If CurrentLine.Contains("tracking") Then
- sw.WriteLine(LinetoWrite)
- ElseIf Not CurrentLine.Contains("end") Then
- sw.WriteLine(LinetoWrite)
- InCodeBlock = True
- Count = 0
- ' End of Code Block
- Else
- InCodeBlock = False
- If RndJump = True Then
- RndWriter.Close()
- sw.WriteLine(File.ReadAllText(RndFile))
- RndLine = "EMPTY"
- RndJump = False
- End If
- sw.WriteLine(LinetoWrite)
- End If
- ' Check to See if you are in a code block
- ElseIf InCodeBlock = True Then
- ' Check to see if you are in a jump segment
- If RndJump = True Then
- ' Check to see if your jumpline is hit
- '' Check first to see if you made it all the way to the jump without hitting another LXX:
- If CurrentLine.Contains(RndLine) Then
- RndJump = False
- RndLine = "EMPTY"
- RndWriter.Close()
- sw.WriteLine(LinetoWrite)
- '' Check to see if the jump is not junk
- ElseIf CurrentLine.Contains(":") Then
- RndWriter.WriteLine(CurrentLine)
- RndWriter.Close()
- sw.WriteLine(File.ReadAllText(RndFile))
- RndLine = "EMPTY"
- RndJump = False
- '' Check for sequential real/fake jumps
- ElseIf CurrentLine.Contains("jump") Then
- RndWriter.Close()
- sw.WriteLine(File.ReadAllText(RndFile))
- RndLine = "L" & CurrentLine.Split("L")(1) & ":"
- RndWriter = New StreamWriter(RndFile, False)
- RndWriter.WriteLine(CurrentLine)
- Else
- '' If neither continue to fill your streamwriter just in case
- RndWriter.WriteLine(CurrentLine)
- End If
- ' Check to see if a new jump segment is initiated
- ElseIf CurrentLine.Contains("jump") Then
- RndJump = True
- RndLine = "L" & CurrentLine.Split("L")(1) & ":"
- RndWriter = New StreamWriter(RndFile, False)
- RndWriter.WriteLine(CurrentLine)
- ' Not in a jump Segment or starting a new one
- Else
- sw.WriteLine(LinetoWrite)
- End If
- Else
- ' Write Currentline back if you are not in a code block
- sw.WriteLine(LinetoWrite)
- End If
- Count = Count + 1
- CurrentLine = sr.ReadLine
- Loop
- End Using
- End Using
- ' Copy File Back into client-1 Directory
- My.Computer.FileSystem.DeleteFile(MyFile)
- My.Computer.FileSystem.RenameFile(NewFile, Path.GetFileNameWithoutExtension(MyFile) & ".asasm")
- Count = 0
- '' Loop 2: all other deobfuscation
- Using sr As StreamReader = New StreamReader(MyFile)
- Using sw As StreamWriter = New StreamWriter(NewFile, False)
- CurrentLine = sr.ReadLine
- Do While (Not CurrentLine Is Nothing)
- LinetoWrite = CurrentLine
- If CurrentLine.Contains(" code") Then
- ' Begining of Code Body
- If CurrentLine.Contains("tracking") Then
- sw.WriteLine(LinetoWrite)
- ElseIf Not CurrentLine.Contains("end") Then
- sw.WriteLine(LinetoWrite)
- InCodeBlock = True
- ' Reset Count
- Count = 0
- TwoSetLocals = 0
- ' End of Code Block
- Else
- InCodeBlock = False
- End If
- End If
- ' Check to See if you are in a code block
- If InCodeBlock = True Then
- ' Write first two line of each code block to the Boolean Array
- If Count = 1 Then
- If Not CurrentLine.Contains("push") Then
- InCodeBlock = False
- sw.WriteLine(LinetoWrite)
- Else
- BoolArray(0) = CurrentLine
- End If
- ElseIf Count = 2 Then
- BoolArray(1) = CurrentLine
- ElseIf Not TwoSetLocals = 2 Then
- ' Check for a swap
- If CurrentLine.Contains("swap") Then
- Dim Temp As String = BoolArray(0)
- BoolArray(0) = BoolArray(1)
- BoolArray(1) = Temp
- End If
- ' Write first two set locals to an array
- If CurrentLine.Contains("set") Then
- TwoSetLocals = TwoSetLocals + 1
- LocalArray(TwoSetLocals - 1) = CurrentLine.Replace("set", "get")
- End If
- ElseIf HitaLocal = True Then
- ' Check to see if its an iffalse jump
- If CurrentLine.Contains("iffalse") Then
- ' Check for a match
- If BoolArray(LocalHit).Contains("false") Then
- CurrentLine.Replace("false", "")
- JumpLine = "L" & CurrentLine.Split("L")(1) & ":"
- Else
- JumpLine = "L" & CurrentLine.Split("L")(1) & ":"
- HitaLocal = False
- End If
- End If
- ' Check to see if its an iffalse jump
- If CurrentLine.Contains("iftrue") Then
- ' Check for a match
- If BoolArray(LocalHit).Contains("true") Then
- JumpLine = "L" & CurrentLine.Split("L")(1) & ":"
- Else
- JumpLine = "L" & CurrentLine.Split("L")(1) & ":"
- HitaLocal = False
- End If
- End If
- 'Check to see if first register is checked against
- ElseIf CurrentLine.Contains(LocalArray(0)) Then
- HitaLocal = True
- LocalHit = 1
- ' Check to see if Second Register is checked against
- ElseIf CurrentLine.Contains(LocalArray(1)) Then
- HitaLocal = True
- LocalHit = 0
- ' Check for label from past if*** check
- ElseIf CurrentLine.Contains(JumpLine) Then
- HitaLocal = False
- sw.WriteLine(LinetoWrite)
- ' Write Good Code
- Else
- sw.WriteLine(LinetoWrite)
- End If
- Else
- ' Write Currentline back if you are not in a code block
- sw.WriteLine(LinetoWrite)
- End If
- Count = Count + 1
- CurrentLine = sr.ReadLine
- Loop
- End Using
- End Using
- ' Copy File Back into client-1 Directory
- My.Computer.FileSystem.DeleteFile(MyFile)
- My.Computer.FileSystem.RenameFile(NewFile, Path.GetFileNameWithoutExtension(MyFile) & ".asasm")
- Processed = Processed + 1
- Try
- Label1.Text = Processed & " of " & Total & "Files"
- Application.DoEvents()
- Catch
- End Try
- End Sub)
- End If
- ' Recompile
- Recompile()
- ' Remove old client-1
- Label1.Text = "Cleaning up files..."
- Application.DoEvents()
- My.Computer.FileSystem.DeleteDirectory(Folder & "/client-1", FileIO.DeleteDirectoryOption.DeleteAllContents)
- My.Computer.FileSystem.DeleteDirectory(Folder & "/client-0", FileIO.DeleteDirectoryOption.DeleteAllContents)
- My.Computer.FileSystem.DeleteFile(Folder & "/client-0.abc")
- My.Computer.FileSystem.DeleteFile(Folder & "/client-1.abc")
- ' Decompile Again
- Decompile()
- ' Moving Files
- Label1.Text = "Cleaning up files..."
- Application.DoEvents()
- My.Computer.FileSystem.MoveDirectory(Folder & "/client-1", Application.StartupPath & "/Deobf/client-1", True)
- My.Computer.FileSystem.MoveDirectory(Folder & "/client-0", Application.StartupPath & "/Deobf/client-0", True)
- My.Computer.FileSystem.MoveFile(Folder & "/client.swf", Application.StartupPath & "/Deobf/client.swf", True)
- My.Computer.FileSystem.DeleteFile(Folder & "/client-0.abc")
- My.Computer.FileSystem.DeleteFile(Folder & "/client-1.abc")
- ' Change Cursor
- Label1.Text = ""
- Application.DoEvents()
- Me.Cursor = System.Windows.Forms.Cursors.Default
- ' Finished!
- MessageBox.Show("Finished Deobfuscation Process!")
- End Sub
- ' Decompile
- Private Sub Decompile()
- Me.Activate()
- Label1.Text = "Decompiling Client..."
- Application.DoEvents()
- Dim FILE_NAME As String = Folder & "\decompile.bat"
- Dim aryText(5) As String
- aryText(0) = "cd " & Folder
- aryText(1) = "swfdecompress client.swf"
- aryText(2) = "abcexport client.swf"
- aryText(3) = "rabcdasm client-1.abc"
- aryText(4) = "rabcdasm client-0.abc"
- Create_Batch(aryText, FILE_NAME)
- End Sub
- ' Recompile SWF
- Private Sub Recompile()
- Me.Activate()
- Label1.Text = "Recompiling Client..."
- Application.DoEvents()
- Dim FILE_NAME As String = Folder & "\recompile.bat"
- Dim aryText(5) As String
- aryText(0) = "cd " & Folder
- aryText(1) = "rabcasm client-1\client-1.main.asasm"
- aryText(2) = "abcreplace client.swf 1 client-1\client-1.main.abc"
- aryText(3) = "rabcasm client-0\client-0.main.asasm"
- aryText(4) = "abcreplace client.swf 0 client-0\client-0.main.abc"
- Create_Batch(aryText, FILE_NAME)
- End Sub
- ' Create And Run Batch Files
- Public Sub Create_Batch(aryText() As String, FileName As String)
- Dim objWriter As New System.IO.StreamWriter(FileName, False)
- For i = 0 To aryText.Length - 1
- objWriter.WriteLine(aryText(i))
- Next
- objWriter.Close()
- Dim Process As New Process
- Dim ps As New ProcessStartInfo(FileName)
- ps.RedirectStandardError = True
- ps.RedirectStandardOutput = True
- ps.CreateNoWindow = True
- ps.WindowStyle = ProcessWindowStyle.Hidden
- ps.UseShellExecute = False
- Process.StartInfo = ps
- Process.Start()
- Process.WaitForExit()
- End Sub
- ' Flex Renamer
- Private Sub Renamer(sender As System.Object, e As System.EventArgs) Handles Button3.Click
- ' Change Cursor
- Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
- ' Delete old Trillix Directory
- If My.Computer.FileSystem.DirectoryExists(Trillix) Then
- My.Computer.FileSystem.DeleteDirectory(Trillix, FileIO.DeleteDirectoryOption.DeleteAllContents)
- End If
- If My.Computer.FileSystem.DirectoryExists(Application.StartupPath & "/Temp") Then
- My.Computer.FileSystem.DeleteDirectory(Application.StartupPath & "/Temp", FileIO.DeleteDirectoryOption.DeleteAllContents)
- End If
- ' Move Project to Trillix Folder
- My.Computer.FileSystem.CopyDirectory(TextBox1.Text, Trillix, True)
- Dim FileChange As String() = Directory.GetFiles(Trillix, "*.*", SearchOption.AllDirectories)
- ' Rename Class Files
- For i = 0 To FileChange.Length - 1
- Dim Tempname As String
- Tempname = FileChange(i).Replace("Trillix", "Temp").Replace("_-", "_").Replace("-", "_").Replace("bin_debug", "bin-debug")
- Tempname = Tempname.Replace("\ try", "\_try").Replace("\try ", "\try_").Replace("\try", "\_try_")
- My.Computer.FileSystem.MoveFile(FileChange(i), Tempname, True)
- Next
- Dim All As String() = Directory.GetFiles(Application.StartupPath & "/Temp", "*.as", SearchOption.AllDirectories)
- '' Loop 0: Fix Scripts and client-1.main
- For i = 0 To All.Length - 1
- Dim NewFile As String = Application.StartupPath & "/Temp/Temp.class.asasm"
- Dim CurrentLine As String = ""
- Dim LinetoWrite As String = ""
- Dim Count As Integer = 0
- Using sr As StreamReader = New StreamReader(All(i))
- Using sw As StreamWriter = New StreamWriter(NewFile, False)
- CurrentLine = sr.ReadLine
- Do While (Not CurrentLine Is Nothing)
- LinetoWrite = CurrentLine
- ' Fix Case for _--
- CurrentLine = CurrentLine.Replace("_--", "++++")
- 'Define Regex Cases
- ' _-$-
- Dim case1 As Regex = New Regex("_-[^\s]-")
- ' _-$$-
- Dim case2 As Regex = New Regex("_-[^\s][^\s]-")
- ' _-$$$-
- Dim case3 As Regex = New Regex("_-[^\s][^\s][^\s]-")
- ' _-$
- Dim case4 As Regex = New Regex("_-[^\s]")
- Dim Check As Boolean = False
- Dim Match As Match
- ' Check Case 1
- Do While Check = False
- Match = case1.Match(CurrentLine)
- If Match.Success = True Then
- CurrentLine = CurrentLine.Replace(Match.Value, Match.Value.Replace("_-", "_").Replace("-", "_"))
- Else
- Check = True
- End If
- Loop
- ' Check Case 2
- Check = False
- Do While Check = False
- Match = case2.Match(CurrentLine)
- If Match.Success = True Then
- CurrentLine = CurrentLine.Replace(Match.Value, Match.Value.Replace("_-", "_").Replace("-", "_"))
- Else
- Check = True
- End If
- Loop
- ' Check Case 3
- Check = False
- Do While Check = False
- Match = case3.Match(CurrentLine)
- If Match.Success = True Then
- CurrentLine = CurrentLine.Replace(Match.Value, Match.Value.Replace("_-", "_").Replace("-", "_"))
- Else
- Check = True
- End If
- Loop
- ' Check Case 4
- Check = False
- Do While Check = False
- Match = case4.Match(CurrentLine)
- If Match.Success = True Then
- CurrentLine = CurrentLine.Replace(Match.Value, Match.Value.Replace("_-", "_"))
- Else
- Check = True
- End If
- Loop
- LinetoWrite = CurrentLine
- ' Write Currentline back in
- sw.WriteLine(LinetoWrite)
- Count = Count + 1
- CurrentLine = sr.ReadLine
- Loop
- End Using
- End Using
- ' Copy File Back into client-1 Directory
- My.Computer.FileSystem.CopyFile(NewFile, All(i), True)
- Next
- ' Delete Move Temp Back to Trillix
- My.Computer.FileSystem.DeleteDirectory(Trillix, FileIO.DeleteDirectoryOption.DeleteAllContents)
- My.Computer.FileSystem.RenameDirectory(Application.StartupPath & "/Temp", "Trillix")
- ' Change Cursor
- Me.Cursor = System.Windows.Forms.Cursors.Default
- ' Finished!
- MessageBox.Show("Finished Renaming Process!")
- End Sub
- ' Open Folder Dialog
- Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
- Dim fd As FolderBrowserDialog = New FolderBrowserDialog()
- If (fd.ShowDialog() = DialogResult.OK) Then
- TextBox1.Text = fd.SelectedPath
- End If
- End Sub
- ' Load Event
- Private Sub Deobfuscator_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
- Label1.Text = ""
- End Sub
- ' Get Newest Client
- Private Sub Button5_Click(sender As System.Object, e As System.EventArgs) Handles Button5.Click
- Using wc As New WebClient()
- Dim version = wc.DownloadString("http://www.realmofthemadgod.com/version.txt")
- Dim swf = "http://www.realmofthemadgod.com/AssembleeGameClient" + version + ".swf"
- wc.DownloadFile(swf, Application.StartupPath & "\Clients\Fresh_Client_" & version & ".swf")
- TextBox2.Text = Application.StartupPath & "\Clients\Fresh_Client_" & version & ".swf"
- End Using
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement