HanDs
NO.2

[Visual Studio文章] 在VB中实现任意文件的16进制方式察看 





学习中请遵循国家相关法律法规,黑客不作恶。没有网络安全就没有国家安全

本站需要登陆后才能查看

     这是我利用文件操作方法编写的文件16进制察看软件。本来是可以利用UltraEdit来干这件事的。我编写的目的就是想看一下自己能不能编出来。于是我就用VB编了一下,先前我只是把源代码直接放到网上,没想到大家很支持我,给了我很大的鼓舞,在这里我十分感谢eastunfail的帮助,使我的代码更加完善。

源代码如下:

Dim col As ColumnHeader
Dim litem As ListItem
Dim sb As ListSubItem
Dim filename As String
Dim index As Long

Private Sub Command1_Click()
Dim b As Byte
'Dim ff() As Byte
Dim fl As Long
Dim sect As Long
Dim ss As Long

ListView1.ListItems.Clear

dlg.ShowOpen
filename = dlg.filename
fl = FileLen(filename)
sect = fl / 16
ss = fl Mod 16


Open filename For Binary As #1
  If sect = 0 Then
    Set litem = ListView1.ListItems.Add()
    For index = 1 To ss
    Get #1, index, b
    Set sb = litem.ListSubItems.Add(index, , DecToHex(b))
    Next index
  End If
 
  If sect <> 0 Then
  For i = 1 To sect
  Set litem = ListView1.ListItems.Add()
    For index = 1 To 16
      Get #1, 16 * (i - 1) + index, b
      Set sb = litem.ListSubItems.Add(index, , DecToHex(b))
    Next index
  Next i
  Set litem = ListView1.ListItems.Add()
  For index = 1 To ss
   Get #1, index, b
   Set sb = litem.ListSubItems.Add(index, , DecToHex(b))
  Next index
  End If
Close #1

End Sub


Private Sub Command2_Click()
MsgBox "Welcome To Three Leaf WorkRoom!!", , "About"
End Sub


Private Sub Form_Load()
Dim i As Integer

ListView1.ColumnHeaders.Add , , "Address", ListView1.Width / 14

For i = 1 To 16
Set col = ListView1.ColumnHeaders.Add()
   col.Text = "+" & DecToHex(i - 1)
   col.Width = ListView1.Width / 25
Next

ListView1.ColumnHeaders.Add , , "ASCII", ListView1.Width / 4

End Sub

Private Function DecToHex(dd As Byte) As String
DecToHex=IIf(Dec>&HF,Hex(dd),"0" & Hex(dd))    '这行代码是eastunfail提供的。
End Function


学习中请遵守法律法规,本网站内容均来自于互联网,本网站不负担法律责任
V B 实现 任意 文件 1 6 进制 方式 察看
#1楼
发帖时间:2016-7-9   |   查看数:0   |   回复数:0
游客组