Naser MohammadZadeh

30 papers A 2C 2Journal 21Unranked 5
YearRankTypeTitle / Venue / Authors
2025 J jnl
IEEE Access
Eesa Nikahd, Naser MohammadZadeh, Zahra Shirmohammadi
2025 J jnl
Inf. Secur. J. A Glob. Perspect.
Maryam Hatami, Hossein Gharaee Garakani, Naser MohammadZadeh
2022 J jnl
IEEE Trans. Circuits Syst. I Regul. Pap.
Fateme Sadat Ayatollahi, M. B. Ghaznavi-Ghoushchi, Naser MohammadZadeh, Seyedeh Fatemeh Ghamkhari
2022 conf
ISVLSI
Amirmohammad Biuki, Naser MohammadZadeh, Robert Wille, Sahar Sargaran
2021 J jnl
Quantum Eng.
Tayebeh Bahreini, Naser MohammadZadeh
2021 J jnl
ACM Trans. Design Autom. Electr. Syst.
Naser MohammadZadeh, Robert Wille, Oliver Keszöcze
2021 A conf
DATE
Oliver Keszöcze, Naser MohammadZadeh, Robert Wille
2019 J jnl
ISC Int. J. Inf. Secur.
Elham Serkani, Hossein Gharaee Garakani, Naser MohammadZadeh
2019 conf
ISCISC
Shayan Mehranpoor, Naser MohammadZadeh, Hossein Gharaee
2019 J jnl
Quantum Inf. Process.
Sajjad Sanaei, Naser MohammadZadeh
2019 J jnl
ACM Trans. Archit. Code Optim.
Sahar Sargaran, Naser MohammadZadeh
2018 J jnl
Int. J. Circuit Theory Appl.
Hanieh Ghaffarishad, Naser MohammadZadeh, Mohammad Bagher Ghaznavi Ghoushchi
2017 J jnl
Int. J. Circuit Theory Appl.
Azim Farghadan, Naser MohammadZadeh
2016 J jnl
J. Inf. Sci. Eng.
Yaser Taheri, Hossein Gharaee Garakani, Naser MohammadZadeh
2016 conf
IST
Mahdie Kiaee, Hossein Gharaee, Naser MohammadZadeh
2016 conf
IST
Shadi Janbabaei, Hossein Gharaee, Naser MohammadZadeh
2016 J jnl
Microelectron. J.
Naser MohammadZadeh
2016 J jnl
Quantum Inf. Process.
Zahra Mirkhani, Naser MohammadZadeh
2016 J jnl
Microprocess. Microsystems
Naser MohammadZadeh, Elaheh Taqavi
2015 J jnl
ACM J. Emerg. Technol. Comput. Syst.
Tayebeh Bahreini, Naser MohammadZadeh
2014 J jnl
Quantum Inf. Process.
Naser MohammadZadeh, Morteza Saheb Zamani, Mehdi Sedighi
2011 J jnl
Quantum Inf. Process.
Naser MohammadZadeh, Morteza Saheb Zamani, Mehdi Sedighi
2010 J jnl
Microelectron. J.
Naser MohammadZadeh, Mehdi Sedighi, Morteza Saheb Zamani
2009 C conf
DSD
Naser MohammadZadeh, Morteza Saheb Zamani, Mehdi Sedighi
2009 A conf
DATE
Naser MohammadZadeh, Minoo Mirsaeedi, Ali Jahanian, Morteza Saheb Zamani
2008 J jnl
J. Circuits Syst. Comput.
Naser MohammadZadeh, Shaahin Hessabi, Maziar Goudarzi, Mahdi Malaki
2008 C conf
DSD
Mehdi Saeedi, Naser MohammadZadeh, Mehdi Sedighi, Morteza Saheb Zamani
2008 J jnl
Microprocess. Microsystems
Maziar Goudarzi, Shaahin Hessabi, Naser MohammadZadeh, Nasim Zainolabedini
2007 conf
ACM Great Lakes Symposium on VLSI
Naser MohammadZadeh, Morteza NajafVand, Shaahin Hessabi, Maziar Goudarzi
2007 J jnl
J. Comput. Syst. Sci.
Maziar Goudarzi, Naser MohammadZadeh, Shaahin Hessabi
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 == []