Wanda Pratt

158 papers A* 24A 8B 4Misc 60Journal 42Unranked 20
YearRankTypeTitle / Venue / Authors
2026 conf
CHI Extended Abstracts
Ray-yuan Chung, Jaime Snyder, Zixuan Xu, Daeun Yoo, Athena C. Ortega, Wanda Pratt, Aaron Wightman, Ryan Hutson, Cozumel Pruette, Ari H. Pollack
2026 J jnl
CoRR
Ray-yuan Chung, Jaime Snyder, Zixuan Xu, Daeun Yoo, Athena C. Ortega, Wanda Pratt, Aaron Wightman, Ryan Hutson, Cozumel Pruette, Ari H. Pollack
2025 J jnl
Int. J. Hum. Comput. Interact.
Erin Beneteau, Alexis Hiniker, Beck Tench, Seray B. Ibrahim, Wanda Pratt
2025 A conf
Conference on Designing Interactive Systems
Lisa G. Dirks, Miranda Belarde-Lewis, Wanda Pratt
2025 J jnl
J. Am. Medical Informatics Assoc.
Raina Langevin, Deepthi Mohanraj, Libby Shah, Janice Sabin, Brian R. Wood, Wanda Pratt, Nadir Weibel, Andrea L. Hartzler
2025 J jnl
Proc. ACM Hum. Comput. Interact.
Hyeyoung Ryu, JaeWon Kim, Sungha Kang, Wanda Pratt
2025 J jnl
CoRR
Jiatao Quan, Ziyue Li, Tian Qi Zhu, Yuxuan Li, Baoying Wang, Wanda Pratt, Nan Gao
2024 A* conf
CHI
Manas Satish Bedmutha, Anuujin Tsedenbal, Kelly Tobar, Sarah Borsotto, Kimberly R. Sladek, Deepansha Singh, Reggie Casanova-Perez, Emily Bascom, Brian R. Wood, Janice Sabin, Wanda Pratt, Andrea L. Hartzler, Nadir Weibel
2024 A* conf
CHI
Emily Bascom, Reggie Casanova-Perez, Kelly Tobar, Manas Satish Bedmutha, Harshini Ramaswamy, Wanda Pratt, Janice Sabin, Brian R. Wood, Nadir Weibel, Andrea L. Hartzler
2024 J jnl
Proc. ACM Hum. Comput. Interact.
Julia C. Dunbar, Wanda Pratt, Emily E. Bascom, Cara Currier, Joseph William Tan Garcia, Jodi Smith, Jaime Snyder, Ari H. Pollack
2024 J jnl
CoRR
Feng Chen, Manas Satish Bedmutha, Ray-yuan Chung, Janice Sabin, Wanda Pratt, Brian R. Wood, Nadir Weibel, Andrea L. Hartzler, Trevor Cohen
2023 A* conf
CHI
Anastasia Schaadhardt, Yue Fu, Cory Gennari Pratt, Wanda Pratt
2023 J jnl
CoRR
Nikhil Kashyap, Manas Satish Bedmutha, Prerit Chaudhary, Brian R. Wood, Wanda Pratt, Janice Sabin, Andrea L. Hartzler, Nadir Weibel
2022 conf
CHI Extended Abstracts
Lisa Dirks, Erin Beneteau, Janice Sabin, Wanda Pratt, Cezanne Lane, Emily Bascom, Reggie Casanova-Perez, Naba Rizvi, Nadir Weibel, Andrea L. Hartzler
2022 Misc conf
AMIA
Connie Yang, Deepthi Mohanraj, Alexandra Dogbe, Ayah Idris, Joseph William Tan Garcia, Linda Janelle Chastine, Emily Bascom, Reggie Casanova-Perez, Janice Sabin, Wanda Pratt, Andrea L. Hartzler, Nadir Weibel
2022 J jnl
J. Am. Medical Informatics Assoc.
Mary Regina Boland, Noémie Elhadad, Wanda Pratt
2022 J jnl
J. Am. Medical Informatics Assoc.
Calvin R. Apodaca, Reggie Casanova-Perez, Emily Bascom, Deepthi Mohanraj, Cezanne Lane, Drishti Vidyarthi, Erin Beneteau, Janice Sabin, Wanda Pratt, Nadir Weibel, Andrea L. Hartzler
2022 J jnl
J. Am. Medical Informatics Assoc.
Hyeyoung Ryu, Wanda Pratt
2022 Misc conf
AMIA
Anastasia Schaadhardt, Wanda Pratt
2022 Misc conf
AMIA
Reggie Casanova-Perez, Wanda Pratt, Andrea L. Hartzler
2022 J jnl
J. Am. Medical Informatics Assoc.
Erin Beneteau, Ann Paradiso, Wanda Pratt
2021 J jnl
J. Am. Medical Informatics Assoc.
Grace Wang, Julia Wignall, Dylan Kinard, Vidhi Singh, Carolyn Foster, Sherri Adams, Wanda Pratt, Arti D. Desai
2021 Misc conf
AMIA
Reggie Casanova-Perez, Calvin R. Apodaca, Emily Bascom, Deepthi Mohanraj, Cezanne Lane, Drishti Vidyarthi, Erin Beneteau, Janice Sabin, Wanda Pratt, Nadir Weibel, Andrea L. Hartzler
2021 Misc conf
AMIA
Erin Beneteau, Ann Paradiso, Wanda Pratt
2021 J jnl
J. Am. Medical Informatics Assoc.
Ari H. Pollack, Sonali R. Mishra, Calvin R. Apodaca, Maher Khelifi, Shefali Haldar, Wanda Pratt
2021 J jnl
Proc. ACM Hum. Comput. Interact.
Yiran Zhao, Yoojung Kim, Calvin R. Apodaca, Regina Casanova-Perez, Shefali Haldar, Sonali R. Mishra, Julia C. Dunbar, Ari H. Pollack, Wanda Pratt
2021 Misc conf
AMIA
Lisa G. Dirks, Wanda Pratt
2021 conf
CHI Extended Abstracts
Sonali R. Mishra, Shefali Haldar, Ari H. Pollack, Predrag V. Klasnja, Wanda Pratt
2021 Misc conf
AMIA
Emily Bascom, Reggie Casanova-Perez, Harshini Ramaswamy, Deepthi Mohanraj, Janice Sabin, Wanda Pratt, Andrea L. Hartzler
2020 J jnl
ACM Trans. Access. Comput.
Kristen Shinohara, Nayeri Jacobo, Wanda Pratt, Jacob O. Wobbrock
2020 Misc conf
AMIA
Shefali Haldar, Maher Khelifi, Sonali R. Mishra, Calvin R. Apodaca, Erin Beneteau, Ari H. Pollack, Wanda Pratt
2020 J jnl
J. Am. Medical Informatics Assoc.
Shefali Haldar, Sonali R. Mishra, Ari H. Pollack, Wanda Pratt
2020 Misc conf
AMIA
Julia C. Dunbar, Calvin R. Apodaca, Katherine Cross, Jason Yip, Ari H. Pollack, Wanda Pratt
2020 J jnl
Proc. ACM Hum. Comput. Interact.
Shefali Haldar, Yoojung Kim, Sonali R. Mishra, Andrea L. Hartzler, Ari H. Pollack, Wanda Pratt
2020 Misc conf
AMIA
Regina Casanova-Perez, Cezanne Lane, Erin Beneteau, Steven R. Rick, Wanda Pratt, Janice Sabin, Nadir Weibel, Andrea L. Hartzler
2020 J jnl
J. Am. Medical Informatics Assoc.
Shefali Haldar, Sonali R. Mishra, Yoojung Kim, Andrea L. Hartzler, Ari H. Pollack, Wanda Pratt
2020 J jnl
J. Am. Medical Informatics Assoc.
Arti D. Desai, Grace Wang, Julia Wignall, Dylan Kinard, Vidhi Singh, Sherri Adams, Wanda Pratt
2020 conf
CHI Extended Abstracts
Erin Beneteau, Sonali R. Mishra, Shefali Haldar, Calvin R. Apodaca, Ari H. Pollack, Wanda Pratt
2019 A* conf
CHI
Shefali Haldar, Sonali R. Mishra, Maher Khelifi, Ari H. Pollack, Wanda Pratt
2019 J jnl
J. Biomed. Informatics
Ari H. Pollack, Tamara D. Simon, Jaime Snyder, Wanda Pratt
2019 Misc conf
AMIA
Shefali Haldar, Yoojung Kim, Ari H. Pollack, Wanda Pratt
2019 A* conf
CHI
Amanda Menking, Ingrid Erickson, Wanda Pratt
2019 conf
VAHC
Ari H. Pollack, Wanda Pratt
2019 conf
ITCH
Shefali Haldar, Sonali R. Mishra, Maher Khelifi, Ari H. Pollack, Wanda Pratt
2019 Misc conf
AMIA
Elena Agapie, Logan Kendall, Sonali R. Mishra, Shefali Haldar, Maher Khelifi, Ari H. Pollack, Wanda Pratt
2018 A* conf
CHI
Kathleen O'Leary, Stephen M. Schueller, Jacob O. Wobbrock, Wanda Pratt
2018 Misc conf
AMIA
Ari H. Pollack, Maher Khelifi, Wanda Pratt
2018 Misc conf
AMIA
Katie O'Leary, Daryl Tanghe, Wanda Pratt, James D. Ralston
2018 A* conf
CHI
Jordan Eschler, Arpita Bhattacharya, Wanda Pratt
2018 Misc conf
AMIA
Maher Khelifi, Shefali Haldar, Sonali R. Mishra, Calvin R. Apodaca, Erin Beneteau, Ari H. Pollack, Wanda Pratt
2018 Misc conf
AMIA
Shefali Haldar, Sonali R. Mishra, Maher Khelifi, Ari H. Pollack, Wanda Pratt
2018 A conf
ASSETS
Kristen Shinohara, Jacob O. Wobbrock, Wanda Pratt
2018 Misc conf
AMIA
Calvin R. Apodaca, Shefali Haldar, Sonali R. Mishra, Maher Khelifi, Ari H. Pollack, Wanda Pratt
2018 Misc conf
AMIA
Sonali R. Mishra, Shefali Haldar, Maher Khelifi, Ari H. Pollack, Wanda Pratt
2018 A* conf
CHI
Sonali R. Mishra, Andrew D. Miller, Shefali Haldar, Maher Khelifi, Jordan Eschler, Rashmi G. Elera, Ari H. Pollack, Wanda Pratt
2018 J jnl
ACM Trans. Access. Comput.
Kristen Shinohara, Cynthia L. Bennett, Wanda Pratt, Jacob O. Wobbrock
2017 A conf
CSCW
Jordan Eschler, Wanda Pratt
2017 Misc conf
AMIA
Lisa M. Vizer, Jordan Eschler, Bon Mi Koo, James D. Ralston, Wanda Pratt
2017 A conf
CSCW
Kathleen O'Leary, Arpita Bhattacharya, Sean A. Munson, Jacob O. Wobbrock, Wanda Pratt
2017 J jnl
J. Biomed. Informatics
Courtland VanDam, Shaheen Kanthawala, Wanda Pratt, Joyce Chai, Jina Huh
2017 Misc conf
AMIA
Wanda Pratt, Patricia C. Dykes, Ryan Greysen, Cornelia M. Ruland, David W. Bates
2017 Misc conf
AMIA
Shefali Haldar, Sonali R. Mishra, Ari H. Pollack, Wanda Pratt
2017 A* conf
CHI
Shefali Haldar, Sonali R. Mishra, Maher Khelifi, Ari H. Pollack, Wanda Pratt
2017 conf
CSCL
Kristen Shinohara, Cynthia L. Bennett, Jacob O. Wobbrock, Wanda Pratt
2016 A* conf
CHI
Sonali R. Mishra, Shefali Haldar, Ari H. Pollack, Logan Kendall, Andrew D. Miller, Maher Khelifi, Wanda Pratt
2016 Misc conf
AMIA
Shefali Haldar, Alex Filipkowski, Sonali R. Mishra, Cory Brown, Rashmi G. Elera, Ari H. Pollack, Wanda Pratt
2016 J jnl
J. Am. Medical Informatics Assoc.
Patrick C. Sanger, Andrea L. Hartzler, Ross J. Lordon, Cheryl A. L. Armstrong, William B. Lober, Heather L. Evans, Wanda Pratt
2016 Misc conf
AMIA
Andrew D. Miller, Ari H. Pollack, Wanda Pratt
2016 A* conf
CHI
Ari H. Pollack, Uba Backonja, Andrew D. Miller, Sonali R. Mishra, Maher Khelifi, Logan Kendall, Wanda Pratt
2016 J jnl
ACM Trans. Comput. Hum. Interact.
Andrea L. Hartzler, Bridget Weis, Carly Cahill, Wanda Pratt, Albert Park, Uba Backonja, David W. McDonald
2016 Misc conf
AMIA
Jordan Eschler, Perry Lin Meas, Paula Lozano, Jennifer B. McClure, James D. Ralston, Wanda Pratt
2016 J jnl
J. Am. Medical Informatics Assoc.
Andrea L. Hartzler, Megan N. Taylor, Albert Park, Troy Griffiths, Uba Backonja, David W. McDonald, Sam Wahbeh, Cory Brown, Wanda Pratt
2016 Misc conf
AMIA
Ari H. Pollack, Andrew D. Miller, Sonali R. Mishra, Wanda Pratt
2016 A conf
CSCW
Andrew D. Miller, Sonali R. Mishra, Logan Kendall, Shefali Haldar, Ari H. Pollack, Wanda Pratt
2016 Misc conf
AMIA
Katie O'Leary, Leslie S. Liu, Jennifer B. McClure, James D. Ralston, Wanda Pratt
2015 A conf
CSCW
Leslie S. Liu, Kori M. Inkpen, Wanda Pratt
2015 Misc conf
AMIA
Jordan Eschler, Leslie S. Liu, Lisa M. Vizer, Jennifer B. McClure, Paula Lozano, Wanda Pratt, James D. Ralston
2015 Misc conf
AMIA
Albert Park, Andrea L. Hartzler, Jina Huh, David W. McDonald, Wanda Pratt
2015 Misc conf
AMIA
Predrag V. Klasnja, Logan Kendall, Wanda Pratt, Katherine S. Blondon
2015 Misc conf
AMIA
Logan Kendall, Sonali R. Mishra, Ari H. Pollack, Barry Aaronson, Wanda Pratt
2015 A conf
ICWSM
Jordan Eschler, Zakariya Dehlawi, Wanda Pratt
2015 A conf
CSCW
Jordan Eschler, Logan Kendall, Kathleen O'Leary, Lisa M. Vizer, Paula Lozano, Jennifer B. McClure, Wanda Pratt, James D. Ralston
2015 Misc conf
UbiComp
Eun Kyoung Choe, Bongshin Lee, Matthew Kay, Wanda Pratt, Julie A. Kientz
2015 conf
HICSS
Jordan Eschler, Katie O'Leary, Logan Kendall, James D. Ralston, Wanda Pratt
2015 A* conf
CHI
Katie O'Leary, Jordan Eschler, Logan Kendall, Lisa M. Vizer, James D. Ralston, Wanda Pratt
2015 Misc conf
AMIA
Katie O'Leary, Lisa M. Vizer, Jordan Eschler, James D. Ralston, Wanda Pratt
2015 Misc conf
AMIA
Maher Khelifi, Logan Kendall, Sonali R. Mishra, Barry Aaronson, Ari H. Pollack, Andrew D. Miller, Wanda Pratt
2015 Misc conf
AMIA
Uba Backonja, Albert Park, Andrea L. Hartzler, Megan N. Taylor, Troy Griffiths, Wanda Pratt
2014 Misc conf
AMIA
Patrick C. Sanger, Andrea L. Hartzler, William B. Lober, Heather L. Evans, Wanda Pratt
2014 Misc conf
AMIA
Logan Kendall, Jordan Eschler, Paula Lozano, Jennifer B. McClure, Lisa M. Vizer, James D. Ralston, Wanda Pratt
2014 Misc conf
AMIA
Andrea L. Hartzler, David W. McDonald, Albert Park, Jina Huh, Charles Weaver, Wanda Pratt
2014 J jnl
ACM Trans. Comput. Hum. Interact.
Jina Huh, Leslie S. Liu, Tina Neogi, Kori Inkpen, Wanda Pratt
2014 Misc conf
AMIA
Ari H. Pollack, Carolyn G. Tweedy, Katherine S. Blondon, Wanda Pratt
2014 J jnl
Interactions
Predrag V. Klasnja, Wanda Pratt
2014 A* conf
CHI
Eun Kyoung Choe, Nicole B. Lee, Bongshin Lee, Wanda Pratt, Julie A. Kientz
2014 A* conf
CHI
Jina Huh, Wanda Pratt
2013 conf
CHI Extended Abstracts
Karen Cheng, Kelly E. Caine, Wanda Pratt, Kay Connelly
2013 A* conf
CHI
Leslie S. Liu, Jina Huh, Tina Neogi, Kori Inkpen, Wanda Pratt
2013 conf
CHI Extended Abstracts
Rupa A. Patel, Andrea L. Hartzler, Mary Czerwinski, Wanda Pratt, Anthony L. Back, Asta Roseway
2013 Misc conf
AMIA
Jina Huh, David W. McDonald, Andrea L. Hartzler, Wanda Pratt
2013 conf
CHI Extended Abstracts
Lauren Wilcox, Rupa A. Patel, Anthony L. Back, Mary Czerwinski, Paul N. Gorman, Eric Horvitz, Wanda Pratt
2013 Misc conf
AMIA
Eun Kyoung Choe, Bongshin Lee, Sean A. Munson, Wanda Pratt, Julie A. Kientz
2013 J jnl
J. Biomed. Informatics
Jina Huh, Meliha Yetisgen-Yildiz, Wanda Pratt
2013 conf
PervasiveHealth
Rupa A. Patel, Andrea L. Hartzler, Wanda Pratt, Anthony L. Back, Mary Czerwinski, Asta Roseway
2012 conf
CSCW (Companion)
Jina Huh, Andrea L. Hartzler, Sean A. Munson, Nick R. Anderson, Kelly Edwards, John L. Gore, David W. McDonald, Jim O'Leary, Andrea A. Parker, Derek Streat, Meliha Yetisgen-Yildiz, Mark S. Ackerman, Wanda Pratt
2012 Misc conf
AMIA
Judy G. Ozbolt, Daniel Z. Sands, Patricia C. Dykes, Wanda Pratt, James Walker
2012 Misc conf
AMIA
Albert Park, Andrea L. Hartzler, Jina Huh, David W. McDonald, Wanda Pratt
2012 J jnl
J. Biomed. Informatics
Predrag V. Klasnja, Wanda Pratt
2012 Misc conf
AMIA
Andrea L. Hartzler, David W. McDonald, Albert Park, Jina Huh, Wanda Pratt
2012 Misc conf
AMIA
Rupa A. Patel, Predrag V. Klasnja, Andrea L. Hartzler, Kenton T. Unruh, Wanda Pratt
2012 A* conf
CHI
Jina Huh, Rupa A. Patel, Wanda Pratt
2012 Misc conf
AMIA
Jina Huh, Meliha Yetisgen-Yildiz, Andrea L. Hartzler, David W. McDonald, Albert Park, Wanda Pratt
2011 conf
CHI Extended Abstracts
Logan Kendall, Andrea Civan-Hartzler, Predrag V. Klasnja, Wanda Pratt
2011 A* conf
CHI
Predrag V. Klasnja, Sunny Consolvo, Wanda Pratt
2010 A* conf
CHI
Predrag V. Klasnja, Andrea Civan-Hartzler, Kenton T. Unruh, Wanda Pratt
2010 A* conf
CHI
Andrea Civan-Hartzler, David W. McDonald, Chris Powell, Meredith M. Skeels, Marlee Mukai, Wanda Pratt
2010 A* conf
CHI
Meredith M. Skeels, Kenton T. Unruh, Christopher Powell, Wanda Pratt
2010 A* conf
CHI
Kenton T. Unruh, Meredith M. Skeels, Andrea Civan-Hartzler, Wanda Pratt
2009 J jnl
J. Biomed. Informatics
Meliha Yetisgen-Yildiz, Wanda Pratt
2009 B conf
GROUP
Andrea Civan, David W. McDonald, Kenton T. Unruh, Wanda Pratt
2009 Misc conf
AMIA
Predrag V. Klasnja, Sunny Consolvo, David W. McDonald, James A. Landay, Wanda Pratt
2008 Misc conf
AMIA
Kenton T. Unruh, Wanda Pratt
2008 Misc conf
AMIA
Meliha Yetisgen-Yildiz, Wanda Pratt
2007 B conf
K-CAP
Meliha Yetisgen-Yildiz, Wanda Pratt
2007 J jnl
Commun. Assoc. Inf. Syst.
Andrea Civan, Wanda Pratt
2007 J jnl
Int. J. Medical Informatics
Kenton T. Unruh, Wanda Pratt
2007 J jnl
J. Biomed. Informatics
Wanda Pratt, Meliha Yetisgen-Yildiz
2007 Misc conf
AMIA
Andrea Civan, Wanda Pratt
2006 J jnl
J. Assoc. Inf. Sci. Technol.
Catherine Blake, Wanda Pratt
2006 J jnl
J. Assoc. Inf. Sci. Technol.
Catherine Blake, Wanda Pratt
2006 Misc conf
AMIA
Andrea Civan, John H. Gennari, Wanda Pratt
2006 Misc conf
AMIA
Andrea Civan, Meredith M. Skeels, Anna Stolyar, Wanda Pratt
2006 J jnl
Commun. ACM
Wanda Pratt, Kenton T. Unruh, Andrea Civan, Meredith M. Skeels
2006 conf
HICSS
Andrea Civan, Wanda Pratt
2006 J jnl
Comput. Support. Cooperative Work.
Madhu C. Reddy, Paul Dourish, Wanda Pratt
2006 J jnl
J. Biomed. Informatics
Meliha Yetisgen-Yildiz, Wanda Pratt
2005 conf
CHI Extended Abstracts
Meredith M. Skeels, Kiera Henning, Meliha Yetisgen-Yildiz, Wanda Pratt
2005 J jnl
J. Biomed. Informatics
Madhu C. Reddy, David W. McDonald, Wanda Pratt, M. Michael Shabot
2005 Misc conf
AMIA
Meliha Yetisgen-Yildiz, Wanda Pratt
2004 conf
CHI Extended Abstracts
Lena Mamykina, Jakob E. Bardram, Ilkka Korhonen, Elizabeth D. Mynatt, Wanda Pratt
2004 J jnl
J. Biomed. Informatics
Wanda Pratt, Madhu C. Reddy, David W. McDonald, Peter Tarczy-Hornoch, John H. Gennari
2003 Misc conf
AMIA
Wanda Pratt, Meliha Yetisgen-Yildiz
2003 Misc conf
AMIA
Madhu C. Reddy, Wanda Pratt, David W. McDonald, M. Michael Shabot
2003 B conf
K-CAP
Wanda Pratt, Meliha Yetisgen-Yildiz
2002 Misc conf
AMIA
Madhu C. Reddy, Wanda Pratt, Paul Dourish, M. Michael Shabot
2002 Misc conf
AMIA
Catherine Blake, Wanda Pratt, Tammy Tengs
2002 conf
ASIST
Catherine Blake, Wanda Pratt
2001 A* conf
ICDM
Catherine Blake, Wanda Pratt
2001 B conf
ECSCW
Madhu C. Reddy, Paul Dourish, Wanda Pratt
2001 A* conf
SIGIR
Jack Muramatsu, Wanda Pratt
2000 Misc conf
AMIA
Madhu C. Reddy, Chad Seeraty, Tai-Wei Lin, Wanda Pratt
2000 Misc conf
AMIA
Catherine Blake, Wanda Pratt
2000 Misc conf
AMIA
Wanda Pratt, Henry Wasserman
2000 J jnl
J. Am. Medical Informatics Assoc.
Wanda Pratt, Lawrence M. Fagan
1999 conf
AAAI/IAAI
Wanda Pratt, Marti A. Hearst, Lawrence M. Fagan
1999 A* conf
SIGIR
Xianping Ge, Wanda Pratt, Padhraic Smyth
1997 conf
AAAI/IAAI
Wanda Pratt
1997 Misc conf
AMIA
Wanda Pratt
redb/extractors/decompiler/apk/method_extractor.py
← Index redb/extractors/decompiler/apk/method_extractor.py python
"""Per-method content extraction, hashing, and similarity computation.

Handles SHA-256 content hashing, ssdeep/TLSH fuzzy hashing, MinHash
computation, and obfuscation indicator detection for APK methods.
"""

import hashlib
import re
from typing import Dict, List, Optional

from redb.extractors.decompiler.apk.smali_normalization import (
    categorize_opcode,
    normalize_method_body,
)
from redb.extractors.decompiler.apk.smali_parser import SmaliParser


# ---------------------------------------------------------------------------
# Smali Prime Product — semantic primes matching Binary Ninja's LLIL primes
# ---------------------------------------------------------------------------
# Each Dalvik semantic category maps to the same prime its LLIL counterpart
# uses in cfg_features.py. This makes prime products semantically comparable
# for APK-vs-APK similarity (not numerically comparable to Binja values).

SMALI_OP_PRIMES = {
    "ALU": 37,       # ADD/SUB → same prime as LLIL_ADD
    "CONV": 131,     # Type conversions → same as LLIL_SX
    "CMP": 103,      # Comparisons → same as LLIL_CMP_E
    "MOV": 2,        # Register moves → same as LLIL_SET_REG
    "CONST": 2,      # Constants → SET_REG equivalent
    "LOAD": 5,       # Field/array reads → same as LLIL_LOAD
    "STORE": 7,      # Field/array writes → same as LLIL_STORE
    "CALL": 17,      # invoke-* → same as LLIL_CALL
    "BRANCH": 29,    # if-* → same as LLIL_IF
    "JMP": 31,       # goto → same as LLIL_GOTO
    "SWITCH": 151,   # switch → same as LLIL_JUMP_TO
    "RET": 23,       # return → same as LLIL_RET
    "ALLOC": 5,      # new-instance/new-array → LOAD-adjacent (heap access)
    "TYPE": 1,       # check-cast/instance-of → identity (metadata)
    "ARR": 5,        # array-length/fill-array → LOAD-adjacent
    "EXC": 23,       # throw → RET-adjacent (control transfer out)
    "SYNC": 1,       # monitor → identity (no LLIL equivalent)
    "OTHER": 1,      # Unknown → identity
}


def compute_prime_product_smali(smali_body: str) -> int:
    """Multiplicative hash of normalized Dalvik opcodes. Mod 2^64.

    Same algorithm as cfg_features.compute_prime_product but using
    Dalvik semantic categories instead of LLIL operation enums.
    """
    if not smali_body:
        return 0

    product = 1
    for line in smali_body.splitlines():
        stripped = line.strip()
        if not stripped or stripped.startswith((".", ":", "#")):
            continue
        opcode = stripped.split()[0].split("/")[0] if stripped else ""
        category = categorize_opcode(opcode)
        prime = SMALI_OP_PRIMES.get(category, 1)
        product = (product * prime) % (2**64)

    return product


def count_call_instructions(smali_body: str) -> int:
    """Count invoke-* instructions in a smali method body."""
    if not smali_body:
        return 0
    count = 0
    for line in smali_body.splitlines():
        stripped = line.strip()
        if stripped.startswith("invoke-"):
            count += 1
    return count


def compute_sha256(content: str) -> str:
    """Compute SHA-256 hash of normalized content."""
    return hashlib.sha256(content.encode("utf-8")).hexdigest()


def compute_ssdeep(content: str) -> Optional[str]:
    """Compute ssdeep fuzzy hash of content."""
    try:
        import ppdeep
        data = content.encode("utf-8")
        if len(data) < 50:
            return None
        result = ppdeep.hash(data)
        return result if result else None
    except (ImportError, Exception):
        return None


def compute_tlsh(content: str) -> Optional[str]:
    """Compute TLSH fuzzy hash of content."""
    try:
        import tlsh
        data = content.encode("utf-8")
        if len(data) < 50:
            return None
        result = tlsh.hash(data)
        return result if result else None
    except (ImportError, Exception):
        return None


def compute_minhash(
    content: str,
    n: int = 3,
    normalization_level: str = "opcode_api",
) -> Optional[List[int]]:
    """Compute MinHash signature from semantically normalized smali n-grams.

    Applies semantic normalization (analogous to Binary Ninja's LLIL) before
    computing the MinHash. This strips register allocation noise and
    instruction encoding variants while preserving operation semantics and
    API references.

    Uses the same algorithm and parameters as the Binary Ninja MinHasher
    (64 seeds from master seed 0xdeadbeef, 8-bit signature elements, mmh3)
    to ensure cross-platform similarity comparisons are compatible.

    Args:
        content: Raw smali method body.
        n: N-gram size (default 3).
        normalization_level: Normalization level for instructions.
            'opcode_api' (default) preserves API call/field references.
            'category' uses only semantic categories.
            'opcode' uses base opcodes without operands.
    """
    try:
        import mmh3
    except ImportError:
        return None

    HASH_MAX = 0xFFFFFFFF
    SIGNATURE_LENGTH = 64
    SIGNATURE_BITS = 8

    # Semantically normalize instructions (like LLIL for native code)
    lines = normalize_method_body(content, level=normalization_level)

    if len(lines) < n:
        return None

    # Build n-grams (tuples of normalized instruction strings)
    shingles = [tuple(lines[i:i + n]) for i in range(len(lines) - n + 1)]

    if not shingles:
        return None

    # Generate deterministic seeds matching the Binary Ninja pipeline
    import random
    rng = random.Random(0xDEADBEEF)
    seeds = [rng.randint(0, HASH_MAX) for _ in range(SIGNATURE_LENGTH)]

    # For each seed, hash all shingles and take the minimum
    signature = []
    for seed in seeds:
        min_val = HASH_MAX
        for shingle in shingles:
            text = "|".join(str(elem) for elem in shingle)
            h = mmh3.hash(text, seed) & HASH_MAX
            if h < min_val:
                min_val = h
        # Truncate to signature bits
        if SIGNATURE_BITS < 32:
            min_val %= (2 ** SIGNATURE_BITS)
        signature.append(min_val)

    return signature


def detect_obfuscation_indicators(
    method_name: str,
    class_name: str,
    smali_body: str,
    instruction_count: int,
) -> Dict[str, bool]:
    """Compute obfuscation indicators for a method.

    Returns dict with boolean indicators.
    """
    indicators = {}

    # Short method name (typical R8/ProGuard output)
    indicators["short_method_name"] = len(method_name) <= 2

    # Short class name — extract simple name from Dalvik descriptor
    simple_class = class_name
    if "/" in simple_class:
        simple_class = simple_class.rsplit("/", 1)[-1]
    simple_class = simple_class.rstrip(";")
    indicators["short_class_name"] = len(simple_class) <= 2

    # String encryption: const-string followed by decryption-pattern call
    indicators["has_string_encryption"] = _detect_string_encryption(smali_body)

    # Reflection calls
    indicators["has_reflection_calls"] = _detect_reflection_calls(smali_body)

    # Excessive goto count (control flow flattening)
    goto_count = _count_goto_instructions(smali_body)
    threshold = max(5, int(instruction_count * 0.15))
    indicators["excessive_goto_count"] = goto_count > threshold

    return indicators


def _detect_string_encryption(smali_body: str) -> bool:
    """Detect const-string followed by decryption-pattern calls."""
    lines = smali_body.split("\n")
    for i, line in enumerate(lines):
        stripped = line.strip()
        if stripped.startswith("const-string"):
            # Check the next 3 lines for invoke-* to potential decryption
            for j in range(i + 1, min(i + 4, len(lines))):
                next_line = lines[j].strip()
                if next_line.startswith("invoke-"):
                    # Common decryption patterns
                    if any(
                        pat in next_line
                        for pat in [
                            "decrypt",
                            "decode",
                            "Cipher",
                            "DES",
                            "AES",
                            "Base64",
                            "getBytes",
                        ]
                    ):
                        return True
    return False


def _detect_reflection_calls(smali_body: str) -> bool:
    """Detect use of Java reflection APIs."""
    reflection_patterns = [
        "Ljava/lang/reflect/",
        "Ljava/lang/Class;->forName",
        "Ljava/lang/Class;->getMethod",
        "Ljava/lang/Class;->getDeclaredMethod",
        "Ljava/lang/Class;->getField",
        "Ljava/lang/Class;->getDeclaredField",
    ]
    for pattern in reflection_patterns:
        if pattern in smali_body:
            return True
    return False


def _count_goto_instructions(smali_body: str) -> int:
    """Count goto/goto_16/goto_32 instructions."""
    count = 0
    for line in smali_body.split("\n"):
        stripped = line.strip()
        if stripped.startswith(("goto ", "goto/16 ", "goto/32 ")):
            count += 1
        elif stripped in ("goto", "goto/16", "goto/32"):
            count += 1
    return count


def dalvik_to_java_class(descriptor: str) -> str:
    """Convert Dalvik class descriptor to Java dot notation.

    Lcom/example/Foo; -> com.example.Foo
    """
    if descriptor.startswith("L") and descriptor.endswith(";"):
        return descriptor[1:-1].replace("/", ".")
    return descriptor.replace("/", ".")


def dalvik_type_to_java(type_desc: str) -> str:
    """Convert a Dalvik type descriptor to Java type name."""
    type_map = {
        "V": "void",
        "Z": "boolean",
        "B": "byte",
        "S": "short",
        "C": "char",
        "I": "int",
        "J": "long",
        "F": "float",
        "D": "double",
    }

    if not type_desc:
        return "void"

    if type_desc in type_map:
        return type_map[type_desc]

    if type_desc.startswith("["):
        return dalvik_type_to_java(type_desc[1:]) + "[]"

    if type_desc.startswith("L") and type_desc.endswith(";"):
        full = type_desc[1:-1].replace("/", ".")
        # Return simple name
        return full.rsplit(".", 1)[-1] if "." in full else full

    return type_desc


def dalvik_to_java_prototype(
    method_name: str, signature: str, class_name: str = ""
) -> str:
    """Convert Dalvik method signature to Java-style prototype.

    Input: method_name='onCreate', signature='(Landroid/os/Bundle;)V'
    Output: 'void onCreate(Bundle)'
    """
    # Parse return type and param types from signature
    if not signature or not signature.startswith("("):
        return f"void {method_name}()"

    close_paren = signature.find(")")
    if close_paren == -1:
        return f"void {method_name}()"

    params_str = signature[1:close_paren]
    return_type_str = signature[close_paren + 1:]

    return_type = dalvik_type_to_java(return_type_str)
    params = _parse_dalvik_params(params_str)
    param_java = ", ".join(dalvik_type_to_java(p) for p in params)

    return f"{return_type} {method_name}({param_java})"


def _parse_dalvik_params(params_str: str) -> List[str]:
    """Parse Dalvik parameter descriptor string into individual types."""
    params = []
    i = 0
    while i < len(params_str):
        ch = params_str[i]
        if ch in "VZBSCIJFD":
            params.append(ch)
            i += 1
        elif ch == "[":
            # Array — find the base type
            array_prefix = "["
            i += 1
            while i < len(params_str) and params_str[i] == "[":
                array_prefix += "["
                i += 1
            if i < len(params_str):
                if params_str[i] == "L":
                    end = params_str.find(";", i)
                    if end != -1:
                        params.append(array_prefix + params_str[i : end + 1])
                        i = end + 1
                    else:
                        break
                else:
                    params.append(array_prefix + params_str[i])
                    i += 1
        elif ch == "L":
            end = params_str.find(";", i)
            if end != -1:
                params.append(params_str[i : end + 1])
                i = end + 1
            else:
                break
        else:
            i += 1
    return params