我查看了 libc.dylib 和 xlib.dylib 的十六进制转储,但在这些文件中找不到这些库中 C 函数的符号。
我认为它们应该在那里,因为我已经完成了可执行文件的十六进制转储,并且变量和函数的符号以纯文本形式存储在符号表中。
当然,这是我现在正在处理的可链接目标文件,但我想知道如果符号不在目标文件中,如何链接到这些库中的符号。
答案1
正如您在 MacOS High Sierra 中看到的:
$ ls -la libc.dylib
lrwxr-xr-x 1 root wheel 15 25 Nov 01:32 libc.dylib -> libSystem.dylib
libc.dylib
是到 的符号链接libSystem.dylib
。
当尝试显示 的内容时libSystem.dylib
,您不会看到很多字符,因为根据您使用strings
或 的cat
情况,您会过早地发现无法打印的字符或文件结尾字符。
要理解这一点,请参阅以下输出strings
:
$ strings /usr/lib/libSystem.dylib
executable_path=
@(#)PROGRAM:System.B PROJECT:Libsystem-1252.50.4
libSystem.dylib
然而,它是多个链接在一起的库的缓存。
libc.dylib
高山的选择:
$ otool -L /usr/lib/libSystem.dylib
libSystem.dylib:
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.50.4)
/usr/lib/system/libcache.dylib (compatibility version 1.0.0, current version 80.0.0)
/usr/lib/system/libcommonCrypto.dylib (compatibility version 1.0.0, current version 60118.50.1)
/usr/lib/system/libcompiler_rt.dylib (compatibility version 1.0.0, current version 62.0.0)
/usr/lib/system/libcopyfile.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/system/libcorecrypto.dylib (compatibility version 1.0.0, current version 562.50.17)
/usr/lib/system/libdispatch.dylib (compatibility version 1.0.0, current version 913.50.12)
/usr/lib/system/libdyld.dylib (compatibility version 1.0.0, current version 551.3.0)
/usr/lib/system/libkeymgr.dylib (compatibility version 1.0.0, current version 28.0.0)
/usr/lib/system/liblaunch.dylib (compatibility version 1.0.0, current version 1205.50.76)
/usr/lib/system/libmacho.dylib (compatibility version 1.0.0, current version 906.0.0)
/usr/lib/system/libquarantine.dylib (compatibility version 1.0.0, current version 86.0.0)
/usr/lib/system/libremovefile.dylib (compatibility version 1.0.0, current version 45.0.0)
/usr/lib/system/libsystem_asl.dylib (compatibility version 1.0.0, current version 356.50.1)
/usr/lib/system/libsystem_blocks.dylib (compatibility version 1.0.0, current version 67.0.0)
/usr/lib/system/libsystem_c.dylib (compatibility version 1.0.0, current version 1244.50.9)
/usr/lib/system/libsystem_configuration.dylib (compatibility version 1.0.0, current version 963.50.8)
/usr/lib/system/libsystem_coreservices.dylib (compatibility version 1.0.0, current version 51.0.0)
/usr/lib/system/libsystem_darwin.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/system/libsystem_dnssd.dylib (compatibility version 1.0.0, current version 878.50.17)
/usr/lib/system/libsystem_info.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/system/libsystem_m.dylib (compatibility version 1.0.0, current version 3147.50.1)
/usr/lib/system/libsystem_malloc.dylib (compatibility version 1.0.0, current version 140.50.6)
/usr/lib/system/libsystem_network.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/system/libsystem_networkextension.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/system/libsystem_notify.dylib (compatibility version 1.0.0, current version 172.0.0)
/usr/lib/system/libsystem_sandbox.dylib (compatibility version 1.0.0, current version 765.50.51)
/usr/lib/system/libsystem_secinit.dylib (compatibility version 1.0.0, current version 30.0.0)
/usr/lib/system/libsystem_kernel.dylib (compatibility version 1.0.0, current version 4570.51.2)
/usr/lib/system/libsystem_platform.dylib (compatibility version 1.0.0, current version 161.50.1)
/usr/lib/system/libsystem_pthread.dylib (compatibility version 1.0.0, current version 301.50.1)
/usr/lib/system/libsystem_symptoms.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/system/libsystem_trace.dylib (compatibility version 1.0.0, current version 829.50.17)
/usr/lib/system/libunwind.dylib (compatibility version 1.0.0, current version 35.3.0)
/usr/lib/system/libxpc.dylib (compatibility version 1.0.0, current version 1205.50.76)
同样正确的是@ajeh 也建议:
$ nm /usr/lib/libSystem.dylib
0000000000001a6a T R8289209$_close
0000000000001a6f T R8289209$_fork
0000000000001a74 T R8289209$_fsync
0000000000001a79 T R8289209$_getattrlist
0000000000001a7e T R8289209$_getrlimit
0000000000001a83 T R8289209$_getxattr
0000000000001a88 T R8289209$_open
0000000000001a8d T R8289209$_pthread_attr_destroy
0000000000001a92 T R8289209$_pthread_attr_init
0000000000001a97 T R8289209$_pthread_attr_setdetachstate
0000000000001a9c T R8289209$_pthread_create
0000000000001aa1 T R8289209$_pthread_mutex_lock
0000000000001aa6 T R8289209$_pthread_mutex_unlock
0000000000001aab T R8289209$_pthread_self
0000000000001ab0 T R8289209$_ptrace
0000000000001ab5 T R8289209$_read
0000000000001aba T R8289209$_setattrlist
0000000000001abf T R8289209$_setrlimit
0000000000001ac4 T R8289209$_sigaction
0000000000001ac9 T R8289209$_stat
0000000000001ace T R8289209$_sysctl
0000000000001ad3 T R8289209$_time
0000000000001ad8 T R8289209$_unlink
0000000000001add T R8289209$_write
0000000000001f98 S ___System_BVersionNumber
0000000000001f60 S ___System_BVersionString
00000000000022d0 S ___crashreporter_info__
U ___error
U ___keymgr_initializer
U ___libdarwin_init
U ___libkernel_init
U ___libplatform_init
U ___malloc_init
U ___pthread_init
U ___stack_logging_early_finished
U __asl_fork_child
U __dirhelper
U __dyld_fork_child
U __dyld_initializer
U __libSC_info_fork_child
U __libSC_info_fork_parent
U __libSC_info_fork_prepare
U __libc_fork_child
U __libc_initializer
U __libcoreservices_fork_child
U __libsecinit_initializer
U __libtrace_fork_child
U __libtrace_init
U __libxpc_initializer
U __mach_fork_child
U __malloc_fork_child
U __malloc_fork_parent
U __malloc_fork_prepare
U __notify_fork_child
U __pthread_atfork_child
U __pthread_atfork_child_handlers
U __pthread_atfork_parent
U __pthread_atfork_parent_handlers
U __pthread_atfork_prepare
U __pthread_atfork_prepare_handlers
U __pthread_clear_qos_tsd
U __pthread_exit_if_canceled
U _close
U _dispatch_atfork_child
U _dispatch_atfork_parent
U _dispatch_atfork_prepare
U _dlsym
U _dyld_get_program_sdk_version
U _exit
U _fork
U _free
U _fsync
U _getattrlist
U _getrlimit
U _getxattr
0000000000001ae2 T _libSystem_atfork_child
0000000000001a47 T _libSystem_atfork_parent
0000000000001a22 T _libSystem_atfork_prepare
000000000000194a t _libSystem_initializer
00000000000022a0 s _libSystem_initializer.libc_funcs
0000000000002220 s _libSystem_initializer.libkernel_funcs
0000000000002280 s _libSystem_initializer.libpthread_funcs
U _libdispatch_init
0000000000001b28 t _mach_init_old
00000000000022c8 D _mach_init_routine
U _malloc
U _open
U _pthread_attr_destroy
U _pthread_attr_init
U _pthread_attr_setdetachstate
U _pthread_create
U _pthread_mutex_lock
U _pthread_mutex_unlock
U _pthread_self
U _ptrace
U _read
U _realloc
U _setattrlist
U _setrlimit
U _sigaction
U _stat
U _strncmp
U _sysctl
U _time
U _unlink
U _write
U _xpc_atfork_child
U _xpc_atfork_parent
U _xpc_atfork_prepare
U dyld_stub_binder
然而,纯nm
inlibSystem.dylib
将显示符号所有包含的库集中在一起。
像这个 bash 脚本一样,一一进行可能会更有趣:
#!/bin/bash
for i in `otool -L /usr/lib/libSystem.dylib | sed "1d" | awk ' { print $1 } '`
do
echo $i
echo "======="
nm $i
echo
done
或者作为一件内衬:
for i in `otool -L /usr/lib/libSystem.dylib | sed "1d" | awk ' { print $1 } '`; do echo $i; echo "=======" ; nm $i ; echo ; done
至于十六进制转储,因为您还没有向我们展示它,所以我假设您对 16 位输出感到困惑(我认为)。
要查看一些字符串转储,请尝试:
$ od -tc /usr/lib/libSystem.dylib | tr -d " " | grep -v "\\\\" | sed 's/^[0-9]*//g' | less
*
*
/usr/lib/libSyst
/system/libcache
/usr/lib/system/
libcommonCrypto.
/usr/lib/system/
libcompiler_rt.d
/usr/lib/system/
libcopyfile.dyli
/usr/lib/system/
libcorecrypto.dy
/usr/lib/system/
libdispatch.dyli
/usr/lib/system/
/system/libkeymg
/usr/lib/system/
/system/libmacho
/usr/lib/system/
libquarantine.dy
/usr/lib/system/
libremovefile.dy
/usr/lib/system/
libsystem_asl.dy
/usr/lib/system/
libsystem_blocks
/usr/lib/system/
libsystem_c.dyli
/usr/lib/system/
libsystem_config
/system/libsyste
m_coreservices.d
/usr/lib/system/
libsystem_darwin
/usr/lib/system/
libsystem_dnssd.
/usr/lib/system/
libsystem_info.d
/usr/lib/system/
libsystem_m.dyli
/usr/lib/system/
libsystem_malloc
/usr/lib/system/
libsystem_networ
/usr/lib/system/
libsystem_networ
kextension.dylib
/usr/lib/system/
libsystem_notify
/usr/lib/system/
libsystem_sandbo
/usr/lib/system/
libsystem_secini
/usr/lib/system/
libsystem_kernel
/usr/lib/system/
libsystem_platfo
/system/libsyste
/system/libsyste
m_symptoms.dylib
/usr/lib/system/
libsystem_trace.
/usr/lib/system/
/system/libxpc.d
*
AVSPM211306I211317H211323H215=
@(#)PROGRAM:Syst
em.BPROJECT:Li
bsystem-1252.50.
*
*
A__pthread_cl
@__pthre
ad_exit_if_cance
@_reallo
@___keymgr_ini
__libdarwin_init
__libplatform_in
qH0@___stack_log
ging_early_finis
@__dyld_fork_chi
@__libSC_info_f
__libSC_info_for
_libSC_info_fork
__libc_fork_chil
@__libcoreserv
@__libtrace_i
__malloc_fork_ch
@__notify_for
_pthread_atfork_
thread_atfork_ch
@__pthread_at
@__pthread_atf
ork_parent_handl
read_atfork_prep
read_atfork_prep
@_dispatch_atfo
_dispatch_atfork
dispatch_atfork_
dyld_get_program
read_attr_destro
@_pthread_attr
thread_mutex_loc
q2000040@_xpc_atfork
pc_atfork_parent
setdetachstate
%025226003006006006006006006006006006
*
%#005005005005005005005005005005
$_pthread
$_pthread_
$_pthread_attr
R8289209$_pthrea
$_pthread_mutex
pthread_mutex_un
$_setattrlis
tem_BVersionNumb
rashreporter_inf
System_atfork_pa
mach_init_routin
ymgr_initializer
_logging_early_f
C_info_fork_chil
SC_info_fork_pre
oreservices_fork
__libtrace_fork_
alloc_fork_child
__pthread_atfork
_atfork_child_ha
_pthread_atfork_
__pthread_atfork
ad_atfork_prepar
read_clear_qos_t
patch_atfork_par
ogram_sdk_versio
hread_attr_destr
ttr_setdetachsta
ystem_initialize
ializer.libkerne
em_initializer.l
_libSystem_initi
alizer.libc_func
u264241247254B346e215364211362i2452q
*
ox343_z;f337cW245ک**jh037
s214220>34703030222027#365*2'
r030y311001352e=213/
I266'|D217362217257I251232330345024)
c244274301N365001006270224:037.202300030
CertificationAu
thority10260024006003U004003
pleCertificatio
nAuthority1301006
SigningCertifi
cationAuthority
kY275Z0332112633473453563169230#59
P266035006304[361]032233Te206s
/b3458275001020drm|iGa234020
&343353205302,$334j302?210374̬**
LSx373337030v2412172442512ʑ**247266
P021210253j355353f040
K254;-357252347326Ɉ**-i¤***
a/ۇ**002363241!271L237016370371331-
r004177035256n372?210263̣**@356027
Q226274317344-255302351YN]034e
'003252g243223$207LJ**y002271]230
ȧ**227201320036#3348231_a376
U0350170010013770040040030020012060023006003
U0350230010013770040050003001
U035016004026004024216i246
wBN004245VB234Q037206332322217
)240'206%http://www.
apple.com/applec
R025j267025030ީ***ѝ**v233036
ZHG3339l200312s336b033267:ʣ**
Z036343207332%J223233357s020223s]364
O377002323016374365363364r0322261047
'016ި**ә**217j346231373a311O362027
yA303356256310kg|314lI206L002323
yڟ**245;037Qb;"361~S
鲷****[R247306325X211r267330̳**
P227?035332j2568277{y1276
c271367205205027351m212304342030224/327o
eCertification
Authority10260024006003U
AppleCertificat
ionAuthority10260
^y204-3536242WLU354213031
M316024i321311031r365]016
#025K025Y035263224367366234236317P272301
C317017235=363+I(032310376
ε**271016331^034326313=265:255364017016
q222GSU301257/A263370373343p315243
A20732122012610X354Z0042214h263
es377g^e274I330v2373024
v0016006003U035017001001377004004003
U0350230010013770040050
U035016004026004024+
.apple.com/apple
Relianceo
nthiscertifica
tebyanyparty
assumesacceptan
ceofthethena
pplicablestanda
rdtermsandcon
ditionsofuse,
certificatepoli
cyandcertifica
tionpracticest
L-x267팛****334363w233362v322w0
O301037205203205033231=G7362251233@216
,Ա**220022330276364s233356322d017313y
o$342353ѷ**p337017E341'312361m
x355347265027027250334~"5312%325331017
k324242$#021367241254217s201`306033
ں**s031O2653316177301207U٧**231271
B373330325q236~241R267033275223B$
*307017035266M234^c310K200027P252
ationAuthority1
CodeSigningCer
tificationAutho
pleInc.10270025006003U004
wareSigning0202001"
`"]323䄢****@A
d306`=221a332R250E'236,d344
**300)270/220o244273e217200j327=h
j'275273210236<?262R9227343267310124
TR230212/#Ve345351*331Q264#372
Glu261261214321023343z301354bAt246
Ztd9?Yn317,300`203
>J373.350?023325240
i246304wBN004245VB234
www.apple.com/ce
rtificateauthori
thiscertificat
ebyanypartya
ssumesacceptanc
eofthethenap
plicablestandar
dtermsandcond
itionsofuse,c
ertificatepolic
yandcertificat
ionpracticesta
tements.05006003U035037004
.0,0*240(240&206$http:
//crl.apple.com/
codesigning.crl0
QN360212I260h224eQ"337375@2175
h@R273%216314372316|022V330300125
U005265J261265a374225|221^r321(264
+m332Kg237005374346347YJC^037
{2047276376272212+3005224P203270376232
b362031mw223343u3176Y1
VKD.230٦**1241360034
f224231Ts023265Q8274$2422400;z
e207254300274025364^0ǝ**243*004337317
G204m237375377Eà**031254<273255217
q6021355350001272264uH202
*S032005005233235306G033365350r240
U004006023002US10230021006003U
ertificationAut
*AppleCodeSign
ingCertificatio
"004f335KoV261HP276246#370i
x[346c207347ϒ**P;301b!/026」
version="1.0"en
coding="UTF-8"?>
PUBLIC"-//Appl
e//DTDPLIST1.0
//EN""http://ww
w.apple.com/DTDs
/PropertyList-1.
Lb1axSFC+piP4aX
_033X243321OU246_231:L3401351A
˥**"235^177031373321A017v^)
m376371`302016`%n201l316031336&
ж**250
c355002225375274273314304ylk314r
d211Jy231V`a245!W,kO227W
(2467213F@Ƒ**352026WH305374301F
Υ**GQ2411Pb217%333|3000312760
d3762127ٕ**214214022u326,`1.
*
/lib/libSystem.B
/usr/lib/system/
/system/libcommo
/system/libcompi
/system/libcopyf
tem/libcorecrypt
/usr/lib/system/
libdispatch.dyli
/lib/system/libd
tem/libkeymgr.dy
/lib/system/libl
tem/libmacho.dyl
/lib/system/libq
/system/libremov
tem/libsystem_as
/usr/lib/system/
libsystem_blocks
/usr/lib/system/
libsystem_c.dyli
/lib/system/libs
ystem_configurat
tem/libsystem_co
reservices.dylib
/lib/system/libs
ystem_darwin.dyl
/lib/system/libs
ystem_dnssd.dyli
/lib/system/libs
ystem_info.dylib
/lib/system/libs
/system/libsyste
/system/libsyste
/system/libsyste
m_networkextensi
tem/libsystem_no
tem/libsystem_sa
tem/libsystem_se
tem/libsystem_ke
tem/libsystem_pl
/system/libsyste
/system/libsyste
m_symptoms.dylib
/lib/system/libs
ystem_trace.dyli
/lib/system/libu
tem/libxpc.dylib
*
RAM:System.BPR
OJECT:Libsystem-
*
*
hread_clear_qos_
@__pthread_exit_
@_ex
@_mall
@dyld_stub
@___libdarwin_
@___libplatfor
@___pthread_ini
_logging_early_f
q80@__libSC_info
<0@__libSC_info_
@0@__libc_fork_c
qH0@__libcoreser
vices_fork_child
@__libtrace_ini
__malloc_fork_pr
t0@__pthread_atf
ork_child_handle
ad_atfork_parent
_atfork_parent_h
_pthread_atfork_
_pthread_atfork_
prepare_handlers
@_dispatch_at
@_dispatch_atf
@_dyld_get_pro
gram_sdk_version
_pthread_attr_de
attr_setdetachst
@_pthread_mutex
hread_mutex_unlo
@_xpc_atfork_pa
ach_init_routine
shreporter_info_
$_pthread
$_pthread_
$_pthread_attr
R8289209$_pthrea
$_pthread_mutex
pthread_mutex_un
$_setattrlis
tem_BVersionNumb
rashreporter_inf
System_atfork_pa
mach_init_routin
ymgr_initializer
_logging_early_f
C_info_fork_chil
SC_info_fork_pre
oreservices_fork
__libtrace_fork_
alloc_fork_child
__pthread_atfork
_atfork_child_ha
_pthread_atfork_
__pthread_atfork
ad_atfork_prepar
read_clear_qos_t
patch_atfork_par
ogram_sdk_versio
hread_attr_destr
ttr_setdetachsta
ystem_initialize
ializer.libkerne
em_initializer.l
_libSystem_initi
alizer.libc_func
u264241247254B346e215364211362i2452q
*
:211$241R214226D257270vMgd
`340203d352237lMo327355003+374311
ɚ**2162521232001.361Dhlgi326277
a375=(033373D|323z2206{ι**
t017251341첕****337234[O2227365{177
i#{}o@H240032353g245375Yۖ
CertificationAu
thority10260024006003U004003
pleCertificatio
nAuthority1301006
SigningCertifi
cationAuthority
kY275Z0332112633473453563169230#59
P266035006304[361]032233Te206s
/b3458275001020drm|iGa234020
&343353205302,$334j302?210374̬**
LSx373337030v2412172442512ʑ**247266
P021210253j355353f040
K254;-357252347326Ɉ**-i¤***
a/ۇ**002363241!271L237016370371331-
r004177035256n372?210263̣**@356027
Q226274317344-255302351YN]034e
'003252g243223$207LJ**y002271]230
ȧ**227201320036#3348231_a376
U0350170010013770040040030020012060023006003
U0350230010013770040050003001
U035016004026004024216i246
wBN004245VB234Q037206332322217
)240'206%http://www.
apple.com/applec
R025j267025030ީ***ѝ**v233036
ZHG3339l200312s336b033267:ʣ**
Z036343207332%J223233357s020223s]364
O377002323016374365363364r0322261047
'016ި**ә**217j346231373a311O362027
yA303356256310kg|314lI206L002323
yڟ**245;037Qb;"361~S
鲷****[R247306325X211r267330̳**
P227?035332j2568277{y1276
c271367205205027351m212304342030224/327o
eCertification
Authority10260024006003U
AppleCertificat
ionAuthority10260
^y204-3536242WLU354213031
M316024i321311031r365]016
#025K025Y035263224367366234236317P272301
C317017235=363+I(032310376
ε**271016331^034326313=265:255364017016
q222GSU301257/A263370373343p315243
A20732122012610X354Z0042214h263
es377g^e274I330v2373024
v0016006003U035017001001377004004003
U0350230010013770040050
U035016004026004024+
.apple.com/apple
Relianceo
nthiscertifica
tebyanyparty
assumesacceptan
ceofthethena
pplicablestanda
rdtermsandcon
ditionsofuse,
certificatepoli
cyandcertifica
tionpracticest
L-x267팛****334363w233362v322w0
O301037205203205033231=G7362251233@216
,Ա**220022330276364s233356322d017313y
o$342353ѷ**p337017E341'312361m
x355347265027027250334~"5312%325331017
k324242$#021367241254217s201`306033
ں**s031O2653316177301207U٧**231271
B373330325q236~241R267033275223B$
*307017035266M234^c310K200027P252
ationAuthority1
CodeSigningCer
tificationAutho
pleInc.10270025006003U004
wareSigning0202001"
`"]323䄢****@A
d306`=221a332R250E'236,d344
**300)270/220o244273e217200j327=h
j'275273210236<?262R9227343267310124
TR230212/#Ve345351*331Q264#372
Glu261261214321023343z301354bAt246
Ztd9?Yn317,300`203
>J373.350?023325240
i246304wBN004245VB234
www.apple.com/ce
rtificateauthori
thiscertificat
ebyanypartya
ssumesacceptanc
eofthethenap
plicablestandar
dtermsandcond
itionsofuse,c
ertificatepolic
yandcertificat
ionpracticesta
tements.05006003U035037004
.0,0*240(240&206$http:
//crl.apple.com/
codesigning.crl0
QN360212I260h224eQ"337375@2175
h@R273%216314372316|022V330300125
U005265J261265a374225|221^r321(264
+m332Kg237005374346347YJC^037
{2047276376272212+3005224P203270376232
b362031mw223343u3176Y1
VKD.230٦**1241360034
f224231Ts023265Q8274$2422400;z
e207254300274025364^0ǝ**243*004337317
G204m237375377Eà**031254<273255217
q6021355350001272264uH202
*S032005005233235306G033365350r240
U004006023002US10230021006003U
ertificationAut
*AppleCodeSign
ingCertificatio
"004W021B277]240020211Q365t230213
e250267300~255)3530043172722636234272
version="1.0"en
coding="UTF-8"?>
PUBLIC"-//Appl
e//DTDPLIST1.0
//EN""http://ww
w.apple.com/DTDs
/PropertyList-1.
FCv12gEIlR9XSYi7
%022361354$:2576340025koX272
_206B353253034263ŗ**221y264255026s
**222260214220g343366240T243ֳ**252AC
CkSI{&375026321370026377
RЕ**001211204360x231g272252317344325%
P335*(023i216na202370
*