Testing the LKM

Testing the module is much more simple than writing one. The compilation is not different from the usual; we simply compile it with the Flat Assembler:

# It is just the name of the output file that differs
# The extension would be 'ko' - kernel object, instead
# of 'o' for regular object
fasm lkm.asm lkm.ko

Once our kernel module is compiled, we need to ensure that it has the executable attribute set by running the chmod +x lkm.ko command in the Terminal.

In order to load the LKM into the currently running kernel, we use the insmode command in the following way:

sudo /sbin/insmode ./lkm.ko

We will not be given any error unless there is a serious problem with the format of the LKM (for example, invalid symbol version(s)). If all went well, try to run the dmesg command in the terminal, like this:

dmesg | tail -n 10

You should see the "<0> Here I am, gentlemen!" string appearing at the end of the system log. If the string is not there, then, most likely, you have to reboot your system, but first try to unload the module by running the rmmod command in the Terminal, like this:

sudo /sbin/rmmod simple_module

If all went well, then we will now be able to create Linux LKMs using pure Assembly.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset