;================================================================================= ; Kernel Module example. ; ; Before re-assembling this example make sure you have changed 'vermagic' ; (kernel_version) to reflect your kernel version. And have executed ; 'koupd lkm.asm' (koupd is located in the bin directory) to generate symversion ; information. ; If '__versions' section already exists, remove it prior to running koupd! ; ; Load module with: 'insmod lkm.ko' ; View currently loaded modules with: 'lsmod' ; To inspect prink-ed messages use: 'cat /var/log/kern.log | tail' ; Unload the module with: 'rmmod lkm' ; ; ; The LSCR Project. ;================================================================================= format ELF section ".text" executable align 4 public init_module public cleanup_module extrn struct_module extrn printk init_module: push init call printk pop eax xor eax, eax ret cleanup_module: push cleanup call printk pop eax ret section ".rodata" writeable align 4 init db "<1>Hello, LKM world", 0xa, 0 cleanup db "<1>Goodbye, cruel world", 0xa, 0 section '.modinfo' align 32 __kernel_version db "kernel_version=2.6.19-1.2911.fc6", 0 __mod_vermagic db "vermagic=2.6.19-1.2911.fc6 SMP mod_unload 586 REGPARM 4KSTACKS ", 0 __module_depends db "depends=", 0 __module_license db "license=GPL", 0 __module_author db "author=...", 0 __module_description db "description=Hello, LKM world", 0 section '.gnu.linkonce.this_module' writeable align 64 __this_module: ; this is actually a module structure (defined in include/linux/module.h) ; this structure has changed in 2.6.6. so if you are using kernel < 2.6.6 ; lookup for the correct offsets. dd 0, 0, 0 @@: db "lkm" ; module name db 160-($-@b) dup(0) dd init_module ; +172bytes. initialization function db 156 dup(0) dd cleanup_module ; +332bytes. finalization function db 48 dup(0)