Navab Singh

14 papers Journal 7Unranked 7
YearRankTypeTitle / Venue / Authors
2024 conf
OFC
Amy S. K. Tong, Wing Wai Chung, Charmaine Goh, Landobasa Y. M. Tobing, Leh Woon Lim, Yuriy A. Akimov, Zhan Jiang Quek, Aravind P. Anthur, Jia Sheng Goh, Huamao Lin, Navab Singh, Qingxin Zhang, Doris Keh Ting Ng
2020 conf
OFC
Ting Hu, Qize Zhong, Nanxi Li, Yuan Dong, Zhengji Xu, Dongdong Li, Yuan Hsing Fu, Yanyan Zhou, Keng Heng Lai, Vladimir Bliznetsov, Hou-Jang Lee, Wei Loong Loh, Shiyang Zhu, Qunying Lin, Navab Singh
2020 conf
OFC
Qize Zhong, Yuan Dong, Dongdong Li, Nanxi Li, Ting Hu, Zhengji Xu, Yanyan Zhou, Keng Heng Lai, Yuan Hsing Fu, Vladimir Bliznetsov, Hou-Jang Lee, Wei Loong Loh, Shiyang Zhu, Qunying Lin, Navab Singh
2020 conf
OFC
Nanxi Li, Yuan Hsing Fu, Yuan Dong, Ting Hu, Zhengji Xu, Qize Zhong, Dongdong Li, Yanyan Zhou, Keng Heng Lai, Vladimir Bliznetsov, Hou-Jang Lee, Wei Loong Loh, Shiyang Zhu, Qunying Lin, Navab Singh
2019 conf
OFC
Shiyang Zhu, Qize Zhong, Ting Hu, Yu Li, Zhengji Xu, Yuan Dong, Navab Singh
2019 conf
OFC
Shiyang Zhu, Ting Hu, Zhengji Xu, Yuan Dong, Qize Zhong, Yu Li, Navab Singh
2019 J jnl
IEEE Trans. Ind. Electron.
Guoqiang Wu, Beibei Han, Daw Don Cheam, Leong Ching Wai, Peter Hyun Kee Chang, Navab Singh, Yuandong Gu
2018 conf
NEMS
Guoqiang Wu, Beibei Han, Daw Don Cheam, Peter Hyun Kee Chang, Navab Singh, Yuandong Gu
2012 J jnl
Microelectron. Reliab.
Hongyu Yu, Yuan Sun, Navab Singh, Guo-Qiang Lo, Dim-Lee Kwong
2004 J jnl
Microelectron. J.
Sohan Singh Mehta, Navab Singh, Moitreyee Mukherjee-Roy, Rakesh Kumar
2004 J jnl
Microelectron. J.
Sohan Singh Mehta, Sun Hai Qin, Moitreyee Mukherjee-Roy, Navab Singh, Rakesh Kumar
2003 J jnl
Microelectron. J.
Moitreyee Mukherjee-Roy, Navab Singh, Sohan Singh Mehta, G. S. Samudra
2003 J jnl
Microelectron. J.
Navab Singh, Moitreyee Mukherjee-Roy, Sohan Singh Mehta
1995 J jnl
Robotica
Navab Singh, H. Zghal, Nariman Sepehri, Suhrid Balakrishnan, Peter D. Lawrence
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 == []