Chandra Krintz

141 papers A* 9A 14B 20C 5Misc 7Journal 31Unranked 51
YearRankTypeTitle / Venue / Authors
2025 conf
FMEC
Rich Wolski, Chandra Krintz, Markus Mock
2025 conf
SC Workshops
Liubov Kurafeeva, Alan Subedi, Ryan Hartung, Michael Fay, Avhishek Biswas, Shantenu Jha, Ozgur O. Kilic, Chandra Krintz, André Merzky, Douglas Thain, Mehmet C. Vuran, Rich Wolski
2025 J jnl
CoRR
Liubov Kurafeeva, Alan Subedi, Ryan Hartung, Michael Fay, Avhishek Biswas, Shantenu Jha, Ozgur O. Kilic, Chandra Krintz, André Merzky, Douglas Thain, Mehmet C. Vuran, Rich Wolski
2024 J jnl
Sensors
Liubov Kurafeeva, Rich Wolski, Chandra Krintz, Thomas Smyth
2024 J jnl
J. Edge Comput.
Fatih Bakir, Sierra Wang, Tyler Ekaireb, Jack Pearson, Chandra Krintz, Rich Wolski
2024 B conf
CLOUD
Tyler Ekaireb, Lukas Brand, Nagarjun Avaraddy, Markus Mock, Chandra Krintz, Rich Wolski
2024 conf
CF
Peiyuan Guan, Animesh Dangwal, Amir Taherkordi, Rich Wolski, Chandra Krintz
2024 conf
FMEC
Shereen Elsayed, Chandra Krintz, Rich Wolski
2023 J jnl
CoRR
Elizabeth Bradley, Chandra Krintz, Melanie Moses
2023 B conf
SMARTCOMP
Gautam Mundewadi, Rich Wolski, Chandra Krintz
2023 C conf
CloudCom
Kerem Çelik, Samridhi Maheshwari, Shereen Elsayed, Markus Mock, Chandra Krintz, Rich Wolski
2023 B conf
IC2E
Nazmus Saquib, Shivaansh Kapoor, Chandra Krintz, Rich Wolski, Markus Mock
2023 conf
SESAME@EuroSys
Tyler Ekaireb, Lukas Brand, Nagarjun Avaraddy, Markus Mock, Chandra Krintz, Rich Wolski
2023 J jnl
IEEE Trans. Parallel Distributed Syst.
Nazmus Saquib, Chandra Krintz, Rich Wolski
2022 B conf
IC2E
Nazmus Saquib, Chandra Krintz, Rich Wolski
2022 conf
Bench
Sierra Wang, Fatih Bakir, Tyler Ekaireb, Jack Pearson, Chandra Krintz, Rich Wolski
2022 conf
PaPoC@EuroSys
Nazmus Saquib, Chandra Krintz, Rich Wolski
2021 conf
IOTSMS
Wei-Tsung Lin, Rich Wolski, Chandra Krintz
2021 conf
SmartWorld/SCALCOM/UIC/ATC/IOP/SCI
Nazmus Saquib, Fatih Bakir, Chandra Krintz, Rich Wolski
2021 Misc conf
SEC
Fatih Bakir, Chandra Krintz, Rich Wolski
2021 J jnl
Softw. Pract. Exp.
Michael Zhang, Chandra Krintz, Rich Wolski
2021 B conf
IC2E
David Bermbach, Abhishek Chandra, Chandra Krintz, Aniruddha Gokhale, Aleksander Slominski, Lauritz Thamsen, Everton Cavalcante, Tian Guo, Ivona Brandic, Rich Wolski
2021 J jnl
CoRR
David Bermbach, Abhishek Chandra, Chandra Krintz, Aniruddha Gokhale, Aleksander Slominski, Lauritz Thamsen, Everton Cavalcante, Tian Guo, Ivona Brandic, Rich Wolski
2021 B conf
IC2E
Nazmus Saquib, Chandra Krintz, Rich Wolski
2021 conf
EDGE
Michael Zhang, Chandra Krintz, Rich Wolski
2020 J jnl
IEEE Trans. Cloud Comput.
Hiranya Jayathilaka, Chandra Krintz, Rich Wolski
2020 Misc conf
ICNC
Stratos Dimopoulos, Chandra Krintz, Rich Wolski
2020 Misc conf
SEC
Gareth George, Fatih Bakir, Rich Wolski, Chandra Krintz
2020 conf
PerCom Workshops
Michael Zhang, Chandra Krintz, Rich Wolski
2019 J jnl
Int. J. Big Data Intell.
Nevena Golubovic, Chandra Krintz, Rich Wolski, Balaji Sethuramasamyraja, Bo Liu
2019 B conf
IC2E
Gareth George, Rich Wolski, Chandra Krintz, John Brevik
2019 Misc conf
SEC
Rich Wolski, Chandra Krintz, Fatih Bakir, Gareth George, Wei-Tsung Lin
2019 conf
DEBS
Wei-Tsung Lin, Fatih Bakir, Chandra Krintz, Rich Wolski, Markus Mock
2019 conf
HotEdge
Fatih Bakir, Rich Wolski, Chandra Krintz, Gowri Sankar Ramachandran
2019 conf
ICIOT
Nevena Golubovic, Rich Wolski, Chandra Krintz, Markus Mock
2019 conf
EDGE
Kyle Carson, John Thomason, Rich Wolski, Chandra Krintz, Markus Mock
2019 B conf
CLOUD
Michael Zhang, Chandra Krintz, Markus Mock, Rich Wolski
2019 conf
MECC@Middleware
Stratos Dimopoulos, Chandra Krintz, Rich Wolski
2018 ch.
Encyclopedia of Database Systems (2nd ed.)
Chandra Krintz
2018 conf
IOT
Chandra Krintz, Rich Wolski, Nevena Golubovic, Fatih Bakir
2018 ch.
Encyclopedia of Database Systems (2nd ed.)
Chandra Krintz
2018 ch.
Encyclopedia of Database Systems (2nd ed.)
Chandra Krintz
2018 ch.
Encyclopedia of Database Systems (2nd ed.)
Chandra Krintz
2018 conf
IEEE CLOUD
Wei-Tsung Lin, Chandra Krintz, Rich Wolski
2018 B conf
IC2E
Wei-Tsung Lin, Chandra Krintz, Rich Wolski, Michael Zhang, Xiaogang Cai, Tongjun Li, Weijin Xu
2017 conf
DASC/PiCom/DataCom/CyberSciTech
Nevena Golubovic, Angad Gill, Chandra Krintz, Rich Wolski
2017 B conf
IC2E
Alexander Pucher, Rich Wolski, Chandra Krintz
2017 J jnl
CoRR
Shashi Shekhar, Joe Colletti, Francisco Muñoz-Arriola, Lakshmish Ramaswamy, Chandra Krintz, Lav R. Varshney, Debra J. Richardson
2017 C conf
CLUSTER
Stratos Dimopoulos, Chandra Krintz, Rich Wolski
2017 B conf
CLOUD
Stratos Dimopoulos, Chandra Krintz, Rich Wolski
2017 A* conf
WWW
Hiranya Jayathilaka, Chandra Krintz, Rich Wolski
2017 conf
IoTDI
Andy Rosales Elias, Nevena Golubovic, Chandra Krintz, Rich Wolski
2016 conf
IEEE BigData
Stratos Dimopoulos, Chandra Krintz, Rich Wolski
2016 conf
GIR
Nevena Golubovic, Chandra Krintz, Rich Wolski, Sara Lafia, Thomas Hervey, Werner Kuhn
2016 A* ed.
PLDI
Chandra Krintz, Emery D. Berger
2016 J jnl
PLoS Comput. Biol.
Brian Drawert, Andreas Hellander, Benjamin B. Bales, Debjani Banerjee, Giovanni Bellesia, Bernie J. Daigle Jr., Geoffrey Douglas, Mengyuan Gu, Anand Gupta, Stefan Hellander, Christopher B. Horuk, Dibyendu Nath, Aviral Takkar, Sheng Wu, Per Lötstedt, Chandra Krintz, Linda R. Petzold
2015 B conf
IC2E
Hiranya Jayathilaka, Chandra Krintz, Rich Wolski
2015 conf
SoCC
Hiranya Jayathilaka, Chandra Krintz, Rich Wolski
2015 C conf
CloudCom
Hiranya Jayathilaka, Chandra Krintz, Rich Wolski
2015 B conf
IC2E
Stratos Dimopoulos, Chandra Krintz, Rich Wolski, Anand Gupta
2015 B conf
IC2E
Alexander Pucher, Emre Gul, Rich Wolski, Chandra Krintz
2014 conf
HPCS
Christopher B. Horuk, Geoffrey Douglas, Anand Gupta, Chandra Krintz, Benjamin B. Bales, Giovanni Bellesia, Brian Drawert, Rich Wolski, Linda R. Petzold, Andreas Hellander
2014 B conf
IC2E
Chandra Krintz, Hiranya Jayathilaka, Stratos Dimopoulos, Alexander Pucher, Rich Wolski, Tevfik Bultan
2014 conf
GECON
Geoffrey Douglas, Brian Drawert, Chandra Krintz, Rich Wolski
2014 conf
IEEE SCC
Hiranya Jayathilaka, Chandra Krintz, Rich Wolski
2013 J jnl
J. Grid Comput.
Navraj Chohan, Chris Bunch, Chandra Krintz, Navyasri Canumalla
2013 J jnl
IEEE Internet Comput.
Chandra Krintz
2012 Misc conf
UCC
Chris Bunch, Vaibhav Arora, Navraj Chohan, Chandra Krintz, Shashank Hegde, Ankit Srivastava
2012 conf
WebApps
Navraj Chohan, Anand Gupta, Chris Bunch, Koshik Prakasam, Chandra Krintz
2012 J jnl
J. Grid Comput.
Chris Bunch, Brian Drawert, Navraj Chohan, Chandra Krintz, Linda R. Petzold, Khawaja S. Shams
2012 conf
HotCloud
Navraj Chohan, Anand Gupta, Chris Bunch, Sujay Sundaram, Chandra Krintz
2012 conf
SC Companion
Linda R. Petzold, Chandra Krintz
2011 conf
IEEE CLOUD
Navraj Chohan, Chris Bunch, Chandra Krintz, Yoshihide Nomura
2010 conf
IEEE CLOUD
Chris Bunch, Navraj Chohan, Chandra Krintz, Jovan Chohan, Jonathan Kupferman, Puneet Lakhina, Yiming Li, Yoshihide Nomura
2010 A conf
OOPSLA
Michal Wegiel, Chandra Krintz
2010 conf
HotCloud
Navraj Chohan, Claris Castillo, Mike Spreitzer, Malgorzata Steinder, Asser N. Tantawi, Chandra Krintz
2009 conf
CloudComp
Navraj Chohan, Chris Bunch, Sydney Pang, Chandra Krintz, Nagy Mostafa, Sunil Soman, Richard Wolski
2009 J jnl
Sci. Comput. Program.
Lingli Zhang, Chandra Krintz
2009 A* conf
ASPLOS
Michal Wegiel, Chandra Krintz
2009 J jnl
ACM Trans. Archit. Code Optim.
Michal Wegiel, Chandra Krintz
2009 conf
PPPJ
Nagy Mostafa, Chandra Krintz
2008 J jnl
J. Signal Process. Syst.
Ye Wen, Selim Gurun, Navraj Chohan, Richard Wolski, Chandra Krintz
2008 A conf
ECOOP
Sunil Soman, Chandra Krintz, Laurent Daynès
2008 J jnl
ACM Trans. Embed. Comput. Syst.
Selim Gurun, Chandra Krintz, Richard Wolski
2008 J jnl
Int. J. High Perform. Comput. Appl.
Selim Gurun, Richard Wolski, Chandra Krintz, Daniel Nurmi
2008 J jnl
ACM SIGPLAN Notices
Eric Allen, Mark W. Bailey, Rastislav Bodík, Kim B. Bruce, Kathleen Fisher, Stephen N. Freund, Robert Harper, Chandra Krintz, Shriram Krishnamurthi, James R. Larus, Doug Lea, Gary T. Leavens, Lori L. Pollock, Stuart Reges, Martin C. Rinard, Mark A. Sheldon, Franklyn A. Turbak, Mitchell Wand
2008 J jnl
ACM SIGPLAN Notices
Kathleen Fisher, Chandra Krintz
2008 J jnl
ACM SIGPLAN Notices
Kathleen Fisher, Chandra Krintz
2008 A* conf
ASPLOS
Michal Wegiel, Chandra Krintz
2008 A conf
IPDPS
Richard Wolski, Selim Gurun, Chandra Krintz, Daniel Nurmi
2008 A* conf
PLDI
Michal Wegiel, Chandra Krintz
2007 J jnl
J. Syst. Softw.
Sunil Soman, Chandra Krintz
2007 B conf
PACT
Priya Nagpurkar, Harold W. Cain, Mauricio J. Serrano, Jong-Deok Choi, Chandra Krintz
2007 J jnl
CoRR
Roland Ducournau, Etienne Gagnon, Chandra Krintz, Philippe Mulet, Jan Vitek, Olivier Zendra
2007 J jnl
CoRR
Olivier Zendra, Eric Jul, Roland Ducournau, Etienne Gagnon, Richard E. Jones, Chandra Krintz, Philippe Mulet, Jan Vitek
2007 conf
ECOOP Workshops
Olivier Zendra, Eric Jul, Roland Ducournau, Etienne Gagnon, Richard E. Jones, Chandra Krintz, Philippe Mulet, Jan Vitek
2007 A conf
CGO
Chris Grzegorczyk, Sunil Soman, Chandra Krintz, Richard Wolski
2007 B conf
PACT
Lingli Zhang, Chandra Krintz, Priya Nagpurkar
2007 B ed.
VEE
Chandra Krintz, Steven Hand, David Tarditi
2007 conf
PPPJ
Lingli Zhang, Chandra Krintz, Priya Nagpurkar
2007 A conf
IPDPS
Hussam Mousa, Chandra Krintz, Lamia Youseff, Richard Wolski
2006 Misc conf
CODES+ISSS
Selim Gurun, Chandra Krintz
2006 J jnl
IEEE Trans. Parallel Distributed Syst.
Chandra Krintz, Sezgin Sucu
2006 conf
Software Engineering Research and Practice
Sunil Soman, Chandra Krintz
2006 J jnl
ACM Trans. Archit. Code Optim.
Priya Nagpurkar, Hussam Mousa, Chandra Krintz, Timothy Sherwood
2006 conf
VTDC@SC
Lamia Youseff, Rich Wolski, Brent C. Gorda, Chandra Krintz
2006 conf
ECOOP Workshops
Roland Ducournau, Etienne Gagnon, Chandra Krintz, Philippe Mulet, Jan Vitek, Olivier Zendra
2006 A conf
CGO
Priya Nagpurkar, Chandra Krintz, Michael Hind, Peter F. Sweeney, V. T. Rajan
2006 conf
ISPA Workshops
Lamia Youseff, Richard Wolski, Brent C. Gorda, Chandra Krintz
2006 J jnl
Sci. Comput. Program.
Priya Nagpurkar, Chandra Krintz
2006 conf
ICSAMOS
Selim Gurun, Ye Wen, Navraj Chohan, Richard Wolski, Chandra Krintz
2006 C conf
ISMM
Sunil Soman, Laurent Daynès, Chandra Krintz
2005 Misc conf
EMSOFT
Selim Gurun, Chandra Krintz
2005 conf
IEEE PACT
Hussam Mousa, Chandra Krintz
2005 A conf
CGO
Priya Nagpurkar, Chandra Krintz, Timothy Sherwood
2005 conf
Automatic Performance Analysis
Chandra Krintz, Selim Gurun
2005 J jnl
ACM Trans. Archit. Code Optim.
Lingli Zhang, Chandra Krintz
2005 A conf
IPDPS
Chandra Krintz, Richard Wolski
2004 B conf
LCTES
Lingli Zhang, Chandra Krintz
2004 A conf
ISLPED
Chandra Krintz, Ye Wen, Richard Wolski
2004 C conf
ISMM
Sunil Soman, Chandra Krintz, David F. Bacon
2004 A conf
MobiSys
Selim Gurun, Chandra Krintz, Richard Wolski
2004 conf
PPPJ
Lingli Zhang, Chandra Krintz
2004 conf
PPPJ
Priya Nagpurkar, Chandra Krintz
2003 conf
ITCC
Sezgin Sucu, Chandra Krintz
2003 A conf
CGO
Chandra Krintz
2003 A* conf
USENIX Security Symposium
Sunil Soman, Chandra Krintz, Giovanni Vigna
2003 conf
PACS
Ye Wen, Richard Wolski, Chandra Krintz
2002 conf
PPPJ/IRE
Chandra Krintz
2002 conf
PPPJ/IRE
Chandra Krintz
2001 B conf
CCGRID
Chandra Krintz, Richard Wolski
2001 A conf
HPDC
Chandra Krintz, Brad Calder
2001 J jnl
Softw. Pract. Exp.
Chandra Krintz, David Grove, Vivek Sarkar, Brad Calder
2001 A* conf
PLDI
Chandra Krintz, Brad Calder
2001 J jnl
Concurr. Comput. Pract. Exp.
Chandra Krintz, Richard Wolski
2000 conf
Java Grande
Chandra Krintz, Richard Wolski
1999 A conf
OOPSLA
Chandra Krintz, Brad Calder, Urs Hölzle
1999 A conf
SC
Richard Wolski, John Brevik, Chandra Krintz, Graziano Obertelli, Neil Spring, Alan Su
1998 A* conf
ASPLOS
Brad Calder, Chandra Krintz, Simmi John, Todd M. Austin
1998 A* conf
ASPLOS
Chandra Krintz, Brad Calder, Han Bok Lee, Benjamin G. Zorn
1995 conf
Parallel and Distributed Computing and Systems
Chandra Krintz, Steven M. Fitzgerald
tests/unit/test_apk_cfg_features.py
← Index tests/unit/test_apk_cfg_features.py python
"""
Unit tests for APK CFG feature parity with the Binary Ninja pipeline.

Tests advanced CFG features computed from smali (topology hash, MD-index,
WL-MinHash, prime product, packed adjacency, block features export) and
the slimmed similarity table.

All tests use mocked smali input — no JADX/apktool/Java required.
"""
import pytest

from redb.extractors.decompiler.apk.smali_cfg import (
    SmaliCFGMetrics,
    compute_cfg_metrics,
)
from redb.extractors.decompiler.apk.method_extractor import (
    SMALI_OP_PRIMES,
    compute_prime_product_smali,
    count_call_instructions,
)

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


# ===================================================================
# Sample smali bodies for testing
# ===================================================================

# Simple linear method: 3 instructions, 1 block
SMALI_LINEAR = """\
    const/4 v0, 0x0
    invoke-virtual {p0, v0}, Lcom/Foo;->bar(I)V
    return-void
"""

# Diamond CFG: if-else with two paths merging
SMALI_DIAMOND = """\
    const/4 v0, 0x1
    if-eqz v0, :cond_0
    invoke-virtual {p0}, Lcom/Foo;->pathA()V
    goto :goto_0
    :cond_0
    invoke-virtual {p0}, Lcom/Foo;->pathB()V
    :goto_0
    return-void
"""

# Loop: a back edge from goto to a label before it
SMALI_LOOP = """\
    const/4 v0, 0x0
    :loop_start
    add-int/lit8 v0, v0, 0x1
    if-lt v0, v1, :loop_start
    return-void
"""

# Multi-block with several invoke calls
SMALI_MULTI_CALL = """\
    invoke-virtual {p0}, Lcom/Foo;->a()V
    invoke-static {v0}, Lcom/Bar;->b(I)V
    invoke-direct {p0, v1}, Lcom/Baz;-><init>(I)V
    const/4 v0, 0x0
    return-void
"""


# ===================================================================
# TestSmaliCFGMetricsAdvanced — new fields in SmaliCFGMetrics
# ===================================================================

class TestSmaliCFGMetricsAdvanced:
    """Test that advanced CFG fields are populated by compute_cfg_metrics."""

    def test_topology_hash_is_bytes(self):
        m = compute_cfg_metrics(SMALI_DIAMOND)
        assert isinstance(m.cfg_topology_hash, bytes)
        assert len(m.cfg_topology_hash) == 16

    def test_topology_hash_nonzero_for_multiblock(self):
        m = compute_cfg_metrics(SMALI_DIAMOND)
        assert m.cfg_topology_hash != b'\x00' * 16

    def test_topology_hash_zero_for_empty(self):
        m = compute_cfg_metrics("")
        assert m.cfg_topology_hash == b'\x00' * 16

    def test_identical_cfg_same_topology_hash(self):
        """Two smali methods with the same CFG structure produce the same hash."""
        smali_a = """\
    const/4 v0, 0x1
    if-eqz v0, :cond_0
    const/4 v1, 0x2
    goto :goto_0
    :cond_0
    const/4 v1, 0x3
    :goto_0
    return-void
"""
        smali_b = """\
    const/4 v5, 0x9
    if-nez v5, :cond_0
    add-int v6, v5, v5
    goto :goto_0
    :cond_0
    sub-int v6, v5, v5
    :goto_0
    return-void
"""
        m_a = compute_cfg_metrics(smali_a)
        m_b = compute_cfg_metrics(smali_b)
        assert m_a.cfg_topology_hash == m_b.cfg_topology_hash

    def test_different_cfg_different_topology_hash(self):
        m_linear = compute_cfg_metrics(SMALI_LINEAR)
        m_diamond = compute_cfg_metrics(SMALI_DIAMOND)
        assert m_linear.cfg_topology_hash != m_diamond.cfg_topology_hash

    def test_md_index_topdown_nonzero(self):
        m = compute_cfg_metrics(SMALI_DIAMOND)
        assert m.md_index_topdown != 0

    def test_md_index_bottomup_nonzero(self):
        m = compute_cfg_metrics(SMALI_DIAMOND)
        assert m.md_index_bottomup != 0

    def test_md_index_zero_for_empty(self):
        m = compute_cfg_metrics("")
        assert m.md_index_topdown == 0
        assert m.md_index_bottomup == 0

    def test_wl_minhash_length(self):
        m = compute_cfg_metrics(SMALI_DIAMOND)
        assert len(m.wl_minhash) == 128

    def test_wl_minhash_sentinel_for_empty(self):
        m = compute_cfg_metrics("")
        assert m.wl_minhash == [255] * 128

    def test_wl_minhash_values_are_uint8(self):
        m = compute_cfg_metrics(SMALI_DIAMOND)
        for val in m.wl_minhash:
            assert 0 <= val <= 255

    def test_cfg_adjacency_nonempty_for_multiblock(self):
        m = compute_cfg_metrics(SMALI_DIAMOND)
        assert len(m.cfg_adjacency) > 0

    def test_cfg_adjacency_empty_for_empty(self):
        m = compute_cfg_metrics("")
        assert m.cfg_adjacency == []

    def test_cfg_adjacency_packed_format(self):
        """Each entry should be (src << 16) | tgt."""
        m = compute_cfg_metrics(SMALI_DIAMOND)
        for edge in m.cfg_adjacency:
            assert isinstance(edge, int)
            src = edge >> 16
            tgt = edge & 0xFFFF
            assert src < m.block_count
            assert tgt < m.block_count

    def test_block_features_exported(self):
        m = compute_cfg_metrics(SMALI_DIAMOND)
        assert len(m.block_features) == m.block_count
        for bf in m.block_features:
            assert len(bf) == 8  # 7 categories + successor_count

    def test_cfg_feature_tlsh_none_for_small(self):
        """Small methods produce None (< 50 bytes of feature data)."""
        m = compute_cfg_metrics(SMALI_LINEAR)
        # Single-block linear method — too small for TLSH
        assert m.cfg_feature_tlsh is None

    def test_loop_count_with_back_edge(self):
        m = compute_cfg_metrics(SMALI_LOOP)
        assert m.loop_count >= 1


# ===================================================================
# TestPrimeProductSmali
# ===================================================================

class TestPrimeProductSmali:

    def test_empty_returns_zero(self):
        assert compute_prime_product_smali("") == 0

    def test_none_returns_zero(self):
        assert compute_prime_product_smali(None) == 0

    def test_known_computation(self):
        """Single invoke instruction → CALL category → prime 17."""
        smali = "    invoke-virtual {p0}, Lcom/Foo;->bar()V"
        assert compute_prime_product_smali(smali) == 17

    def test_two_instructions(self):
        """const (CONST→2) * invoke (CALL→17) = 34."""
        smali = """\
    const/4 v0, 0x0
    invoke-virtual {p0, v0}, Lcom/Foo;->bar(I)V
"""
        assert compute_prime_product_smali(smali) == 2 * 17

    def test_skips_directives_and_labels(self):
        """Directives, labels, and comments should be skipped."""
        smali = """\
.registers 2
.line 10
    :label
    # comment
    const/4 v0, 0x0
"""
        # Only const/4 → CONST → prime 2
        assert compute_prime_product_smali(smali) == 2

    def test_position_independent(self):
        """Reordering instructions produces the same product (multiplication is commutative)."""
        smali_a = """\
    add-int v0, v1, v2
    invoke-virtual {p0}, Lcom/Foo;->bar()V
"""
        smali_b = """\
    invoke-virtual {p0}, Lcom/Foo;->bar()V
    add-int v0, v1, v2
"""
        assert compute_prime_product_smali(smali_a) == compute_prime_product_smali(smali_b)

    def test_all_categories_have_primes(self):
        """Every category in SMALI_OP_PRIMES is a positive integer."""
        for cat, prime in SMALI_OP_PRIMES.items():
            assert isinstance(prime, int)
            assert prime >= 1

    def test_mod_2_64(self):
        """Result should be mod 2^64 (doesn't overflow)."""
        # A very long method — product stays within uint64
        smali = "\n".join(["    mul-int v0, v1, v2"] * 1000)
        result = compute_prime_product_smali(smali)
        assert 0 <= result < 2**64


# ===================================================================
# TestCallCount
# ===================================================================

class TestCallCount:

    def test_empty(self):
        assert count_call_instructions("") == 0

    def test_none(self):
        assert count_call_instructions(None) == 0

    def test_single_invoke(self):
        smali = "    invoke-virtual {p0}, Lcom/Foo;->bar()V"
        assert count_call_instructions(smali) == 1

    def test_multiple_invoke_types(self):
        assert count_call_instructions(SMALI_MULTI_CALL) == 3

    def test_non_invoke_not_counted(self):
        smali = """\
    const/4 v0, 0x0
    add-int v1, v0, v0
    return-void
"""
        assert count_call_instructions(smali) == 0


# ===================================================================
# TestSimilarityTableSlimmed
# ===================================================================

class TestSimilarityTableSlimmed:
    """Verify the similarity table no longer contains moved fields."""

    def test_export_similarity_no_block_count(self):
        """block_count should not be in similarity export columns."""
        from redb.extractors.decompiler.DecompileAPK import DecompileAPK
        from unittest.mock import MagicMock

        extractor = DecompileAPK.__new__(DecompileAPK)
        extractor.log = MagicMock()
        extractor.sha256 = "a" * 64
        extractor.sha1 = "b" * 40
        extractor.md5 = "c" * 32
        extractor.analysis_results = {
            "sha256": "a" * 64,
            "sha1": "b" * 40,
            "md5": "c" * 32,
            "similarity_metrics": [{
                "smali_method_hash": "d" * 64,
                "cyclomatic_complexity": 3,
                "ssdeep_smali": None,
                "tlsh_smali": None,
                "minhash": [1, 2, 3],
            }],
        }

        export = extractor.prepare_export_data("ClickHouseExporter")
        sim_cols = export["method_similarity_metrics"]["column_names"]
        assert "block_count" not in sim_cols
        assert "edge_count" not in sim_cols
        assert "loop_count" not in sim_cols
        assert "max_depth" not in sim_cols
        assert "max_fan_out" not in sim_cols
        # These should still be there
        assert "smali_method_hash" in sim_cols
        assert "ssdeep_smali" in sim_cols
        assert "minhash" in sim_cols
        # cyclomatic_complexity moved to cfg table
        assert "cyclomatic_complexity" not in sim_cols


# ===================================================================
# TestCFGTableExport
# ===================================================================

class TestCFGTableExport:
    """Verify the new CFG table is exported correctly."""

    def test_export_cfg_table_present(self):
        from redb.extractors.decompiler.DecompileAPK import DecompileAPK
        from unittest.mock import MagicMock

        extractor = DecompileAPK.__new__(DecompileAPK)
        extractor.log = MagicMock()
        extractor.analysis_results = {
            "sha256": "a" * 64,
            "sha1": "b" * 40,
            "md5": "c" * 32,
            "cfg": [{
                "smali_method_hash": "d" * 64,
                "cfg_topology_hash": b'\x01' * 16,
                "block_count": 4,
                "edge_count": 5,
                "instructions_count": 20,
                "call_count": 3,
                "cyclomatic_complexity": 3,
                "loop_count": 1,
                "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": [[10, 1, 0, 2, 1, 0, 0, 2]] * 4,
                "cfg_adjacency": [0x00010000, 0x00010002],
            }],
        }

        export = extractor.prepare_export_data("ClickHouseExporter")
        assert "cfg_methods" in export
        cfg_export = export["cfg_methods"]
        assert cfg_export["table"] == "code_apk_cfg_methods"
        assert len(cfg_export["data"]) == 1
        assert "cfg_topology_hash" in cfg_export["column_names"]
        assert "prime_product_smali" in cfg_export["column_names"]
        assert "wl_minhash" in cfg_export["column_names"]
        assert "bb_features" in cfg_export["column_names"]
        assert "cfg_adjacency" in cfg_export["column_names"]
        # Verify column count matches data width
        assert len(cfg_export["column_names"]) == len(cfg_export["data"][0])
        assert len(cfg_export["column_type_names"]) == len(cfg_export["data"][0])