Task configuration:
{"task_id": "08", "task_name": "create_new_project", "description": "\u5728QGIS\u4e2d\u521b\u5efa\u5e76\u4fdd\u5b58\u4e00\u4e2a\u65b0\u7684\u9879\u76ee", "application_info": {"name": "QGIS", "executable_path": "/home/agent/qgis/QGIS/build-master/output/bin/qgis", "args": []}, "mcp_servers": [{"command": "python", "args": ["/home/agent/agent-demo/PC-Canary/tests/context_data/QGIS/qgis_config/qgis_mcp/qgis_mcp_server.py"]}], "context_data": [{"from": "tests/context_data/QGIS/qgis_sample_data", "to": "/home/agent/testbed/QGIS"}, {"from": "tests/context_data/QGIS/qgis_config", "to": "/home/agent/.local/share/QGIS"}], "task_parameters": {"save_path": "/home/agent/testbed/QGIS/test.qgz"}, "instruction_template": "\u5728QGIS\u4e2d\u521b\u5efa\u5e76\u4fdd\u5b58\u65b0\u9879\u76ee,\u8def\u5f84\u4e3a${save_path}", "evaluation_setup": {"scripts": [{"role": "hook", "path": "hooker.js"}, {"role": "handler", "path": "handler.py"}], "timeout": 180}, "total_key_steps": 2, "events": {"script_initialized": {"description": "\u94a9\u5b50\u811a\u672c\u521d\u59cb\u5316", "is_key_step": false}, "clear_function_found": {"description": "\u627e\u5230\u521b\u5efa\u65b0\u9879\u76ee\u7684\u51fd\u6570", "is_key_step": false}, "newProject_created": {"description": "\u65b0\u9879\u76ee\u5df2\u521b\u5efa", "is_key_step": true, "key_step_index": 1, "key_step_name": "\u521b\u5efa\u65b0\u9879\u76ee\u6210\u529f"}, "setPath_function_found": {"description": "\u627e\u5230\u4fdd\u5b58\u65b0\u9879\u76ee\u7684\u51fd\u6570", "is_key_step": false}, "newProject_saved": {"description": "\u65b0\u9879\u76ee\u88ab\u4fdd\u5b58", "is_key_step": true, "key_step_index": 2, "key_step_name": "\u4fdd\u5b58\u65b0\u9879\u76ee\u6210\u529f"}, "error": {"description": "\u6765\u81ea\u811a\u672c\u7684\u9519\u8bef\u4e8b\u4ef6", "is_key_step": false}}}

Hook script:
// QGIS创建新项目钩子脚本
// 用于监听QGIS创建和保存新项目的操作并检测参数

(function() {
    // 脚本常量设置
    const clearProject_SYMBOL_NAME="_ZN10QgsProject5clearEv" // QgsProject::clear 函数的符号
    const setPath_SYMBOL_NAME="_ZN10QgsProject11setFileNameERK7QString" // QgsProject::setFileName 函数的符号
    
    // 计数器和时间戳，用于过滤启动时的自动调用
    let clearCounter = 0;
        
    // 向评估系统发送事件
    function sendEvent(eventType, data = {}) {
        const payload = {
            event: eventType,
            ...data,
            timestamp: new Date().getTime()
        };
        send(payload);
    }
    
    const HEADER_SIZE = 24;   
    const SIZE_OFFSET = 4;                  

    function qstringToString(qstr) {
        try {
            const d = qstr.readPointer();                         // QString::d
            const len = d.add(SIZE_OFFSET).readU32();             // QStringData::size
            const data = d.add(HEADER_SIZE);                      // first UTF‑16 char
            return Memory.readUtf16String(data, len);
        } catch (error) {
            console.log("解析QString失败:", error);
            return "";
        }
    }

    // 初始化钩子并立即执行
    function initHook() {
        sendEvent("script_initialized", {
            message: "QGIS创建新项目监控脚本已启动"
        });
        
        // 查找创建新项目的函数 QgsProject::clear
        let clearProjectAddr = Module.findExportByName(null, clearProject_SYMBOL_NAME);
        
        // 如果没找到，尝试扫描所有加载的模块
        if (!clearProjectAddr) {
            sendEvent("function_search_start", {
                message: "正在查找QgsProject::clear函数..."
            });
            
            // 遍历模块
            Process.enumerateModules({
                onMatch: function(module) {
                    if (module.name.includes("qgis_core")) {
                        sendEvent("module_found", {
                            module_name: module.name,
                            base_address: module.base.toString()
                        });
                        
                        // 在qgis_core模块中查找符号
                        const symbol = module.findExportByName(clearProject_SYMBOL_NAME);
                        if (symbol) {
                            clearProjectAddr = symbol;
                        }
                    }
                },
                onComplete: function() {}
            });
            
            // 如果仍未找到，报告错误
            if (!clearProjectAddr) {
                sendEvent("error", {
                    error_type: "function_not_found",
                    message: "无法找到QgsProject::clear函数"
                });
                return;
            }
        }
        
        // 报告找到函数
        sendEvent("clear_function_found", {
            address: clearProjectAddr.toString(),
            message: "找到QgsProject::clear函数"
        });
        
        // 查找保存项目的函数 QgsProject::setFileName
        let setFileNameAddr = Module.findExportByName(null, setPath_SYMBOL_NAME);
        
        // 如果没找到，尝试扫描所有加载的模块
        if (!setFileNameAddr) {
            sendEvent("function_search_start", {
                message: "正在查找QgsProject::setFileName函数..."
            });
            
            // 遍历模块
            Process.enumerateModules({
                onMatch: function(module) {
                    if (module.name.includes("qgis_core")) {
                        sendEvent("module_found", {
                            module_name: module.name,
                            base_address: module.base.toString()
                        });
                        
                        // 在qgis_core模块中查找符号
                        const symbol = module.findExportByName(setPath_SYMBOL_NAME);
                        if (symbol) {
                            setFileNameAddr = symbol;
                        }
                    }
                },
                onComplete: function() {}
            });
            
            // 如果仍未找到，报告错误
            if (!setFileNameAddr) {
                sendEvent("error", {
                    error_type: "function_not_found",
                    message: "无法找到QgsProject::setFileName函数"
                });
                return;
            }
        }
        
        // 报告找到函数
        sendEvent("setPath_function_found", {
            address: setFileNameAddr.toString(),
            message: "找到QgsProject::setFileName函数"
        });
        
        // 安装钩子 - 创建新项目
        Interceptor.attach(clearProjectAddr, {
            onEnter: function(args) {
                try {
                    clearCounter++;
                    
                    
                    // 忽略启动时期的自动调用（计数器为1时的调用）
                    if (clearCounter > 1 ) {
                        console.log("检测到用户创建新项目");
                        
                        // 发送事件通知
                        sendEvent("newProject_created", {
                            message: "检测到创建新项目"
                        });
                    } else {
                        console.log("忽略应用启动时的项目初始化");
                    }
                } catch (error) {
                    sendEvent("error", {
                        error_type: "hook_execution_error",
                        message: `监控创建新项目时出错: ${error.message}`,
                        stack: error.stack
                    });
                }
            }
        });
        
        // 安装钩子 - 保存项目
        Interceptor.attach(setFileNameAddr, {
            onEnter: function(args) {
                try {
                    // 获取函数的第二个参数（const QString &name），第一个是this指针
                    const pathQString = args[1];
                    const filePath = qstringToString(pathQString);
                    
                    console.log("检测到保存项目路径:", filePath);
                    
                    // 发送事件通知
                    sendEvent("newProject_saved", {
                        path: filePath,
                        message: `检测到保存项目设置: 路径=${filePath}`
                    });
                } catch (error) {
                    sendEvent("error", {
                        error_type: "hook_execution_error",
                        message: `监控保存项目时出错: ${error.message}`,
                        stack: error.stack
                    });
                }
            }
        });
        
        sendEvent("hook_installed", {
            message: "钩子安装完成，等待创建和保存新项目操作..."
        });
    }
    
    // 立即执行钩子初始化
    initHook();
})();

Evaluation handler:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
QGIS创建新项目事件处理器
负责处理钩子脚本产生的事件并更新评估指标
"""

import os
from typing import Dict, Any, Optional, List

def message_handler(message: Dict[str, Any], logger: Any, task_parameter: Dict[str, Any]) -> Optional[List[Dict[str, Any]]]:
    """
    处理从钩子脚本接收的消息
    
    Args:
        message: Frida消息对象
        logger: 日志记录器
        task_parameter: 任务参数
        
    Returns:
        Optional[List[Dict[str, Any]]]: 如果任务状态有更新返回状态列表，否则返回None
    """

    # 处理消息
    if message.get('type') == 'send' and 'payload' in message:
        payload = message['payload']
        
        # 检查是否包含事件类型
        if 'event' in payload:
            event_type = payload['event']
            logger.debug(f"接收到事件: {event_type}")
            
            # 处理特定事件
            if event_type == "script_initialized":
                logger.info(f"钩子脚本初始化: {payload.get('message', '')}")
                return None
                
            elif event_type == "clear_function_found":
                logger.info(f"找到创建新项目函数: {payload.get('address', '')}")
                return None
                
            elif event_type == "setPath_function_found":
                logger.info(f"找到保存项目函数: {payload.get('address', '')}")
                return None
                
            elif event_type == "newProject_created":
                logger.info(f"检测到创建新项目")
                
                # 返回关键步骤
                return [{"status": "key_step", "index": 1, "name": "创建新项目成功"}]
                
            elif event_type == "newProject_saved":
                path = payload.get("path", "")
                logger.info(f"检测到保存项目: 路径={path}")
                
                # 检查路径是否匹配预期
                expected_path = task_parameter.get("save_path", "").lower()
                
                path_matches = expected_path in path.lower() or os.path.basename(expected_path) in path.lower()
                
                if path_matches:
                    logger.info("保存路径匹配预期目标!")                    
                    # 返回关键步骤和成功状态（全部步骤完成）
                    return [
                        {"status": "key_step", "index": 2, "name": "保存新项目成功"},
                        {"status": "success", "reason": f"成功创建并保存新项目: 路径={path}"}
                    ]
                else:
                    logger.info(f"保存路径与预期不符。预期路径: {expected_path}, 实际: {path}")
                
            elif event_type == "error":
                error_type = payload.get("error_type", "unknown")
                error_message = payload.get("message", "未知错误")
                logger.error(f"钩子脚本错误 ({error_type}): {error_message}")
                
                # 返回错误状态
                return [{
                    "status": "error",
                    "type": error_type,
                    "message": error_message
                }]
                
    elif message.get('type') == 'error':
        stack = message.get('stack', '')
        logger.error(f"钩子脚本错误: {stack}")
        
        # 返回错误状态
        return [{
            "status": "error",
            "type": "script_error",
            "message": "钩子脚本执行错误",
            "stack_trace": stack
        }]
    
    return None