Wei Bao

147 papers A* 22A 15B 16C 3Misc 3Journal 70Unranked 17
YearRankTypeTitle / Venue / Authors
2026 A* conf
AAAI
Ruoyu Wu, Wei Bao, Ben Liang, Hequn Wang
2026 J jnl
J. Parallel Distributed Comput.
Zizhao Wang, Wei Bao, Ruoyu Wu, Dong Yuan, Albert Y. Zomaya
2026 A* conf
AAAI
Xinyi Sheng, Wei Bao, Hequn Wang, Yuqin Liu, Sen Fu
2025 A* conf
AAAI
Binghan Wu, Wei Bao, Bing Bing Zhou
2025 J jnl
IEEE Trans. Dependable Secur. Comput.
Xinyi Sheng, Zhengjie Yang, Wei Bao
2025 A conf
CIKM
Ruoyu Wu, Wei Bao, Hequn Wang
2025 A conf
UAI
Ruoyu Wu, Wei Bao, Ben Liang, Liming Ge
2025 J jnl
IEEE Trans. Big Data
Sen Fu, Zhengjie Yang, Chuang Hu, Wei Bao
2025 A conf
CIKM
Xubin Chen, Zhengjie Yang, Xinyi Sheng, Sen Fu, Wei Bao
2024 A* conf
ACM Multimedia
Jiaming Shen, Kun Hu, Wei Bao, Chang Wen Chen, Zhiyong Wang
2024 J jnl
Future Gener. Comput. Syst.
Zao Zhang, Yuning Zhang, Wei Bao, Changyang Li, Dong Yuan
2024 J jnl
IEEE Trans. Parallel Distributed Syst.
Binghan Wu, Wei Bao, Bing Bing Zhou
2024 A conf
AAMAS
Binghan Wu, Wei Bao, Bing Zhou
2024 J jnl
Inf. Sci.
Yanli Li, Weiping Ding, Huaming Chen, Wei Bao, Dong Yuan
2024 J jnl
IEEE Trans. Cloud Comput.
Huanghuang Liang, Qianlong Sang, Chuang Hu, Dazhao Cheng, Xiaobo Zhou, Dan Wang, Wei Bao, Yu Wang
2024 conf
ICA3PP (4)
Yichen Guo, Xinyi Sheng, Wei Bao, Bing Bing Zhou
2024 A conf
CIKM
Long Tan Le, Tuan Dung Nguyen, Tung-Anh Nguyen, Choong Seon Hong, Suranga Seneviratne, Wei Bao, Nguyen Hoang Tran
2024 J jnl
CoRR
Tung-Anh Nguyen, Long Tan Le, Tuan Dung Nguyen, Wei Bao, Suranga Seneviratne, Choong Seon Hong, Nguyen Hoang Tran
2024 J jnl
IEEE/ACM Trans. Netw.
Tung-Anh Nguyen, Long Tan Le, Tuan Dung Nguyen, Wei Bao, Suranga Seneviratne, Choong Seon Hong, Nguyen Hoang Tran
2024 J jnl
IEEE Internet Things J.
Liming Ge, Wei Bao, Xinyi Sheng, Dong Yuan, Bing Bing Zhou, Zhiyong Wang
2024 A conf
CIKM
Xinyi Sheng, Wei Bao, Liming Ge
2023 conf
AI (1)
Liming Ge, David Zhaochen Jiang, Wei Bao
2023 J jnl
IEEE Trans. Pattern Anal. Mach. Intell.
Xiuwen Gong, Dong Yuan, Wei Bao, Fulin Luo
2023 conf
Q2SWinet
Ruoyu Wu, Wei Bao, Liming Ge, Bing Bing Zhou
2023 J jnl
CoRR
Jiaming Shen, Kun Hu, Wei Bao, Chang Wen Chen, Zhiyong Wang
2023 J jnl
IEEE Trans. Cloud Comput.
Huanghuang Liang, Qianlong Sang, Chuang Hu, Dazhao Cheng, Xiaobo Zhou, Dan Wang, Wei Bao, Yu Wang
2023 J jnl
IEEE Trans. Neural Networks Learn. Syst.
Xiuwen Gong, Dong Yuan, Wei Bao
2023 J jnl
World Wide Web (WWW)
Weiyu Ju, Dong Yuan, Wei Bao, Liming Ge, Bing Bing Zhou
2023 J jnl
Comput. Secur.
Yanli Li, Dong Yuan, Abubakar Sadiq Sani, Wei Bao
2023 J jnl
IEEE Trans. Artif. Intell.
Zhengjie Yang, Sen Fu, Wei Bao, Dong Yuan, Albert Y. Zomaya
2023 J jnl
CoRR
Nan Yang, Dong Yuan, Charles Z. Liu, Yongkun Deng, Wei Bao
2023 J jnl
CoRR
Nan Yang, Xuanyu Chen, Charles Z. Liu, Dong Yuan, Wei Bao, Lizhen Cui
2023 A* conf
INFOCOM
Tung-Anh Nguyen, Jiayu He, Long Tan Le, Wei Bao, Nguyen Hoang Tran
2023 J jnl
CoRR
Yu Zhang, Huaming Chen, Wei Bao, Zhongzheng Lai, Zao Zhang, Dong Yuan
2023 J jnl
IEEE Trans. Parallel Distributed Syst.
Zhengjie Yang, Sen Fu, Wei Bao, Dong Yuan, Albert Y. Zomaya
2023 A conf
ICDCS
Zhengjie Yang, Sen Fu, Wei Bao, Dong Yuan, Bing Bing Zhou
2023 J jnl
CoRR
Yanli Li, Huaming Chen, Wei Bao, Zhengmeng Xu, Dong Yuan
2023 conf
ACSW
Yanli Li, Laicheng Zhong, Dong Yuan, Huaming Chen, Wei Bao
2023 B conf
ICPP
Yuning Zhang, Zao Zhang, Wei Bao, Dong Yuan
2023 A* conf
IJCAI
Ruoyu Wu, Wei Bao, Liming Ge
2023 J jnl
CoRR
Ruoyu Wu, Wei Bao, Liming Ge
2023 Misc conf
AusDM
Nan Yang, Laicheng Zhong, Fan Huang, Wei Bao, Dong Yuan
2023 J jnl
CoRR
Nan Yang, Laicheng Zhong, Fan Huang, Dong Yuan, Wei Bao
2023 conf
ICA3PP (1)
Liming Ge, Wei Bao, Dong Yuan, Bing Bing Zhou
2023 B conf
IJCNN
Liming Ge, Wei Bao, Xinyi Sheng, Dong Yuan, Bing Bing Zhou
2023 J jnl
IEEE Trans. Mob. Comput.
Shizhe Zang, Wei Bao, Phee Lep Yeoh, Branka Vucetic, Yonghui Li
2023 A conf
ICME
Zao Zhang, Dong Yuan, Yu Zhang, Wei Bao
2023 conf
ICSE Companion
Zhongzheng Lai, Dong Yuan, Huaming Chen, Yu Zhang, Wei Bao
2022 conf
MobiArch
Zao Zhang, Yuning Zhang, Dong Yuan, Wei Bao
2022 ed.
ADHOCNETS/TRIDENTCOM
Wei Bao, Xingliang Yuan, Longxiang Gao, Tom H. Luan, David Bong Jun Choi
2022 J jnl
IEEE Netw.
Nan Yang, Dong Yuan, Yuning Zhang, Yongkun Deng, Wei Bao
2022 A* conf
IJCAI
Binghan Wu, Wei Bao, Dong Yuan, Bing Zhou
2022 J jnl
IEEE Trans. Parallel Distributed Syst.
Canh T. Dinh, Nguyen Hoang Tran, Tuan Dung Nguyen, Wei Bao, Amir Rezaei Balef, Bing Bing Zhou, Albert Y. Zomaya
2022 conf
SIGCOMM Posters and Demos
Zhongzheng Lai, Dong Yuan, Wei Bao, Yu Zhang, Bing Bing Zhou
2022 A* conf
MobiCom
Liming Ge, Wei Bao, Dong Yuan, Bing Bing Zhou
2022 conf
ACCV (Workshops)
Yanli Li, Abubakar Sadiq Sani, Dong Yuan, Wei Bao
2022 J jnl
Concurr. Comput. Pract. Exp.
MohammadReza HoseinyFarahabady, Javid Taheri, Albert Y. Zomaya, Zahir Tari, Wei Bao
2022 J jnl
IEEE Trans. Parallel Distributed Syst.
Zhengjie Yang, Wei Bao, Dong Yuan, Nguyen Hoang Tran, Albert Y. Zomaya
2022 J jnl
CoRR
Tung-Anh Nguyen, Jiayu He, Long Tan Le, Wei Bao, Nguyen Hoang Tran
2022 J jnl
IEEE Trans. Multim.
Xiuwen Gong, Jiahui Yang, Dong Yuan, Wei Bao
2022 J jnl
CoRR
Zhengjie Yang, Sen Fu, Wei Bao, Dong Yuan, Albert Y. Zomaya
2022 A* conf
ICML
Xiuwen Gong, Dong Yuan, Wei Bao
2022 A* conf
AAAI
Xiuwen Gong, Dong Yuan, Wei Bao
2022 B conf
ICPP
Liming Ge, Zizhao Wang, Wei Bao, Dong Yuan, Nguyen Hoang Tran, Bing Bing Zhou, Albert Y. Zomaya
2022 J jnl
IEEE Trans. Neural Networks Learn. Syst.
Xiuwen Gong, Dong Yuan, Wei Bao
2021 J jnl
IEEE Trans. Ind. Informatics
Abubakar Sadiq Sani, Dong Yuan, Wei Bao, Zhao Yang Dong
2021 A* conf
AAAI
Binghan Wu, Wei Bao, Dong Yuan
2021 A conf
CIKM
Weiyu Ju, Wei Bao, Liming Ge, Dong Yuan
2021 A* conf
IJCAI
Xiuwen Gong, Dong Yuan, Wei Bao
2021 J jnl
CoRR
Xiuwen Gong, Dong Yuan, Wei Bao
2021 J jnl
IEEE/ACM Trans. Netw.
Canh T. Dinh, Nguyen Hoang Tran, Minh N. H. Nguyen, Choong Seon Hong, Wei Bao, Albert Y. Zomaya, Vincent Gramoli
2021 conf
iThings/GreenCom/CPSCom/SmartData/Cybermatics
Yu Zhang, Zhongzheng Lai, Dong Yuan, Wei Bao, Bing Bing Zhou, Jing Qiu, Shen Wang, Stewart Adams
2021 B conf
CCGRID
Weiyu Ju, Wei Bao, Dong Yuan, Liming Ge, Bing Bing Zhou
2021 A* conf
ICAPS
Binghan Wu, Wei Bao, Dong Yuan, Bing Zhou
2021 C ed.
QShine
Xingliang Yuan, Wei Bao, Xun Yi, Nguyen Hoang Tran
2021 A* conf
NeurIPS
Xiuwen Gong, Dong Yuan, Wei Bao
2021 J jnl
ACM Trans. Sens. Networks
Weiyu Ju, Dong Yuan, Wei Bao, Liming Ge, Bing Bing Zhou
2020 J jnl
Comput. Commun.
Zizhao Wang, Wei Bao, Dong Yuan, Liming Ge, Nguyen Hoang Tran, Albert Y. Zomaya
2020 conf
INFOCOM Workshops
Yi Zhao, Wei Bao, Dan Wang, Ke Xu, Liang Lv
2020 J jnl
CoRR
Canh T. Dinh, Nguyen Hoang Tran, Tuan Dung Nguyen, Wei Bao, Amir Rezaei Balef
2020 J jnl
CoRR
Zhengjie Yang, Wei Bao, Dong Yuan, Nguyen Hoang Tran, Albert Y. Zomaya
2020 B conf
ICPP
Canh T. Dinh, Nguyen Hoang Tran, Tuan Dung Nguyen, Wei Bao, Albert Y. Zomaya, Bing Bing Zhou
2020 A* conf
AAAI
Xiuwen Gong, Dong Yuan, Wei Bao
2020 J jnl
CoRR
Xiuwen Gong, Jiahui Yang, Dong Yuan, Wei Bao
2020 J jnl
IEEE Trans. Computers
Wei Bao, Dong Yuan, Bing Bing Zhou, Albert Y. Zomaya
2020 B conf
CCGRID
M. Reza HoseinyFarahabady, Ali Jannesari, Javid Taheri, Wei Bao, Albert Y. Zomaya, Zahir Tari
2019 J jnl
IEEE Internet Things J.
Hazem Ibrahim, Wei Bao, Uyen Trang Nguyen
2019 Misc conf
SEC
Weiyu Ju, Dong Yuan, Wei Bao, Liming Ge, Bing Bing Zhou
2019 A* conf
INFOCOM
Chuang Hu, Wei Bao, Dan Wang, Fengming Liu
2019 J jnl
CCF Trans. Netw.
Dan Wang, Fangming Liu, Wei Bao, Lin Wang, Jiangchuan Liu, Yuanyuan Yang, Weisong Shi
2019 J jnl
CoRR
Canh T. Dinh, Nguyen Hoang Tran, Minh N. H. Nguyen, Choong Seon Hong, Wei Bao, Albert Y. Zomaya, Vincent Gramoli
2019 A* conf
INFOCOM
Nguyen Hoang Tran, Wei Bao, Albert Y. Zomaya, Minh N. H. Nguyen, Choong Seon Hong
2019 J jnl
IEEE J. Sel. Areas Commun.
Shizhe Zang, Wei Bao, Phee Lep Yeoh, Branka Vucetic, Yonghui Li
2019 J jnl
IEEE Trans. Commun.
Shizhe Zang, Wei Bao, Phee Lep Yeoh, Branka Vucetic, Yonghui Li
2019 C conf
PDCAT
Tao Tang, Hao Wu, Wei Bao, Pengyi Yang, Dong Yuan, Bing Bing Zhou
2019 C conf
PDCAT
M. Reza HoseinyFarahabady, Ali Jannesari, Wei Bao, Zahir Tari, Albert Y. Zomaya
2019 A conf
MSWiM
Zizhao Wang, Wei Bao, Dong Yuan, Liming Ge, Nguyen Hoang Tran, Albert Y. Zomaya
2019 J jnl
IEEE Netw.
Yi Qian, Dan Wu, Wei Bao, Pascal Lorenz
2019 J jnl
IEEE Trans. Inf. Forensics Secur.
Abubakar Sadiq Sani, Dong Yuan, Wei Bao, Zhao Yang Dong, Branka Vucetic, Elisa Bertino
2019 A conf
ICDCS
Abubakar Sadiq Sani, Dong Yuan, Wei Bao, Phee Lep Yeoh, Zhao Yang Dong, Branka Vucetic, Elisa Bertino
2018 conf
ICC
Abubakar Sadiq Sani, Dong Yuan, Phee Lep Yeoh, Wei Bao, Shiping Chen, Branka Vucetic
2018 J jnl
J. Parallel Distributed Comput.
Yucen Nan, Wei Li, Wei Bao, Flávia Coimbra Delicato, Paulo F. Pires, Albert Y. Zomaya
2018 B conf
MobiHoc
Wei Bao, Dong Yuan, Keqi Shi, Weiyu Ju, Albert Y. Zomaya
2018 A* conf
INFOCOM
Chuang Hu, Wei Bao, Dan Wang
2018 J jnl
IEEE Trans. Wirel. Commun.
Wei Bao, Ben Liang
2018 conf
HotEdge
Shizhe Zang, Wei Bao, Phee Lep Yeoh, Branka Vucetic, Yonghui Li
2018 J jnl
IEEE Commun. Mag.
He Chen, Rana Abbas, Peng Cheng, Mahyar Shirvanimoghaddam, Wibowo Hardjawana, Wei Bao, Yonghui Li, Branka Vucetic
2018 B conf
MobiHoc
Wei Bao, Yonghui Li, Branka Vucetic
2018 A conf
MSWiM
Wei Bao, Dong Yuan, Zhengjie Yang, Shen Wang, Bing Bing Zhou, Stewart Adams, Albert Y. Zomaya
2018 J jnl
ACM Trans. Sens. Networks
Chuang Hu, Wei Bao, Dan Wang, Yi Qian, Muqiao Zheng, Shi Wang
2018 J jnl
IEEE Commun. Mag.
Dan Wang, Wei Bao, Chuang Hu, Yi Qian, Muqiao Zheng, Shi Wang
2017 J jnl
IEEE Access
Yucen Nan, Wei Li, Wei Bao, Flávia Coimbra Delicato, Paulo F. Pires, Yong Dou, Albert Y. Zomaya
2017 A conf
MSWiM
Wei Bao, Wei Li, Flávia Coimbra Delicato, Paulo F. Pires, Dong Yuan, Bing Bing Zhou, Albert Y. Zomaya
2017 J jnl
IEEE Commun. Mag.
Wei Bao, Dong Yuan, Zhengjie Yang, Shen Wang, Wei Li, Bing Bing Zhou, Albert Y. Zomaya
2017 J jnl
CoRR
Wei Bao, He Chen, Yonghui Li, Branka Vucetic
2017 J jnl
IEEE J. Sel. Areas Commun.
Wei Bao, He Chen, Yonghui Li, Branka Vucetic
2017 conf
ISCIT
Shizhe Zang, Wei Bao, Phee Lep Yeoh, He Chen, Zihuai Lin, Branka Vucetic, Yonghui Li
2017 conf
ICC
Nor Aishah Muhammad, He Chen, Wei Bao, Yonghui Li, Branka Vucetic
2017 B conf
NCA
Abubakar Sadiq Sani, Dong Yuan, Wei Bao, Zhao Yang Dong
2017 J jnl
CoRR
He Chen, Rana Abbas, Peng Cheng, Mahyar Shirvanimoghaddam, Wibowo Hardjawana, Wei Bao, Yonghui Li, Branka Vucetic
2017 conf
BuildSys
Chuang Hu, Wei Bao, Dan Wang, Yi Qian, Muqiao Zheng, Shi Wang
2016 B conf
NCA
Yucen Nan, Wei Li, Wei Bao, Flávia Coimbra Delicato, Paulo F. Pires, Albert Y. Zomaya
2016 A* conf
INFOCOM
Wei Bao, Ben Liang
2015 conf
ICC
Wei Bao, Stefan Valentin
2015 B conf
MobiHoc
Wei Bao, Ben Liang
2015 J jnl
IEEE J. Sel. Areas Commun.
Yicheng Lin, Wei Bao, Wei Yu, Ben Liang
2015 A* conf
INFOCOM
Wei Bao, Ben Liang
2015 J jnl
IEEE Trans. Commun.
Wei Bao, Ben Liang
2015 J jnl
IEEE Trans. Wirel. Commun.
Wei Bao, Ben Liang
2015 J jnl
IEEE J. Sel. Areas Commun.
Wei Bao, Ben Liang
2015 J jnl
IEEE Trans. Wirel. Commun.
Wei Bao, Ben Liang
2014 A conf
MSWiM
Wei Bao, Ben Liang
2014 Misc conf
ICASSP
Wei Bao, Ben Liang
2014 J jnl
CoRR
Yicheng Lin, Wei Bao, Wei Yu, Ben Liang
2014 A* conf
INFOCOM
Wei Bao, Ben Liang
2013 J jnl
IEEE Trans. Wirel. Commun.
Wei Bao, Ben Liang
2013 A* conf
INFOCOM
Wei Bao, Ben Liang
2013 J jnl
CoRR
Wei Bao, Ben Liang
2013 J jnl
CoRR
Wei Bao, Ben Liang
2013 A conf
MSWiM
Wei Bao, Ben Liang
2013 J jnl
CoRR
Wei Bao, Ben Liang
2012 J jnl
CoRR
Wei Bao, Ben Liang
2012 B conf
GLOBECOM
Wei Bao, Vahid Shah-Mansouri, Vincent W. S. Wong, Victor C. M. Leung
2011 B conf
WCNC
Wei Bao, Yifei Hao, Tong Wang
2010 B conf
GLOBECOM
Wei Bao, Vincent W. S. Wong, Victor C. M. Leung
2009 B conf
GLOBECOM
Hongmei Liu, Gang Chuai, Wei Bao, Mugen Peng, Wenbo Wang
2009 B conf
GLOBECOM
Wei Bao, Wenbo Wang, Hongmei Liu, Mugen Peng
tests/unit/test_apk_decompile_extractor.py
← Index tests/unit/test_apk_decompile_extractor.py python
"""
Unit tests for DecompileAPK extractor, export data, and ClickHouse schemas.

Tests the main DecompileAPK extractor class following the DecompileBinja test pattern.
All analysis is mocked — no JADX/apktool/Java installation required.
"""
import hashlib
import os
import tempfile
import zipfile

import pytest
from unittest.mock import MagicMock, patch, PropertyMock
from dataclasses import asdict

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


def _create_fake_apk_file():
    """Create a minimal APK file for testing and return its path."""
    tmpdir = tempfile.mkdtemp()
    apk_path = os.path.join(tmpdir, "test.apk")
    with zipfile.ZipFile(apk_path, "w") as zf:
        zf.writestr("AndroidManifest.xml", b"<manifest/>")
        zf.writestr("classes.dex", b"dex\n035\x00" + b"\x00" * 100)
    return apk_path


# ============================================================================
# DecompileAPK Extractor Tests
# ============================================================================

class TestDecompileAPK:
    """Tests for the DecompileAPK extractor class."""

    def test_tag(self):
        from redb.extractors.decompiler.DecompileAPK import DecompileAPK
        apk_path = _create_fake_apk_file()
        try:
            ext = DecompileAPK(apk_path, MagicMock())
            assert ext.tag() == "apk_decompiled"
        finally:
            os.unlink(apk_path)

    def test_get_clickhouse_table(self):
        from redb.extractors.decompiler.DecompileAPK import DecompileAPK
        apk_path = _create_fake_apk_file()
        try:
            ext = DecompileAPK(apk_path, MagicMock())
            assert ext.get_clickhouse_table() is None
        finally:
            os.unlink(apk_path)

    def test_timeout_default(self):
        from redb.extractors.decompiler.DecompileAPK import DecompileAPK
        apk_path = _create_fake_apk_file()
        try:
            ext = DecompileAPK(apk_path, MagicMock())
            assert ext.APK_DECOMPILE_TIMEOUT == 600
        finally:
            os.unlink(apk_path)

    def test_timeout_from_env(self):
        from redb.extractors.decompiler.DecompileAPK import DecompileAPK
        apk_path = _create_fake_apk_file()
        try:
            with patch.dict(os.environ, {"APK_DECOMPILE_TIMEOUT": "900"}):
                ext = DecompileAPK(apk_path, MagicMock())
                assert ext.APK_DECOMPILE_TIMEOUT == 900
        finally:
            os.unlink(apk_path)

    def test_timeout_invalid_env(self):
        from redb.extractors.decompiler.DecompileAPK import DecompileAPK
        apk_path = _create_fake_apk_file()
        try:
            with patch.dict(os.environ, {"APK_DECOMPILE_TIMEOUT": "not_a_number"}):
                ext = DecompileAPK(apk_path, MagicMock())
                assert ext.APK_DECOMPILE_TIMEOUT == 600
        finally:
            os.unlink(apk_path)

    def test_calculate_md5(self):
        from redb.extractors.decompiler.DecompileAPK import DecompileAPK
        apk_path = _create_fake_apk_file()
        try:
            ext = DecompileAPK(apk_path, MagicMock())
            result = ext.calculate_md5("test_string")
            assert len(result) == 32
            assert result == hashlib.md5(b"test_string").hexdigest()
        finally:
            os.unlink(apk_path)

    def test_context_manager(self):
        from redb.extractors.decompiler.DecompileAPK import DecompileAPK
        apk_path = _create_fake_apk_file()
        try:
            with DecompileAPK(apk_path, MagicMock()) as ext:
                assert ext is not None
        finally:
            os.unlink(apk_path)

    def test_cleanup_run(self):
        from redb.extractors.decompiler.DecompileAPK import DecompileAPK
        apk_path = _create_fake_apk_file()
        try:
            ext = DecompileAPK(apk_path, MagicMock())
            ext.analyzer = MagicMock()
            ext.cleanup_run()
            assert ext.analyzer is None
        finally:
            os.unlink(apk_path)


# ============================================================================
# Export Data Tests
# ============================================================================

class TestPrepareExportData:
    """Tests for DecompileAPK.prepare_export_data() ClickHouse schemas."""

    def _make_extractor_with_results(self):
        from redb.extractors.decompiler.DecompileAPK import DecompileAPK
        apk_path = _create_fake_apk_file()
        ext = DecompileAPK(apk_path, MagicMock())
        ext.analysis_results = {
            "sha256": "a" * 64,
            "sha1": "b" * 40,
            "md5": "c" * 32,
            "decompiled_content": [
                {
                    "decompiled_method_hash": "d" * 64,
                    "decompiled_method": "public void foo() {}",
                    "decompiled_method_type": "USER",
                    "decompiled_has_string_encryption": False,
                    "decompiled_has_reflection_calls": False,
                    "decompiled_excessive_goto_count": False,
                }
            ],
            "decompiled_refs": [
                {
                    "decompiled_method_hash": "d" * 64,
                    "smali_method_hash": "e" * 64,
                    "decompiled_class_name": "com.example.Foo",
                    "decompiled_method_name": "foo",
                    "decompiled_method_signature": "()V",
                    "decompiled_method_prototype": "void foo()",
                    "functions_caller": ["bar"],
                    "functions_call": ["baz"],
                }
            ],
            "smali_content": [
                {
                    "smali_method_hash": "e" * 64,
                    "smali_method": "invoke-virtual {p0}, Lfoo;->bar()V\nreturn-void",
                    "smali_method_type": "USER",
                    "smali_instructions_count": 10,
                    "smali_register_count": 3,
                    "smali_has_string_encryption": False,
                    "smali_has_reflection_calls": False,
                    "smali_excessive_goto_count": False,
                    "smali_flattened_score": 0.0,
                    "smali_mba_score": 0.0,
                }
            ],
            "smali_refs": [
                {
                    "smali_method_hash": "e" * 64,
                    "decompiled_method_hash": "d" * 64,
                    "smali_class_name": "com.example.Foo",
                    "smali_method_name": "foo",
                    "smali_method_signature": "()V",
                    "ssdeep_smali": None,
                    "tlsh_smali": None,
                }
            ],
            "similarity_metrics": [
                {
                    "smali_method_hash": "e" * 64,
                    "cyclomatic_complexity": 2,
                    "ssdeep_smali": None,
                    "tlsh_smali": None,
                    "ssdeep_smali_normalized": None,
                    "tlsh_smali_normalized": None,
                    "minhash": [],
                }
            ],
            "cfg": [
                {
                    "smali_method_hash": "e" * 64,
                    "cfg_topology_hash": b'\x01' * 16,
                    "block_count": 3,
                    "edge_count": 3,
                    "cfg_instructions_count": 10,
                    "call_count": 1,
                    "cyclomatic_complexity": 2,
                    "loop_count": 0,
                    "max_depth": 2,
                    "max_fan_out": 2,
                    "md_index_topdown": 12345,
                    "md_index_bottomup": 67890,
                    "prime_product_smali": 999,
                    "cfg_feature_tlsh": None,
                    "wl_minhash": [0] * 128,
                    "bb_features": [[5, 1, 0, 1, 1, 0, 0, 2]] * 3,
                    "cfg_adjacency": [0x00000001, 0x00000002],
                }
            ],
            "strings": [
                {
                    "string": "https://evil.example.com/payload",
                    "string_encoding": "UTF8",
                    "string_offset": 0,
                    "string_length": 31,
                    "string_entropy": 3.95,
                }
            ],
            "analysis_errors": [
                {
                    "class_name": "com.example.Foo",
                    "method_name": "bar",
                    "error_location": "jadx",
                    "error_message": "timeout",
                    "error_type": "TimeoutError",
                }
            ],
        }
        return ext, apk_path

    def test_returns_none_when_no_results(self):
        from redb.extractors.decompiler.DecompileAPK import DecompileAPK
        apk_path = _create_fake_apk_file()
        try:
            ext = DecompileAPK(apk_path, MagicMock())
            assert ext.prepare_export_data("ClickHouseExporter") is None
        finally:
            os.unlink(apk_path)

    def test_multi_table_flag(self):
        ext, apk_path = self._make_extractor_with_results()
        try:
            export = ext.prepare_export_data("ClickHouseExporter")
            assert export["multi_table"] is True
        finally:
            os.unlink(apk_path)

    def test_all_table_keys_present(self):
        ext, apk_path = self._make_extractor_with_results()
        try:
            export = ext.prepare_export_data("ClickHouseExporter")
            assert "decompiled_content" in export
            assert "decompiled_refs" in export
            assert "smali_content" in export
            assert "smali_refs" in export
            assert "method_similarity_metrics" in export
            assert "strings_raw" in export
            assert "analysis_errors" in export
        finally:
            os.unlink(apk_path)

    def test_decompiled_content_schema(self):
        ext, apk_path = self._make_extractor_with_results()
        try:
            export = ext.prepare_export_data("ClickHouseExporter")
            dc = export["decompiled_content"]
            assert dc["table"] == "code_apk_decompiled_methods_content"
            assert len(dc["column_names"]) == 7
            assert len(dc["column_type_names"]) == 7
            assert "decompiled_method_hash" in dc["column_names"]
            assert "decompiled_method" in dc["column_names"]
            assert "analysis_date" in dc["column_names"]
            assert len(dc["data"]) == 1
            assert len(dc["data"][0]) == 7
        finally:
            os.unlink(apk_path)

    def test_decompiled_refs_schema(self):
        ext, apk_path = self._make_extractor_with_results()
        try:
            export = ext.prepare_export_data("ClickHouseExporter")
            dr = export["decompiled_refs"]
            assert dr["table"] == "code_apk_decompiled_methods_references"
            assert len(dr["column_names"]) == 10
            assert len(dr["column_type_names"]) == 10
            assert "sha256" in dr["column_names"]
            assert "sha1" not in dr["column_names"]
            assert "md5" not in dr["column_names"]
            assert "functions_caller" in dr["column_names"]
            assert "functions_call" in dr["column_names"]
        finally:
            os.unlink(apk_path)

    def test_smali_content_schema(self):
        ext, apk_path = self._make_extractor_with_results()
        try:
            export = ext.prepare_export_data("ClickHouseExporter")
            sc = export["smali_content"]
            assert sc["table"] == "code_apk_smali_methods_content"
            assert len(sc["column_names"]) == 11
            assert len(sc["column_type_names"]) == 11
            assert "smali_instructions_count" in sc["column_names"]
            assert "smali_register_count" in sc["column_names"]
            assert "smali_flattened_score" in sc["column_names"]
            assert "smali_mba_score" in sc["column_names"]
        finally:
            os.unlink(apk_path)

    def test_smali_refs_schema(self):
        ext, apk_path = self._make_extractor_with_results()
        try:
            export = ext.prepare_export_data("ClickHouseExporter")
            sr = export["smali_refs"]
            assert sr["table"] == "code_apk_smali_methods_references"
            assert len(sr["column_names"]) == 7
            assert len(sr["column_type_names"]) == 7
            assert "sha1" not in sr["column_names"]
            assert "md5" not in sr["column_names"]
            assert "ssdeep_smali" not in sr["column_names"]
            assert "tlsh_smali" not in sr["column_names"]
        finally:
            os.unlink(apk_path)

    def test_similarity_metrics_schema(self):
        ext, apk_path = self._make_extractor_with_results()
        try:
            export = ext.prepare_export_data("ClickHouseExporter")
            sm = export["method_similarity_metrics"]
            assert sm["table"] == "code_apk_method_similarity_metrics"
            assert len(sm["column_names"]) == 7
            assert "minhash" in sm["column_names"]
            assert "ssdeep_smali_normalized" in sm["column_names"]
            assert "tlsh_smali_normalized" in sm["column_names"]
            # cyclomatic_complexity moved to cfg table
            assert "cyclomatic_complexity" not in sm["column_names"]
            assert "block_count" not in sm["column_names"]
            assert "loop_count" not in sm["column_names"]
        finally:
            os.unlink(apk_path)

    def test_analysis_errors_schema(self):
        ext, apk_path = self._make_extractor_with_results()
        try:
            export = ext.prepare_export_data("ClickHouseExporter")
            ae = export["analysis_errors"]
            assert ae["table"] == "code_apk_analysis_errors"
            assert len(ae["column_names"]) == 9
            assert "error_hash" in ae["column_names"]
            assert "status" in ae["column_names"]
        finally:
            os.unlink(apk_path)

    def test_sha256_propagated_to_refs(self):
        ext, apk_path = self._make_extractor_with_results()
        try:
            export = ext.prepare_export_data("ClickHouseExporter")
            # Check that sha256 from analysis_results appears in ref rows
            dr_row = export["decompiled_refs"]["data"][0]
            assert dr_row[0] == "a" * 64  # sha256
            # sha1 and md5 no longer included in refs
            assert "sha1" not in export["decompiled_refs"]["column_names"]
            assert "md5" not in export["decompiled_refs"]["column_names"]
        finally:
            os.unlink(apk_path)

    def test_empty_tables_not_included(self):
        from redb.extractors.decompiler.DecompileAPK import DecompileAPK
        apk_path = _create_fake_apk_file()
        try:
            ext = DecompileAPK(apk_path, MagicMock())
            ext.analysis_results = {
                "sha256": "a" * 64,
                "sha1": "b" * 40,
                "md5": "c" * 32,
                "decompiled_content": [],
                "decompiled_refs": [],
                "smali_content": [],
                "smali_refs": [],
                "similarity_metrics": [],
                "cfg": [],
                "strings": [],
                "analysis_errors": [],
            }
            export = ext.prepare_export_data("ClickHouseExporter")
            assert export == {"multi_table": True}
        finally:
            os.unlink(apk_path)

    def test_non_clickhouse_exporter_returns_none(self):
        ext, apk_path = self._make_extractor_with_results()
        try:
            result = ext.prepare_export_data("ElasticsearchExporter")
            assert result is None
        finally:
            os.unlink(apk_path)


# ============================================================================
# Dataclass Tests
# ============================================================================

class TestAPKCodeAnalysisDataclasses:
    """Tests for the new APK code analysis dataclasses."""

    def test_decompiled_method_content(self):
        from redb.models.dataclasses import APKDecompiledMethodContent
        dc = APKDecompiledMethodContent(
            decompiled_method_hash="a" * 64,
            decompiled_method="public void foo() {}",
            decompiled_method_type="USER",
        )
        assert dc.decompiled_has_string_encryption is False
        assert dc.decompiled_has_reflection_calls is False
        assert dc.decompiled_excessive_goto_count is False

    def test_decompiled_method_content_populated(self):
        from redb.models.dataclasses import APKDecompiledMethodContent
        dc = APKDecompiledMethodContent(
            decompiled_method_hash="a" * 64,
            decompiled_method="public void foo() {}",
            decompiled_method_type="USER",
            decompiled_has_string_encryption=True,
            decompiled_has_reflection_calls=True,
            decompiled_excessive_goto_count=True,
        )
        assert dc.decompiled_has_string_encryption is True
        d = asdict(dc)
        assert d["decompiled_method_hash"] == "a" * 64

    def test_decompiled_method_reference(self):
        from redb.models.dataclasses import APKDecompiledMethodReference
        dr = APKDecompiledMethodReference(
            sha256="a" * 64,
            sha1="b" * 40,
            md5="c" * 32,
            decompiled_method_hash="d" * 64,
        )
        assert dr.functions_caller == []
        assert dr.functions_call == []
        assert dr.smali_method_hash is None

    def test_smali_method_content(self):
        from redb.models.dataclasses import APKSmaliMethodContent
        sc = APKSmaliMethodContent(
            smali_method_hash="e" * 64,
            smali_method="invoke-virtual {p0}, Lfoo;->bar()V",
            smali_method_type="USER",
            smali_instructions_count=5,
            smali_register_count=3,
        )
        assert sc.smali_instructions_count == 5
        assert sc.smali_register_count == 3

    def test_smali_method_reference(self):
        from redb.models.dataclasses import APKSmaliMethodReference
        sr = APKSmaliMethodReference(
            sha256="a" * 64,
            sha1="b" * 40,
            md5="c" * 32,
            smali_method_hash="e" * 64,
        )
        assert sr.decompiled_method_hash is None
        assert sr.ssdeep_smali is None
        assert sr.tlsh_smali is None

    def test_method_similarity_metrics(self):
        from redb.models.dataclasses import APKMethodSimilarityMetrics
        ms = APKMethodSimilarityMetrics(smali_method_hash="e" * 64)
        assert ms.cyclomatic_complexity is None
        assert ms.ssdeep_smali_normalized is None
        assert ms.tlsh_smali_normalized is None
        assert ms.minhash == []

    def test_code_analysis_error(self):
        from redb.models.dataclasses import APKCodeAnalysisError
        err = APKCodeAnalysisError(
            sha256="a" * 64,
            error_location="jadx",
            error_message="timeout",
        )
        assert err.class_name is None
        assert err.method_name is None
        assert err.error_type is None


# ============================================================================
# Tag Enum Tests
# ============================================================================

class TestAPKDecompiledTag:
    """Tests for the APK_DECOMPILED tag enum."""

    def test_tag_exists(self):
        from redb.extractors.enum import Tag
        assert hasattr(Tag, "APK_DECOMPILED")

    def test_tag_value(self):
        from redb.extractors.enum import Tag
        assert Tag.APK_DECOMPILED.value == "apk_decompiled"


# ============================================================================
# Worker Integration Tests
# ============================================================================

class TestAPKWorkerDecompileIntegration:
    """Tests that DecompileAPK is registered in workers.py."""

    def test_module_registered(self):
        """Verify DecompileAPK is discoverable via the extractor registry."""
        from redb.extractor_registry import get_extractor_class
        cls = get_extractor_class("DecompileAPK")
        assert cls is not None, "DecompileAPK not found in extractor registry"
        assert cls.__name__ == "DecompileAPK"

    def test_worker_apk_dispatch_includes_decompile(self):
        import inspect
        import redb.workers as workers
        source = inspect.getsource(workers.process_binary_file)
        assert "DecompileAPK" in source