Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Get CPU name using low level machine instructions (Assembly!) in VB!

Total Hit ( 3280)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Here is the most advanced technique probably you have ever seen in VB. Haven't you been told by the "experts" that you can't do low level programming stuff in VB which you can do in C/C++/ASM ? But here I shall prove them wrong. This little code will demonstrate how to execute low level Machine instructions in VB to get CPU name. You can pass byte array containing low level machine instruction to CallWindowProc API. I will add more articles in VB & Assembly section in future.

Just copy and paste the following code into your form.

Click here to copy the following block
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

Public Function GetCpuName() As String

  Dim MachineCode(0 To 35) As Byte
  Dim VarAddr        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

  CallWindowProc VarPtr(MachineCode(0)), EAX, VarPtr(CPUName(1)), VarPtr(CPUName(9)), VarPtr(CPUName(5))
  GetCpuName = StrConv(CPUName(), vbUnicode)  'UnicodeName
End Function

Private Sub Form_Load()
  MsgBox GetCpuName
End Sub



Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.