Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports Mono.Cecil
- Imports Mono.Cecil.Cil
- Public Class Form1
- Dim ASM As AssemblyDefinition
- Dim List As ListBox = New ListBox
- Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
- Dim opf As New OpenFileDialog
- If opf.ShowDialog = vbOK Then
- TextBox1.Text = opf.FileName
- If Protectpart1(opf.FileName) Then
- ASM.Write(opf.FileName)
- MsgBox("Done")
- End If
- End If
- End Sub
- Public Function Protectpart1(ByVal file As String) As Boolean
- Try
- Dim tmpnmbr As Integer = New Random().Next(40, 75)
- ASM = AssemblyDefinition.ReadAssembly(file)
- Dim definition As TypeDefinition
- For Each definition In ASM.MainModule.Types
- If (definition.Name <> "<Module>") Then
- Me.RenameTypesMethodsFields(definition, True, True, True)
- Dim i As Integer
- For i = 0 To tmpnmbr - 1
- Dim item As New MethodDefinition(Me.SingleCharRename, (MethodAttributes.ReuseSlot Or MethodAttributes.Private), ASM.MainModule.Import(Type.GetType("System.Void")))
- definition.Methods.Add(item)
- item.Body.Instructions.Add(Instruction.Create(OpCodes.Br_S, CByte(&H2C)))
- item.Body.Instructions.Add(Instruction.Create(OpCodes.Nop))
- List.Items.Add(item)
- Next i
- End If
- Next
- Dim definition3 As TypeDefinition
- For Each definition3 In ASM.MainModule.Types
- If (definition3.Namespace <> "") Then
- Dim newValue As String = Me.SingleCharRename
- Dim resource As Resource
- For Each resource In ASM.MainModule.Resources
- resource.Name = resource.Name.Replace(definition3.Namespace, newValue)
- Next
- definition3.Namespace = newValue
- End If
- Next
- Catch exception As Exception
- MessageBox.Show(exception.Message)
- Return False
- End Try
- Return True
- End Function
- Private Sub RenameTypesMethodsFields(ByVal t As TypeDefinition, ByVal renameType As Boolean, ByVal renameMethods As Boolean, ByVal renameFields As Boolean)
- Dim definition As TypeDefinition
- For Each definition In t.NestedTypes
- Me.RenameTypesMethodsFields(definition, renameType, renameMethods, False)
- Next
- If renameFields Then
- Dim definition2 As FieldDefinition
- For Each definition2 In t.Fields
- ' definition2.Name = Me.SingleCharRename
- Next
- End If
- Dim str As String = Me.SingleCharRename
- Dim resource As Resource
- For Each resource In t.Module.Resources
- resource.Name = resource.Name.Replace(t.FullName, (t.Namespace & "." & str))
- Next
- If renameType Then
- t.Name = str
- End If
- End Sub
- Private Function SingleCharRename() As String
- Dim rna As New Random
- Return random_key_string(rna.Next(10, 15))
- End Function
- Public Function random_key_string(ByVal lenght As Integer) As String
- Randomize()
- Dim s As New System.Text.StringBuilder("")
- Dim b() As Char = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".ToCharArray()
- For i As Integer = 1 To lenght
- Randomize()
- Dim z As Integer = CInt(Int(((b.Length - 2) - 0 + 1) * Rnd()) + 1)
- s.Append(b(z))
- Next
- Return s.ToString
- End Function
- End Class
Advertisement
Add Comment
Please, Sign In to add comment