Ramez Elmasri

167 papers A* 15A 13B 13C 10Misc 4Journal 33Unranked 63
YearRankTypeTitle / Venue / Authors
2024 J jnl
Int. J. Artif. Intell. Tools
Bhanu Jain, Manfred Huber, Ramez Elmasri
2023 Misc conf
FLAIRS
Bhanu Jain, Manfred Huber, Ramez Elmasri
2021 J jnl
CoRR
Bhanu Jain, Manfred Huber, Ramez Elmasri
2021 conf
PETRA
Mohammad Shaito, Ramez Elmasri
2021 C conf
DATA
Mary E. Koone, Ramez Elmasri
2021 conf
PETRA
Mohammad Rezaei, Farnaz Farahanipad, Alex Dillhoff, Ramez Elmasri, Vassilis Athitsos
2021 conf
PETRA
Poojitha Thota, Ramez Elmasri
2020 J jnl
J. Inf. Telecommun.
Kulsawasd Jitkajornwanich, Neelabh Pant, Mohammadhani Fouladgar, Ramez Elmasri
2019 conf
PETRA
Mousa Almotairi, Tariq Alsahfi, Ramez Elmasri
2019 C conf
NLDB
Aishwarya Ashok, Ramez Elmasri, Ganapathy S. Natarajan
2019 conf
IWCTS@SIGSPATIAL
Tariq Alsahfi, Mousa Almotairi, Ramez Elmasri, Bader Alshemaimri
2018 conf
ACIIDS (2)
Neelabh Pant, Mohammadhani Fouladgar, Ramez Elmasri, Kulsawasd Jitkajornwanich
2018 ch.
Encyclopedia of Database Systems (2nd ed.)
Ramez Elmasri
2018 ch.
Encyclopedia of Database Systems (2nd ed.)
Ramez Elmasri
2018 ch.
Encyclopedia of Database Systems (2nd ed.)
Ramez Elmasri
2018 ch.
Encyclopedia of Database Systems (2nd ed.)
Ramez Elmasri
2018 ch.
Encyclopedia of Database Systems (2nd ed.)
Ramez Elmasri
2018 conf
LocalRec@SIGSPATIAL
Madhuri Debnath, Praveen Kumar Tripathi, Ashis Kumer Biswas, Ramez Elmasri
2018 conf
IWCTS@SIGSPATIAL
Mousa Almotairi, Tariq Alsahfi, Ramez Elmasri
2017 J jnl
CoRR
Mohammadhani Fouladgar, Mostafa Parchami, Ramez Elmasri, Amir Ghaderi
2017 B conf
IJCNN
Mohammadhani Fouladgar, Mostafa Parchami, Ramez Elmasri, Amir Ghaderi
2016 conf
PETRA
Praveen Kumar Tripathi, Madhuri Debnath, Ramez Elmasri
2016 conf
IEEE BigData
Upa Gupta, Kulsawasd Jitkajornwanich, Ramez Elmasri, Leonidas Fegaras
2016 conf
IWGS@SIGSPATIAL
Mohammadhani Fouladgar, Ramez Elmasri
2016 Misc conf
FLAIRS
Madhuri Debnath, Praveen Kumar Tripathi, Ramez Elmasri
2016 conf
SocInfo (1)
Madhuri Debnath, Praveen Kumar Tripathi, Ramez Elmasri
2016 conf
BigData Congress
Surya Narayanan Swaminathan, Ramez Elmasri
2016 A* conf
ICDE
Nandish Jayaram, Arijit Khan, Chengkai Li, Xifeng Yan, Ramez Elmasri
2016 conf
MobiGIS
Mohammadhani Fouladgar, Ramez Elmasri
2015 conf
MOD
Kulsawasd Jitkajornwanich, Ramez Elmasri
2015 conf
MELT@SIGSPATIAL
Praveen Kumar Tripathi, Madhuri Debnath, Ramez Elmasri
2015 conf
ICDM Workshops
Piraporn Jangyodsuk, Dong-Jun Seo, Ramez Elmasri, Jean Gao
2015 J jnl
IEEE Trans. Knowl. Data Eng.
Nandish Jayaram, Arijit Khan, Chengkai Li, Xifeng Yan, Ramez Elmasri
2014 conf
GeoRich@SIGMOD
Praveen Kumar Tripathi, Madhuri Debnath, Ramez Elmasri
2014 A* conf
ICDE
Nandish Jayaram, Mahesh Gupta, Arijit Khan, Chengkai Li, Xifeng Yan, Ramez Elmasri
2014 conf
GRADES
Nandish Jayaram, Arijit Khan, Chengkai Li, Xifeng Yan, Ramez Elmasri
2013 conf
ICDM Workshops
Madhuri Debnath, Praveen Kumar Tripathi, Ramez Elmasri
2013 conf
IEEE BigData
Kulsawasd Jitkajornwanich, Upa Gupta, Sakthi Kumaran Shanmuganathan, Ramez Elmasri, Leonidas Fegaras, John McEnery
2013 J jnl
CoRR
Nandish Jayaram, Arijit Khan, Chengkai Li, Xifeng Yan, Ramez Elmasri
2012 conf
BigSpatial@SIGSPATIAL
Kulsawasd Jitkajornwanich, Ramez Elmasri, John McEnery, Chengkai Li
2012 C conf
CIBCB
Kamal Taha, Ramez Elmasri
2012 J jnl
IEEE Trans. Syst. Man Cybern. Part C
Jae Sung Choi, Hyun Lee, Daniel W. Engels, Ramez Elmasri
2012 B conf
ASONAM
Kamal Taha, Ramez Elmasri
2011 conf
SWIM
Kulsawasd Jitkajornwanich, Ramez Elmasri, Chengkai Li, John McEnery
2011 J jnl
J. Integr. Bioinform.
Kamal Taha, Ramez Elmasri
2011 conf
IEEE SCC
Kamal Taha, Ramez Elmasri
2011 conf
RFID-TA
Jae Sung Choi, Mingon Kang, Ramez Elmasri, Daniel W. Engels
2010 B conf
AINA
Hyun Lee, Jae Sung Choi, Ramez Elmasri
2010 J jnl
J. Digit. Inf. Manag.
Kamal Taha, Ramez Elmasri
2010 J jnl
IEEE Trans. Syst. Man Cybern. Part A
Hyun Lee, Jae Sung Choi, Ramez Elmasri
2010 J jnl
Knowl. Inf. Syst.
Kamal Taha, Ramez Elmasri
2010 J jnl
J. Digit. Content Technol. its Appl.
Hyun Lee, Byoungyong Lee, Kyungseo Park, Ramez Elmasri
2010 J jnl
Inf. Syst.
Kamal Taha, Ramez Elmasri
2010 J jnl
IEEE Trans. Knowl. Data Eng.
Kamal Taha, Ramez Elmasri
2009 conf
PerCom Workshops
Hyun Lee, Jae Sung Choi, Ramez Elmasri
2009 B conf
SMC
Hyun Lee, Jae Sung Choi, Ramez Elmasri
2009 conf
NCM
Hyun Lee, Young Ran Lee, Jae Sung Choi, Ramez Elmasri
2009 book
Grundlagen von Datenbanksystemen (3. Aufl., Bachelorausgabe).
Ramez Elmasri, Shamkant B. Navathe
2009 conf
XSym
Kamal Taha, Ramez Elmasri
2009 conf
NCM
Jae Sung Choi, Hyun Lee, Ramez Elmasri, Daniel W. Engels
2009 J jnl
J. Database Manag.
Kamal Taha, Ramez Elmasri
2009 J jnl
J. Comput. Sci. Eng.
Hyoil Han, Ramez Elmasri, Martin Doerr, Mathias Brochhausen
2009 B conf
AINA
Hyun Lee, Jae Sung Choi, Ramez Elmasri
2009 conf
CSE (1)
Kamal Taha, Ramez Elmasri
2008 conf
WSAN
Byoungyong Lee, Kyungseo Park, Ramez Elmasri
2008 conf
DataX@EDBT
Kamal Taha, Ramez Elmasri
2008 conf
PETRA
Hyun Lee, Kyungseo Park, Byoungyong Lee, Jae Sung Choi, Ramez Elmasri
2008 Misc conf
SAC
Jack Fu, Feng Ji, Ramez Elmasri
2008 ed.
ONISW
Ramez Elmasri, Martin Doerr, Mathias Brochhausen, Hyoil Han
2007 conf
CCNC
Byoungyong Lee, Kyungseo Park, Ramez Elmasri
2007 conf
AINA Workshops (2)
Kyungseo Park, Byoungyong Lee, Ramez Elmasri
2007 J jnl
Int. J. Bioinform. Res. Appl.
Ramez Elmasri, Feng Ji, Jack Fu, Yiming Zhang, Zoe Raja
2007 B conf
CBMS
Ramez Elmasri, Jack Fu, Feng Ji
2007 conf
BNCOD
Kamal Taha, Ramez Elmasri
2007 conf
ICOIN
Byoungyong Lee, Kyungseo Park, Ramez Elmasri
2007 Misc conf
CATA
Jae Sung Choi, Yonghe Liu, Ramez Elmasri
2007 conf
PDCS
Jae Sung Choi, Byoungyong Lee, Kyungseo Park, Ramez Elmasri
2006 ed.
ER (Workshops)
John F. Roddick, V. Richard Benjamins, Samira Si-Said Cherfi, Roger H. L. Chiang, Christophe Claramunt, Ramez Elmasri, Fabio Grandi, Hyoil Han, Martin Hepp, Miltiadis D. Lytras, Vojislav B. Misic, Geert Poels, Il-Yeol Song, Juan Trujillo, Christelle Vangenot
2006 conf
ICOIN
Kyungseo Park, Ramez Elmasri
2006 B conf
CBMS
Ramez Elmasri, Feng Ji, Jack Fu, Yiming Zhang, Zoe Raja
2006 conf
ER (Workshops)
Hyoil Han, Ramez Elmasri
2006 conf
ICDE Workshops
Kyungseo Park, Ramez Elmasri
2005 C conf
AICCSA
Choong Hun Kim, Kyungseo Park, Jack Fu, Ramez Elmasri
2005 J jnl
Data Knowl. Eng.
Ramez Elmasri, Qing Li, Jack Fu, Yu-Chi Wu, Babak Hojabri, Swathi Ande
2005 book
Ramez Elmasri, Shamkant B. Navathe
2005 C conf
AICCSA
Feng Ji, Ramez Elmasri, Yiming Zhang, B. Ritesh, Zoe Raja
2004 J jnl
J. Intell. Inf. Syst.
Hyoil Han, Ramez Elmasri
2003 B conf
LCN
Kyungseo Park, Ramez Elmasri, Wook Choi
2003 J jnl
SIGMOD Rec.
Sharma Chakravarthy, Y. Alp Aslandogan, Ramez Elmasri, Leonidas Fegaras, Jung-Hwan Oh
2003 B conf
WCNC
Damla Turgut, Begumhan Turgut, Ramez Elmasri, Than V. Le
2002 A conf
ER
Ramez Elmasri, Yu-Chi Wu, Babak Hojabri, Charley Li, Jack Fu
2002 book
Grundlagen von Datenbanksystemen (3. Aufl.).
Ramez Elmasri, Shamkant B. Navathe
2002 B conf
GLOBECOM
Damla Turgut, Sajal K. Das, Ramez Elmasri, Begumhan Turgut
2002 A* conf
ICDE
Mutsumi Nakamura, Ramez Elmasri
2001 conf
OOIS
Damla Turgut, Nevin Aydin, Ramez Elmasri, Begumhan Turgut
2001 A* conf
ICDE
Jae Young Lee, Ramez Elmasri
2001 conf
DEXA Workshop
Jason Dongwon Kwak, Ramez Elmasri, Wook Choi, Rung-Chi Ye, Ajit Mahareddy
2001 conf
International Conference on Internet Computing (1)
Hyoil Han, Ramez Elmasri
2001 conf
International Conference on Internet Computing (1)
Hyoil Han, S. Garimella, Ramez Elmasri
2001 conf
OOIS
Damla Turgut, Nevin Aydin, Ramez Elmasri, Begumhan Turgut
2001 conf
International Conference on Internet Computing (1)
Hyoil Han, Ramez Elmasri
2001 A* conf
VLDB
Leonidas Fegaras, Ramez Elmasri
2001 B conf
COMPSAC
Damla Turgut, Nevin Aydin, Ramez Elmasri, Begumhan Turgut
2000 book
Fundamentals of Database Systems, 3rd Edition.
Ramez Elmasri, Shamkant B. Navathe
2000 C conf
TIME
Han-Chieh Wei, Ramez Elmasri
2000 J jnl
Ann. Math. Artif. Intell.
Han-Chieh Wei, Ramez Elmasri
2000 conf
WISE (2)
Keng-Woei Tan, Hyoil Han, Ramez Elmasri
2000 conf
JISBD
Ramez Elmasri
1999 C conf
TIME
Han-Chieh Wei, Ramez Elmasri
1998 conf
DIISM
Ramez Elmasri, Daeweon Son, John J. Mills, N. Kishor
1998 C conf
TIME
Leonidas Fegaras, Ramez Elmasri
1998 conf
DIISM
John J. Mills, M. Brand, Ramez Elmasri
1998 A conf
ER
Jae Young Lee, Ramez Elmasri
1998 J jnl
Data Knowl. Eng.
Jae Yong Lee, Ramez Elmasri, Jongho Won
1997 conf
NGITS
Jongho Won, Ramez Elmasri, Jason Dongwon Kwak
1997 conf
Temporal Databases, Dagstuhl
Ramez Elmasri, Jae Young Lee
1997 conf
Temporal Databases, Dagstuhl
Christian S. Jensen, Curtis E. Dyreson, Michael H. Böhlen, James Clifford, Ramez Elmasri, Shashi K. Gadia, Fabio Grandi, Patrick J. Hayes, Sushil Jajodia, Wolfgang Käfer, Nick Kline, Nikos A. Lorentzos, Yannis G. Mitsopoulos, Angelo Montanari, Daniel A. Nonen, Elisa Peressi, Barbara Pernici, John F. Roddick, Nandlal L. Sarda, Maria Rita Scalas, Arie Segev, Richard T. Snodgrass, Michael D. Soo, Abdullah Uz Tansel, Paolo Tiberio, Gio Wiederhold
1997 J jnl
J. Syst. Integr.
Vram Kouramajian, Ramez Elmasri
1996 B conf
SSDBM
Daeweon Son, Ramez Elmasri
1996 C conf
DEXA
Mario A. Nascimento, Margaret H. Dunham, Ramez Elmasri
1996 A* conf
ICDE
Jongho Won, Ramez Elmasri
1996 A conf
ER
Jae Young Lee, Ramez Elmasri, Jongho Won
1995 C conf
ISCC
Bob Welch, Abdelsalam Helal, Ramez Elmasri
1995 B conf
DASFAA
Vram Kouramajian, Ramez Elmasri
1995 conf
ACM Southeast Regional Conference
Vram Kouramajian, Ramez Elmasri
1994 J jnl
SIGMOD Rec.
Christian S. Jensen, James Clifford, Ramez Elmasri, Shashi K. Gadia, Patrick J. Hayes, Sushil Jajodia
1994 J jnl
SIGMOD Rec.
Richard T. Snodgrass, Ilsoo Ahn, Gad Ariav, Don S. Batory, James Clifford, Curtis E. Dyreson, Ramez Elmasri, Fabio Grandi, Christian S. Jensen, Wolfgang Käfer, Nick Kline, Krishna G. Kulkarni, T. Y. Cliff Leung, Nikos A. Lorentzos, John F. Roddick, Arie Segev, Michael D. Soo, Suryanarayana M. Sripada
1994 A* conf
ICDE
Vram Kouramajian, Ramez Elmasri, Anurag Chaudhry
1994 A ed.
ER
Ramez Elmasri, Vram Kouramajian, Bernhard Thalheim
1994 book
Ramez Elmasri, Shamkant B. Navathe
1994 J jnl
SIGMOD Rec.
Richard T. Snodgrass, Ilsoo Ahn, Gad Ariav, Don S. Batory, James Clifford, Curtis E. Dyreson, Ramez Elmasri, Fabio Grandi, Christian S. Jensen, Wolfgang Käfer, Nick Kline, Krishna G. Kulkarni, T. Y. Cliff Leung, Nikos A. Lorentzos, John F. Roddick, Arie Segev, Michael D. Soo, Suryanarayana M. Sripada
1994 A conf
CIKM
Vram Kouramajian, Ibrahim Kamel, Ramez Elmasri, Syed Waheed
1994 J jnl
SIGMOD Rec.
Niki Pissinou, Richard T. Snodgrass, Ramez Elmasri, Inderpal Singh Mumick, M. Tamer Özsu, Barbara Pernici, Arie Segev, Babis Theodoulidis, Umeshwar Dayal
1993 ch.
Temporal Databases
Ramez Elmasri, Gene T. J. Wuu, Vram Kouramajian
1993 conf
Advanced Database Systems
Ramez Elmasri, Vram Kouramajian
1993 A conf
CIKM
Abdelsalam Helal, Tung-Hui Ku, Ramez Elmasri, Sourav Mukherjee
1993 conf
DOOD
Ramez Elmasri, Suresh James, Vram Kouramajian
1993 A conf
CIKM
Ramez Elmasri, Vram Kouramajian, Shian Fernando
1993 ch.
Temporal Databases
Ramez Elmasri, Gene T. J. Wuu, Vram Kouramajian
1993 conf
Interfaces in Industrial Systems for Production Engineering
John J. Mills, John K. Graham, Ramez Elmasri, Bob P. Weems
1992 A conf
ER
Ramez Elmasri, Vram Kouramajian
1992 A* conf
ICDE
Ramez Elmasri, Muhammad Jaseemuddin, Vram Kouramajian
1991 A* conf
VLDB
Ramez Elmasri
1991 A* conf
ICDE
Ramez Elmasri, Yeong-Joon Kim, Gene T. J. Wuu
1991 A conf
ER
Vram Kouramajian, Ramez Elmasri
1990 J jnl
Computer
Bogdan D. Czejdo, Ramez Elmasri, Marek Rusinkiewicz, David W. Embley
1990 A* conf
ICDE
Ramez Elmasri, Gene T. J. Wuu
1990 A conf
ER
Ramez Elmasri, Ihab El-Assal, Vram Kouramajian
1990 A* conf
VLDB
Ramez Elmasri, Gene T. J. Wuu, Yeong-Joon Kim
1989 J jnl
IEEE Trans. Software Eng.
James A. Larson, Shamkant B. Navathe, Ramez Elmasri
1989 book
Fundamentals of Database Systems
Ramez Elmasri, Shamkant B. Navathe
1988 conf
DPDS
M. Samy Gamal-Eldin, Gomer Thomas, Ramez Elmasri
1988 conf
ACM Conference on Computer Science
Bogdan D. Czejdo, Ramez Elmasri, Marek Rusinkiewicz, David W. Embley
1987 conf
ACM Conference on Computer Science
Bogdan D. Czejdo, Ramez Elmasri, Marek Rusinkiewicz, David W. Embley
1987 A* conf
ICDE
Ramez Elmasri, P. Srinivas, Gomer Thomas
1986 J jnl
Computer
Shamkant B. Navathe, Ramez Elmasri, James A. Larson
1985 A conf
ER
Ramez Elmasri, James A. Larson
1985 J jnl
Data Knowl. Eng.
Ramez Elmasri, James A. Weeldreyer, Alan R. Hevner
1984 A* conf
ICDE
Ramez Elmasri, Shamkant B. Navathe
1984 A* conf
VLDB
Shamkant B. Navathe, T. Sashidhar, Ramez Elmasri
1984 J jnl
IEEE Database Eng. Bull.
Ramez Elmasri, James A. Larson, Shamkant B. Navathe, T. Sahidar
1981 A conf
ER
Ramez Elmasri, Gio Wiederhold
1981 J jnl
SIGMOD Rec.
Ramez Elmasri, Cory Devor, Said K. Rahimi
1980
Ramez Elmasri
1980 conf
AFIPS National Computer Conference
Ramez Elmasri, Gio Wiederhold
1979 conf
SIGMOD Conference
Ramez Elmasri, Gio Wiederhold
1979 A conf
ER
Gio Wiederhold, Ramez Elmasri
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