I don't like the so-called business logic that is boasted by today's Internet industry to be more damned than Hades , I just like the machine itself , So I can't program , yes , It's retribution .
I can only C Language and assembly , But not very much .
But I think C Those generated automatically by language compiler push RBP Such instructions are terrible , So I prefer a more pure compilation .
I used to be a user Java People who have written about the interface , I'm also a person who can't open the machine directly with the machine code , I don't understand UML But people who used screwdrivers to program , At least I admire people like that .
this paper , I'll show you one written in assembler Linux Kernel module , No, gcc Generated prologue & epilogue, Neither include So a bunch of header files , Simple and direct , Please see ：
; test.asm global init_module global cleanup_module extern printk section .
data msg db" Zhejiang Wenzhou leather shoes wet , It's not fat when it's raining \n", 32, 0 section .text init_module: mov rdi, $msg
call printk xor rax, rax ret cleanup_module: ret
Makefile as follows ：
obj-m += mod.o mod-objs = test.o KDIR := /lib/modules/`uname -r`/build PWD :=
$(shell pwd) default: nasm -f elf64 test.asm -o test.o make -C $(KDIR) M=$(PWD)
direct make, The effect is as follows ：
[root@localhost test]# dmesg [ 1076.387265] Zhejiang Wenzhou leather shoes wet , It's not fat when it's raining
Try printing out the current kernel version ?
Easy to handle !
[root@localhost ~]# cat /proc/kallsyms |grep linux_banner ffffffff8164c0e0 R
The code is as follows ：
global init_module extern printk section .text init_module: mov rdi,
0xffffffff8164c0e0 call printk mov rax, -1 ret
The effect is as follows ：
[root@localhost test]# insmod ./mod.ko insmod: ERROR: could not insert module
./mod.ko: Operation not permitted[root@localhost test]# dmesg [ 1757.595004]
Linux version 3.10.x86_64(admin@2969c2e8d7c0) (gcc version 4.8.5 20150623 (Red
Hat 4.8.5-4) (GCC) ) #1 SMP Thu Jan 25 10:26:17 CST 2018
Zhejiang Wenzhou leather shoes wet , It's not fat when it's raining !