Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. /* symsearch: - looks up also for unexproted symbols in the kernel
  2. * exports function:
  3. *
  4. * unsigned long lookup_symbol_address(const char *name);
  5. *
  6. * Created by Skrilax_CZ
  7. * GPL
  8. */
  9.  
  10. #include <linux/module.h>
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/string.h>
  14.  
  15. extern int
  16. kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *,
  17. unsigned long),
  18. void *data);
  19.  
  20. /* Calling a C function if I know the address
  21. * a) declare it exactly as it was, add the naked attribute
  22. * b) body:
  23. *
  24. * asm volatile("ldr r12,=function_address\n\t"
  25. * "ldr pc,[r12,#0]");
  26. *
  27. * c) function_address is a variable storing the address
  28. *
  29. * Below is an example.
  30. */
  31.  
  32. static unsigned long kallsyms_lookup_name_address = 0;
  33.  
  34. //unsigned long kallsyms_lookup_name(const char *name)
  35. unsigned long __attribute__((naked))
  36. lookup_symbol_address(const char *name)
  37. {
  38. //just change the pc value to the address, so it returns to previous caller
  39. //note that first instruction will actually put a pointer to r12
  40. asm volatile("ldr r12,=kallsyms_lookup_name_address\n\t"
  41. "ldr pc,[r12,#0]");
  42. //lr value remains original, so it returns to the caller
  43. }
  44.  
  45. EXPORT_SYMBOL(lookup_symbol_address);
  46.  
  47. static int
  48. find_kallsyms_lookup_name(void* data, const char* name,
  49. struct module * module, unsigned long address)
  50. {
  51. //kallsyms_lookup_name is our friend
  52. if (!strcmp(name, "kallsyms_lookup_name"))
  53. {
  54. printk(KERN_INFO "symsearch: found kallsyms_lookup_name on 0x%lx.\n", address);
  55. kallsyms_lookup_name_address = address;
  56. return 1;
  57. }
  58.  
  59. return 0;
  60. }
  61.  
  62. static int __init
  63. symsearch_init(void)
  64. {
  65. //kallsyms export the kallsyms_on_each_symbol so use that
  66. kallsyms_on_each_symbol(&find_kallsyms_lookup_name, NULL);
  67. return kallsyms_lookup_name_address == 0;
  68. }
  69.  
  70. module_init(symsearch_init);
  71. MODULE_LICENSE("GPL");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement