Or Litany

143 papers A* 31A 3B 2Journal 90Unranked 17
YearRankTypeTitle / Venue / Authors
2026 J jnl
CoRR
Yuxuan Zhang, Katarína Tóthová, Zian Wang, Kangxue Yin, Haithem Turki, Riccardo de Lutio, Yen-Yu Chang, Or Litany, Sanja Fidler, Zan Gojcic
2026 J jnl
CoRR
Matan Levy, Gavriel Habib, Issar Tzachor, Dvir Samuel, Rami Ben-Ari, Nir Darshan, Or Litany, Dani Lischinski
2026 J jnl
CoRR
Léopold Maillard, Francis Engelmann, Tom Durand, Boxiao Pan, Yang You, Or Litany, Leonidas J. Guibas, Maks Ovsjanikov
2026 J jnl
CoRR
Avigail Cohen Rimon, Amir Mann, Mirela Ben-Chen, Or Litany
2026 J jnl
CoRR
Junchen Liu, Sven Elflein, Or Litany, Zan Gojcic, Ruilong Li
2025 J jnl
CoRR
Saar Stern, Ido Sobol, Or Litany
2025 conf
ISBI
Daniel Gilo, Tzofi Klinghoffer, Or Litany
2025 J jnl
Comput. Graph. Forum
Avigail Cohen Rimon, Mirela Ben-Chen, Or Litany
2025 J jnl
CoRR
Avigail Cohen Rimon, Mirela Ben-Chen, Or Litany
2025 J jnl
CoRR
Nhat Phuong Anh Vu, Abhishek Saroha, Or Litany, Daniel Cremers
2025 A* conf
SIGGRAPH Asia
Yarin Bekor, Gal Michael Harari, Or Perel, Or Litany
2025 J jnl
CoRR
Yarin Bekor, Gal Michael Harari, Or Perel, Or Litany
2025 J jnl
CoRR
Daniel Gilo, Or Litany
2025 J jnl
CoRR
Luca Collorone, Matteo Gioia, Massimiliano Pappa, Paolo Leoni, Giovanni Ficarra, Or Litany, Indro Spinelli, Fabio Galasso
2025 A* conf
ICLR
Ziyu Chen, Jiawei Yang, Jiahui Huang, Riccardo de Lutio, Janick Martinez Esturo, Boris Ivanovic, Or Litany, Zan Gojcic, Sanja Fidler, Marco Pavone, Li Song, Yue Wang
2025 J jnl
CoRR
Tomer Borreda, Fangqiang Ding, Sanja Fidler, Shengyu Huang, Or Litany
2025 J jnl
Trans. Mach. Learn. Res.
Tomer Borreda, Daniel Freedman, Or Litany
2025 J jnl
CoRR
Elisabetta Fedele, Francis Engelmann, Ian Huang, Or Litany, Marc Pollefeys, Leonidas J. Guibas
2025 J jnl
CoRR
Assaf Singer, Noam Rotstein, Amir Mann, Ron Kimmel, Or Litany
2025 J jnl
CoRR
Abhishek Saroha, Florian Hofherr, Mariia Gladkova, Cecilia Curreli, Or Litany, Daniel Cremers
2024 A* conf
CVPR
Chenfeng Xu, Huan Ling, Sanja Fidler, Or Litany
2024 J jnl
CoRR
Chensheng Peng, Ido Sobol, Masayoshi Tomizuka, Kurt Keutzer, Chenfeng Xu, Or Litany
2024 A* conf
ICLR
Matan Atzmon, Jiahui Huang, Francis Williams, Or Litany
2024 J jnl
CoRR
Matan Atzmon, Jiahui Huang, Francis Williams, Or Litany
2024 A* conf
CVPR
Hanfeng Wu, Xingxing Zuo, Stefan Leutenegger, Or Litany, Konrad Schindler, Shengyu Huang
2024 A* conf
ICLR
Jiawei Yang, Boris Ivanovic, Or Litany, Xinshuo Weng, Seung Wook Kim, Boyi Li, Tong Che, Danfei Xu, Sanja Fidler, Marco Pavone, Yue Wang
2024 J jnl
CoRR
Daniel Gilo, Tzofi Klinghoffer, Or Litany
2024 conf
CVPR Workshops
Mathis Petrovich, Or Litany, Umar Iqbal, Michael J. Black, Gül Varol, Xue Bin Peng, Davis Rempe
2024 J jnl
CoRR
Mathis Petrovich, Or Litany, Umar Iqbal, Michael J. Black, Gül Varol, Xue Bin Peng, Davis Rempe
2024 J jnl
CoRR
Ziyu Chen, Jiawei Yang, Jiahui Huang, Riccardo de Lutio, Janick Martinez Esturo, Boris Ivanovic, Or Litany, Zan Gojcic, Sanja Fidler, Marco Pavone, Li Song, Yue Wang
2024 J jnl
CoRR
Francis Engelmann, Ayça Takmaz, Jonas Schult, Elisabetta Fedele, Johanna Wald, Songyou Peng, Xi Wang, Or Litany, Siyu Tang, Federico Tombari, Marc Pollefeys, Leonidas J. Guibas, Hongbo Tian, Chunjie Wang, Xiaosheng Yan, Bingwen Wang, Xuanyang Zhang, Xiao Liu, Phuc Nguyen, Khoi Nguyen, Anh Tran, Cuong Pham, Zhening Huang, Xiaoyang Wu, Xi Chen, Hengshuang Zhao, Lei Zhu, Joan Lasenby
2024 J jnl
CoRR
Tomer Borreda, Daniel Freedman, Or Litany
2024 A* conf
SIGGRAPH Asia
Jihyeon Je, Jiayi Liu, Guandao Yang, Boyang Deng, Shengqu Cai, Gordon Wetzstein, Or Litany, Leonidas J. Guibas
2024 J jnl
CoRR
Jihyeon Je, Jiayi Liu, Guandao Yang, Boyang Deng, Shengqu Cai, Gordon Wetzstein, Or Litany, Leonidas J. Guibas
2024 J jnl
Trans. Mach. Learn. Res.
Moshe Kimhi, Shai Kimhi, Evgenii Zheltonozhskii, Or Litany, Chaim Baskin
2024 conf
ECCV (24)
Qunjie Zhou, Maxim Maximov, Or Litany, Laura Leal-Taixé
2024 J jnl
CoRR
Qunjie Zhou, Maxim Maximov, Or Litany, Laura Leal-Taixé
2024 A* conf
CVPR
Dávid Rozenberszki, Or Litany, Angela Dai
2024 A* conf
NeurIPS
Ido Sobol, Chenfeng Xu, Or Litany
2024 J jnl
CoRR
Ido Sobol, Chenfeng Xu, Or Litany
2023 J jnl
CoRR
Chenfeng Xu, Huan Ling, Sanja Fidler, Or Litany
2023 J jnl
CoRR
Hanfeng Wu, Xingxing Zuo, Stefan Leutenegger, Or Litany, Konrad Schindler, Shengyu Huang
2023 J jnl
CoRR
Jiawei Yang, Boris Ivanovic, Or Litany, Xinshuo Weng, Seung Wook Kim, Boyi Li, Tong Che, Danfei Xu, Sanja Fidler, Marco Pavone, Yue Wang
2023 A* conf
CVPR
Wei Dong, Christopher B. Choy, Charles Loop, Or Litany, Yuke Zhu, Anima Anandkumar
2023 J jnl
CoRR
Wei Dong, Christopher B. Choy, Charles Loop, Or Litany, Yuke Zhu, Anima Anandkumar
2023 A* conf
ICRA
Jonas Schult, Francis Engelmann, Alexander Hermans, Or Litany, Siyu Tang, Bastian Leibe
2023 conf
SIGGRAPH Courses
Towaki Takikawa, Shunsuke Saito, James Tompkin, Vincent Sitzmann, Srinath Sridhar, Or Litany, Alex Yu
2023 A* conf
CVPR
Jiahui Huang, Zan Gojcic, Matan Atzmon, Or Litany, Sanja Fidler, Francis Williams
2023 J jnl
CoRR
Jiahui Huang, Zan Gojcic, Matan Atzmon, Or Litany, Sanja Fidler, Francis Williams
2023 A* conf
ICCV
Shengyu Huang, Zan Gojcic, Zian Wang, Francis Williams, Yoni Kasten, Sanja Fidler, Konrad Schindler, Or Litany
2023 J jnl
CoRR
Shengyu Huang, Zan Gojcic, Zian Wang, Francis Williams, Yoni Kasten, Sanja Fidler, Konrad Schindler, Or Litany
2023 J jnl
CoRR
Moshe Kimhi, Shai Kimhi, Evgenii Zheltonozhskii, Or Litany, Chaim Baskin
2023 A* conf
ICCV
Tzofi Klinghoffer, Jonah Philion, Wenzheng Chen, Or Litany, Zan Gojcic, Jungseock Joo, Ramesh Raskar, Sanja Fidler, José M. Álvarez
2023 J jnl
CoRR
Tzofi Klinghoffer, Jonah Philion, Wenzheng Chen, Or Litany, Zan Gojcic, Jungseock Joo, Ramesh Raskar, Sanja Fidler, José M. Álvarez
2023 A* conf
CVPR
Davis Rempe, Zhengyi Luo, Xue Bin Peng, Ye Yuan, Kris Kitani, Karsten Kreis, Sanja Fidler, Or Litany
2023 J jnl
CoRR
Davis Rempe, Zhengyi Luo, Xue Bin Peng, Ye Yuan, Kris Kitani, Karsten Kreis, Sanja Fidler, Or Litany
2023 J jnl
CoRR
Dávid Rozenberszki, Or Litany, Angela Dai
2022 J jnl
CoRR
Cinjon Resnick, Or Litany, Amlan Kar, Karsten Kreis, James Lucas, Kyunghyun Cho, Sanja Fidler
2022 A conf
WACV
Evgenii Zheltonozhskii, Chaim Baskin, Avi Mendelson, Alex M. Bronstein, Or Litany
2022 J jnl
CoRR
Or Litany, Haggai Maron, David Acuna, Jan Kautz, Gal Chechik, Sanja Fidler
2022 A* conf
NeurIPS
Jun Gao, Tianchang Shen, Zian Wang, Wenzheng Chen, Kangxue Yin, Daiqing Li, Or Litany, Zan Gojcic, Sanja Fidler
2022 J jnl
CoRR
Jun Gao, Tianchang Shen, Zian Wang, Wenzheng Chen, Kangxue Yin, Daiqing Li, Or Litany, Zan Gojcic, Sanja Fidler
2022 A* conf
CVPR
Davis Rempe, Jonah Philion, Leonidas J. Guibas, Sanja Fidler, Or Litany
2022 A* conf
NeurIPS
Xiaohui Zeng, Arash Vahdat, Francis Williams, Zan Gojcic, Or Litany, Sanja Fidler, Karsten Kreis
2022 J jnl
CoRR
Xiaohui Zeng, Arash Vahdat, Francis Williams, Zan Gojcic, Or Litany, Sanja Fidler, Karsten Kreis
2022 conf
ECCV (33)
Dávid Rozenberszki, Or Litany, Angela Dai
2022 J jnl
CoRR
Dávid Rozenberszki, Or Litany, Angela Dai
2022 conf
SIGGRAPH (Conference Paper Track)
Hsueh-Ti Derek Liu, Francis Williams, Alec Jacobson, Sanja Fidler, Or Litany
2022 J jnl
CoRR
Hsueh-Ti Derek Liu, Francis Williams, Alec Jacobson, Sanja Fidler, Or Litany
2022 J jnl
Comput. Graph. Forum
Luca Moschella, Simone Melzi, Luca Cosmo, Filippo Maggioli, Or Litany, Maks Ovsjanikov, Leonidas J. Guibas, Emanuele Rodolà
2022 J jnl
CoRR
Jonas Schult, Francis Engelmann, Alexander Hermans, Or Litany, Siyu Tang, Bastian Leibe
2022 conf
ECCV (2)
Gopal Sharma, Kangxue Yin, Subhransu Maji, Evangelos Kalogerakis, Or Litany, Sanja Fidler
2022 J jnl
CoRR
Gopal Sharma, Kangxue Yin, Subhransu Maji, Evangelos Kalogerakis, Or Litany, Sanja Fidler
2022 A* conf
CVPR
Francis Williams, Zan Gojcic, Sameh Khamis, Denis Zorin, Joan Bruna, Sanja Fidler, Or Litany
2022 J jnl
Comput. Graph. Forum
Yiheng Xie, Towaki Takikawa, Shunsuke Saito, Or Litany, Shiqin Yan, Numair Khan, Federico Tombari, James Tompkin, Vincent Sitzmann, Srinath Sridhar
2021 A* conf
CVPR
He Wang, Yezhen Cong, Or Litany, Yue Gao, Leonidas J. Guibas
2021 conf
ICCVW
Cinjon Resnick, Or Litany, Amlan Kar, Karsten Kreis, James Lucas, Kyunghyun Cho, Sanja Fidler
2021 A conf
WACV
Zhangsihao Yang, Or Litany, Tolga Birdal, Srinath Sridhar, Leonidas J. Guibas
2021 J jnl
CoRR
Evgenii Zheltonozhskii, Chaim Baskin, Avi Mendelson, Alex M. Bronstein, Or Litany
2021 A* conf
NeurIPS
Wenzheng Chen, Joey Litalien, Jun Gao, Zian Wang, Clement Fuji Tsang, Sameh Khamis, Or Litany, Sanja Fidler
2021 J jnl
CoRR
Wenzheng Chen, Joey Litalien, Jun Gao, Zian Wang, Clement Fuji Tsang, Sameh Khamis, Or Litany, Sanja Fidler
2021 J jnl
CoRR
Davis Rempe, Jonah Philion, Leonidas J. Guibas, Sanja Fidler, Or Litany
2021 conf
3DV
Alexey Nekrasov, Jonas Schult, Or Litany, Bastian Leibe, Francis Engelmann
2021 J jnl
CoRR
Alexey Nekrasov, Jonas Schult, Or Litany, Bastian Leibe, Francis Engelmann
2021 J jnl
CoRR
Francis Williams, Zan Gojcic, Sameh Khamis, Denis Zorin, Joan Bruna, Sanja Fidler, Or Litany
2021 J jnl
CoRR
Yiheng Xie, Towaki Takikawa, Shunsuke Saito, Or Litany, Shiqin Yan, Numair Khan, Federico Tombari, James Tompkin, Vincent Sitzmann, Srinath Sridhar
2021 A* conf
IJCAI
Haggai Maron, Or Litany, Gal Chechik, Ethan Fetaya
2021 A* conf
ICRA
Fei Xia, Chengshu Li, Roberto Martín-Martín, Or Litany, Alexander Toshev, Silvio Savarese
2021 A conf
WACV
Or Litany, Ari Morcos, Srinath Sridhar, Leonidas J. Guibas, Judy Hoffman
2021 J jnl
CoRR
Cinjon Resnick, Or Litany, Cosmas Heiß, Hugo Larochelle, Joan Bruna, Kyunghyun Cho
2021 J jnl
CoRR
Luca Moschella, Simone Melzi, Luca Cosmo, Filippo Maggioli, Or Litany, Maks Ovsjanikov, Leonidas J. Guibas, Emanuele Rodolà
2021 J jnl
CoRR
Ge Zhang, Or Litany, Srinath Sridhar, Leonidas J. Guibas
2021 A* conf
ICCV
Congyue Deng, Or Litany, Yueqi Duan, Adrien Poulenard, Andrea Tagliasacchi, Leonidas J. Guibas
2021 J jnl
CoRR
Congyue Deng, Or Litany, Yueqi Duan, Adrien Poulenard, Andrea Tagliasacchi, Leonidas J. Guibas
2021 A* conf
CVPR
Zan Gojcic, Or Litany, Andreas Wieser, Leonidas J. Guibas, Tolga Birdal
2021 J jnl
CoRR
Zan Gojcic, Or Litany, Andreas Wieser, Leonidas J. Guibas, Tolga Birdal
2020 J jnl
CoRR
He Wang, Yezhen Cong, Or Litany, Yue Gao, Leonidas J. Guibas
2020 J jnl
CoRR
Zhangsihao Yang, Or Litany, Tolga Birdal, Srinath Sridhar, Leonidas J. Guibas
2020 J jnl
CoRR
Francis Williams, Or Litany, Avneesh Sud, Kevin Swersky, Andrea Tagliasacchi
2020 A* conf
CVPR
Charles R. Qi, Xinlei Chen, Or Litany, Leonidas J. Guibas
2020 J jnl
CoRR
Charles R. Qi, Xinlei Chen, Or Litany, Leonidas J. Guibas
2020 J jnl
CoRR
Cinjon Resnick, Or Litany, Hugo Larochelle, Joan Bruna, Kyunghyun Cho
2020 J jnl
CoRR
Or Litany, Emanuele Rodolà, Alex M. Bronstein, Michael M. Bronstein, Daniel Cremers
2020 J jnl
CoRR
Shubham Tulsiani, Or Litany, Charles R. Qi, He Wang, Leonidas J. Guibas
2020 A* conf
ICML
Haggai Maron, Or Litany, Gal Chechik, Ethan Fetaya
2020 J jnl
CoRR
Haggai Maron, Or Litany, Gal Chechik, Ethan Fetaya
2020 conf
ECCV (3)
Saining Xie, Jiatao Gu, Demi Guo, Charles R. Qi, Leonidas J. Guibas, Or Litany
2020 J jnl
CoRR
Saining Xie, Jiatao Gu, Demi Guo, Charles R. Qi, Leonidas J. Guibas, Or Litany
2020 J jnl
CoRR
Fei Xia, Chengshu Li, Roberto Martín-Martín, Or Litany, Alexander Toshev, Silvio Savarese
2020 J jnl
CoRR
Or Litany, Ari Morcos, Srinath Sridhar, Leonidas J. Guibas, Judy Hoffman
2020 J jnl
CoRR
Oshri Halimi, Ido Imanuel, Or Litany, Giovanni Trappolini, Emanuele Rodolà, Leonidas J. Guibas, Ron Kimmel
2020 conf
ECCV (24)
Oshri Halimi, Ido Imanuel, Or Litany, Giovanni Trappolini, Emanuele Rodolà, Leonidas J. Guibas, Ron Kimmel
2019 A* conf
ICCV
Charles R. Qi, Or Litany, Kaiming He, Leonidas J. Guibas
2019 J jnl
CoRR
Charles R. Qi, Or Litany, Kaiming He, Leonidas J. Guibas
2019 conf
Eurographics (Tutorials)
Michael M. Bronstein, Leonidas J. Guibas, Iasonas Kokkinos, Or Litany, Niloy J. Mitra, Federico Monti, Emanuele Rodolà
2019 conf
3DOR@Eurographics
Roberto M. Dyke, C. Stride, Yu-Kun Lai, Paul L. Rosin, Mathieu Aubry, Amit Boyarski, Alexander M. Bronstein, Michael M. Bronstein, Daniel Cremers, Matthew Fisher, Thibault Groueix, Daoliang Guo, Vladimir G. Kim, Ron Kimmel, Zorah Lähner, Kun Li, Or Litany, Tal Remez, Emanuele Rodolà, Bryan C. Russell, Yusuf Sahillioglu, Ron Slossberg, Gary K. L. Tam, Matthias Vestner, Z. Wu, Jingyu Yang
2019 A* conf
CVPR
Oshri Halimi, Or Litany, Emanuele Rodolà, Alexander M. Bronstein, Ron Kimmel
2018 J jnl
IEEE Trans. Image Process.
Tal Remez, Or Litany, Raja Giryes, Alexander M. Bronstein
2018 J jnl
CoRR
Tal Remez, Or Litany, Raja Giryes, Alexander M. Bronstein
2018 A* conf
CVPR
Or Litany, Alexander M. Bronstein, Michael M. Bronstein, Ameesh Makadia
2018 J jnl
CoRR
Federico Monti, Oleksandr Shchur, Aleksandar Bojchevski, Or Litany, Stephan Günnemann, Michael M. Bronstein
2018 J jnl
CoRR
Or Litany, Daniel Freedman
2018 J jnl
CoRR
Oshri Halimi, Or Litany, Emanuele Rodolà, Alexander M. Bronstein, Ron Kimmel
2017 J jnl
Comput. Vis. Image Underst.
Or Litany, Tal Remez, Daniel Freedman, Lior Shapira, Alexander M. Bronstein, Ran Gal
2017 J jnl
CoRR
Tal Remez, Or Litany, Raja Giryes, Alexander M. Bronstein
2017 J jnl
CoRR
Tal Remez, Or Litany, Raja Giryes, Alexander M. Bronstein
2017 A* conf
ICCV
Or Litany, Tal Remez, Emanuele Rodolà, Alexander M. Bronstein, Michael M. Bronstein
2017 J jnl
CoRR
Or Litany, Tal Remez, Emanuele Rodolà, Alexander M. Bronstein, Michael M. Bronstein
2017 B conf
ICIP
Tal Remez, Or Litany, Raja Giryes, Alexander M. Bronstein
2017 J jnl
CoRR
Or Litany, Alexander M. Bronstein, Michael M. Bronstein, Ameesh Makadia
2017 conf
3DOR@Eurographics
Emanuele Rodolà, Luca Cosmo, Or Litany, Michael M. Bronstein, Alexander M. Bronstein, Nicolas Audebert, A. Ben Hamza, Alexandre Boulch, Umberto Castellani, Minh N. Do, Duc Anh Duong, Takahiko Furuya, Andrea Gasparetto, Y. Hong, J. Kim, Bertrand Le Saux, Roee Litman, Majid Masoumi, Giorgia Minello, Hai-Dang Nguyen, V.-T. Nguyen, Ryutarou Ohbuchi, Viet-Khoi Pham, Thuyen V. Phan, M. Rezaei, Andrea Torsello, Minh-Triet Tran, Q. T. Tran, Bao Truong, L. Wan, Changqing Zou
2017 conf
3DV
Matthias Vestner, Zorah Lähner, Amit Boyarski, Or Litany, Ron Slossberg, Tal Remez, Emanuele Rodolà, Alexander M. Bronstein, Michael M. Bronstein, Ron Kimmel, Daniel Cremers
2017 J jnl
CoRR
Zorah Lähner, Matthias Vestner, Amit Boyarski, Or Litany, Ron Slossberg, Tal Remez, Emanuele Rodolà, Alexander M. Bronstein, Michael M. Bronstein, Ron Kimmel, Daniel Cremers
2017 J jnl
Comput. Graph. Forum
Or Litany, Emanuele Rodolà, Alexander M. Bronstein, Michael M. Bronstein
2017 conf
MICCAI (1)
Guy Alexandroni, Yana Podolsky, Hayit Greenspan, Tal Remez, Or Litany, Alexander M. Bronstein, Raja Giryes
2016 B conf
ICCP
Tal Remez, Or Litany, Alexander M. Bronstein
2016 J jnl
CoRR
Or Litany, Tal Remez, Alexander M. Bronstein
2016 J jnl
CoRR
Tal Remez, Or Litany, Shachar Yoseff, Harel Haim, Alexander M. Bronstein
2016 J jnl
Comput. Graph. Forum
Or Litany, Emanuele Rodolà, Alexander M. Bronstein, Michael M. Bronstein, Daniel Cremers
2015 J jnl
CoRR
Tal Remez, Or Litany, Alexander M. Bronstein
2015 J jnl
CoRR
Or Litany, Tal Remez, Daniel Freedman, Lior Shapira, Alexander M. Bronstein, Ran Gal
2015 J jnl
CoRR
Or Litany, Tal Remez, Alexander M. Bronstein
2012 conf
ECCV Workshops (1)
Or Litany, Alexander M. Bronstein, Michael M. Bronstein
redb/extractors/js_extractors/js_patterns.py
← Index redb/extractors/js_extractors/js_patterns.py python
"""Canonical, compiled JavaScript regex patterns shared across JS extractors.

All suspicious-API patterns and the few feature-only patterns live here so each
expression is compiled exactly once per Python process and so any pattern that
was previously duplicated across `js_features.py` and `js_suspicious_apis.py`
now resolves to a single shared compiled object.

JavaScript is case-sensitive at runtime, but every suspicious-API pattern matches
either a literal-case identifier (`\\beval\\s*\\(`, `String\\.fromCharCode`, etc.)
or a string-quoted token (`"powershell"`). Compiling them with `re.IGNORECASE`
matches the historical behaviour of `JSSuspiciousAPIsExtractor` and is safe for
the patterns that historically came from `JSFeaturesExtractor` — those literals
are spelled in real-world JS exactly as written.

`scan_source()` is the entry point used by extractors: it walks the source once
per pattern using the pre-compiled regexes and returns a flat
`{name: {"count": N, "lines": [unique_line_numbers_sorted]}}` dict. Both
`JSFeaturesExtractor` and `JSSuspiciousAPIsExtractor` consume the same dict so
the per-pattern × per-line loops they used to run independently collapse to a
single shared scan.
"""

import bisect
import re
from typing import Dict, Iterable, List, Mapping

_FLAGS = re.IGNORECASE

# Canonical compiled patterns, keyed by their human-readable name. The name is
# also the value emitted into `redb_js_suspicious_apis.api_name`.
PATTERNS = {
    # ---- code execution ----
    "eval": re.compile(r"\beval\s*\(", _FLAGS),
    "Function constructor": re.compile(r"\bnew\s+Function\s*\(", _FLAGS),
    "execScript": re.compile(r"\bexecScript\s*\(", _FLAGS),
    "document.write": re.compile(r"\bdocument\.write(?:ln)?\s*\(", _FLAGS),
    "innerHTML assignment": re.compile(r"\.innerHTML\s*=", _FLAGS),
    "outerHTML assignment": re.compile(r"\.outerHTML\s*=", _FLAGS),
    "insertAdjacentHTML": re.compile(r"\.insertAdjacentHTML\s*\(", _FLAGS),
    # ---- network ----
    "XMLHttpRequest": re.compile(r"\bnew\s+XMLHttpRequest\b", _FLAGS),
    "fetch": re.compile(r"\bfetch\s*\(", _FLAGS),
    "WebSocket": re.compile(r"\bnew\s+WebSocket\s*\(", _FLAGS),
    "navigator.sendBeacon": re.compile(r"\bnavigator\.sendBeacon\s*\(", _FLAGS),
    "ActiveXObject XMLHTTP": re.compile(
        r"ActiveXObject\s*\(\s*[\"\'](?:MSXML2\.XMLHTTP|Microsoft\.XMLHTTP)", _FLAGS
    ),
    "require network module": re.compile(
        r"require\s*\(\s*[\"\'](?:http|https|net|dgram)[\"\']", _FLAGS
    ),
    "axios": re.compile(r"\baxios\b", _FLAGS),
    # ---- filesystem ----
    "require fs": re.compile(r"require\s*\(\s*[\"\']fs[\"\']", _FLAGS),
    "require path": re.compile(r"require\s*\(\s*[\"\']path[\"\']", _FLAGS),
    "FileSystemObject": re.compile(r"Scripting\.FileSystemObject", _FLAGS),
    "ADODB.Stream": re.compile(r"ADODB\.Stream", _FLAGS),
    "Shell.Application": re.compile(r"Shell\.Application", _FLAGS),
    "WScript.CreateObject": re.compile(r"WScript\.CreateObject", _FLAGS),
    # ---- process ----
    "require child_process": re.compile(r"require\s*\(\s*[\"\']child_process[\"\']", _FLAGS),
    "child_process exec": re.compile(r"child_process\.(?:exec|spawn|execFile|fork)\s*\(", _FLAGS),
    "WScript.Shell": re.compile(r"WScript\.Shell", _FLAGS),
    "WScript.Shell.Run": re.compile(r"\.Run\s*\(", _FLAGS),
    "WScript.Shell.Exec": re.compile(r"\.Exec\s*\(", _FLAGS),
    "ShellExecute": re.compile(r"\bShellExecute\b", _FLAGS),
    "PowerShell reference": re.compile(r"[\"\']powershell[\"\']", _FLAGS),
    "cmd.exe reference": re.compile(r"[\"\']cmd\.exe[\"\']", _FLAGS),
    "require os": re.compile(r"require\s*\(\s*[\"\']os[\"\']", _FLAGS),
    # ---- registry ----
    "RegRead": re.compile(r"\.RegRead\s*\(", _FLAGS),
    "RegWrite": re.compile(r"\.RegWrite\s*\(", _FLAGS),
    "RegDelete": re.compile(r"\.RegDelete\s*\(", _FLAGS),
    "StdRegProv": re.compile(r"StdRegProv", _FLAGS),
    # ---- crypto / encoding ----
    "atob": re.compile(r"\batob\s*\(", _FLAGS),
    "btoa": re.compile(r"\bbtoa\s*\(", _FLAGS),
    "String.fromCharCode": re.compile(r"String\.fromCharCode\s*\(", _FLAGS),
    "unescape": re.compile(r"\bunescape\s*\(", _FLAGS),
    "decodeURIComponent": re.compile(r"\bdecodeURIComponent\s*\(", _FLAGS),
    "Buffer.from": re.compile(r"Buffer\.from\s*\(", _FLAGS),
    "crypto module": re.compile(r"crypto\.create(?:Cipher|Decipher|Hash|Hmac)", _FLAGS),
    # ---- DOM manipulation ----
    "document.forms": re.compile(r"document\.forms", _FLAGS),
    "document.cookie": re.compile(r"document\.cookie", _FLAGS),
    "querySelector sensitive input": re.compile(
        r"document\.querySelector\s*\([^)]*(?:password|credit|card|cvv|ssn)", _FLAGS
    ),
    "submit event listener": re.compile(r"addEventListener\s*\(\s*[\"\']submit", _FLAGS),
    "createElement script/iframe": re.compile(
        r"\.createElement\s*\(\s*[\"\'](?:script|iframe)", _FLAGS
    ),
    "dynamic script src": re.compile(r"\.src\s*=\s*[\"\'](?:https?://|//)", _FLAGS),
}

# Pattern name -> category (one of code_execution / network / filesystem /
# process / registry / crypto_encoding / dom_manipulation).
CATEGORIES = {
    "eval": "code_execution",
    "Function constructor": "code_execution",
    "execScript": "code_execution",
    "document.write": "code_execution",
    "innerHTML assignment": "code_execution",
    "outerHTML assignment": "code_execution",
    "insertAdjacentHTML": "code_execution",
    "XMLHttpRequest": "network",
    "fetch": "network",
    "WebSocket": "network",
    "navigator.sendBeacon": "network",
    "ActiveXObject XMLHTTP": "network",
    "require network module": "network",
    "axios": "network",
    "require fs": "filesystem",
    "require path": "filesystem",
    "FileSystemObject": "filesystem",
    "ADODB.Stream": "filesystem",
    "Shell.Application": "filesystem",
    "WScript.CreateObject": "filesystem",
    "require child_process": "process",
    "child_process exec": "process",
    "WScript.Shell": "process",
    "WScript.Shell.Run": "process",
    "WScript.Shell.Exec": "process",
    "ShellExecute": "process",
    "PowerShell reference": "process",
    "cmd.exe reference": "process",
    "require os": "process",
    "RegRead": "registry",
    "RegWrite": "registry",
    "RegDelete": "registry",
    "StdRegProv": "registry",
    "atob": "crypto_encoding",
    "btoa": "crypto_encoding",
    "String.fromCharCode": "crypto_encoding",
    "unescape": "crypto_encoding",
    "decodeURIComponent": "crypto_encoding",
    "Buffer.from": "crypto_encoding",
    "crypto module": "crypto_encoding",
    "document.forms": "dom_manipulation",
    "document.cookie": "dom_manipulation",
    "querySelector sensitive input": "dom_manipulation",
    "submit event listener": "dom_manipulation",
    "createElement script/iframe": "dom_manipulation",
    "dynamic script src": "dom_manipulation",
}

# Patterns consumed only by JSFeaturesExtractor (no category, never surfaced as
# a suspicious-API row). Kept here so every JS regex is compiled in one place.
FEATURE_PATTERNS = {
    "hex_escape": re.compile(r"\\x[0-9a-fA-F]{2}"),
    "unicode_escape": re.compile(r"\\u[0-9a-fA-F]{4}"),
    "base64_string": re.compile(r"[A-Za-z0-9+/]{40,}={0,2}"),
    # decodeURI matches BOTH decodeURI and decodeURIComponent. The latter is also
    # a suspicious-API pattern in PATTERNS; this broader form is what the
    # `decodeuri_count` feature column has historically counted.
    "decodeURI": re.compile(r"\b(?:decodeURI|decodeURIComponent)\s*\(", _FLAGS),
    "settimeout_setinterval": re.compile(r"\b(?:setTimeout|setInterval)\s*\(", _FLAGS),
    "function_decl": re.compile(r"\bfunction\s+\w+\s*\(|\bfunction\s*\("),
    "var_decl": re.compile(r"\b(?:var|let|const)\s+"),
    "string_concat": re.compile(r"[\"\'][\s]*\+[\s]*[\"\']"),
    "comment": re.compile(r"//.*?$|/\*[\s\S]*?\*/", re.MULTILINE),
    "long_string": re.compile(r"[\"\']([^\"\']{256,})[\"\']"),
    "array_function_call": re.compile(r"\[(?:0x[0-9a-f]+|[\d]+)\]\s*\(", _FLAGS),
}

# Patterns consumed only by JSStringsExtractor for encoded-string discovery.
# Scoped to *hidden* strings only — patterns whose decoded form is not visible
# to a substring search over the raw text. Plain long literals are not
# extracted here because they're already preserved in code_text_content and
# scraped by the IOC pipeline over text_raw / text_normalized.
#
# Distinct from FEATURE_PATTERNS even where the names rhyme:
#   FEATURE_PATTERNS["hex_escape"] / ["unicode_escape"]   -> single escape
#   STRING_PATTERNS["hex_escape_seq"] / ["unicode_escape_seq"] -> 4+ / 3+ in a row
#   FEATURE_PATTERNS["base64_string"]                     -> bare base64 token
#   STRING_PATTERNS["base64_quoted"]                      -> base64 inside JS quotes
# These do not share match objects with the suspicious-API or feature scans, so
# they are not folded into JSContext.scan; the strings extractor walks them
# itself (one finditer per pattern, with shared line-offset bisect in #4b).
STRING_PATTERNS = {
    "hex_escape_seq": re.compile(r"(?:\\x[0-9a-fA-F]{2}){4,}"),
    "unicode_escape_seq": re.compile(r"(?:\\u[0-9a-fA-F]{4}){3,}"),
    "charcode_call": re.compile(r"String\.fromCharCode\s*\(\s*([\d,\s]+)\s*\)"),
    "base64_quoted": re.compile(r"[\"\']([A-Za-z0-9+/]{40,}={0,2})[\"\']"),
    "concat_chain": re.compile(r"(?:[\"\'][^\"\']+[\"\']\s*\+\s*){3,}[\"\'][^\"\']+[\"\']"),
}


def line_offsets(source: str) -> List[int]:
    """Sorted list of byte offsets for every newline in `source`, plus a final
    sentinel of len(source). Used to translate match offsets into 1-indexed
    line numbers via bisect.
    """
    offsets = [-1]  # so that bisect_right of offset 0 returns line 1
    push = offsets.append
    idx = source.find("\n")
    while idx != -1:
        push(idx)
        idx = source.find("\n", idx + 1)
    return offsets


def _scan_one(
    pattern: "re.Pattern[str]", source: str, offsets: List[int]
) -> Dict[str, object]:
    """Run a single compiled pattern over `source` and return count + unique lines."""
    count = 0
    seen_lines: "set[int]" = set()
    for m in pattern.finditer(source):
        count += 1
        seen_lines.add(bisect.bisect_right(offsets, m.start()))
    if not count:
        return None  # type: ignore[return-value]
    return {"count": count, "lines": sorted(seen_lines)}


def scan_source(
    source: str,
    patterns: Iterable[Mapping[str, "re.Pattern[str]"]] = (PATTERNS, FEATURE_PATTERNS),
) -> Dict[str, Dict[str, object]]:
    """Scan `source` against every compiled pattern in `patterns`.

    Returns a dict keyed by pattern name. Each entry has:
        "count": total number of matches in the source
        "lines": sorted list of unique 1-indexed line numbers where the pattern
                 matched (deduplicated — multiple matches on the same line
                 collapse to one entry, preserving the historical
                 line-set semantics of JSSuspiciousAPIsExtractor)
    Patterns with zero matches are absent from the dict; callers should default
    to {"count": 0, "lines": []}.
    """
    if not source:
        return {}
    offsets = line_offsets(source)
    results: Dict[str, Dict[str, object]] = {}
    for table in patterns:
        for name, pat in table.items():
            entry = _scan_one(pat, source, offsets)
            if entry is not None:
                results[name] = entry
    return results