Rafael Castro-Linares

38 papers C 5Journal 14Unranked 19
YearRankTypeTitle / Venue / Authors
2025 J jnl
Int. J. Control
Adrian Humberto Martinez-Vasquez, Rafael Castro-Linares, Hebertt Sira-Ramírez
2021 conf
CCE
J. Lagunas-Avila, Rafael Castro-Linares, Jaime Álvarez-Gallegos
2021 J jnl
J. Intell. Robotic Syst.
C. Mauricio Arteaga-Escamilla, Rafael Castro-Linares, Jaime Álvarez-Gallegos
2020 J jnl
Algorithms
Abraham Efraim Rodriguez-Mata, Ricardo Luna, José Ricardo Pérez-Correa, Víctor Alejandro González-Huitrón, Rafael Castro-Linares, Manuel A. Duarte-Mermoud
2020 conf
CCE
José Ignacio Aguilar Pérez, Rafael Castro-Linares, Manuel A. Duarte-Mermoud
2020 conf
CCE
Adrian Humberto Martinez-Vasquez, Rafael Castro-Linares, Abraham Efraim Rodriguez-Mata
2019 conf
CCE
Jaime Álvarez-Gallegos, Rafael Castro-Linares, M. A. Zempoalteca-Jimenez
2018 J jnl
Algorithms
Arturo Govea-Vargas, Rafael Castro-Linares, Manuel A. Duarte-Mermoud, Norelys Aguila-Camacho, Gustavo E. Ceballos-Benavides
2018 J jnl
Algorithms
Manuel A. Duarte-Mermoud, Javier A. Gallegos, Norelys Aguila-Camacho, Rafael Castro-Linares
2018 J jnl
J. Frankl. Inst.
Javier A. Gallegos, Manuel A. Duarte-Mermoud, Rafael Castro-Linares
2015 conf
CCE
C. Mitre-Arreguin, Rafael Castro-Linares, Martín Velasco-Villa, Manuel Duarte-Mermoud
2015 J jnl
Syst. Control. Lett.
Javier A. Gallegos, Manuel A. Duarte-Mermoud, Norelys Aguila-Camacho, Rafael Castro-Linares
2015 J jnl
Int. J. Robotics Autom.
Francisco Rosales-Hernández, Martín Velasco-Villa, Rafael Castro-Linares, Basilio Del-Muro-Cuéllar, Miguel Angel Hernandez Perez
2015 conf
SyRoCo
M. A. Vallejo-Alarcón, Rafael Castro-Linares, Martín Velasco-Villa
2015 J jnl
Commun. Nonlinear Sci. Numer. Simul.
Manuel A. Duarte-Mermoud, Norelys Aguila-Camacho, Javier A. Gallegos, Rafael Castro-Linares
2014 J jnl
J. Intell. Robotic Syst.
José Gerardo Benítez Morales, Hugo Rodríguez-Cortés, Rafael Castro-Linares
2013 J jnl
J. Frankl. Inst.
Martín Velasco-Villa, Rafael Castro-Linares, Francisco Rosales-Hernández, Basilio Del-Muro-Cuéllar, Miguel Angel Hernandez Perez
2013 conf
ECC
José Gerardo Benítez Morales, Hugo Rodríguez-Cortés, Rafael Castro-Linares
2013 C conf
ACC
Mario Ramirez-Neria, José L. García-Antonio, Hebertt Sira-Ramírez, Martín Velasco-Villa, Rafael Castro-Linares
2011 conf
ICCA
Juan Fernando Peza-Solís, Rafael Castro-Linares, Gerardo Silva-Navarro
2011 conf
CCE
Juan Fernando Peza-Solís, Gerardo Silva-Navarro, Rafael Castro-Linares
2011 conf
ICCA
José L. García-Antonio, Rafael Castro-Linares, Martín Velasco-Villa
2010 conf
CCE
Juan Fernando Peza-Solís, Gerardo Silva-Navarro, Rafael Castro-Linares
2010 conf
CDC
Hebertt Sira-Ramírez, Rafael Castro-Linares
2009 J jnl
Computación y Sistemas
Juan Fernando Peza-Solís, Gerardo Silva-Navarro, Rafael Castro-Linares
2007 conf
ICINCO-SPSMC
Rafael Castro-Linares, Alain Glumineau
2005 conf
CDC/ECC
Rafael Castro-Linares, David Estrada-Duran
2005 C conf
ICINCO
E. Alvarez-Sanchez, Jaime Álvarez-Gallegos, Rafael Castro-Linares
2005 C conf
CCA
Rafael Castro-Linares, Eduardo Licéaga-Castro, José Gerardo Benítez Morales
2003 conf
ECC
Rafael Castro-Linares, Jaime Álvarez-Gallegos, E. Alvarez-Sanchez
2002 C conf
ACC
V. Vasquez-Lopez, Rafael Castro-Linares, Jaime Álvarez-Gallegos
2001 conf
CDC
Jesús de León-Morales, Rafael Castro-Linares, Jaime Álvarez-Gallegos, J. M. Mendivil-Avila
2000 C conf
ACC
Jesús de León-Morales, Rafael Castro-Linares, G. Acosta-Villarreal
2000 conf
CDC
J. Alfredo Rosas-Flores, Jaime Álvarez-Gallegos, Rafael Castro-Linares
2000 J jnl
IEEE Trans. Autom. Control.
Claude H. Moog, Rafael Castro-Linares, Martín Velasco-Villa, Luis Alejandro Marquez Martinez
1999 conf
ECC
Hebertt Sira-Ramírez, Rafael Castro-Linares
1999 conf
ECC
Rafael Castro-Linares, Wen Yu, Alexander S. Poznyak
1994 J jnl
IEEE Trans. Autom. Control.
Rafael Castro-Linares, Claude H. Moog
redb/s3_utils.py
← Index redb/s3_utils.py python
"""
S3 and file utility functions for REDB.

Contains MinIO/S3 client creation, S3 key generation,
file download, and archive extraction helpers.
"""
import os
import tempfile
from typing import Optional, List

from minio import Minio
from minio.error import S3Error


def get_minio_client():
    """Create and return a Minio client using credentials from .env file"""
    return Minio(
        endpoint=os.getenv("S3_ENDPOINT"),
        access_key=os.getenv("S3_ACCESS_KEY"),
        secret_key=os.getenv("S3_SECRET_KEY"),
        secure=os.getenv("S3_SECURE", "false").lower() == "true"
    )


def generate_s3_key_from_hash(sample_hash: str) -> str:
    """
    Generate S3 key from hash using sharding structure.
    Example: 09f7d02a3c2382199458c98a62b045145ee54ab6aba86166aecf3d10c3c1444c
    becomes: 09/f7/09f7d02a3c2382199458c98a62b045145ee54ab6aba86166aecf3d10c3c1444c.zip
    """
    if len(sample_hash) < 4:
        raise ValueError(f"Hash too short for sharding: {sample_hash}")

    # Create sharded path: first 2 chars / next 2 chars / full_hash.zip
    return f"{sample_hash[:2]}/{sample_hash[2:4]}/{sample_hash}.zip"


def download_s3_object(s3_bucket: str, s3_key: str, temp_dir: str, logger=None) -> Optional[str]:
    """
    Download an object from S3 to a local temporary directory and return the local path.
    If the .zip file is not found, automatically tries .7z as a fallback for legacy uploads.
    """
    try:
        minio_client = get_minio_client()
        local_path = os.path.join(temp_dir, os.path.basename(s3_key))

        # Download the file
        minio_client.fget_object(s3_bucket, s3_key, local_path)

        return local_path
    except S3Error as e:
        # If .zip not found and error is NoSuchKey, try .7z fallback
        if e.code == 'NoSuchKey' and s3_key.endswith('.zip'):
            s3_key_7z = s3_key[:-4] + '.7z'  # Replace .zip with .7z
            if logger:
                logger.info(f".zip not found, trying .7z fallback: {s3_key_7z}")
            try:
                local_path_7z = os.path.join(temp_dir, os.path.basename(s3_key_7z))
                minio_client.fget_object(s3_bucket, s3_key_7z, local_path_7z)
                if logger:
                    logger.info(f"Successfully downloaded .7z fallback: {s3_key_7z}")
                return local_path_7z
            except S3Error as e2:
                if logger:
                    logger.error(f"Failed to download S3 object {s3_key} (tried both .zip and .7z): {e2}")
                else:
                    print(f"[ERROR] Failed to download S3 object {s3_key} (tried both .zip and .7z): {e2}")
                return None
        else:
            if logger:
                logger.error(f"Failed to download S3 object {s3_key}: {e}")
            else:
                print(f"[ERROR] Failed to download S3 object {s3_key}: {e}")
            return None


def extract_fat_slices(macho, output_dir: str, logger) -> List[tuple]:
    """
    Extract slices from FAT Mach-O binary using machofile's dump_slices() API.

    Args:
        macho: Parsed machofile.UniversalMachO object
        output_dir: Directory to write slice files
        logger: Logger instance

    Returns:
        List of (arch_name, slice_path, slice_sha256, slice_md5, slice_sha1) tuples
    """
    result = []
    try:
        # Use machofile's dump_slices API (v2026.2.5+)
        slices = macho.dump_slices(output_dir=output_dir)
        logger.debug(f"Extracted {len(slices)} slices from FAT binary")

        for arch_name, slice_path in slices:
            # Get hash info for this slice from machofile
            general_info = macho.get_general_info(arch=arch_name)
            slice_sha256 = general_info.get('SHA256')
            slice_md5 = general_info.get('MD5')
            slice_sha1 = general_info.get('SHA1')
            result.append((arch_name, slice_path, slice_sha256, slice_md5, slice_sha1))
            logger.debug(f"Slice {arch_name}: {slice_sha256}")

    except Exception as e:
        logger.error(f"Error extracting FAT slices: {e}")

    return result