Isabelle M. Demeure

48 papers A* 1A 1B 5C 3Misc 1Journal 7Unranked 29
YearRankTypeTitle / Venue / Authors
2015 J jnl
ACM Trans. Auton. Adapt. Syst.
Sylvain Frey, Ada Diaconescu, David Menga, Isabelle M. Demeure
2014 conf
UbiComp Adjunct
Robin Despouys, Rémi Sharrock, Isabelle M. Demeure
2013 conf
SASO
Sylvain Frey, Ada Diaconescu, David Menga, Isabelle M. Demeure
2013 J jnl
ACM Comput. Surv.
Xavier Grehant, Isabelle M. Demeure, Sverre Jarp
2013 B conf
ICPP
Ruijing Hu, Julien Sopena, Luciana Arantes, Pierre Sens, Isabelle M. Demeure
2013 conf
SASO Workshops
Sylvain Frey, Ada Diaconescu, David Menga, Isabelle M. Demeure
2013 conf
ITST
Sébastien Faye, Claude Chaudet, Isabelle M. Demeure
2013 conf
WIMS
B. Helena Rodriguez, Jean-Claude Moissinac, Isabelle M. Demeure
2013 conf
ICAC
Sylvain Frey, Ada Diaconescu, David Menga, Isabelle M. Demeure
2012 conf
ITSC
Sébastien Faye, Claude Chaudet, Isabelle M. Demeure
2012 conf
UrBaNe@CoNEXT
Sébastien Faye, Claude Chaudet, Isabelle M. Demeure
2012 conf
WONS
Claude Chaudet, Isabelle M. Demeure, Salma Ktari
2012 B conf
SECON
Claude Chaudet, Nicola Costagliola, Isabelle M. Demeure, Salma Ktari, Samuel Tardieu
2012 B conf
SRDS
Ruijing Hu, Julien Sopena, Luciana Arantes, Pierre Sens, Isabelle M. Demeure
2012 conf
SMARTGREENS
Sylvain Frey, François Huguet, Cédric Mivielle, David Menga, Ada Diaconescu, Isabelle M. Demeure
2012 conf
CFIP/NOTERE (Sélection)
Sébastien Faye, Claude Chaudet, Isabelle M. Demeure
2011 ed.
NOTERE
Isabelle M. Demeure, Thomas Robert, Ahmed Serhrouchni
2011 conf
AINTEC
Claude Chaudet, Isabelle M. Demeure, Salma Ktari, Nicola Costagliola, Samuel Tardieu
2010 J jnl
Mob. Networks Appl.
Amir R. Khakpour, Isabelle M. Demeure
2010 J jnl
Multim. Syst.
Annie Gentes, Aude Guyot-Mbodji, Isabelle M. Demeure
2010 conf
MobiCASE
Hoa Dung Ha Duong, Isabelle M. Demeure
2010 C conf
iiWAS
B. Helena Rodriguez, Jean-Claude Moissinac, Isabelle M. Demeure
2009 conf
CTS
Hoa Ha Duong, Isabelle M. Demeure
2009 conf
MOBILWARE
Amir R. Khakpour, Isabelle M. Demeure
2009 J jnl
Serv. Oriented Comput. Appl.
Juan A. Botía Blaya, Isabelle M. Demeure, Paolo Gianrossi, Pedro García López, Juan Antonio Martínez Navarro, Eike Michael Meyer, Patrizio Pelliccione, Frédérique Tastet-Cherel
2009 conf
MOBILWARE
Hoa Ha Duong, Isabelle M. Demeure
2009 A conf
IPDPS
Xavier Grehant, Isabelle M. Demeure
2008 C conf
WETICE
Juan A. Botía Blaya, Antonio Fernandez Gómez-Skarmeta, Hoa Ha Doung, Isabelle M. Demeure
2008 conf
NOTERE
Guilhem Paroux, Isabelle M. Demeure, Laurent Reynaud
2008 conf
NOTERE
Hoa Ha Duong, Isabelle M. Demeure
2008 conf
MindTrek
Annie Gentes, Aude Guyot-Mbodji, Isabelle M. Demeure
2008 B conf
PIMRC
Ludovic Martin, Isabelle M. Demeure
2008 conf
CTS
Isabelle M. Demeure, Annie Gentes, Julien Stuyck, Aude Guyot-Mbodji, Ludovic Martin
2008 conf
NOTERE
Ludovic Martin, Isabelle M. Demeure
2007 conf
Euro-Par Workshops
Xavier Grehant, Olivier Pernet, Sverre Jarp, Isabelle M. Demeure, Peter Toft
2006 J jnl
ACM SIGMOBILE Mob. Comput. Commun. Rev.
Ivan Ganchev, Mairtin O'Droma, Matthias Siebert, Faouzi Bader, Hakima Chaouchi, Ivan Armuelles Voinov, Isabelle M. Demeure, Fintan McEvoy
2005 conf
UbiMob
Eric Lecolinet, Claudie Faure, Isabelle M. Demeure, Jean-Claude Moissinac, Stuart Pook
2005 conf
DFMA
Isabelle M. Demeure, Claudie Faure, Eric Lecolinet, Jean-Claude Moissinac, Stuart Pook
2004 conf
UbiMob
Zakia Kazi-Aoul, Isabelle M. Demeure, Jean-Claude Moissinac
2003 C ed.
DAIS
Jean-Bernard Stefani, Isabelle M. Demeure, Daniel Hagimont
2003 conf
EUSAI
Paul Simons, Yacine Ghamri-Doudane, Sidi-Mohammed Senouci, Farid Bachiri, Anelise Munaretto, Jouko Kaasila, Gwendal Le Grand, Isabelle M. Demeure
2002 conf
MWCN
Ouahiba Fouial, Nadia Boukhatem, Isabelle M. Demeure
2001 B conf
OPODIS
Ouahiba Fouial, Nadia Boukhatem, Isabelle M. Demeure
1996 conf
EUROMICRO
Jocelyne Farhat-Gissler, Isabelle M. Demeure
1994 J jnl
J. Parallel Distributed Comput.
Isabelle M. Demeure, Gary J. Nutt
1992 A* conf
INFOCOM
P. Vittali, Isabelle M. Demeure, Noëmie Simoni, A. Hafner
1989 conf
PP
Isabelle M. Demeure, Sharon L. Smith, Gary J. Nutt
1989 Misc conf
WSC
Gary J. Nutt, Adam Beguelin, Isabelle M. Demeure, R. Stephen Elliot, Jeffrey D. McWhirter
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 "";
        }
    }
}