rbdc 0.9.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/dyncall/BUGS +1 -1
- data/dyncall/CMakeLists.txt +19 -7
- data/dyncall/ChangeLog +61 -20
- data/dyncall/LICENSE +1 -1
- data/dyncall/Makefile.generic +2 -0
- data/dyncall/ToDo +97 -29
- data/dyncall/autovar/README.txt +1 -0
- data/dyncall/autovar/autovar_ABI.h +4 -2
- data/dyncall/autovar/autovar_ARCH.h +9 -5
- data/dyncall/autovar/autovar_CC.h +3 -1
- data/dyncall/autovar/autovar_OS.h +2 -2
- data/dyncall/autovar/autovar_OSFAMILY.h +1 -1
- data/dyncall/configure +94 -38
- data/dyncall/dyncall/dyncall.3 +8 -4
- data/dyncall/dyncall/dyncall.h +1 -1
- data/dyncall/dyncall/dyncall_alloc.h +1 -1
- data/dyncall/dyncall/dyncall_api.c +3 -1
- data/dyncall/dyncall/dyncall_call.S +13 -5
- data/dyncall/dyncall/dyncall_call_arm32_arm.S +1 -2
- data/dyncall/dyncall/dyncall_call_arm32_arm.h +1 -1
- data/dyncall/dyncall/dyncall_call_arm32_arm_armhf.S +24 -26
- data/dyncall/dyncall/dyncall_call_arm32_arm_armhf.h +1 -1
- data/dyncall/dyncall/dyncall_call_arm32_thumb.h +1 -1
- data/dyncall/dyncall/dyncall_call_arm32_thumb_armhf.S +1 -1
- data/dyncall/dyncall/dyncall_call_arm32_thumb_gas.s +3 -7
- data/dyncall/dyncall/dyncall_call_arm64.S +2 -2
- data/dyncall/dyncall/dyncall_call_arm64.h +2 -2
- data/dyncall/dyncall/dyncall_call_mips.h +1 -1
- data/dyncall/dyncall/dyncall_call_mips_eabi.h +1 -1
- data/dyncall/dyncall/dyncall_call_mips_eabi_gas.s +16 -16
- data/dyncall/dyncall/dyncall_call_mips_gas.S +2 -2
- data/dyncall/dyncall/dyncall_call_mips_n32.h +5 -4
- data/dyncall/dyncall/dyncall_call_mips_n32_gas.s +4 -4
- data/dyncall/dyncall/dyncall_call_mips_n64.h +3 -3
- data/dyncall/dyncall/dyncall_call_mips_n64_gas.s +2 -2
- data/dyncall/dyncall/dyncall_call_mips_o32.h +4 -3
- data/dyncall/dyncall/dyncall_call_mips_o32_gas.s +1 -3
- data/dyncall/dyncall/dyncall_call_ppc32.S +1 -1
- data/dyncall/dyncall/dyncall_call_ppc32.h +1 -1
- data/dyncall/dyncall/dyncall_call_sparc.h +1 -1
- data/dyncall/dyncall/{dyncall_call_sparc.S → dyncall_call_sparc.s} +39 -44
- data/dyncall/dyncall/dyncall_call_sparc64.h +5 -5
- data/dyncall/dyncall/dyncall_call_sparc64.s +177 -0
- data/dyncall/dyncall/dyncall_call_x64.S +83 -86
- data/dyncall/dyncall/dyncall_call_x64.h +1 -1
- data/dyncall/dyncall/dyncall_call_x86.S +9 -9
- data/dyncall/dyncall/dyncall_call_x86.h +1 -1
- data/dyncall/dyncall/dyncall_call_x86_nasm.asm +5 -5
- data/dyncall/dyncall/dyncall_callf.c +18 -18
- data/dyncall/dyncall/dyncall_callf.h +1 -1
- data/dyncall/dyncall/dyncall_callvm.c +3 -3
- data/dyncall/dyncall/dyncall_callvm.h +1 -1
- data/dyncall/dyncall/dyncall_callvm_arm32_arm.c +25 -40
- data/dyncall/dyncall/dyncall_callvm_arm32_arm.h +1 -5
- data/dyncall/dyncall/dyncall_callvm_arm32_arm_armhf.c +25 -33
- data/dyncall/dyncall/dyncall_callvm_arm32_arm_armhf.h +1 -5
- data/dyncall/dyncall/dyncall_callvm_arm32_thumb.c +24 -36
- data/dyncall/dyncall/dyncall_callvm_arm32_thumb.h +1 -5
- data/dyncall/dyncall/dyncall_callvm_arm64.c +23 -27
- data/dyncall/dyncall/dyncall_callvm_arm64.h +2 -6
- data/dyncall/dyncall/dyncall_callvm_arm64_apple.c +23 -30
- data/dyncall/dyncall/dyncall_callvm_base.c +1 -1
- data/dyncall/dyncall/dyncall_callvm_mips.c +1 -1
- data/dyncall/dyncall/dyncall_callvm_mips.h +1 -1
- data/dyncall/dyncall/dyncall_callvm_mips_eabi.c +30 -27
- data/dyncall/dyncall/dyncall_callvm_mips_eabi.h +1 -5
- data/dyncall/dyncall/dyncall_callvm_mips_n32.c +24 -30
- data/dyncall/dyncall/{dyncall_call_sparc_v9.h → dyncall_callvm_mips_n32.h} +18 -8
- data/dyncall/dyncall/dyncall_callvm_mips_n64.c +23 -30
- data/dyncall/dyncall/dyncall_callvm_mips_n64.h +4 -6
- data/dyncall/dyncall/dyncall_callvm_mips_o32.c +31 -29
- data/dyncall/dyncall/dyncall_callvm_mips_o32.h +1 -3
- data/dyncall/dyncall/dyncall_callvm_ppc32.c +22 -20
- data/dyncall/dyncall/dyncall_callvm_ppc32.h +1 -3
- data/dyncall/dyncall/dyncall_callvm_ppc64.c +54 -15
- data/dyncall/dyncall/dyncall_callvm_ppc64.h +0 -2
- data/dyncall/dyncall/dyncall_callvm_sparc.c +34 -26
- data/dyncall/dyncall/dyncall_callvm_sparc.h +1 -3
- data/dyncall/dyncall/dyncall_callvm_sparc64.c +94 -150
- data/dyncall/dyncall/dyncall_callvm_sparc64.h +11 -17
- data/dyncall/dyncall/dyncall_callvm_x64.c +37 -36
- data/dyncall/dyncall/dyncall_callvm_x64.h +1 -4
- data/dyncall/dyncall/dyncall_callvm_x86.c +22 -63
- data/dyncall/dyncall/dyncall_callvm_x86.h +1 -17
- data/dyncall/dyncall/dyncall_config.h +1 -1
- data/dyncall/dyncall/dyncall_macros.h +28 -19
- data/dyncall/dyncall/dyncall_signature.h +1 -1
- data/dyncall/dyncall/dyncall_types.h +17 -18
- data/dyncall/dyncall/dyncall_utils.h +1 -1
- data/dyncall/dyncall/dyncall_value.h +28 -21
- data/dyncall/dyncall/dyncall_vector.c +1 -1
- data/dyncall/dyncall/dyncall_vector.h +1 -1
- data/dyncall/dyncall/gen-masm.sh +2 -2
- data/dyncall/dyncallback/CMakeLists.txt +1 -2
- data/dyncall/dyncallback/Makefile.generic +1 -1
- data/dyncall/dyncallback/dyncall_alloc_wx.c +1 -1
- data/dyncall/dyncallback/dyncall_alloc_wx.h +4 -3
- data/dyncall/dyncallback/dyncall_alloc_wx_malloc.c +8 -2
- data/dyncall/dyncallback/dyncall_alloc_wx_mmap.c +67 -4
- data/dyncall/dyncallback/dyncall_alloc_wx_win32.c +7 -2
- data/dyncall/dyncallback/dyncall_args.c +19 -15
- data/dyncall/dyncallback/dyncall_args.h +1 -1
- data/dyncall/dyncallback/{dyncall_args_arm32_arm.c → dyncall_args_arm32.c} +4 -4
- data/dyncall/dyncallback/{dyncall_args_arm32_arm.h → dyncall_args_arm32.h} +6 -6
- data/dyncall/dyncallback/dyncall_args_arm64.c +2 -2
- data/dyncall/dyncallback/dyncall_args_arm64_apple.c +2 -2
- data/dyncall/dyncallback/dyncall_args_mips.c +26 -21
- data/dyncall/dyncallback/dyncall_args_mips.h +18 -6
- data/dyncall/dyncallback/dyncall_args_mips64.c +81 -0
- data/dyncall/dyncallback/dyncall_args_mips_o32.c +104 -0
- data/dyncall/dyncallback/dyncall_args_ppc32.c +2 -2
- data/dyncall/dyncallback/dyncall_args_ppc32.h +1 -1
- data/dyncall/dyncallback/dyncall_args_ppc32_sysv.c +1 -1
- data/dyncall/dyncallback/dyncall_args_ppc64.c +24 -3
- data/dyncall/dyncallback/dyncall_args_sparc32.c +41 -15
- data/dyncall/dyncallback/dyncall_args_sparc32.h +2 -2
- data/dyncall/dyncallback/dyncall_args_sparc64.c +28 -15
- data/dyncall/dyncallback/dyncall_args_sparc64.h +7 -3
- data/dyncall/dyncallback/dyncall_args_x64.c +1 -1
- data/dyncall/dyncallback/dyncall_args_x64.h +1 -1
- data/dyncall/dyncallback/dyncall_args_x86.c +1 -1
- data/dyncall/dyncallback/dyncall_args_x86.h +1 -1
- data/dyncall/dyncallback/dyncall_callback.c +10 -12
- data/dyncall/dyncallback/dyncall_callback.h +2 -4
- data/dyncall/dyncallback/dyncall_callback_arch.S +12 -2
- data/dyncall/dyncallback/{dyncall_callback_arm32_arm.c → dyncall_callback_arm32.c} +25 -10
- data/dyncall/dyncallback/dyncall_callback_arm32_arm_apple.s +7 -7
- data/dyncall/dyncallback/dyncall_callback_arm32_arm_gas.S +9 -9
- data/dyncall/dyncallback/dyncall_callback_arm32_thumb_apple.S +1 -1
- data/dyncall/dyncallback/dyncall_callback_arm32_thumb_gas.S +1 -1
- data/dyncall/dyncallback/dyncall_callback_arm64.S +2 -2
- data/dyncall/dyncallback/dyncall_callback_arm64.c +20 -14
- data/dyncall/dyncallback/dyncall_callback_mips.c +26 -9
- data/dyncall/dyncallback/dyncall_callback_mips_eabi_gas.s +99 -0
- data/dyncall/dyncallback/{dyncall_args_arm32_thumb.h → dyncall_callback_mips_gas.S} +14 -9
- data/dyncall/dyncallback/{dyncall_callback_arm32_thumb.c → dyncall_callback_mips_n32_gas.s} +12 -7
- data/dyncall/dyncallback/dyncall_callback_mips_n64_gas.s +98 -0
- data/dyncall/dyncallback/dyncall_callback_mips_o32_gas.s +100 -0
- data/dyncall/dyncallback/dyncall_callback_ppc32.S +54 -54
- data/dyncall/dyncallback/dyncall_callback_ppc32.c +23 -5
- data/dyncall/dyncallback/dyncall_callback_ppc32_apple.s +92 -117
- data/dyncall/dyncallback/dyncall_callback_ppc64.S +2 -2
- data/dyncall/dyncallback/dyncall_callback_ppc64.c +23 -5
- data/dyncall/dyncallback/dyncall_callback_sparc32.c +25 -7
- data/dyncall/dyncallback/dyncall_callback_sparc32.s +55 -4
- data/dyncall/dyncallback/dyncall_callback_sparc64.c +25 -7
- data/dyncall/dyncallback/dyncall_callback_sparc64.s +89 -5
- data/dyncall/dyncallback/dyncall_callback_x64.S +8 -8
- data/dyncall/dyncallback/dyncall_callback_x64.c +19 -6
- data/dyncall/dyncallback/dyncall_callback_x86.S +29 -25
- data/dyncall/dyncallback/dyncall_callback_x86.c +24 -11
- data/dyncall/dyncallback/dyncall_thunk.c +6 -6
- data/dyncall/dyncallback/dyncall_thunk.h +9 -7
- data/dyncall/dyncallback/{dyncall_thunk_arm32_arm.c → dyncall_thunk_arm32.c} +5 -3
- data/dyncall/dyncallback/{dyncall_thunk_arm32_arm.h → dyncall_thunk_arm32.h} +7 -7
- data/dyncall/dyncallback/dyncall_thunk_arm64.c +2 -2
- data/dyncall/dyncallback/dyncall_thunk_arm64.h +8 -13
- data/dyncall/dyncallback/dyncall_thunk_mips.c +16 -20
- data/dyncall/dyncallback/dyncall_thunk_mips.h +4 -2
- data/dyncall/dyncallback/dyncall_thunk_mips64.c +103 -0
- data/dyncall/dyncallback/{dyncall_callback_arm32_thumb.h → dyncall_thunk_mips64.h} +15 -8
- data/dyncall/dyncallback/dyncall_thunk_ppc32.c +4 -4
- data/dyncall/dyncallback/dyncall_thunk_ppc32.h +1 -1
- data/dyncall/dyncallback/dyncall_thunk_ppc32_sysv.c +9 -9
- data/dyncall/dyncallback/dyncall_thunk_ppc64.c +2 -2
- data/dyncall/dyncallback/dyncall_thunk_sparc32.c +19 -2
- data/dyncall/dyncallback/dyncall_thunk_sparc32.h +5 -4
- data/dyncall/dyncallback/dyncall_thunk_sparc64.c +42 -2
- data/dyncall/dyncallback/dyncall_thunk_sparc64.h +5 -5
- data/dyncall/dyncallback/dyncall_thunk_x64.c +1 -1
- data/dyncall/dyncallback/dyncall_thunk_x64.h +2 -2
- data/dyncall/dyncallback/dyncall_thunk_x86.c +1 -1
- data/dyncall/dyncallback/dyncall_thunk_x86.h +2 -2
- data/dyncall/dyncallback/dyncallback.3 +16 -11
- data/dyncall/dynload/dynload.3 +63 -8
- data/dyncall/dynload/dynload.c +2 -8
- data/dyncall/dynload/dynload.h +9 -5
- data/dyncall/dynload/dynload_alloc.h +1 -1
- data/dyncall/dynload/dynload_syms.c +1 -3
- data/dyncall/dynload/dynload_syms_elf.c +19 -11
- data/dyncall/dynload/dynload_syms_mach-o.c +151 -75
- data/dyncall/dynload/dynload_syms_pe.c +24 -24
- data/dyncall/dynload/dynload_unix.c +156 -13
- data/dyncall/dynload/dynload_windows.c +15 -11
- data/dyncall/portasm/portasm-arm.S +1 -1
- data/dyncall/portasm/portasm-ppc.S +1 -1
- data/dyncall/portasm/{portasm-x64-att.S → portasm-x64.S} +7 -4
- data/dyncall/portasm/portasm-x86.S +4 -2
- data/{dyncall-bindings/ruby/rbdc/extconf.rb → extconf.rb} +4 -4
- data/{dyncall-bindings/ruby/rbdc/rbdc.c → rbdc.c} +5 -5
- metadata +24 -48
- data/dyncall/Makefile.M +0 -15
- data/dyncall/buildsys/dynmake/Makefile.base.M +0 -82
- data/dyncall/buildsys/dynmake/dynmake.bat +0 -2
- data/dyncall/buildsys/dynmake/dynmake.sh +0 -4
- data/dyncall/dynMakefile +0 -4
- data/dyncall/dyncall/Makefile.M +0 -10
- data/dyncall/dyncall/TODO +0 -9
- data/dyncall/dyncall/dynMakefile +0 -4
- data/dyncall/dyncall/dyncall_call_sparc64.S +0 -362
- data/dyncall/dyncall/dyncall_call_sparc_v9.S +0 -222
- data/dyncall/dyncall/dyncall_call_x64-att.S +0 -147
- data/dyncall/dyncall/dyncall_callvm_sparc_v9.c +0 -182
- data/dyncall/dyncall/dyncall_callvm_sparc_v9.h +0 -46
- data/dyncall/dyncallback/Makefile.M +0 -10
- data/dyncall/dyncallback/README.txt +0 -9
- data/dyncall/dyncallback/TODO +0 -4
- data/dyncall/dyncallback/dynMakefile +0 -4
- data/dyncall/dyncallback/dyncall_args_arm32_thumb.c +0 -30
- data/dyncall/dyncallback/dyncall_callback_arm32_arm.h +0 -46
- data/dyncall/dyncallback/dyncall_callback_mips.h +0 -43
- data/dyncall/dyncallback/dyncall_callback_ppc32.h +0 -43
- data/dyncall/dyncallback/dyncall_callback_ppc64.h +0 -56
- data/dyncall/dyncallback/dyncall_callback_sparc32.h +0 -44
- data/dyncall/dyncallback/dyncall_callback_x64.h +0 -45
- data/dyncall/dyncallback/dyncall_callback_x86.h +0 -50
- data/dyncall/dyncallback/dyncall_thunk_arm32_thumb.c +0 -30
- data/dyncall/dyncallback/dyncall_thunk_arm32_thumb.h +0 -36
- data/dyncall/dynload/Makefile.M +0 -10
- data/dyncall/dynload/TODO +0 -20
- data/dyncall/dynload/dynMakefile +0 -4
- data/dyncall/dynload/dynload_darwin.c +0 -90
data/dyncall/dynload/dynload.h
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
Description: public header for library dynload
|
7
7
|
License:
|
8
8
|
|
9
|
-
Copyright (c) 2007-
|
9
|
+
Copyright (c) 2007-2018 Daniel Adler <dadler@uni-goettingen.de>,
|
10
10
|
Tassilo Philipp <tphilipp@potion-studios.com>
|
11
11
|
|
12
12
|
Permission to use, copy, modify, and distribute this software for any
|
@@ -36,17 +36,21 @@ extern "C" {
|
|
36
36
|
#define DL_API
|
37
37
|
#endif
|
38
38
|
|
39
|
-
/* --- public api ---------------------------------------------------------- */
|
40
39
|
|
41
40
|
/* shared library loading and explicit symbol resolving */
|
41
|
+
/* dlLoadLibrary will search for specified lib (e.g. as leaf name, only), */
|
42
|
+
/* to the platforms dynamic linking style */
|
42
43
|
|
43
44
|
typedef struct DLLib_ DLLib;
|
44
45
|
|
45
|
-
DL_API DLLib* dlLoadLibrary(const char*
|
46
|
-
DL_API void dlFreeLibrary(DLLib* pLib);
|
47
|
-
DL_API void* dlFindSymbol(DLLib* pLib, const char* pSymbolName);
|
46
|
+
DL_API DLLib* dlLoadLibrary (const char* libPath);
|
47
|
+
DL_API void dlFreeLibrary (DLLib* pLib);
|
48
|
+
DL_API void* dlFindSymbol (DLLib* pLib, const char* pSymbolName);
|
49
|
+
DL_API int dlGetLibraryPath(DLLib* pLib, char* sOut, int bufSize);
|
50
|
+
|
48
51
|
|
49
52
|
/* symbol table enumeration - only for symbol lookup, not resolve */
|
53
|
+
/* note that dlSymsInit does not search library paths */
|
50
54
|
|
51
55
|
typedef struct DLSyms_ DLSyms;
|
52
56
|
|
@@ -6,7 +6,7 @@
|
|
6
6
|
Description: heap memory management interface (header only)
|
7
7
|
License:
|
8
8
|
|
9
|
-
Copyright (c) 2007-
|
9
|
+
Copyright (c) 2007-2018 Daniel Adler <dadler@uni-goettingen.de>,
|
10
10
|
Tassilo Philipp <tphilipp@potion-studios.com>
|
11
11
|
|
12
12
|
Permission to use, copy, modify, and distribute this software for any
|
@@ -6,7 +6,7 @@
|
|
6
6
|
Description:
|
7
7
|
License:
|
8
8
|
|
9
|
-
Copyright (c) 2007-
|
9
|
+
Copyright (c) 2007-2018 Daniel Adler <dadler@uni-goettingen.de>,
|
10
10
|
Tassilo Philipp <tphilipp@potion-studios.com>
|
11
11
|
|
12
12
|
Permission to use, copy, modify, and distribute this software for any
|
@@ -33,7 +33,5 @@
|
|
33
33
|
#include "dynload_syms_mach-o.c"
|
34
34
|
#elif defined(ABI_ELF)
|
35
35
|
#include "dynload_syms_elf.c"
|
36
|
-
#else
|
37
|
-
void dummy() { }
|
38
36
|
#endif
|
39
37
|
|
@@ -6,7 +6,7 @@
|
|
6
6
|
Description:
|
7
7
|
License:
|
8
8
|
|
9
|
-
Copyright (c) 2007-
|
9
|
+
Copyright (c) 2007-2018 Daniel Adler <dadler@uni-goettingen.de>,
|
10
10
|
Tassilo Philipp <tphilipp@potion-studios.com>,
|
11
11
|
Olivier Chafik <olivier.chafik@gmail.com>
|
12
12
|
|
@@ -38,6 +38,9 @@
|
|
38
38
|
#if defined(OS_OpenBSD)
|
39
39
|
# include <stdint.h>
|
40
40
|
# include <elf_abi.h>
|
41
|
+
#elif defined(OS_NetBSD)
|
42
|
+
# include <stddef.h>
|
43
|
+
# include <elf.h>
|
41
44
|
#elif defined(OS_SunOS)
|
42
45
|
# include <libelf.h>
|
43
46
|
#elif defined(OS_BeOS)
|
@@ -121,14 +124,21 @@ struct DLSyms_
|
|
121
124
|
DLSyms* dlSymsInit(const char* libPath)
|
122
125
|
{
|
123
126
|
unsigned char* pMem;
|
124
|
-
void* pSectionContent;
|
125
127
|
int i;
|
126
128
|
struct stat st;
|
127
129
|
Elf_Shdr* pS;
|
128
|
-
DLSyms* pSyms
|
130
|
+
DLSyms* pSyms;
|
131
|
+
|
132
|
+
if(stat(libPath, &st) == -1)
|
133
|
+
return NULL;
|
134
|
+
|
135
|
+
i = open(libPath, O_RDONLY);
|
136
|
+
if(i == -1)
|
137
|
+
return NULL;
|
138
|
+
|
139
|
+
pSyms = (DLSyms*)dlAllocMem(sizeof(DLSyms));
|
129
140
|
memset(pSyms, 0, sizeof(DLSyms));
|
130
|
-
pSyms->file =
|
131
|
-
stat(libPath, &st);
|
141
|
+
pSyms->file = i;
|
132
142
|
pSyms->fileSize = st.st_size;
|
133
143
|
pSyms->pElf_Ehdr = (Elf_Ehdr*) mmap((void*) NULL, pSyms->fileSize, PROT_READ, MAP_SHARED, pSyms->file, 0);
|
134
144
|
|
@@ -150,7 +160,7 @@ DLSyms* dlSymsInit(const char* libPath)
|
|
150
160
|
for (i = 1; i < pSyms->pElf_Ehdr->e_shnum; i++)
|
151
161
|
{
|
152
162
|
Elf_Shdr* pSection = &pS[i];
|
153
|
-
pSectionContent = ((char*)pMem) + pSection->sh_offset;
|
163
|
+
void* pSectionContent = ((char*)pMem) + pSection->sh_offset;
|
154
164
|
switch (pSection->sh_type)
|
155
165
|
{
|
156
166
|
case SHT_DYNSYM:
|
@@ -160,7 +170,7 @@ DLSyms* dlSymsInit(const char* libPath)
|
|
160
170
|
}
|
161
171
|
break;
|
162
172
|
case SHT_STRTAB:
|
163
|
-
|
173
|
+
/* Do not trust pSyms->pElf_Ehdr->e_shstrndx! */
|
164
174
|
if (!pSyms->pStrTab) {
|
165
175
|
pSyms->pStrTab = (const char*)pSectionContent;
|
166
176
|
pSyms->strTabSize = pSection->sh_size;
|
@@ -186,9 +196,7 @@ void dlSymsCleanup(DLSyms* pSyms)
|
|
186
196
|
|
187
197
|
int dlSymsCount(DLSyms* pSyms)
|
188
198
|
{
|
189
|
-
|
190
|
-
return 0;
|
191
|
-
return pSyms->nSymbols;
|
199
|
+
return pSyms ? pSyms->nSymbols : 0;
|
192
200
|
}
|
193
201
|
|
194
202
|
|
@@ -197,7 +205,7 @@ const char* dlSymsName(DLSyms* pSyms, int index)
|
|
197
205
|
int str_index;
|
198
206
|
if(!pSyms || !pSyms->pSymTab || index < 0 || index >= pSyms->nSymbols)
|
199
207
|
return NULL;
|
200
|
-
|
208
|
+
|
201
209
|
str_index = pSyms->pSymTab[index].st_name;
|
202
210
|
if (str_index < 0 || str_index >= pSyms->strTabSize)
|
203
211
|
return NULL;
|
@@ -3,10 +3,12 @@
|
|
3
3
|
Package: dyncall
|
4
4
|
Library: dynload
|
5
5
|
File: dynload/dynload_syms_mach-o.c
|
6
|
-
Description:
|
6
|
+
Description:
|
7
7
|
License:
|
8
8
|
|
9
|
-
Copyright (c) 2007-2015 Olivier Chafik <olivier.chafik@gmail.com
|
9
|
+
Copyright (c) 2007-2015 Olivier Chafik <olivier.chafik@gmail.com>,
|
10
|
+
2017-2018 refactored completely for stability, API
|
11
|
+
consistency and portability by Tassilo Philipp.
|
10
12
|
|
11
13
|
Permission to use, copy, modify, and distribute this software for any
|
12
14
|
purpose with or without fee is hereby granted, provided that the above
|
@@ -25,136 +27,209 @@
|
|
25
27
|
|
26
28
|
|
27
29
|
/*
|
28
|
-
|
30
|
+
|
29
31
|
dynamic symbol resolver for Mach-O
|
30
32
|
|
31
33
|
*/
|
32
34
|
|
33
35
|
#include "dynload.h"
|
34
36
|
#include "dynload_alloc.h"
|
37
|
+
#include "../autovar/autovar_ARCH.h"
|
38
|
+
#include "../autovar/autovar_OS.h"
|
35
39
|
|
36
40
|
#include <mach-o/dyld.h>
|
37
41
|
#include <mach-o/nlist.h>
|
42
|
+
#include <sys/stat.h>
|
38
43
|
#include <dlfcn.h>
|
39
44
|
#include <string.h>
|
40
45
|
|
41
|
-
#if defined(ARCH_X64)
|
46
|
+
#if defined(ARCH_X64) || defined(ARCH_PPC64) || defined(ARCH_ARM64) /*@@@ use dyncall_macros.h*/
|
42
47
|
#define MACH_HEADER_TYPE mach_header_64
|
48
|
+
#define MACH_HEADER_MAGIC_NR MH_MAGIC_64
|
49
|
+
#define SEGMEND_COMMAND_ID LC_SEGMENT_64
|
43
50
|
#define SEGMENT_COMMAND segment_command_64
|
44
51
|
#define NLIST_TYPE nlist_64
|
45
52
|
#else
|
46
53
|
#define MACH_HEADER_TYPE mach_header
|
54
|
+
#define MACH_HEADER_MAGIC_NR MH_MAGIC
|
55
|
+
#define SEGMEND_COMMAND_ID LC_SEGMENT
|
47
56
|
#define SEGMENT_COMMAND segment_command
|
48
57
|
#define NLIST_TYPE nlist
|
49
58
|
#endif
|
50
59
|
|
51
60
|
|
52
|
-
struct DLLib_
|
53
|
-
{
|
54
|
-
char* libPath;
|
55
|
-
void* handle;
|
56
|
-
};
|
57
|
-
|
58
|
-
|
59
61
|
struct DLSyms_
|
60
62
|
{
|
61
|
-
|
63
|
+
DLLib* pLib;
|
64
|
+
const char* pStringTable;
|
62
65
|
const struct NLIST_TYPE* pSymbolTable;
|
63
|
-
uint32_t
|
66
|
+
uint32_t symbolCount;
|
67
|
+
uintptr_t symOffset;
|
64
68
|
};
|
65
69
|
|
66
70
|
|
67
|
-
DLSyms* dlSymsInit(const char* libPath)
|
71
|
+
DLSyms* dlSymsInit(const char* libPath)
|
68
72
|
{
|
73
|
+
DLLib* pLib;
|
69
74
|
DLSyms* pSyms = NULL;
|
70
|
-
uint32_t
|
71
|
-
|
75
|
+
uint32_t i, n;
|
76
|
+
struct stat st0;
|
77
|
+
const struct MACH_HEADER_TYPE* pHeader = NULL;
|
78
|
+
const struct dysymtab_command* dysymtab_cmd = NULL;
|
79
|
+
|
80
|
+
if(stat(libPath, &st0) == -1)
|
81
|
+
return NULL;
|
82
|
+
|
83
|
+
pLib = dlLoadLibrary(libPath);
|
84
|
+
if(!pLib)
|
85
|
+
return NULL;
|
86
|
+
|
87
|
+
/* Loop over all dynamically linked images to find ours. */
|
88
|
+
for(i = 0, n = _dyld_image_count(); i < n; ++i)
|
72
89
|
{
|
73
|
-
|
74
|
-
|
90
|
+
struct stat st1;
|
91
|
+
const char* name = _dyld_get_image_name(i);
|
92
|
+
|
93
|
+
if(name && (stat(name, &st1) != -1))
|
75
94
|
{
|
76
|
-
|
77
|
-
|
78
|
-
if (
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
95
|
+
/* Don't rely on name comparison alone, as libPath might be relative, symlink, differently */
|
96
|
+
/* cased, etc., but compare inode number with the one of the mapped dyld image. */
|
97
|
+
if(st0.st_ino == st1.st_ino/*!strcmp(name, libPath)*/)
|
98
|
+
{
|
99
|
+
pHeader = (const struct MACH_HEADER_TYPE*) _dyld_get_image_header(i);
|
100
|
+
//@@@ slide = _dyld_get_image_vmaddr_slide(i);
|
101
|
+
break; /* found header */
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
if(pHeader && (pHeader->magic == MACH_HEADER_MAGIC_NR) && (pHeader->filetype == MH_DYLIB)/*@@@ ignore for now, seems to work without it on El Capitan && !(pHeader->flags & MH_SPLIT_SEGS)*/)
|
107
|
+
{
|
108
|
+
const char* pBase = (const char*)pHeader;
|
109
|
+
uintptr_t slide = 0, symOffset = 0;
|
110
|
+
const struct load_command* cmd = (const struct load_command*)(pBase + sizeof(struct MACH_HEADER_TYPE));
|
111
|
+
|
112
|
+
for(i = 0, n = pHeader->ncmds; i < n; ++i, cmd = (const struct load_command*)((const char*)cmd + cmd->cmdsize))
|
113
|
+
{
|
114
|
+
if(cmd->cmd == SEGMEND_COMMAND_ID)
|
115
|
+
{
|
116
|
+
const struct SEGMENT_COMMAND* seg = (struct SEGMENT_COMMAND*)cmd;
|
117
|
+
/*@@@ unsure why I used this instead of checking __TEXT: if((seg->fileoff == 0) && (seg->filesize != 0))*/
|
118
|
+
if(strcmp(seg->segname, "__TEXT") == 0)
|
119
|
+
slide = (uintptr_t)pHeader - seg->vmaddr; /* effective offset of segment from header */
|
120
|
+
|
121
|
+
/* If we have __LINKEDIT segment (= raw data for dynamic linkers), use that one to find symbal table address. */
|
122
|
+
if(strcmp(seg->segname, "__LINKEDIT") == 0) {
|
123
|
+
/* Recompute pBase relative to where __LINKEDIT segment is in memory. */
|
124
|
+
pBase = (const char*)(seg->vmaddr - seg->fileoff) + slide;
|
125
|
+
|
126
|
+
/*@@@ we might want to also check maxprot and initprot here:
|
127
|
+
VM_PROT_READ ((vm_prot_t) 0x01)
|
128
|
+
VM_PROT_WRITE ((vm_prot_t) 0x02)
|
129
|
+
VM_PROT_EXECUTE ((vm_prot_t) 0x04)*/
|
130
|
+
|
131
|
+
symOffset = slide; /* this is also offset of symbols */
|
132
|
+
}
|
133
|
+
}
|
134
|
+
else if(cmd->cmd == LC_SYMTAB && !pSyms/* only init once - just safety check */)
|
135
|
+
{
|
136
|
+
const struct symtab_command* scmd = (const struct symtab_command*)cmd;
|
137
|
+
|
138
|
+
/* cmd->cmdsize must be size of struct, otherwise something is off; abort */
|
139
|
+
if(cmd->cmdsize != sizeof(struct symtab_command))
|
140
|
+
break;
|
141
|
+
|
142
|
+
pSyms = (DLSyms*)dlAllocMem(sizeof(DLSyms));
|
143
|
+
pSyms->symbolCount = scmd->nsyms;
|
144
|
+
pSyms->pStringTable = pBase + scmd->stroff;
|
145
|
+
pSyms->pSymbolTable = (struct NLIST_TYPE*)(pBase + scmd->symoff);
|
146
|
+
pSyms->symOffset = symOffset;
|
147
|
+
pSyms->pLib = pLib;
|
148
|
+
}
|
149
|
+
else if(cmd->cmd == LC_DYSYMTAB && !dysymtab_cmd/* only init once - just safety check */)
|
84
150
|
{
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
{
|
90
|
-
if (cmd->cmd == LC_SYMTAB)
|
91
|
-
{
|
92
|
-
const struct symtab_command* scmd = (const struct symtab_command*)cmd;
|
93
|
-
|
94
|
-
pSyms = (DLSyms*)( dlAllocMem(sizeof(DLSyms)) );
|
95
|
-
pSyms->symbolCount = scmd->nsyms;
|
96
|
-
pSyms->pStringTable = pBase + scmd->stroff;
|
97
|
-
pSyms->pSymbolTable = (struct NLIST_TYPE*)(pBase + scmd->symoff);
|
98
|
-
|
99
|
-
return pSyms;
|
100
|
-
}
|
101
|
-
cmd = (const struct load_command*)(((char*)cmd) + cmd->cmdsize);
|
151
|
+
/* @@@ unused, we'll always run over all symbols, and not check locals, globals, etc.
|
152
|
+
if(cmd->cmdsize != sizeof(struct symtab_command)) {
|
153
|
+
dlSymsCleanup(pSyms);
|
154
|
+
break;
|
102
155
|
}
|
156
|
+
|
157
|
+
dysymtab_cmd = (const struct dysymtab_command*)cmd;*/
|
103
158
|
}
|
104
|
-
break;
|
105
159
|
}
|
106
160
|
}
|
161
|
+
|
162
|
+
/* Got symbol table? */
|
163
|
+
if(pSyms) {
|
164
|
+
/* Alter symtable info if we got symbols organized in local/defined/undefined groups. */
|
165
|
+
/* Only use local ones in that case. */
|
166
|
+
/*@@@ don't restrict to only local symbols if(dysymtab_cmd) {
|
167
|
+
pSyms->pSymbolTable += dysymtab_cmd->ilocalsym;
|
168
|
+
pSyms->symbolCount = dysymtab_cmd->nlocalsym;
|
169
|
+
}*/
|
170
|
+
return pSyms;
|
171
|
+
}
|
172
|
+
|
173
|
+
/* Couldn't init syms, so free lib and return error. */
|
174
|
+
dlFreeLibrary(pLib);
|
107
175
|
return NULL;
|
108
176
|
}
|
109
177
|
|
110
178
|
|
111
179
|
void dlSymsCleanup(DLSyms* pSyms)
|
112
180
|
{
|
113
|
-
if
|
114
|
-
|
115
|
-
|
116
|
-
|
181
|
+
if(pSyms) {
|
182
|
+
dlFreeLibrary(pSyms->pLib);
|
183
|
+
dlFreeMem(pSyms);
|
184
|
+
}
|
117
185
|
}
|
118
186
|
|
119
187
|
int dlSymsCount(DLSyms* pSyms)
|
120
188
|
{
|
121
|
-
|
122
|
-
return 0;
|
123
|
-
return pSyms->symbolCount;
|
189
|
+
return pSyms ? pSyms->symbolCount : 0;
|
124
190
|
}
|
125
191
|
|
126
|
-
|
192
|
+
|
193
|
+
const char* dlSymsName(DLSyms* pSyms, int index)
|
127
194
|
{
|
128
195
|
const struct NLIST_TYPE* nl;
|
129
|
-
|
196
|
+
unsigned char t;
|
197
|
+
|
198
|
+
if(!pSyms)
|
130
199
|
return NULL;
|
131
|
-
|
200
|
+
|
132
201
|
nl = pSyms->pSymbolTable + index;
|
133
|
-
|
134
|
-
return NULL; // would be empty string anyway
|
135
|
-
|
136
|
-
//TODO skip more symbols based on nl->n_desc and nl->n_type ?
|
137
|
-
return nl;
|
138
|
-
}
|
202
|
+
t = nl->n_type & N_TYPE;
|
139
203
|
|
204
|
+
/* Return name by lookup through it's address. This guarantees to be consistent with dlsym and dladdr */
|
205
|
+
/* calls as used in dlFindAddress and dlSymsNameFromValue - the "#if 0"-ed code below returns the */
|
206
|
+
/* name directly, but assumes wrongly that everything is prefixed with an underscore on Darwin. */
|
140
207
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
if (!nl)
|
145
|
-
return NULL;
|
146
|
-
|
147
|
-
return pSyms->pStringTable + nl->n_un.n_strx;
|
148
|
-
}
|
208
|
+
/* only handle symbols that are in a section and aren't symbolic debug entries */
|
209
|
+
if((t == N_SECT) && (nl->n_type & N_STAB) == 0)
|
210
|
+
return dlSymsNameFromValue(pSyms, (void*)(nl->n_value + pSyms->symOffset));
|
149
211
|
|
212
|
+
return NULL; /* @@@ handle N_INDR, etc.? */
|
150
213
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
if
|
214
|
+
#if 0
|
215
|
+
/* Mach-O manual: Symbols with an index into the string table of zero */
|
216
|
+
/* (n_un.n_strx == 0) are defined to have a null ("") name. */
|
217
|
+
if(nl->n_un.n_strx == 0)
|
218
|
+
return NULL; /*@@@ have return pointer to some static "" string? */
|
219
|
+
|
220
|
+
/* Skip undefined symbols. @@@ should we? */
|
221
|
+
if(t == N_UNDF || t == N_PBUD) /* @@@ check if N_PBUD is defined, it's not in the NeXT manual, but on Darwin 8.0.1 */
|
155
222
|
return NULL;
|
156
|
-
|
157
|
-
|
223
|
+
|
224
|
+
/*TODO skip more symbols based on nl->n_desc and nl->n_type ? */
|
225
|
+
|
226
|
+
/* Return name - handles lookup of indirect names. */
|
227
|
+
return &pSyms->pStringTable[(t == N_INDR ? nl->n_value : nl->n_un.n_strx)
|
228
|
+
#if defined(OS_Darwin)
|
229
|
+
+ 1 /* Skip '_'-prefix */
|
230
|
+
#endif
|
231
|
+
];
|
232
|
+
#endif
|
158
233
|
}
|
159
234
|
|
160
235
|
|
@@ -163,6 +238,7 @@ const char* dlSymsNameFromValue(DLSyms* pSyms, void* value)
|
|
163
238
|
Dl_info info;
|
164
239
|
if (!dladdr(value, &info) || (value != info.dli_saddr))
|
165
240
|
return NULL;
|
166
|
-
|
241
|
+
|
167
242
|
return info.dli_sname;
|
168
243
|
}
|
244
|
+
|
@@ -6,7 +6,7 @@
|
|
6
6
|
Description:
|
7
7
|
License:
|
8
8
|
|
9
|
-
Copyright (c) 2007-
|
9
|
+
Copyright (c) 2007-2018 Daniel Adler <dadler@uni-goettingen.de>,
|
10
10
|
Tassilo Philipp <tphilipp@potion-studios.com>
|
11
11
|
Olivier Chafik <olivier.chafik@gmail.com>
|
12
12
|
|
@@ -31,12 +31,6 @@
|
|
31
31
|
|
32
32
|
#include <windows.h>
|
33
33
|
|
34
|
-
struct DLLib_
|
35
|
-
{
|
36
|
-
IMAGE_DOS_HEADER dos_header;
|
37
|
-
};
|
38
|
-
|
39
|
-
|
40
34
|
struct DLSyms_
|
41
35
|
{
|
42
36
|
DLLib* pLib;
|
@@ -50,14 +44,25 @@ struct DLSyms_
|
|
50
44
|
|
51
45
|
DLSyms* dlSymsInit(const char* libPath)
|
52
46
|
{
|
53
|
-
DLLib*
|
54
|
-
DLSyms*
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
47
|
+
DLLib* pLib;
|
48
|
+
DLSyms* pSyms;
|
49
|
+
IMAGE_DOS_HEADER* pDOSHeader;
|
50
|
+
IMAGE_NT_HEADERS* pNTHeader;
|
51
|
+
IMAGE_DATA_DIRECTORY* pExportsDataDir;
|
52
|
+
IMAGE_EXPORT_DIRECTORY* pExports;
|
53
|
+
const char* base;
|
54
|
+
|
55
|
+
pLib = dlLoadLibrary(libPath);
|
56
|
+
if(!pLib)
|
57
|
+
return NULL;
|
58
|
+
|
59
|
+
base = (const char*)pLib;
|
60
|
+
pDOSHeader = (IMAGE_DOS_HEADER*)base;
|
61
|
+
pNTHeader = (IMAGE_NT_HEADERS*)(base + pDOSHeader->e_lfanew);
|
62
|
+
pExportsDataDir = &pNTHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT];
|
63
|
+
pExports = (IMAGE_EXPORT_DIRECTORY*)(base + pExportsDataDir->VirtualAddress);
|
64
|
+
|
65
|
+
pSyms = (DLSyms*)dlAllocMem(sizeof(DLSyms));
|
61
66
|
pSyms->pBase = base;
|
62
67
|
pSyms->pNames = (DWORD*)(base + pExports->AddressOfNames);
|
63
68
|
pSyms->pFuncs = (DWORD*)(base + pExports->AddressOfFunctions);
|
@@ -86,25 +91,20 @@ int dlSymsCount(DLSyms* pSyms)
|
|
86
91
|
|
87
92
|
const char* dlSymsName(DLSyms* pSyms, int index)
|
88
93
|
{
|
89
|
-
return
|
94
|
+
return pSyms->pBase + pSyms->pNames[index];
|
90
95
|
}
|
91
96
|
|
92
97
|
|
93
|
-
|
94
|
-
{
|
95
|
-
return (void*)(pSyms->pBase + pSyms->pFuncs[pSyms->pOrds[index]]);
|
96
|
-
}
|
97
|
-
|
98
|
-
|
99
|
-
const char* dlSymsNameFromValue(DLSyms* pSyms, void* value)
|
98
|
+
const char* dlSymsNameFromValue(DLSyms* pSyms, void* value)
|
100
99
|
{
|
101
100
|
int i, c=dlSymsCount(pSyms);
|
102
101
|
for(i=0; i<c; ++i)
|
103
102
|
{
|
104
|
-
if(
|
103
|
+
if((void*)(pSyms->pBase + pSyms->pFuncs[pSyms->pOrds[i]]) == value)
|
105
104
|
return dlSymsName(pSyms, i);
|
106
105
|
}
|
107
106
|
|
108
107
|
/* Not found. */
|
109
108
|
return NULL;
|
110
109
|
}
|
110
|
+
|