VERSION 5.00
Begin VB.Form Form20 
   Caption         =   " Direct Logical Disk Search"
   ClientHeight    =   4020
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   3420
   Icon            =   "logicaldisksearch.frx":0000
   LinkTopic       =   "Form20"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4020
   ScaleWidth      =   3420
   StartUpPosition =   3  'Windows Default
   Begin VB.DriveListBox Drive1 
      Height          =   315
      Left            =   1440
      TabIndex        =   12
      Top             =   960
      Width           =   1815
   End
   Begin VB.TextBox Text3 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   162
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   360
      Left            =   1800
      MaxLength       =   10
      TabIndex        =   2
      Top             =   1920
      Width           =   1215
   End
   Begin VB.CheckBox Check1 
      Caption         =   "Case"
      Height          =   255
      Left            =   240
      TabIndex        =   3
      Top             =   2400
      Value           =   1  'Checked
      Width           =   735
   End
   Begin VB.Frame Frame1 
      Caption         =   "Search Data"
      Height          =   675
      Left            =   120
      TabIndex        =   10
      Top             =   120
      Width           =   3135
      Begin VB.TextBox Text2 
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   162
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   120
         TabIndex        =   0
         Top             =   220
         Width           =   2895
      End
   End
   Begin VB.OptionButton Option2 
      Caption         =   "Binary Search"
      Height          =   255
      Left            =   1800
      TabIndex        =   5
      Top             =   2760
      Width           =   1335
   End
   Begin VB.OptionButton Option1 
      Caption         =   "String Search"
      Height          =   255
      Left            =   240
      TabIndex        =   4
      Top             =   2760
      Value           =   -1  'True
      Width           =   1335
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Cancel"
      Height          =   375
      Left            =   120
      TabIndex        =   6
      Top             =   3240
      Width           =   1335
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Seek"
      Height          =   375
      Left            =   1800
      TabIndex        =   7
      Top             =   3240
      Width           =   1455
   End
   Begin VB.TextBox Text1 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   162
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   360
      Left            =   1800
      MaxLength       =   10
      TabIndex        =   1
      Text            =   "0"
      Top             =   1440
      Width           =   1215
   End
   Begin VB.Label Label3 
      Caption         =   "Ending Sector :"
      Height          =   255
      Left            =   240
      TabIndex        =   11
      Top             =   1980
      Width           =   1335
   End
   Begin VB.Label Label1 
      Caption         =   "Logical Drive :"
      Height          =   255
      Left            =   240
      TabIndex        =   8
      Top             =   1005
      Width           =   1095
   End
   Begin VB.Label Label2 
      Caption         =   "Beginning Sector :"
      Height          =   255
      Left            =   240
      TabIndex        =   9
      Top             =   1500
      Width           =   1335
   End
End
Attribute VB_Name = "Form20"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Rem 11-12-2008
Public T5 As String
Public T4 As String
Public T6 As String
Public iCh2 As Integer
Public iO2 As Boolean
Dim DriveName As String
Dim STXT As String
Dim Y As Long
Dim E As Long

Private Sub Command1_Click()
If Val(Text3.Text) - Val(Text1.Text) > 65536 Then
   If MsgBox("Searching duration may be take many minutes!... Do you want to continue to direct disk search?", 36, " ! WARNING ! LONG DISTANCE DISK SEARCHING !") <> 6 Then Exit Sub
End If
On Error GoTo ErrMsg
Close TmpFileNo
Kill "BINFILEHEX.TMP"
OpenFileName = ""
Form1.Caption = "BINARY FILE EDITOR by Erdogan Tan"
SF = -1
CX = 512
TmpFileNo = FreeFile
Open "BINFILEHEX.TMP" For Binary As TmpFileNo Len = 1
FL = 0
FP = 0
FF = 1
SFP = 0
SL = 0
Dim X As Integer
Dim Z As Long
Dim sc As Long
Dim cs As Long
Call SearchData
If SL > 0 And SFP > 0 Then
   For X = 0 To 511
       FL = FL + 1
       Put TmpFileNo, FL, abResult(X)
   Next X
   Sector = bs
   DF = True
   Search = True
   LogicalDisk = True
   DRV = DriveName
   Call Form1.ShowFileBinHex
End If
Cikis:
Unload Me
Exit Sub
ErrMsg:
Beep
MsgBox ("Drive could not read!..." + Chr$(13) + Chr$(13) + "Error Number: " + Str$(Err)), 48, "! ERROR !"
C1LI = 0
Resume Cikis
End Sub

Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Check1.Value = 0
Option1.Value = True
Unload Me
End Sub

Private Sub Drive1_LostFocus()
DriveName = UCase(Left(Drive1.Drive, 1)) + Right(Drive1.Drive, Len(Drive1.Drive) - 1)
End Sub

Private Sub Form_Load()
DriveName = Drive1.List(0)
Rem On Error Resume Next
Rem Drive1.Drive = DRV
Rem 11-12-2008
Text2.Text = T5
DriveName = Drive1.Drive
If T4 = "" Then
   Text1.Text = "0"
Else
   Text1.Text = T4
End If
If T6 = "" Then
   Text3.Text = CStr(&H7FFFFFFF)
Else
   Text3.Text = T6
End If
If iCh2 = 0 Then
   Check1.Value = 1
Else
   Check1.Value = 0
End If
If iO2 = False Then
   Option1.Value = True
   Rem Option2.Value = False
Else
   Option1.Value = False
   Option2.Value = True
End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
T5 = Text2.Text
T4 = Text1.Text
T6 = Text3.Text
If Check1.Value = 0 Then
   iCh2 = 1
Else
   iCh2 = 0
End If
If Option1.Value = True Then
   iO2 = False
Else
   iO2 = True
End If
End Sub

Private Sub Option1_Click()
Frame1.Caption = "Enter String to Search :"
End Sub

Private Sub Option2_Click()
Frame1.Caption = "Enter Hex Data to Search :"
End Sub

Private Sub Text1_GotFocus()
Text1.SelLength = Text1.MaxLength
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
  Text3.SetFocus
End If
End Sub

Private Sub Text2_GotFocus()
Text2.SelLength = Text2.MaxLength
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
  Text1.SetFocus
End If
End Sub

Private Sub SearchData()
STXT = Trim$(Text2.Text)
If STXT = "" Then Exit Sub
Dim X As Integer
Dim Y0 As Integer
Dim Y1 As Integer
Dim Y2 As Integer
Dim H As String * 1
Y = Val(Text1.Text)
E = Val(Text3.Text)
If Y < 0 Then
   Y = 0
   Text1.Text = "0"
End If
If Option2.Value = True Then
   Dim HexStr As String
   STXT = UCase(STXT)
   For X = 1 To Len(STXT) Step 2
       H = Mid$(STXT, X, 1)
       Y1 = Asc(H)
       If Val(H) = 0 And H <> "0" Then
          If Y1 < Asc("A") Or Y1 > Asc("F") Then
             Y1 = 0
          Else
             Y1 = 10 + Y1 - Asc("A")
          End If
       Else
          Y1 = Y1 - Asc("0")
       End If
       H = Mid$(STXT, X + 1, 1)
       Y2 = Asc(H)
       If Val(H) = 0 And H <> "0" Then
          If Y2 < Asc("A") Or Y2 > Asc("F") Then
             Y2 = 0
          Else
             Y2 = 10 + Y2 - Asc("A")
          End If
       Else
          Y2 = Y2 - Asc("0")
       End If
       Y0 = (Y1 * 16) + Y2
       HexStr = HexStr + Chr$(Y0)
   Next X
   If HexStr <> "" Then
      SFP = SearchOnDisk(HexStr, Y)
      If SFP > 0 Then
         Me.Caption = "Sector " + CStr(Sector) + " ..."
         SL = Len(HexStr)
      Else
         Me.Caption = "Direct Physical Disk Search"
         SL = 0
      End If
   End If
Else
   If Check1.Value = 0 Then
      STXT = UCase(Trim$(Text2.Text))
   Else
      STXT = Trim$(Text2.Text)
   End If
   If STXT <> "" Then
      SFP = SearchOnDisk(STXT, Y)
      If SFP > 0 Then
         Me.Caption = "Sector " + CStr(Sector) + " ..."
         SL = Len(STXT)
      Else
         Me.Caption = "Direct Physical Disk Search"
         SL = 0
      End If
   End If
End If
End Sub

Private Function SearchOnDisk(SText As String, STRT As Long) As Long
Dim StrL As Integer
Dim X As Integer
Dim N As Integer
Dim LS As String * 1
Dim RS As String * 1
Dim Bulundu As Boolean
Dim S As Long
S = STRT
TKR2:
Y = DirectReadDriveNT(DriveName, S, 0, abResult(), 512)
If Y > 0 Then
   Me.Caption = "Searching sector " + CStr(S) + " ..."
   X = 1
   StrL = Len(SText)
   For N = 0 To 511
       RS = Chr$(abResult(N))
       If Option1.Value = True And Check1.Value = 0 Then
          LS = UCase(RS)
       Else
          LS = RS
       End If
       If Mid$(SText, X, 1) = LS Then
          If X = StrL Then
             SearchOnDisk = N + 1 - StrL + 1
             Bulundu = True
             bs = S
             Exit For
          Else
             X = X + 1
          End If
       Else
          X = 1
       End If
   Next N
   If Bulundu = False Then
      S = S + 1
      If S <= E Then GoTo TKR2
   End If
End If
End Function

Private Sub Text3_GotFocus()
Text3.SelLength = Text1.MaxLength
End Sub

Private Sub Text3_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
  Text2.SetFocus
End If
End Sub

Private Sub Text3_LostFocus()
If Val(Text3.Text) > &H7FFFFFFF Then
   Text3.Text = CStr(&H7FFFFFFF)
Else
   Text3.Text = CStr(Val(Text3.Text))
   If Val(Text3.Text) < Val(Text1.Text) + 1 Then
      Text3.Text = Val(Text1.Text) + 1
   End If
End If
End Sub
