Skip to content

Commit

Permalink
Map checksums and paths in android d2d pipeline #1366
Browse files Browse the repository at this point in the history
Signed-off-by: Jono Yang <[email protected]>
  • Loading branch information
JonoYang committed Sep 9, 2024
1 parent 7b2e308 commit c2228f7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
11 changes: 2 additions & 9 deletions scanpipe/pipelines/android_d2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
# Visit https://github.com/aboutcode-org/scancode.io for support and download.

from aboutcode.pipeline import group
from scanpipe import pipes
from scanpipe.pipelines.deploy_to_develop import DeployToDevelop
from scanpipe.pipes import d2d

Expand Down Expand Up @@ -58,13 +56,8 @@ def steps(cls):
cls.collect_and_create_codebase_resources,
cls.map_checksum,
cls.find_java_packages,
cls.map_java_to_class,
cls.map_jar_to_source,
cls.flag_mapped_resources_archives_and_ignored_directories,
cls.remove_packages_without_resources,
cls.flag_deployed_from_resources_with_missing_license,
cls.create_local_files_packages,
cls.map_path,
)

def convert_dex_to_java(self):
d2d.convert_dex_to_java(self.project)
d2d.convert_dex_to_java(self.project, to_only=True)
25 changes: 13 additions & 12 deletions scanpipe/pipes/d2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
from collections import defaultdict
from contextlib import suppress
from dataclasses import dataclass
from os.path import abspath
from os.path import expanduser
from os.path import join
from pathlib import Path
from re import match as regex_match

Expand All @@ -37,12 +40,8 @@
from django.db.models.functions import Concat
from django.template.defaultfilters import pluralize

from os.path import abspath
from os.path import expanduser
from os.path import join
from commoncode import fileutils
from commoncode.fileutils import file_name
from commoncode import command
from commoncode import fileutils
from commoncode.paths import common_prefix
from elf_inspector.dwarf import get_dwarf_paths
from extractcode import EXTRACT_SUFFIX
Expand Down Expand Up @@ -1894,12 +1893,17 @@ def map_go_paths(project, logger=None):
)


def convert_dex_to_java(project):
def convert_dex_to_java(project, to_only=False):
"""
Decompile .dex files in `project` into Java source code using `jadx`. If
`to_only` is True, then only the .dex files in the to/ codebase are
decompiled, otherwise all .dex files in `project are decompiled.
"""
location = project.codebase_path
abs_location = abspath(expanduser(location))
for top, _, files in fileutils.walk(abs_location):
for f in files:
if not f.endswith('.dex'):
if not f.endswith(".dex") or (to_only and (FROM in top)):
continue
loc = join(top, f)
run_jadx(location=loc)
Expand All @@ -1911,15 +1915,12 @@ def run_jadx(location):
This will decompile the classes.dex file into Java source files.
"""
rc, result, err = command.execute(
command.execute(
cmd_loc="jadx",
args=[
"-d",
f"{file_name(location)}-java",
f"{location}-out",
location,
],
to_files=False,
)

if rc != 0:
raise Exception(err)
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ scancodeio_pipelines =
analyze_docker_image = scanpipe.pipelines.docker:Docker
analyze_root_filesystem_or_vm_image = scanpipe.pipelines.root_filesystem:RootFS
analyze_windows_docker_image = scanpipe.pipelines.docker_windows:DockerWindows
android_d2d = scanpipe.pipelines.android_d2d:AndroidAPKDeployToDevelop
collect_strings_gettext = scanpipe.pipelines.collect_strings_gettext:CollectStringsGettext
collect_symbols_ctags = scanpipe.pipelines.collect_symbols_ctags:CollectSymbolsCtags
collect_symbols_pygments = scanpipe.pipelines.collect_symbols_pygments:CollectSymbolsPygments
Expand Down

0 comments on commit c2228f7

Please sign in to comment.