Anda di halaman 1dari 6

'PROJECT: Singlix Code Grabber (Binary File Edit, Disk Edit 2.0) 'EXE FILE:BINFILEHEX.EXE (binfilehex.vbp) Version 2.

0 BETA 'Full VB 5.0/6.0 source code of this project: http://www.singlix.net/download/bf e_src.zip '************************ 'VB Project FILE: physicaldiskread.frm '************ VB 5.0/6.0 Source Code ********************** Option Explicit '=============NT staff============= 'Read/Write drive with any file system Rem Rem Rem Rem Rem Rem Rem Rem Rem Rem Rem Rem Rem Rem 8-11-2008 'ByRef lpBuffer' and 'cBytes' long return modification by Erdogan Tan *** "DirectReadDriveNT" function was originally written by Arkadiy Olovyannikov with a variant return ... for reading logical (dos/windows) drive/disk sectors... *** Physical disk read/write features/procedures is written by Erdogan Tan by using information on Microsoft Developers Network (MSDN) web site http://msdn.microsoft.com/tr-tr/library/aa363858(en-us,VS.85).aspx Adapted to Visual Basic (5.0) code by Erdogan Tan on 27-10-2008 ... and successfully realized on Windows XP SP3 (8-11-2008) This code is successfully running on Windows XP Home & Professional.

Private Function DirectReadDriveNT(ByVal sDrive As String, ByVal iStartSec As Lo ng, ByVal iOffset As Long, ByRef lpBuffer() As Byte, ByVal cBytes As Long) As Lo ng Dim hDevice As Long Dim abBuff() As Byte Dim nSectors As Integer nSectors = Int((iOffset + cBytes - 1) / BytesPerSector) + 1 Rem hDevice = CreateFile("\\.\" & UCase(Left(sDrive, 1)) & ":", GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, 0&, OPEN_EXISTING, 0&, 0 &) Rem 4-11-2008 Physical disk read/write modification hDevice = CreateFile("\\.\" & sDrive, GENERIC_READ Or GENERIC_WRITE, FILE_SH ARE_READ Or FILE_SHARE_WRITE, 0&, OPEN_EXISTING, 0&, 0&) If hDevice = INVALID_HANDLE_VALUE Then Exit Function Call SetFilePointer(hDevice, iStartSec * BytesPerSector, 0, FILE_BEGIN) ReDim lpBuffer(cBytes - 1) ReDim abBuff(nSectors * BytesPerSector - 1) Call ReadFile(hDevice, abBuff(0), UBound(abBuff) + 1, cBytes, 0&) CloseHandle hDevice CopyMemory lpBuffer(0), abBuff(iOffset), cBytes DirectReadDriveNT = cBytes End Function Private Function DirectWriteDriveNT(ByVal sDrive As String, ByVal iStartSec As L ong, ByVal iOffset As Long, ByVal sWrite As String) As Boolean Dim hDevice As Long Dim abBuff() As Byte Dim ab() As Byte Dim nRead As Long Dim nSectors As Long nSectors = Int((iOffset + Len(sWrite) - 1) / BytesPerSector) + 1 Rem hDevice = CreateFile("\\.\" & UCase(Left(sDrive, 1)) & ":", GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, 0&, OPEN_EXISTING, 0&, 0

&) Rem 4-11-2008 Physical disk read/write modification hDevice = CreateFile("\\.\" & sDrive, GENERIC_READ Or GENERIC_WRITE, FILE_SH ARE_READ Or FILE_SHARE_WRITE, 0&, OPEN_EXISTING, 0&, 0&) If hDevice = INVALID_HANDLE_VALUE Then Exit Function abBuff = DirectReadDriveNT(sDrive, iStartSec, 0, nSectors * BytesPerSector) ab = StrConv(sWrite, vbFromUnicode) CopyMemory abBuff(iOffset), ab(0), Len(sWrite) Call SetFilePointer(hDevice, iStartSec * BytesPerSector, 0, FILE_BEGIN) Call LockFile(hDevice, LoWord(iStartSec * BytesPerSector), HiWord(iStartSec * BytesPerSector), LoWord(nSectors * BytesPerSector), HiWord(nSectors * BytesPer Sector)) DirectWriteDriveNT = WriteFile(hDevice, abBuff(0), UBound(abBuff) + 1, nRead , 0&) Call FlushFileBuffers(hDevice) Call UnlockFile(hDevice, LoWord(iStartSec * BytesPerSector), HiWord(iStartSe c * BytesPerSector), LoWord(nSectors * BytesPerSector), HiWord(nSectors * BytesP erSector)) CloseHandle hDevice End Function Private Sub Command1_Click() On Error GoTo ErrMsg Close TmpFileNo Kill "BINFILEHEX.TMP" 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 bs As Long Dim sc As Long Dim cs As Long bs = Val(Text1.Text) If bs < 0 Then bs = 0 Text1.Text = 0 End If sc = Val(Text2.Text) If sc < 1 Then sc = 1 Text2.Text = 1 End If Y = bs Z = DirectReadDriveNT(DRV, Y, 0, abResult(), 512) If Z > 0 Then MsgBox (Z) 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(DRV, Y, 0, abResult(), 512) If Z > 0 Then cs = (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 DF = True If Option1.Value = True Then DRV = "Physical Disk 0" Else If Option2.Value = True Then DRV = "Physical Disk 1" Else If Option3.Value = True Then DRV = "Physical Disk 2" Else DRV = "Physical Disk 3" End If End If End If Call Form1.ShowFileBinHex Else MsgBox ("Invalid handle value !" + Chr$(13) + Chr$(10) + "(Disk not ready or read error.)"), 48, " Physical Disk " + Right$(DRV, 1) + " Read Error !" End If cikis: Unload Me Exit Sub ErrMsg: Beep MsgBox ("Drive could not read!..." + Chr$(13) + Chr$(13) + "Error Number: " + St r$(Err)), 48, "! ERROR !" Resume cikis End Sub Private Sub Form_Load() Rem 4-11-2008 DRV = "PhysicalDrive0" End Sub Private Sub Option1_Click() Rem 4-11-2008 DRV = "PhysicalDrive0" End Sub Private Sub Option2_Click() Rem 4-11-2008 DRV = "PhysicalDrive1" End Sub Private Sub Option3_Click() Rem 4-11-2008 DRV = "PhysicalDrive2"

End Sub Private Sub Option4_Click() Rem 4-11-2008 DRV = "PhysicalDrive3" End Sub '********************************************************** 'VB Project FILE: diskio.bas (diskio module) '************ VB 5.0/6.0 Source Code ********************** '***************************************************************** ' Module for performing Direct Read/Write access to disk sectors ' ' Written by Arkadiy Olovyannikov (ark@fesma.ru) '***************************************************************** Public abResult() As Byte '*************Win9x direct Read/Write Staff********** Public Enum FAT_WRITE_AREA_CODE FAT_AREA = &H2001 ROOT_DIR_AREA = &H4001 DATA_AREA = &H6001 End Enum Public Type DISK_IO dwStartSector As Long wSectors As Integer dwBuffer As Long End Type Public Type DIOC_REGISTER reg_EBX As Long reg_EDX As Long reg_ECX As Long reg_EAX As Long reg_EDI As Long reg_ESI As Long reg_Flags As Long End Type Public Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 End Type Public Public Public Public Public Public Public Public Const Const Const Const Const Const Const Const VWIN32_DIOC_DOS_IOCTL = 1& 'Int13 - 440X functions VWIN32_DIOC_DOS_INT25 = 2& 'Int25 - Direct Read Command VWIN32_DIOC_DOS_INT26 = 3& 'Int26 - Direct Write Command VWIN32_DIOC_DOS_DRIVEINFO = 6& 'Extended Int 21h function 7305h FILE_DEVICE_FILE_SYSTEM = &H9& FILE_ANY_ACCESS = 0 FILE_READ_ACCESS = &H1 FILE_WRITE_ACCESS = &H2

Public Public Public Public Public Public

Const Const Const Const Const Const

GENERIC_READ = &H80000000 GENERIC_WRITE = &H40000000 FILE_SHARE_READ = &H1 FILE_SHARE_WRITE = &H2 OPEN_EXISTING = 3 INVALID_HANDLE_VALUE = -1&

Public Const FILE_BEGIN = 0 Public Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (LpVer sionInformation As OSVERSIONINFO) As Long Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpF ileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByV al lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFl agsAndAttributes As Long, ByVal hTemplateFile As Long) As Long Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Lo ng Public Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Long, B yVal dwIoControlCode As Long, ByRef lpInBuffer As Any, ByVal nInBufferSize As Lo ng, ByRef lpOutBuffer As Any, ByVal nOutBufferSize As Long, ByRef lpBytesReturne d As Long, ByVal lpOverlapped As Long) As Long Public Declare Function SetFilePointer Lib "kernel32" (ByVal hFile As Long, ByVa l lDistanceToMove As Long, lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As L ong) As Long Public Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer A s Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lp Overlapped As Long) As Long Public Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByV al lpOverlapped As Long) As Long Public Declare Function FlushFileBuffers Lib "kernel32" (ByVal hFile As Long) As Long Public Declare Function LockFile Lib "kernel32" (ByVal hFile As Long, ByVal dwFi leOffsetLow As Long, ByVal dwFileOffsetHigh As Long, ByVal nNumberOfBytesToLockL ow As Long, ByVal nNumberOfBytesToLockHigh As Long) As Long Public Declare Function UnlockFile Lib "kernel32" (ByVal hFile As Long, ByVal dw FileOffsetLow As Long, ByVal dwFileOffsetHigh As Long, ByVal nNumberOfBytesToUnl ockLow As Long, ByVal nNumberOfBytesToUnlockHigh As Long) As Long Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) 'Additions by Erdogan Tan Public Const BytesPerSector = 512 Public BSBuffer(511) As Byte Public CX As Integer Public DRV As String Public DF As Boolean Public Function IsWindowsNT() As Boolean Dim verinfo As OSVERSIONINFO verinfo.dwOSVersionInfoSize = Len(verinfo) If (GetVersionEx(verinfo)) = 0 Then Exit Function If verinfo.dwPlatformId = 2 Then IsWindowsNT = True End Function Public Function MAKEWORD(ByVal bLo As Byte, ByVal bHi As Byte) As Integer If bHi And &H80 Then

MAKEWORD = (((bHi And &H7F) * 256) + bLo) Or &H8000 Else MAKEWORD = (bHi * 256) + bLo End If End Function Rem Erdogan Tan 28-3-2008 Public Function LoWord(ByVal dNum As Double) As Long LoWord = CLng(dNum Mod 65536) End Function Rem Erdogan Tan 28-3-2008 Public Function HiWord(ByVal dNum As Double) As Long HiWord = CLng(dNum - (dNum Mod 65536)) End Function

Anda mungkin juga menyukai