Skip to content

Commit 70827df

Browse files
author
Li
committed
Add elfread #1685
Signed-off-by: Li <[email protected]>
1 parent 86a19fc commit 70827df

File tree

49 files changed

+2752
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2752
-1
lines changed

plugins/scancode-lkmclue/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ A ScanCode scan plugin to find lkmclue source info.
33
To start the test case, please run:
44
1. ./configure
55
2. source bin/activate
6-
3. pip install -e plugins/scancode-ctags-manylinux1_x86_64 -e plugins/scancode-lkmclue
6+
3. pip install -e plugins/scancode-ctags-manylinux1_x86_64 -e plugins/scancode-readelf-manylinux1_x86_64 -e plugins/scancode-lkmclue
77
4. pytest -vvs plugins/scancode-lkmclue/tests/test_lkmclue.py
8+
pytest -vvs plugins/scancode-lkmclue/tests/test_elf.py
89

910
Note that in step3, the path depends on your OS versions, please update according to your real os enviroment.

plugins/scancode-lkmclue/setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
entry_points={
5050
'scancode_scan': [
5151
'scancode-lkmclue = lkmclue:LKMClueScanner',
52+
'scancode-elf = elf:ELFScanner',
53+
5254
],
5355
}
5456

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#
2+
# Copyright (c) 2019 nexB Inc. and others. All rights reserved.
3+
# http://nexb.com and https://github.com/nexB/scancode-toolkit/
4+
# The ScanCode software is licensed under the Apache License version 2.0.
5+
# Data generated with ScanCode require an acknowledgment.
6+
# ScanCode is a trademark of nexB Inc.
7+
#
8+
# You may not use this software except in compliance with the License.
9+
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
10+
# Unless required by applicable law or agreed to in writing, software distributed
11+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
13+
# specific language governing permissions and limitations under the License.
14+
#
15+
# When you publish or redistribute any data created with ScanCode or any ScanCode
16+
# derivative work, you must accompany this data with the following acknowledgment:
17+
#
18+
# Generated with ScanCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES
19+
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
20+
# ScanCode should be considered or used as legal advice. Consult an Attorney
21+
# for any legal advice.
22+
# ScanCode is a free software code scanning tool from nexB Inc. and others.
23+
# Visit https://github.com/nexB/scancode-toolkit/ for support and download.
24+
25+
from __future__ import absolute_import
26+
from __future__ import unicode_literals
27+
28+
from collections import OrderedDict
29+
from functools import partial
30+
from itertools import chain
31+
32+
import attr
33+
34+
from commoncode import fileutils
35+
from plugincode.scan import ScanPlugin
36+
from plugincode.scan import scan_impl
37+
from scancode import CommandLineOption
38+
from scancode import SCAN_GROUP
39+
from typecode import contenttype
40+
from elf.elf import Elf
41+
42+
43+
@scan_impl
44+
class ELFScanner(ScanPlugin):
45+
"""
46+
Collect the names of shared objects/libraries needed by an Elf binary file.
47+
"""
48+
resource_attributes = OrderedDict(
49+
elf_needed_library=attr.ib(default=attr.Factory(list), repr=False),
50+
)
51+
52+
options = [
53+
CommandLineOption(('--elf',),
54+
is_flag=True, default=False,
55+
help=' Collect the names of shared objects/libraries needed by an Elf binary file.',
56+
help_group=SCAN_GROUP,
57+
sort_order=100),
58+
]
59+
60+
def is_enabled(self, elf, **kwargs):
61+
return elf
62+
63+
def get_scanner(self, **kwargs):
64+
return get_elf_needed_library
65+
66+
67+
def get_elf_needed_library(location, **kwargs):
68+
"""
69+
Return a list of needed_libraries
70+
"""
71+
72+
T = contenttype.get_type(location)
73+
if not T.is_elf:
74+
return
75+
elfie = elf.Elf(location)
76+
results =[]
77+
for needed_library in elfie.needed_libraries:
78+
results.append(needed_library)
79+
return dict(elf_needed_library=results)

0 commit comments

Comments
 (0)