王朝网络
分享
 
 
 

用VB更换桌面墙纸DIY

王朝厨房·作者佚名  2007-01-04
宽屏版  字体: |||超大  

下面的例子完全用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

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
>>返回首页<<
推荐阅读
 
 
频道精选
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
© 2005- 王朝网络 版权所有