diff --git a/CapConverter.exe b/CapConverter.exe index 3dcd587..74d1ca8 100644 Binary files a/CapConverter.exe and b/CapConverter.exe differ diff --git a/ComDlg32.OCX b/ComDlg32.OCX deleted file mode 100644 index e3de177..0000000 Binary files a/ComDlg32.OCX and /dev/null differ diff --git a/CommonDialogs.bas b/CommonDialogs.bas new file mode 100644 index 0000000..36f2f29 --- /dev/null +++ b/CommonDialogs.bas @@ -0,0 +1,167 @@ +Attribute VB_Name = "CommonDialogs" +Option Explicit +Public Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long +Public Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long +Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenFilename As OPENFILENAME) As Long +Public Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenFilename As OPENFILENAME) As Long +Public Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long +Public Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long +Public Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long +Public Declare Function lstrlen Lib "kernel32" Alias "lstrlenW" (ByVal lpString As Long) As Long + +Public Type OPENFILENAME + lStructSize As Long 'The size of this struct (Use the Len function) + hwndOwner As Long 'The hWnd of the owner window. The dialog will be modal to this window + hInstance As Long 'The instance of the calling thread. You can use the App.hInstance here. + lpstrFilter As String 'Use this to filter what files are shown in the dialog. Separate each filter with Chr$(0). The string also has to end with a Chr(0). + lpstrCustomFilter As String 'The pattern the user has chosen is saved here if you pass a non empty string. I never use this one + nMaxCustFilter As Long 'The maximum saved custom filters. Since I never use the lpstrCustomFilter I always pass 0 to this. + nFilterIndex As Long 'What filter (of lpstrFilter) is showed when the user opens the dialog. + lpstrFile As String 'The path and name of the file the user has chosed. This must be at least MAX_PATH (260) character long. + nMaxFile As Long 'The length of lpstrFile + 1 + lpstrFileTitle As String 'The name of the file. Should be MAX_PATH character long + nMaxFileTitle As Long 'The length of lpstrFileTitle + 1 + lpstrInitialDir As String 'The path to the initial path. If you pass an empty string the initial path is the current path. + lpstrTitle As String 'The caption of the dialog. + flags As Long 'Flags. See the values in MSDN Library (you can look at the flags property of the common dialog control) + nFileOffset As Integer 'Points to the what character in lpstrFile where the actual filename begins (zero based) + nFileExtension As Integer 'Same as nFileOffset except that it points to the file extention. + lpstrDefExt As String 'Can contain the extention Windows should add to a file if the user doesn't provide one (used with the GetSaveFileName API function) + lCustData As Long 'Only used if you provide a Hook procedure + lpfnHook As Long 'Pointer to the hook procedure + lpTemplateName As String 'A string that contains a dialog template resource name. Only used with the hook procedure. +End Type + +Public Type OFSTRUCT + cBytes As Byte + fFixedDisk As Byte + nErrCode As Integer + Reserved1 As Integer + Reserved2 As Integer + szPathName(128&) As Byte +End Type + +Public Const OF_READ As Long = &H0 'Opens a file for reading only. +Public Const OF_WRITE As Long = &H1 'Opens a file for write access only. +Public Const OF_READWRITE As Long = &H2 'Opens a file with read/write permissions. +Public Const OF_SHARE_COMPAT As Long = &H0 'For MS-DOS–based file systems, opens a file with compatibility mode, allows any process on a specified computer to open the file any number of times. +Public Const OF_SHARE_DENY_NONE As Long = &H40 'Opens a file without denying read or write access to other processes. On MS-DOS-based file systems, if the file has been opened in compatibility mode by any other process, the function fails. +Public Const OF_SHARE_DENY_READ As Long = &H30 'Opens a file and denies read access to other processes. On MS-DOS-based file systems, if the file has been opened in compatibility mode, or for read access by any other process, the function fails. +Public Const OF_SHARE_DENY_WRITE As Long = &H20 'Opens a file and denies write access to other processes. On MS-DOS-based file systems, if a file has been opened in compatibility mode, or for write access by any other process, the function fails. +Public Const OF_SHARE_EXCLUSIVE As Long = &H10 'Opens a file with exclusive mode, and denies both read/write access to other processes. If a file has been opened in any other mode for read/write access, even by the current process, the function fails. +Public Const OF_CANCEL As Long = &H800 'Ignored. To produce a dialog box containing a Cancel button, use OF_PROMPT. +Public Const OF_CREATE As Long = &H1000 'Creates a new file. If the file exists, it is truncated to zero (0) length. +Public Const OF_DELETE As Long = &H200 'Deletes a file. +Public Const OF_EXIST As Long = &H4000 'Opens a file and then closes it. Use this to test for the existence of a file. +Public Const OF_PARSE As Long = &H100 'Fills the OFSTRUCT structure, but does not do anything else. +Public Const OF_PROMPT As Long = &H2000 'Displays a dialog box if a requested file does not exist. A dialog box informs a user that the system cannot find a file, and it contains Retry and Cancel buttons. The Cancel button directs OpenFile to return a file-not-found error message. +Public Const OF_REOPEN As Long = &H8000 'Opens a file by using information in the reopen buffer. +Public Const OF_VERIFY As Long = &H400 'Verifies that the date and time of a file are the same as when it was opened previously. This is useful as an extra check for read-only files. +Public Const HFILE_ERROR As Long = -1& + +Public Type BrowseInfo + hwndOwner As Long + pIDLRoot As Long + pszDisplayName As Long + lpszTitle As Long + ulFlags As Long + lpfnCallback As Long + lParam As Long + iImage As Long +End Type + +Public Function file_exists(ByVal file_name As String) As Boolean + On Error Resume Next + Dim lResult As Long + Dim open_file_struct As OFSTRUCT + lResult = OpenFile(file_name, open_file_struct, OF_EXIST) + file_exists = IIf(lResult <> -1&, True, False) +End Function + +Public Function is_file(str As String) As Boolean + Dim fso As Scripting.FileSystemObject + Set fso = New Scripting.FileSystemObject + Dim return_value As Boolean + return_value = fso.FileExists(str) + Set fso = Nothing + is_file = return_value +End Function + +Public Function is_folder(str As String) As Boolean + Dim fso As Scripting.FileSystemObject + Set fso = New Scripting.FileSystemObject + Dim return_value As Boolean + return_value = fso.FolderExists(str) + Set fso = Nothing + is_folder = return_value +End Function + +Public Function get_path_from_file(fileName As String) As String + Dim pos As Integer + pos = InStrRev(fileName, "\") + If pos > 0 Then + get_path_from_file = Left$(fileName, pos) + Else + get_path_from_file = "" + End If +End Function + +Public Function ShowOpenFileDialog(owner_hwnd As Long, caption As String) As String + Dim OFN As OPENFILENAME + OFN.lStructSize = Len(OFN) + OFN.hwndOwner = owner_hwnd + OFN.hInstance = App.hInstance + OFN.lpstrTitle = IIf(caption <> "", caption, "Choose File") + If (InStr(caption, "HCCAP") > 0) Then + OFN.lpstrFilter = "HCCAP Files (*.hccap)" & Chr$(0) & "*.hccap" & Chr$(0) + OFN.lpstrDefExt = "hccap" + ElseIf (InStr(caption, "CAP") > 0) Then + OFN.lpstrFilter = "CAP Files (*.cap;*.pcap;*.dmp)" & Chr$(0) & "*.cap;*.pcap;*.dmp" & Chr$(0) & "All files (*.*)" & Chr$(0) & "*.*" & Chr$(0) + OFN.lpstrDefExt = "cap" + Else + OFN.lpstrFilter = "All files (*.*)" & Chr$(0) & "*.*" & Chr$(0) + End If + OFN.nFilterIndex = 1 + OFN.lpstrFile = String(257, 0) + OFN.nMaxFile = Len(OFN.lpstrFile) - 1 + OFN.lpstrFileTitle = OFN.lpstrFile + OFN.nMaxFileTitle = OFN.nMaxFile + OFN.lpstrInitialDir = IIf((last_path <> ""), last_path, App.path) + OFN.flags = 0 + If GetOpenFileName(OFN) Then + last_path = get_path_from_file(Trim$(OFN.lpstrFile)) + ShowOpenFileDialog = IIf(is_file(Trim$(OFN.lpstrFile)), Trim$(OFN.lpstrFile), "") + Else + ShowOpenFileDialog = "" + End If +End Function + +Public Function ShowSaveFileDialog(owner_hwnd As Long, caption As String) As String + Dim OFN As OPENFILENAME + OFN.lStructSize = Len(OFN) + OFN.hwndOwner = owner_hwnd + OFN.hInstance = App.hInstance + OFN.lpstrTitle = IIf(caption <> "", caption, "Save File As") + If (InStr(caption, "HCCAP") > 0) Then + OFN.lpstrFilter = "HCCAP Files (*.hccap)" & Chr$(0) & "*.hccap" & Chr$(0) + OFN.lpstrDefExt = "hccap" + ElseIf (InStr(caption, "CAP") > 0) Then + OFN.lpstrFilter = "CAP Files (*.cap;*.pcap;*.dmp)" & Chr$(0) & "*.cap;*.pcap;*.dmp" & Chr$(0) & "All files (*.*)" & Chr$(0) & "*.*" & Chr$(0) + OFN.lpstrDefExt = "cap" + Else + OFN.lpstrFilter = "All files (*.*)" & Chr$(0) & "*.*" & Chr$(0) + End If + OFN.nFilterIndex = 1 + OFN.lpstrFile = String(257, 0) + OFN.nMaxFile = Len(OFN.lpstrFile) - 1 + OFN.lpstrFileTitle = OFN.lpstrFile + OFN.nMaxFileTitle = OFN.nMaxFile + OFN.lpstrInitialDir = IIf((last_path <> ""), last_path, App.path) + OFN.flags = 0 + If GetSaveFileName(OFN) Then + last_path = get_path_from_file(Trim$(OFN.lpstrFile)) + ShowSaveFileDialog = Trim$(OFN.lpstrFile) + Else + ShowSaveFileDialog = "" + End If +End Function diff --git a/Form1.frm b/Form1.frm index 518e95c..08a5a6a 100644 --- a/Form1.frm +++ b/Form1.frm @@ -1,5 +1,4 @@ VERSION 5.00 -Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX" Begin VB.Form Form1 Caption = "Cap Converter" ClientHeight = 10335 @@ -48,13 +47,6 @@ Begin VB.Form Form1 Top = 375 Width = 495 End - Begin MSComDlg.CommonDialog CommonDialog - Left = 6960 - Top = 8880 - _ExtentX = 847 - _ExtentY = 847 - _Version = 393216 - End Begin VB.CommandButton btnWriteCAP Caption = "Save As CAP..." Height = 645 @@ -254,7 +246,6 @@ Begin VB.Form Form1 Begin VB.Label lblCounter Alignment = 1 'Right Justify Caption = "0" - Enabled = 0 'False Height = 195 Left = 2760 TabIndex = 25 @@ -371,7 +362,7 @@ Option Explicit Private Sub btnNext_Click() If (num_hccap_records > 1) Then current_index = current_index + 1 - lblCounter.Caption = current_index + 1 & "/" & num_hccap_records + lblCounter.caption = current_index + 1 & "/" & num_hccap_records If num_hccap_records - 1 > current_index Then btnNext.Enabled = True Else @@ -397,7 +388,7 @@ End Sub Private Sub btnPrev_Click() If (num_hccap_records > 1) Then current_index = current_index - 1 - lblCounter.Caption = current_index + 1 & "/" & num_hccap_records + lblCounter.caption = current_index + 1 & "/" & num_hccap_records If num_hccap_records - 1 > current_index Then btnNext.Enabled = True Else @@ -450,46 +441,42 @@ ElseIf txtKEYMIC.Text = "" Then txtKEYMIC.SetFocus Exit Sub End If -CommonDialog.fileName = "" -CommonDialog.Filter = "CAP Files (*.cap;*.pcap;*.dmp)|*.cap;*.pcap;*.dmp|All files (*.*)|*.*" -CommonDialog.DefaultExt = "cap" -CommonDialog.DialogTitle = "Save CAP As" -CommonDialog.InitDir = IIf((last_path <> ""), last_path, App.path) -CommonDialog.ShowSave -If (CommonDialog.CancelError = False) And (CommonDialog.fileName <> "") Then - last_path = get_path_from_file(CommonDialog.fileName) + +Dim file_to_save As String +Dim msgbox_result As VbMsgBoxResult +file_to_save = ShowSaveFileDialog(Me.hwnd, "Save CAP As") +If (file_to_save <> "") Then + If is_file(file_to_save) = True Then + msgbox_result = MsgBox("A file named """ & Left$(file_to_save, lstrlen(StrPtr(file_to_save))) & """ already exists. Replace?", vbExclamation + vbYesNo, "Warning") + If (msgbox_result = vbNo) Then + Call btnWriteCAP_Click + Exit Sub + End If + End If If (num_hccap_records > 1) Then - Dim msgbox_result As VbMsgBoxResult msgbox_result = MsgBox("Multiple handshakes were detected." & vbCrLf & "Would you like to save all of them to a single CAP file?" & vbCrLf & vbCrLf & "YES: will save all handshakes to a single cap file" & vbCrLf & "NO: will save only the currently selected handshake" & vbCrLf & "CANCEL: will not save anything", vbQuestion + vbYesNoCancel, "Create multi cap?") If (msgbox_result = vbYes) Then - Call WriteCAP(CommonDialog.fileName, txtESSID.Text, txtBSSID.Text, txtSTA.Text, txtSNONCE.Text, txtANONCE.Text, txtEAPOL.Text, txtEAPOLSIZE.Text, txtKEYVER.Text, txtKEYMIC.Text, False) + Call WriteCAP(file_to_save, txtESSID.Text, txtBSSID.Text, txtSTA.Text, txtSNONCE.Text, txtANONCE.Text, txtEAPOL.Text, txtEAPOLSIZE.Text, txtKEYVER.Text, txtKEYMIC.Text, False) ElseIf (msgbox_result = vbNo) Then - Call WriteCAP(CommonDialog.fileName, txtESSID.Text, txtBSSID.Text, txtSTA.Text, txtSNONCE.Text, txtANONCE.Text, txtEAPOL.Text, txtEAPOLSIZE.Text, txtKEYVER.Text, txtKEYMIC.Text, True) + Call WriteCAP(file_to_save, txtESSID.Text, txtBSSID.Text, txtSTA.Text, txtSNONCE.Text, txtANONCE.Text, txtEAPOL.Text, txtEAPOLSIZE.Text, txtKEYVER.Text, txtKEYMIC.Text, True) End If Else - Call WriteCAP(CommonDialog.fileName, txtESSID.Text, txtBSSID.Text, txtSTA.Text, txtSNONCE.Text, txtANONCE.Text, txtEAPOL.Text, txtEAPOLSIZE.Text, txtKEYVER.Text, txtKEYMIC.Text, True) + Call WriteCAP(file_to_save, txtESSID.Text, txtBSSID.Text, txtSTA.Text, txtSNONCE.Text, txtANONCE.Text, txtEAPOL.Text, txtEAPOLSIZE.Text, txtKEYVER.Text, txtKEYMIC.Text, True) End If End If End Sub Private Sub btnReadCAP_Click() -CommonDialog.fileName = "" -CommonDialog.Filter = "CAP Files (*.cap;*.pcap;*.dmp)|*.cap;*.pcap;*.dmp|All files (*.*)|*.*" -CommonDialog.FilterIndex = 1 -CommonDialog.DefaultExt = "cap" -CommonDialog.DialogTitle = "Choose CAP File" -CommonDialog.InitDir = IIf((last_path <> ""), last_path, App.path) -CommonDialog.ShowOpen -If (CommonDialog.CancelError = False) And (CommonDialog.fileName <> "") Then +Dim file_to_open As String +file_to_open = ShowOpenFileDialog(Me.hwnd, "Choose CAP File") +If (file_to_open <> "") Then btnReadCAP.Enabled = False btnReadHCCAP.Enabled = False btnWriteCAP.Enabled = False btnWriteHCCAP.Enabled = False - last_path = get_path_from_file(CommonDialog.fileName) - tmp_hccap_records = ReadCAP(CommonDialog.fileName) + tmp_hccap_records = ReadCAP(file_to_open) If (num_hccap_records > 0) Then lblCounter.Visible = True - lblCounter.Enabled = True txtESSID.Text = tmp_hccap_records(0).ESSID txtBSSID.Text = tmp_hccap_records(0).BSSID txtSTA.Text = tmp_hccap_records(0).STATION_MAC @@ -501,8 +488,8 @@ If (CommonDialog.CancelError = False) And (CommonDialog.fileName <> "") Then txtKEYMIC.Text = tmp_hccap_records(0).KEY_MIC End If current_index = 0 - lblCounter.Caption = current_index + 1 & "/" & num_hccap_records - If (current_index = 0) And (num_hccap_records = 1) Then + lblCounter.caption = current_index + 1 & "/" & num_hccap_records + If ((current_index = 0) And (num_hccap_records = 1)) Or (num_hccap_records = 0) Then lblCounter.Visible = False End If If num_hccap_records > 1 Then @@ -521,19 +508,12 @@ End If End Sub Private Sub btnReadHCCAP_Click() -On Error Resume Next -CommonDialog.fileName = "" -CommonDialog.Filter = "HCCAP Files (*.hccap)|*.hccap" -CommonDialog.DefaultExt = "hccap" -CommonDialog.DialogTitle = "Choose HCCAP File" -CommonDialog.InitDir = IIf((last_path <> ""), last_path, App.path) -CommonDialog.ShowOpen -If (CommonDialog.CancelError = False) And (CommonDialog.fileName <> "") Then - last_path = get_path_from_file(CommonDialog.fileName) - tmp_hccap_records = ReadHCCAP(CommonDialog.fileName) +Dim file_to_open As String +file_to_open = ShowOpenFileDialog(Me.hwnd, "Choose HCCAP File") +If (file_to_open <> "") Then + tmp_hccap_records = ReadHCCAP(file_to_open) If (num_hccap_records > 0) Then lblCounter.Visible = True - lblCounter.Enabled = True txtESSID.Text = tmp_hccap_records(0).ESSID txtBSSID.Text = tmp_hccap_records(0).BSSID txtSTA.Text = tmp_hccap_records(0).STATION_MAC @@ -545,8 +525,8 @@ If (CommonDialog.CancelError = False) And (CommonDialog.fileName <> "") Then txtKEYMIC.Text = tmp_hccap_records(0).KEY_MIC End If current_index = 0 - lblCounter.Caption = current_index + 1 & "/" & num_hccap_records - If (current_index = 0) And (num_hccap_records = 1) Then + lblCounter.caption = current_index + 1 & "/" & num_hccap_records + If ((current_index = 0) And (num_hccap_records = 1)) Or (num_hccap_records = 0) Then lblCounter.Visible = False End If If num_hccap_records > 1 Then @@ -590,24 +570,27 @@ ElseIf txtKEYMIC.Text = "" Then txtKEYMIC.SetFocus Exit Sub End If -CommonDialog.fileName = "" -CommonDialog.Filter = "HCCAP Files (*.hccap)|*.hccap" -CommonDialog.DefaultExt = "hccap" -CommonDialog.DialogTitle = "Save HCCAP As" -CommonDialog.InitDir = IIf((last_path <> ""), last_path, App.path) -CommonDialog.ShowSave -If (CommonDialog.CancelError = False) And (CommonDialog.fileName <> "") Then - last_path = get_path_from_file(CommonDialog.fileName) + +Dim file_to_save As String +Dim msgbox_result As VbMsgBoxResult +file_to_save = ShowSaveFileDialog(Me.hwnd, "Save HCCAP As") +If (file_to_save <> "") Then + If is_file(file_to_save) = True Then + msgbox_result = MsgBox("A file named """ & Left$(file_to_save, lstrlen(StrPtr(file_to_save))) & """ already exists. Replace?", vbExclamation + vbYesNo, "Warning") + If (msgbox_result = vbNo) Then + Call btnWriteHCCAP_Click + Exit Sub + End If + End If If (num_hccap_records > 1) Then - Dim msgbox_result As VbMsgBoxResult msgbox_result = MsgBox("Multiple handshakes were detected." & vbCrLf & "Would you like to save all of them to a single HCCAP file?" & vbCrLf & vbCrLf & "YES: will save all handshakes to a single multi hccap file" & vbCrLf & "NO: will save only the currently selected handshake" & vbCrLf & "CANCEL: will not save anything", vbQuestion + vbYesNoCancel, "Create multi hccap?") If (msgbox_result = vbYes) Then - Call WriteHCCAP(CommonDialog.fileName, txtESSID.Text, txtBSSID.Text, txtSTA.Text, txtSNONCE.Text, txtANONCE.Text, txtEAPOL.Text, txtEAPOLSIZE.Text, txtKEYVER.Text, txtKEYMIC.Text, False) + Call WriteHCCAP(file_to_save, txtESSID.Text, txtBSSID.Text, txtSTA.Text, txtSNONCE.Text, txtANONCE.Text, txtEAPOL.Text, txtEAPOLSIZE.Text, txtKEYVER.Text, txtKEYMIC.Text, False) ElseIf (msgbox_result = vbNo) Then - Call WriteHCCAP(CommonDialog.fileName, txtESSID.Text, txtBSSID.Text, txtSTA.Text, txtSNONCE.Text, txtANONCE.Text, txtEAPOL.Text, txtEAPOLSIZE.Text, txtKEYVER.Text, txtKEYMIC.Text, True) + Call WriteHCCAP(file_to_save, txtESSID.Text, txtBSSID.Text, txtSTA.Text, txtSNONCE.Text, txtANONCE.Text, txtEAPOL.Text, txtEAPOLSIZE.Text, txtKEYVER.Text, txtKEYMIC.Text, True) End If Else - Call WriteHCCAP(CommonDialog.fileName, txtESSID.Text, txtBSSID.Text, txtSTA.Text, txtSNONCE.Text, txtANONCE.Text, txtEAPOL.Text, txtEAPOLSIZE.Text, txtKEYVER.Text, txtKEYMIC.Text, True) + Call WriteHCCAP(file_to_save, txtESSID.Text, txtBSSID.Text, txtSTA.Text, txtSNONCE.Text, txtANONCE.Text, txtEAPOL.Text, txtEAPOLSIZE.Text, txtKEYVER.Text, txtKEYMIC.Text, True) End If End If End Sub @@ -659,17 +642,15 @@ Private Sub Form_Load() txtKEYMIC.Text = tmp_hccap_records(0).KEY_MIC End If current_index = 0 - lblCounter.Caption = current_index + 1 & "/" & num_hccap_records + lblCounter.caption = current_index + 1 & "/" & num_hccap_records If num_hccap_records > 1 Then btnNext.Enabled = True btnPrev.Enabled = False lblCounter.Visible = True - lblCounter.Enabled = True Else btnNext.Enabled = False btnPrev.Enabled = False lblCounter.Visible = False - lblCounter.Enabled = False End If End If End If diff --git a/Form2.frm b/Form2.frm index 9fca817..0869059 100644 --- a/Form2.frm +++ b/Form2.frm @@ -1,5 +1,4 @@ VERSION 5.00 -Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX" Begin VB.Form Form2 Caption = "Cap Converter" ClientHeight = 8115 @@ -59,13 +58,6 @@ Begin VB.Form Form2 Top = 720 Width = 5655 End - Begin MSComDlg.CommonDialog CommonDialog1 - Left = 6240 - Top = 120 - _ExtentX = 847 - _ExtentY = 847 - _Version = 393216 - End Begin VB.Label lblOutputFile Caption = "Output File:" Height = 195 @@ -148,23 +140,6 @@ Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit -Private Declare Function SetCursor Lib "user32" (ByVal hCursor As Long) As Long -Private Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long -Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long -Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long -Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long - -Private Type BrowseInfo - hWndOwner As Long - pIDLRoot As Long - pszDisplayName As Long - lpszTitle As Long - ulFlags As Long - lpfnCallback As Long - lParam As Long - iImage As Long -End Type - 'Output Options: '[ ] Extract first found handshake only '[ ] Combine all found handshakes into single hccap @@ -178,15 +153,27 @@ End Type Private Sub btnInputFile_Click() If lblFileMode.ForeColor = &H80000012 Then 'Browse for File - CommonDialog1.fileName = "" - CommonDialog1.Filter = "CAP Files (*.cap;*.pcap;*.dmp)|*.cap;*.pcap;*.dmp|HCCAP Files (*.hccap)|*.hccap|All files (*.*)|*.*" - CommonDialog1.FilterIndex = 1 - CommonDialog1.DefaultExt = "cap" - CommonDialog1.DialogTitle = "Choose Input File" - CommonDialog1.InitDir = IIf((last_path <> ""), last_path & "\", App.path) - CommonDialog1.ShowOpen - If (CommonDialog1.CancelError = False) And (CommonDialog1.fileName <> "") Then - txtInputFile.Text = CommonDialog1.fileName + Dim file_to_open As String + Dim OFN As OPENFILENAME + OFN.lStructSize = Len(OFN) + OFN.hwndOwner = Me.hwnd + OFN.hInstance = App.hInstance + OFN.lpstrTitle = "Choose Input File" + OFN.lpstrFilter = "CAP Files (*.cap;*.pcap;*.dmp)" & Chr$(0) & "*.cap;*.pcap;*.dmp" & Chr$(0) & "HCCAP Files (*.hccap)" & Chr$(0) & "*.hccap" & Chr$(0) & "All files (*.*)" & Chr$(0) & "*.*" & Chr$(0) + OFN.lpstrDefExt = "cap" + OFN.nFilterIndex = 1 + OFN.lpstrFile = String(257, 0) + OFN.nMaxFile = Len(OFN.lpstrFile) - 1 + OFN.lpstrFileTitle = OFN.lpstrFile + OFN.nMaxFileTitle = OFN.nMaxFile + OFN.lpstrInitialDir = IIf((last_path <> ""), last_path, App.path) + OFN.flags = 0 + If GetOpenFileName(OFN) Then + last_path = get_path_from_file(Trim$(OFN.lpstrFile)) + file_to_open = IIf(is_file(Trim$(OFN.lpstrFile)), Trim$(OFN.lpstrFile), "") + End If + If (file_to_open <> "") Then + txtInputFile.Text = file_to_open Dim fso As Scripting.FileSystemObject Set fso = New Scripting.FileSystemObject last_path = fso.GetParentFolderName(txtInputFile.Text) @@ -195,7 +182,7 @@ If lblFileMode.ForeColor = &H80000012 Then 'Browse for File End If Else 'Browse for Directory Dim tBrowseInfo As BrowseInfo - tBrowseInfo.hWndOwner = Me.hwnd + tBrowseInfo.hwndOwner = Me.hwnd tBrowseInfo.lpszTitle = lstrcat("Choose Input Directory", "") tBrowseInfo.ulFlags = 1 + 2 + &H4& Dim tmpLong As Long @@ -213,23 +200,35 @@ End Sub Private Sub btnOutputFile_Click() If lblFileMode.ForeColor = &H80000012 Then 'Browse for File - CommonDialog1.fileName = "" - CommonDialog1.Filter = "HCCAP Files (*.hccap)|*.hccap|CAP Files (*.cap;*.pcap;*.dmp)|*.cap;*.pcap;*.dmp|All files (*.*)|*.*" - CommonDialog1.FilterIndex = 1 - CommonDialog1.DefaultExt = "hccap" - CommonDialog1.DialogTitle = "Choose Output File" - CommonDialog1.InitDir = IIf((last_path <> ""), last_path & "\", App.path) - CommonDialog1.ShowSave - If (CommonDialog1.CancelError = False) And (CommonDialog1.fileName <> "") Then - txtOutputFile.Text = CommonDialog1.fileName + Dim file_to_save As String + Dim OFN As OPENFILENAME + OFN.lStructSize = Len(OFN) + OFN.hwndOwner = Me.hwnd + OFN.hInstance = App.hInstance + OFN.lpstrTitle = "Save File As" + OFN.lpstrFilter = "HCCAP Files (*.hccap)" & Chr$(0) & "*.hccap" & Chr$(0) & "CAP Files (*.cap;*.pcap;*.dmp)" & Chr$(0) & "*.cap;*.pcap;*.dmp" & Chr$(0) & "All files (*.*)" & Chr$(0) & "*.*" & Chr$(0) + OFN.lpstrDefExt = "hccap" + OFN.nFilterIndex = 1 + OFN.lpstrFile = String(257, 0) + OFN.nMaxFile = Len(OFN.lpstrFile) - 1 + OFN.lpstrFileTitle = OFN.lpstrFile + OFN.nMaxFileTitle = OFN.nMaxFile + OFN.lpstrInitialDir = IIf((last_path <> ""), last_path, App.path) + OFN.flags = 0 + If GetSaveFileName(OFN) Then + last_path = get_path_from_file(Trim$(OFN.lpstrFile)) + file_to_save = Trim$(OFN.lpstrFile) + End If + If (file_to_save <> "") Then + txtOutputFile.Text = file_to_save Dim fso As Scripting.FileSystemObject Set fso = New Scripting.FileSystemObject - last_path = fso.GetParentFolderName(CommonDialog1.fileName) + last_path = fso.GetParentFolderName(file_to_save) Set fso = Nothing End If Else Dim tBrowseInfo As BrowseInfo - tBrowseInfo.hWndOwner = Me.hwnd + tBrowseInfo.hwndOwner = Me.hwnd tBrowseInfo.lpszTitle = lstrcat("Choose Output Directory", "") tBrowseInfo.ulFlags = 1 + 2 + &H4& Dim tmpLong As Long @@ -247,9 +246,6 @@ End Sub Private Sub Form_Load() RemoveMenu GetSystemMenu(Me.hwnd, 0), 2, &H400& 'prevent resizing - 'txtInputFile.Text = "F:\hccap_info\3.cap" - 'txtOutputFile.Text = "F:\hccap_info\3.hccap" - 'command line args If (Command$ <> "") Then Dim cmdline_file As String @@ -285,8 +281,8 @@ Private Sub lblDirectoryMode_Click() lblDirectoryMode.FontUnderline = False lblFileMode.ForeColor = &HFF0000 'blue lblFileMode.FontUnderline = True - lblInputFile.Caption = "Input Directory:" - lblOutputFile.Caption = "Output Directory:" + lblInputFile.caption = "Input Directory:" + lblOutputFile.caption = "Output Directory:" Dim fso As Scripting.FileSystemObject Set fso = New Scripting.FileSystemObject If (is_file(txtInputFile.Text) = True) Then @@ -305,8 +301,8 @@ Private Sub lblFileMode_Click() lblFileMode.FontUnderline = False lblDirectoryMode.ForeColor = &HFF0000 'blue lblDirectoryMode.FontUnderline = True - lblInputFile.Caption = "Input File:" - lblOutputFile.Caption = "Output File:" + lblInputFile.caption = "Input File:" + lblOutputFile.caption = "Output File:" txtInputFile.Text = "" txtOutputFile.Text = "" End If diff --git a/Module1.bas b/Module1.bas index 437a33a..9021872 100644 --- a/Module1.bas +++ b/Module1.bas @@ -1,13 +1,15 @@ Attribute VB_Name = "Module1" Option Explicit +Public Declare Function InitCommonControlsEx Lib "comctl32.dll" (iccex As tagInitCommonControlsEx) As Boolean Public Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long Public Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long +Public Declare Function SetCursor Lib "user32" (ByVal hCursor As Long) As Long +Public Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long Public Type tagInitCommonControlsEx lngSize As Long lngICC As Long End Type -Public Declare Function InitCommonControlsEx Lib "comctl32.dll" (iccex As tagInitCommonControlsEx) As Boolean Public Type hccap_record ESSID As String @@ -34,8 +36,8 @@ Public Sub Main() InitCommonControlsEx iccex Load Form1 Form1.Show - 'Load MainForm - 'MainForm.Show + 'Load Form2 + 'Form2.Show End Sub Public Function hex_digits_only(input_str As String) As String @@ -73,52 +75,3 @@ Public Function bytes2num(LoByte As Byte, HiByte As Byte) As Long End If 'bytes2num = CLng("&H" & Right$("0" & Hex$(LoByte), 2) & Right$("0" & Hex$(HiByte), 2)) End Function - -Public Function get_path_from_file(fileName As String) As String - Dim pos As Integer - pos = InStrRev(fileName, "\") - If pos > 0 Then - get_path_from_file = Left$(fileName, pos) - Else - get_path_from_file = "" - End If -End Function - -Public Function is_file(str As String) As Boolean - Dim fso As Scripting.FileSystemObject - Set fso = New Scripting.FileSystemObject - Dim return_value As Boolean - return_value = fso.FileExists(str) - Set fso = Nothing - is_file = return_value -End Function - -Public Function is_folder(str As String) As Boolean - Dim fso As Scripting.FileSystemObject - Set fso = New Scripting.FileSystemObject - Dim return_value As Boolean - return_value = fso.FolderExists(str) - Set fso = Nothing - is_folder = return_value -End Function - -'Private Type OFSTRUCT -' cBytes As Byte -' fFixedDisk As Byte -' nErrCode As Integer -' Reserved1 As Integer -' Reserved2 As Integer -' szPathName(128&) As Byte -'End Type -'Public Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long -'Public Function file_exists(ByVal file_name As String) As Boolean -' On Error Resume Next -' Dim open_file_result As Long -' Dim OfSt As OFSTRUCT -' open_file_result = OpenFile(file_name, OfSt, &H4000&) -' If open_file_result <> -1& Then -' file_exists = True -' Else -' file_exists = False -' End If -'End Function diff --git a/Project1.vbp b/Project1.vbp index d63a705..cdaeedc 100644 --- a/Project1.vbp +++ b/Project1.vbp @@ -1,6 +1,5 @@ Type=Exe -Reference=*\G{420B2830-E718-11CF-893D-00A0C9054228}#1.0#0#..\..\..\Windows\SysWOW64\scrrun.dll#Microsoft Scripting Runtime -Object={F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0; COMDLG32.OCX +Reference=*\G{420B2830-E718-11CF-893D-00A0C9054228}#1.0#0#..\..\..\..\WINXP\system32\scrrun.dll#Microsoft Scripting Runtime Form=Form1.frm Module=Module1; Module1.bas Module=Write_CAP; WriteCAP.bas @@ -9,6 +8,7 @@ Module=Read_HCCAP; ReadHCCAP.bas Module=Write_HCCAP; WriteHCCAP.bas Form=Form2.frm Module=RegistryModule; RegistryModule.bas +Module=CommonDialogs; CommonDialogs.bas ResFile32="manifest.res" IconForm="Form1" Startup="Sub Main" @@ -20,8 +20,8 @@ Name="CapConverter" HelpContextID="0" CompatibleMode="0" MajorVer=1 -MinorVer=2 -RevisionVer=1 +MinorVer=3 +RevisionVer=0 AutoIncrementVer=0 ServerSupportFiles=0 CompilationType=0 diff --git a/Project1.vbw b/Project1.vbw index 3a88212..f468977 100644 --- a/Project1.vbw +++ b/Project1.vbw @@ -1,8 +1,9 @@ -Form1 = 196, 61, 1106, 784, , 5, 6, 813, 818, C +Form1 = 196, 61, 1106, 784, Z, 5, 6, 813, 818, C Module1 = 75, 75, 729, 692, Write_CAP = 88, 116, 923, 604, Read_CAP = 132, 174, 967, 662, Read_HCCAP = 22, 29, 857, 517, Write_HCCAP = 132, 174, 967, 662, -Form2 = 22, 29, 857, 517, , 0, 0, 835, 488, C +Form2 = 22, 29, 857, 517, , 0, 0, 856, 812, C RegistryModule = 175, 175, 829, 792, +CommonDialogs = 44, 58, 854, 546, diff --git a/RegistryModule.bas b/RegistryModule.bas index 109e5ce..e7fb326 100644 --- a/RegistryModule.bas +++ b/RegistryModule.bas @@ -159,7 +159,7 @@ Public Sub RegDeleteSubKey(ByVal Group As Long, ByVal section As String) RC = RegCloseKey(hKey) Exit Sub RegDeleteSubKeyError: - Call DisplayError(RC, "RegDeleteSubKey") + Call DisplayRegError(RC, "RegDeleteSubKey") End Sub 'Wrapper for the RegDeleteValue Win32 API @@ -171,7 +171,7 @@ Public Sub DeleteValue(ByVal Group As Long, ByVal section As String, ByVal Key A RC = RegCloseKey(hKey) Exit Sub DeleteValueError: - Call DisplayError(RC, "DeleteValue") + Call DisplayRegError(RC, "DeleteValue") End Sub 'Wrapper for the RegOpenKeyEx and RegCloseKey Win32 API @@ -189,11 +189,11 @@ Public Function RegKeyExists(ByVal RootKey As Long, ByVal SubKey As String) As B RegKeyExists = False Exit Function Else - Call DisplayError(RC, "RegOpenKeyEx") + Call DisplayRegError(RC, "RegOpenKeyEx") End If Exit Function RegKeyExistsError: - Call DisplayError(RC, "RegKeyExists") + Call DisplayRegError(RC, "RegKeyExists") End Function 'Wrapper for the RegOpenKeyEx, RegQueryValueEx, and RegCloseKey Win32 API @@ -220,18 +220,18 @@ Public Function RegValueExists(ByVal RootKey As Long, ByVal SubKey As String, By RegValueExists = False Exit Function Else - Call DisplayError(RC, "RegQueryValueEx") + Call DisplayRegError(RC, "RegQueryValueEx") Call RegCloseKey(hKey) Exit Function End If Call RegCloseKey(hKey) Else - Call DisplayError(RC, "RegOpenKeyEx") + Call DisplayRegError(RC, "RegOpenKeyEx") Call RegCloseKey(hKey) End If Exit Function RegValueExistsError: - Call DisplayError(RC, "RegValueExists") + Call DisplayRegError(RC, "RegValueExists") RegValueExists = False End Function @@ -247,7 +247,7 @@ Public Sub WriteRegistry(ByVal Group As Long, ByVal section As String, ByVal Key If RC <> 0 Then GoTo WriteRegistryError Exit Sub WriteRegistryError: - Call DisplayError(RC, "WriteRegistry") + Call DisplayRegError(RC, "WriteRegistry") End Sub 'Wrapper for the RegOpenKey, RegQueryValueEx, and RegCloseKey Win32 API @@ -286,7 +286,7 @@ Public Function ReadRegistry(ByVal Group As Long, ByVal section As String, ByVal ReadRegistry = sValue End Function -Public Sub DisplayError(ByVal errNum As Integer, ByVal func As String) +Public Sub DisplayRegError(ByVal errNum As Integer, ByVal func As String) Select Case errNum Case 0 MsgBox "Error Accessing the Registry." & vbNewLine & vbNewLine & "Error Number: " & errNum & vbNewLine & "Error Description: ERROR_NONE" & vbNewLine & "Calling Function: " & func, vbExclamation + vbOKOnly