Jump to content
Tuts 4 You

[Help VB.NET] value does not fall within the expected range


mrtifa13

Recommended Posts

Hello eveyone , i was coding an obfuscator , everything is working good , but when i start to deobfuscate , it says value does not fall within the expected range , can someone help me please , here is the code 

  Private Sub DesignButton8_Click(sender As Object, e As EventArgs) Handles DesignButton8.Click
        Try
            Dim S As New SaveFileDialog
            S.Filter = "|*.exe"
            If S.ShowDialog = vbOK Then
                If Protectpart2() = True Then
                    ASM.Write(S.FileName)
                        MsgBox("Sucessfully Obfuscated at: " & vbCrLf & S.FileName, MsgBoxStyle.Information)
                    Else
                        Exit Sub
 
                    End If
                End If
        Catch ex As Exception
        End Try
    End Sub
 
    Public Function Protectpart2() As Boolean
        Dim FilePath As String = ""
        Try
            ASM = AssemblyDefinition.ReadAssembly(FilePath)
            ASM.MainModule.Attributes = ModuleAttributes.Required32Bit
            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 750 - 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
 
Link to comment

check your code more carefully and debug it


here is the problem :



Dim FilePath As String = ""

you've passed an empty path to "ReadAssembly"


Edited by n0th!ng
  • Like 1
Link to comment

check your code more carefully and debug it

here is the problem :


Dim FilePath As String = ""

you've passed an empty path to "ReadAssembly"

well , how can i fix it :D , sorry for my lazy brain im just new on vb.net

Link to comment

How on earth you code a obfuscator if you don't know basic coding....????


 


Replace:



Dim FilePath As String = ""

With:



Dim result As DialogResult = OpenFileDialog1.ShowDialog()
If result = Windows.Forms.DialogResult.OK Then
Dim FilePath As String = OpenFileDialog1.FileName.ToString
EndIf

This is when you execute trough a button.


 


Inside your bolean function you can:


1. Make fixed file path value:



Dim FilePath As String = "c:\assembly.exe"

or before passing the arguments to function just open the dialog and pass the result to a variable withch is later imported to your boolean variable.



Public Function Protectpart2( byval mypath as string) As Boolean


Dim FilePath As String = mypath

Edited by GIV
  • Like 1
Link to comment

 

How on earth you code a obfuscator if you don't know basic coding....????

 

Replace:

Dim FilePath As String = ""

With:

Dim result As DialogResult = OpenFileDialog1.ShowDialog()If result = Windows.Forms.DialogResult.OK ThenDim FilePath As String = OpenFileDialog1.FileName.ToStringEndIf

This is when you execute trough a button.

 

Inside your bolean function you can:

1. Make fixed file path value:

Dim FilePath As String = "c:\assembly.exe"

or before passing the arguments to function just open the dialog and pass the result to a variable withch is later imported to your boolean variable.

Public Function Protectpart2( byval mypath as string) As Boolean
Dim FilePath As String = mypath

like this u mean?

 

  Private Sub DesignButton8_Click(ByVal sender As Object, ByVal e As EventArgs) Handles DesignButton8.Click
        Try
            Dim File1 As New OpenFileDialog
            Dim FilePath As String = File1.FileName.ToString
            Dim result As DialogResult = File1.ShowDialog()
            If result = Windows.Forms.DialogResult.OK Then
                File1.FileName.ToString()
            End If
            Dim S As New SaveFileDialog
            S.Filter = "|*.exe"
            If S.ShowDialog = vbOK Then
                If Protectpart2() = True Then
                    ASM.Write(S.FileName)
                    ASM.Write(SavePath)
                    MsgBox("Sucessfully Obfuscated at: " & vbCrLf & S.FileName, MsgBoxStyle.Information)
                Else
                    Exit Sub
 
                End If
            End If
        Catch ex As Exception
        End Try
    End Sub
 
    Public Function Protectpart2() As Boolean
        Dim FilePath As String = "c:\...\...\desktop\"
        Try
            ASM = AssemblyDefinition.ReadAssembly(FilePath)
            ASM.MainModule.Attributes = ModuleAttributes.Required32Bit
            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 750 - 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
Link to comment

Define a global variable as:

public FilePath  as string=""

Just before execute your code make a button with the code inside:

 

 

 

Dim result As DialogResult = OpenFileDialog1.ShowDialog()
If result = Windows.Forms.DialogResult.OK Then
Dim FilePath As String = OpenFileDialog1.FileName.ToString
EndIf

Link to comment

Define a global variable as:

public FilePath  as string=""

Just before execute your code make a button with the code inside:

do u have skype?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...