1,488
社区成员




Dim AsmCode(18) As Long
AsmCode(0) = &H83EC8B55: AsmCode(1) = &H75FF08EC
AsmCode(2) = &H3475FF38: AsmCode(3) = &HFF3075FF
AsmCode(4) = &H75FF2C75: AsmCode(5) = &H2475FF28
AsmCode(6) = &HFF2075FF: AsmCode(7) = &H75FF1C75
AsmCode(8) = &H1475FF18: AsmCode(9) = &HFF1075FF
AsmCode(10) = &H75FF0C75: AsmCode(11) = &HFC75FF08
AsmCode(12) = &H50F8458D: AsmCode(13) = &H100068
AsmCode(14) = &H2000B800: AsmCode(15) = &HC08B0000
AsmCode(16) = &H458BD0FF: AsmCode(17) = &H34C2C9F8
'//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Private Declare Function CopyFileEx Lib "kernel32" Alias "CopyFileExA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal lpProgressRoutine As Long, lpData As Any, pbCancel As Long, ByVal dwCopyFlags As Long) As Long
Private Declare Function MoveFileWithProgress Lib "kernel32" Alias "MoveFileWithProgressA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal lpProgressRoutine As Long, lpData As Any, ByVal dwFlags As Long) As Long
Private Const ERROR_SUCCESS As Long = 0
Private Const ERROR_ALREADY_EXISTS As Long = 183&
Private Const CALLBACK_CHUNK_FINISHED As Long = &H0
Private Const CALLBACK_STREAM_SWITCH As Long = &H1
Private Const COPY_FILE_FAIL_IF_EXISTS As Long = &H1
Private Const COPY_FILE_RESTARTABLE As Long = &H2
Private Const COPY_FILE_OPEN_SOURCE_FOR_WRITE As Long = &H4
Private Const MOVEFILE_REPLACE_EXISTING As Long = &H1
Private Const MOVEFILE_COPY_ALLOWED As Long = &H2
Private Const MOVEFILE_DELAY_UNTIL_REBOOT As Long = &H4
Private Const MOVEFILE_WRITE_THROUGH As Long = &H8
Private Const PROGRESS_CONTINUE As Long = 0 '让拷贝过程继续;
Private Const PROGRESS_CANCEL As Long = 1 '终止拷贝过程并删除目标文件
Private Const PROGRESS_STOP As Long = 2 '停止拷贝,但以后可以继续开始;
Private Const PROGRESS_QUIET As Long = 3 '继续拷贝过程,但从此不再进行回调。
Public Enum ProcessStatus
mContinue = 1 '继续操作
mPause = 0 '暂停操作
mCancel = -1 '终止操作
End Enum
Private pStatus As ProcessStatus
Public Event OnProgress(ByVal TotalFileSize As Currency, ByVal TotalBytesTransferred As Currency, ByVal StreamSize As Currency, ByVal StreamBytesTransferred As Currency, ByVal dwStreamNumber As Long, ByVal dwCallbackReason As Long, ByVal hSourceFile As Long, ByVal hDestinationFile As Long)
Public Event OnCancel()
Public Event OnPause()
Public Event OnFinished()
Public Property Let Status(ByVal vData As ProcessStatus)
pStatus = vData
End Property
Public Property Get Status() As ProcessStatus
Status = pStatus
End Property
Public Function CallBackRoutine(ByVal TotalFileSize As Currency, ByVal TotalBytesTransferred As Currency, ByVal StreamSize As Currency, ByVal StreamBytesTransferred As Currency, ByVal dwStreamNumber As Long, ByVal dwCallbackReason As Long, ByVal hSourceFile As Long, ByVal hDestinationFile As Long) As Long
If pStatus = mPause Then
RaiseEvent OnPause
Do While pStatus = mPause
DoEvents
Loop
ElseIf pStatus = mCancel Then
RaiseEvent OnCancel
CallBackRoutine = PROGRESS_CANCEL
Else
Select Case dwCallbackReason
Case CALLBACK_STREAM_SWITCH
'////////////////////////////////////////////////
Case CALLBACK_CHUNK_FINISHED
RaiseEvent OnProgress(TotalFileSize, TotalBytesTransferred, StreamSize, StreamBytesTransferred, dwStreamNumber, dwCallbackReason, hSourceFile, hDestinationFile)
DoEvents
End Select
CallBackRoutine = PROGRESS_CONTINUE
End If
End Function
Public Function MoveFile(ByVal fileSource As String, ByVal fileDest As String) As Long
pStatus = mContinue
MoveFile = MoveFileWithProgress(fileSource, fileDest, AddressOf FileProgressRoutine, ByVal ObjPtr(Me), MOVEFILE_COPY_ALLOWED Or MOVEFILE_REPLACE_EXISTING Or MOVEFILE_WRITE_THROUGH)
If MoveFile Then RaiseEvent OnFinished
End Function
Public Function CopyFile(ByVal fileSource As String, ByVal fileDest As String) As Long
pStatus = mContinue
CopyFile = CopyFileEx(fileSource, fileDest, AddressOf FileProgressRoutine, ByVal ObjPtr(Me), 0, COPY_FILE_RESTARTABLE)
If CopyFile Then RaiseEvent OnFinished
End Function
然后一个回调模块:mProgressCallBack.bas
Option Explicit
Public Function FileProgressRoutine(ByVal TotalFileSize As Currency, ByVal TotalBytesTransferred As Currency, ByVal StreamSize As Currency, ByVal StreamBytesTransferred As Currency, ByVal dwStreamNumber As Long, ByVal dwCallbackReason As Long, ByVal hSourceFile As Long, ByVal hDestinationFile As Long, ByVal lpData As CFileOperator) As Long
FileProgressRoutine = lpData.CallBackRoutine(TotalFileSize, TotalBytesTransferred, StreamSize, StreamBytesTransferred, dwStreamNumber, dwCallbackReason, hSourceFile, hDestinationFile)
End Function
最后一个Form:4个按钮,2个文本框,1个Progressbar
Private WithEvents cf As CFileOperator
Private Sub cf_OnCancel()
MsgBox "操作已取消!", 16
End Sub
Private Sub cf_OnFinished()
MsgBox "操作成功完成!", vbInformation
Me.Caption = "就绪"
End Sub
Private Sub cf_OnProgress(ByVal TotalFileSize As Currency, ByVal TotalBytesTransferred As Currency, ByVal StreamSize As Currency, ByVal StreamBytesTransferred As Currency, ByVal dwStreamNumber As Long, ByVal dwCallbackReason As Long, ByVal hSourceFile As Long, ByVal hDestinationFile As Long)
If TotalFileSize Then
pb.Value = CInt((TotalBytesTransferred / TotalFileSize) * 100)
Me.Caption = "已完成" & pb.Value & "%........."
End If
End Sub
Private Sub Form_Load()
Set cf = New CFileOperator
Command1.Caption = "复制"
Command2.Caption = "移动"
Command3.Caption = "暂停"
Command4.Caption = "取消"
End Sub
Private Sub Command1_Click()
pb.Value = 0
cf.CopyFile Text1.Text, Text2.Text
End Sub
Private Sub Command2_Click()
pb.Value = 0
cf.MoveFile Text1.Text, Text2.Text
End Sub
Private Sub Command3_Click()
If cf.Status = mPause Then
Command3.Caption = "暂停"
cf.Status = mContinue
Else
Command3.Caption = "点击继续..."
cf.Status = mPause
End If
End Sub
Private Sub Command4_Click()
cf.Status = mCancel
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set cf = Nothing
End Sub
55 push ebp
8BEC mov ebp, esp
83EC 08 sub esp, 0x00000008
我对机器指令也不是很熟悉,就解释这几个字节。其它的,你看着办吧…………
至于“如何得到”这些机器指令编码,
方法一般就是“用汇编语言”把自己需要的“过程代码”写好,然后编译成exe,
然后从文件中获取到相应的机器指令字节序列;
或者用OD等调试工具,直接在“内存代码区”一行一行的输入这个“汇编过程”,
调试器会直接给你“翻译”出对应的机器指令字节,完成后把这段“字节序列”获取到。
最后就是在VB中用数组来表示这一系列的“字节序列”了。