平时写frida hook 脚本,有时打印出来的日志太多都是一个颜色不美观。
于是找AI 问了一下frida打印日志字体加颜色的方法
// ANSI 转义码
const RESET = “\x1b[0m”;
const RED = “\x1b[31m”;
const GREEN = “\x1b[32m”;
const YELLOW = “\x1b[33m”;
const BLUE = “\x1b[34m”;
const MAGENTA = “\x1b[35m”;
const CYAN = “\x1b[36m”;
const WHITE = “\x1b[37m”;
// 示例函数
function logWithColor(message, color) {console.log(color + message + RESET);
}
调用示例:
logWithColor(“log带颜色” , GREEN);
// Frida 脚本示例// ANSI 转义码const RESET = "\x1b[0m";const RED = "\x1b[31m";const GREEN = "\x1b[32m";const YELLOW = "\x1b[33m";const BLUE = "\x1b[34m";const MAGENTA = "\x1b[35m";const CYAN = "\x1b[36m";const WHITE = "\x1b[37m";// 示例函数function logWithColor(message, color) {console.log(color + message + RESET);}测试脚本:
Java.perform(function () {try {// 打印 Android Java 版本logWithColor('Java version: ' + Java.androidVersion, GREEN);// 创建一个长度为 1024 的 byte 数组var buffer = Java.array('byte', new Array(1024).fill(0)); // 使用 fill(0) 填充数组logWithColor('Buffer created with length: ' + buffer.length , YELLOW);} catch (e) {console.error('Error: ' + e.message);console.error('Stack trace: ' + e.stack);}
});
结果: