M. B. Srinivas

126 papers A 4B 2C 14Misc 14Journal 32Unranked 60
YearRankTypeTitle / Venue / Authors
2025 J jnl
IEEE Access
N. K. Jisy, Sudha Radhika, Sirisha Senthil, M. B. Srinivas
2025 J jnl
IEEE Access
Sesibhushana Rao Bommana, Sreehari Veeramachaneni, Syed Ershad Ahmed, M. B. Srinivas
2024 conf
MWSCAS
Sesibhushana Rao Bommana, Sreehari Veeramachaneni, M. B. Srinivas
2024 J jnl
Comput. methods Biomech. Biomed. Eng. Imaging Vis.
N. K. Jisy, Md. Hasnat Ali, Sirisha Senthil, M. B. Srinivas
2024 conf
AICAS
Harshiv Chandra, Akash Ghosh, Rahul Singh, M. B. Srinivas
2023 J jnl
J. Ambient Intell. Humaniz. Comput.
Khushi Gupta, Arshdeep Singh, Sreenivasa Reddy Yeduri, M. B. Srinivas, Linga Reddy Cenkeramaddi
2022 J jnl
IEEE Trans. Very Large Scale Integr. Syst.
Mahesh Kumar Adimulam, M. B. Srinivas
2022 J jnl
J. Parallel Distributed Comput.
Diyanesh Chinnakkonda, Karthick Rajamani, M. B. Srinivas
2022 J jnl
SN Comput. Sci.
P. Sai Phaneendra, Chetan Kumar Vudadha, M. B. Srinivas
2022 J jnl
IEEE Trans. Comput. Aided Des. Integr. Circuits Syst.
Saravanan Sethuraman, Venkata Kalyan Tavva, M. B. Srinivas
2021 conf
NER
Kotturi Venkata SaiTeja, Ponduru Manoj Kumar, Punnamraju Sarath Chandra, N. K. Jisy, Md. Hasnat Ali, M. B. Srinivas
2021 J jnl
IEEE Consumer Electron. Mag.
Himanshu Thapliyal, Katina Michael, Saraju P. Mohanty, M. B. Srinivas, Madhavi K. Ganapathiraju
2021 Misc conf
COMSNETS
Jyoti Bhatia, Aveen Dayal, Ajit Jha, Santosh Kumar Vishvakarma, J. Soumya, M. B. Srinivas, Phaneendra K. Yalavarthy, Abhinav Kumar, V. Lalitha, Sagar Koorapati, Linga Reddy Cenkeramaddi
2020 J jnl
IEEE Trans. Ind. Informatics
Veeresh Babu Vulligaddala, Sandeep Vernekar, Sudhakar Singamala, Ravi Kumar Adusumalli, Vijay Ele, Manfred Brandl, M. B. Srinivas
2020 J jnl
IEEE Trans. Comput. Aided Des. Integr. Circuits Syst.
Saravanan Sethuraman, Venkata Kalyan Tavva, Karthick Rajamani, Chitra K. Subramanian, Kyu-Hyoun Kim, Hillery C. Hunter, M. B. Srinivas
2019 J jnl
Signal Image Video Process.
Avinash S. Vaidya, M. B. Srinivas
2019 J jnl
J. Signal Process. Syst.
Syed Ershad Ahmed, M. B. Srinivas
2019 J jnl
Circuits Syst. Signal Process.
Goutham Makkena, M. B. Srinivas
2018 J jnl
IEEE J. Solid State Circuits
Veeresh Babu Vulligaddala, Ravikumar Adusumalli, Sudhakar Singamala, M. B. Srinivas
2018 Misc conf
VLSID
Mahesh Kumar Adimulam, Amit Kapoor, Sreehari Veeramachaneni, M. B. Srinivas
2018 conf
ISMVL
Chetan Kumar Vudadha, M. B. Srinivas
2018 conf
iSES
Linga Reddy Cenkeramaddi, Ashish Goyal, Asheesh Bhuria, M. B. Srinivas, J. Soumya
2018 J jnl
Microelectron. J.
Chetan Kumar Vudadha, Sai Phaneendra Parlapalli, M. B. Srinivas
2018 J jnl
Integr.
Syed Ershad Ahmed, Ch. Santosh Varma, M. B. Srinivas
2018 J jnl
Circuits Syst. Signal Process.
Goutham Makkena, M. B. Srinivas
2018 J jnl
IEEE Trans. Circuits Syst. I Regul. Pap.
Chetan Kumar Vudadha, Ajay Surya, Saurabh Agrawal, M. B. Srinivas
2017 conf
ISVLSI
Mahesh Kumar Adimulam, Krishna Kumar Movva, K. Kolluru, M. B. Srinivas
2017 Misc conf
VLSID
Anjali Gopinath, Ravi Kumar Adusumalli, Veeresh Babu Vulligaddala, M. B. Srinivas
2017 conf
EMBC
Mahesh Kumar Adimulam, Adimulam Divya, K. Tejaswi, M. B. Srinivas
2017 conf
SoCC
Mahesh Kumar Adimulam, Krishna Kumar Movva, M. B. Srinivas
2017 C conf
VLSI-SoC
Mahesh Kumar Adimulam, Krishna Kumar Movva, Amit Kapoor, M. B. Srinivas
2017 C conf
RC
Sai Phaneendra Parlapalli, Chetan Kumar Vudadha, M. B. Srinivas
2017 C conf
RC
Sai Phaneendra Parlapalli, Chetan Kumar Vudadha, M. B. Srinivas
2017 conf
SoCC
M. B. Srinivas
2017 conf
MobiHealth
Mahesh Kumar Adimulam, M. B. Srinivas
2016 Misc conf
VLSID
Syed Ershad Ahmed, S. Sweekruth Srinivas, M. B. Srinivas
2016 J jnl
Int. J. Bus. Data Commun. Netw.
Rakhee, M. B. Srinivas
2016 conf
iNIS
Chetan Kumar Vudadha, P. Sai Phaneendra, M. B. Srinivas
2016 C conf
ARITH
Syed Ershad Ahmed, Sanket Kadam, M. B. Srinivas
2016 conf
CISP-BMEI
Mahesh Kumar Adimulam, M. B. Srinivas
2014 Misc conf
VLSID
Ch. Santosh Varma, Syed Ershad Ahmed, M. B. Srinivas
2014 Misc conf
VLSID
B. Naveen Kumar Reddy, M. Chandra Sekhar, Sreehari Veeramachaneni, M. B. Srinivas
2014 conf
SoCC
Abhilash K. N, M. B. Srinivas
2014 conf
APCCAS
Soumya Ganguly, Abhishek Mittal, Syed Ershad Ahmed, M. B. Srinivas
2014 Misc conf
VLSID
P. Sai Phaneendra, Chetan Kumar Vudadha, Sreehari Veeramachaneni, M. B. Srinivas
2014 conf
BIODEVICES
Avinash S. Vaidya, T. S. L. Radhika, M. B. Srinivas, Mannan Mridha
2013 conf
EMBC
Avinash S. Vaidya, M. B. Srinivas, P. Himabindu, Daria Jumaxanova
2013 conf
EMBC
Goutham Makkena, Prabhakara Rao, M. B. Srinivas
2012 conf
ISED
Syed Ershad Ahmed, Sibi Abraham, Sreehari Veeramachaneni, N. Moorthy Muthukrishnan, M. B. Srinivas
2012 conf
ISCIT
Chetan Kumar Vudadha, Phaneendra P. Sai, Sreehari Veeramachaneni, M. B. Srinivas
2012 Misc conf
VLSI Design
Chetan Kumar Vudadha, Goutham Makkena, M. Venkata Swamy Nayudu, P. Sai Phaneendra, Syed Ershad Ahmed, Sreehari Veeramachaneni, N. Moorthy Muthukrishnan, M. B. Srinivas
2012 conf
CyberC
Santosh Kumar Jena, M. B. Srinivas
2011 conf
ISED
Mahesh Kumar Adimulam, Krishna Kumar Movva, Sreehari Veeramachaneni, N. Moorthy Muthukrishnan, M. B. Srinivas
2011 conf
ISVLSI
Chetan Kumar V., Sai Phaneendra P., Syed Ershad Ahmed, Sreehari Veeramachaneni, N. Moorthy Muthukrishnan, M. B. Srinivas
2011 conf
ISED
Chetan Kumar V., P. Sai Phaneendra, Syed Ershad Ahmed, Sreehari Veeramachaneni, N. Moorthy Muthukrishnan, M. B. Srinivas
2011 C conf
DSD
Chetan Kumar V., P. Sai Phaneendra, Syed Ershad Ahmed, Sreehari Veeramachaneni, N. Moorthy Muthukrishnan, M. B. Srinivas
2011 conf
ISCIT
P. Sai Phaneendra, Chetan Kumar Vudadha, Syed Ershad Ahmed, Sreehari Veeramachaneni, N. Moorthy Muthukrishnan, M. B. Srinivas
2010 conf
ISVLSI
Mahesh Kumar Adimulam, Sreehari Veeramachaneni, N. Moorthy Muthukrishnan, M. B. Srinivas
2010 conf
ACM Great Lakes Symposium on VLSI
Mahesh Kumar Adimulam, Krishna Kumar Movva, Sreehari Veeramachaneni, N. Moorthy Muthukrishnan, M. B. Srinivas
2010 conf
ICWET
Pradeep Jamwal, M. B. Srinivas, G. V. K. Sarma, M. Murali Krishna
2010 J jnl
J. Low Power Electron.
Sandeep Saini, A. Mahesh Kumar, Sreehari Veeramachaneni, M. B. Srinivas
2010 Misc conf
VLSI Design
Sandeep Saini, Mahesh Kumar Adimulam, Sreehari Veeramachaneni, M. B. Srinivas
2010 conf
APCCAS
Gudipati Kalyan, M. B. Srinivas
2009 conf
ISVLSI
Anshul Singh, Aman Gupta, Sreehari Veeramachaneni, M. B. Srinivas
2009 J jnl
J. Low Power Electron.
Mahesh Kumar Adimulam, Sreehari Veeramachaneni, M. B. Srinivas
2009 conf
SoCC
Mahesh Kumar Adimulam, Sreehari Veeramachaneni, M. B. Srinivas
2009 conf
ISVLSI
Swathi Ramasahayam, M. B. Srinivas
2009 Misc conf
VLSI Design
Sreehari Veeramachaneni, Mahesh Kumar Adimulam, Venkat Tummala, M. B. Srinivas
2009 J jnl
Trans. Comput. Sci.
Himanshu Thapliyal, Hamid R. Arabnia, M. B. Srinivas
2009 B conf
IWCMC
Vasanth Iyer, S. Sitharama Iyengar, Garimella Rama Murthy, Bertrand Hochet, Vir V. Phoha, M. B. Srinivas
2008 Misc conf
VLSI Design
Sreehari Veeramachaneni, Kirthi M. Krishna, Prateek G. V., Subroto S., Bharat S., M. B. Srinivas
2008 conf
ISVLSI
Lingamneni Avinash, Kirthi Krishna Muntimadugu, M. B. Srinivas
2008 conf
ACM Great Lakes Symposium on VLSI
J. V. R. Ravindra, M. B. Srinivas
2008 conf
ISQED
Chittarsu Raghunandan, K. S. Sainarayanan, M. B. Srinivas
2008 conf
SUTC
Vasanth Iyer, Rammurthy Garimella, M. B. Srinivas
2007 conf
SAMOS
Shashank Mittal, Md. Zafar Ali Khan, M. B. Srinivas
2007 C conf
DSD
J. V. R. Ravindra, M. B. Srinivas
2007 Misc conf
VLSI Design
M. Sudhakar, Ramachandruni Venkata Kamala, M. B. Srinivas
2007 C conf
VLSI-SoC
M. Sudhakar, Ramachandruni Venkata Kamala, M. B. Srinivas
2007 conf
SBCCI
Sudhakar Maddi, M. B. Srinivas
2007 C conf
ISCAS
Chittarsu Raghunandan, K. S. Sainarayanan, M. B. Srinivas
2007 B conf
GLOBECOM
Shashank Mittal, Md. Zafar Ali Khan, M. B. Srinivas
2007 conf
SBCCI
K. S. Sainarayanan, Chittarsu Raghunandan, M. B. Srinivas
2007 conf
ACM Great Lakes Symposium on VLSI
Chittarsu Raghunandan, K. S. Sainarayanan, M. B. Srinivas
2007 J jnl
J. Circuits Syst. Comput.
J. V. R. Ravindra, M. B. Srinivas
2007 conf
ISVLSI
K. S. Sainarayanan, Chittarsu Raghunandan, M. B. Srinivas
2007 conf
Nano-Net
J. V. R. Ravindra, M. B. Srinivas
2007 J jnl
Mob. Networks Appl.
M. Sudhakar, Ramachandruni Venkata Kamala, M. B. Srinivas
2007 Misc conf
VLSI Design
Sreehari Veeramachaneni, Kirthi M. Krishna, Lingamneni Avinash, Reddy Puppala Sreekanth, M. B. Srinivas
2007 C conf
ISCAS
Sreehari Veeramachaneni, Kirthi M. Krishna, Lingamneni Avinash, Reddy Puppala Sreekanth, M. B. Srinivas
2007 conf
ACM Great Lakes Symposium on VLSI
Sreehari Veeramachaneni, Lingamneni Avinash, Kirthi M. Krishna, M. B. Srinivas
2007 conf
ISVLSI
Sreehari Veeramachaneni, Kirthi M. Krishna, Lingamneni Avinash, Reddy Puppala Sreekanth, M. B. Srinivas
2007 conf
FOCI
Keerthi Laal Kala, M. B. Srinivas
2006 conf
APCCAS
Keerthi Laal Kala, M. B. Srinivas
2006 J jnl
CoRR
Himanshu Thapliyal, M. B. Srinivas
2006 C conf
ISCAS
K. S. Sainarayanan, J. V. R. Ravindra, M. B. Srinivas
2006 C conf
DSD
Ramachandruni Venkata Kamala, M. Sudhakar, M. B. Srinivas
2006 J jnl
CoRR
Himanshu Thapliyal, M. B. Srinivas
2006 C conf
VLSI-SoC
Ramachandruni Venkata Kamala, M. B. Srinivas
2006 C conf
AICCSA
Himanshu Thapliyal, Neela Gopi, K. K. Pavan Kumar, M. B. Srinivas
2006 conf
DELTA
K. S. Sainarayanan, J. V. R. Ravindra, M. B. Srinivas
2006 conf
DELTA
Himanshu Thapliyal, Anvesh Ramasahayam, Vivek Reddy Kotha, Kunul Gottimukkula, M. B. Srinivas
2006 J jnl
CoRR
Himanshu Thapliyal, Saurabh Kotiyal, M. B. Srinivas
2006 Misc conf
VLSI Design
Himanshu Thapliyal, Saurabh Kotiyal, M. B. Srinivas
2006 J jnl
CoRR
Himanshu Thapliyal, M. B. Srinivas
2006 C conf
AICCSA
Himanshu Thapliyal, M. B. Srinivas
2006 J jnl
CoRR
Himanshu Thapliyal, M. B. Srinivas
2006 A conf
ESA
Pallavi Devi Gopineedi, Himanshu Thapliyal, M. B. Srinivas, Hamid R. Arabnia
2006 J jnl
CoRR
Himanshu Thapliyal, Hamid R. Arabnia, M. B. Srinivas
2006 conf
Asia-Pacific Computer Systems Architecture Conference
Himanshu Thapliyal, M. B. Srinivas
2006 J jnl
CoRR
Himanshu Thapliyal, M. B. Srinivas
2005 conf
ICNC (3)
Keerthi Laal Kala, M. B. Srinivas
2005 A conf
ESA
Himanshu Thapliyal, M. B. Srinivas, Hamid R. Arabnia
2005 conf
Asia-Pacific Computer Systems Architecture Conference
Himanshu Thapliyal, M. B. Srinivas
2005 A conf
ESA
Himanshu Thapliyal, M. B. Srinivas, Hamid R. Arabnia
2005 conf
Circuits, Signals, and Systems
K. S. Sainarayanan, J. V. R. Ravindra, M. B. Srinivas
2005 conf
AMCS
Himanshu Thapliyal, M. B. Srinivas, Hamid R. Arabnia
2005 conf
CDES
Himanshu Thapliyal, M. B. Srinivas, Hamid R. Arabnia
2005 conf
Security and Management
Himanshu Thapliyal, M. B. Srinivas, Hamid R. Arabnia
2005 conf
Security and Management
Himanshu Thapliyal, M. B. Srinivas, Hamid R. Arabnia
2005 conf
ITCC (2)
Yaswanth Narvaneni, M. B. Srinivas
2005 A conf
ESA
Himanshu Thapliyal, M. B. Srinivas, Hamid R. Arabnia
2005 conf
CSC
Saurabh Kotiyal, Himanshu Thapliyal, M. B. Srinivas, Hamid R. Arabnia
2005 conf
CDES
Himanshu Thapliyal, M. B. Srinivas, Rameshwar Rao, Hamid R. Arabnia
2003 conf
ASP-DAC
I. Vijay Kumar, M. B. Srinivas
2003 conf
ASP-DAC
K. Kalyan Chakravarthy, M. B. Srinivas
tests/unit/test_decompile_medium_level.py
← Index tests/unit/test_decompile_medium_level.py python
# tests/unit/test_decompile_medium_level.py
"""Unit tests (mocked BN) for bninja/analysis/medium_level.py
   and bninja/analysis/medium_level_normalization.py."""
# tests/unit/test_decompile_medium_level.py
import sys
from unittest.mock import MagicMock, patch

# Installa gli stubs BN
from tests.unit.conftest_binja_stubs import install_binja_stubs
install_binja_stubs()

# ── Definisci MockMLILInstruction PRIMA di importare il modulo ──
class MockMLILInstruction:
    def __init__(self, operation, address=0, operands=None):
        self.operation = operation
        self.address = address
        self.operands = operands or []

# ── Patcha il modulo BN in modo che isinstance() funzioni ──
sys.modules["binaryninja"].MediumLevelILInstruction = MockMLILInstruction
sys.modules["binaryninja"].SSAVariable = type("SSAVariable", (), {})
sys.modules["binaryninja"].Variable = type("Variable", (), {})
sys.modules["binaryninja"].ILIntrinsic = type("ILIntrinsic", (), {})

# Ora importa il modulo — vede già i tipi corretti
from redb.extractors.decompiler.bninja.analysis.medium_level_normalization import (
    MediumLevelNormalization,
)	

class MockMLILFunction:
    def __init__(self, instructions):
        self._instructions = instructions

    @property
    def instructions(self):
        return iter(self._instructions)

    @property
    def basic_blocks(self):
        # one block containing all instructions, good enough for MinHasher
        block = MagicMock()
        block.__iter__ = lambda self_: iter([])  # not used by MediumLevelAnalysis
        return [block]


class MockFunction:
    def __init__(self, name="func", start=0x1000, mlil=None):
        self.name = name
        self.start = start
        self.mlil = mlil



class TestMediumLevelNormalization:
    def setup_method(self):
        from redb.extractors.decompiler.bninja.analysis.medium_level_normalization import (
            MediumLevelNormalization,
        )
        self.norm = MediumLevelNormalization()

    def test_normalize_skeleton_single_instruction(self):
        il = MockMLILInstruction(operation=42, operands=[])
        result = self.norm.normalize_instruction_all_levels(il)
        assert result == [42]

    def test_normalize_skeleton_nested(self):
        inner = MockMLILInstruction(operation=7, operands=[])
        outer = MockMLILInstruction(operation=1, operands=[inner])
        result = self.norm.normalize_instruction_all_levels(outer)
        assert result == [1, 7]

    def test_normalize_skeleton_with_list_operand(self):
        inner_a = MockMLILInstruction(operation=10, operands=[])
        inner_b = MockMLILInstruction(operation=11, operands=[])
        outer = MockMLILInstruction(operation=2, operands=[[inner_a, inner_b]])
        result = self.norm.normalize_instruction_all_levels(outer)
        assert result == [2, 10, 11]

    def test_normalize_skeleton_none(self):
        result = self.norm.normalize_instruction_all_levels(None)
        # collect on None should leave ops empty
        assert result == []

    def test_normalize_typed_appends_leaf_types(self):
        # operand is a plain int -> "CONST"
        il = MockMLILInstruction(operation=3, operands=[42])
        result = self.norm.normalize_instr_with_operands(il)
        assert result == [3, "CONST"]

    def test_normalize_typed_bool_before_int(self):
        # bool must be detected before int (since bool is an int subclass)
        il = MockMLILInstruction(operation=4, operands=[True])
        result = self.norm.normalize_instr_with_operands(il)
        assert result == [4, "BOOL"]

    def test_normalize_typed_float(self):
        il = MockMLILInstruction(operation=5, operands=[1.5])
        result = self.norm.normalize_instr_with_operands(il)
        assert result == [5, "FLOAT_CONST"]

    def test_normalize_typed_str(self):
        il = MockMLILInstruction(operation=6, operands=["hello"])
        result = self.norm.normalize_instr_with_operands(il)
        assert result == [6, "STR"]

    def test_normalize_typed_unknown_falls_back_to_typename(self):
        class Weird:
            pass
        il = MockMLILInstruction(operation=8, operands=[Weird()])
        result = self.norm.normalize_instr_with_operands(il)
        assert result == [8, "WEIRD"]

    def test_normalize_typed_nested_mlil(self):
        inner = MockMLILInstruction(operation=99, operands=[7])
        outer = MockMLILInstruction(operation=1, operands=[inner])
        result = self.norm.normalize_instr_with_operands(outer)
        assert result == [1, 99, "CONST"]

    def test_normalize_typed_list_mixed(self):
        inner = MockMLILInstruction(operation=50, operands=[])
        il = MockMLILInstruction(operation=2, operands=[[inner, 99]])
        result = self.norm.normalize_instr_with_operands(il)
        assert result == [2, 50, "CONST"]


class TestMediumLevelAnalysis:
    def _make_analysis(self, instructions=None, mlil=True, start=0x1000):
        from redb.extractors.decompiler.bninja.analysis.medium_level import (
            MediumLevelAnalysis,
        )
        mlil_func = MockMLILFunction(instructions or []) if mlil else None
        func = MockFunction(name="testfunc", start=start, mlil=mlil_func)
        bv = MagicMock()
        return MediumLevelAnalysis(func, bv, MagicMock())

    def test_collect_returns_empty_when_no_mlil(self):
        a = self._make_analysis(mlil=False)
        sk, sk_addr, ty, ty_addr = a._collect_mlil_skeleton_and_typed()
        assert sk == [] and sk_addr == [] and ty == [] and ty_addr == []

    def test_collect_skeleton_and_typed_basic(self):
        instrs = [
            MockMLILInstruction(operation=1, address=0x1000, operands=[]),
            MockMLILInstruction(operation=2, address=0x1004, operands=[42]),
        ]
        a = self._make_analysis(instructions=instrs, start=0x1000)
        sk, sk_addr, ty, ty_addr = a._collect_mlil_skeleton_and_typed()

        assert sk == [[1], [2]]
        assert ty == [[1], [2, "CONST"]]
        assert sk_addr == [(0, [1]), (4, [2])]
        assert ty_addr == [(0, [1]), (4, [2, "CONST"])]

    def test_collect_negative_offset_clamped_to_zero(self):
        instrs = [
            MockMLILInstruction(operation=1, address=0x900, operands=[]),
        ]
        a = self._make_analysis(instructions=instrs, start=0x1000)
        _, sk_addr, _, ty_addr = a._collect_mlil_skeleton_and_typed()
        assert sk_addr[0][0] == 0
        assert ty_addr[0][0] == 0

    def test_log_error_records_entry(self):
        a = self._make_analysis()
        a.log_error("boom", "fname", 0x1234, ValueError("x"), "loc")
        assert len(a.errors) == 1
        err = a.errors[0]
        assert err["function_name"] == "fname"
        assert err["function_address"] == "4660"  # hex 0x1234
        assert err["error_location"] == "loc"
        assert err["error_message"] == "boom"
        assert err["error_type"] == "ValueError"
        assert "timestamp" in err

    @patch(
        "redb.extractors.decompiler.bninja.analysis.medium_level.MinHasher"
    )
    def test_analyze_returns_expected_keys(self, mock_minhasher):
        mock_minhasher.return_value.calculateMinHash.return_value = [1, 2, 3]

        instrs = [
            MockMLILInstruction(operation=1, address=0x1000, operands=[]),
            MockMLILInstruction(operation=2, address=0x1004, operands=[42]),
            MockMLILInstruction(operation=3, address=0x1008, operands=[]),
        ]
        a = self._make_analysis(instructions=instrs, start=0x1000)
        result, errors = a.analyze()

        expected_keys = {
            "function_address",
            "body_mlil_skeleton_vector",
            "sha256_mlil_skeleton",
            "tlsh_mlil_skeleton",
            "minhash_mlil_skeleton",
            "body_mlil_typed_vector",
            "sha256_mlil_typed",
            "tlsh_mlil_typed",
            "minhash_mlil_typed",
        }
        assert set(result.keys()) == expected_keys
        assert result["function_address"] == 0x1000
        assert result["minhash_mlil_skeleton"] == [1, 2, 3]
        assert result["minhash_mlil_typed"] == [1, 2, 3]
        assert errors == []

    @patch(
        "redb.extractors.decompiler.bninja.analysis.medium_level.MinHasher"
    )
    def test_analyze_empty_mlil(self, mock_minhasher):
        mock_minhasher.return_value.calculateMinHash.return_value = []
        a = self._make_analysis(mlil=False)
        result, errors = a.analyze()
        assert result["body_mlil_skeleton_vector"] == []
        assert result["body_mlil_typed_vector"] == []
        assert errors == []

    @patch(
        "redb.extractors.decompiler.bninja.analysis.medium_level.MinHasher"
    )
    def test_analyze_sha256_differs_skeleton_vs_typed(self, mock_minhasher):
        mock_minhasher.return_value.calculateMinHash.return_value = []

        instrs = [
            MockMLILInstruction(operation=1, address=0x1000, operands=[42]),
            MockMLILInstruction(operation=2, address=0x1004, operands=["foo"]),
            MockMLILInstruction(operation=3, address=0x1008, operands=[True]),
        ]
        a = self._make_analysis(instructions=instrs)
        result, _ = a.analyze()
        # skeleton ignores operand leaves, typed includes them -> different hashes
        assert result["sha256_mlil_skeleton"] != result["sha256_mlil_typed"]


class TestMinHasherMLILKinds:
    def _make_func(self, instrs):
        # MinHasher iterates basic_blocks then over each block
        block = MagicMock()
        block.__iter__ = lambda self_: iter(instrs)
        f = MagicMock()
        f.basic_blocks = [block]
        return f

    def test_mlil_skeleton_uses_medium_normalizer(self):
        from redb.extractors.decompiler.bninja.similarity.minhasher import (
            MinHasher, TokenKind,
        )
        instrs = [
            MockMLILInstruction(operation=i, operands=[]) for i in range(5)
        ]
        func = self._make_func(instrs)
        hasher = MinHasher(seed=42, il_function=func, kind=TokenKind.MLIL)
        result = hasher.calculateMinHash()
        # 5 instructions -> 3 trigrams -> non-empty signature
        assert result != []

    def test_typed_mlil_differs_from_skeleton(self):
        from redb.extractors.decompiler.bninja.similarity.minhasher import (
            MinHasher, TokenKind,
        )
        instrs = [
            MockMLILInstruction(operation=1, operands=[42]),
            MockMLILInstruction(operation=2, operands=["s"]),
            MockMLILInstruction(operation=3, operands=[True]),
            MockMLILInstruction(operation=4, operands=[1.5]),
        ]
        func = self._make_func(instrs)
        skel = MinHasher(seed=42, il_function=func, kind=TokenKind.MLIL).calculateMinHash()
        typed = MinHasher(seed=42, il_function=func, kind=TokenKind.TYPED_MLIL).calculateMinHash()
        # Same seed, same instructions, but typed has extra leaf tokens
        # -> hashes should generally differ
        assert skel != typed

    def test_mlil_too_few_instructions(self):
        from redb.extractors.decompiler.bninja.similarity.minhasher import (
            MinHasher, TokenKind,
        )
        instrs = [MockMLILInstruction(operation=1, operands=[])] * 2
        func = self._make_func(instrs)
        hasher = MinHasher(seed=42, il_function=func, kind=TokenKind.MLIL)
        assert hasher.calculateMinHash() == []

    def test_unsupported_kind_raises(self):
        from redb.extractors.decompiler.bninja.similarity.minhasher import MinHasher
        func = self._make_func([])
        hasher = MinHasher(seed=42, il_function=func, kind="bogus")
        with pytest.raises(ValueError):
            hasher.calculateMinHash()