Vincent Gramoli

190 papers A* 7A 27B 23C 3Misc 3Journal 88Unranked 28
YearRankTypeTitle / Venue / Authors
2026 J jnl
CoRR
Andrei Lebedev, Vincent Gramoli
2026 ed.
ICDCN Companion
Keiichi Yasumoto, Idit Keidar, Hirozumi Yamaguchi, Simone Silvestri, Vincent Gramoli
2026 J jnl
IACR Cryptol. ePrint Arch.
Pierre Civit, Daniel Collins, Vincent Gramoli, Rachid Guerraoui, Jovan Komatovic, Manuel Vidigueira, Pouriya Zarbafian
2026 J jnl
CoRR
Qin Wang, Ruiqiang Li, Guangsheng Yu, Vincent Gramoli, Shiping Chen
2026 J jnl
CoRR
Andrei Lebedev, Vincent Gramoli
2026 Misc ed.
ICDCN
Keiichi Yasumoto, Idit Keidar, Hirozumi Yamaguchi, Simone Silvestri, Vincent Gramoli
2025 conf
DSN-S
Vincent Gramoli, Rachid Guerraoui, Andrei Lebedev, Gauthier Voron
2025 J jnl
IACR Cryptol. ePrint Arch.
Pierre Civit, Daniel Collins, Vincent Gramoli, Rachid Guerraoui, Jovan Komatovic, Manuel Vidigueira, Pouriya Zarbafian
2025 A conf
Middleware
Vincent Gramoli, Rachid Guerraoui, Andrei Lebedev, Gauthier Voron
2024 A conf
DSN
Vincent Gramoli, Zhenliang Lu, Qiang Tang, Pouriya Zarbafian
2024 J jnl
Distributed Ledger Technol. Res. Pract.
Chris Natoli, Parinya Ekparinya, Guillaume Jourjon, Vincent Gramoli
2024 J jnl
Distributed Comput.
Pierre Civit, Muhammad Ayaz Dzulfikar, Seth Gilbert, Vincent Gramoli, Rachid Guerraoui, Jovan Komatovic, Manuel Vidigueira
2024 conf
DSN-S
Andrei Lebedev, Vincent Gramoli
2024 J jnl
IACR Cryptol. ePrint Arch.
Vincent Gramoli, Zhenliang Lu, Qiang Tang, Pouriya Zarbafian
2024 ed.
ApPLIED@PODC
Ioannis Chatzigiannakis, Vincent Gramoli
2024 conf
ESORICS (4)
Vincent Gramoli, Zhenliang Lu, Qiang Tang, Pouriya Zarbafian
2024 J jnl
CoRR
Vincent Gramoli, Rachid Guerraoui, Andrei Lebedev, Gauthier Voron
2024 A conf
DSN
Alejandro Ranchal-Pedrosa, Vincent Gramoli
2023 conf
TPCTC
Jeeta Ann Chacko, Ruben Mayer, Alan D. Fekete, Vincent Gramoli, Hans-Arno Jacobsen
2023 conf
ESORICS (4)
Pouriya Zarbafian, Vincent Gramoli
2023 J jnl
J. Parallel Distributed Comput.
Pierre Civit, Seth Gilbert, Vincent Gramoli, Rachid Guerraoui, Jovan Komatovic
2023 A conf
CSF
Alejandro Ranchal-Pedrosa, Vincent Gramoli
2023 B conf
CCGrid
Deepal Tennakoon, Vincent Gramoli
2023 J jnl
Distributed Comput.
Rob van Glabbeek, Vincent Gramoli, Pierre Tholoniat
2023 A conf
EuroSys
Vincent Gramoli, Rachid Guerraoui, Andrei Lebedev, Chris Natoli, Gauthier Voron
2023 B conf
OPODIS
Vincent Gramoli
2023 conf
ApPLIED@PODC
Gauthier Voron, Vincent Gramoli
2023 J jnl
J. Parallel Distributed Comput.
Karolos Antoniadis, Julien Benhaim, Antoine Desjardins, Elias Poroma, Vincent Gramoli, Rachid Guerraoui, Gauthier Voron, Igor Zablotchi
2023 A conf
IPDPS
Pouriya Zarbafian, Vincent Gramoli
2023 J jnl
CoRR
Andrei Lebedev, Vincent Gramoli
2023 J jnl
IEEE Trans. Serv. Comput.
Nasrin Sohrabi, Zahir Tari, Gauthier Voron, Vincent Gramoli, Qiang Fu
2023 A conf
IPDPS
Deepal Tennakoon, Yiding Hua, Vincent Gramoli
2023 J jnl
Commun. ACM
Vincent Gramoli, Qiang Tang
2023 J jnl
CoRR
Alejandro Ranchal-Pedrosa, Vincent Gramoli
2022 B ed.
OPODIS
Quentin Bramas, Vincent Gramoli, Alessia Milani
2022 ed.
Tokenomics
Vincent Gramoli, Hanna Halaburda, Rafael Pass
2022 A conf
IPDPS
Pierre Civit, Seth Gilbert, Vincent Gramoli, Rachid Guerraoui, Jovan Komatovic
2022 J jnl
CoRR
Alejandro Ranchal-Pedrosa, Vincent Gramoli
2022 book
Vincent Gramoli
2022 A* conf
PODC
Nathalie Bertrand, Vincent Gramoli, Igor Konnov, Marijana Lazic, Pierre Tholoniat, Josef Widder
2022 A conf
DISC
Pierre Civit, Muhammad Ayaz Dzulfikar, Seth Gilbert, Vincent Gramoli, Rachid Guerraoui, Jovan Komatovic, Manuel Vidigueira
2022 J jnl
CoRR
Pierre Civit, Muhammad Ayaz Dzulfikar, Seth Gilbert, Vincent Gramoli, Rachid Guerraoui, Jovan Komatovic, Manuel Vidigueira
2022 J jnl
CoRR
Deepal Tennakoon, Yiding Hua, Vincent Gramoli
2022 A conf
ICDCS
Pierre Civit, Seth Gilbert, Vincent Gramoli, Rachid Guerraoui, Jovan Komatovic, Zarko Milosevic, Adi Seredinschi
2022 J jnl
IACR Cryptol. ePrint Arch.
Pierre Civit, Seth Gilbert, Vincent Gramoli, Rachid Guerraoui, Jovan Komatovic, Zarko Milosevic, Adi Seredinschi
2022 conf
FAB
Deepal Tennakoon, Vincent Gramoli
2022 A conf
DISC
Nathalie Bertrand, Vincent Gramoli, Igor Konnov, Marijana Lazic, Pierre Tholoniat, Josef Widder
2022 J jnl
CoRR
Nathalie Bertrand, Vincent Gramoli, Igor Konnov, Marijana Lazic, Pierre Tholoniat, Josef Widder
2022 conf
ConsensusDay@CCS
Alejandro Ranchal-Pedrosa, Vincent Gramoli
2022 J jnl
CoRR
Deepal Tennakoon, Vincent Gramoli
2022 J jnl
CoRR
Deepal Tennakoon, Vincent Gramoli
2022 A conf
AsiaCCS
Alejandro Ranchal-Pedrosa, Vincent Gramoli
2022 J jnl
IEEE Data Eng. Bull.
Deepal Tennakoon, Vincent Gramoli
2021 ed.
FAB
Vincent Gramoli, Mohammad Sadoghi
2021 J jnl
Parallel Comput.
Mansour Khelghatdoust, Vincent Gramoli
2021 J jnl
CoRR
Alejandro Ranchal-Pedrosa, Vincent Gramoli
2021 J jnl
IACR Cryptol. ePrint Arch.
Pierre Civit, Seth Gilbert, Vincent Gramoli, Rachid Guerraoui, Jovan Komatovic
2021 A conf
DISC
Pouriya Zarbafian, Vincent Gramoli
2021 book
Vincent Gramoli, Nicolas Nicolaou, Alexander A. Schwarzmann
2021 J jnl
IEEE/ACM Trans. Netw.
Canh T. Dinh, Nguyen Hoang Tran, Minh N. H. Nguyen, Choong Seon Hong, Wei Bao, Albert Y. Zomaya, Vincent Gramoli
2021 A conf
ICDCS
Karolos Antoniadis, Antoine Desjardins, Vincent Gramoli, Rachid Guerraoui, Igor Zablotchi
2021 B conf
PaCT
Vitaly Aksenov, Vincent Gramoli, Petr Kuznetsov, Di Shang, Srivatsan Ravi
2021 A conf
ICDCS
Pierre Civit, Seth Gilbert, Vincent Gramoli
2021 conf
Blockchain
Alejandro Ranchal-Pedrosa, Vincent Gramoli
2021 J jnl
CoRR
Alejandro Ranchal-Pedrosa, Vincent Gramoli
2021 A* conf
SP
Tyler Crain, Christopher Natoli, Vincent Gramoli
2020 J jnl
IEEE Netw. Lett.
Seppo Hätönen, Md Tanvir Ishtaique ul Huque, Ashwin Rao, Guillaume Jourjon, Vincent Gramoli, Sasu Tarkoma
2020 conf
ESORICS (1)
Christian Cachin, Daniel Collins, Tyler Crain, Vincent Gramoli
2020 J jnl
CoRR
Alejandro Ranchal-Pedrosa, Vincent Gramoli
2020 A conf
DISC
Pierre Civit, Seth Gilbert, Vincent Gramoli
2020 J jnl
Concurr. Comput. Pract. Exp.
Guillaume Vizier, Vincent Gramoli
2020 B conf
SPAA
Rob van Glabbeek, Vincent Gramoli, Pierre Tholoniat
2020 J jnl
CoRR
Rob van Glabbeek, Vincent Gramoli, Pierre Tholoniat
2020 J jnl
Future Gener. Comput. Syst.
Vincent Gramoli
2020 J jnl
Internet Things
Runchao Han, Gary Shapiro, Vincent Gramoli, Xiwei Xu
2020 A* conf
NDSS
Parinya Ekparinya, Vincent Gramoli, Guillaume Jourjon
2020 B conf
NCA
Gary Shapiro, Christopher Natoli, Vincent Gramoli
2019 J jnl
Concurr. Comput. Pract. Exp.
Tyler Crain, Vincent Gramoli, Michel Raynal
2019 J jnl
CoRR
Christian Cachin, Daniel Collins, Tyler Crain, Vincent Gramoli
2019 J jnl
CoRR
Pierre Tholoniat, Vincent Gramoli
2019 J jnl
CoRR
Rob van Glabbeek, Vincent Gramoli, Pierre Tholoniat
2019 J jnl
CoRR
Christopher Natoli, Jiangshan Yu, Vincent Gramoli, Paulo Jorge Esteves Veríssimo
2019 J jnl
CoRR
Gauthier Voron, Vincent Gramoli
2019 J jnl
CoRR
Canh T. Dinh, Nguyen Hoang Tran, Minh N. H. Nguyen, Choong Seon Hong, Wei Bao, Albert Y. Zomaya, Vincent Gramoli
2019 B conf
NCA
Alejandro Ranchal-Pedrosa, Vincent Gramoli
2019 J jnl
CoRR
Alejandro Ranchal-Pedrosa, Vincent Gramoli
2019 J jnl
IACR Cryptol. ePrint Arch.
Pierre Civit, Seth Gilbert, Vincent Gramoli
2019 J jnl
IEEE Trans. Netw. Serv. Manag.
Md Tanvir Ishtaique ul Huque, Guillaume Jourjon, Craig Russell, Vincent Gramoli
2019 J jnl
CoRR
Parinya Ekparinya, Vincent Gramoli, Guillaume Jourjon
2019 conf
Tokenomics
Michael Spain, Sean Foley, Vincent Gramoli
2018 J jnl
IEEE Commun. Stand. Mag.
Vincent Gramoli, Mark Staples
2018 conf
iThings/GreenCom/CPSCom/SmartData
Guillaume Vizier, Vincent Gramoli
2018 B conf
NCA
Tyler Crain, Vincent Gramoli, Mikel Larrea, Michel Raynal
2018 A* conf
ASPLOS
Stephen Mallon, Vincent Gramoli, Guillaume Jourjon
2018 J jnl
CoRR
Parinya Ekparinya, Vincent Gramoli, Guillaume Jourjon
2018 conf
NTMS
Runchao Han, Vincent Gramoli, Xiwei Xu
2018 J jnl
CoRR
Tyler Crain, Christopher Natoli, Vincent Gramoli
2018 B conf
SRDS
Parinya Ekparinya, Vincent Gramoli, Guillaume Jourjon
2018 conf
Euro-Par
Mansour Khelghatdoust, Vincent Gramoli
2018 J jnl
CoRR
Mansour Khelghatdoust, Vincent Gramoli
2018 J jnl
IEEE Trans. Dependable Secur. Comput.
Daniel Sun, Alan D. Fekete, Vincent Gramoli, Guoqiang Li, Xiwei Xu, Liming Zhu
2018 J jnl
Distributed Comput.
Vincent Gramoli, Rachid Guerraoui, Vasileios Trigonakis
2018 J jnl
CoRR
Lexi Brent, Anton Jurisevic, Michael Kong, Eric Liu, François Gauthier, Vincent Gramoli, Ralph Holz, Bernhard Scholz
2017 J jnl
CoRR
Tyler Crain, Vincent Gramoli, Mikel Larrea, Michel Raynal
2017 conf
Euro-Par
Vitaly Aksenov, Vincent Gramoli, Petr Kuznetsov, Anna Malova, Srivatsan Ravi
2017 J jnl
CoRR
Vitaly Aksenov, Vincent Gramoli, Petr Kuznetsov, Anna Malova, Srivatsan Ravi
2017 J jnl
Concurr. Comput. Pract. Exp.
Ian Dick, Alan D. Fekete, Vincent Gramoli
2017 J jnl
J. Parallel Distributed Comput.
Pascal Felber, Vincent Gramoli, Rachid Guerraoui
2017 J jnl
IEEE Commun. Mag.
Md Tanvir Ishtaique ul Huque, Guillaume Jourjon, Vincent Gramoli
2017 J jnl
IEEE Trans. Netw. Serv. Manag.
Md Tanvir Ishtaique ul Huque, Weisheng Si, Guillaume Jourjon, Vincent Gramoli
2017 B conf
SRDS
Ingo Weber, Vincent Gramoli, Alexander Ponomarev, Mark Staples, Ralph Holz, An Binh Tran, Paul Rimba
2017 B conf
LCN
Parinya Ekparinya, Vincent Gramoli, Guillaume Jourjon, Liming Zhu
2017 A conf
DSN
Christopher Natoli, Vincent Gramoli
2016 J jnl
Parallel Process. Lett.
Tyler Crain, Vincent Gramoli, Michel Raynal
2016 B conf
LCN
Stephen Mallon, Vincent Gramoli, Guillaume Jourjon
2016 J jnl
CoRR
Stephen Mallon, Vincent Gramoli, Guillaume Jourjon
2016 J jnl
IEEE Trans. Parallel Distributed Syst.
Antonio Fernández Anta, Vincent Gramoli, Ernesto Jiménez, Anne-Marie Kermarrec, Michel Raynal
2016 C conf
CLUSTER
Mansour Khelghatdoust, Vincent Gramoli, Daniel Sun
2016 B conf
SIROCCO
Vincent Gramoli, Petr Kuznetsov, Srivatsan Ravi
2016 J jnl
CoRR
Vincent Gramoli, Petr Kuznetsov, Srivatsan Ravi
2016 conf
ACSW
Vincent Gramoli, Michael A. Charleston, Bryn Jeffries, Irena Koprinska, Martin McGrane, Alex Radu, Anastasios Viglas, Kalina Yacef
2016 conf
Euro-Par
Martin Groen, Vincent Gramoli
2016 J jnl
IEEE Trans. Parallel Distributed Syst.
Vincent Gramoli, Len Bass, Alan D. Fekete, Daniel W. Sun
2016 J jnl
CoRR
Christopher Natoli, Vincent Gramoli
2016 B conf
NCA
Christopher Natoli, Vincent Gramoli
2016 J jnl
CoRR
Christopher Natoli, Vincent Gramoli
2016 conf
WICSA
Xiwei Xu, Cesare Pautasso, Liming Zhu, Vincent Gramoli, Alexander Ponomarev, An Binh Tran, Shiping Chen
2016 conf
Euro-Par Workshops
Vincent Gramoli
2015 J jnl
CoRR
Vincent Gramoli, Petr Kuznetsov, Srivatsan Ravi, Di Shang
2015 book
Vincent Gramoli
2015 ch.
Transactional Memory
Hagit Attiya, Vincent Gramoli, Alessia Milani
2015 conf
NETYS
Vincent Gramoli, Guillaume Jourjon, Olivier Mehani
2015 B conf
PPoPP
Vincent Gramoli
2015 B conf
SRDS
Daniel Sun, Daniel Guimarans, Alan D. Fekete, Vincent Gramoli, Liming Zhu
2015 conf
NETYS
Vincent Gramoli, Rachid Guerraoui, Anne-Marie Kermarrec
2015 B conf
LCN
Md Tanvir Ishtaique ul Huque, Guillaume Jourjon, Vincent Gramoli
2015 ch.
Transactional Memory
Pascal Felber, Christof Fetzer, Vincent Gramoli, Derin Harmanci, Martin Nowack
2015 J jnl
Computing
Vincent Gramoli, Rachid Guerraoui
2015 A conf
DISC
Joel Gibson, Vincent Gramoli
2014 J jnl
Bull. EATCS
Maria Couceiro, Vincent Gramoli, Paolo Romano
2014 J jnl
CoRR
Vincent Gramoli, Guillaume Jourjon, Olivier Mehani
2014 J jnl
Commun. ACM
Vincent Gramoli, Rachid Guerraoui
2014 C conf
CloudCom
Peng Lu, Young Choon Lee, Vincent Gramoli, Luke M. Leslie, Albert Y. Zomaya
2014 conf
BDCloud
Daniel Sun, Len Bass, Alan D. Fekete, Vincent Gramoli, An Binh Tran, Sherry Xu, Liming Zhu
2014 A conf
ECOOP
Vincent Gramoli, Rachid Guerraoui
2014 conf
ICOOOLPS@ECOOP
Vincent Gramoli, Andrew E. Santosa
2013 conf
Euro-Par
Tyler Crain, Vincent Gramoli, Michel Raynal
2013 A conf
IPDPS
Vincent Gramoli, Rachid Guerraoui, Mihai Letia
2013 ed.
NETYS
Vincent Gramoli, Rachid Guerraoui
2013 A conf
ICDCS
Tyler Crain, Vincent Gramoli, Michel Raynal
2012 B conf
PPoPP
Tyler Crain, Vincent Gramoli, Michel Raynal
2012 A conf
DISC
Tyler Crain, Vincent Gramoli, Michel Raynal
2012 A* conf
PODC
Vincent Gramoli, Petr Kuznetsov, Srivatsan Ravi
2012 J jnl
CoRR
Vincent Gramoli, Petr Kuznetsov, Srivatsan Ravi
2012 A conf
EuroSys
Vincent Gramoli, Rachid Guerraoui, Vasileios Trigonakis
2012 J jnl
SIGACT News
Vincent Gramoli, Alessia Milani
2011 A conf
ECOOP
Derin Harmanci, Vincent Gramoli, Pascal Felber
2011 B conf
SPAA
Vincent Gramoli, Rachid Guerraoui
2011 A conf
Middleware
Vincent Gramoli, Rachid Guerraoui
2011 J jnl
Commun. ACM
Aleksandar Dragojevic, Pascal Felber, Vincent Gramoli, Rachid Guerraoui
2011 J jnl
Tech. Sci. Informatiques
Vincent Gramoli
2010 C conf
SSS
Hagit Attiya, Vincent Gramoli, Alessia Milani
2010 B conf
SPAA
Hagit Attiya, Vincent Gramoli, Alessia Milani
2010 J jnl
J. Parallel Distributed Comput.
Derin Harmanci, Vincent Gramoli, Pascal Felber, Christof Fetzer
2010 J jnl
Parallel Process. Lett.
Vincent Gramoli, Derin Harmanci, Pascal Felber
2010 J jnl
IEEE Micro
Yehuda Afek, Ulrich Drepper, Pascal Felber, Christof Fetzer, Vincent Gramoli, Michael Hohmuth, Etienne Rivière, Per Stenström, Osman S. Unsal, Walther Maldonado, Derin Harmanci, Patrick Marlier, Stephan Diestelhorst, Martin Pohlack, Adrián Cristal, Ibrahim Hur, Aleksandar Dragojevic, Rachid Guerraoui, Michal Kapalka, Sasa Tomic, Guy Korland, Nir Shavit, Martin Nowack, Torvald Riegel
2010 J jnl
SIGACT News
Srivatsan Ravi, Vincent Gramoli, Victor Luchangco
2009 A conf
DISC
Pascal Felber, Vincent Gramoli, Rachid Guerraoui
2009 J jnl
J. Parallel Distributed Comput.
Gregory V. Chockler, Seth Gilbert, Vincent Gramoli, Peter M. Musial, Alexander A. Shvartsman
2009 J jnl
IEEE Trans. Computers
Vincent Gramoli, Ymir Vigfusson, Ken Birman, Anne-Marie Kermarrec, Robbert van Renesse
2009 J jnl
SIGACT News
Vincent Gramoli
2008 A* conf
PODC
Vincent Gramoli, Ymir Vigfusson, Ken Birman, Anne-Marie Kermarrec, Robbert van Renesse
2008 J jnl
CoRR
Vincent Gramoli, Anne-Marie Kermarrec, Achour Mostéfaoui, Michel Raynal, Bruno Sericola
2008 A* conf
PODC
Vincent Gramoli, Anne-Marie Kermarrec, Erwan Le Merrer
2008 J jnl
CoRR
Erwan Le Merrer, Vincent Gramoli, Anne-Marie Kermarrec, Aline Carneiro Viana, Marin Bertier
2008 Misc conf
EDCC
Vincent Gramoli, Anne-Marie Kermarrec, Erwan Le Merrer
2008 J jnl
CoRR
Vincent Gramoli, Michel Raynal
2008 B conf
OPODIS
Vincent Gramoli, Derin Harmanci, Pascal Felber
2007
Vincent Gramoli
2007 J jnl
CoRR
Antonio Fernández, Vincent Gramoli, Ernesto Jiménez, Anne-Marie Kermarrec, Michel Raynal
2007 A conf
ICDCS
Antonio Fernández, Vincent Gramoli, Ernesto Jiménez, Anne-Marie Kermarrec, Michel Raynal
2007 J jnl
ACM SIGOPS Oper. Syst. Rev.
Paolo Costa, Vincent Gramoli, Márk Jelasity, Gian Paolo Jesi, Erwan Le Merrer, Alberto Montresor, Leonardo Querzoni
2007 Misc conf
SAC
Vincent Gramoli, Emmanuelle Anceaume, Antonino Virgillito
2007 B conf
OPODIS
Vincent Gramoli, Michel Raynal
2006 conf
OTM Workshops (2)
Vincent Gramoli, Anne-Marie Kermarrec, Achour Mostéfaoui, Michel Raynal, Bruno Sericola
2006 J jnl
CoRR
Antonio Fernández, Vincent Gramoli, Ernesto Jiménez, Anne-Marie Kermarrec, Michel Raynal
2006 conf
MobiShare@MobiCom
Erwan Le Merrer, Vincent Gramoli, Anne-Marie Kermarrec, Aline Carneiro Viana, Marin Bertier
2005 conf
PDCS
Vincent Gramoli, Peter M. Musial, Alexander A. Shvartsman
2005 conf
ISPAN
Emmanuelle Anceaume, Maria Gradinariu, Vincent Gramoli, Antonino Virgillito
2005 B conf
OPODIS
Gregory V. Chockler, Seth Gilbert, Vincent Gramoli, Peter M. Musial, Alexander A. Shvartsman
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