Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System
- Imports System.IO
- Imports System.Threading
- Imports System.Threading.Tasks
- Imports System.Security.Cryptography
- Imports System.Text.RegularExpressions
- Public Class Compare
- ' Initialize Variables
- Dim Folder As String = Application.StartupPath & "/RABCDasm"
- Dim Compare As String = Application.StartupPath & "/Compare"
- Dim OldFiles As String()
- Dim NewFiles As String()
- Dim swfok As Boolean = False
- ' Client 1 Selection
- Private Sub Client1(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
- 'Client 2 Selector
- Private Sub Client2(sender As System.Object, e As System.EventArgs) Handles Button3.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
- TextBox1.Text = strFileName
- swfok = True
- Else
- MessageBox.Show("You have to pick a .swf silly...")
- End If
- End If
- End Sub
- ' Decompile Client
- Private Sub Decompile()
- Dim FILE_NAME As String = Folder & "\decompile.bat"
- 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"
- Create_Batch(aryText, FILE_NAME)
- End Sub
- ' Recompile SWF
- Private Sub Recompile()
- Dim FILE_NAME As String = Folder & "\recompile.bat"
- Dim aryText(3) 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"
- 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 = False
- ps.WindowStyle = ProcessWindowStyle.Hidden
- ps.UseShellExecute = False
- Process.StartInfo = ps
- Process.Start()
- Process.WaitForExit()
- End Sub
- ' Remove Junk Code
- Private Sub Deobf(Path As String)
- ' Copy over RABCDasm and the swf
- My.Computer.FileSystem.CopyFile(Path, 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)
- ' Loop Through Every Single file from top to bottom
- Parallel.For(0, Classes.Length, Sub(i)
- ' Create a Streamreader to read through each file
- '' Create Dummy file to be filed, copied in, and deleted
- Dim NewFile As String = Folder & "/Temp" & i & ".class.asasm"
- '' Path to current file in loop
- Dim MyFile As String = Classes(i)
- '' 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 = Folder & "/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.CopyFile(NewFile, MyFile, True)
- 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.CopyFile(NewFile, MyFile, True)
- End Sub)
- ' Recompile
- Recompile()
- ' Remove old client-1
- My.Computer.FileSystem.DeleteDirectory(Folder & "/client-1", FileIO.DeleteDirectoryOption.DeleteAllContents)
- My.Computer.FileSystem.DeleteFile(Folder & "/client-1.abc")
- ' Decompile Again
- Decompile()
- End Sub
- ' Compare Clients
- Private Sub CompareClients(sender As System.Object, e As System.EventArgs) Handles Button1.Click
- If TextBox1.Text = "" Then
- MessageBox.Show("You have to pick a .swf...")
- ElseIf 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
- Try
- ' Create Directory for Process
- If My.Computer.FileSystem.DirectoryExists(Compare) Then
- My.Computer.FileSystem.DeleteDirectory(Compare, FileIO.DeleteDirectoryOption.DeleteAllContents)
- End If
- Catch
- MessageBox.Show("You Need to Close File Explorer")
- Me.Cursor = System.Windows.Forms.Cursors.Default
- Exit Sub
- End Try
- ' Deobfuscate Old Client
- Deobf(TextBox1.Text)
- ' Move and Clean
- My.Computer.FileSystem.CopyDirectory(Folder & "/client-1", Compare & "/Old")
- My.Computer.FileSystem.DeleteDirectory(Folder, FileIO.DeleteDirectoryOption.DeleteAllContents)
- ' Deobfuscate New Client
- Deobf(TextBox2.Text)
- ' Move and Clean
- My.Computer.FileSystem.CopyDirectory(Folder & "/client-1", Compare & "/New")
- My.Computer.FileSystem.DeleteDirectory(Folder, FileIO.DeleteDirectoryOption.DeleteAllContents)
- ' Create an Array containing all of the files in the */client-1 directory
- Dim Classes As String() = Directory.GetFiles(Folder & "/client1-1", "*.class.asasm", SearchOption.AllDirectories)
- Dim BoolArray(Classes.Length) As Boolean
- ' Loop Through Every Single file from top to bottom
- For i = 0 To Classes.Length - 1
- BoolArray(i) = CompareFiles(Classes(i), Classes(i).Replace("client1", "client2"))
- If BoolArray(i) = False Then
- Dim CurrentLine As String = ""
- Using sr As StreamReader = New StreamReader(Classes(i))
- Using sw As StreamWriter = New StreamWriter(Folder & "/Temp.txt")
- CurrentLine = sr.ReadLine
- Do While (Not CurrentLine Is Nothing)
- Dim LinetoWrite = CurrentLine
- sw.WriteLine(LinetoWrite.Replace("#1", "#0").Replace("#2", "0"))
- CurrentLine = sr.ReadLine
- Loop
- End Using
- End Using
- My.Computer.FileSystem.CopyFile(Folder & "/Temp.txt", Classes(i), True)
- My.Computer.FileSystem.DeleteFile(Folder & "/Temp.txt")
- Using sr As StreamReader = New StreamReader(Classes(i).Replace("client1", "client2"))
- Using sw As StreamWriter = New StreamWriter(Folder & "/Temp.txt")
- CurrentLine = sr.ReadLine
- Do While (Not CurrentLine Is Nothing)
- Dim LinetoWrite = CurrentLine
- sw.WriteLine(LinetoWrite.Replace("#1", "#0").Replace("#2", "0"))
- CurrentLine = sr.ReadLine
- Loop
- End Using
- End Using
- My.Computer.FileSystem.CopyFile(Folder & "/Temp.txt", Classes(i).Replace("client1", "client2"), True)
- My.Computer.FileSystem.DeleteFile(Folder & "/Temp.txt")
- End If
- BoolArray(i) = CompareFiles(Classes(i), Classes(i).Replace("client1", "client2"))
- Next
- ' Write Files that do not match to a .txt file
- Dim MyFile As String = Application.StartupPath & "/DifferentClasses.txt"
- If My.Computer.FileSystem.FileExists(MyFile) Then
- My.Computer.FileSystem.DeleteFile(MyFile)
- End If
- Dim Info As StreamWriter
- Info = File.AppendText(MyFile)
- Info.WriteLine("Classes that are not the same:")
- Info.WriteLine("")
- Dim Count = 0
- For i = 0 To Classes.Length - 1
- If BoolArray(i) = False Then
- Info.WriteLine(Classes(i))
- End If
- Next
- Info.Flush()
- Info.Close()
- My.Computer.FileSystem.DeleteDirectory(Folder, FileIO.DeleteDirectoryOption.DeleteAllContents)
- Me.Cursor = System.Windows.Forms.Cursors.Default
- MessageBox.Show("Comparison Complete!", "Finished", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
- Me.Activate()
- Process.Start(MyFile)
- End If
- End Sub
- ' Check Hashes
- Public Function CompareFiles(ByVal FileFullPath1 As String, _
- ByVal FileFullPath2 As String) As Boolean
- 'returns true if two files passed to is are identical, false
- 'otherwise
- 'does byte comparison; works for both text and binary files
- 'Throws exception on errors; you can change to just return
- 'false if you prefer
- Dim objMD5 As New MD5CryptoServiceProvider()
- Dim objEncoding As New System.Text.ASCIIEncoding()
- Dim aFile1() As Byte, aFile2() As Byte
- Dim strContents1, strContents2 As String
- Dim objReader As StreamReader
- Dim objFS As FileStream
- Dim bAns As Boolean
- If Not File.Exists(FileFullPath1) Then _
- Throw New Exception(FileFullPath1 & " doesn't exist")
- If Not File.Exists(FileFullPath2) Then _
- Throw New Exception(FileFullPath2 & " doesn't exist")
- Try
- objFS = New FileStream(FileFullPath1, FileMode.Open)
- objReader = New StreamReader(objFS)
- aFile1 = objEncoding.GetBytes(objReader.ReadToEnd)
- strContents1 = _
- objEncoding.GetString(objMD5.ComputeHash(aFile1))
- objReader.Close()
- objFS.Close()
- objFS = New FileStream(FileFullPath2, FileMode.Open)
- objReader = New StreamReader(objFS)
- aFile2 = objEncoding.GetBytes(objReader.ReadToEnd)
- strContents2 = _
- objEncoding.GetString(objMD5.ComputeHash(aFile2))
- bAns = strContents1 = strContents2
- objReader.Close()
- objFS.Close()
- aFile1 = Nothing
- aFile2 = Nothing
- Catch ex As Exception
- Throw ex
- End Try
- Return bAns
- End Function
- Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
- ' Create a pair of filename arrays
- OldFiles = Directory.GetFiles(Compare & "/Old", "*.class.asasm", SearchOption.AllDirectories)
- NewFiles = Directory.GetFiles(Compare & "/New", "*.class.asasm", SearchOption.AllDirectories)
- Parallel.For(0, NewFiles.Length, Sub(i)
- ' Create a Streamreader to read through each file
- '' Create Dummy file to be filed, copied in, and deleted
- Dim NewFile As String = Compare & "/Temp" & i & ".class.asasm"
- '' Path to current file in loop
- Dim MyFile As String = NewFiles(i)
- '' Loop Variables
- Dim CurrentLine As String = ""
- Dim LinetoWrite As String = ""
- Using sr As StreamReader = New StreamReader(NewFiles(i))
- Using sw As StreamWriter = New StreamWriter(NewFile)
- CurrentLine = sr.ReadLine
- Do While (Not CurrentLine Is Nothing)
- ' Make Macros all the same
- CurrentLine = CurrentLine.Replace("#1", "#0").Replace("#2", "#0")
- 'Define Regex Cases
- Dim name_ As Regex = New Regex("[-!$%^&*()+|~=`{}\[\]:"""";'<>?,.\/]_-([a-z][A-Z][0-9][-][\s])+[-!$%^&*()+|~=`{}\[\]:"""";'<>?,.\/]")
- Dim RegCheck As Boolean = False
- Dim Match As Match
- ' Change names_
- Do While RegCheck = False
- Match = name_.Match(CurrentLine)
- If Match.Success = True Then
- CurrentLine = CurrentLine.Replace(Match.Value, Match.Value.Chars(0) & "$$$" & Match.Value.Chars(Match.Value.Length - 1))
- MessageBox.Show(CurrentLine)
- Else
- RegCheck = True
- End If
- Loop
- LinetoWrite = CurrentLine
- sw.WriteLine(LinetoWrite)
- CurrentLine = sr.ReadLine
- Loop
- End Using
- End Using
- End Sub)
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement