| 网站首页 | 新闻中心 | 系统安全 | 网络安全 | 安全技术 | 下载中心 | 安全365社区 |
安全365
收藏本站
设为首页
会员登录:
站内搜索: 新闻中心 系统安全 网络安全 安全技术 下载中心
| 系统安全首页 | 漏洞分析 | 入侵检测 | 升级补丁 | 安全配置 |
Linux发行版知识普及:三个版本的CPUID
Linux发行版知识普及:三个版本的CPUID
作者:korn 文章来源:赛迪网 点击数: 更新时间:2008-1-31 1:59:10
 

第一个版本

x86-ubuntu-64位环境,at&t格式(gas汇编),使用linux系统调用:

#cpuid.s show extract the processor vendor ID
.section .data
output:
.ascii "the processor vendor ID is 'XXXXXXXXXXXX'\n"
.section .text
.globl main
main:
movl $0, %eax
cpuid
movl $output, %edi
movl %ebx, 28(%edi)
movl %edx, 32(%edi)
movl %ecx, 36(%edi)
movl $4, %eax
movl $1, %ebx
movl $output, %ecx
movl $42, %edx
int $0x80
movl $1, %eax
movl $0, %ebx
int $0x80

第二个版本

x86-ubuntu-64位环境,at&t格式(gas汇编),使用C库函数,注意使用了64位寄存器,想改成32位只要把所有带r的改成带e的就可以了

# cpuidinlib.s show extract the processor vendor ID using library
.section .data
output:
.asciz "the processor vendor ID is %s\n"

.section .bss
.lcomm buffer, 12

.section .text
.globl _start
_start:
movq $0, %rax
cpuid
movq $buffer, %rdi
movl %ebx, (%rdi)
movl %edx, 4(%rdi)
movl %ecx, 8(%rdi)

movq $output, %rdi
movq $buffer, %rsi
xorq %rax, %rax
call printf
movq $0, %rdi
xorq %rax, %rax
call exit
不过上面有一个问题
printf("%s", str);

这样的形式不常见,既然是字符串, str应该是以0结束的,但是注意上面并没有以0结束,那么printf是怎么判断字符串结束了呢? 在C下一样成功,不知道为什么,知道的告诉我下。

第三个 x86-win32,使用intel语法(masm32开发包), 调用windows API.这个估计都熟悉

;; cpuid
.686
.model flat, stdcall
option casemap: none
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
includelib msvcrt.lib
sprintf PROTO C:DWORD, :DWORD, :VARARG

.data
msg db 'the processor vendor ID is %s', 0
note db '注意', 0
.data?
result db 13 dup(?)
buff db 128 dup(?)
.code
start:
call go
invoke ExitProcess,NULL
go:
mov eax, 0
cpuid
mov edi, offset result
mov [edi], ebx
mov 4[edi], edx
mov 8[edi], ecx
mov byte ptr 12[edi], 0

push dword ptr offset result
push dword ptr offset msg
push dword ptr offset buff
;call sprintf 
mov eax, 77c0f931H
call eax
add esp, 12

invoke MessageBox, NULL, addr buff, addr note, MB_OK
ret
end start

 

文章录入:郝丽    责任编辑:郝丽 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
     
     
     
    实用技巧 Linux环境下简
    通过监控Linux运行进程来
    用NFS服务开发ARM Linux
    Linux 和 Unix 系统中最
    认识三大方便的开源 Lin
    Linux操作系统下PPPOE拨
    Linux下实现从Ext2到Ext
    我的 Linux 玩具清单
    Excel电子表格导出TXT在
    Linux下更改网卡的物理地
    站长邮箱:webmaster@anquan365.com
    联系电话:86-10-67634029 点击这里给我发消息

    Copyright © 2006-2008 www.anquan365.com 北京华安普特网络科技有限公司 版权所有