Strip out Strings of exe files

By | 2019-09-27

This is a small little bit code that will rip out all the string in a file. Start a new program and place this code in to the General Declarations select of the Form. Also you will need to add a command button to the form as well. Then press F5.

Module

Public Sub sDumpStrings(strFile As String, strTextFile As String, intMinSize As Integer)
    
    If Len(Dir(strFile)) = 0 Then Exit Sub
    Dim b() As Byte
    Dim hFile As Integer
    Dim bIsString As Boolean
    Dim i As Long
    Dim lngLen As Long
    Dim strLine As String
    Const strCompare = "[A-Z a-z 0-9,.!?@#$%]"
    hFile = FreeFile
    Open strFile For Binary As #hFile
    lngLen = LOF(hFile)
    ReDim b(1 To lngLen)
    Get #hFile, , b
    Close #hFile
    
    hFile = FreeFile
    Open strTextFile For Output As #hFile
    
    For i = 1 To lngLen
        If Chr(b(i)) Like strCompare Then
            If Chr(b(i + 1)) Like strCompare Then
                strLine = strLine & Chr(b(i))
            ElseIf i > 1 Then
                If Chr(b(i - 1)) Like strCompare Then
                    strLine = strLine & Chr(b(i))
                    If Len(strLine) > intMinSize Then
                        Print #hFile, strLine
                        Debug.Print strLine
                    End If
                    strLine = ""
                End If
            End If
        End If
    Next

    Close #hFile
    MsgBox "All done", vbInformation
    
End Sub

Usage

Private Sub Command1_Click()
    sDumpStrings "C:\Windows\Notepad.exe", "C:\Notepad.txt", 15
    ' Change the filename if you like
    
End Sub

Private Sub Form_Load()
    Command1.Caption = "Strip out Strings"
    
End Sub

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.