Kan Wang

53 papers B 4C 2Misc 1Journal 35Unranked 11
YearRankTypeTitle / Venue / Authors
2026 J jnl
Appl. Math. Comput.
Qiuyue Tan, Haizhen Qiu, Yiqiao Wang, Kan Wang
2026 J jnl
Comput. Phys. Commun.
Yushuo Ren, Zeguang Li, Henglong Lin, Huifu Wang, Kan Wang
2025 J jnl
CoRR
Ruizhi Zhang, Shengfeng Zhu, Kan Wang, Ding She, Jean-Philippe Argaud, Bertrand Bouriquet, Qing Li, Helin Gong
2025 J jnl
Int. J. Prod. Res.
Chin-Yuan Tseng, Junxuan Li, Li-Hsiang Lin, Kan Wang, Chelsea C. White III, Ben Wang
2025 J jnl
CoRR
Bingxiang Kang, Jie Zou, Guofa Li, Pengwei Zhang, Jie Zeng, Kan Wang, Jie Li
2025 J jnl
Comput. Phys. Commun.
Xingyu Zhao, Guodong Liu, Shanfang Huang, Kan Wang, Qiaoyan Chen, Guoming Liu
2025 J jnl
ISPRS Int. J. Geo Inf.
Kan Wang, Jianjun Bai, Feng Bao, Feifei Hua, Xing Dang, Na Gu
2025 J jnl
Neural Networks
Xiaohua Gu, Fei Lu, Liping Yang, Kan Wang, Lusi Li, Guang Yang, Yiling Sun
2025 J jnl
CoRR
Ben Cohen, Emaad Khwaja, Youssef Doubli, Salahidine Lemaachi, Chris Lettieri, Charles Masson, Hugo Miccinilli, Elise Ramé, Qiqi Ren, Afshin Rostamizadeh, Jean Ogier du Terrail, Anna-Monica Toon, Kan Wang, Stephan Xie, Zongzhe Xu, Viktoriya Zhukova, David Asker, Ameet Talwalkar, Othmane Abou-Amal
2024 J jnl
Comput. Phys. Commun.
Hao Luo, Shanfang Huang, Kan Wang, Xiang Xiao
2024 conf
HCI (16)
Kan Wang, Oleksandra Shmelova-Nesterenko
2024 J jnl
IEEE Trans. Intell. Veh.
Wenli Li, Fanke Qiu, Lingxi Li, Yinan Zhang, Kan Wang
2024 J jnl
CoRR
Ben Cohen, Emaad Khwaja, Kan Wang, Charles Masson, Elise Ramé, Youssef Doubli, Othmane Abou-Amal
2023 J jnl
Sensors
Xu Yang, Hai Fang, Yuan Gao, Xingjie Wang, Kan Wang, Zheng Liu
2022 conf
FSDM
Ying Cui, Xiang Dai, Lican Dai, Kan Wang
2022 J jnl
J. Comput. Sci. Eng.
Kan Wang
2022 conf
CECNet
Yuan Gao, Hai Fang, Kan Wang
2022 J jnl
IEEE Instrum. Meas. Mag.
Ville Tiukuvaara, Kan Wang, Tom J. Smy, Shulabh Gupta
2022 conf
ACCV (2)
Kan Wang, Shuping Hu, Jun Cheng, Jianxin Pang, Huan Tan
2022 J jnl
Comput. Phys. Commun.
Qingquan Pan, Nan An, Tengfei Zhang, Xiaojing Liu, Yun Cai, Lianjie Wang, Kan Wang
2022 B conf
ICTAI
Jingbo Miao, Yanwei Liu, Kan Wang, Jinxia Liu, Antonios Argyriou, Yanni Han, Zhen Xu
2022 conf
PRCV (1)
Shuping Hu, Kan Wang, Jun Cheng, Huan Tan, Jianxin Pang
2022 B conf
ICIP
Jingbo Miao, Yanwei Liu, Kan Wang, Jinxia Liu, Zhen Xu
2022 J jnl
J. Frankl. Inst.
Hao Zheng, Ling Zheng, Yinong Li, Kan Wang, Ziwei Zhang, Minghui Ding
2021 B conf
TrustCom
Hongyu Peng, Fujian Sun, Kan Wang, Tianlu Hao, Dequan Xiao, Lexi Xu
2021 conf
CSSE
Yuanyuan Tian, Kan Wang
2021 J jnl
J. Comput. Phys.
Minyun Liu, Yugao Ma, Xiaoyu Guo, Shichang Liu, Guodong Liu, Shanfang Huang, Kan Wang
2020 J jnl
EURASIP J. Wirel. Commun. Netw.
Rong Fei, Jingyuan Sha, Qingzheng Xu, Bo Hu, Kan Wang, Shasha Li
2020 conf
ISPA/BDCloud/SocialCom/SustainCom
Hongyu Peng, Hanliang Xiao, Tianlu Hao, Kan Wang, Zhenkai Chen, Lexi Xu
2020 J jnl
Sensors
Yong Liu, Haoran Chen, Shenghai Wang, Kan Wang, Minghao Li, Tengfei Peng
2019 J jnl
IEEE Access
Kan Wang, Zhong Wu
2019 J jnl
Discret. Appl. Math.
Changhong Lu, Bing Wang, Kan Wang, Yana Wu
2018 conf
DSP
Yu Zhang, Tong Liu, Linbo Zhang, Kan Wang
2018 J jnl
J. Comb. Optim.
Changhong Lu, Bing Wang, Kan Wang
2018 C conf
TENCON
Kan Wang, Xin Yu, Shuiping Gou
2018 J jnl
IEEE Access
Liya Huang, Zhong Wu, Kan Wang
2018 J jnl
Sensors
Liya Huang, Zhong Wu, Kan Wang
2018 J jnl
Int. J. Embed. Syst.
Huyin Zhang, Kan Wang
2017 J jnl
IEEE Trans. Comput. Aided Des. Integr. Circuits Syst.
Kan Wang, Sheqin Dong, Fengxian Jiao
2016 conf
ICYCSEE (1)
Huyin Zhang, Kan Wang
2016 J jnl
Graphs Comb.
Changhong Lu, Chao Wang, Kan Wang
2015 J jnl
Graphs Comb.
Changhong Lu, Kan Wang, Xingxing Yu
2014 J jnl
Sci. China Inf. Sci.
Xiang Wang, Guangqian Yuan, Xun Wang, Zexi Zhao, Kan Wang
2013 J jnl
J. Syst. Softw.
Kan Wang, Zhe-Ming Lu, Yongjian Hu
2013 J jnl
J. Syst. Softw.
Yongjian Hu, Kan Wang, Zhe-Ming Lu
2013 Misc conf
ICIG
Wehao Xie, Yong Deng, Lichao Lian, Kan Wang, Zhaoyang Luo, Hui Gong
2012 J jnl
Appl. Intell.
Kan Wang, Yujun Zheng
2012 conf
IIH-MSP
Kan Wang, Yongjian Hu, Zhe-Ming Lu
2012 C conf
IGARSS
Lu Xiang, Xiuli Feng, Jianqing Wang, Kan Wang
2011 J jnl
Discret. Appl. Math.
Weifan Wang, Qiaojun Shu, Kan Wang, Ping Wang
2009 J jnl
Kybernetes
Yanmei Yang, Hongsheng Su, Kan Wang
2006 conf
ISDA (2)
Yujun Zheng, Kan Wang, Jun-Wei Yang
2006 B conf
FM
Yujun Zheng, Jinquan Wang, Kan Wang, Jinyun Xue
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 "";
        }
    }
}