请教高手,对于调用汇编语言怎么办?

tanyx 2003-09-11 11:53:47
如果是一个简单的COM文件呢?
如果是一个编译好的EXE文件呢?
能否将汇编代码放入源程序内(系列十六进制数据)?如何进入呢。
还有什么好办法调用汇编语言?
或者替代的,调用C语言。
...全文
36 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
900126 2003-09-28
  • 打赏
  • 举报
回复
一个危险的例子。给我留言。
jlum99 2003-09-12
  • 打赏
  • 举报
回复
上面的程序即使做出来,也还是有局限性的.
tanyx 2003-09-12
  • 打赏
  • 举报
回复
不论行否,整整齐齐就该给分啊。
yunfeng007 2003-09-12
  • 打赏
  • 举报
回复
下面的例子完全用VB进行ASM编程的示例,本例获得CPU ID.
工程文件分为一个form1.frm 和一个模块module1.bas
----------------------form1.frm的源文件---------------------
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 1965
ClientLeft = 60
ClientTop = 345
ClientWidth = 3105
LinkTopic = "Form1"
ScaleHeight = 1965
ScaleWidth = 3105
StartUpPosition = 2 注释:Bildschirmmitte
Begin VB.CommandButton Command1
Caption = "Get CPU Name"
Height = 495
Left = 840
TabIndex = 0
Top = 315
Width = 1425
End
Begin VB.Label Label2
Alignment = 2 注释:Zentriert
AutoSize = -1 注释:True
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 注释:False
Italic = 0 注释:False
Strikethrough = 0 注释:False
EndProperty
Height = 240
Left = 1515
TabIndex = 2
Top = 1065
Width = 60
End
Begin VB.Label Label1
Alignment = 2 注释:Zentriert
AutoSize = -1 注释:True
BeginProperty Font
Name = "Arial"
Size = 12
Charset = 0
Weight = 700
Underline = 0 注释:False
Italic = 0 注释:False
Strikethrough = 0 注释:False
EndProperty
Height = 285
Left = 1515
TabIndex = 1
Top = 1350
Width = 75
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)

Label1 = ""
Label2 = ""

End Sub

Private Sub Command1_Click()

Label1 = GetCpuName() & " CPU"
Label2 = "You have a" & IIf(InStr("AEIOU", Left$(Label1, 1)), "n", "")

End Sub
------------------------------end---------------------------------





下面是modu1e.bas的源代码

----------------------module1.bas的源文件--------------------------
Option Explicit
注释:
注释:This shows how to incorporate machine code into VB
注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:
注释:The example fills the array with a few machine instructions and then copies
注释:them to a procedure address. The modified procedure is then called thru
注释:CallWindowProc. The result of this specific machine code is your CPU Vendor Name.
注释:
注释:##########################################################################
注释:Apparently it gets a Stack Pointer Error, but I don注释:t know why; if anybody
注释:can fix that please let me know... UMGEDV@AOL.COM
注释:The Error is not present in the native compiled version; so I think it got
注释:something to do with the P-Code Calling Convention (strange though)...
注释:##########################################################################
注释:
注释:Sub Dummy serves to reserve some space to copy the machine instructions into.
注释:
注释:
注释:Tested on Intel and AMD CPU注释:s (uncompiled and compiled)
注释:
注释:
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 Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
Private x As Long

Public Function GetCpuName() As String

Dim MachineCode(0 To 35) As Byte
Dim VarAddr As Long
Dim FunctAddr As Long
Dim EAX As Long
Dim CPUName(1 To 12) As Byte

注释:set up machine code

MachineCode(0) = &H55 注释:push ebp

MachineCode(1) = &H8B 注释:move ebp,esp
MachineCode(2) = &HEC

MachineCode(3) = &H57 注释:push edi

MachineCode(4) = &H52 注释:push edx

MachineCode(5) = &H51 注释:push ecx

MachineCode(6) = &H53 注释:push ebx

MachineCode(7) = &H8B 注释:move eax,dword ptr [ebp+8]
MachineCode(8) = &H45
MachineCode(9) = &H8

MachineCode(10) = &HF 注释:cpuid
MachineCode(11) = &HA2

MachineCode(12) = &H8B 注释:mov edi,dword ptr [ebp+12]
MachineCode(13) = &H7D
MachineCode(14) = &HC

MachineCode(15) = &H89 注释:move dword ptr [edi],ebx
MachineCode(16) = &H1F

MachineCode(17) = &H8B 注释:mov edi,dword ptr [ebp+16]
MachineCode(18) = &H7D
MachineCode(19) = &H10

MachineCode(20) = &H89 注释:move dword ptr [edi],ecx
MachineCode(21) = &HF

MachineCode(22) = &H8B 注释:mov edi,dword ptr [ebp+20]
MachineCode(23) = &H7D
MachineCode(24) = &H14

MachineCode(25) = &H89 注释:move dword ptr [edi],edx
MachineCode(26) = &H17

MachineCode(27) = &H58 注释:pop ebx

MachineCode(28) = &H59 注释:pop ecx

MachineCode(29) = &H5A 注释:pop edx

MachineCode(30) = &H55 注释:pop edi

MachineCode(31) = &HC9 注释:leave

MachineCode(32) = &HC2 注释:ret 16 I tried everything from 0 to 24
MachineCode(33) = &H10 注释: but all produce the stack error
MachineCode(34) = &H0

注释:tell cpuid what we want
EAX = 0

注释:get address of Machine Code
VarAddr = VarPtr(MachineCode(0))

注释:get address of Sub Dummy
FunctAddr = GetAddress(AddressOf Dummy)

注释:copy the Machine Code to where it can be called
CopyMemory ByVal FunctAddr, ByVal VarAddr, 35 注释:35 bytes machine code

注释:call it
On Error Resume Next 注释:apparently it gets a stack pointer error when in P-Code but i dont know why
CallWindowProc FunctAddr, EAX, VarPtr(CPUName(1)), VarPtr(CPUName(9)), VarPtr(CPUName(5))
注释:Debug.Print Err; Err.Description
注释:MsgBox Err & Err.Description
On Error GoTo 0

GetCpuName = StrConv(CPUName(), vbUnicode) 注释:UnicodeName

End Function

Private Function GetAddress(Address As Long) As Long

GetAddress = Address

End Function

Private Sub Dummy()

注释:the code below just reserves some space to copy the machine code into
注释:it is never executed

x = 0
x = 1
x = 2
x = 3
x = 4
x = 5
x = 6
x = 7
x = 8
x = 9
x = 10
x = 0
x = 1
x = 2
x = 3
x = 4
x = 5
x = 6
x = 7
x = 8
x = 9
x = 10

End Sub
tanyx 2003-09-12
  • 打赏
  • 举报
回复
不行,我要每秒种调用10000次以上,怎么能用shell呢。
jlum99 2003-09-11
  • 打赏
  • 举报
回复
用DEBUG
planetike 2003-09-11
  • 打赏
  • 举报
回复
用shell命令去执行com,exe,不知道怎么调用汇编与C,Delphi可以执行汇编,不知道VB行不行.
下面的代码可以让程序在shell时停下来,待shell命令执行后才继续.
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

Private Const SYNCHRONIZE = &H100000
Private Const INFINITE = &HFFFF ' Infinite timeout
Private Const WAIT_TIMEOUT = &H102&

Public Function ShellForWait(sAppName As String, Optional ByVal lShowWindow As VbAppWinStyle = vbMinimizedFocus, Optional ByVal lWaitTime As Long = 0) As Boolean
Dim lID As Long, lHnd As Long, lRet As Long
On Error Resume Next
lID = Shell(sAppName, lShowWindow)
If lID > 0 Then
lHnd = OpenProcess(SYNCHRONIZE, 0, lID)
If lHnd <> 0 Then
Do
lRet = WaitForSingleObject(lHnd, lWaitTime)
DoEvents
Loop While lRet = WAIT_TIMEOUT
CloseHandle lHnd
ShellForWait = True
Else
ShellForWait = False
End If
Else
ShellForWait = False
End If
End Function

Private Sub Command1_Click()
ShellForWait "cmd.exe ", , &HFFFF
MsgBox ""
End Sub

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧