Task configuration:
{"task_id": "02", "task_name": "add_rasterLayer", "description": "\u5728QGIS\u4e2d\u6dfb\u52a0\u6805\u683c\u56fe\u5c42", "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": {"rasterLayerPath": "/home/agent/testbed/QGIS/qgis_sample_data/raster/landcover.img"}, "instruction_template": "\u5728QGIS\u4e2d\u6dfb\u52a0\u6805\u683c\u56fe\u5c42,\u7edd\u5bf9\u8def\u5f84\u4e3a${rasterLayerPath}", "evaluation_setup": {"scripts": [{"role": "hook", "path": "hooker.js"}, {"role": "handler", "path": "handler.py"}], "timeout": 180}, "total_key_steps": 1, "events": {"script_initialized": {"description": "\u94a9\u5b50\u811a\u672c\u521d\u59cb\u5316", "is_key_step": false}, "addrasterLayer_function_found": {"description": "\u627e\u5230\u6dfb\u52a0\u6805\u683c\u56fe\u5c42\u51fd\u6570", "is_key_step": false}, "raster_layer_added": {"description": "\u68c0\u6d4b\u5230\u5f85\u6dfb\u52a0\u7684\u6805\u683c\u56fe\u5c42\u8def\u5f84", "is_key_step": true, "key_step_index": 1, "key_step_name": "\u9884\u671f\u6805\u683c\u56fe\u5c42\u5df2\u6dfb\u52a0"}, "error": {"description": "\u6765\u81ea\u811a\u672c\u7684\u9519\u8bef\u4e8b\u4ef6", "is_key_step": false}}}

Hook script:
// QGIS图层添加钩子脚本
// 用于监听QGIS的添加栅格图层操作并检测相关参数

(function() {
    // 脚本常量设置
    const SYMBOL_NAME = "_ZN10QgsProject11addMapLayerEP11QgsMapLayerbb"; // QgsProject::addMapLayer函数的符号
    
    // 向评估系统发送事件
    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) {
        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);
    }

    // 初始化钩子并立即执行
    function initHook() {
        sendEvent("script_initialized", {
            message: "QGIS栅格图层添加监控脚本已启动"
        });
        
        // 查找addRasterLayer函数
        let addRasterLayerAddr = Module.findExportByName(null, SYMBOL_NAME);
        
        // 如果没找到，尝试扫描所有加载的模块
        if (!addRasterLayerAddr) {
            sendEvent("function_search_start", {
                message: "正在查找QgsProject::addMapLayer函数..."
            });
            
            // 遍历模块
            Process.enumerateModules({
                onMatch: function(module) {
                    if (module.name.includes("qgis_core") ) {
                        sendEvent("module_found", {
                            module_name: module.name,
                            base_address: module.base.toString()
                        });
                        
                        // 在qgis_app模块中查找符号
                        const symbol = module.findExportByName(SYMBOL_NAME);
                        if (symbol) {
                            addRasterLayerAddr = symbol;
                        }
                    }
                },
                onComplete: function() {}
            });
            
            // 如果仍未找到，报告错误
            if (!addRasterLayerAddr) {
                sendEvent("error", {
                    error_type: "function_not_found",
                    message: "无法找到QgsAppLayerHandling::addRasterLayer函数"
                });
                return;
            }
        }
        
        // 报告找到函数
        sendEvent("addrasterLayer_function_found", {
            address: addRasterLayerAddr.toString(),
            message: "找到QgsProject::addMapLayer函数"
        });
        
        // 安装钩子
        Interceptor.attach(addRasterLayerAddr, {
            onEnter: function(args) {
                try {
                    const layerPointer = args[1];
                    const uriQString = layerPointer.add(0x18); 
                    const uri = qstringToString(uriQString);
                    console.log("添加栅格图层,路径为:", uri);
                    
                    // 发送事件通知
                    sendEvent("raster_layer_added", {
                        uri: uri,
                        message: `检测到添加栅格图层,路径为:${uri}`
                    });
                } catch (error) {
                    sendEvent("error", {
                        error_type: "hook_execution_error",
                        message: `执行钩子时出错: ${error.message}`,
                    });
                }
            }
            
        });
        
        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 == "addRasterLayer_function_found":
                logger.info(f"找到addRasterLayer函数: {payload.get('address', '')}")
                return None
                
            elif event_type == "raster_layer_added":
                detected_uri = payload.get("uri", "")
                logger.info(f"检测到添加栅格图层: {detected_uri}")
                
                # 检查图层路径是否匹配预期
                expected_path = task_parameter.get("rasterLayerPath", "")
                
                # 标准化路径用于比较
                detected_uri_norm = os.path.normpath(detected_uri)
                expected_path_norm = os.path.normpath(expected_path)
                logger.debug(f"标准化路径 - 检测到: {detected_uri_norm}, 预期: {expected_path_norm}")
                
                # 判断检测到的图层路径是否与预期相符
                if detected_uri_norm == expected_path_norm or detected_uri.endswith(expected_path):
                    logger.info("栅格图层路径匹配预期目标!")                    
                    # 返回关键步骤和成功状态
                    return [
                        {"status": "key_step", "index": 1, "name": "预期栅格图层已添加"},
                        {"status": "success", "reason": f"成功添加栅格图层: {detected_uri}"}
                    ]
                else:
                    logger.info(f"添加的栅格图层路径与预期不符。预期: {expected_path}, 实际: {detected_uri}")
                
            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