Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PoroCYon
smol
Commits
9d117fe6
Commit
9d117fe6
authored
Feb 06, 2019
by
PoroCYon
Committed by
PoroCYon
Feb 27, 2019
Browse files
use better defaults for lib search paths
parent
d9a5eac2
Changes
1
Hide whitespace changes
Inline
Side-by-side
smoldd.py
View file @
9d117fe6
...
...
@@ -30,12 +30,25 @@ def readstr(blob, off):
return
text
.
decode
(
'utf-8'
),
off
def
find_libs
(
bits
,
libname
):
dirs
=
os
.
environ
[
'LD_LIBRARY_PATH'
].
split
(
':'
)
dirs
+=
[
'/usr/lib'
,
'/lib'
]
def
get_def_libpaths
(
cc_bin
,
is32bit
):
if
is32bit
:
return
[
'/usr/lib32/'
,
'/lib32/'
]
out
=
subprocess
.
check_output
([
cc_bin
,
'-print-search-dirs'
],
stderr
=
subprocess
.
DEVNULL
)
stuff
=
dict
({})
for
l
in
out
.
decode
(
'utf-8'
).
splitlines
():
blah
=
l
.
split
(
': '
)
stuff
[
blah
[
0
]]
=
blah
[
1
].
lstrip
(
'='
).
split
(
':'
)
return
stuff
[
"libraries"
]
def
find_libs
(
bits
,
deflibs
,
libname
):
dirs
=
os
.
environ
[
'LD_LIBRARY_PATH'
].
split
(
':'
)
+
deflibs
for
d
in
dirs
:
for
f
in
glob
.
glob
(
glob
.
escape
(
d
+
str
(
bits
)
+
'/'
+
libname
)
+
'*'
):
for
f
in
glob
.
glob
(
glob
.
escape
(
d
+
libname
)
+
'*'
):
yield
f
def
build_hashtab
(
scanelf_bin
,
lib
):
...
...
@@ -57,6 +70,8 @@ def main():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'input'
,
type
=
argparse
.
FileType
(
'rb'
),
default
=
sys
.
stdin
.
buffer
,
help
=
"input file"
)
parser
.
add_argument
(
'--cc'
,
default
=
shutil
.
which
(
'cc'
),
help
=
"C compiler binary"
)
parser
.
add_argument
(
'--scanelf'
,
default
=
shutil
.
which
(
'scanelf'
),
help
=
"scanelf binary"
)
...
...
@@ -68,6 +83,8 @@ def main():
is32bit
=
machnum
==
archmagic
[
'i386'
]
deflibs
=
get_def_libpaths
(
args
.
cc
,
is32bit
)
phoff
,
phsz
,
phnum
=
0
,
0
,
0
if
is32bit
:
phoff
=
struct
.
unpack
(
'<I'
,
blob
[
28
:
28
+
4
])[
0
]
...
...
@@ -124,7 +141,7 @@ def main():
sys
.
stdout
.
write
(
"* "
+
libname
)
libs
=
list
(
find_libs
(
32
if
is32bit
else
64
,
libname
))
libs
=
list
(
find_libs
(
(
32
if
is32bit
else
64
),
deflibs
,
libname
))
print
(
" -> NOT FOUND"
if
len
(
libs
)
==
0
else
(
" -> "
+
libs
[
0
]))
ht
=
dict
({})
if
len
(
libs
)
==
0
else
build_hashtab
(
args
.
scanelf
,
libs
[
0
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment