Nathan S. Netanyahu

138 papers A* 10A 6B 5C 12Journal 70Unranked 28
YearRankTypeTitle / Venue / Authors
2026 J jnl
CoRR
Eli Passov, Nathan S. Netanyahu, Yosi Keller
2026 J jnl
CoRR
Ido Faran, Nathan S. Netanyahu, Maxim Shoshany
2025 J jnl
CoRR
Daniel Rika, Dror Sholomon, Eli David, Alexandre Pais, Nathan S. Netanyahu
2025 conf
ICANN (2)
Doron Nevo, Eli David, Nathan S. Netanyahu
2025 conf
ICDAR (Workshops 2)
Guy Gisfan, Eli (Omid) David, Nathan S. Netanyahu
2025 C conf
ICPRAM
Ido Faran, Nathan S. Netanyahu, Elena Roitberg, Maxim Shoshany
2023 J jnl
CoRR
Steven Zvi Lapp, Eli David, Nathan S. Netanyahu
2023 J jnl
CoRR
Ella Eidlin, Assaf Hoogi, Nathan S. Netanyahu
2023 B conf
IJCNN
Itay Mosafi, Eli David, Nathan S. Netanyahu
2022 J jnl
Entropy
Itay Mosafi, Eli (Omid) David, Yaniv Altshuler, Nathan S. Netanyahu
2022 conf
ICANN (4)
Doron Nevo, Eli (Omid) David, Nathan S. Netanyahu
2022 J jnl
CoRR
Daniel Rika, Dror Sholomon, Eli David, Nathan S. Netanyahu
2022 J jnl
CoRR
Eli Passov, Eli (Omid) David, Nathan S. Netanyahu
2022 J jnl
CoRR
Daniel Rika, Dror Sholomon, Eli David, Nathan S. Netanyahu
2021 conf
ICANN (3)
Nelly David, Nathan S. Netanyahu
2021 J jnl
Big Data Cogn. Comput.
Alina Raphael, Zvy Dubinsky, Nathan S. Netanyahu, David Iluz
2021 conf
ICANN (4)
Eli Passov, Eli David, Nathan S. Netanyahu
2020 C conf
IGARSS
Ido Faran, Nathan S. Netanyahu, Eli David, Ronit Rud, Maxim Shoshany
2019 J jnl
CoRR
Daniel Rika, Dror Sholomon, Eli David, Nathan S. Netanyahu
2019 A conf
GECCO
Daniel Rika, Dror Sholomon, Eli (Omid) David, Nathan S. Netanyahu
2019 J jnl
CoRR
Katia Huri, Eli David, Nathan S. Netanyahu
2019 conf
ICANN (Workshop)
Itay Mosafi, Eli (Omid) David, Nathan S. Netanyahu
2019 J jnl
CoRR
Itay Mosafi, Eli David, Nathan S. Netanyahu
2019 C conf
IGARSS
Ido Faran, Nathan S. Netanyahu, Eli (Omid) David, Maxim Shoshany, Fadi Kizel, Jisung Geba Chang, Ronit Rud
2019 J jnl
CoRR
Ido Faran, Nathan S. Netanyahu, Eli David, Maxim Shoshany, Fadi Kizel, Jisung Geba Chang, Ronit Rud
2019 J jnl
CoRR
Evyatar Illouz, Eli David, Nathan S. Netanyahu
2019 B conf
IJCNN
Itay Mosafi, Eli (Omid) David, Nathan S. Netanyahu
2019 J jnl
CoRR
Itay Mosafi, Eli David, Nathan S. Netanyahu
2019 J jnl
CoRR
Ido Cohen, Eli David, Nathan S. Netanyahu
2019 J jnl
Entropy
Ido Cohen, Eli (Omid) David, Nathan S. Netanyahu
2018 conf
ICANN (3)
Katia Huri, Eli (Omid) David, Nathan S. Netanyahu
2018 conf
ICANN (3)
Evyatar Illouz, Eli (Omid) David, Nathan S. Netanyahu
2017 J jnl
CoRR
Dror Sholomon, Eli David, Nathan S. Netanyahu
2017 J jnl
CoRR
Dror Sholomon, Eli David, Nathan S. Netanyahu
2017 J jnl
IEEE Trans. Geosci. Remote. Sens.
Fadi Kizel, Maxim Shoshany, Nathan S. Netanyahu, Gilad Even-Tzur, Jón Atli Benediktsson
2017 J jnl
CoRR
Sarit Chicotay, Eli David, Nathan S. Netanyahu
2017 conf
GECCO (Companion)
Sarit Chicotay, Eli (Omid) David, Nathan S. Netanyahu
2017 J jnl
CoRR
Dror Sholomon, Eli David, Nathan S. Netanyahu
2017 J jnl
CoRR
Dror Sholomon, Eli David, Nathan S. Netanyahu
2017 conf
ICANN (2)
Ido Cohen, Eli (Omid) David, Nathan S. Netanyahu, Noa Liscovitch, Gal Chechik
2017 J jnl
CoRR
Ido Cohen, Eli David, Nathan S. Netanyahu, Noa Liscovitch, Gal Chechik
2017 J jnl
CoRR
Eli David, Nathan S. Netanyahu, Lior Wolf
2017 J jnl
CoRR
Eli David, Nathan S. Netanyahu
2017 J jnl
CoRR
Eli David, Nathan S. Netanyahu
2017 J jnl
CoRR
Eli David, Moshe Koppel, Nathan S. Netanyahu
2017 J jnl
CoRR
Dror Sholomon, Eli David, Nathan S. Netanyahu
2017 J jnl
CoRR
Eli David, H. Jaap van den Herik, Moshe Koppel, Nathan S. Netanyahu
2017 J jnl
CoRR
Eli David, Moshe Koppel, Nathan S. Netanyahu
2017 J jnl
CoRR
Sarit Chicotay, Eli David, Nathan S. Netanyahu
2017 J jnl
CoRR
Eli David, H. Jaap van den Herik, Moshe Koppel, Nathan S. Netanyahu
2016 J jnl
Comput. Stat. Data Anal.
David M. Mount, Nathan S. Netanyahu, Christine D. Piatko, Angela Y. Wu, Ruth Silverman
2016 J jnl
Genet. Program. Evolvable Mach.
Dror Sholomon, Omid E. David, Nathan S. Netanyahu
2016 conf
ICANN (2)
Dror Sholomon, Omid E. David, Nathan S. Netanyahu
2016 conf
ICANN (2)
Omid E. David, Nathan S. Netanyahu, Lior Wolf
2016 conf
ICANN (2)
Omid E. David, Nathan S. Netanyahu
2015 J jnl
IEEE Geosci. Remote. Sens. Lett.
Benny Kupfer, Nathan S. Netanyahu, Ilan Shimshoni
2015 B conf
IJCNN
Omid E. David, Nathan S. Netanyahu
2015 C conf
IGARSS
Fadi Kizel, Maxim Shoshany, Nathan S. Netanyahu
2014 A* conf
AAAI
Dror Sholomon, Omid E. David, Nathan S. Netanyahu
2014 J jnl
IEEE Trans. Evol. Comput.
Omid E. David, H. Jaap van den Herik, Moshe Koppel, Nathan S. Netanyahu
2014 A conf
GECCO
Dror Sholomon, Omid E. David, Nathan S. Netanyahu
2014 A conf
GECCO
Erez Levy, Omid E. David, Nathan S. Netanyahu
2014 conf
CVPR Workshops
Sarit Chicotay, Omid E. David, Nathan S. Netanyahu
2014 J jnl
Algorithmica
David M. Mount, Nathan S. Netanyahu, Christine D. Piatko, Ruth Silverman, Angela Y. Wu
2014 J jnl
ICGA J.
Omid E. David, H. Jaap van den Herik, Moshe Koppel, Nathan S. Netanyahu
2013 A* conf
CVPR
Dror Sholomon, Omid David, Nathan S. Netanyahu
2013 A conf
GECCO
Eliyahu Kiperwasser, Omid David, Nathan S. Netanyahu
2013 C conf
IGARSS
Benny Kupfer, Nathan S. Netanyahu, Ilan Shimshoni
2013 B conf
IEEE Congress on Evolutionary Computation
Erez Levy, Omid David, Nathan S. Netanyahu
2012 conf
ACCV Workshops (2)
Shahar Daliyot, Nathan S. Netanyahu
2011 J jnl
IEEE Geosci. Remote. Sens. Lett.
Maxim Shoshany, Fadi Kizel, Nathan S. Netanyahu, Naftali Goldshlager, Thomas Jarmer, Gilad Even-Tzur
2011 ch.
Image Registration for Remote Sensing
Jacqueline Le Moigne, Nathan S. Netanyahu, Roger D. Eastman
2011 J jnl
Genet. Program. Evolvable Mach.
Omid David-Tabibi, Moshe Koppel, Nathan S. Netanyahu
2011 conf
ICHIT (1)
Omid David, Nathan S. Netanyahu, Yoav Rosenberg
2011 book
Image Registration for Remote Sensing
Jacqueline Le Moigne, Nathan S. Netanyahu, Roger D. Eastman
2011 ch.
Image Registration for Remote Sensing
Jacqueline Le Moigne, Nathan S. Netanyahu, Roger D. Eastman
2011 ch.
Image Registration for Remote Sensing
Jacqueline Le Moigne, Arlene A. Cole-Rhodes, Roger D. Eastman, Nathan S. Netanyahu, Harold S. Stone, Ilya Zavorin, Jeffrey T. Morisette
2011 ch.
Image Registration for Remote Sensing
David M. Mount, Nathan S. Netanyahu, San Ratanasanya
2011 J jnl
CoRR
Asaph Ben-Yair, Ariel Felner, Sarit Kraus, Nathan S. Netanyahu, Roni Stern
2011 ch.
Image Registration for Remote Sensing
Roger D. Eastman, Nathan S. Netanyahu, Jacqueline Le Moigne
2010 J jnl
ICGA J.
Omid David-Tabibi, Moshe Koppel, Nathan S. Netanyahu
2010 conf
GECCO (Companion)
Omid David-Tabibi, Nathan S. Netanyahu, Yoav Rosenberg, Moshe Shimoni
2010 J jnl
CoRR
Omid David-Tabibi, Moshe Koppel, Nathan S. Netanyahu
2009 A conf
GECCO
Omid David-Tabibi, H. Jaap van den Herik, Moshe Koppel, Nathan S. Netanyahu
2008 conf
Computers and Games
Omid David-Tabibi, Nathan S. Netanyahu
2008 A conf
GECCO
Omid David-Tabibi, Moshe Koppel, Nathan S. Netanyahu
2008 J jnl
CoRR
Omid David-Tabibi, Nathan S. Netanyahu
2007 J jnl
Int. J. Comput. Geom. Appl.
Nargess Memarsadeghi, David M. Mount, Nathan S. Netanyahu, Jacqueline Le Moigne
2007 J jnl
Comput. Stat. Data Anal.
David M. Mount, Nathan S. Netanyahu, Kathleen Romanik, Ruth Silverman, Angela Y. Wu
2007 C conf
IGARSS
Antonio J. Plaza, Jacqueline Le Moigne, Nathan S. Netanyahu
2007 A* conf
CVPR
Roger D. Eastman, Jacqueline Le Moigne, Nathan S. Netanyahu
2006 ed.
Computers and Games
H. Jaap van den Herik, Yngvi Björnsson, Nathan S. Netanyahu
2006 conf
ICASSP (5)
Jacqueline Le Moigne, Arlene A. Cole-Rhodes, Roger D. Eastman, Peyush Jain, Aimee Joshua, Nargess Memarsadeghi, David M. Mount, Nathan S. Netanyahu, Jeffrey T. Morisette, Ezinne Uko-Ozoro
2004 conf
SCG
David M. Mount, Nathan S. Netanyahu, Christine D. Piatko, Ruth Silverman, Angela Y. Wu
2004 J jnl
Comput. Geom.
Tapas Kanungo, David M. Mount, Nathan S. Netanyahu, Christine D. Piatko, Ruth Silverman, Angela Y. Wu
2004 C conf
IGARSS
Jacqueline Le Moigne, Jeffrey T. Morisette, Arlene A. Cole-Rhodes, Kisha L. Johnson, Nathan S. Netanyahu, Roger D. Eastman, Harold S. Stone, Ilya Zavorin, Peyush Jain
2004 J jnl
ICGA J.
Omid David-Tabibi, Ariel Felner, Nathan S. Netanyahu
2004 conf
Computers and Games
Omid David-Tabibi, Ariel Felner, Nathan S. Netanyahu
2004 J jnl
IEEE Trans. Geosci. Remote. Sens.
Nathan S. Netanyahu, Jacqueline Le Moigne, Jeffrey G. Masek
2004 J jnl
J. Artif. Intell. Res.
Ariel Felner, Roni Stern, Sarit Kraus, Asaph Ben-Yair, Nathan S. Netanyahu
2004 conf
VisSym
Amihood Amir, Reuven Kashi, Daniel A. Keim, Nathan S. Netanyahu, Markus Wawryniuk
2003 C conf
IGARSS
Nargess Memarsadeghi, David M. Mount, Nathan S. Netanyahu, Jacqueline Le Moigne
2003 A* conf
ICDM
Amihood Amir, Reuven Kashi, Nathan S. Netanyahu, Daniel A. Keim, Markus Wawryniuk
2003 C conf
IGARSS
Jacqueline Le Moigne, Jeffrey T. Morisette, Arlene A. Cole-Rhodes, Nathan S. Netanyahu, Roger D. Eastman, Harold S. Stone
2003 A* conf
ICDM
Amihood Amir, Reuven Kashi, Nathan S. Netanyahu
2003 C conf
IGARSS
Lior Friedman, Nathan S. Netanyahu, Maxim Shoshany
2002 conf
SCG
Tapas Kanungo, David M. Mount, Nathan S. Netanyahu, Christine D. Piatko, Ruth Silverman, Angela Y. Wu
2002 C conf
IGARSS
Idan Feldberg, Nathan S. Netanyahu, Maxim Shoshany
2002 J jnl
IEEE Trans. Pattern Anal. Mach. Intell.
Tapas Kanungo, David M. Mount, Nathan S. Netanyahu, Christine D. Piatko, Ruth Silverman, Angela Y. Wu
2002 C conf
IGARSS
Avraham Gal, Maxim Shoshany, Nathan S. Netanyahu
2002 J jnl
ICGA J.
Omid David-Tabibi, Nathan S. Netanyahu
2001 J jnl
Pattern Recognit.
Nathan S. Netanyahu, Isaac Weiss
2001 A* conf
VLDB
Amihood Amir, Reuven Kashi, Nathan S. Netanyahu
2001 J jnl
IEEE Trans. Image Process.
David M. Mount, Tapas Kanungo, Nathan S. Netanyahu, Christine D. Piatko, Ruth Silverman, Angela Y. Wu
2001 J jnl
Comput. Geom.
David M. Mount, Nathan S. Netanyahu
2000 J jnl
Comput. Geom.
David M. Mount, Nathan S. Netanyahu, Ruth Silverman, Angela Y. Wu
2000 J jnl
Int. J. Comput. Geom. Appl.
David M. Mount, Nathan S. Netanyahu, Christine D. Piatko, Ruth Silverman, Angela Y. Wu
2000 conf
SCG
Tapas Kanungo, David M. Mount, Nathan S. Netanyahu, Christine D. Piatko, Ruth Silverman, Angela Y. Wu
1999 A* conf
SODA
Tapas Kanungo, David M. Mount, Nathan S. Netanyahu, Christine D. Piatko, Ruth Silverman, Angela Y. Wu
1999 J jnl
Pattern Recognit.
David M. Mount, Nathan S. Netanyahu, Jacqueline Le Moigne
1998 J jnl
Pattern Recognit.
Peter Cucka, Nathan S. Netanyahu, Azriel Rosenfeld
1998 J jnl
J. ACM
Sunil Arya, David M. Mount, Nathan S. Netanyahu, Ruth Silverman, Angela Y. Wu
1998 J jnl
Algorithmica
Jirí Matousek, David M. Mount, Nathan S. Netanyahu
1998 conf
SCG
David M. Mount, Nathan S. Netanyahu, Jacqueline Le Moigne
1998 conf
CCCG
David M. Mount, Nathan S. Netanyahu, Christine D. Piatko, Ruth Silverman, Angela Y. Wu
1997 A* conf
SODA
David M. Mount, Nathan S. Netanyahu, Kathleen Romanik, Ruth Silverman, Angela Y. Wu
1997 J jnl
Pattern Recognit.
Nathan S. Netanyahu, Vasanth Philomin, Azriel Rosenfeld, Arnold J. Stromberg
1996 J jnl
Int. J. Pattern Recognit. Artif. Intell.
Peter Cucka, Nathan S. Netanyahu, Azriel Rosenfeld
1996 B conf
ICPR
Nathan S. Netanyahu, Vasanth Philomin, Azriel Rosenfeld, Arnold J. Stromberg
1995 J jnl
IEEE Expert
Nicholas M. Short Jr., Robert F. Cromp, William J. Campbell, James C. Tilton, Jacqueline Le Moigne, Gyorgy Fekete, Nathan S. Netanyahu, Keith Wichmann, Walter B. Ligon III
1994 A* conf
SODA
Sunil Arya, David M. Mount, Nathan S. Netanyahu, Ruth Silverman, Angela Y. Wu
1994 conf
ICPR (2)
Nathan S. Netanyahu, Isaac Weiss
1994 J jnl
CVGIP Graph. Model. Image Process.
David M. Mount, Nathan S. Netanyahu
1993 conf
CCCG
David M. Mount, Nathan S. Netanyahu
1993 A* conf
SODA
Jirí Matousek, David M. Mount, Nathan S. Netanyahu
1992 J jnl
Int. J. Comput. Geom. Appl.
Michael B. Dillencourt, David M. Mount, Nathan S. Netanyahu
1989 J jnl
IEEE Trans. Pattern Anal. Mach. Intell.
Behzad Kamgar-Parsi, Behrooz Kamgar-Parsi, Nathan S. Netanyahu
1988 J jnl
Pattern Recognit. Lett.
John Canning, J. John Kim, Nathan S. Netanyahu, Azriel Rosenfeld
redb/extractors/decompiler/bninja/analysis/cfg.py
← Index redb/extractors/decompiler/bninja/analysis/cfg.py python
from binaryninja.enums import LowLevelILOperation as LLIL_OP

# Support both package and standalone imports
try:
    from . import cfg_features
except ImportError:
    from redb.extractors.decompiler.bninja.analysis import cfg_features


# ---------------------------------------------------------------------------
# Task 2.2: Build LLIL operation maps at import time using real enum values
# ---------------------------------------------------------------------------

# Prime product map: LLIL operation integer value -> small prime
cfg_features.LLIL_OP_PRIMES = {
    # SET_REG, SET_REG_SPLIT
    LLIL_OP.LLIL_SET_REG.value: 2,
    LLIL_OP.LLIL_SET_REG_SPLIT.value: 2,
    # SET_FLAG
    LLIL_OP.LLIL_SET_FLAG.value: 3,
    # LOAD
    LLIL_OP.LLIL_LOAD.value: 5,
    # STORE
    LLIL_OP.LLIL_STORE.value: 7,
    # PUSH, POP
    LLIL_OP.LLIL_PUSH.value: 11,
    LLIL_OP.LLIL_POP.value: 13,
    # CALL, TAILCALL, SYSCALL
    LLIL_OP.LLIL_CALL.value: 17,
    LLIL_OP.LLIL_TAILCALL.value: 17,
    LLIL_OP.LLIL_SYSCALL.value: 19,
    # RET, NORET
    LLIL_OP.LLIL_RET.value: 23,
    LLIL_OP.LLIL_NORET.value: 23,
    # IF, GOTO
    LLIL_OP.LLIL_IF.value: 29,
    LLIL_OP.LLIL_GOTO.value: 31,
    # ADD, SUB
    LLIL_OP.LLIL_ADD.value: 37,
    LLIL_OP.LLIL_SUB.value: 41,
    # AND, OR, XOR
    LLIL_OP.LLIL_AND.value: 43,
    LLIL_OP.LLIL_OR.value: 47,
    LLIL_OP.LLIL_XOR.value: 53,
    # LSL, LSR, ASR, ROL, ROR
    LLIL_OP.LLIL_LSL.value: 59,
    LLIL_OP.LLIL_LSR.value: 61,
    LLIL_OP.LLIL_ASR.value: 67,
    LLIL_OP.LLIL_ROL.value: 71,
    LLIL_OP.LLIL_ROR.value: 73,
    # MUL, DIVU, DIVS, MODU, MODS
    LLIL_OP.LLIL_MUL.value: 79,
    LLIL_OP.LLIL_DIVU.value: 83,
    LLIL_OP.LLIL_DIVS.value: 83,
    LLIL_OP.LLIL_MODU.value: 89,
    LLIL_OP.LLIL_MODS.value: 89,
    # NEG, NOT
    LLIL_OP.LLIL_NEG.value: 97,
    LLIL_OP.LLIL_NOT.value: 101,
    # CMP_E, CMP_NE, CMP_SLT, CMP_ULT, CMP_SLE, CMP_ULE
    # CMP_SGT, CMP_UGT, CMP_SGE, CMP_UGE
    LLIL_OP.LLIL_CMP_E.value: 103,
    LLIL_OP.LLIL_CMP_NE.value: 103,
    LLIL_OP.LLIL_CMP_SLT.value: 107,
    LLIL_OP.LLIL_CMP_ULT.value: 107,
    LLIL_OP.LLIL_CMP_SLE.value: 109,
    LLIL_OP.LLIL_CMP_ULE.value: 109,
    LLIL_OP.LLIL_CMP_SGT.value: 113,
    LLIL_OP.LLIL_CMP_UGT.value: 113,
    LLIL_OP.LLIL_CMP_SGE.value: 127,
    LLIL_OP.LLIL_CMP_UGE.value: 127,
    # NOP
    LLIL_OP.LLIL_NOP.value: 1,
    # SX, ZX, LOW_PART, BOOL_TO_INT
    LLIL_OP.LLIL_SX.value: 131,
    LLIL_OP.LLIL_ZX.value: 137,
    LLIL_OP.LLIL_LOW_PART.value: 139,
    LLIL_OP.LLIL_BOOL_TO_INT.value: 149,
    # JUMP, JUMP_TO
    LLIL_OP.LLIL_JUMP.value: 151,
    LLIL_OP.LLIL_JUMP_TO.value: 151,
}

# Category map: LLIL operation integer value -> category index
_ARITHMETIC = {
    LLIL_OP.LLIL_ADD, LLIL_OP.LLIL_ADC, LLIL_OP.LLIL_SUB, LLIL_OP.LLIL_SBB,
    LLIL_OP.LLIL_MUL, LLIL_OP.LLIL_MULU_DP, LLIL_OP.LLIL_MULS_DP,
    LLIL_OP.LLIL_DIVU, LLIL_OP.LLIL_DIVU_DP, LLIL_OP.LLIL_DIVS,
    LLIL_OP.LLIL_DIVS_DP, LLIL_OP.LLIL_MODU, LLIL_OP.LLIL_MODS,
    LLIL_OP.LLIL_NEG,
}
_LOGIC = {
    LLIL_OP.LLIL_AND, LLIL_OP.LLIL_OR, LLIL_OP.LLIL_XOR, LLIL_OP.LLIL_NOT,
    LLIL_OP.LLIL_LSL, LLIL_OP.LLIL_LSR, LLIL_OP.LLIL_ASR,
    LLIL_OP.LLIL_ROL, LLIL_OP.LLIL_RLC, LLIL_OP.LLIL_ROR, LLIL_OP.LLIL_RRC,
}
_TRANSFER = {
    LLIL_OP.LLIL_SET_REG, LLIL_OP.LLIL_SET_REG_SPLIT, LLIL_OP.LLIL_SET_FLAG,
    LLIL_OP.LLIL_GOTO, LLIL_OP.LLIL_IF, LLIL_OP.LLIL_JUMP, LLIL_OP.LLIL_JUMP_TO,
    LLIL_OP.LLIL_RET, LLIL_OP.LLIL_NORET, LLIL_OP.LLIL_PUSH, LLIL_OP.LLIL_POP,
}
_CALL = {
    LLIL_OP.LLIL_CALL, LLIL_OP.LLIL_TAILCALL, LLIL_OP.LLIL_SYSCALL,
}
_COMPARISON = {
    LLIL_OP.LLIL_CMP_E, LLIL_OP.LLIL_CMP_NE,
    LLIL_OP.LLIL_CMP_SLT, LLIL_OP.LLIL_CMP_ULT,
    LLIL_OP.LLIL_CMP_SLE, LLIL_OP.LLIL_CMP_ULE,
    LLIL_OP.LLIL_CMP_SGE, LLIL_OP.LLIL_CMP_UGE,
    LLIL_OP.LLIL_CMP_SGT, LLIL_OP.LLIL_CMP_UGT,
    LLIL_OP.LLIL_TEST_BIT, LLIL_OP.LLIL_FLAG_COND,
}
_MEMORY = {
    LLIL_OP.LLIL_LOAD, LLIL_OP.LLIL_STORE,
}

cfg_features.LLIL_OP_CATEGORIES = {}
for _op in _ARITHMETIC:
    cfg_features.LLIL_OP_CATEGORIES[_op.value] = cfg_features.CAT_ARITHMETIC
for _op in _LOGIC:
    cfg_features.LLIL_OP_CATEGORIES[_op.value] = cfg_features.CAT_LOGIC
for _op in _TRANSFER:
    cfg_features.LLIL_OP_CATEGORIES[_op.value] = cfg_features.CAT_TRANSFER
for _op in _CALL:
    cfg_features.LLIL_OP_CATEGORIES[_op.value] = cfg_features.CAT_CALL
for _op in _COMPARISON:
    cfg_features.LLIL_OP_CATEGORIES[_op.value] = cfg_features.CAT_COMPARISON
for _op in _MEMORY:
    cfg_features.LLIL_OP_CATEGORIES[_op.value] = cfg_features.CAT_MEMORY

# Set of CALL operation values for counting
_CALL_OPS = {op.value for op in _CALL}


# ---------------------------------------------------------------------------
# Task 2.1 + 2.3: Rewritten CFGAnalysis
# ---------------------------------------------------------------------------

class CFGAnalysis:
    def __init__(self, function, llil_function=None):
        self.function = function
        self.llil_function = llil_function

    def extract_function_cfg(self):
        """Extract function-level CFG features as a flat dictionary."""

        if self.function is None:
            return None

        blocks = list(self.function.basic_blocks)
        if not blocks:
            return None

        n = len(blocks)

        # 1. Build index-based adjacency from Binary Ninja blocks
        addr_to_idx = {b.start: i for i, b in enumerate(blocks)}
        successors = [[] for _ in range(n)]
        predecessors = [[] for _ in range(n)]
        for i, block in enumerate(blocks):
            for edge in block.outgoing_edges:
                if edge.target is None:
                    continue
                target_idx = addr_to_idx.get(edge.target.start)
                if target_idx is not None:
                    successors[i].append(target_idx)
                    predecessors[target_idx].append(i)

        # 2. BFS order (reusable across multiple features)
        bfs = cfg_features.bfs_order(successors, n)

        # 3. Collect per-block LLIL operations (for prime product + ACFG features)
        block_llil_ops = self._collect_block_llil_ops(blocks, addr_to_idx, n)
        all_llil_ops = [op for block_ops in block_llil_ops for op in block_ops]

        # 4. Structural counts
        edge_count = sum(len(s) for s in successors)
        total_llil = sum(len(ops) for ops in block_llil_ops)
        call_count = sum(
            1 for ops in block_llil_ops for op in ops
            if op in _CALL_OPS
        )

        # 5. Compute all features
        bb_features = cfg_features.build_block_features(block_llil_ops, successors, n)

        return {
            "cfg_topology_hash": cfg_features.compute_topology_hash(successors, bfs, n),
            "block_count": n,
            "edge_count": edge_count,
            "llil_total_operations": total_llil,
            "call_count": call_count,
            "cyclomatic_complexity": edge_count - n + 2,
            "loop_count": cfg_features.count_back_edges(successors, n),
            "max_depth": cfg_features.bfs_max_depth(successors, n),
            "max_fan_out": max((len(s) for s in successors), default=0),
            "md_index_topdown": cfg_features.compute_md_index_topdown(successors, predecessors, bfs),
            "md_index_bottomup": cfg_features.compute_md_index_bottomup(successors, predecessors, n),
            "prime_product_llil": cfg_features.compute_prime_product(all_llil_ops),
            "cfg_feature_tlsh": cfg_features.compute_cfg_feature_tlsh(bb_features, bfs),
            "wl_minhash": cfg_features.compute_wl_minhash(successors, predecessors, bb_features, n),
            "bb_features": bb_features,
            "cfg_adjacency": cfg_features.pack_adjacency(successors),
        }

    def _collect_block_llil_ops(self, blocks, addr_to_idx, n):
        """
        Collect LLIL operation integers per native basic block.
        Walks the full expression tree of each instruction so that
        nested operations (e.g. ADD inside SET_REG) are captured.
        Returns list of n lists, one per block.
        """
        block_ops = [[] for _ in range(n)]

        if self.llil_function is None:
            return block_ops

        try:
            for llil_block in self.llil_function.basic_blocks:
                # Map LLIL block to native block via source_block
                if llil_block.source_block is not None:
                    native_idx = addr_to_idx.get(llil_block.source_block.start)
                    if native_idx is not None:
                        for instr in llil_block:
                            self._walk_llil_ops(instr, block_ops[native_idx])
        except Exception:
            pass  # Return empty ops — LLIL-dependent fields will be 0/null

        return block_ops

    @staticmethod
    def _walk_llil_ops(expr, ops_list):
        """Collect operation values from an LLIL expression tree iteratively."""
        stack = [expr]
        while stack:
            node = stack.pop()
            if hasattr(node, 'operation'):
                ops_list.append(node.operation.value)
            if hasattr(node, 'operands'):
                for operand in node.operands:
                    if hasattr(operand, 'operation'):
                        stack.append(operand)