Oscar H. Ibarra

437 papers A* 24A 8B 35C 45Misc 9Journal 256Unranked 57
YearRankTypeTitle / Venue / Authors
2026 J jnl
Theor. Comput. Sci.
Noah Friesen, Oscar H. Ibarra, Jozef Jirásek, Ian McQuillan
2025 J jnl
Int. J. Found. Comput. Sci.
Oscar H. Ibarra, Ian McQuillan
2025 J jnl
Nat. Comput.
Oscar H. Ibarra, Ian McQuillan
2025 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Ian McQuillan
2025 J jnl
Inf. Comput.
Oscar H. Ibarra, Ian McQuillan
2025 C conf
DLT
Oscar H. Ibarra, Ian McQuillan
2025 J jnl
CoRR
Noah Friesen, Oscar H. Ibarra, Jozef Jirásek, Ian McQuillan
2024 J jnl
Comput. Sci. J. Moldova
Oscar H. Ibarra, Ian McQuillan
2024 C conf
DLT
Oscar H. Ibarra, Ian McQuillan
2024 J jnl
CoRR
Oscar H. Ibarra, Ian McQuillan
2023 J jnl
Inf. Comput.
Oscar H. Ibarra, Ian McQuillan
2023 conf
ATVA (1)
Oscar H. Ibarra, Ian McQuillan
2023 J jnl
Inf. Comput.
Oscar H. Ibarra, Ian McQuillan
2023 B conf
FoSSaCS
Pascal Baumann, Flavio D'Alessandro, Moses Ganardi, Oscar H. Ibarra, Ian McQuillan, Lia Schütze, Georg Zetzsche
2023 J jnl
CoRR
Pascal Baumann, Flavio D'Alessandro, Moses Ganardi, Oscar H. Ibarra, Ian McQuillan, Lia Schütze, Georg Zetzsche
2022 J jnl
CoRR
Oscar H. Ibarra, Ian McQuillan
2022 J jnl
CoRR
Oscar H. Ibarra, Ian McQuillan
2022 C conf
DLT
Oscar H. Ibarra, Ian McQuillan
2022 J jnl
CoRR
Arturo Carpi, Flavio D'Alessandro, Oscar H. Ibarra, Ian McQuillan
2022 J jnl
CoRR
Oscar H. Ibarra, Ian McQuillan
2022 J jnl
CoRR
Oscar H. Ibarra, Jozef Jirásek, Ian McQuillan, Luca Prigioniero
2022 J jnl
CoRR
Oscar H. Ibarra, Ian McQuillan
2021 J jnl
Int. J. Found. Comput. Sci.
Oscar H. Ibarra, Sartaj K. Sahni
2021 J jnl
Int. J. Found. Comput. Sci.
Oscar H. Ibarra, Ian McQuillan
2021 J jnl
Inf. Comput.
Flavio D'Alessandro, Oscar H. Ibarra, Ian McQuillan
2021 J jnl
Theor. Comput. Sci.
Arturo Carpi, Flavio D'Alessandro, Oscar H. Ibarra, Ian McQuillan
2021 J jnl
Int. J. Found. Comput. Sci.
Oscar H. Ibarra, Jozef Jirásek, Ian McQuillan, Luca Prigioniero
2020 J jnl
CoRR
Oscar H. Ibarra, Ian McQuillan
2020 J jnl
Int. J. Found. Comput. Sci.
Oscar H. Ibarra, Ian McQuillan
2020 C conf
DLT
Oscar H. Ibarra, Jozef Jirásek Jr., Ian McQuillan, Luca Prigioniero
2019 J jnl
CoRR
Joey Eremondi, Oscar H. Ibarra, Ian McQuillan
2019 J jnl
J. Comput. Syst. Sci.
Joey Eremondi, Oscar H. Ibarra, Ian McQuillan
2019 J jnl
CoRR
Oscar H. Ibarra, Ian McQuillan, Bala Ravikumar
2019 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Ian McQuillan, Bala Ravikumar
2019 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Ian McQuillan
2019 J jnl
Inf. Comput.
Oscar H. Ibarra, Ian McQuillan
2019 J jnl
CoRR
Joey Eremondi, Oscar H. Ibarra, Ian McQuillan
2019 J jnl
CoRR
Oscar H. Ibarra, Ian McQuillan
2019 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Ian McQuillan
2018 J jnl
Inf. Comput.
Oscar H. Ibarra, Zhe Dang, Qin Li
2018 C conf
DLT
Oscar H. Ibarra, Ian McQuillan
2018 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra
2018 ch.
Reversibility and Universality
Oscar H. Ibarra, Ian McQuillan
2018 conf
IPDPS Workshops
Oscar H. Ibarra, Koji Nakano, Akihiro Fujiwara, Susumu Matsumae
2018 C conf
DLT
Oscar H. Ibarra, Ian McQuillan, Bala Ravikumar
2018 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Ian McQuillan
2018 J jnl
Int. J. Found. Comput. Sci.
Joey Eremondi, Oscar H. Ibarra, Ian McQuillan
2018 J jnl
J. Autom. Lang. Comb.
Oscar H. Ibarra, Ian McQuillan
2018 J jnl
Inf. Comput.
Joey Eremondi, Oscar H. Ibarra, Ian McQuillan
2018 C conf
CIAA
Oscar H. Ibarra, Ian McQuillan
2018 conf
DCFS
Oscar H. Ibarra, Ian McQuillan
2018 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Ian McQuillan
2017 J jnl
Inf. Comput.
Joey Eremondi, Oscar H. Ibarra, Ian McQuillan
2017 J jnl
Inf. Comput.
Srujan Kumar Enaganti, Oscar H. Ibarra, Lila Kari, Steffen Kopecki
2017 J jnl
Inf. Comput.
Cewei Cui, Zhe Dang, Thomas R. Fischer, Oscar H. Ibarra
2017 conf
IPDPS Workshops
Oscar H. Ibarra, Koji Nakano
2017 J jnl
Comput.
Oscar H. Ibarra, Cewei Cui, Zhe Dang, Thomas R. Fischer
2017 C conf
LATA
Flavio D'Alessandro, Oscar H. Ibarra, Ian McQuillan
2017 J jnl
CoRR
Oscar H. Ibarra, Ian McQuillan
2017 J jnl
Nat. Comput.
Srujan Kumar Enaganti, Oscar H. Ibarra, Lila Kari, Steffen Kopecki
2017 C conf
DLT
Oscar H. Ibarra, Ian McQuillan
2017 J jnl
CoRR
Oscar H. Ibarra, Ian McQuillan
2016 conf
IPDPS Workshops
Oscar H. Ibarra, Koji Nakano, Akihiro Fujiwara, Susumu Matsumae
2016 J jnl
Int. J. Found. Comput. Sci.
Francis Y. L. Chin, Oscar H. Ibarra, Sartaj K. Sahni
2016 J jnl
CoRR
Joey Eremondi, Oscar H. Ibarra, Ian McQuillan
2016 J jnl
Inf. Comput.
Cewei Cui, Zhe Dang, Thomas R. Fischer, Oscar H. Ibarra
2016 C conf
CIAA
Oscar H. Ibarra, Ian McQuillan
2016 C conf
DLT
Oscar H. Ibarra, Ian McQuillan
2016 J jnl
CoRR
Flavio D'Alessandro, Oscar H. Ibarra, Ian McQuillan
2016 J jnl
Inf. Comput.
Oscar H. Ibarra, Bala Ravikumar
2016 J jnl
Nat. Comput.
Oscar H. Ibarra
2016 J jnl
CoRR
Joey Eremondi, Oscar H. Ibarra, Ian McQuillan
2016 J jnl
Nat. Comput.
Oscar H. Ibarra, Lila Kari, Steffen Kopecki
2016 J jnl
Theor. Comput. Sci.
Zhe Dang, Thomas R. Fischer, William J. Hutton III, Oscar H. Ibarra, Qin Li
2016 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Ian McQuillan
2016 J jnl
Fundam. Informaticae
Oscar H. Ibarra
2015 conf
IPDPS Workshops
Oscar H. Ibarra, Koji Nakano, Akihiro Fujiwara, Susumu Matsumae
2015 J jnl
Int. J. Found. Comput. Sci.
Arto Salomaa, Francis Y. L. Chin, Oscar H. Ibarra, Sartaj Sahni
2015 C conf
TAMC
Joey Eremondi, Oscar H. Ibarra, Ian McQuillan
2015 C conf
LATA
Joey Eremondi, Oscar H. Ibarra, Ian McQuillan
2015 J jnl
Int. J. Found. Comput. Sci.
Oscar H. Ibarra
2015 conf
DCFS
Joey Eremondi, Oscar H. Ibarra, Ian McQuillan
2015 C conf
DLT
Joey Eremondi, Oscar H. Ibarra, Ian McQuillan
2015 Misc conf
COCOON
Zhe Dang, Thomas R. Fischer, William J. Hutton III, Oscar H. Ibarra, Qin Li
2015 J jnl
Fundam. Informaticae
Oscar H. Ibarra, Shinnosuke Seki
2014 conf
IPDPS Workshops
Oscar H. Ibarra
2014 conf
DCFS
Oscar H. Ibarra
2014 J jnl
Formal Methods Syst. Des.
Fang Yu, Muath Alkhalaf, Tevfik Bultan, Oscar H. Ibarra
2014 conf
MFCS (1)
Cewei Cui, Zhe Dang, Thomas R. Fischer, Oscar H. Ibarra
2014 C conf
CiE
Oscar H. Ibarra, Cewei Cui, Zhe Dang, Thomas R. Fischer
2014 B conf
DNA
Oscar H. Ibarra
2014 C conf
CIAA
Oscar H. Ibarra
2014 C conf
LATA
Oscar H. Ibarra, Bala Ravikumar
2014 J jnl
Int. J. Found. Comput. Sci.
Oscar H. Ibarra, Bala Ravikumar
2014 ed.
UCNC
Oscar H. Ibarra, Lila Kari, Steffen Kopecki
2014 J jnl
J. Autom. Lang. Comb.
Oscar H. Ibarra, Nicholas Q. Trân
2013 conf
IPDPS Workshops
Oscar H. Ibarra
2013 C conf
LATA
Cewei Cui, Zhe Dang, Thomas R. Fischer, Oscar H. Ibarra
2013 J jnl
Int. J. Found. Comput. Sci.
Oscar H. Ibarra, Nicholas Q. Trân
2013 C conf
LATA
Oscar H. Ibarra, Bala Ravikumar
2013 C conf
TAMC
Oscar H. Ibarra, Shinnosuke Seki
2013 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Shinnosuke Seki
2013 J jnl
Int. J. Found. Comput. Sci.
Hsu-Chun Yen, Oscar H. Ibarra
2013 J jnl
Theor. Comput. Sci.
Cewei Cui, Zhe Dang, Thomas R. Fischer, Oscar H. Ibarra
2013 C conf
CIAA
Oscar H. Ibarra, Bala Ravikumar
2013 C conf
Developments in Language Theory
Oscar H. Ibarra, Bala Ravikumar
2012 J jnl
Fundam. Informaticae
Oscar H. Ibarra, Ömer Egecioglu
2012 conf
IPDPS Workshops
Oscar H. Ibarra
2012 J jnl
Int. J. Found. Comput. Sci.
Oscar H. Ibarra, Shinnosuke Seki
2012 C ed.
Developments in Language Theory
Hsu-Chun Yen, Oscar H. Ibarra
2012 C conf
CIAA
Oscar H. Ibarra, Nicholas Q. Trân
2012 B conf
SOFSEM
Ömer Egecioglu, Oscar H. Ibarra, Nicholas Q. Trân
2012 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Nicholas Q. Trân
2012 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Hsu-Chun Yen
2012 J jnl
Theor. Comput. Sci.
Ehsan Chiniforooshan, Mark Daley, Oscar H. Ibarra, Lila Kari, Shinnosuke Seki
2012 J jnl
Int. J. Found. Comput. Sci.
Francis Y. L. Chin, Oscar H. Ibarra, Sartaj Sahni, Arto Salomaa
2012 C conf
LATA
Oscar H. Ibarra, Nicholas Q. Trân
2011 conf
IPDPS Workshops
Oscar H. Ibarra
2011 conf
AFL
Oscar H. Ibarra, Shinnosuke Seki
2011 J jnl
Int. J. Found. Comput. Sci.
Oscar H. Ibarra
2011 conf
DCFS
Oscar H. Ibarra, Nicholas Q. Trân
2011 C conf
Developments in Language Theory
Oscar H. Ibarra, Hsu-Chun Yen
2011 C conf
CIAA
Oscar H. Ibarra
2011 B conf
SOFSEM
Ehsan Chiniforooshan, Mark Daley, Oscar H. Ibarra, Lila Kari, Shinnosuke Seki
2011 J jnl
Int. J. Found. Comput. Sci.
Fang Yu, Tevfik Bultan, Oscar H. Ibarra
2010 conf
IPDPS Workshops
Oscar H. Ibarra
2010 J jnl
Nat. Comput.
Linmin Yang, Zhe Dang, Oscar H. Ibarra
2010 Misc conf
COCOON
Oscar H. Ibarra
2010 C conf
Developments in Language Theory
Oscar H. Ibarra
2010 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Igor Potapov, Hsu-Chun Yen
2010 J jnl
Theor. Comput. Sci.
Pierluigi Frisco, Oscar H. Ibarra
2010 J jnl
Nat. Comput.
Oscar H. Ibarra, Mario J. Pérez-Jiménez, Takashi Yokomori
2010 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Juhani Karhumäki, Alexander Okhotin
2010 J jnl
Inf. Comput.
Oscar H. Ibarra
2010 J jnl
Int. J. Found. Comput. Sci.
Oscar H. Ibarra, Hsu-Chun Yen
2010 C conf
CIAA
Fang Yu, Tevfik Bultan, Oscar H. Ibarra
2009 conf
Workshop on Membrane Computing
Oscar H. Ibarra
2009 B ed.
ISAAC
Yingfei Dong, Ding-Zhu Du, Oscar H. Ibarra
2009 J jnl
Theor. Comput. Sci.
Matteo Cavaliere, Oscar H. Ibarra, Gheorghe Paun, Ömer Egecioglu, Mihai Ionescu, Sara Woodworth
2009 Misc conf
COCOON
Oscar H. Ibarra, Ömer Egecioglu
2009 conf
DCFS
Pierluigi Frisco, Oscar H. Ibarra
2009 conf
Algorithmic Bioprocesses
Oscar H. Ibarra, Sara Woodworth
2009 C conf
CiE
Ömer Egecioglu, Oscar H. Ibarra
2009 C conf
Developments in Language Theory
Pierluigi Frisco, Oscar H. Ibarra
2009 J jnl
Int. J. Found. Comput. Sci.
Oscar H. Ibarra, Bala Ravikumar
2009 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Andrei Paun, Alfonso Rodríguez-Patón
2009 A conf
TACAS
Fang Yu, Tevfik Bultan, Oscar H. Ibarra
2008 J jnl
Nat. Comput.
Oscar H. Ibarra, Sara Woodworth
2008 conf
ISPAN
Oscar H. Ibarra
2008 J jnl
Int. J. Parallel Emergent Distributed Syst.
Oscar H. Ibarra, Andrei Paun
2008 J jnl
Int. J. Found. Comput. Sci.
John Jack, Alfonso Rodríguez-Patón, Oscar H. Ibarra, Andrei Paun
2008 C ed.
CIAA
Oscar H. Ibarra, Bala Ravikumar
2008 J jnl
Theor. Comput. Sci.
Cagdas Evren Gerede, Oscar H. Ibarra, Bala Ravikumar, Jianwen Su
2008 J jnl
Int. J. Found. Comput. Sci.
Oscar H. Ibarra, Zhe Dang, Linmin Yang
2008 J jnl
Int. J. Found. Comput. Sci.
Linmin Yang, Zhe Dang, Oscar H. Ibarra
2008 B conf
LATIN
Oscar H. Ibarra, Juhani Karhumäki, Alexander Okhotin
2008 J jnl
Nat. Comput.
Oscar H. Ibarra, Sara Woodworth, Fang Yu, Andrei Paun
2008 B conf
DNA
Oscar H. Ibarra, Andrei Paun, Alfonso Rodríguez-Patón
2008 conf
SPIN
Fang Yu, Tevfik Bultan, Marco Cova, Oscar H. Ibarra
2007 conf
Formal Models, Languages and Applications
Ömer Egecioglu, Oscar H. Ibarra
2007 B conf
DNA
Matteo Cavaliere, Ömer Egecioglu, Oscar H. Ibarra, Mihai Ionescu, Gheorghe Paun, Sara Woodworth
2007 C conf
UC
Linmin Yang, Zhe Dang, Oscar H. Ibarra
2007 J jnl
Int. J. Found. Comput. Sci.
Oscar H. Ibarra, Sara Woodworth
2007 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra
2007 ch.
Handbook of Parallel Computing
Andrei Paun, Oscar H. Ibarra
2007 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Andrei Paun, Gheorghe Paun, Alfonso Rodríguez-Patón, Petr Sosík, Sara Woodworth
2007 J jnl
Int. J. Found. Comput. Sci.
Oscar H. Ibarra, Hsu-Chun Yen
2007 B conf
FCT
Oscar H. Ibarra, Sara Woodworth
2006 conf
Workshop on Membrane Computing
Oscar H. Ibarra, Sara Woodworth
2006 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Gheorghe Paun
2006 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Hsu-Chun Yen
2006 C ed.
Developments in Language Theory
Oscar H. Ibarra, Zhe Dang
2006 C ed.
CIAA
Oscar H. Ibarra, Hsu-Chun Yen
2006 C conf
UC
Oscar H. Ibarra, Sara Woodworth, Fang Yu, Andrei Paun
2006 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Bala Ravikumar
2006 J jnl
Int. J. Comput. Math.
Oscar H. Ibarra, Sara Woodworth
2006 J jnl
Nat. Comput.
Erzsébet Csuhaj-Varjú, Oscar H. Ibarra, György Vaszil
2006 J jnl
Fundam. Informaticae
Oscar H. Ibarra, Sara Woodworth, Hsu-Chun Yen, Zhe Dang
2006 J jnl
J. Autom. Lang. Comb.
Zhe Dang, Oscar H. Ibarra, Cheng Li, Gaoyan Xie
2006 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Zhe Dang
2006 J jnl
J. Autom. Lang. Comb.
Oscar H. Ibarra, Bala Ravikumar, Cagdas Evren Gerede
2005 B conf
DNA
Oscar H. Ibarra, Andrei Paun
2005 B conf
DNA
Oscar H. Ibarra, Sara Woodworth
2005 C conf
CIAA
Oscar H. Ibarra, Hsu-Chun Yen
2005 C conf
UC
Zhe Dang, Oscar H. Ibarra, Cheng Li, Gaoyan Xie
2005 Misc conf
COCOON
Oscar H. Ibarra, Sara Woodworth, Hsu-Chun Yen, Zhe Dang
2005 conf
Workshop on Membrane Computing
Oscar H. Ibarra, Sara Woodworth, Hsu-Chun Yen, Zhe Dang
2005 Misc conf
SYNASC
Oscar H. Ibarra, Sara Woodworth
2005 J jnl
Theor. Comput. Sci.
Zhe Dang, Oscar H. Ibarra, Jianwen Su
2005 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra
2005 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra
2005 J jnl
Int. J. Found. Comput. Sci.
Zhe Dang, Oscar H. Ibarra
2005 J jnl
Theor. Comput. Sci.
Zhe Dang, Oscar H. Ibarra, Zhi-Wei Sun
2005 J jnl
Int. J. Found. Comput. Sci.
Oscar H. Ibarra, Hsu-Chun Yen, Zhe Dang
2005 conf
IEEE SCC
Cagdas Evren Gerede, Oscar H. Ibarra, Bala Ravikumar, Jianwen Su
2005 A conf
ICSOC
Ozgur D. Sahin, Cagdas Evren Gerede, Divyakant Agrawal, Amr El Abbadi, Oscar H. Ibarra, Jianwen Su
2005 A* conf
ICALP
Cheng Li, Zhe Dang, Oscar H. Ibarra, Hsu-Chun Yen
2005 B conf
MFCS
Oscar H. Ibarra
2005 conf
Workshop on Membrane Computing
Oscar H. Ibarra
2004 conf
IFIP TCS
Ömer Egecioglu, Oscar H. Ibarra
2004 C conf
CIAA
Oscar H. Ibarra
2004 A conf
ICSOC
Cagdas Evren Gerede, Richard Hull, Oscar H. Ibarra, Jianwen Su
2004 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Zhe Dang, Ömer Egecioglu
2004 B conf
ISAAC
Zhe Dang, Oscar H. Ibarra, Jianwen Su
2004 J jnl
Int. J. Found. Comput. Sci.
Oscar H. Ibarra, Louxin Zhang
2004 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra
2004 J jnl
Int. J. Found. Comput. Sci.
Jacir Luiz Bordim, Oscar H. Ibarra, Yasuaki Ito, Koji Nakano
2004 B conf
ICALT
Yasmín Pérez, Rafael Gamboa, Oscar H. Ibarra
2004 conf
DCFS
Zhe Dang, Oscar H. Ibarra
2004 B conf
DNA
Erzsébet Csuhaj-Varjú, Oscar H. Ibarra, György Vaszil
2004 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra
2004 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Zhe Dang
2004 conf
UPP
Oscar H. Ibarra
2004 J jnl
Theor. Comput. Sci.
Zhe Dang, Tevfik Bultan, Oscar H. Ibarra, Richard A. Kemmerer
2004 conf
FSTTCS
Zhe Dang, Oscar H. Ibarra, Pierluigi San Pietro, Gaoyan Xie
2004 C conf
Developments in Language Theory
Oscar H. Ibarra, Hsu-Chun Yen, Zhe Dang
2003 A* conf
ICALP
Gaoyan Xie, Zhe Dang, Oscar H. Ibarra
2003 B conf
MFCS
Oscar H. Ibarra, Zhe Dang, Ömer Egecioglu, Gaurav Saxena
2003 J jnl
Theor. Comput. Sci.
Mark Daley, Oscar H. Ibarra, Lila Kari
2003 A* conf
CAV
Gaoyan Xie, Zhe Dang, Oscar H. Ibarra, Pierluigi San Pietro
2003 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Zhe Dang
2003 J jnl
Theor. Comput. Sci.
Zhe Dang, Oscar H. Ibarra, Richard A. Kemmerer
2003 C ed.
CIAA
Oscar H. Ibarra, Zhe Dang
2003 J jnl
J. Autom. Lang. Comb.
Mark Daley, Oscar H. Ibarra, Lila Kari, Ian McQuillan, Koji Nakano
2003 conf
Workshop on Membrane Computing
Oscar H. Ibarra
2003 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Zhe Dang, Pierluigi San Pietro
2002 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Jianwen Su
2002 Misc ed.
COCOON
Oscar H. Ibarra, Louxin Zhang
2002 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Jianwen Su, Zhe Dang, Tevfik Bultan, Richard A. Kemmerer
2002 A* conf
PODS
Hoda M. O. Mokhtar, Jianwen Su, Oscar H. Ibarra
2002 B conf
ISAAC
Zhe Dang, Oscar H. Ibarra, Zhi-Wei Sun
2002 C conf
Developments in Language Theory
Oscar H. Ibarra, Zhe Dang, Zhi-Wei Sun
2002 J jnl
J. Comput. Syst. Sci.
Tero Harju, Oscar H. Ibarra, Juhani Karhumäki, Arto Salomaa
2002 J jnl
Int. J. Found. Comput. Sci.
Zhe Dang, Oscar H. Ibarra
2002 A conf
CIKM
Hongjun Zhu, Jianwen Su, Oscar H. Ibarra
2002 J jnl
Int. J. Found. Comput. Sci.
Oscar H. Ibarra
2002 A conf
IPDPS
Oscar H. Ibarra, Stephan Olariu, Koji Nakano, Jie Wu
2001 conf
Where Mathematics, Computer Science, Linguistics and Biology Meet
Oscar H. Ibarra, Jianwen Su, Constantinos Bartzis
2001 Misc conf
COCOON
Zhe Dang, Oscar H. Ibarra, Richard A. Kemmerer
2001 A* conf
ICALP
Tero Harju, Oscar H. Ibarra, Juhani Karhumäki, Arto Salomaa
2001 conf
FSTTCS
Zhe Dang, Oscar H. Ibarra, Pierluigi San Pietro
2001 B conf
SSTD
Jianwen Su, Haiyan Xu, Oscar H. Ibarra
2001 B conf
SSTD
Hongjun Zhu, Jianwen Su, Oscar H. Ibarra
2001 J jnl
Int. J. Found. Comput. Sci.
Oscar H. Ibarra, Tevfik Bultan, Jianwen Su
2001 B conf
ISAAC
Oscar H. Ibarra, Zhe Dang
2001 C conf
CIAA
Zhe Dang, Tevfik Bultan, Oscar H. Ibarra, Richard A. Kemmerer
2000 J jnl
Int. J. Digit. Libr.
Huican Zhu, Tao Yang, Qi Zheng, David Watson, Oscar H. Ibarra, Terence R. Smith
2000 A* conf
CAV
Zhe Dang, Oscar H. Ibarra, Tevfik Bultan, Richard A. Kemmerer, Jianwen Su
2000 B conf
MFCS
Oscar H. Ibarra, Jianwen Su, Zhe Dang, Tevfik Bultan, Richard A. Kemmerer
2000 conf
Web-Age Information Management
Hongjun Zhu, Jianwen Su, Oscar H. Ibarra
2000 C conf
CIAA
Oscar H. Ibarra, Jianwen Su
2000 J jnl
Theor. Comput. Sci.
Athanassios S. Poulakidas, Ashok Srinivasan, Ömer Egecioglu, Oscar H. Ibarra, Tao Yang
2000 B conf
CONCUR
Oscar H. Ibarra, Tevfik Bultan, Jianwen Su
2000 C conf
CIAA
Oscar H. Ibarra
2000 B conf
SSDBM
Hongjun Zhu, Jianwen Su, Oscar H. Ibarra
2000 conf
IPDPS Workshops
Oscar H. Ibarra, Koji Nakano, Stephan Olariu
1999 J jnl
J. Comput. Syst. Sci.
Oscar H. Ibarra, Jianwen Su
1999 A* conf
ICDE
Hongjun Zhu, Jianwen Su, Oscar H. Ibarra
1999 conf
Jewels are Forever
Oscar H. Ibarra, Jianwen Su
1998 A conf
HPDC
Huican Zhu, Tao Yang, Qi Zheng, David Watson, Oscar H. Ibarra, Terence R. Smith
1998 J jnl
J. Parallel Distributed Comput.
Daniel Andresen, Tao Yang, Oscar H. Ibarra, Ömer Egecioglu
1998 B ed.
ISAAC
Kyung-Yong Chwa, Oscar H. Ibarra
1997 Misc conf
COCOON
Athanassios S. Poulakidas, Ashok Srinivasan, Ömer Egecioglu, Oscar H. Ibarra, Tao Yang
1997 J jnl
Int. J. Found. Comput. Sci.
Oscar H. Ibarra, Pedro C. Diniz, Martin C. Rinard
1997 A* conf
PODS
Oscar H. Ibarra, Jianwen Su
1997 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Nicholas Q. Trân, Tao Yang
1997 J jnl
J. Parallel Distributed Comput.
Yizhou Yu, Oscar H. Ibarra, Tao Yang
1997 J jnl
J. Parallel Distributed Comput.
Daniel Andresen, Tao Yang, Oscar H. Ibarra
1996 B conf
Data Compression Conference
Athanassios S. Poulakidas, Ashok Srinivasan, Ömer Egecioglu, Oscar H. Ibarra, Tao Yang
1996 Misc conf
COCOON
Oscar H. Ibarra, Pedro C. Diniz, Martin C. Rinard
1996 conf
IRREGULAR
Yizhou Yu, Oscar H. Ibarra, Tao Yang
1996 J jnl
J. Parallel Distributed Comput.
Tao Yang, Oscar H. Ibarra
1996 conf
IPPS
Daniel Andresen, Tao Yang, Vegard Holmedahl, Oscar H. Ibarra
1996 conf
ADL
Daniel Andresen, Tao Yang, Ömer Egecioglu, Oscar H. Ibarra, Terence R. Smith
1995 J jnl
Pattern Recognit. Lett.
Oscar H. Ibarra, Ting-Chuen Pong, Stephen M. Sohn
1995 J jnl
J. Parallel Distributed Comput.
Oscar H. Ibarra, Qi Zheng
1995 J jnl
SIAM J. Comput.
Oscar H. Ibarra, Tao Jiang, Nicholas Q. Trân, Hui Wang
1995 conf
SPDP
Tao Yang, Oscar H. Ibarra
1994 conf
Great Lakes Symposium on VLSI
Douglas Chang, Teofilo F. Gonzalez, Oscar H. Ibarra
1994 J jnl
J. Parallel Distributed Comput.
Oscar H. Ibarra, Myung Hee Kim
1994 J jnl
Acta Informatica
Oscar H. Ibarra, Nicholas Q. Trân
1994 conf
Results and Trends in Theoretical Computer Science
Oscar H. Ibarra, Tao Jiang
1994 B conf
ISAAC
Oscar H. Ibarra, Nicholas Q. Trân
1994 J jnl
J. Algorithms
Oscar H. Ibarra, Qi Zheng
1994 J jnl
Theor. Comput. Sci.
Tao Jiang, Oscar H. Ibarra, Hui Wang
1994 conf
IPPS
Myung Hee Kim, Oscar H. Ibarra
1993 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Nicholas Q. Trân
1993 conf
ICPP (3)
Oscar H. Ibarra, Qi Zheng
1993 A* conf
ICALP
Oscar H. Ibarra, Tao Jiang, Nicholas Q. Trân, Hui Wang
1993 J jnl
J. Algorithms
Oscar H. Ibarra, Hui Wang, Tao Jiang
1993 B conf
MFCS
Oscar H. Ibarra, Nicholas Q. Trân
1993 J jnl
Int. J. Found. Comput. Sci.
Oscar H. Ibarra, Tao Jiang, Nicholas Q. Trân, Hui Wang
1993 A conf
STACS
Oscar H. Ibarra, Tao Jiang, Nicholas Q. Trân, Hui Wang
1993 conf
IPPS
Oscar H. Ibarra, Qi Zheng
1993 J jnl
J. Parallel Distributed Comput.
Oscar H. Ibarra, Myung Hee Kim
1993 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Nicholas Q. Trân
1992 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Tao Jiang, Hui Wang
1992 J jnl
Inf. Sci.
Tao Jiang, Oscar H. Ibarra, Hui Wang, Qi Zheng
1992 J jnl
Parallel Comput.
J. Andrew Holey, Oscar H. Ibarra
1992 A* conf
ICALP
Oscar H. Ibarra, Nicholas Q. Trân
1992 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Nicholas Q. Trân
1992 conf
IPPS
Oscar H. Ibarra, Myung Hee Kim
1992 J jnl
IEEE Trans. Computers
Oscar H. Ibarra, Tao Jiang, Hui Wang
1991 conf
IPPS
Oscar H. Ibarra, Myung Hee Kim
1991 J jnl
J. Comput. Syst. Sci.
Oscar H. Ibarra, Tao Jiang
1991 J jnl
Bull. EATCS
Oscar H. Ibarra
1991 B conf
FCT
Oscar H. Ibarra, Nicholas Q. Trân
1991 J jnl
SIGACT News
Oscar H. Ibarra
1991 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Hui Wang
1991 J jnl
IEEE Trans. Computers
Oscar H. Ibarra, Ting-Chuen Pong, Stephen M. Sohn
1991 J jnl
Inf. Comput.
Oscar H. Ibarra, Tao Jiang, Jik H. Chang, Bala Ravikumar
1991 B conf
MFCS
Oscar H. Ibarra, Tao Jiang, Hui Wang
1991 J jnl
SIAM J. Comput.
Oscar H. Ibarra, Tao Jiang
1991 conf
ICPP (3)
J. Andrew Holey, Oscar H. Ibarra
1991 conf
IPPS
J. Andrew Holey, Oscar H. Ibarra
1990 J jnl
Int. J. Parallel Program.
Oscar H. Ibarra, Michael A. Palis
1990 conf
SPDP
Oscar H. Ibarra, Hui Wang, Tao Jiang
1990 conf
ICPP (3)
J. Andrew Holey, Oscar H. Ibarra
1990 J jnl
IEEE Trans. Parallel Distributed Syst.
Oscar H. Ibarra, Stephen M. Sohn
1990 conf
ICPP (3)
Oscar H. Ibarra, Tao Jiang, Hui Wang
1990 J jnl
IEEE Trans. Acoust. Speech Signal Process.
Oscar H. Ibarra, Ting-Chuen Pong, Stephen M. Sohn
1990 J jnl
J. VLSI Signal Process.
Oscar H. Ibarra, Tao Jiang, Jik H. Chang, Michael A. Palis
1989 B conf
WADS
Oscar H. Ibarra, Michael A. Palis
1989 J jnl
Theor. Comput. Sci.
Jik H. Chang, Oscar H. Ibarra, Michael A. Palis
1989 J jnl
J. Comput. Syst. Sci.
Oscar H. Ibarra, Tao Jiang, Jik H. Chang
1989 conf
ICPP (1)
Oscar H. Ibarra, Stephen M. Sohn
1989 J jnl
Inf. Process. Lett.
Oscar H. Ibarra, Tao Jiang
1989 conf
FSTTCS
Oscar H. Ibarra, Tao Jiang, Hui Wang
1989 J jnl
SIAM J. Comput.
Bala Ravikumar, Oscar H. Ibarra
1988 A* conf
ICALP
Jik H. Chang, Oscar H. Ibarra, Michael A. Palis
1988 A* conf
COLT
Oscar H. Ibarra, Tao Jiang
1988 conf
AWOC
Oscar H. Ibarra, Tao Jiang, Bala Ravikumar, Jik H. Chang
1988 J jnl
IEEE Trans. Computers
David Hung-Chang Du, Oscar H. Ibarra, J. Fernando Naveda
1988 J jnl
J. ACM
Jik H. Chang, Oscar H. Ibarra, Anastasios Vergis
1988 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Tao Jiang
1988 J jnl
Inf. Process. Lett.
Oscar H. Ibarra, Tao Jiang, Bala Ravikumar
1988 J jnl
Math. Syst. Theory
Oscar H. Ibarra, Bala Ravikumar
1988 J jnl
IEEE Trans. Computers
Jik H. Chang, Oscar H. Ibarra, Moon-Jung Chung, Kotesh K. Rao
1988 conf
SCT
Oscar H. Ibarra, Tao Jiang
1988 J jnl
IEEE Trans. Pattern Anal. Mach. Intell.
Jik H. Chang, Oscar H. Ibarra, Ting-Chuen Pong, Stephen M. Sohn
1988 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Michael A. Palis
1987 J jnl
SIAM J. Comput.
Oscar H. Ibarra, Michael A. Palis
1987 J jnl
SIAM J. Comput.
Oscar H. Ibarra, Tao Jiang
1987 A* conf
ICALP
Oscar H. Ibarra, Tao Jiang
1987 J jnl
IEEE Trans. Computers
Jik H. Chang, Oscar H. Ibarra, Michael A. Palis
1987 conf
FSTTCS
Oscar H. Ibarra, Bala Ravikumar
1987 J jnl
IEEE Trans. Comput. Aided Des. Integr. Circuits Syst.
David Hung-Chang Du, Oscar H. Ibarra, J. Fernando Naveda
1987 J jnl
Inf. Process. Lett.
Jik H. Chang, Oscar H. Ibarra, Bala Ravikumar, Leonard Berman
1987 B conf
ICPP
Jik H. Chang, Oscar H. Ibarra, Ting-Chuen Pong, Stephen M. Sohn
1987 J jnl
IEEE Trans. Acoust. Speech Signal Process.
Oscar H. Ibarra, Michael A. Palis
1986 J jnl
IEEE Trans. Computers
Oscar H. Ibarra, Sam M. Kim, Michael A. Palis
1986 J jnl
Theor. Comput. Sci.
Jik H. Chang, Oscar H. Ibarra, Michael A. Palis, Bala Ravikumar
1986 A conf
STACS
Oscar H. Ibarra, Bala Ravikumar
1986 A* conf
FOCS
Jik H. Chang, Oscar H. Ibarra, Anastasios Vergis
1986 B conf
ICPP
Jik H. Chang, Oscar H. Ibarra, Michael A. Palis
1986 B conf
MFCS
Oscar H. Ibarra
1986 B conf
ICPP
Jik H. Chang, Moon-Jung Chung, Oscar H. Ibarra, Kotesh K. Rao
1985 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Michael A. Palis, Sam M. Kim
1985 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Michael A. Palis, Jik H. Chang
1985 J jnl
Inf. Control.
Oscar H. Ibarra, Louis E. Rosier
1985 J jnl
Inf. Control.
Oscar H. Ibarra, Sam M. Kim, Louis E. Rosier
1985 J jnl
SIAM J. Comput.
Oscar H. Ibarra, Sam M. Kim, Shlomo Moran
1985 J jnl
Inf. Control.
Oscar H. Ibarra, Sam M. Kim, Louis E. Rosier
1985 J jnl
J. Parallel Distributed Comput.
Oscar H. Ibarra, Michael A. Palis, Sam M. Kim
1985 J jnl
Inf. Control.
Oscar H. Ibarra, Louis E. Rosier
1984 J jnl
Acta Informatica
Oscar H. Ibarra, Sam M. Kim
1984 J jnl
Math. Syst. Theory
Oscar H. Ibarra, Brian S. Leininger, Louis E. Rosier
1984 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Sam M. Kim
1984 A* conf
FOCS
Oscar H. Ibarra, Michael A. Palis, Sam M. Kim
1984 A* conf
ICALP
Oscar H. Ibarra, Sam M. Kim, Louis E. Rosier
1984 B conf
MFCS
Oscar H. Ibarra, Louis E. Rosier
1983 J jnl
Math. Syst. Theory
Eitan M. Gurari, Oscar H. Ibarra
1983 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra
1983 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Shlomo Moran, Louis E. Rosier
1983 J jnl
Theor. Comput. Sci.
Tat-hung Chan, Oscar H. Ibarra
1983 J jnl
J. ACM
Oscar H. Ibarra, Brian S. Leininger
1983 J jnl
SIAM J. Comput.
Tat-hung Chan, Oscar H. Ibarra
1983 J jnl
J. Comput. Syst. Sci.
Oscar H. Ibarra, Brian S. Leininger
1983 J jnl
J. ACM
Oscar H. Ibarra, Shlomo Moran
1983 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Louis E. Rosier
1983 J jnl
SIAM J. Comput.
Oscar H. Ibarra, Shlomo Moran
1982 J jnl
Math. Syst. Theory
Eitan M. Gurari, Oscar H. Ibarra
1982 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra
1982 J jnl
J. Algorithms
Oscar H. Ibarra, Shlomo Moran, Roger Hui
1982 J jnl
J. Comput. Syst. Sci.
Oscar H. Ibarra, Shlomo Moran
1982 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Brian S. Leininger, Shlomo Moran
1982 J jnl
Theor. Comput. Sci.
Eitan M. Gurari, Oscar H. Ibarra
1982 J jnl
SIAM J. Comput.
Oscar H. Ibarra, Brian S. Leininger
1982 J jnl
SIAM J. Comput.
Oscar H. Ibarra, Brian S. Leininger
1982 J jnl
J. ACM
Eitan M. Gurari, Oscar H. Ibarra
1981 J jnl
SIAM J. Comput.
Oscar H. Ibarra, Brian S. Leininger
1981 J jnl
Inf. Process. Lett.
Oscar H. Ibarra, Shlomo Moran
1981 J jnl
Math. Syst. Theory
Oscar H. Ibarra, Louis E. Rosier
1981 A* conf
ICALP
Oscar H. Ibarra, Brian S. Leininger, Shlomo Moran
1981 J jnl
Inf. Process. Lett.
Oscar H. Ibarra, Louis E. Rosier
1981 J jnl
Inf. Process. Lett.
Oscar H. Ibarra, Shlomo Moran, Louis E. Rosier
1981 A* conf
ICALP
Eitan M. Gurari, Oscar H. Ibarra
1981 J jnl
J. Comput. Syst. Sci.
Eitan M. Gurari, Oscar H. Ibarra
1981 J jnl
J. ACM
Eitan M. Gurari, Oscar H. Ibarra
1981 J jnl
Theor. Comput. Sci.
Eitan M. Gurari, Oscar H. Ibarra
1981 A* conf
FOCS
Eitan M. Gurari, Oscar H. Ibarra
1980 J jnl
Inf. Process. Lett.
Oscar H. Ibarra, Shlomo Moran, Louis E. Rosier
1980 J jnl
SIAM J. Comput.
Eitan M. Gurari, Oscar H. Ibarra
1980 A* conf
STOC
Oscar H. Ibarra, Brian S. Leininger
1979 J jnl
J. ACM
Eitan M. Gurari, Oscar H. Ibarra
1979 J jnl
Inf. Process. Lett.
Eitan M. Gurari, Oscar H. Ibarra
1979 J jnl
Math. Syst. Theory
Oscar H. Ibarra
1979 J jnl
J. Comput. Syst. Sci.
Eitan M. Gurari, Oscar H. Ibarra
1979 J jnl
J. Comput. Syst. Sci.
Eitan M. Gurari, Oscar H. Ibarra
1979 A* conf
STOC
Eitan M. Gurari, Oscar H. Ibarra
1978 A* conf
STOC
Eitan M. Gurari, Oscar H. Ibarra
1978 J jnl
Math. Oper. Res.
Oscar H. Ibarra, Chul E. Kim
1978 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra
1978 J jnl
J. ACM
Oscar H. Ibarra
1978 J jnl
SIAM J. Comput.
Oscar H. Ibarra
1977 J jnl
SIAM J. Comput.
Teofilo F. Gonzalez, Oscar H. Ibarra, Sartaj Sahni
1977 J jnl
J. ACM
Oscar H. Ibarra, Chul E. Kim
1977 A* conf
FOCS
Oscar H. Ibarra
1976 A* conf
STOC
Oscar H. Ibarra, Chul E. Kim
1976 J jnl
J. Comput. Syst. Sci.
Oscar H. Ibarra, Chul E. Kim
1976 J jnl
Theor. Comput. Sci.
Oscar H. Ibarra, Sartaj Sahni, Chul E. Kim
1975 J jnl
J. ACM
Oscar H. Ibarra, Chul E. Kim
1975 J jnl
J. Comput. Syst. Sci.
Oscar H. Ibarra, Sartaj Sahni
1975 J jnl
IEEE Trans. Computers
Oscar H. Ibarra, Sartaj Sahni
1974 J jnl
SIAM J. Comput.
Oscar H. Ibarra
1974 J jnl
Inf. Process. Lett.
Oscar H. Ibarra
1974 J jnl
Acta Informatica
Oscar H. Ibarra, Chul E. Kim
1973 J jnl
Inf. Sci.
Oscar H. Ibarra
1973 J jnl
J. Comput. Syst. Sci.
Oscar H. Ibarra
1972 J jnl
J. ACM
Oscar H. Ibarra
1971 J jnl
J. Comput. Syst. Sci.
Oscar H. Ibarra
1971 J jnl
Math. Syst. Theory
Oscar H. Ibarra
1970 J jnl
Inf. Control.
Oscar H. Ibarra
1970 J jnl
J. Comput. Syst. Sci.
Ronald V. Book, Sheila A. Greibach, Oscar H. Ibarra, Ben Wegbreit
1968 J jnl
Inf. Control.
Michael A. Harrison, Oscar H. Ibarra
1967 J jnl
IEEE Trans. Electron. Comput.
Oscar H. Ibarra
1967 J jnl
Inf. Control.
Jim Gray, Michael A. Harrison, Oscar H. Ibarra
redb/extractors/yara.py
← Index redb/extractors/yara.py python
"""
YARA Extractor - Scans binary files with YARA rules and stores matches in ClickHouse.

This extractor uses the yara-x library to scan samples against a collection of
YARA rules located in the 'yara/' folder at the project root.

Supports both:
- Pre-compiled rules (.yarac) for faster loading
- Source rules (.yar/.yara) compiled on-the-fly

Schema Design:
- yara_rules: Rule metadata stored once per unique rule (deduplicated by rule_id)
- yara_matches: Sample-rule matches with binary sha256 for efficiency
"""
import inspect
import json
import os
import re
import threading
import time
from datetime import datetime, timezone
from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple

import xxhash
import yara_x

from redb.extractors.enum import Tag
from redb.extractors.extractor import Extractor
from redb.models.dataclasses import YaraMatch, YaraRule


# Default compiled rules filename (can be overridden via YARA_COMPILED_RULES env var)
COMPILED_RULES_FILENAME = os.getenv("YARA_COMPILED_RULES", "compiled_rules.yarac")

# Default source collection name
DEFAULT_SOURCE_COLLECTION = os.getenv("YARA_SOURCE_COLLECTION", "default")


def canonicalize_rule(rule_text: str) -> str:
    """
    Canonicalize YARA rule text for consistent hashing.

    Strips comments and normalizes whitespace, but excludes metadata
    so rules with same logic but different metadata get the same ID.
    """
    # Strip single-line comments
    text = re.sub(r'//.*$', '', rule_text, flags=re.MULTILINE)
    # Strip multi-line comments
    text = re.sub(r'/\*.*?\*/', '', text, flags=re.DOTALL)
    # Strip meta section (keep only strings/condition)
    text = re.sub(r'meta\s*:\s*[^}]+(?=strings|condition|})', '', text, flags=re.DOTALL)
    # Normalize whitespace
    text = ' '.join(text.split())
    return text


def generate_rule_id(rule_text: str) -> int:
    """
    Generate a unique rule_id from canonicalized rule content.

    Returns:
        UInt64 hash of the canonical rule content
    """
    canonical = canonicalize_rule(rule_text)
    return xxhash.xxh64(canonical.encode('utf-8')).intdigest()


def sha256_hex_to_binary(hex_str: str) -> bytes:
    """Convert SHA256 hex string to binary (32 bytes)."""
    return bytes.fromhex(hex_str)


def sha256_binary_to_hex(binary: bytes) -> str:
    """Convert SHA256 binary (32 bytes) to hex string."""
    return binary.hex()


def parse_yara_rules(file_content: str) -> List[Dict[str, Any]]:
    """
    Parse individual YARA rules from file content.

    Handles files with multiple rules and extracts:
    - rule_name: The rule identifier
    - rule_tags: List of tags (from 'rule Name : tag1 tag2 {')
    - rule_meta: Dict of metadata key-value pairs
    - rule_text: Full rule source code

    Args:
        file_content: Raw content of a .yar/.yara file

    Returns:
        List of dicts, each containing rule_name, rule_tags, rule_meta, rule_text
    """
    rules = []

    # Pattern to match rule declarations: rule Name or rule Name : tags
    # We need to find rule boundaries by tracking braces
    rule_pattern = re.compile(
        r'(?:^|\n)\s*((?:private\s+|global\s+)*rule\s+(\w+)\s*(?::\s*([^{]*))?\s*\{)',
        re.MULTILINE
    )

    matches = list(rule_pattern.finditer(file_content))

    for i, match in enumerate(matches):
        rule_start = match.start(1)  # Start of 'rule ...'
        rule_name = match.group(2)
        tags_str = match.group(3) or ""
        rule_tags = [t.strip() for t in tags_str.split() if t.strip()]

        # Find the matching closing brace by counting braces
        brace_count = 0
        rule_end = match.end()
        in_string = False
        escape_next = False

        for j, char in enumerate(file_content[match.end() - 1:], start=match.end() - 1):
            if escape_next:
                escape_next = False
                continue
            if char == '\\':
                escape_next = True
                continue
            if char == '"' and not escape_next:
                in_string = not in_string
                continue
            if in_string:
                continue
            if char == '{':
                brace_count += 1
            elif char == '}':
                brace_count -= 1
                if brace_count == 0:
                    rule_end = j + 1
                    break

        rule_text = file_content[rule_start:rule_end].strip()

        # Extract metadata from rule
        meta = {}
        meta_match = re.search(
            r'meta\s*:\s*(.*?)(?=strings\s*:|condition\s*:|$)',
            rule_text,
            re.DOTALL
        )
        if meta_match:
            meta_text = meta_match.group(1)
            for line in meta_text.strip().split('\n'):
                if '=' in line:
                    key, _, value = line.partition('=')
                    key = key.strip()
                    value = value.strip().strip('"\'')
                    if key and not key.startswith('//'):
                        meta[key] = value

        rules.append({
            'rule_name': rule_name,
            'rule_tags': rule_tags,
            'rule_meta': meta,
            'rule_text': rule_text,
        })

    return rules


class YaraBatchInsertBuffer:
    """
    Thread-safe buffer for batching YARA match inserts.

    Collects matches from multiple samples and flushes to ClickHouse
    when batch_size is reached or flush_interval expires.
    """

    def __init__(
        self,
        exporter,
        index_prefix: str,
        batch_size: int = 1000,
        flush_interval: int = 30,
    ):
        self.exporter = exporter
        self.index_prefix = index_prefix
        self.batch_size = batch_size
        self.flush_interval = flush_interval

        self.matches_buffer: List[List] = []
        self.rules_buffer: Dict[int, List] = {}  # rule_id -> rule_data (deduplicated)
        self.lock = threading.Lock()
        self.last_flush = time.time()

        # Start background flush timer
        self._stop_timer = False
        self._timer_thread = threading.Thread(target=self._flush_timer, daemon=True)
        self._timer_thread.start()

    def add(self, sha256_binary: bytes, matches: List[Tuple], rules: Dict[int, List]) -> None:
        """
        Add matches and rules to buffer.

        Args:
            sha256_binary: Binary SHA256 (32 bytes)
            matches: List of match tuples (sha256_binary, rule_id, rule_name, scan_date, match_strings)
            rules: Dict of rule_id -> rule_data tuples
        """
        with self.lock:
            self.matches_buffer.extend(matches)
            # Merge rules (deduplicated by rule_id)
            for rule_id, rule_data in rules.items():
                if rule_id not in self.rules_buffer:
                    self.rules_buffer[rule_id] = rule_data

            if len(self.matches_buffer) >= self.batch_size:
                self._flush_locked()

    def _flush_locked(self) -> None:
        """Flush buffer (must hold lock)."""
        if not self.matches_buffer:
            return

        try:
            # Insert rules first (deduplicated)
            if self.rules_buffer:
                rules_data = list(self.rules_buffer.values())
                self.exporter.batch_insert(
                    table='yara_rules',
                    rows=rules_data,
                    column_names=[
                        'rule_id', 'rule_name', 'source_collection',
                        'ingested_at', 'rule_text', 'rule_meta', 'rule_tags'
                    ],
                    column_type_names=[
                        'UInt64', 'String', 'LowCardinality(String)',
                        "DateTime64(3, 'UTC')", 'String', 'JSON', 'Array(LowCardinality(String))'
                    ]
                )

            # Insert matches
            self.exporter.batch_insert(
                table='yara_matches',
                rows=self.matches_buffer,
                column_names=[
                    'sha256', 'rule_id', 'rule_name',
                    'scan_date', 'match_strings'
                ],
                column_type_names=[
                    'FixedString(32)', 'UInt64', 'LowCardinality(String)',
                    "DateTime64(3, 'UTC')", 'Array(String)'
                ]
            )

            print(f"[YARA] Flushed {len(self.matches_buffer)} matches and {len(self.rules_buffer)} rules")

        except Exception as e:
            print(f"[YARA] Error flushing batch: {e}")

        # Clear buffers
        self.matches_buffer = []
        self.rules_buffer = {}
        self.last_flush = time.time()

    def flush(self) -> None:
        """Public flush (acquires lock)."""
        with self.lock:
            self._flush_locked()

    def _flush_timer(self) -> None:
        """Background timer for periodic flushes."""
        while not self._stop_timer:
            time.sleep(5)  # Check every 5 seconds
            with self.lock:
                if time.time() - self.last_flush > self.flush_interval and self.matches_buffer:
                    self._flush_locked()

    def stop(self) -> None:
        """Stop the background timer and flush remaining data."""
        self._stop_timer = True
        self.flush()


class YaraExtractor(Extractor):
    """
    Extractor that scans binary files with YARA rules.

    The YARA rules are loaded from the 'yara/' folder at the project root.
    Each matching rule is stored in ClickHouse with its metadata.

    Supports pre-compiled rules for faster loading:
    - If 'yara/compiled_rules.yarac' exists, it will be loaded directly
    - Otherwise, all .yar/.yara files are compiled and cached in memory
    - Use YaraExtractor.compile_and_save() to pre-compile rules
    """

    # Class-level cache for compiled YARA rules
    _compiled_rules = None
    _rules_path = None

    def __init__(
        self,
        filepath: str,
        log: Any,
        exporters: Optional[List] = None,
        index_prefix: Optional[str] = None,
        known_benign: bool = False,
        known_malicious: bool = False,
    ):
        super().__init__(
            filepath,
            log,
            exporters,
            index_prefix,
            known_benign,
            known_malicious,
        )
        self.matches: List[YaraMatch] = []
        self.rules: Dict[str, YaraRule] = {}  # rule_name -> YaraRule (deduplicated)

    @classmethod
    def get_yara_rules_path(cls) -> Path:
        """Get the path to the YARA rules directory."""
        # Default to 'yara/' in project root
        project_root = Path(__file__).parent.parent.parent
        default_path = project_root / "yara"

        # Allow override via environment variable
        rules_path = os.getenv("YARA_RULES_PATH", str(default_path))
        return Path(rules_path)

    @classmethod
    def get_compiled_rules_path(cls) -> Path:
        """Get the path to the pre-compiled rules file."""
        return cls.get_yara_rules_path() / COMPILED_RULES_FILENAME

    @classmethod
    def load_compiled_rules(cls) -> Optional[yara_x.Rules]:
        """
        Load pre-compiled YARA rules from .yarac file.

        Returns:
            Compiled Rules object or None if file doesn't exist
        """
        compiled_path = cls.get_compiled_rules_path()
        if not compiled_path.exists():
            return None

        try:
            with open(compiled_path, "rb") as f:
                rules = yara_x.Rules.deserialize_from(f)
            # Only log in debug mode (non-prod) to avoid spamming in bulk processing
            if os.getenv("SERVER_ENV") != "prod":
                print(f"[DEBUG] Loaded pre-compiled YARA rules from {compiled_path}")
            return rules
        except Exception as e:
            print(f"[WARNING] Failed to load compiled rules from {compiled_path}: {e}")
            return None

    @classmethod
    def compile_rules_from_source(cls) -> Optional[yara_x.Rules]:
        """
        Compile all YARA rules from source .yar/.yara files.

        Returns:
            Compiled Rules object or None if no rules found
        """
        rules_path = cls.get_yara_rules_path()

        if not rules_path.exists():
            return None

        # Find all .yar and .yara files recursively
        rule_files = []
        for ext in ["*.yar", "*.yara"]:
            rule_files.extend(rules_path.rglob(ext))

        if not rule_files:
            return None

        print(f"[INFO] Compiling {len(rule_files)} YARA rule files from {rules_path}")

        # Compile all rules using yara-x compiler
        compiler = yara_x.Compiler()
        compiled_count = 0
        failed_count = 0

        for rule_file in rule_files:
            try:
                with open(rule_file, "r", encoding="utf-8") as f:
                    rule_content = f.read()
                # Use the relative path from rules_path as namespace
                namespace = str(rule_file.relative_to(rules_path).parent)
                if namespace == ".":
                    namespace = "default"
                compiler.new_namespace(namespace)
                compiler.add_source(rule_content)
                compiled_count += 1
            except Exception as e:
                # Log warning but continue with other rules
                print(f"[WARNING] Failed to compile YARA rule {rule_file}: {e}")
                failed_count += 1
                continue

        try:
            rules = compiler.build()
            print(f"[INFO] Successfully compiled {compiled_count} rule files ({failed_count} failed)")
            return rules
        except Exception as e:
            print(f"[ERROR] Failed to build YARA rules: {e}")
            return None

    @classmethod
    def compile_rules(cls, force_reload: bool = False) -> Optional[yara_x.Rules]:
        """
        Get compiled YARA rules, loading from cache, .yarac file, or compiling from source.

        Priority:
        1. Return cached rules if available
        2. Load pre-compiled .yarac file if it exists
        3. Compile from source .yar/.yara files

        Args:
            force_reload: If True, ignore cache and reload rules

        Returns:
            Compiled YARA rules or None if no rules found
        """
        rules_path = cls.get_yara_rules_path()

        # Return cached rules if available and path hasn't changed
        if (
            cls._compiled_rules is not None
            and cls._rules_path == rules_path
            and not force_reload
        ):
            return cls._compiled_rules

        # Try loading pre-compiled rules first
        rules = cls.load_compiled_rules()

        # If no pre-compiled rules, compile from source
        if rules is None:
            rules = cls.compile_rules_from_source()

        # Cache the rules
        if rules is not None:
            cls._compiled_rules = rules
            cls._rules_path = rules_path

        return rules

    @classmethod
    def compile_and_save(cls, output_path: Optional[Path] = None) -> bool:
        """
        Compile all YARA rules from source and save to a .yarac file.

        This is useful for pre-compiling rules for faster loading in production.

        Args:
            output_path: Path to save compiled rules (default: yara/compiled_rules.yarac)

        Returns:
            True if successful, False otherwise
        """
        if output_path is None:
            output_path = cls.get_compiled_rules_path()

        # Force compile from source
        rules = cls.compile_rules_from_source()
        if rules is None:
            print("[ERROR] No rules to compile")
            return False

        try:
            # Ensure parent directory exists
            output_path.parent.mkdir(parents=True, exist_ok=True)

            with open(output_path, "wb") as f:
                rules.serialize_into(f)

            print(f"[INFO] Saved compiled YARA rules to {output_path}")
            return True
        except Exception as e:
            print(f"[ERROR] Failed to save compiled rules: {e}")
            return False

    def _extract_yara_matches(self) -> Tuple[List[YaraMatch], Dict[str, YaraRule]]:
        """
        Scan the binary with compiled YARA rules.

        Returns:
            Tuple of (matches list, rules dict) for each matching rule
        """
        self.log.debug(inspect.currentframe().f_code.co_name)

        compiled_rules = self.compile_rules()
        if compiled_rules is None:
            self.log.warning("No YARA rules found or compiled")
            return [], {}

        matches = []
        rules = {}

        try:
            # Scan the binary data
            scan_results = compiled_rules.scan(self.binary)

            # Process each matching rule
            for rule in scan_results.matching_rules:
                rule_name = rule.identifier

                # Extract rule metadata and store rule (deduplicated by name)
                if rule_name not in rules:
                    meta = {}
                    for identifier, value in rule.metadata:
                        meta[identifier] = str(value)
                    rules[rule_name] = YaraRule(
                        rule_name=rule_name,
                        rule_tags=list(rule.tags),
                        rule_meta=meta,
                    )

                # Extract matched string identifiers
                matched_strings = []
                for pattern in rule.patterns:
                    for match in pattern.matches:
                        matched_strings.append(pattern.identifier)

                # Remove duplicates from matched strings
                matched_strings = list(set(matched_strings))

                yara_match = YaraMatch(
                    rule_name=rule_name,
                    match_strings=matched_strings,
                )
                matches.append(yara_match)

                self.log.debug(
                    f"YARA match: {rule_name} (tags: {list(rule.tags)})"
                )

        except Exception as e:
            self.log.error(f"Error scanning with YARA: {e}")
            return [], {}

        return matches, rules

    def extract(self) -> Optional[List[YaraMatch]]:
        """
        Extract YARA matches from the binary.

        Returns:
            List of YaraMatch objects or None on error
        """
        self.log.debug(inspect.currentframe().f_code.co_name)
        try:
            self.matches, self.rules = self._extract_yara_matches()
            return self.matches if self.matches else None
        except Exception as e:
            self.log.error(f"Error extracting YARA matches: {e}")
            return None

    def tag(self) -> str:
        """Return the tag for this extractor."""
        return Tag.YARA.value

    def get_clickhouse_table(self) -> str:
        """Return the ClickHouse table name for YARA matches."""
        return "yara_matches"

    def get_clickhouse_tables(self) -> Dict[str, str]:
        """Return all ClickHouse table names for multi-table support."""
        return {
            'rules': 'yara_rules',
            'matches': 'yara_matches',
        }

    def prepare_export_data(self, exporter_type: str) -> Any:
        """
        Prepare data for export to the specified exporter type.

        Uses optimized normalized schema with two tables:
        - yara_rules: Rule metadata with rule_id (UInt64 hash)
        - yara_matches: Matches with binary sha256 (32 bytes) and rule_id

        Args:
            exporter_type: The type of exporter (e.g., 'ClickHouseExporter')

        Returns:
            Data formatted for the specified exporter
        """

        if exporter_type == "ClickHouseExporter":
            if not self.matches:
                return None

            current_time = datetime.now(timezone.utc)
            source_collection = DEFAULT_SOURCE_COLLECTION

            # Convert sha256 hex to binary (32 bytes)
            sha256_binary = sha256_hex_to_binary(self.sha256)

            # Build rules data from self.rules (deduplicated by rule_id)
            rules_data = {}  # rule_id -> rule_data
            for rule_name, rule in self.rules.items():
                rule_content = f"rule {rule_name} {{ }}"  # Simplified for now
                rule_id = generate_rule_id(rule_content)
                if rule_id not in rules_data:
                    rules_data[rule_id] = [
                        rule_id,
                        rule.rule_name,
                        source_collection,
                        current_time,  # ingested_at
                        "",  # rule_text (empty for now, populated during sync)
                        json.dumps(rule.rule_meta),
                        rule.rule_tags,
                    ]

            # Build matches data
            matches_data = []
            for match in self.matches:
                rule_content = f"rule {match.rule_name} {{ }}"
                rule_id = generate_rule_id(rule_content)

                matches_data.append([
                    sha256_binary,  # Binary sha256 (32 bytes)
                    rule_id,
                    match.rule_name,
                    current_time,  # scan_date
                    match.match_strings,
                ])

            return {
                'multi_table': True,
                'rules': {
                    'table': 'yara_rules',
                    'data': list(rules_data.values()),
                    'column_names': [
                        'rule_id',
                        'rule_name',
                        'source_collection',
                        'ingested_at',
                        'rule_text',
                        'rule_meta',
                        'rule_tags',
                    ],
                    'column_type_names': [
                        'UInt64',
                        'String',
                        'LowCardinality(String)',
                        "DateTime64(3, 'UTC')",
                        'String',
                        'JSON',
                        'Array(LowCardinality(String))',
                    ],
                },
                'matches': {
                    'table': 'yara_matches',
                    'data': matches_data,
                    'column_names': [
                        'sha256',
                        'rule_id',
                        'rule_name',
                        'scan_date',
                        'match_strings',
                    ],
                    'column_type_names': [
                        'FixedString(32)',  # Binary sha256
                        'UInt64',
                        'LowCardinality(String)',
                        "DateTime64(3, 'UTC')",
                        'Array(String)',
                    ],
                },
            }

        return None


def sync_rules_to_db(source_collection: str = None) -> bool:
    """
    Sync all YARA rules from source files to the database.

    This ensures all rules exist in yara_rules table before scanning begins.
    Should be run before batch scanning or in container initialization.

    Args:
        source_collection: Source collection name (default from env)

    Returns:
        True if successful, False otherwise
    """
    from redb import settings

    source_collection = source_collection or DEFAULT_SOURCE_COLLECTION
    rules_path = YaraExtractor.get_yara_rules_path()

    if not rules_path.exists():
        print(f"[ERROR] Rules path does not exist: {rules_path}")
        return False

    # Find all rule files
    rule_files = []
    for ext in ["*.yar", "*.yara"]:
        rule_files.extend(rules_path.rglob(ext))

    if not rule_files:
        print(f"[INFO] No rule files found in {rules_path}")
        return True

    print(f"[INFO] Syncing {len(rule_files)} rule files to database...")

    current_time = datetime.now(timezone.utc)
    rules_data = []
    total_rules = 0

    for rule_file in rule_files:
        try:
            with open(rule_file, "r", encoding="utf-8") as f:
                file_content = f.read()

            # Parse individual rules from file (handles multiple rules per file)
            parsed_rules = parse_yara_rules(file_content)

            for rule in parsed_rules:
                rule_id = generate_rule_id(rule['rule_text'])

                rules_data.append([
                    rule_id,
                    rule['rule_name'],
                    source_collection,
                    current_time,
                    rule['rule_text'],
                    json.dumps(rule['rule_meta']),
                    rule['rule_tags'],
                ])
                total_rules += 1

        except Exception as e:
            print(f"[WARNING] Failed to parse rule file {rule_file}: {e}")
            continue

    print(f"[INFO] Parsed {total_rules} individual rules from {len(rule_files)} files")

    if not rules_data:
        print("[INFO] No rules to sync")
        return True

    # Insert rules to database
    try:
        client = settings.create_clickhouse_client()
        table = "yara_rules"

        client.insert(
            table,
            rules_data,
            column_names=[
                'rule_id', 'rule_name', 'source_collection',
                'ingested_at', 'rule_text', 'rule_meta', 'rule_tags'
            ],
            column_type_names=[
                'UInt64', 'String', 'LowCardinality(String)',
                "DateTime64(3, 'UTC')", 'String', 'JSON', 'Array(LowCardinality(String))'
            ]
        )

        print(f"[INFO] Successfully synced {len(rules_data)} rules to {table}")
        client.close()
        return True

    except Exception as e:
        print(f"[ERROR] Failed to sync rules to database: {e}")
        return False


# CLI utility for pre-compiling rules and syncing
if __name__ == "__main__":
    import argparse

    parser = argparse.ArgumentParser(description="YARA Rules Management Utility")
    parser.add_argument(
        "--compile",
        action="store_true",
        help="Compile all YARA rules and save to .yarac file",
    )
    parser.add_argument(
        "--sync-rules",
        action="store_true",
        help="Sync all YARA rules to the database (run before batch scanning)",
    )
    parser.add_argument(
        "--output",
        type=str,
        help="Output path for compiled rules (default: yara/compiled_rules.yarac)",
    )
    parser.add_argument(
        "--rules-path",
        type=str,
        help="Path to YARA rules directory (default: yara/)",
    )
    parser.add_argument(
        "--source-collection",
        type=str,
        help="Source collection name for rules (default: from YARA_SOURCE_COLLECTION env)",
    )

    args = parser.parse_args()

    if args.rules_path:
        os.environ["YARA_RULES_PATH"] = args.rules_path

    if args.compile:
        output_path = Path(args.output) if args.output else None
        success = YaraExtractor.compile_and_save(output_path)
        if not success:
            exit(1)

    if args.sync_rules:
        success = sync_rules_to_db(args.source_collection)
        if not success:
            exit(1)

    if not args.compile and not args.sync_rules:
        parser.print_help()