Kamal Berahmand

58 papers A* 2Journal 55Unranked 1
YearRankTypeTitle / Venue / Authors
2026 A* conf
WWW
Kamal Berahmand, Saman Forouzandeh, Mehrnoush Mohammadi, Parham Moradi, Mahdi Jalili
2026 J jnl
CoRR
Kamal Berahmand, Saman Forouzandeh, Mehrnoush Mohammadi, Parham Moradi, Mahdi Jalili
2026 J jnl
ACM Comput. Surv.
Farid Saberi-Movahed, Kamal Berahmand, Razieh Sheikhpour, Yuefeng Li, Shirui Pan, Mahdi Jalili
2026 J jnl
Pattern Recognit.
Razieh Sheikhpour, Farid Saberi-Movahed, Mahdi Jalili, Kamal Berahmand
2025 J jnl
ACM Trans. Intell. Syst. Technol.
Kamal Berahmand, Fatemeh Daneshfar, Maryam Rahmaninia, Maryam Haghighat, Mahdi Jalili
2025 J jnl
CoRR
Kamal Berahmand, Farid Saberi-Movahed, Razieh Sheikhpour, Yuefeng Li, Mahdi Jalili
2025 J jnl
Inf. Sci.
Mehrnoush Mohammadi, Kamal Berahmand, Saman Forouzandeh, Xujuan Zhou, Hassan Khosravi
2025 J jnl
Array
Kamal Berahmand, Xujuan Zhou, Yuefeng Li, Raj Gururajan, Prabal Datta Barua, U. Rajendra Acharya, Srinivas Kondalsamy-Chennakesavan
2025 A* conf
ICDM
Kamal Berahmand, Razieh Sheikhpour, Farid Saberi-Movahed, Mahdi Jalili
2025 J jnl
IEEE Trans. Artif. Intell.
Sajad Ahmadian, Kamal Berahmand, Mehrdad Rostami, Saman Forouzandeh, Parham Moradi, Mahdi Jalili
2025 J jnl
ACM Trans. Knowl. Discov. Data
Kamal Berahmand, Mehrnoush Mohammadi, Razieh Sheikhpour, Mahdi Jalili, Richi Nayak, Hassan Khosravi
2025 J jnl
Inf. Sci.
Razieh Sheikhpour, Mehrnoush Mohammadi, Kamal Berahmand, Farid Saberi-Movahed, Hassan Khosravi
2025 J jnl
IEEE Trans. Netw. Sci. Eng.
Mehrnoush Mohammadi, Kamal Berahmand, Shadi Azizi, Razieh Sheikhpour, Hassan Khosravi
2025 J jnl
Pattern Recognit.
Razieh Sheikhpour, Kamal Berahmand, Mehrnoush Mohammadi, Hassan Khosravi
2024 J jnl
IEEE Trans. Comput. Soc. Syst.
Kamal Berahmand, Yuefeng Li, Yue Xu
2024 J jnl
Neurocomputing
Mehrdad Rostami, Kamal Berahmand, Saman Forouzandeh, Sajad Ahmadian, Vahid Farrahi, Mourad Oussalah
2024 J jnl
Expert Syst. Appl.
Vahid Jannesari, Maryam Keshvari, Kamal Berahmand
2024 J jnl
Artif. Intell. Rev.
Kamal Berahmand, Fatemeh Daneshfar, Elaheh Sadat Salehi, Yuefeng Li, Yue Xu
2024 J jnl
Comput. Biol. Medicine
Saman Forouzandeh, Mehrdad Rostami, Kamal Berahmand, Razieh Sheikhpour
2024 J jnl
CoRR
Farid Saberi-Movahed, Kamal Berahmand, Razieh Sheikhpour, Yuefeng Li, Shirui Pan
2024 J jnl
IEEE Trans. Knowl. Data Eng.
Kamal Berahmand, Sondos Bahadori, Maryam Nooraei Abadeh, Yuefeng Li, Yue Xu
2024 J jnl
Eng. Appl. Artif. Intell.
Saman Forouzandeh, Kamal Berahmand, Mehrdad Rostami, Aliyeh Aminzadeh, Mourad Oussalah
2024 J jnl
Neurocomputing
Kamal Berahmand, Mehrnoush Mohammadi, Razieh Sheikhpour, Yuefeng Li, Yue Xu
2023 J jnl
Expert Syst. Appl.
Saman Forouzandeh, Kamal Berahmand, Razieh Sheikhpour, Yuefeng Li
2023 J jnl
J. Comb. Optim.
Wenjun Li, Ting Li, Kamal Berahmand
2023 J jnl
IEEE Access
Mehrdad Rostami, Mourad Oussalah, Kamal Berahmand, Vahid Farrahi
2023 J jnl
Neural Comput. Appl.
Kamal Berahmand, Yuefeng Li, Yue Xu
2023 J jnl
IEEE Trans. Netw. Sci. Eng.
Kamal Berahmand, Mehrnoush Mohammadi, Farid Saberi-Movahed, Yuefeng Li, Yue Xu
2023 J jnl
Knowl. Based Syst.
Razieh Sheikhpour, Kamal Berahmand, Saman Forouzandeh
2023 J jnl
J. Cloud Comput.
Soudabeh Hedayati, Neda Maleki, Tobias Olsson, Fredrik Ahlgren, Mahdi Seyednezhad, Kamal Berahmand
2023 J jnl
Multim. Tools Appl.
Elahe Nasiri, Kamal Berahmand, Yuefeng Li
2022 conf
KDIR
Merhrdad Rostami, Vahid Farahi, Kamal Berahmand, Saman Forouzandeh, Sajad Ahmadian, Mourad Oussalah
2022 J jnl
J. King Saud Univ. Comput. Inf. Sci.
Kamal Berahmand, Sogol Haghani, Mehrdad Rostami, Yuefeng Li
2022 J jnl
Clust. Comput.
Kamal Berahmand, Mehrnoush Mohammadi, Azadeh Faroughi, Rojiar Pir Mohammadiani
2022 J jnl
J. King Saud Univ. Comput. Inf. Sci.
Kamal Berahmand, Elahe Nasiri, Saman Forouzandeh, Yuefeng Li
2022 J jnl
Intell. Syst. Appl.
Mehrdad Rostami, Usman Muhammad, Saman Forouzandeh, Kamal Berahmand, Vahid Farrahi, Mourad Oussalah
2022 J jnl
Comput. Biol. Medicine
Farshad Saberi-Movahed, Mahyar Mohammadifard, Adel Mehrpooya, Mohammad Rezaei-Ravari, Kamal Berahmand, Mehrdad Rostami, Saeed Karami, Mohammad Najafzadeh, Davood Hajinezhad, Mina Jamshidi, Farshid Abedi, Mahtab Mohammadifard, Elnaz Farbod, Farinaz Safavi, Mohammadreza Dorvash, Negar Mottaghi-Dastjerdi, Shahrzad Vahedi, Mahdi Eftekhari, Farid Saberi-Movahed, Hamid Alinejad-Rokny, Shahab S. Band, Iman Tavassoly
2022 J jnl
Knowl. Based Syst.
Farid Saberi-Movahed, Mehrdad Rostami, Kamal Berahmand, Saeed Karami, Prayag Tiwari, Mourad Oussalah, Shahab S. Band
2022 J jnl
Artif. Intell. Medicine
Mehrdad Rostami, Saman Forouzandeh, Kamal Berahmand, Mina Soltani, Meisam Shahsavari, Mourad Oussalah
2022 J jnl
Comput. Biol. Medicine
Saeid Azadifar, Mehrdad Rostami, Kamal Berahmand, Parham Moradi, Mourad Oussalah
2022 J jnl
Big Data
Elahe Nasiri, Kamal Berahmand, Zeynab Samei, Yuefeng Li
2021 J jnl
Int. J. Inf. Technol. Decis. Mak.
Saman Forouzandeh, Kamal Berahmand, Elahe Nasiri, Mehrdad Rostami
2021 J jnl
CoRR
Kamal Berahmand, Elahe Nasiri, Saman Forouzandeh, Yuefeng Li
2021 J jnl
Computing
Kamal Berahmand, Elahe Nasiri, Mehrdad Rostami, Saman Forouzandeh
2021 J jnl
J. Big Data
Mehrdad Rostami, Kamal Berahmand, Saman Forouzandeh
2021 J jnl
Comput. Biol. Medicine
Elahe Nasiri, Kamal Berahmand, Mehrdad Rostami, Mohammad Dabiri
2021 J jnl
Eng. Appl. Artif. Intell.
Saman Forouzandeh, Mehrdad Rostami, Kamal Berahmand
2021 J jnl
Multim. Tools Appl.
Saman Forouzandeh, Kamal Berahmand, Mehrdad Rostami
2021 J jnl
Eng. Appl. Artif. Intell.
Mehrdad Rostami, Kamal Berahmand, Elahe Nasiri, Saman Forouzandeh
2021 J jnl
Comput. Biol. Medicine
Kamal Berahmand, Elahe Nasiri, Rojiar Pir Mohammadiani, Yuefeng Li
2020 J jnl
CoRR
Mehrdad Rostami, Kamal Berahmand, Saman Forouzandeh
2020 J jnl
J. Big Data
Mehrdad Rostami, Kamal Berahmand, Saman Forouzandeh
2020 J jnl
CoRR
Saman Forouzandeh, Mehrdad Rostami, Kamal Berahmand
2020 J jnl
CoRR
Saman Forouzandeh, Mehrdad Rostami, Kamal Berahmand
2020 J jnl
CoRR
Mehrdad Rostami, Kamal Berahmand, Saman Forouzandeh
2019 J jnl
J. Syst. Sci. Complex.
Kamal Berahmand, Asgarali Bouyer
2019 J jnl
Computing
Kamal Berahmand, Asgarali Bouyer, Negin Samadi
2018 J jnl
IEEE Trans. Comput. Soc. Syst.
Kamal Berahmand, Asgarali Bouyer, Mahdi Vasighi
redb/extractors/decompiler/_archive/GhidraDecompilerScript-v2.java
← Index redb/extractors/decompiler/_archive/GhidraDecompilerScript-v2.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 {
        System.err.println("{\"debug\": \"Script starting\"}");

        // 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];

        // Add debug output after setup
        System.err.println("{\"debug\": \"Processing file: " + 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);
        }

        System.err.println("{\"debug\": \"Preparing final 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) {
        try {
            Address entry = function.getEntryPoint();
            String functionName = function.getName();
            String functionAddress = entry.toString();

            // Process each analysis type independently
            boolean hasAnyResults = false;

            try {
                if (processDecompiledCode(function, output.getJSONArray("decompiled"),
                                        functionName, functionAddress)) {
                    hasAnyResults = true;
                }
            } catch (Exception e) {
                System.err.println(String.format(
                    "{\"error\": \"Decompilation failed for function %s: %s\"}",
                    functionName, e.getMessage().replace("\"", "'")));
            }

            try {
                if (processDisassembledCode(function, output.getJSONArray("disassembled"),
                                        functionName, functionAddress)) {
                    hasAnyResults = true;
                }
            } catch (Exception e) {
                System.err.println(String.format(
                    "{\"error\": \"Disassembly failed for function %s: %s\"}",
                    functionName, e.getMessage().replace("\"", "'")));
            }

            try {
                if (processCFG(function, output.getJSONArray("cfg"), functionAddress)) {
                    hasAnyResults = true;
                }
            } catch (Exception e) {
                System.err.println(String.format(
                    "{\"error\": \"CFG extraction failed for function %s: %s\"}",
                    functionName, e.getMessage().replace("\"", "'")));
            }

            if (!hasAnyResults) {
                System.err.println(String.format(
                    "{\"warning\": \"No results obtained for function %s\"}",
                    functionName));
            }

        } catch (Exception e) {
            System.err.println(String.format(
                "{\"error\": \"Failed to process function: %s\"}",
                e.getMessage().replace("\"", "'")));
        }
    }

    private boolean processDecompiledCode(Function function, JSONArray decompArray,
                                        String functionName, String functionAddress) {
        try {
            DecompileResults results = decompInterface.decompileFunction(function, 30, monitor);
            if (results == null || !results.decompileCompleted()) {
                System.err.println(String.format(
                    "{\"warning\": \"Decompilation incomplete for function %s\"}",
                    functionName));
                return false;
            }

            String decompiledCode = results.getDecompiledFunction().getC();
            if (decompiledCode == null || decompiledCode.trim().isEmpty()) {
                System.err.println(String.format(
                    "{\"warning\": \"Empty decompilation result for function %s\"}",
                    functionName));
                return false;
            }

            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);
            return true;

        } catch (Exception e) {
            throw new RuntimeException("Decompilation error: " + e.getMessage(), e);
        }
    }

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

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

            while (instructions.hasNext()) {
                try {
                    Instruction instr = instructions.next();
                    if (instr != null) {
                        String disasmLine = instr.toString();
                        if (disasmLine != null && !disasmLine.trim().isEmpty()) {
                            disassembly.append(disasmLine).append("\n");
                            normalized.append(normalizeInstruction(disasmLine)).append("\n");
                            instructionCount++;
                            hasValidInstructions = true;
                        }
                    }
                } catch (Exception e) {
                    System.err.println(String.format(
                        "{\"warning\": \"Skipped invalid instruction in %s: %s\"}",
                        functionName, e.getMessage().replace("\"", "'")));
                }
            }

            if (!hasValidInstructions) {
                System.err.println(String.format(
                    "{\"warning\": \"No valid instructions found in function %s\"}",
                    functionName));
                return false;
            }

            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);

            // Initialize similarity fields as null
            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);
            return true;

        } catch (Exception e) {
            throw new RuntimeException("Disassembly error: " + e.getMessage(), e);
        }
    }

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

            boolean hasValidBlocks = false;

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

                    if (blockInstructions == null || blockInstructions.trim().isEmpty()) {
                        continue;
                    }

                    String blockId = calculateHash(blockInstructions);

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

                    // Process successors with error handling
                    JSONArray successorAddresses = new JSONArray();
                    try {
                        CodeBlockReferenceIterator successors = block.getDestinations(monitor);
                        while (successors.hasNext()) {
                            try {
                                CodeBlockReference ref = successors.next();
                                if (ref != null && ref.getDestinationAddress() != null) {
                                    successorAddresses.put(ref.getDestinationAddress().toString());
                                }
                            } catch (Exception e) {
                                System.err.println(String.format(
                                    "{\"warning\": \"Skipped invalid successor in block %s: %s\"}",
                                    blockId, e.getMessage().replace("\"", "'")));
                            }
                        }
                    } catch (Exception e) {
                        System.err.println(String.format(
                            "{\"warning\": \"Error processing successors for block %s: %s\"}",
                            blockId, e.getMessage().replace("\"", "'")));
                    }

                    blockObj.put("successor_blocks", successorAddresses);
                    cfgArray.put(blockObj);
                    hasValidBlocks = true;

                } catch (Exception e) {
                    System.err.println(String.format(
                        "{\"warning\": \"Skipped invalid block in function %s: %s\"}",
                        functionAddress, e.getMessage().replace("\"", "'")));
                }
            }

            return hasValidBlocks;

        } catch (Exception e) {
            throw new RuntimeException("CFG extraction error: " + e.getMessage(), e);
        }
    }

    private String getBlockInstructions(CodeBlock block) {
        StringBuilder instructions = new StringBuilder();
        try {
            AddressIterator addresses = block.getAddresses(true);
            while (addresses.hasNext()) {
                try {
                    Address addr = addresses.next();
                    if (addr != null) {
                        Instruction instr = currentProgram.getListing().getInstructionAt(addr);
                        if (instr != null) {
                            instructions.append(instr.toString()).append("\n");
                        }
                    }
                } catch (Exception e) {
                    System.err.println(String.format(
                        "{\"warning\": \"Skipped invalid instruction at address %s: %s\"}",
                        addresses.next(), e.getMessage().replace("\"", "'")));
                }
            }
        } catch (Exception e) {
            System.err.println(String.format(
                "{\"warning\": \"Error getting block instructions: %s\"}",
                e.getMessage().replace("\"", "'")));
        }
        return instructions.toString();
    }

    private String normalizeInstruction(String instruction) {
        try {
            if (instruction == null || instruction.trim().isEmpty()) {
                return "";
            }
            return instruction.replaceAll("0x[0-9a-fA-F]+", "IMM")
                            .replaceAll("\\b\\d+\\b", "NUM")
                            .replaceAll("[\\[\\]\\+\\-\\*/%&|^]+", "_OP_");
        } catch (Exception e) {
            System.err.println(String.format(
                "{\"warning\": \"Error normalizing instruction: %s\"}",
                e.getMessage().replace("\"", "'")));
            return instruction;
        }
    }

    private String calculateHash(String content) {
        try {
            if (content == null || content.trim().isEmpty()) {
                return "";
            }
            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(String.format(
                "{\"error\": \"Error calculating hash: %s\"}",
                e.getMessage().replace("\"", "'")));
            return "";
        }
    }
}