Jamshid Dehmeshki

39 papers B 3C 7Journal 14Unranked 15
YearRankTypeTitle / Venue / Authors
2022 J jnl
IEEE Access
Maryam Yalsavar, Paknoosh Karimaghaee, Akbar Sheikh-Akbari, Mohammad Hassan Khooban, Jamshid Dehmeshki, Salah Al-Majeed
2021 J jnl
IEEE Access
Meysam Tavakoli, Alireza Mehdizadeh, Reza Aghayan, Reza Pourreza-Shahri, Tim Ellis, Jamshid Dehmeshki
2021 J jnl
IET Image Process.
Meysam Tavakoli, Alireza Mehdizadeh, Reza Pourreza-Shahri, Jamshid Dehmeshki
2020 J jnl
Health Informatics J.
Bram Knols, Mathijs Louws, Alec Hardenbol, Jamshid Dehmeshki, Marjan Askari
2019 J jnl
IEEE Trans. Fuzzy Syst.
Rahil Hosseini, Salah Dine Qanadli, Sarah Barman, Mahdi Mazinani, Tim Ellis, Jamshid Dehmeshki
2019 conf
IST
Maryam Yalsavar, Paknoosh Karimaghaee, Akbar Sheikh-Akbari, Jamshid Dehmeshki, Mohammad Hassan Khooban, Salah Al-Majeed
2018 conf
CSIT (1)
S. Habib, Jamshid Dehmeshki
2015 J jnl
Comput. Medical Imaging Graph.
R. A. Welikala, Muhammad Moazam Fraz, Jamshid Dehmeshki, Andreas Hoppe, Vikas Tah, Samantha Mann, Thomas H. Williamson, Sarah A. Barman
2014 J jnl
Comput. Methods Programs Biomed.
R. A. Welikala, Jamshid Dehmeshki, Andreas Hoppe, Vikas Tah, Samantha Mann, Thomas H. Williamson, Sarah Barman
2014 conf
MIE
Jamshid Dehmeshki, Adina Ion, Tim J. Ellis, Francesco Doenz, Anne-Marie Jouannic, Salah Dine Qanadli
2014 conf
ICDIP
Maryam Hajiesmaeili, Jamshid Dehmeshki, Bashir Bagheri Nakhjavanlo, Tim Ellis
2014 J jnl
J. Math. Imaging Vis.
Reza Aghayan, Tim Ellis, Jamshid Dehmeshki
2013 C conf
ISPA
Alireza Nikravanshalmani, Mojdeh Karamimohammdi, Jamshid Dehmeshki
2012 J jnl
IEEE Trans. Fuzzy Syst.
Rahil Hosseini, Salah Dine Qanadli, Sarah Barman, Mahdi Mazinani, Tim Ellis, Jamshid Dehmeshki
2012 conf
ISVC (1)
Maryam Hajiesmaeili, Bashir Bagherinakhjavanlo, Jamshid Dehmeshki, Tim Ellis
2011 conf
SITIS
Bashir Bagheri Nakhjavanlo, Tim J. Ellis, P. H. Soan, Jamshid Dehmeshki
2011 conf
DSP
Yousef Ebrahimdoost, Salah Dine Qanadli, Alireza Nikravanshalmani, Tim J. Ellis, Zahra Falah Shojaee, Jamshid Dehmeshki
2010 conf
IPCV
Yousef Ebrahimdoost, Jamshid Dehmeshki, Tim J. Ellis, Mohsen Firoozbakht, Salah Dine Qanadli
2010 C conf
ICDS
Rahil Hosseini, Jamshid Dehmeshki, Sarah Barman, Mahdi Mazinani, Anne-Marie Jouannic, Salah Dine Qanadli
2010 B conf
FUZZ-IEEE
Rahil Hosseini, Jamshid Dehmeshki, Sarah Barman, Mahdi Mazinani, Salah Dine Qanadli
2010 conf
Computer-Aided Diagnosis
F. Ferreira, Jamshid Dehmeshki, Hamdan Amin, Mandana Ebadian Dehkordi, A. Belli, Anne-Marie Jouannic, Salah Dine Qanadli
2010 C conf
ICDS
Adina Ion, Jamshid Dehmeshki, Hamdan Amin, A. Jouannic, Salah Dine Qanadli
2010 C conf
ICDS
Mahdi Mazinani, Jamshid Dehmeshki, Rahil Hosseini, Tim Ellis, Salah Dine Qanadli
2010 C conf
ICDS
Mohsen Firoozbakht, Jamshid Dehmeshki, M. Martini, Yousef Ebrahimdoost, Hamdan Amin, Mandana Ebadian Dehkordi, A. Youannic, Salah Dine Qanadli
2010 C conf
ICDS
Yousef Ebrahimdoost, Jamshid Dehmeshki, T. S. Ellis, Mohsen Firoozbakht, A. Youannic, Salah Dine Qanadli
2010 conf
Computer-Aided Diagnosis
Rahil Hosseini, Jamshid Dehmeshki, Sarah Barman, Mahdi Mazinani, Salah Dine Qanadli
2009 C conf
ICDS
Jamshid Dehmeshki, Hamdan Amin, M. Ebadian-Dehkordi, Anne-Marie Jouannic, Salah Dine Qanadli
2009 J jnl
IEEE Trans. Biomed. Eng.
Xujiong Ye, Xinyu Lin, Jamshid Dehmeshki, Greg G. Slabaugh, Gareth Beddoe
2008 J jnl
IEEE Trans. Medical Imaging
Jamshid Dehmeshki, Hamdan Amin, Manlio Valdivieso Casique, Xujiong Ye
2007 J jnl
Comput. Medical Imaging Graph.
Jamshid Dehmeshki, Xujiong Ye, Xinyu Lin, Manlio Valdivieso Casique, Hamdan Amin
2007 J jnl
IEEE Trans. Medical Imaging
Jamshid Dehmeshki, Xujiong Ye, Hamdan Amin, Maryam Abaei, Xinyu Lin, Salah Dine Qanadli
2006 conf
ISBI
Jamshid Dehmeshki, Xujiong Ye, Manlio Valdivieso Casique, Xinyu Lin
2004 B conf
Image Processing
Jamshid Dehmeshki, Hamdan Amin, Wing Wong, Mandana Ebadian Dehkordi, Nahid Kamangari, Mary Roddie, John Costello
2004 B conf
Image Processing
Jamshid Dehmeshki, Musib Siddique, Wing Wong, Irina Chis Ster
2003 conf
MLDM
Jamshid Dehmeshki, Mustafa Karaköy, Manlio Valdivieso Casique
2003 conf
ICIP (1)
Jamshid Dehmeshki, Xujiong Ye, John Costello
1999 J jnl
Pattern Recognit. Lett.
Jamshid Dehmeshki
1998 conf
Electronic Imaging
F. N. Hatfield, Jamshid Dehmeshki
1998 conf
Electronic Imaging
Jamshid Dehmeshki, F. N. Hatfield
redb/extractors/js_extractors/js_deobfuscator.py
← Index redb/extractors/js_extractors/js_deobfuscator.py python
"""Subprocess-driven JavaScript deobfuscator with jsbeautifier fallback.

Owns the heavy lifting that was previously embedded inside
`JSDeobfuscationExtractor` (`_run_deobfuscator` + `_try_jsbeautifier`). Exposed
as a single module-level entry point `deobfuscate(source, log)` so it can be
called from `JSContext.deobfuscated` (cached per sample) without dragging
extractor state through the call.

Configuration (env vars):
    JS_DEOBFUSCATOR_PATH    Path or name of the external tool (default: webcrack).
    JS_DEOBFUSCATE_TIMEOUT  Seconds before the external tool is killed
                            (process-group SIGTERM, then SIGKILL). Default: 60.

If the external tool produces non-empty output and exits 0, that wins. Otherwise
the source is run through jsbeautifier (which only normalises formatting, but
already exposes strings hidden by minification). If neither path produces
output, returns (None, None).

`FileNotFoundError` for the external tool is treated as routine — the analysis
server is either provisioned with the tool or it isn't — and demoted to a
debug-level log.
"""

import os
import signal
import subprocess
import tempfile
from typing import Optional, Tuple

DEFAULT_DEOBFUSCATOR = "webcrack"
DEFAULT_TIMEOUT_SECS = 60


def _run_external(
    source: str, deobfuscator_path: str, timeout: int, log
) -> Tuple[Optional[str], int]:
    """Run the configured external deobfuscator over `source` and capture stdout.

    Returns (text, returncode). `text` is `None` and `returncode` is `-1` when
    the binary is missing, the run timed out, or any other unexpected failure
    occurred. Missing-binary is logged at debug; timeouts and unexpected errors
    surface at warning/error.
    """
    try:
        with tempfile.NamedTemporaryFile(
            suffix=".js", mode="w", delete=False, encoding="utf-8"
        ) as tmp:
            tmp.write(source)
            tmp_path = tmp.name

        try:
            process = subprocess.Popen(
                [deobfuscator_path, tmp_path],
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                preexec_fn=os.setsid,
            )

            try:
                stdout, _ = process.communicate(timeout=timeout)
                return stdout.decode("utf-8", errors="replace"), process.returncode
            except subprocess.TimeoutExpired:
                # Kill the entire process group so spawned helpers (e.g. node
                # subprocesses webcrack itself launches) get cleaned up too.
                try:
                    os.killpg(os.getpgid(process.pid), signal.SIGTERM)
                    process.wait(timeout=5)
                except Exception:
                    try:
                        os.killpg(os.getpgid(process.pid), signal.SIGKILL)
                    except Exception:
                        pass
                log.warning(f"Deobfuscation timed out after {timeout}s")
                return None, -1
        finally:
            try:
                os.unlink(tmp_path)
            except Exception:
                pass
    except FileNotFoundError:
        log.debug(f"Deobfuscator binary not found at {deobfuscator_path}")
        return None, -1
    except Exception as e:
        log.error(f"Error running deobfuscator: {e}")
        return None, -1


def _try_jsbeautifier(source: str, log) -> Tuple[Optional[str], Optional[str]]:
    """Fallback path: format the source with jsbeautifier. Returns
    `(text, "jsbeautifier")` or `(None, None)` if jsbeautifier isn't installed
    or the call raised."""
    try:
        import jsbeautifier
        opts = jsbeautifier.default_options()
        opts.indent_size = 2
        return jsbeautifier.beautify(source, opts), "jsbeautifier"
    except ImportError:
        log.debug("jsbeautifier not available")
        return None, None
    except Exception as e:
        log.warning(f"jsbeautifier failed: {e}")
        return None, None


def deobfuscate(source: str, log) -> Tuple[Optional[str], Optional[str]]:
    """Run the configured external deobfuscator, falling back to jsbeautifier.

    Returns `(text, normalizer_used)` on success, or `(None, None)` when neither
    path produced non-empty output. `normalizer_used` is the basename of the
    external tool (e.g. `"webcrack"`) or the literal `"jsbeautifier"`.
    """
    if not source:
        return None, None

    deobfuscator_path = os.getenv("JS_DEOBFUSCATOR_PATH", DEFAULT_DEOBFUSCATOR)
    timeout = int(os.getenv("JS_DEOBFUSCATE_TIMEOUT", str(DEFAULT_TIMEOUT_SECS)))

    text, returncode = _run_external(source, deobfuscator_path, timeout, log)
    if text and returncode == 0 and text.strip():
        return text, os.path.basename(deobfuscator_path)

    return _try_jsbeautifier(source, log)