Victor M. Larios-Rosillo

33 papers B 1Journal 7Unranked 22
YearRankTypeTitle / Venue / Authors
2021 conf
ISC2
Mario E. Vallejo, Victor M. Larios-Rosillo, Verónica Gutiérrez Magallanes, Cecilia Cobian, María de la Luz Guzmán Castañeda, Guillermo Balandrán Téllez
2021 J jnl
IEEE Trans. Engineering Management
Olga B. Mora Sánchez, Emmanuel López-Neri, E. Julieta Cedillo-Elias, Emmanuel Aceves-Martínez, Victor M. Larios-Rosillo
2020 conf
ISC2
Ángel Ruiz-Zafra, Janet Pigueiras, Andrés Millan-Alcaide, Victor M. Larios-Rosillo, Ma. Roció Maciel Arellano
2020 conf
ISC2
Neale A. Smith, Adriana I. Camacho, Edgar J. Escobedo, Jonatan M. Contreras, Oscar Mondragon, Natalia Villanueva-Rosales, Ruey Long Cheu, Victor M. Larios-Rosillo
2020 conf
ISC2
Ramon A. Briseño, Juan C. López, Ma. Roció Maciel Arellano, Victor M. Larios-Rosillo, Jesús Raul Beltrán-Ramírez, Carlos López-Zaragoza
2020 J jnl
IET Softw.
Elsa Estrada, Ma. Roció Maciel Arellano, Adriana Peña Pérez Negrón, Graciela Lara-López, Victor M. Larios-Rosillo, Alberto Ochoa
2020 conf
ISC2
Victor M. Garcia, Ruth P. Granados, Mario E. Medina, Luis Ochoa, Oscar A. Mondragon, Ruey Long Cheu, Natalia Villanueva-Rosales, Victor M. Larios-Rosillo
2020 J jnl
Res. Comput. Sci.
Ramon A. Briseño, Juan C. López, Ma. Roció Maciel Arellano, Victor M. Larios-Rosillo, J. Raul Beltrán, Jose Antonio Orizaga Trejo
2019 J jnl
Res. Comput. Sci.
César Lozano Díaz, Adriana Lorena Iñiguez-Carrillo, Ma. Roció Maciel Arellano, Victor M. Larios-Rosillo, Emmanuel Aceves, Alberto Ochoa, Edgar Cossio
2019 conf
ISC2
E. Julieta Cedillo-Elias, Victor M. Larios-Rosillo, Jose Antonio Orizaga Trejo, Carlos E. Lomas-Moreno, J. Raul Beltrán-Ramírez, Ma. Roció Maciel Arellano
2019 conf
ISC2
Dessislava Petrova-Antonova, Olga B. Mora Sánchez, Victor M. Larios-Rosillo, Mónica M. Zuluaga Ramirez
2019 conf
ISC2
Victor M. Larios-Rosillo, Rasmus Michaelson, Ari Virtanen, Jalmari Talola, Ma. Roció Maciel Arellano, J. Raul Beltrán
2019 conf
ISC2
Cecilia E. Ramírez, Juan Manuel Viveros Paredes, Edgardo Flores Torales, Héctor Pérez Ladrón de Guevara, Jorge Iván Delgado Saucedo, Juan Manuel Riestra Castañeda, Abel Hurtado Macías, Jesús Máximo Montes, Jorge Valente López Arellano, Alfredo Rodríguez, Karen Esmonde-White, Martha Z. Vardaki, Victor M. Larios-Rosillo
2019 conf
ISC2
Lina Patrica Zapata, Marco Flores, Victor M. Larios-Rosillo, Ma. Roció Maciel Arellano, Enrique Arias-Antúnez
2019 conf
ISC2
Luis Holguin, Alberto Ochoa-Zezzatti, Victor M. Larios-Rosillo, Edgar Cossio, Ma. Roció Maciel Arellano, Gilberto Rivera Zárate
2019 conf
ISC2
Jesús Máximo Montes, Cecilia E. Ramírez, Manuel Coronado Gutierrez, Victor M. Larios-Rosillo
2019 conf
ISC2
Carlos V. Chavez, Emiliano Ruiz, Adrian Gomez Rodriguez, Itzel Rivas Pena, Victor M. Larios-Rosillo, Natalia Villanueva-Rosales, Oscar Mondragon, Ruey Long Cheu
2019 conf
ISC2
Ubaldo Castro, Jonathan Avila, Cynthia V. Sustaita, M. Armando Hernandez, Victor M. Larios-Rosillo, Natalia Villanueva-Rosales, Oscar Mondragon, Ruey Long Cheu, Ma. Roció Maciel Arellano
2018 J jnl
Int. J. Comb. Optim. Probl. Informatics
Elsa Estrada, Ma. del Rocio Boone Rojas, Carlos Alberto Ochoa Ortíz Zezzatti, María Beatríz Bernábe-Loranca, Diego Oliva, Victor M. Larios-Rosillo
2018 conf
ISC2
E. Julieta Cedillo-Elias, Jose Antonio Orizaga Trejo, Victor M. Larios-Rosillo, L. Alberto Maciel Arellano
2018 J jnl
Proc. IEEE
Gilles Betis, Victor M. Larios-Rosillo, Dario Petri, Xiaojun Wu, Aaron Deacon, Aawatif Hayar
2016 conf
ISC2
Gonzalo R. Ceballos, Victor M. Larios-Rosillo
2016 conf
ISC2
Victor M. Larios-Rosillo, Leopoldo Gomez, Olga B. Mora, Ma. Roció Maciel Arellano, Natalia Villanueva-Rosales
2016 conf
ISC2
Natalia Villanueva-Rosales, Luis Garnica Chavira, Victor M. Larios-Rosillo, Leopoldo Gomez, Emmanuel Aceves
2016 conf
ISC2
Manuel Avalos, Pablo Salazar, Victor M. Larios-Rosillo, Hector A. Duran-Limon
2016 conf
ISC2
Maya Alba, Manuel Avalos, Carlos Guzman, Victor M. Larios-Rosillo
2015 conf
ISC2
Natalia Villanueva-Rosales, Ruey Long Cheu, Ann Q. Gates, Norma Rivera, Oscar Mondragon, Sergio D. Cabrera, Carlos Ferregut, César Carrasco, Soheil Nazarian, Heidi A. Taboada, Victor M. Larios-Rosillo, Liliana Ibeth Barbosa-Santillán, Miroslav Svitek, Ondrej Pribyl, Tomas Horak, Dana Procházková
2012 J jnl
Int. J. Game Based Learn.
César García-García, José Luis Fernández-Robles, Victor M. Larios-Rosillo, Hervé Luga
2006 ed.
IICS
Thomas Böhme, Victor M. Larios-Rosillo, Helena Unger, Herwig Unger
2005 ed.
ISSADS
Félix F. Ramos Corchado, Victor M. Larios-Rosillo, Herwig Unger
2004 ed.
ISSADS
Félix F. Ramos, Herwig Unger, Victor M. Larios-Rosillo
2002 B conf
OPODIS
Nicandro Farías Mendoza, Félix F. Ramos Corchado, Victor M. Larios-Rosillo
2000 conf
DCW
Marc Bui, Victor M. Larios-Rosillo
redb/extractors/decompiler/_archive/GhidraDecompilerScript-latest.java
← Index redb/extractors/decompiler/_archive/GhidraDecompilerScript-latest.java java
import ghidra.app.script.GhidraScript;
import ghidra.program.model.listing.*;
import ghidra.app.decompiler.*;
import ghidra.program.model.block.*;
import ghidra.program.model.symbol.*;
import ghidra.program.model.pcode.*;
import ghidra.program.model.address.*;
import org.json.JSONObject;
import org.json.JSONArray;
import java.security.MessageDigest;
import java.nio.charset.StandardCharsets;

public class GhidraDecompilerScript extends GhidraScript {
    private DecompInterface decompInterface;
    private BasicBlockModel basicBlockModel;
    
    @Override
    public void run() throws Exception {
        // Get binary hash and filepath from arguments
        String[] args = getScriptArgs();
        if (args.length < 2) {
            System.err.println("{\"error\": \"Both SHA256 and filepath arguments are required\"}");
            return;
        }
        String sha256 = args[0];
        String filepath = args[1];

        // Initialize analysis components
        setupDecompiler();
        basicBlockModel = new BasicBlockModel(currentProgram);

        // Create the main JSON object for output
        JSONObject output = new JSONObject();
        output.put("sha256", sha256);
        output.put("decompiled", new JSONArray());
        output.put("disassembled", new JSONArray());
        output.put("cfg", new JSONArray());

        // Process all functions
        FunctionIterator functions = currentProgram.getFunctionManager().getFunctions(true);
        for (Function function : functions) {
            processFunction(function, output);
        }

        // Output the final JSON to stdout
        System.out.println(output.toString());
    }

    private void setupDecompiler() {
        decompInterface = new DecompInterface();
        DecompileOptions options = new DecompileOptions();
        decompInterface.setOptions(options);
        decompInterface.openProgram(currentProgram);
    }

    private void processFunction(Function function, JSONObject output) {
        Address entry = function.getEntryPoint();
        String functionName = function.getName();
        String functionAddress = entry.toString();

        // Process decompiled code
        processDecompiledCode(function, output.getJSONArray("decompiled"), 
                            functionName, functionAddress);

        // Process disassembled code
        processDisassembledCode(function, output.getJSONArray("disassembled"), 
                              functionName, functionAddress);

        // Process CFG
        processCFG(function, output.getJSONArray("cfg"), functionAddress);
    }

    private void processDecompiledCode(Function function, JSONArray decompArray, 
                                     String functionName, String functionAddress) {
        DecompileResults results = decompInterface.decompileFunction(function, 30, monitor);
        if (results.decompileCompleted()) {
            String decompiledCode = results.getDecompiledFunction().getC();
            String contentHash = calculateHash(decompiledCode);

            JSONObject functionObj = new JSONObject();
            functionObj.put("decompiled_content_hash", contentHash);
            functionObj.put("decompiled_function_name", functionName);
            functionObj.put("decompiled_function_address", functionAddress);
            functionObj.put("decompiled_function", decompiledCode);
            
            decompArray.put(functionObj);
        }
    }

    private void processDisassembledCode(Function function, JSONArray disasmArray, 
                                       String functionName, String functionAddress) {
        try {
            StringBuilder disassembly = new StringBuilder();
            StringBuilder normalized = new StringBuilder();
            int instructionCount = 0;

            Listing listing = currentProgram.getListing();
            AddressSetView functionBody = function.getBody();
            InstructionIterator instructions = listing.getInstructions(functionBody, true);

            while (instructions.hasNext()) {
                try {
                    Instruction instr = instructions.next();
                    String disasmLine = instr.toString();
                    disassembly.append(disasmLine).append("\n");
                    normalized.append(normalizeInstruction(disasmLine)).append("\n");
                    instructionCount++;
                } catch (Exception e) {
                    System.err.println("Error processing instruction in " + functionName + ": " + e.getMessage());
                }
            }

            String disassembledCode = disassembly.toString();
            String contentHash = calculateHash(disassembledCode);

            JSONObject functionObj = new JSONObject();
            functionObj.put("disassembled_content_hash", contentHash);
            functionObj.put("disassembled_function_name", functionName);
            functionObj.put("disassembled_function_address", functionAddress);
            functionObj.put("disassembled_function", disassembledCode);
            functionObj.put("normalized_disassembly", normalized.toString());
            functionObj.put("instruction_count", instructionCount);

            // Set similarity-related fields to null for now
            functionObj.put("minhash_signature", JSONObject.NULL);
            functionObj.put("opcode_frequency_vector", JSONObject.NULL);
            functionObj.put("api_calls_vector", JSONObject.NULL);
            functionObj.put("instruction_embedding", JSONObject.NULL);

            disasmArray.put(functionObj);
        } catch (Exception e) {
            System.err.println("Error processing disassembly for " + functionName + ": " + e.getMessage());
        }
    }

    private void processCFG(Function function, JSONArray cfgArray, String functionAddress) {
        try {
            CodeBlockIterator blocks = basicBlockModel.getCodeBlocksContaining(
                function.getBody(), monitor);

            while (blocks.hasNext()) {
                CodeBlock block = blocks.next();
                String blockInstructions = getBlockInstructions(block);
                String blockId = calculateHash(blockInstructions);

                JSONObject blockObj = new JSONObject();
                blockObj.put("block_id", blockId);
                blockObj.put("function_address", functionAddress);
                blockObj.put("block_instructions", blockInstructions);

                // Get successor blocks
                CodeBlockReferenceIterator successors = block.getDestinations(monitor);
                JSONArray successorAddresses = new JSONArray();
                while (successors.hasNext()) {
                    CodeBlockReference ref = successors.next();
                    successorAddresses.put(ref.getDestinationAddress().toString());
                }
                blockObj.put("successor_blocks", successorAddresses);

                cfgArray.put(blockObj);
            }
        } catch (Exception e) {
            System.err.println("{\"error\": \"Error processing CFG: " + 
                             e.getMessage().replace("\"", "'") + "\"}");
        }
    }

    private String normalizeInstruction(String instruction) {
        return instruction.replaceAll("0x[0-9a-fA-F]+", "IMM")
                        .replaceAll("\\b\\d+\\b", "NUM");
    }

    private String getBlockInstructions(CodeBlock block) {
        StringBuilder instructions = new StringBuilder();
        AddressIterator addresses = block.getAddresses(true);
        while (addresses.hasNext()) {
            Address addr = addresses.next();
            Instruction instr = currentProgram.getListing().getInstructionAt(addr);
            if (instr != null) {
                instructions.append(instr.toString()).append("\n");
            }
        }
        return instructions.toString();
    }

    private String calculateHash(String content) {
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-256");
            byte[] hash = digest.digest(content.getBytes(StandardCharsets.UTF_8));
            StringBuilder hexString = new StringBuilder();
            for (byte b : hash) {
                hexString.append(String.format("%02x", b));
            }
            return hexString.toString();
        } catch (Exception e) {
            System.err.println("{\"error\": \"Error calculating hash\"}");
            return "";
        }
    }
}