elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Librería de Snippets para VB.NET !! (Compartan aquí sus snippets)
0 Usuarios y 7 Visitantes están viendo este tema.
Páginas: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 [17] 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 ... 59 Ir Abajo Respuesta Imprimir
Autor Tema: Librería de Snippets para VB.NET !! (Compartan aquí sus snippets)  (Leído 485,766 veces)
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.813



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #160 en: 7 Junio 2013, 21:14 pm »

Devuelve la versión instalada de InternetExplorer en el PC:

Código
  1. #Region " Get IExplorer Version "
  2.  
  3.    ' [ Get IExplorer Version Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    '
  9.    ' MsgBox(Get_IExplorer_Version)       ' Result: 8
  10.    ' MsgBox(Get_IExplorer_Version(True)) ' Result: 8.00.7600.16385
  11.  
  12.    Private Function Get_IExplorer_Version(Optional ByVal Long_Version As Boolean = False) As String
  13.  
  14.        Try
  15.            If Long_Version Then
  16.                Return FileVersionInfo.GetVersionInfo(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\ieframe.dll").ProductVersion
  17.            Else
  18.                Return FileVersionInfo.GetVersionInfo(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\ieframe.dll").ProductVersion.Split(".").First
  19.            End If
  20.        Catch ex As Exception
  21.            MsgBox(ex.Message)
  22.            Return 0
  23.        End Try
  24.  
  25.    End Function
  26.  
  27. #End Region


En línea

z3nth10n


Desconectado Desconectado

Mensajes: 1.583


"Jack of all trades, master of none." - Zenthion


Ver Perfil WWW
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #161 en: 7 Junio 2013, 21:40 pm »

Ahora me pongo yo critico, y para que coño quiero saber la versión de mi IE? XD

Hombre, se me ocurren ideas tal como parchear algunos errores en los webbrowsers pero, es poca cosa... xD


En línea


Interesados hablad por Discord.
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.813



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #162 en: 8 Junio 2013, 04:43 am »

Ahora me pongo yo critico, y para que coño quiero saber la versión de mi IE? XD

Hombre, se me ocurren ideas tal como parchear algunos errores en los webbrowsers pero, es poca cosa... xD

La idea es conocer la versión de IExplorer de otro PC que no sea el tuyo/mio para anticiparse a posibles errores, por ejemplo si te pagan por una aplicación y quieres usar el render de IE10 en un webbrowser pero ese PC tiene IE8 pues...cagada, no?

Un saludo!
En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.813



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #163 en: 8 Junio 2013, 06:49 am »

Suspender o continuar un proceso externo:



(Corregido un pequeño bug de última hora en la función "resume-thread" al comprobar si existia el proceso en el diccionario.)
Código
  1. #Region " Pause-Resume Thread Class "
  2.  
  3. Public Class Process_Thread
  4.  
  5.    ' [ Pause-Resume Thread Functions ]
  6.    '
  7.    ' // By Elektro H@cker
  8.    '
  9.    ' Examples :
  10.    '
  11.    ' Process_Thread.Pause_Thread("ffmpeg.exe")       ' Pause  ffmpeg.exe (with thread 0)
  12.    ' Process_Thread.Resume_Thread("ffmpeg.exe")      ' Resume ffmpeg.exe (with thread 0)
  13.    ' Process_Thread.Pause_Thread("cmd.exe", , True)  ' Pause  all instances of cmd.exe (with thread 0)
  14.    ' Process_Thread.Resume_Thread("cmd.exe", , True) ' Resume all instances of cmd.exe (with thread 0)
  15.    ' Process_Thread.Pause_Thread("Process.exe", 2)   ' Pause the thread 2 of "Process.exe"
  16.    ' Process_Thread.Resume_Thread("Process.exe", 2)  ' Resume the thread 2 of "Process.exe"
  17.  
  18.    <System.Runtime.InteropServices.DllImport("kernel32.dll")> _
  19.    Private Shared Function OpenThread(ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Boolean, ByVal dwThreadId As UInt32) As IntPtr
  20.    End Function
  21.  
  22.    <System.Runtime.InteropServices.DllImport("kernel32.dll")> _
  23.    Private Shared Function SuspendThread(hThread As IntPtr) As UInteger
  24.    End Function
  25.  
  26.    <System.Runtime.InteropServices.DllImport("kernel32.dll")> _
  27.    Private Shared Function ResumeThread(hThread As IntPtr) As UInt32
  28.    End Function
  29.  
  30.    <System.Runtime.InteropServices.DllImport("kernel32.dll", SetLastError:=True)> _
  31.    Private Shared Function CloseHandle(ByVal hObject As IntPtr) As <System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean
  32.    End Function
  33.  
  34.    ''' <summary>
  35.    ''' Dictionary to store the current paused threads.
  36.    ''' </summary>
  37.    Public Shared Thread_Handle_Dictionary As New Dictionary(Of String, IntPtr)
  38.  
  39. #Region " Pause Thread "
  40.  
  41.    ''' <summary>
  42.    ''' Function to pause a thread.
  43.    ''' </summary>
  44.    '''
  45.    ''' <param name="Process_Name">The name of the process, ex: cmd.exe</param>
  46.    ''' <param name="Thread_Number">The thread to pause, ex: 0</param>
  47.    ''' <param name="Recursive"> <value name="True">Pause the thread in all processes found recursively.</value></param>
  48.    ''' <returns>True if the process is found; otherwise, False.</returns>
  49.    Public Shared Function Pause_Thread(ByRef Process_Name As String, _
  50.                                  Optional ByVal Thread_Number As Int32 = 0, _
  51.                                  Optional ByVal Recursive As Boolean = False) As Boolean
  52.  
  53.        If Process_Name.ToLower.EndsWith(".exe") Then _
  54.        Process_Name = Process_Name.Substring(0, Process_Name.Length - 4)
  55.  
  56.        Dim proc() As Process = Process.GetProcessesByName(Process_Name)
  57.  
  58.        If Not proc.Length = 0 Then
  59.  
  60.            If Recursive Then
  61.  
  62.                For proc_num As Integer = 0 To proc.Length - 1
  63.                    Try
  64.                        Thread_Handle_Dictionary.Add(Process_Name.ToLower & Thread_Number.ToString & ";" & proc(proc_num).Handle.ToString, _
  65.                                                     OpenThread(&H2, True, proc(proc_num).Threads(Thread_Number).Id))
  66.                        SuspendThread(Thread_Handle_Dictionary.Item(Process_Name.ToLower & Thread_Number.ToString & ";" & proc(proc_num).Handle.ToString))
  67.                        Application.DoEvents()
  68.                    Catch ex As Exception
  69.                        MsgBox(ex.Message) ' The handle already exist in the Dictionary.
  70.                        Return False
  71.                    End Try
  72.                Next
  73.  
  74.            Else
  75.  
  76.                Try
  77.                    Thread_Handle_Dictionary.Add(Process_Name.ToLower & Thread_Number.ToString & ";" & proc(0).Handle.ToString, _
  78.                                                 OpenThread(&H2, True, proc(0).Threads(Thread_Number).Id))
  79.                    SuspendThread(Thread_Handle_Dictionary.Item(Process_Name.ToLower & Thread_Number.ToString & ";" & proc(0).Handle.ToString))
  80.                Catch ex As Exception
  81.                    MsgBox(ex.Message) ' The handle already exist in the Dictionary.
  82.                    Return False
  83.                End Try
  84.  
  85.            End If
  86.  
  87.        Else ' proc.Length = 0
  88.  
  89.            Throw New Exception("Process """ & Process_Name & """ not found.")
  90.            Return False
  91.  
  92.        End If
  93.  
  94.        Return True
  95.  
  96.    End Function
  97.  
  98. #End Region
  99.  
  100. #Region " Resume Thread "
  101.  
  102.    ''' <summary>
  103.    ''' Function to resume a thread.
  104.    ''' </summary>
  105.    '''
  106.    ''' <param name="Process_Name">The name of the process, ex: cmd.exe</param>
  107.    ''' <param name="Thread_Number">The thread to resume, ex: 0</param>
  108.    ''' <param name="Recursive"> <value name="True">Resume the thread in all processes found recursively.</value></param>
  109.    ''' <returns>True if the process is found; otherwise, False.</returns>
  110.    Public Shared Function Resume_Thread(ByRef Process_Name As String, _
  111.                                  Optional ByVal Thread_Number As Int32 = 0, _
  112.                                  Optional ByVal Recursive As Boolean = False) As Boolean
  113.  
  114.        If Process_Name.ToLower.EndsWith(".exe") Then _
  115.        Process_Name = Process_Name.Substring(0, Process_Name.Length - 4)
  116.  
  117.        Dim Process_Exist As Boolean = False ' To check if process exist in the dictionary.
  118.  
  119.        Dim Temp_Dictionary As New Dictionary(Of String, IntPtr) ' Replic of the "Thread_Handle_Dictionary" dictionary.
  120.  
  121.        For Each Process In Thread_Handle_Dictionary
  122.            If Process.Key.StartsWith(Process_Name.ToLower & Thread_Number.ToString) Then Process_Exist = True
  123.            Temp_Dictionary.Add(Process.Key, Process.Value)
  124.        Next
  125.  
  126.        If Process_Exist Then
  127.  
  128.            If Recursive Then
  129.                For Each Process In Temp_Dictionary
  130.                    If Process.Key.ToLower.Contains(Process_Name.ToLower & Thread_Number.ToString) Then
  131.                        ResumeThread(Process.Value)
  132.                        CloseHandle(Process.Value)
  133.                        Thread_Handle_Dictionary.Remove(Process.Key)
  134.                    End If
  135.                    Application.DoEvents()
  136.                Next
  137.            Else
  138.  
  139.                For Each Process In Temp_Dictionary
  140.                    If Process.Key.ToLower.Contains(Process_Name.ToLower & Thread_Number.ToString) Then
  141.                        ResumeThread(Process.Value)
  142.                        CloseHandle(Process.Value)
  143.                        Thread_Handle_Dictionary.Remove(Process.Key)
  144.                        Exit For
  145.                    End If
  146.                    Application.DoEvents()
  147.                Next
  148.  
  149.            End If
  150.  
  151.            Return True
  152.  
  153.        Else
  154.  
  155.            Throw New Exception("Process """ & Process_Name & """ with thread number """ & Thread_Number & """ not found.")
  156.            Return False
  157.  
  158.        End If
  159.  
  160.    End Function
  161.  
  162. #End Region
  163.  
  164. End Class
  165.  
  166. #End Region
« Última modificación: 8 Junio 2013, 08:08 am por EleKtro H@cker » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.813



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #164 en: 9 Junio 2013, 18:59 pm »

Resalta en colores la sintaxis de un script.
(Lo convierte a código HTML)

http://colorcode.codeplex.com/releases/view/103657



Código
  1. #Region " [ColorCode] Color Code "
  2.  
  3.    ' [ColorCode] Color Code
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Instructions:
  8.    ' 1. Add a reference to ColorCode.dll
  9.    '
  10.    ' Examples:
  11.    ' HtmlTextBox1.Text = Color_Code(IO.File.ReadAllText("c:\Code.vb"), ColorCode.Languages.VbDotNet)
  12.    ' HtmlTextbox1.Text = Color_Code(IO.File.ReadAllText("c:\Code.cs"), ColorCode.Languages.CSharp)
  13.  
  14.    Private Function Color_Code(ByVal Code As String, ByVal Language As ColorCode.ILanguage) As String
  15.        Return New ColorCode.CodeColorizer().Colorize(Code, Language)
  16.    End Function
  17.  
  18. #End Region




Randomizar el contenido de un Array de tipo String:

Código
  1. #Region " Randomize String Array "
  2.  
  3.    ' [ Randomize String Array Function ]
  4.    '
  5.    ' Examples :
  6.    ' Dim MyArray As Array = Randomize_String_Array({"a", "b", "c", "d", "e"}) ' Result: {"d", "a", "c", "e", "b"}
  7.  
  8.    Dim Array_randomizer As New Random
  9.  
  10.    Private Function Randomize_String_Array(ByVal array() As String) As Array
  11.        Return array.OrderBy(Function() Array_randomizer.Next).ToArray
  12.    End Function
  13.  
  14. #End Region




Randomizar el contenido de cualquier tipo de Array:

Código
  1. #Region " Randomize Array "
  2.  
  3.    ' [ Randomize Array ]
  4.    '
  5.    ' Examples :
  6.    ' Dim strarray() As String = {"a", "b", "3"}
  7.    ' Dim IntArray As Array = {1, 2, 3}
  8.    ' Randomize_Array(strarray)
  9.    ' Randomize_Array(IntArray)
  10.  
  11.    Dim Array_Randomizer As New Random
  12.  
  13.    Public Sub Randomize_Array(ByVal array As Array)
  14.  
  15.        For i As Int64 = array.Length To 1 Step -1
  16.            Dim j As Int64 = Array_Randomizer.Next(i)
  17.            Dim tmp As Object = array(j)
  18.            array(j) = array(i - 1)
  19.            array(i - 1) = tmp
  20.        Next
  21.  
  22.    End Sub
  23.  
  24. #End Region




Une el contenido de un Array de cualquier tipo
(hace unos días posteé un código parecido, pero solo funcionaba para arrays de string)

Código
  1. #Region " Join Array "
  2.  
  3.    ' [ Join Array Function ]
  4.    '
  5.    ' Examples :
  6.    '
  7.    ' Dim StrArray() As String = {"a", "b", "c"} ' String array
  8.    ' Dim IntArray As Array = {1, 2, 3}          ' Integer array
  9.    ' MsgBox(Join_Array(StrArray, " "))          ' Result: a b c
  10.    ' MsgBox(Join_Array(IntArray, " "))          ' Result: 1 2 3
  11.  
  12.    Private Function Join_Array(ByVal array As Array, ByVal Separator As String)
  13.        Return String.Join(Separator, array.Cast(Of Object).Select(Function(x) x.ToString))
  14.    End Function
  15.  
  16. #End Region




cifrar-descifrar un string de manera selectiva (usando los caracteres que nos de la gana, por eso el código es así de largo)

Código
  1. #Region " Encrypt-Decrypt String Selective "
  2.  
  3.    ' [ Encrypt-Decrypt String Selective Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    '
  9.    ' MsgBox(Encrypt_Text("Hello world"))           ' Result: à`336 L6ë3m
  10.    ' MsgBox(Decrypt_Text("à`336 L6ë3m"))           ' Result: Hello world
  11.    ' MsgBox(Encrypt_Text("¡ Hello world !", True)) ' Result: = <ÁÍÍÀ cÀ,Í3 Ï
  12.    ' MsgBox(Decrypt_Text("= <ÁÍÍÀ cÀ,Í3 Ï", True)) ' Result: ¡ Hello world !
  13.  
  14.    Public Shared Function Encrypt_Text(ByVal str As String, _
  15.                                        Optional ByVal Include_Special_Characters As Boolean = False) As String
  16.  
  17.        Dim Temp_String As String = String.Empty
  18.        Dim Replacement_Found As Boolean = False
  19.  
  20.        Static Characters As Char()
  21.        Static Replacements As Char()
  22.  
  23.        If Include_Special_Characters Then
  24.            Characters = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ0123456789áéíóúÁÉÍÓÚàèìòùÀÈÌÒÙäëïöüÄËÏÖÜçǺª<>¡!¿?()[]{}/\|·.:;,-+=_~¬^'`´¨*$%&€#@""".ToCharArray
  25.            Replacements = {"h", "ó", "Ó", "3", "Á", "è", "A", "^", "ö", "~", "O", "Í", "€", "q", "ú", "À", "Ç", "È", ",", "ì", "i", "ï", "ò", "c", "0", "ñ", "4", "l", "Ü", "ª", "¬", "S", "&", "?", "<", ":", "T", "*", "e", ".", "R", "É", "D", "7", "9", "Ú", "n", "¿", "L", "m", "¨", "Ë", "]", "Ä", "Q", "w", "V", "'", "G", "K", "é", "v", "ù", "}", "P", "E", "X", "+", "í", "´", "$", "{", "_", "Ñ", "u", "ë", "H", "g", "d", "x", "8", "/", "ä", "#", "|", "-", "1", "M", "Ò", "o", ")", "N", "Y", "á", "Ù", "Ì", "%", "ç", """", "a", "=", "Ï", "z", "Ö", ">", ";", "2", "6", "B", "y", "b", "`", "s", "5", "t", "[", "(", "à", "ü", "!", "¡", "f", "W", "k", "r", "U", "J", "·", "Z", "F", "C", "º", "I", "@", "p", "j"}
  26.        Else
  27.            Characters = _
  28.            "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ0123456789áéíóúÁÉÍÓÚàèìòùÀÈÌÒÙäëïöüÄËÏÖÜçǺª¡¿·¬`´¨€".ToCharArray
  29.            ' Removed chars for better improvement in code encryptation: = & + - ^ " % ' < > ( ) { } . $ [ ] ; @ ! ? ~ : / \ | * # , _
  30.  
  31.            Replacements = _
  32.            {"u", "Ñ", "T", "m", "`", "P", "Ç", "Z", "h", "x", "á", "3", "¬", "R", "ª", "6", "ò", "N", "ë", "Ì", "g", "ö", "I", "L", "a", "À", "·", "V", "5", "Ë", "Ù", "´", "Ö", "J", "à", "¡", "n", "4", "È", "j", "ç", "b", "c", "y", "E", "ù", "Ó", "f", "º", "Q", "q", "G", "e", "B", "0", "€", "9", "o", "ì", "O", "8", "¿", "r", "v", "ó", "2", "Ï", "1", "¨", "i", "Á", "D", "t", "Í", "k", "Ú", "C", "ñ", "Ä", "S", "A", "é", "7", "Ü", "K", "z", "í", "è", "Y", "ü", "F", "s", "p", "X", "U", "Ò", "l", "É", "ú", "d", "ï", "M", "W", "H", "ä", "w"}
  33.            '  a,   b,   c,   d,   e,   f,   g,   h,   i,   j,   k,   l,   m,   n,   ñ,   o,   p,   q,   r,   s,   t,   u,   v,   w,   x,   y,   z,   A,   B,   C,   D,   E,   F,   G,   H,   I,   J,   K,   L,   M,   N,   Ñ,   O,   P,   Q,   R,   S,   T,   U,   V,   W,   X,   Y,   Z,   0,   1,   2,   3,   4,   5,   6,   7,   8,   9,   á,   é,   í,   ó,   ú,   Á,   É,   Í,   Ó,   Ú,   à,   è,   ì,   ò,   ù,   À,   È,   Ì,   Ò,   Ù,   ä,   ë,   ï,   ö,   ü,   Ä,   Ë,   Ï,   Ö,   Ü,   ç,   Ç,   º,   ª,   ¡,   ¿,   ·,   ¬,   `,   ´,   ¨,   €
  34.        End If
  35.  
  36.        For Each character As Char In str
  37.  
  38.            For x As Int32 = 0 To Characters.Length - 1
  39.  
  40.                If character = Characters(x) Then
  41.                    Replacement_Found = True
  42.                    Temp_String &= Replacements(x)
  43.                    Exit For
  44.                End If
  45.  
  46.            Next
  47.  
  48.            If Not Replacement_Found Then Temp_String &= character Else Replacement_Found = False
  49.            Application.DoEvents()
  50.  
  51.        Next
  52.  
  53.        Return Temp_String
  54.  
  55.    End Function
  56.  
  57.    Public Shared Function Decrypt_Text(ByVal str As String, _
  58.                                        Optional ByVal Include_Special_Characters As Boolean = False) As String
  59.  
  60.        Dim Temp_String As String = String.Empty
  61.        Dim Replacement_Found As Boolean = False
  62.  
  63.        Static Characters As Char()
  64.        Static Replacements As Char()
  65.  
  66.        If Include_Special_Characters Then
  67.            Characters = {"h", "ó", "Ó", "3", "Á", "è", "A", "^", "ö", "~", "O", "Í", "€", "q", "ú", "À", "Ç", "È", ",", "ì", "i", "ï", "ò", "c", "0", "ñ", "4", "l", "Ü", "ª", "¬", "S", "&", "?", "<", ":", "T", "*", "e", ".", "R", "É", "D", "7", "9", "Ú", "n", "¿", "L", "m", "¨", "Ë", "]", "Ä", "Q", "w", "V", "'", "G", "K", "é", "v", "ù", "}", "P", "E", "X", "+", "í", "´", "$", "{", "_", "Ñ", "u", "ë", "H", "g", "d", "x", "8", "/", "ä", "#", "|", "-", "1", "M", "Ò", "o", ")", "N", "Y", "á", "Ù", "Ì", "%", "ç", """", "a", "=", "Ï", "z", "Ö", ">", ";", "2", "6", "B", "y", "b", "`", "s", "5", "t", "[", "(", "à", "ü", "!", "¡", "f", "W", "k", "r", "U", "J", "·", "Z", "F", "C", "º", "I", "@", "p", "j"}
  68.            Replacements = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ0123456789áéíóúÁÉÍÓÚàèìòùÀÈÌÒÙäëïöüÄËÏÖÜçǺª<>¡!¿?()[]{}/\|·.:;,-+=_~¬^'`´¨*$%&€#@""".ToCharArray
  69.        Else
  70.            Characters = _
  71.            {"u", "Ñ", "T", "m", "`", "P", "Ç", "Z", "h", "x", "á", "3", "¬", "R", "ª", "6", "ò", "N", "ë", "Ì", "g", "ö", "I", "L", "a", "À", "·", "V", "5", "Ë", "Ù", "´", "Ö", "J", "à", "¡", "n", "4", "È", "j", "ç", "b", "c", "y", "E", "ù", "Ó", "f", "º", "Q", "q", "G", "e", "B", "0", "€", "9", "o", "ì", "O", "8", "¿", "r", "v", "ó", "2", "Ï", "1", "¨", "i", "Á", "D", "t", "Í", "k", "Ú", "C", "ñ", "Ä", "S", "A", "é", "7", "Ü", "K", "z", "í", "è", "Y", "ü", "F", "s", "p", "X", "U", "Ò", "l", "É", "ú", "d", "ï", "M", "W", "H", "ä", "w"}
  72.            '  a,   b,   c,   d,   e,   f,   g,   h,   i,   j,   k,   l,   m,   n,   ñ,   o,   p,   q,   r,   s,   t,   u,   v,   w,   x,   y,   z,   A,   B,   C,   D,   E,   F,   G,   H,   I,   J,   K,   L,   M,   N,   Ñ,   O,   P,   Q,   R,   S,   T,   U,   V,   W,   X,   Y,   Z,   0,   1,   2,   3,   4,   5,   6,   7,   8,   9,   á,   é,   í,   ó,   ú,   Á,   É,   Í,   Ó,   Ú,   à,   è,   ì,   ò,   ù,   À,   È,   Ì,   Ò,   Ù,   ä,   ë,   ï,   ö,   ü,   Ä,   Ë,   Ï,   Ö,   Ü,   ç,   Ç,   º,   ª,   ¡,   ¿,   ·,   ¬,   `,   ´,   ¨,   €
  73.  
  74.            Replacements = _
  75.             "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ0123456789áéíóúÁÉÍÓÚàèìòùÀÈÌÒÙäëïöüÄËÏÖÜçǺª¡¿·¬`´¨€".ToCharArray
  76.            ' Removed chars for better improvement in code encryptation: = & + - ^ " % ' < > ( ) { } . $ [ ] ; @ ! ? ~ : / \ | * # , _
  77.        End If
  78.  
  79.        For Each character As Char In str
  80.  
  81.            For x As Int32 = 0 To Characters.Length - 1
  82.  
  83.                If character = Characters(x) Then
  84.                    Replacement_Found = True
  85.                    Temp_String &= Replacements(x)
  86.                    Exit For
  87.                End If
  88.  
  89.            Next
  90.  
  91.            If Not Replacement_Found Then Temp_String &= character Else Replacement_Found = False
  92.            Application.DoEvents()
  93.  
  94.        Next
  95.  
  96.        Return Temp_String
  97.  
  98.    End Function
  99.  
  100. #End Region

« Última modificación: 9 Junio 2013, 19:01 pm por EleKtro H@cker » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.813



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #165 en: 11 Junio 2013, 11:56 am »

Otro código de ORO:

Devuelve de la manera más eficaz y sencilla una lista de tipo FileInfo con todos los archivos de un directorio,
Le hice dos overloads para poder usar la función de varias maneras y evitar posibles errores en el "SearchPattern",
La función es "IgnoreCase", devuelve la extensión en uppercase y lowercase y todas las variantes posibles, en fin, esto es la perfección:

Código
  1. #Region " Get Files "
  2.  
  3.    ' [ Get Files Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    '
  9.    ' For Each file In Get_Files("C:\Windows", False) : MsgBox(file.Name) : Next
  10.    '
  11.    ' For Each file In Get_Files("C:\Windows", True, "dll")   : MsgBox(file.Name) : Next
  12.    ' For Each file In Get_Files("C:\Windows", True, ".dll")  : MsgBox(file.Name) : Next
  13.    ' For Each file In Get_Files("C:\Windows", True, "*.dll") : MsgBox(file.Name) : Next
  14.    '
  15.    ' For Each file In Get_Files("C:\Windows", False, {"dll", "ini"})     : MsgBox(file.Name) : Next
  16.    ' For Each file In Get_Files("C:\Windows", False, {".dll", ".ini"})   : MsgBox(file.Name) : Next
  17.    ' For Each file In Get_Files("C:\Windows", False, {"*.dll", "*.ini"}) : MsgBox(file.Name) : Next
  18.  
  19.    ' Get Files {directory} {recursive}
  20.    Private Function Get_Files(ByVal directory As String, ByVal recursive As Boolean) As List(Of IO.FileInfo)
  21.        Dim searchOpt As IO.SearchOption = If(recursive, IO.SearchOption.AllDirectories, IO.SearchOption.TopDirectoryOnly)
  22.        Return IO.Directory.GetFiles(directory, "*", searchOpt).Select(Function(p) New IO.FileInfo(p)).ToList
  23.    End Function
  24.  
  25.    ' Get Files {directory} {recursive} {ext}
  26.    Private Function Get_Files(ByVal directory As String, ByVal recursive As Boolean, ext As String) As List(Of IO.FileInfo)
  27.  
  28.        If ext.StartsWith("*") Then
  29.            ext = ext.Substring(1, ext.Length - 1)
  30.        ElseIf Not ext = "*" AndAlso Not ext.StartsWith(".") Then
  31.            ext = ("." & ext)
  32.        ElseIf ext = "*" Then
  33.            ext = Nothing
  34.        End If
  35.  
  36.        Dim searchOpt As IO.SearchOption = If(recursive, IO.SearchOption.AllDirectories, IO.SearchOption.TopDirectoryOnly)
  37.        Return IO.Directory.GetFiles(directory, "*" & ext, searchOpt).Select(Function(p) New IO.FileInfo(p)).ToList
  38.  
  39.    End Function
  40.  
  41.    ' Get Files {directory} {recursive} {exts()}
  42.    Private Function Get_Files(ByVal directory As String, ByVal recursive As Boolean, ParamArray exts() As String) As List(Of IO.FileInfo)
  43.  
  44.        Dim FileExts(exts.Count) As String
  45.        Dim ExtCount As Int32 = 0
  46.  
  47.        For Each ext In exts
  48.            If ext.StartsWith("*") Then
  49.                FileExts(ExtCount) = ext.Substring(1, ext.Length - 1)
  50.            ElseIf Not ext = "*" AndAlso Not ext.StartsWith(".") Then
  51.                FileExts(ExtCount) = ("." & ext)
  52.            ElseIf Not ext = "*" AndAlso ext.StartsWith(".") Then
  53.                FileExts(ExtCount) = ext
  54.            ElseIf ext = "*" Then
  55.                FileExts(ExtCount) = Nothing
  56.            End If
  57.            ExtCount += 1
  58.        Next
  59.  
  60.        Dim searchOpt As IO.SearchOption = If(recursive, IO.SearchOption.AllDirectories, IO.SearchOption.TopDirectoryOnly)
  61.        Dim filenameExtComparer As New FilenameExtensionComparer
  62.        Return IO.Directory.GetFiles(directory, "*", searchOpt).Where(Function(o) FileExts.Contains(IO.Path.GetExtension(o), filenameExtComparer)).Select(Function(p) New IO.FileInfo(p)).ToList
  63.  
  64.    End Function
  65.  
  66.    ' FilenameExtensionComparer
  67.    Public Class FilenameExtensionComparer : Implements IEqualityComparer(Of String)
  68.  
  69.        Public Function Equals1(s As String, t As String) As Boolean Implements IEqualityComparer(Of String).Equals
  70.            Return String.Compare(s, t, StringComparison.OrdinalIgnoreCase) = 0
  71.        End Function
  72.  
  73.        Public Function GetHashCode1(s As String) As Integer Implements IEqualityComparer(Of String).GetHashCode
  74.            Return s.GetHashCode()
  75.        End Function
  76.  
  77.    End Class
  78.  
  79. #End Region
« Última modificación: 11 Junio 2013, 11:59 am por EleKtro H@cker » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.813



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #166 en: 11 Junio 2013, 19:59 pm »

Cargar o guardar valores fácilmente en un archivo INI:

Código
  1. #Region " INI Manager "
  2.  
  3. ' [ INI Manager Functions ]
  4. '
  5. ' // By Elektro H@cker
  6. '
  7. ' Examples :
  8. '
  9. ' INI_Manager.Set_Value(".\Test.ini", "TextValue", TextBox1.Text) ' Save
  10. ' TextBox1.Text = INI_Manager.Load_Value(".\Test.ini", "TextValue") ' Load
  11. ' INI_Manager.Delete_Value(".\Test.ini", "TextValue") ' Delete
  12. ' INI_Manager.Sort_Values(".\Test.ini") ' Sort INI File
  13.  
  14. Public Class INI_Manager
  15.  
  16.    ''' <summary>
  17.    ''' The INI File Location.
  18.    ''' </summary>
  19.    Public Shared INI_File As String = IO.Path.Combine(Application.StartupPath, Process.GetCurrentProcess().ProcessName & ".ini")
  20.  
  21.    ''' <summary>
  22.    ''' Set a value.
  23.    ''' </summary>
  24.    ''' <param name="File">The INI file location</param>
  25.    ''' <param name="ValueName">The value name</param>
  26.    ''' <param name="Value">The value data</param>
  27.    Public Shared Sub Set_Value(ByVal File As String, ByVal ValueName As String, ByVal Value As String)
  28.  
  29.        Try
  30.  
  31.            If Not IO.File.Exists(File) Then ' Create a new INI File with "Key=Value""
  32.  
  33.                My.Computer.FileSystem.WriteAllText(File, ValueName & "=" & Value, False)
  34.                Exit Sub
  35.  
  36.            Else ' Search line by line in the INI file for the "Key"
  37.  
  38.                Dim Line_Number As Int64 = 0
  39.                Dim strArray() As String = IO.File.ReadAllLines(File)
  40.  
  41.                For Each line In strArray
  42.                    If line.ToLower.StartsWith(ValueName.ToLower & "=") Then
  43.                        strArray(Line_Number) = ValueName & "=" & Value
  44.                        IO.File.WriteAllLines(File, strArray) ' Replace "value"
  45.                        Exit Sub
  46.                    End If
  47.                    Line_Number += 1
  48.                Next
  49.  
  50.                Application.DoEvents()
  51.  
  52.                My.Computer.FileSystem.WriteAllText(File, vbNewLine & ValueName & "=" & Value, True) ' Key don't exist, then create the new "Key=Value"
  53.  
  54.            End If
  55.  
  56.        Catch ex As Exception
  57.            MsgBox(ex.Message)
  58.        End Try
  59.  
  60.    End Sub
  61.  
  62.    ''' <summary>
  63.    ''' Load a value.
  64.    ''' </summary>
  65.    ''' <param name="File">The INI file location</param>
  66.    ''' <param name="ValueName">The value name</param>
  67.    ''' <returns>The value itself</returns>
  68.    Public Shared Function Load_Value(ByVal File As String, ByVal ValueName As String) As Object
  69.  
  70.        If Not IO.File.Exists(File) Then
  71.  
  72.            Throw New Exception(File & " not found.") ' INI File not found.
  73.            Return Nothing
  74.  
  75.        Else
  76.  
  77.            For Each line In IO.File.ReadAllLines(File)
  78.                If line.ToLower.StartsWith(ValueName.ToLower & "=") Then Return line.Split("=").Last
  79.            Next
  80.  
  81.            Application.DoEvents()
  82.  
  83.            Throw New Exception("Key: " & """" & ValueName & """" & " not found.") ' Key not found.
  84.            Return Nothing
  85.  
  86.        End If
  87.  
  88.    End Function
  89.  
  90.    ''' <summary>
  91.    ''' Delete a key.
  92.    ''' </summary>
  93.    ''' <param name="File">The INI file location</param>
  94.    ''' <param name="ValueName">The value name</param>
  95.    Public Shared Sub Delete_Value(ByVal File As String, ByVal ValueName As String)
  96.  
  97.        If Not IO.File.Exists(File) Then
  98.  
  99.            Throw New Exception(File & " not found.") ' INI File not found.
  100.            Exit Sub
  101.  
  102.        Else
  103.  
  104.            Try
  105.  
  106.                Dim Line_Number As Int64 = 0
  107.                Dim strArray() As String = IO.File.ReadAllLines(File)
  108.  
  109.                For Each line In strArray
  110.                    If line.ToLower.StartsWith(ValueName.ToLower & "=") Then
  111.                        strArray(Line_Number) = Nothing
  112.                        Exit For
  113.                    End If
  114.                    Line_Number += 1
  115.                Next
  116.  
  117.                Array.Copy(strArray, Line_Number + 1, strArray, Line_Number, UBound(strArray) - Line_Number)
  118.                ReDim Preserve strArray(UBound(strArray) - 1)
  119.  
  120.                My.Computer.FileSystem.WriteAllText(File, String.Join(vbNewLine, strArray), False)
  121.  
  122.            Catch ex As Exception
  123.                MsgBox(ex.Message)
  124.            End Try
  125.  
  126.        End If
  127.  
  128.    End Sub
  129.  
  130.    ''' <summary>
  131.    ''' Sorts the entire INI File.
  132.    ''' </summary>
  133.    ''' <param name="File">The INI file location</param>
  134.    Public Shared Sub Sort_Values(ByVal File As String)
  135.  
  136.        If Not IO.File.Exists(File) Then
  137.  
  138.            Throw New Exception(File & " not found.") ' INI File not found.
  139.            Exit Sub
  140.  
  141.        Else
  142.  
  143.            Try
  144.  
  145.                Dim Line_Number As Int64 = 0
  146.                Dim strArray() As String = IO.File.ReadAllLines(File)
  147.                Dim TempList As New List(Of String)
  148.  
  149.                For Each line As String In strArray
  150.                    If line <> "" Then TempList.Add(strArray(Line_Number))
  151.                    Line_Number += 1
  152.                Next
  153.  
  154.                TempList.Sort()
  155.                IO.File.WriteAllLines(File, TempList)
  156.  
  157.            Catch ex As Exception
  158.                MsgBox(ex.Message)
  159.            End Try
  160.  
  161.        End If
  162.  
  163.    End Sub
  164.  
  165. End Class
  166.  
  167. #End Region
« Última modificación: 11 Junio 2013, 20:02 pm por EleKtro H@cker » En línea

z3nth10n


Desconectado Desconectado

Mensajes: 1.583


"Jack of all trades, master of none." - Zenthion


Ver Perfil WWW
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #167 en: 11 Junio 2013, 21:06 pm »

Entonces este IniReader usa Secciones? Si no explicame, como hago para llamar a 2 pcbs desde el mismo .INI :silbar: ;D
En línea


Interesados hablad por Discord.
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.813



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #168 en: 11 Junio 2013, 21:51 pm »

Entonces este IniReader usa Secciones?
No, no lee secciones ni tampoco guarda secciones, no me gustan las secciones ni tampoco las considero útiles, menos para aplicaciones grandes como CCleaner.

explicame, como hago para llamar a 2 pcbs desde el mismo .INI :silbar: ;D

Pues primero guardas el valor de cada PictureBox en el ini, y luego obtienes los valores préviamente guardados y los asignas a... a lo que estés intentando asignarlo.

Lee los comentarios al principio de la Class, ahí hay ejemplos, no sé que puede resultar tán dificil (de verdad), crea un post porque si con esos ejemplos no te aclara entonces ya no se que más decir.

Saludos!
« Última modificación: 11 Junio 2013, 21:57 pm por EleKtro H@cker » En línea

z3nth10n


Desconectado Desconectado

Mensajes: 1.583


"Jack of all trades, master of none." - Zenthion


Ver Perfil WWW
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #169 en: 11 Junio 2013, 22:07 pm »

Nada ya se como quedaría, a veces parezco tonto. :-[
« Última modificación: 11 Junio 2013, 22:26 pm por Ikillnukes » En línea


Interesados hablad por Discord.
Páginas: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 [17] 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 ... 59 Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines