Skip to content

Commit 5b8cb6a

Browse files
authored
Add dlsym for oldfunc. (#8)
1 parent 9661796 commit 5b8cb6a

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Dockerfile for QEMU testing
22
# docker build -t metacall/plthook .
3+
34
FROM ubuntu:latest
45

56
RUN apt update \

plthook_elf.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,8 @@ int plthook_replace(plthook_t *plthook, const char *funcname, void *funcaddr, vo
899899
}
900900
}
901901
if (oldfunc) {
902-
*oldfunc = *addr;
902+
void *prev = dlsym(RTLD_DEFAULT, funcname);
903+
*oldfunc = (prev != NULL) ? prev : *addr;
903904
}
904905
*addr = funcaddr;
905906
if (!(prot & PROT_WRITE)) {

0 commit comments

Comments
 (0)