Permalink
Browse files

tramp all plt entries even if function is not found in ruby binary

  • Loading branch information...
1 parent 74c5905 commit 14b8626cd46cbbb4396b91953e6c974e23d64c9a @tmm1 tmm1 committed Apr 20, 2010
Showing with 24 additions and 26 deletions.
  1. +24 −26 ext/elf.c
View
@@ -562,32 +562,7 @@ bin_update_image(const char *trampee, struct tramp_st2_entry *tramp, void **orig
/* first check if the symbol is in the PLT */
trampee_addr = find_plt_addr(trampee, NULL);
- /* it isn't in the PLT, try to find it in the binary itself */
- if (!trampee_addr) {
- dbg_printf("Couldn't find %s in the PLT...\n", trampee);
- unsigned char *byte = ruby_info->text_segment;
- trampee_addr = bin_find_symbol(trampee, NULL, 0);
- size_t count = 0;
- int num = 0;
-
- assert(byte != NULL);
-
- if (!trampee_addr) {
- dbg_printf("WARNING: Couldn't find: %s anywhere, so not tramping!\n", trampee);
- return 0;
- }
-
- if (orig_func) {
- *orig_func = trampee_addr;
- }
-
- for(; count < ruby_info->text_segment_len; byte++, count++) {
- if (arch_insert_st1_tramp(byte, trampee_addr, tramp) == 0) {
- num++;
- }
- }
- dbg_printf("Inserted %d tramps for: %s\n", num, trampee);
- } else {
+ if (trampee_addr) {
void *ret = NULL;
dbg_printf("Found %s in the PLT, inserting tramp...\n", trampee);
ret = overwrite_got(trampee_addr, tramp->addr);
@@ -598,6 +573,29 @@ bin_update_image(const char *trampee, struct tramp_st2_entry *tramp, void **orig
*orig_func = ret;
dbg_printf("setting orig function: %p\n", *orig_func);
}
+ } else {
+ trampee_addr = bin_find_symbol(trampee, NULL, 0);
+ dbg_printf("Couldn't find %s in the PLT...\n", trampee);
+
+ if (trampee_addr) {
+ unsigned char *byte = ruby_info->text_segment;
+ size_t count = 0;
+ int num = 0;
+
+ assert(byte != NULL);
+
+ if (orig_func) {
+ *orig_func = trampee_addr;
+ }
+
+ for(; count < ruby_info->text_segment_len; byte++, count++) {
+ if (arch_insert_st1_tramp(byte, trampee_addr, tramp) == 0) {
+ num++;
+ }
+ }
+
+ dbg_printf("Inserted %d tramps for: %s\n", num, trampee);
+ }
}
dbg_printf("Trying to hook %s in other libraries...\n", trampee);

0 comments on commit 14b8626

Please sign in to comment.