VERSION 5.00
Begin VB.Form Form19 
   Caption         =   " Direct Physical Disk Search"
   ClientHeight    =   4020
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   3420
   Icon            =   "physicaldisksearch.frx":0000
   LinkTopic       =   "Form19"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4020
   ScaleWidth      =   3420
   StartUpPosition =   3  'Windows Default
   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        =   3
      Top             =   1920
      Width           =   1215
   End
   Begin VB.CheckBox Check1 
      Caption         =   "Case"
      Height          =   255
      Left            =   240
      TabIndex        =   4
      Top             =   2400
      Value           =   1  'Checked
      Width           =   735
   End
   Begin VB.Frame Frame1 
      Caption         =   "Search Data"
      Height          =   675
      Left            =   120
      TabIndex        =   11
      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        =   6
      Top             =   2760
      Width           =   1335
   End
   Begin VB.OptionButton Option1 
      Caption         =   "String Search"
      Height          =   255
      Left            =   240
      TabIndex        =   5
      Top             =   2760
      Value           =   -1  'True
      Width           =   1335
   End
   Begin VB.ComboBox Combo1 
      Height          =   315
      Left            =   1560
      TabIndex        =   1
      Text            =   "PhysicalDrive0"
      Top             =   960
      Width           =   1695
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Cancel"
      Height          =   375
      Left            =   120
      TabIndex        =   7
      Top             =   3240
      Width           =   1335
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Seek"
      Height          =   375
      Left            =   1800
      TabIndex        =   8
      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        =   2
      Text            =   "0"
      Top             =   1440
      Width           =   1215
   End
   Begin VB.Label Label3 
      Caption         =   "Ending Sector :"
      Height          =   255
      Left            =   240
      TabIndex        =   12
      Top             =   1980
      Width           =   1335
   End
   Begin VB.Label Label1 
      Caption         =   "Physical  Drive :"
      Height          =   255
      Left            =   240
      TabIndex        =   9
      Top             =   1005
      Width           =   1215
   End
   Begin VB.Label Label2 
      Caption         =   "Beginning Sector :"
      Height          =   255
      Left            =   240
      TabIndex        =   10
      Top             =   1500
      Width           =   1335
   End
End
Attribute VB_Name = "Form19"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Rem 10-12-2008
Public T2 As String
Public Cm1 As String
Public T1 As String
Public T3 As String
Public iCh1 As Integer
Public iO1 As Boolean
Dim DriveName As String
Dim STXT As String
Dim Y As Long
Dim E As Long

Private Sub Combo1_Change()
Combo1.ListIndex = C1LI
End Sub

Private Sub Combo1_Click()
C1LI = Combo1.ListIndex
End Sub

Private Sub Combo1_LostFocus()
DriveName = Combo1.Text
End Sub

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
   If Combo1.ListIndex = 0 Then
      DRV = "Physical Disk 0"
   Else
      If Combo1.ListIndex = 1 Then
         DRV = "Physical Disk 1"
      Else
         If Combo1.ListIndex = 2 Then
            DRV = "Physical Disk 2"
         Else
            DRV = "Physical Disk 3"
         End If
      End If
   End If
   LogicalDisk = False
   Search = True
   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 = ""
Combo1.Text = ""
Check1.Value = 0
Option1.Value = True
Unload Me
End Sub

Private Sub Form_Load()
Rem 4-11-2008
Combo1.AddItem "PhysicalDrive0"
Combo1.AddItem "PhysicalDrive1"
Combo1.AddItem "PhysicalDrive2"
Combo1.AddItem "PhysicalDrive3"
Rem 10-12-2008
Text2.Text = T2
Combo1.Text = Cm1
DriveName = Cm1
If T1 = "" Then
   Text1.Text = "0"
Else
   Text1.Text = T1
End If
If T3 = "" Then
   Text3.Text = CStr(&H7FFFFFFF)
Else
   Text3.Text = T3
End If
If iCh1 = 0 Then
   Check1.Value = 1
Else
   Check1.Value = 0
End If
If iO1 = 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)
T2 = Text2.Text
T1 = Text1.Text
T3 = Text3.Text
Cm1 = Combo1.Text
If Check1.Value = 0 Then
   iCh1 = 1
Else
   iCh1 = 0
End If
If Option1.Value = True Then
   iO1 = False
Else
   iO1 = 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
TKR1:
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 TKR1
   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
