豆包复刻:原生安卓(Compose + 内嵌 Termux)+ Web / Windows
一个界面照着豆包抠的 AI 助手。主力是安卓端,完全离线自主:不依赖电脑、 不需要另外装 Termux。 安卓端 - 原生 Jetpack Compose,7 个页面,配色/圆角/间距对着真机截图量出来的 - 完整动效:抽屉滑入、页面切换、气泡淡入上移、面板底部升起、typing 三点、按钮回弹 - 内置 Termux:bash/apt/pkg 388 个命令、真 pty 终端; pty 不可用的 ROM 上自动降级成命令控制台 - APK 内嵌 CPython 3.13(Chaquopy),AI 内核跑在手机上 - 设备能力:定位 / 陀螺仪 / 加速度计 / 光线 / 电量 / 剪贴板 - 语音:朗读 + 语音输入,火山豆包音色 / OpenAI 兼容 / 设备自带三级引擎 AI 能力 - 10 家 OpenAI 兼容提供商:方舟 / OpenAI / DeepSeek / Kimi / 智谱 / 通义 / 硅基流动 / OpenRouter / 本地 Ollama / 自定义 - 思考强度按各家支持情况发不同字段(thinking / reasoning_effort / 不发), 认不出来的一律不发,避免给不支持的厂商发字段直接 400 - MCP 三种传输(http / stdio / inproc)、工具热加载、文件上传、权限模式 跨端 - 安卓走原生 Compose,Web / Windows 走 Lynx - Node 与 Python 两份内核接口逐字段一致,关键路径都有对拍脚本 自检脚本(都不需要真 Key) - verify-phone.mjs 设备端 24 项验收 - verify-speech.mjs 语音链路 31 项,两份内核各跑一遍 - parity-thinking.mjs 思考强度映射对拍 - probe-settings-wipe.mjs 设置防清空攻击测试 - mock-llm.mjs 假的 OpenAI + 火山语音服务 许可 MIT;第三方组件(Termux Apache-2.0、Chaquopy、Compose、LynxJS、Electron) 的授权见 LICENSE。
This commit is contained in:
67
scripts/device-settings-attack.mjs
Normal file
67
scripts/device-settings-attack.mjs
Normal file
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* 在**设备**上验证设置守卫:按"旧版前端那种全量下发空值"的打法打一次 PUT,
|
||||
* 配置必须一个字都不能掉。
|
||||
*
|
||||
* 为什么要单独做设备版:手机跑的是 Python 内核(Chaquopy),
|
||||
* 电脑跑的是 Node 内核,两份实现是分别写的,只在电脑上验过不算数。
|
||||
*
|
||||
* 用法: node scripts/device-settings-attack.mjs [serial] [port]
|
||||
*/
|
||||
import { spawnSync } from 'node:child_process';
|
||||
|
||||
const SERIAL = process.argv[2] || 'emulator-5556';
|
||||
const PORT = process.argv[3] || '5199';
|
||||
const ADB = 'C:\\Android\\Sdk\\platform-tools\\adb.exe';
|
||||
|
||||
function sh(cmd, timeout = 60000) {
|
||||
const res = spawnSync(ADB, ['-s', SERIAL, 'shell', cmd], { encoding: 'utf8', timeout });
|
||||
return `${res.stdout || ''}${res.stderr || ''}`.trim();
|
||||
}
|
||||
|
||||
function getState() {
|
||||
const out = sh(`curl -s --max-time 20 http://127.0.0.1:${PORT}/api/state`);
|
||||
try {
|
||||
return JSON.parse(out);
|
||||
} catch {
|
||||
console.error('拿不到 state,原始返回:', out.slice(0, 300));
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
function put(patch) {
|
||||
const b64 = Buffer.from(JSON.stringify(patch), 'utf8').toString('base64');
|
||||
sh(`echo '${b64}' | base64 -d > /data/local/tmp/patch.json`);
|
||||
const out = sh(
|
||||
`curl -s --max-time 20 -X PUT -H 'Content-Type: application/json' -d @/data/local/tmp/patch.json http://127.0.0.1:${PORT}/api/settings`,
|
||||
);
|
||||
return out.slice(0, 80);
|
||||
}
|
||||
|
||||
const KEYS = ['provider', 'model', 'baseUrl', 'thinkingLevel', 'nickname'];
|
||||
|
||||
console.log(`=== 设备 ${SERIAL} 上的 Python 内核 ===`);
|
||||
const before = getState().settings;
|
||||
console.log(' 保存前:', KEYS.map((k) => `${k}=${JSON.stringify(before[k])}`).join(' '));
|
||||
console.log(` hasApiKey=${before.hasApiKey} systemPrompt=${(before.systemPrompt || '').length}字`);
|
||||
|
||||
console.log('\n--- 攻击:全量下发空值(就是"一保存就清空"那个 bug 的形状)---');
|
||||
console.log(' PUT →', put({ provider: '', baseUrl: '', model: '', apiKey: '', nickname: '', thinkingLevel: '', systemPrompt: '' }));
|
||||
|
||||
const after = getState().settings;
|
||||
console.log(' 保存后:', KEYS.map((k) => `${k}=${JSON.stringify(after[k])}`).join(' '));
|
||||
console.log(` hasApiKey=${after.hasApiKey} systemPrompt=${(after.systemPrompt || '').length}字`);
|
||||
|
||||
const hurt = [];
|
||||
for (const key of KEYS) {
|
||||
if (String(before[key] ?? '') !== String(after[key] ?? '')) {
|
||||
hurt.push(`${key}: ${JSON.stringify(before[key])} → ${JSON.stringify(after[key])}`);
|
||||
}
|
||||
}
|
||||
if (before.hasApiKey && !after.hasApiKey) hurt.push('API Key 被清掉了');
|
||||
|
||||
console.log('\n=== 结论 ===');
|
||||
if (hurt.length) {
|
||||
console.log(' ❌ 还是被改动:\n ' + hurt.join('\n '));
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(' ✅ 空值被忽略,配置一个字都没掉');
|
||||
Reference in New Issue
Block a user