转载:
1.linux常用查看硬件设备信息命令 https://blog.csdn.net/shaozengwei/article/details/39054169
2.linux的所有进程https://www.cnblogs.com/zwgblog/p/5971455.html
常见的格式 :ps options
ps ax显示所有的进程清单
3.内核版本,系统运行那个内核版本直接影响应用程序可以使用那些系统调用
$ uname -a
内核版本格式 linux-a.b.c
4.系统调用
为了启动系统调用,需要使用INT指令,Linux系统调用于中断0x80。执行INT指 令时,所有操作转移到内核中的系统调用处理程序。系统调用完成t执行转移回INT指令之后的下一条指令(当然,除非执行了exit系统调用)
EBX寄存器用于保存指向输入参数的内存位置的指针,输入参数按照连续的顺序存储。系统调用这个指针访问内存位置以便读取参数。
5.系统调用
https://blog.csdn.net/pk_20140716/article/details/49978527
5.1 系统调用sysinfo可以用于返回关于系统如何配置以及有什么可用的资源,每个系统值被返回到结构体内的特定位置,必须在一个内存位置创建这个结构,以便直接可以返回到这里:
.section .data
result:
uptime:
.int 0
loadl:
.int 0
load5:
.int 0
load15:
.int 0
totalram:
.int 0
freeram:
.int 0
sharedram:
.int 0
bufferram:
.int 0
totalswap:
.int 0
freeswap:
.int 0
procs:
.byte 0x00,0x00
totalhigh:
.int 0
memunit:
.int 0
执行INT指令后,返回结构值被加载到这个内存位置中,各个内存标签可以用于引用每个单独的值。
.section .data
result:
uptime:
.int 0
loadl:
.int 0
load5:
.int 0
load15:
.int 0
totalram:
.int 0
freeram:
.int 0
sharedram:
.int 0
bufferram:
.int 0
totalswap:
.int 0
freeswap:
.int 0
procs:
.byte 0x00,0x00
totalhigh:
.int 0
memunit:
.int 0
.section .text
.globl _start
_start:
nop
movl $result,%ebx
movl $116,%eax
int $0x80
movl $1,%eax
movl $0,%ebx
int $0x80
类似于这种,每个变量都可以查询
5.2 跟踪系统调用:
strace程序 是重点
.section .bss
.lcomm pid ,4
.lcomm uid ,4
.lcomm gid ,4
.section .text
.globl _start
_start:
movl $20,%eax
int $0x80
movl %eax,pid
movl $24,%eax
int $0x80
movl %eax ,uid
movl $47,%eax
int $0x80
movl %eax,gid
end:
movl $1,%eax
movl $0,%ebx
int $0x80
运行结果:
此程序具有很高的参考价值
.section .data
timespec:
.int 5,0#此处设置了秒数
output:
.ascii "THis is a test message.\n"
output_end:
.equ len,output_end -output
.section .bss
.lcomm rem,8
.section .text
.globl _start
_start:
nop
movl $10,%ecx#一共执行10次
loopl:
pushl %ecx
movl $4,%eax
movl $1,%ebx
movl $output ,%ecx
movl $len,%edx
int $0x80
movl $162,%eax
movl $timespec ,%ebx
movl $rem,%ecx
int $0x80
popl %ecx
loop loopl
movl $1,%eax
movl $0,%ebx
int $0x80