📄 clsasm.cls
字号:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsasm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'+ 《声明》 +
'+ 该类可以任意修改和转载,如有修改,修改者请发送修改后的代码给原作者 +
'+ ,代码修改者可以添加修改者的信息,作者保留此类的所有权,凡是用到此类 +
'+ 请保留下列作者的相关信息. +
'+ +
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'+ 《汇编基础类》 +
'+ 日 期: 2007年7月10日 +
'+ 名 称: clsASM +
'+ BG Studio +
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'+ 原作者信息 +
'+ 作 者:孙 林 +
'+ 博 客: http://bycw2007.blog.163.com +
'+ E-MAIL: bycw2005@yahoo.com.cn +
'+ +
'+ 关于我:本人就读与上海工程技术大学(www.sues.edu.cn),所学专业虽然 +
'+ 是城市轨道交通,与计算机毫无联系,但是本人从小酷爱计算机 +
'+ 也算比较热爱编程,希望与广大编程爱好者交个朋友 +
'+ +
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'+ 代码修改者信息 +
'+ 源码更新:不要踩我 +
'+ 更新日期:2007年7月10日 +
'+ 更新内容:略 +
'+ +
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function CreateRemoteThread Lib "kernel32" (ByVal hProcess As Long, lpThreadAttributes As Any, ByVal dwStackSize As Long, lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadId As Long) As Long
Private Declare Function VirtualFreeEx Lib "kernel32" (ByVal hProcess As Long, lpAddress As Any, ByVal dwSize As Long, ByVal dwFreeType As Long) As Long
Private Declare Function VirtualAllocEx Lib "kernel32" (ByVal hProcess As Long, lpAddress As Any, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Const PAGE_EXECUTE_READWRITE = &H40
Const MEM_COMMIT = &H1000
Const MEM_RELEASE = &H8000
Const MEM_DECOMMIT = &H4000
Const PROCESS_ALL_ACCESS = &H1F0FFF
Dim OPcode As String
Dim id As Long
Dim ptAddr(10) As Long
Function Get_Result() As String
Dim i As Long
ReDim AsmCode(Len(OPcode) / 2 - 1) As Byte
For i = 0 To UBound(AsmCode)
AsmCode(i) = CByte("&H" & Mid(OPcode, i * 2 + 1, 2))
Next
Get_Result = CallWindowProc(VarPtr(AsmCode(0)), 0, 0, 0, 0)
End Function
Function Get_Code() As String
Get_Code = OPcode
End Function
Function inject(pid As Long) As Long '返回值为调用runasm和free的参数
Dim i As Long, tmp_Addr As Long, RThwnd As Long, h As Long
ReDim AsmCode(Len(OPcode) / 2 - 1) As Byte
For i = 0 To UBound(AsmCode)
AsmCode(i) = CByte("&H" & Mid(OPcode, i * 2 + 1, 2))
Next
h = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
ptAddr(id) = VirtualAllocEx(h, ByVal 0&, UBound(AsmCode) + 1, MEM_COMMIT, PAGE_EXECUTE_READWRITE)
WriteProcessMemory h, ByVal ptAddr(id), ByVal VarPtr(AsmCode(0)), UBound(AsmCode) + 1, ByVal 0&
CloseHandle (h)
inject = id
id = id + 1
OPcode = ""
End Function
Function free(pid As Long, aid As Long)
Dim RThwnd As Long, h As Long
h = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
VirtualFreeEx h, ptAddr(aid), 0, MEM_RELEASE
CloseHandle h
End Function
Function Run_ASM(pid As Long, aid As Long) As Long
Dim RThwnd As Long, h As Long
h = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
RThwnd = CreateRemoteThread(h, ByVal 0&, 0, ByVal ptAddr(aid), ByVal 0&, ByVal 0&, ByVal 0&)
CloseHandle RThwnd
CloseHandle h
End Function
Function Int2Hex(Value As Long, n As Long) As String '高地位互换
Dim tmp1 As String, tmp2 As String, i As Long
tmp1 = Right("0000000" + Hex(Value), n)
For i = 0 To Len(tmp1) / 2 - 1
tmp2 = tmp2 + Mid(tmp1, Len(tmp1) - 1 - 2 * i, 2)
Next i
Int2Hex = tmp2
End Function
Function Leave() As Long
OPcode = OPcode + "C9"
End Function
Function Pushad() As Long
OPcode = OPcode + "60"
End Function
Function Popad() As Long
OPcode = OPcode + "61"
End Function
Function Nop() As Long
OPcode = OPcode + "90"
End Function
Function ret() As Long
OPcode = OPcode + "C3"
End Function
Function RetA(i As Long) As Long
OPcode = OPcode + Int2Hex(i, 4)
End Function
Function IN_AL_DX() As Long
OPcode = OPcode + "EC"
End Function
Function TEST_EAX_EAX() As Long
OPcode = OPcode + "85C0"
End Function
'Add
'+++++++++++++++++++++++++++++++++++
Function Add_EAX_EDX() As Long
OPcode = OPcode + "03C2"
End Function
Function Add_EBX_EAX() As Long
OPcode = OPcode + "03D8"
End Function
Function Add_EAX_DWORD_Ptr(i As Long) As Long
OPcode = OPcode + "0305" + Int2Hex(i, 8)
End Function
Function Add_EBX_DWORD_Ptr(i As Long) As Long
OPcode = OPcode + "031D" + Int2Hex(i, 8)
End Function
Function Add_EBP_DWORD_Ptr(i As Long) As Long
OPcode = OPcode + "032D" + Int2Hex(i, 8)
End Function
Function Add_EAX(i As Long) As Long
OPcode = OPcode + "05" + Int2Hex(i, 8)
End Function
Function Add_EBX(i As Long) As Long
If i <= 127 Then
OPcode = OPcode + "83C3" + Int2Hex(i, 2)
Else
OPcode = OPcode + "81C3" + Int2Hex(i, 8)
End If
End Function
Function Add_ECX(i As Long) As Long
If i <= 127 Then
OPcode = OPcode + "83C1" + Int2Hex(i, 2)
Else
OPcode = OPcode + "81C1" + Int2Hex(i, 8)
End If
End Function
Function Add_EDX(i As Long) As Long
If i <= 127 Then
OPcode = OPcode + "83C2" + Int2Hex(i, 2)
Else
OPcode = OPcode + "81C2" + Int2Hex(i, 8)
End If
End Function
Function Add_ESI(i As Long) As Long
If i <= 127 Then
OPcode = OPcode + "83C6" + Int2Hex(i, 2)
Else
OPcode = OPcode + "81C6" + Int2Hex(i, 8)
End If
End Function
Function Add_ESP(i As Long) As Long
If i <= 127 Then
OPcode = OPcode + "83C4" + Int2Hex(i, 2)
Else
OPcode = OPcode + "81C4" + Int2Hex(i, 8)
End If
End Function
'Call
'+++++++++++++++++++++++++++++++++++
Function Call_EAX() As Long
OPcode = OPcode + "FFD0"
End Function
Function Call_EBX() As Long
OPcode = OPcode + "FFD3"
End Function
Function Call_ECX() As Long
OPcode = OPcode + "FFD1"
End Function
Function Call_EDX() As Long
OPcode = OPcode + "FFD2"
End Function
Function Call_ESI() As Long
OPcode = OPcode + "FFD2"
End Function
Function Call_ESP() As Long
OPcode = OPcode + "FFD4"
End Function
Function Call_EBP() As Long
OPcode = OPcode + "FFD5"
End Function
Function Call_EDI() As Long
OPcode = OPcode + "FFD7"
End Function
Function Call_DWORD_Ptr(i As Long) As Long
OPcode = OPcode + "FF15" + Int2Hex(i, 8)
End Function
Function Call_DWORD_Ptr_EAX() As Long
OPcode = OPcode + "FF10"
End Function
Function Call_DWORD_Ptr_EBX() As Long
OPcode = OPcode + "FF13"
End Function
'Cmp
'+++++++++++++++++++++++++++++++++++
Function Cmp_EAX(i As Long) As Long
If i <= 127 Then
OPcode = OPcode + "83F8" + Int2Hex(i, 2)
Else
OPcode = OPcode + "3D" + Int2Hex(i, 8)
End If
End Function
Function Cmp_EAX_EDX() As Long
OPcode = OPcode + "3BC2"
End Function
Function Cmp_EAX_DWORD_Ptr(i As Long) As Long
OPcode = OPcode + "3B05" + Int2Hex(i, 8)
End Function
Function Cmp_DWORD_Ptr_EAX(i As Long) As Long
OPcode = OPcode + "3905" + Int2Hex(i, 8)
End Function
'DEC
'+++++++++++++++++++++++++++++++++++
Function Dec_EAX() As Long
OPcode = OPcode + "48"
End Function
Function Dec_EBX() As Long
OPcode = OPcode + "4B"
End Function
Function Dec_ECX() As Long
OPcode = OPcode + "49"
End Function
Function Dec_EDX() As Long
OPcode = OPcode + "4A"
End Function
'Idiv
'+++++++++++++++++++++++++++++++++++
Function Idiv_EAX() As Long
OPcode = OPcode + "F7F8"
End Function
Function Idiv_EBX() As Long
OPcode = OPcode + "F7FB"
End Function
Function Idiv_ECX() As Long
OPcode = OPcode + "F7F9"
End Function
Function Idiv_EDX() As Long
OPcode = OPcode + "F7FA"
End Function
'Imul
'+++++++++++++++++++++++++++++++++++
Function Imul_EAX_EDX() As Long
OPcode = OPcode + "0FAFC2"
End Function
Function Imul_EAX(i As Long) As Long
OPcode = OPcode + "6BC0" + Int2Hex(i, 2)
End Function
Function ImulB_EAX(i As Long) As Long
OPcode = OPcode + "69C0" + Int2Hex(i, 8)
End Function
'INC
'+++++++++++++++++++++++++++++++++++
Function Inc_EAX() As Long
OPcode = OPcode + "40"
End Function
Function Inc_EBX() As Long
OPcode = OPcode + "43"
End Function
Function Inc_ECX() As Long
OPcode = OPcode + "41"
End Function
Function Inc_EDX() As Long
OPcode = OPcode + "42"
End Function
Function Inc_EDI() As Long
OPcode = OPcode + "47"
End Function
Function Inc_ESI() As Long
OPcode = OPcode + "46"
End Function
Function Inc_DWORD_Ptr_EAX() As Long
OPcode = OPcode + "FF00"
End Function
Function Inc_DWORD_Ptr_EBX() As Long
OPcode = OPcode + "FF03"
End Function
Function Inc_DWORD_Ptr_ECX() As Long
OPcode = OPcode + "FF01"
End Function
Function Inc_DWORD_Ptr_EDX() As Long
OPcode = OPcode + "FF02"
End Function
'JMP/JE/JNE
'+++++++++++++++++++++++++++++++++++
Function JMP_EAX() As Long
OPcode = OPcode + "FFE0"
End Function
Function SUB_ESP(i As Long) As Long 'mov[ESP],X
If i <= 255 Then
OPcode = OPcode + "83EC" + Int2Hex(i, 2)
Else
OPcode = OPcode + "81EC" + Int2Hex(i, 8)
End If
End Function
'Mov
Function Mov_DWORD_Ptr_ESP(x As Long) As Long 'mov[ESP],X
OPcode = OPcode + "C70424" + Int2Hex(x, 8)
End Function
Function Mov_DWORD_Ptr_ESP_ADD_EAX(x As Long) As Long 'mov[ESP+X],EAX
OPcode = OPcode + "894424" + Int2Hex(x, 2)
End Function
Function Mov_DWORD_Ptr_ESP_ADD(x As Long, Y As Long) As Long 'mov[ESP+X],Y
OPcode = OPcode + "C74424" + Int2Hex(x, 2) + Int2Hex(Y, 8)
End Function
Function Mov_DWORD_Ptr_EAX_ADD(x As Long, Y As Long) As Long 'mov[EAX+X],Y
OPcode = OPcode + "C740" + Int2Hex(x, 2) + Int2Hex(Y, 8)
End Function
Function Mov_DWORD_Ptr_EAX(i As Long) As Long
OPcode = OPcode + "A3" + Int2Hex(i, 8)
End Function
Function Mov_EAX(i As Long) As Long
OPcode = OPcode + "B8" + Int2Hex(i, 8)
End Function
Function Mov_EBX(i As Long) As Long
OPcode = OPcode + "BB" + Int2Hex(i, 8)
End Function
Function Mov_ECX(i As Long) As Long
OPcode = OPcode + "B9" + Int2Hex(i, 8)
End Function
Function Mov_EDX(i As Long) As Long
OPcode = OPcode + "BA" + Int2Hex(i, 8)
End Function
Function Mov_ESI(i As Long) As Long
OPcode = OPcode + "BE" + Int2Hex(i, 8)
End Function
Function Mov_ESP(i As Long) As Long
OPcode = OPcode + "BC" + Int2Hex(i, 8)
End Function
Function Mov_EBP(i As Long) As Long
OPcode = OPcode + "BD" + Int2Hex(i, 8)
End Function
Function Mov_EDI(i As Long) As Long
OPcode = OPcode + "BF" + Int2Hex(i, 8)
End Function
Function Mov_EBX_DWORD_Ptr(i As Long) As Long
OPcode = OPcode + "8B1D" + Int2Hex(i, 8)
End Function
Function Mov_ECX_DWORD_Ptr(i As Long) As Long
OPcode = OPcode + "8B0D" + Int2Hex(i, 8)
End Function
Function Mov_EAX_DWORD_Ptr(i As Long) As Long
OPcode = OPcode + "A1" + Int2Hex(i, 8)
End Function
Function Mov_EDX_DWORD_Ptr(i As Long) As Long
OPcode = OPcode + "8B15" + Int2Hex(i, 8)
End Function
Function Mov_ESI_DWORD_Ptr(i As Long) As Long
OPcode = OPcode + "8B35" + Int2Hex(i, 8)
End Function
Function Mov_ESP_DWORD_Ptr(i As Long) As Long
OPcode = OPcode + "8B25" + Int2Hex(i, 8)
End Function
Function Mov_EBP_DWORD_Ptr(i As Long) As Long
OPcode = OPcode + "8B2D" + Int2Hex(i, 8)
End Function
Function Mov_EAX_DWORD_Ptr_EAX() As Long
OPcode = OPcode + "8B00"
End Function
Function Mov_EAX_DWORD_Ptr_EBP() As Long
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -