ibennz

mono

Mar 28th, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.78 KB | None | 0 0
  1. Imports Mono.Cecil
  2. Imports Mono.Cecil.Cil
  3. Public Class Form1
  4.     Dim ASM As AssemblyDefinition
  5.     Dim List As ListBox = New ListBox
  6.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  7.         Dim opf As New OpenFileDialog
  8.         If opf.ShowDialog = vbOK Then
  9.             TextBox1.Text = opf.FileName
  10.  
  11.             If Protectpart1(opf.FileName) Then
  12.                 ASM.Write(opf.FileName)
  13.                 MsgBox("Done")
  14.             End If
  15.  
  16.         End If
  17.     End Sub
  18.     Public Function Protectpart1(ByVal file As String) As Boolean
  19.         Try
  20.             Dim tmpnmbr As Integer = New Random().Next(40, 75)
  21.             ASM = AssemblyDefinition.ReadAssembly(file)
  22.             Dim definition As TypeDefinition
  23.             For Each definition In ASM.MainModule.Types
  24.                 If (definition.Name <> "<Module>") Then
  25.                     Me.RenameTypesMethodsFields(definition, True, True, True)
  26.                     Dim i As Integer
  27.                     For i = 0 To tmpnmbr - 1
  28.                         Dim item As New MethodDefinition(Me.SingleCharRename, (MethodAttributes.ReuseSlot Or MethodAttributes.Private), ASM.MainModule.Import(Type.GetType("System.Void")))
  29.                         definition.Methods.Add(item)
  30.                         item.Body.Instructions.Add(Instruction.Create(OpCodes.Br_S, CByte(&H2C)))
  31.                         item.Body.Instructions.Add(Instruction.Create(OpCodes.Nop))
  32.                         List.Items.Add(item)
  33.                     Next i
  34.                 End If
  35.             Next
  36.             Dim definition3 As TypeDefinition
  37.             For Each definition3 In ASM.MainModule.Types
  38.                 If (definition3.Namespace <> "") Then
  39.                     Dim newValue As String = Me.SingleCharRename
  40.                     Dim resource As Resource
  41.                     For Each resource In ASM.MainModule.Resources
  42.                         resource.Name = resource.Name.Replace(definition3.Namespace, newValue)
  43.                     Next
  44.                     definition3.Namespace = newValue
  45.                 End If
  46.             Next
  47.         Catch exception As Exception
  48.             MessageBox.Show(exception.Message)
  49.             Return False
  50.         End Try
  51.         Return True
  52.     End Function
  53.  
  54.     Private Sub RenameTypesMethodsFields(ByVal t As TypeDefinition, ByVal renameType As Boolean, ByVal renameMethods As Boolean, ByVal renameFields As Boolean)
  55.         Dim definition As TypeDefinition
  56.         For Each definition In t.NestedTypes
  57.             Me.RenameTypesMethodsFields(definition, renameType, renameMethods, False)
  58.         Next
  59.         If renameFields Then
  60.             Dim definition2 As FieldDefinition
  61.             For Each definition2 In t.Fields
  62.  
  63.                 ' definition2.Name = Me.SingleCharRename
  64.             Next
  65.         End If
  66.  
  67.         Dim str As String = Me.SingleCharRename
  68.         Dim resource As Resource
  69.         For Each resource In t.Module.Resources
  70.             resource.Name = resource.Name.Replace(t.FullName, (t.Namespace & "." & str))
  71.         Next
  72.         If renameType Then
  73.             t.Name = str
  74.         End If
  75.     End Sub
  76.     Private Function SingleCharRename() As String
  77.         Dim rna As New Random
  78.         Return random_key_string(rna.Next(10, 15))
  79.     End Function
  80.  
  81.     Public Function random_key_string(ByVal lenght As Integer) As String
  82.         Randomize()
  83.         Dim s As New System.Text.StringBuilder("")
  84.         Dim b() As Char = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".ToCharArray()
  85.         For i As Integer = 1 To lenght
  86.             Randomize()
  87.             Dim z As Integer = CInt(Int(((b.Length - 2) - 0 + 1) * Rnd()) + 1)
  88.             s.Append(b(z))
  89.         Next
  90.         Return s.ToString
  91.     End Function
  92. End Class
Advertisement
Add Comment
Please, Sign In to add comment