R. Sabitha

21 papers Journal 20Unranked 1
YearRankTypeTitle / Venue / Authors
2026 J jnl
Int. J. Comput. Intell. Syst.
G. Gokila Deepa, S. Karthik, Muthu Subash Kavitha, R. Sabitha
2025 J jnl
Frontiers Big Data
R. Sabitha, D. Sundar
2024 conf
ICCCSP
S. B. Indra, S. Harshini, R. Sabitha
2023 J jnl
Comput. Syst. Sci. Eng.
R. Sabitha, C. Gokul Prasad, S. Karthik
2023 J jnl
Comput. Syst. Sci. Eng.
D. Loganathan, M. Balasubramani, R. Sabitha, S. Karthik
2023 J jnl
Wirel. Pers. Commun.
R. Sabitha, S. Gopikrishnan, B. J. Bejoy, V. Anusuya, V. Saravanan
2023 J jnl
Circuits Syst. Signal Process.
R. Sabitha, P. Poonkodi, Muthu Subash Kavitha, S. Karthik
2022 J jnl
Ad Hoc Sens. Wirel. Networks
R. Sabitha, Anand Prakash Shukla, Abolfazl Mehbodniya, L. Shakkeera, Pundru Chandra Shaker Reddy
2022 J jnl
J. Interconnect. Networks
Xiaoran Fu, K. Lokesh Krishna, R. Sabitha
2022 J jnl
Int. J. Inf. Comput. Secur.
B. Yamini, R. Sabitha
2022 J jnl
J. Interconnect. Networks
Xiaoli Qiu, Wei Li, Yang Li, Hongmei Gu, Fei Song, R. Sabitha
2021 J jnl
Pattern Recognit. Lett.
M. Ananthi, P. Rajkumar, R. Sabitha, S. Karthik
2021 J jnl
J. Medical Imaging Health Informatics
G. S. Gopika, J. Shanthini, Muthu Subash Kavitha, R. Sabitha
2021 J jnl
Wirel. Pers. Commun.
M. Shobana, R. Sabitha, S. Karthik
2021 J jnl
Wirel. Pers. Commun.
D. Loganathan, M. Balasubramani, R. Sabitha
2021 J jnl
Pattern Recognit. Lett.
R. Sabitha, A. Aruna, S. Karthik, J. Shanthini
2021 J jnl
Wirel. Pers. Commun.
J. Raj Kannan, R. Sabitha, S. Karthik, J. Shanthini
2021 J jnl
Wirel. Pers. Commun.
V. Sampath, S. Karthik, R. Sabitha
2019 J jnl
Clust. Comput.
S. Madhurikkha, R. Sabitha
2019 J jnl
J. Medical Syst.
Muthu Subash Kavitha, J. Shanthini, R. Sabitha
2019 J jnl
Clust. Comput.
R. Thilagavathy, R. Sabitha
tests/unit/test_apk_apktool_wrapper.py
← Index tests/unit/test_apk_apktool_wrapper.py python
"""
Unit tests for apktool wrapper subprocess management and smali directory detection.

All subprocess calls are mocked — no apktool/Java installation required.
"""
import os
import tempfile

import pytest
from unittest.mock import MagicMock, patch

pytestmark = [pytest.mark.unit, pytest.mark.apk, pytest.mark.decompile]


class TestApktoolDisassembler:
    """Tests for ApktoolDisassembler subprocess wrapper."""

    @patch.dict(os.environ, {}, clear=False)
    def test_init_defaults(self):
        os.environ.pop("APKTOOL_PATH", None)
        from redb.extractors.decompiler.apk.apktool_wrapper import ApktoolDisassembler
        a = ApktoolDisassembler()
        assert a.apktool_path == "apktool"
        assert a.timeout == 120

    def test_init_custom(self):
        from redb.extractors.decompiler.apk.apktool_wrapper import ApktoolDisassembler
        a = ApktoolDisassembler(apktool_path="/opt/apktool", timeout=120)
        assert a.apktool_path == "/opt/apktool"
        assert a.timeout == 120

    def test_init_from_env(self):
        from redb.extractors.decompiler.apk.apktool_wrapper import ApktoolDisassembler
        with patch.dict(os.environ, {"APKTOOL_PATH": "/usr/bin/apktool", "APKTOOL_TIMEOUT": "90"}):
            a = ApktoolDisassembler()
            assert a.apktool_path == "/usr/bin/apktool"
            assert a.timeout == 90

    @patch("subprocess.Popen")
    def test_disassemble_success(self, mock_popen):
        from redb.extractors.decompiler.apk.apktool_wrapper import ApktoolDisassembler
        mock_proc = MagicMock()
        mock_proc.communicate.return_value = ("output", "")
        mock_proc.returncode = 0
        mock_popen.return_value = mock_proc

        a = ApktoolDisassembler()
        result = a.disassemble("/test.apk", "/output")
        assert result is True

    @patch("subprocess.Popen")
    def test_disassemble_failure(self, mock_popen):
        from redb.extractors.decompiler.apk.apktool_wrapper import ApktoolDisassembler
        mock_proc = MagicMock()
        mock_proc.communicate.return_value = ("", "error")
        mock_proc.returncode = 1
        mock_popen.return_value = mock_proc

        a = ApktoolDisassembler(log=MagicMock())
        result = a.disassemble("/test.apk", "/output")
        assert result is False

    @patch("subprocess.Popen")
    def test_disassemble_timeout(self, mock_popen):
        from redb.extractors.decompiler.apk.apktool_wrapper import ApktoolDisassembler
        import subprocess
        mock_proc = MagicMock()
        mock_proc.communicate.side_effect = subprocess.TimeoutExpired(cmd="apktool", timeout=10)
        mock_proc.pid = 12345
        mock_popen.return_value = mock_proc

        with patch("os.getpgid", return_value=12345), \
             patch("os.killpg"):
            a = ApktoolDisassembler(timeout=10, log=MagicMock())
            result = a.disassemble("/test.apk", "/output")
            assert result is False

    @patch("subprocess.Popen", side_effect=FileNotFoundError)
    def test_disassemble_not_found(self, mock_popen):
        from redb.extractors.decompiler.apk.apktool_wrapper import ApktoolDisassembler
        a = ApktoolDisassembler(log=MagicMock())
        result = a.disassemble("/test.apk", "/output")
        assert result is False

    @patch("subprocess.Popen")
    def test_disassemble_command_args(self, mock_popen):
        from redb.extractors.decompiler.apk.apktool_wrapper import ApktoolDisassembler
        mock_proc = MagicMock()
        mock_proc.communicate.return_value = ("", "")
        mock_proc.returncode = 0
        mock_popen.return_value = mock_proc

        a = ApktoolDisassembler(apktool_path="/opt/apktool")
        a.disassemble("/test.apk", "/output")

        cmd = mock_popen.call_args[0][0]
        assert cmd[0] == "/opt/apktool"
        assert "d" in cmd
        assert "--no-res" in cmd
        assert "--force" in cmd
        assert "/test.apk" in cmd

    def test_get_smali_directories_single_dex(self):
        from redb.extractors.decompiler.apk.apktool_wrapper import ApktoolDisassembler
        with tempfile.TemporaryDirectory() as tmpdir:
            os.makedirs(os.path.join(tmpdir, "smali"))
            a = ApktoolDisassembler()
            dirs = a.get_smali_directories(tmpdir)
            assert len(dirs) == 1
            assert dirs[0].endswith("smali")

    def test_get_smali_directories_multi_dex(self):
        from redb.extractors.decompiler.apk.apktool_wrapper import ApktoolDisassembler
        with tempfile.TemporaryDirectory() as tmpdir:
            os.makedirs(os.path.join(tmpdir, "smali"))
            os.makedirs(os.path.join(tmpdir, "smali_classes2"))
            os.makedirs(os.path.join(tmpdir, "smali_classes3"))
            # Should not be included
            os.makedirs(os.path.join(tmpdir, "res"))
            os.makedirs(os.path.join(tmpdir, "original"))

            a = ApktoolDisassembler()
            dirs = a.get_smali_directories(tmpdir)
            assert len(dirs) == 3

    def test_get_smali_directories_empty(self):
        from redb.extractors.decompiler.apk.apktool_wrapper import ApktoolDisassembler
        with tempfile.TemporaryDirectory() as tmpdir:
            a = ApktoolDisassembler()
            dirs = a.get_smali_directories(tmpdir)
            assert dirs == []

    def test_get_smali_directories_nonexistent(self):
        from redb.extractors.decompiler.apk.apktool_wrapper import ApktoolDisassembler
        a = ApktoolDisassembler()
        dirs = a.get_smali_directories("/nonexistent/path")
        assert dirs == []