Jaina Mistry

17 papers Journal 17
YearRankTypeTitle / Venue / Authors
2021 J jnl
Briefings Bioinform.
Franziska Hufsky, Kevin Lamkiewicz, Alexandre Almeida, Abdel Aouacheria, Cecilia N. Arighi, Alex Bateman, Jan Baumbach, Niko Beerenwinkel, Christian Brandt, Marco Cacciabue, Sara Chuguransky, Oliver Drechsel, Robert D. Finn, Adrian Fritz, Stephan Fuchs, Georges Hattab, Anne-Christin Hauschild, Dominik Heider, Marie Hoffmann, Martin Hölzer, Stefan Hoops, Lars Kaderali, Ioanna Kalvari, Max von Kleist, Renó Kmiecinski, Denise Kühnert, Gorka Lasso, Pieter Libin, Markus List, Hannah F. Löchel, Maria Jesus Martin, Roman Martin, Julian O. Matschinske, Alice C. McHardy, Pedro Mendes, Jaina Mistry, Vincent Navratil, Eric P. Nawrocki, Áine Niamh O'toole, Nancy Ontiveros-Palacios, Anton I. Petrov, Guillermo Rangel-Pineros, Nicole Redaschi, Susanne Reimering, Knut Reinert, Alejandro Reyes, Lorna J. Richardson, David L. Robertson, Sepideh Sadegh, Joshua B. Singer, Kristof Theys, Chris Upton, Marius Welzel, Lowri Williams, Manja Marz
2021 J jnl
Nucleic Acids Res.
Jaina Mistry, Sara Chuguransky, Lowri Williams, Matloob Qureshi, Gustavo A. Salazar, Erik L. L. Sonnhammer, Silvio C. E. Tosatto, Lisanna Paladin, Shriya Raj, Lorna J. Richardson, Robert D. Finn, Alex Bateman
2019 J jnl
Nucleic Acids Res.
Sara El-Gebali, Jaina Mistry, Alex Bateman, Sean R. Eddy, Aurelien Luciani, Simon C. Potter, Matloob Qureshi, Lorna J. Richardson, Gustavo A. Salazar, Alfredo Smart, Erik L. L. Sonnhammer, Layla Hirsh, Lisanna Paladin, Damiano Piovesan, Silvio C. E. Tosatto, Robert D. Finn
2017 J jnl
Nucleic Acids Res.
Robert D. Finn, Teresa K. Attwood, Patricia C. Babbitt, Alex Bateman, Peer Bork, Alan J. Bridge, Hsin-Yu Chang, Zsuzsanna Dosztányi, Sara El-Gebali, Matthew Fraser, Julian Gough, David Haft, Gemma L. Holliday, Hongzhan Huang, Xiaosong Huang, Ivica Letunic, Rodrigo Lopez, Shennan Lu, Aron Marchler-Bauer, Huaiyu Mi, Jaina Mistry, Darren A. Natale, Marco Necci, Gift Nuka, Christine A. Orengo, Young Mi Park, Sebastien Pesseat, Damiano Piovesan, Simon C. Potter, Neil D. Rawlings, Nicole Redaschi, Lorna J. Richardson, Catherine Rivoire, Amaia Sangrador-Vegas, Christian J. A. Sigrist, Ian Sillitoe, Ben Smithers, Silvano Squizzato, Granger G. Sutton, Narmada Thanki, Paul D. Thomas, Silvio C. E. Tosatto, Cathy H. Wu, Ioannis Xenarios, Lai-Su L. Yeh, Siew-Yit Yong, Alex L. Mitchell
2016 J jnl
Nucleic Acids Res.
Robert D. Finn, Penelope Coggill, Ruth Y. Eberhardt, Sean R. Eddy, Jaina Mistry, Alex L. Mitchell, Simon C. Potter, Marco Punta, Matloob Qureshi, Amaia Sangrador-Vegas, Gustavo A. Salazar, John G. Tate, Alex Bateman
2015 J jnl
Nucleic Acids Res.
Tony E. Lewis, Ian Sillitoe, Antonina Andreeva, Tom L. Blundell, Daniel W. A. Buchan, Cyrus Chothia, Domenico Cozzetto, Jose M. Dana, Ioannis Filippis, Julian Gough, David T. Jones, Lawrence A. Kelley, Gerard J. Kleywegt, Federico Minneci, Jaina Mistry, Alexey G. Murzin, Bernardo Ochoa-Montaño, Matt E. Oates, Marco Punta, Owen J. L. Rackham, Jonathan Stahlhacke, Michael J. E. Sternberg, Sameer Velankar, Christine A. Orengo
2015 J jnl
Briefings Bioinform.
Zachary Chiang, Åke Västermark, Marco Punta, Penelope Coggill, Jaina Mistry, Robert D. Finn, Milton H. Saier Jr.
2014 J jnl
Nucleic Acids Res.
Robert D. Finn, Alex Bateman, Jody Clements, Penelope Coggill, Ruth Y. Eberhardt, Sean R. Eddy, Andreas Heger, Kirstie Hetherington, Liisa Holm, Jaina Mistry, Erik L. L. Sonnhammer, John G. Tate, Marco Punta
2013 J jnl
Database J. Biol. Databases Curation
Jaina Mistry, Penny C. Coggill, Ruth Y. Eberhardt, Antonio Deiana, Andrea Giansanti, Robert D. Finn, Alex Bateman, Marco Punta
2013 J jnl
Database J. Biol. Databases Curation
Jaina Mistry, Penny C. Coggill, Ruth Y. Eberhardt, Antonio Deiana, Andrea Giansanti, Robert D. Finn, Alex Bateman, Marco Punta
2012 J jnl
Nucleic Acids Res.
Marco Punta, Penny C. Coggill, Ruth Y. Eberhardt, Jaina Mistry, John G. Tate, Chris Boursnell, Ningze Pang, Kristoffer Forslund, Goran Ceric, Jody Clements, Andreas Heger, Liisa Holm, Erik L. L. Sonnhammer, Sean R. Eddy, Alex Bateman, Robert D. Finn
2010 J jnl
Nucleic Acids Res.
Robert D. Finn, Jaina Mistry, John G. Tate, Penny C. Coggill, Andreas Heger, Joanne E. Pollington, O. Luke Gavin, Prasad Gunasekaran, Goran Ceric, Kristoffer Forslund, Liisa Holm, Erik L. L. Sonnhammer, Sean R. Eddy, Alex Bateman
2009 J jnl
Nucleic Acids Res.
Sarah Hunter, Rolf Apweiler, Teresa K. Attwood, Amos Bairoch, Alex Bateman, David Binns, Peer Bork, Ujjwal Das, Louise C. Daugherty, Lauranne Duquenne, Robert D. Finn, Julian Gough, Daniel H. Haft, Nicolas Hulo, Daniel Kahn, Elizabeth Kelly, Aurélie Laugraud, Ivica Letunic, David Lonsdale, Rodrigo Lopez, Martin Madera, John Maslen, Craig McAnulla, Jennifer McDowall, Jaina Mistry, Alex L. Mitchell, Nicola J. Mulder, Darren A. Natale, Christine A. Orengo, Antony F. Quinn, Jeremy D. Selengut, Christian J. A. Sigrist, Manjula Thimma, Paul D. Thomas, Franck Valentin, Derek Wilson, Cathy H. Wu, Corin Yeats
2008 J jnl
Nucleic Acids Res.
Robert D. Finn, John G. Tate, Jaina Mistry, Penny C. Coggill, Stephen John Sammut, Hans-Rudolf Hotz, Goran Ceric, Kristoffer Forslund, Sean R. Eddy, Erik L. L. Sonnhammer, Alex Bateman
2007 J jnl
Nucleic Acids Res.
Nicola J. Mulder, Rolf Apweiler, Teresa K. Attwood, Amos Bairoch, Alex Bateman, David Binns, Peer Bork, Virginie Buillard, Lorenzo Cerutti, Richard R. Copley, Emmanuel Courcelle, Ujjwal Das, Louise C. Daugherty, Mark Dibley, Robert D. Finn, Wolfgang Fleischmann, Julian Gough, Daniel H. Haft, Nicolas Hulo, Sarah Hunter, Daniel Kahn, Alexander Kanapin, Anish Kejariwal, Alberto Labarga, Petra S. Langendijk-Genevaux, David Lonsdale, Rodrigo Lopez, Ivica Letunic, Martin Madera, John Maslen, Craig McAnulla, Jennifer McDowall, Jaina Mistry, Alex L. Mitchell, Anastasia N. Nikolskaya, Sandra E. Orchard, Christine A. Orengo, Robert Petryszak, Jeremy D. Selengut, Christian J. A. Sigrist, Paul D. Thomas, Franck Valentin, Derek Wilson, Cathy H. Wu, Corin Yeats
2007 J jnl
BMC Bioinform.
Jaina Mistry, Alex Bateman, Robert D. Finn
2006 J jnl
Nucleic Acids Res.
Robert D. Finn, Jaina Mistry, Benjamin Schuster-Böckler, Sam Griffiths-Jones, Volker Hollich, Timo Lassmann, Simon Moxon, Mhairi Marshall, Ajay Khanna, Richard Durbin, Sean R. Eddy, Erik L. L. Sonnhammer, Alex Bateman
redb/extractors/decompiler/apk/smali_parser.py
← Index redb/extractors/decompiler/apk/smali_parser.py python
"""Smali file parser — extracts individual method bodies from apktool output.

Parses .smali files produced by apktool and extracts per-method bodies,
instruction counts, and register counts.
"""

import os
import re
from dataclasses import dataclass, field
from typing import Dict, List, Optional


@dataclass
class SmaliMethod:
    """Parsed smali method data."""
    class_name: str
    method_name: str
    method_signature: str
    body: str
    instruction_count: int = 0
    register_count: int = 0
    access_flags: List[str] = field(default_factory=list)


# Directives start with '.' — these are metadata, not instructions
_DIRECTIVE_RE = re.compile(r"^\s*\.")
# Labels start with ':'
_LABEL_RE = re.compile(r"^\s*:")
# Blank or comment lines
_BLANK_OR_COMMENT_RE = re.compile(r"^\s*(#.*)?$")
# Method declaration
_METHOD_START_RE = re.compile(
    r"^\.method\s+(.*?)\s+(\S+)\(([^)]*)\)(\S+)\s*$"
)
_METHOD_START_SIMPLE_RE = re.compile(
    r"^\.method\s+(.*)"
)
# .registers or .locals directive
_REGISTERS_RE = re.compile(r"^\s*\.registers\s+(\d+)")
_LOCALS_RE = re.compile(r"^\s*\.locals\s+(\d+)")
# .line directive
_LINE_RE = re.compile(r"^\s*\.line\s+\d+")


class SmaliParser:
    """Parser for apktool smali output files."""

    @staticmethod
    def parse_smali_file(filepath: str) -> List[SmaliMethod]:
        """Parse a single .smali file and return list of methods.

        Each .smali file contains one class with all its methods.
        """
        with open(filepath, "r", encoding="utf-8", errors="replace") as f:
            content = f.read()

        return SmaliParser._parse_smali_content(content, filepath)

    @staticmethod
    def _parse_smali_content(content: str, source: str = "") -> List[SmaliMethod]:
        """Parse smali text content and extract methods."""
        lines = content.split("\n")
        methods = []

        # Extract class name from .class directive
        class_name = ""
        for line in lines:
            if line.startswith(".class "):
                parts = line.split()
                class_name = parts[-1]  # Last token is the class descriptor
                break

        in_method = False
        method_lines = []
        method_header = ""
        access_flags = []
        skip_method = False

        for line in lines:
            if line.startswith(".method "):
                in_method = True
                method_lines = []
                method_header = line
                skip_method = False

                # Parse access flags and method signature
                remainder = line[len(".method "):].strip()
                tokens = remainder.split()
                access_flags = []
                method_sig_token = tokens[-1] if tokens else ""

                for t in tokens[:-1]:
                    access_flags.append(t)

                # Skip abstract and native methods (no body)
                if "abstract" in access_flags or "native" in access_flags:
                    skip_method = True

            elif line.startswith(".end method"):
                if in_method and not skip_method:
                    body = "\n".join(method_lines)
                    method_name, signature = SmaliParser._parse_method_sig(
                        method_header
                    )
                    instruction_count = SmaliParser.count_instructions(body)
                    register_count = SmaliParser._extract_register_count(body)

                    methods.append(
                        SmaliMethod(
                            class_name=class_name,
                            method_name=method_name,
                            method_signature=signature,
                            body=body,
                            instruction_count=instruction_count,
                            register_count=register_count,
                            access_flags=access_flags,
                        )
                    )
                in_method = False
                method_lines = []
                access_flags = []

            elif in_method and not skip_method:
                method_lines.append(line)

        return methods

    @staticmethod
    def parse_smali_directory(dirpath: str) -> Dict[str, SmaliMethod]:
        """Parse all .smali files in a directory tree.

        Returns dict keyed by 'ClassName->methodName(signature)ReturnType'.
        """
        result = {}
        for root, _dirs, files in os.walk(dirpath):
            for fname in files:
                if fname.endswith(".smali"):
                    fpath = os.path.join(root, fname)
                    try:
                        methods = SmaliParser.parse_smali_file(fpath)
                        for m in methods:
                            key = SmaliParser.make_method_key(
                                m.class_name, m.method_name, m.method_signature
                            )
                            result[key] = m
                    except Exception:
                        continue
        return result

    @staticmethod
    def normalize_smali_body(body: str) -> str:
        """Normalize smali body for consistent hashing.

        Strips comments, .line directives, normalizes whitespace.
        """
        lines = []
        for line in body.split("\n"):
            stripped = line.strip()
            # Skip empty lines, comments, and .line directives
            if not stripped or stripped.startswith("#"):
                continue
            if _LINE_RE.match(stripped):
                continue
            lines.append(stripped)
        return "\n".join(lines)

    @staticmethod
    def count_instructions(body: str) -> int:
        """Count actual Dalvik instructions (skip directives, labels, blanks)."""
        count = 0
        for line in body.split("\n"):
            stripped = line.strip()
            if not stripped:
                continue
            if _DIRECTIVE_RE.match(stripped):
                continue
            if _LABEL_RE.match(stripped):
                continue
            if _BLANK_OR_COMMENT_RE.match(stripped):
                continue
            count += 1
        return count

    @staticmethod
    def _extract_register_count(body: str) -> int:
        """Extract register count from .registers or .locals directive.

        apktool outputs .locals (local registers only) by default.
        .registers (total = locals + params) is used with --use-registers.
        We return whichever is present.
        """
        for line in body.split("\n"):
            stripped = line.strip()
            m = _REGISTERS_RE.match(stripped)
            if m:
                return int(m.group(1))
            m = _LOCALS_RE.match(stripped)
            if m:
                return int(m.group(1))
        return 0

    @staticmethod
    def _parse_method_sig(header_line: str) -> tuple:
        """Parse method name and signature from .method header line.

        Input: '.method public onCreate(Landroid/os/Bundle;)V'
        Returns: ('onCreate', '(Landroid/os/Bundle;)V')
        """
        remainder = header_line[len(".method "):].strip()
        tokens = remainder.split()
        if not tokens:
            return ("unknown", "()")

        # Last token contains methodName(params)returnType
        method_part = tokens[-1]

        paren_idx = method_part.find("(")
        if paren_idx == -1:
            return (method_part, "()")

        method_name = method_part[:paren_idx]
        signature = method_part[paren_idx:]

        return (method_name, signature)

    @staticmethod
    def make_method_key(class_name: str, method_name: str, signature: str) -> str:
        """Build a canonical method key for cross-tool matching.

        Format: 'Lcom/example/Foo;->methodName(params)ReturnType'
        """
        return f"{class_name}->{method_name}{signature}"