|
| 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