VERSION 5.00
Begin VB.Form Form4 
   Caption         =   " Logical Disk Read"
   ClientHeight    =   2490
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   3480
   Icon            =   "logicaldiskread.frx":0000
   LinkTopic       =   "Form4"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2490
   ScaleWidth      =   3480
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Command2 
      Caption         =   "Cancel"
      Height          =   375
      Left            =   240
      TabIndex        =   6
      Top             =   1800
      Width           =   1335
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Read"
      Height          =   375
      Left            =   1800
      TabIndex        =   7
      Top             =   1800
      Width           =   1400
   End
   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          =   360
      Left            =   1800
      MaxLength       =   7
      TabIndex        =   5
      Text            =   "1"
      Top             =   1200
      Width           =   855
   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        =   3
      Text            =   "0"
      Top             =   720
      Width           =   1095
   End
   Begin VB.DriveListBox Drive1 
      Height          =   315
      Left            =   1440
      TabIndex        =   1
      Top             =   240
      Width           =   1815
   End
   Begin VB.Label Label1 
      Caption         =   "Logical Drive :"
      Height          =   255
      Left            =   240
      TabIndex        =   0
      Top             =   285
      Width           =   1095
   End
   Begin VB.Label Label3 
      Caption         =   "Number of Sectors :"
      Height          =   255
      Left            =   240
      TabIndex        =   4
      Top             =   1260
      Width           =   1455
   End
   Begin VB.Label Label2 
      Caption         =   "Beginning Sector :"
      Height          =   255
      Left            =   240
      TabIndex        =   2
      Top             =   780
      Width           =   1335
   End
End
Attribute VB_Name = "Form4"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim BytesPerSector As Double
Dim dgBuffer(23) As Byte
Dim DriveName As String

Private Sub Command1_Click()
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 Y As Long
Dim Z As Long
Dim sc As Long
Dim cs As Long
If GetDriveGeometry(DriveName, dgBuffer()) = True Then
   BytesPerSector = Form11.GetDoubleNumberFrom4Bytes(dgBuffer(20), dgBuffer(21), dgBuffer(22), dgBuffer(23))
Else
   BytesPerSector = 512
End If
bs = Val(Text1.Text)
If bs < 0 Then
   bs = 0
   Text1.Text = 0
End If
If BytesPerSector > 512 Then
   Y = CLng(BytesPerSector / 512)
Else
   Y = 1
End If
sc = Val(Text2.Text)
If sc < Y Then
   sc = Y
   Text2.Text = CStr(sc)
End If
If BytesPerSector <> 512 Then
   If bs > 0 Then
      MsgBox ("Bytes per sector is " + CStr(BytesPerSector)) + " for this drive." + Chr$(13) + Chr$(10) + "This program uses 512 bytes per sector format for showing data." + Chr$(13) + Chr$(10) + "So, the sector value is shown as " + CStr(bs) + " but it is originally sector " + CStr((bs * 512) \ BytesPerSector) + ".", 0, " " + DriveName + " has " + CStr(BytesPerSector) + " bytes per sector."
   Else
      MsgBox ("Bytes per sector is " + CStr(BytesPerSector)) + " for this drive." + Chr$(13) + Chr$(10) + "This program uses 512 bytes per sector format for showing data.", 0, " " + DriveName + " has " + CStr(BytesPerSector) + " bytes per sector."
   End If
End If
Y = bs
Z = DirectReadDriveNT(DriveName, Y, 0, abResult(), 512)
If Z > 0 Then
   For X = 0 To 511
       FL = FL + 1
       Put TmpFileNo, FL, abResult(X)
   Next X
   If sc > 1 Then
      For Y = bs + 1 To bs + sc - 1
          Z = DirectReadDriveNT(DriveName, Y, 0, abResult(), 512)
          If Z > 0 Then
             cs = CLng((Y - bs) * 512)
             For X = 0 To 511
                 FL = cs + X + 1
                 Put TmpFileNo, FL, abResult(X)
             Next X
          Else
             Exit For
          End If
      Next Y
   End If
   Sector = bs
   LogicalDisk = True
   DF = True
   DRV = DriveName
   Call Form1.ShowFileBinHex
Else
   Sector = 0
   MsgBox ("Invalid handle value !" + Chr$(13) + Chr$(10) + "(Disk not ready or read error.)"), 48, " Physical Disk " + Right(DriveName, 1) + " Read Error !"
   DF = False
End If
Cikis:
Unload Me
Exit Sub
ErrMsg:
Beep
MsgBox ("Drive could not read!..." + Chr$(13) + Chr$(13) + "Error Number: " + Str$(Err)), 48, "! ERROR !"
Resume Cikis
End Sub

Private Sub Command2_Click()
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
End Sub

Private Sub Text1_GotFocus()
Text1.SelLength = Text1.MaxLength
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
   Text2.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
