samedi 26 juillet 2014

c - déterminer l'emplacement (adresse mémoire) où le module du pilote réside - Stack Overflow


When a linux kernel driver is loaded dynamically, how do we write a C function to report the location (memory address) where the driver module is residing?


This is more for windows, however, if we adapt similar for Linux driver will that work?



long sizeOfExe = 0;
FILE *fp;

fp = fopen("./Mini.ko", "rb"); // reading itself

fseek(fp, 0L, SEEK_END);
sizeOfExe = ftell(fp);

printf("The size of this driver module is: %ld bytes\n", sizeOfExe);
int* addressStartOfFile = &fp;
printf("Location of this driver module starts at: 0x%x\n", addressStartOfFile);
printf("Location of this driver module ends at: 0x%x\n", (addressStartOfFile+sizeOfExe));

/*
The size of this driver module is: 18727 bytes
Location of this driver module starts at: 0x28ff30
Location of this driver module ends at: 0x2a23cc
*/



When a linux kernel driver is loaded dynamically, how do we write a C function to report the location (memory address) where the driver module is residing?


This is more for windows, however, if we adapt similar for Linux driver will that work?



long sizeOfExe = 0;
FILE *fp;

fp = fopen("./Mini.ko", "rb"); // reading itself

fseek(fp, 0L, SEEK_END);
sizeOfExe = ftell(fp);

printf("The size of this driver module is: %ld bytes\n", sizeOfExe);
int* addressStartOfFile = &fp;
printf("Location of this driver module starts at: 0x%x\n", addressStartOfFile);
printf("Location of this driver module ends at: 0x%x\n", (addressStartOfFile+sizeOfExe));

/*
The size of this driver module is: 18727 bytes
Location of this driver module starts at: 0x28ff30
Location of this driver module ends at: 0x2a23cc
*/


0 commentaires:

Enregistrer un commentaire