AMG 文档

AMG官方源™

https://apt.amg987.com/

AMG 官方文档与脚本指南

全面的AMG HTTP脚本开发指南,包含指令说明、环境配置和实用脚本示例

一、HTTP 指令说明

功能 代码示例
启动应用 runApp("com.superdev.AMG");
注:所有指令调用前必须先执行此指令
原始机器 http://127.0.0.1:8080/cmd?fun=originRecord
一键新机 http://127.0.0.1:8080/cmd?fun=newRecord
获取当前记录名 http://127.0.0.1:8080/cmd?fun=getCurrentRecordName
返回当前记录名文本
下一条记录 http://127.0.0.1:8080/cmd?fun=nextRecord
还原第一条记录 http://127.0.0.1:8080/cmd?fun=firstRecord
重命名指定记录 http://127.0.0.1:8080/cmd?fun=setRecordName&oldName="旧名称"&newName="新名称"
还原指定记录 http://127.0.0.1:8080/cmd?fun=setRecord&recordName="记录名称"
删除指定记录 http://127.0.0.1:8080/cmd?fun=deleteRecord&recordName="记录名称"
导入AMG记录 http://127.0.0.1:8080/cmd?fun=importData
导入路径:/var/mobile/Media/AMG/import
导出AMG记录 http://127.0.0.1:8080/cmd?fun=exportData
导出路径:/var/mobile/Media/AMG/export

二、指令返回值说明

http.request 调用后返回 res,code

  • 成功执行时 code=200
  • 结果同时保存于文件:/var/mobile/amgResult.txt
返回值 说明
0 指令执行失败
1 指令执行成功
2 指令执行中

三、Roothide 环境说明

3.1 根目录区别

Roothide 环境存在两个独立根目录:

  • 系统根(rootfs): iOS原生系统目录,未被修改
  • 越狱根(jbroot): 挂载于系统根的随机路径(如/var/containers/Bundle/Application/.jbroot-XXXXXXXXXXXXXXXX/
系统根反向挂载于越狱根的 rootfs/ 目录下

3.2 路径访问规则

访问场景 路径格式 示例
非Shell脚本访问越狱根 直接路径 /var/mobile/Media/1.txt
Shell脚本访问系统根 需加/rootfs前缀 /rootfs/usr/bin/hidutil
代码中转换路径 使用jbroot()函数 jbroot("/var/mobile/Media/1.txt")

3.3 AMG记录路径

普通访问:

/private/var/mobile/Media/AMG/data/

Shell脚本访问:

/rootfs/private/var/mobile/Media/AMG/data/

四、TouchIOS 脚本示例

4.1 封装常用执行函数



-- 字符转义函数
local function sh_escape(path)
    path = string.gsub(path, "([ \\()<>'\"`#&*;?~$])", "\\%1")
    return path
end

-- 文件操作函数
function fdelete(path)  -- 删除文件/目录
    assert(type(path)=="string" and path~="", '参数异常')
    os.execute('rm -rf '..sh_escape(path))
end

function frename(from, to)  -- 重命名/移动
    assert(type(from)=="string" and from~="", '参数1异常')
    assert(type(to)=="string" and to~="", '参数2异常')
    os.execute('mv -f '..sh_escape(from).." "..sh_escape(to))
end

-- AMG状态检查
function Check_AMG()
    ::run_amg:: 
    if app.front_bid() ~= "com.superdev.AMG" then
        sys.toast("启动AMG")
        app.run("com.superdev.AMG")
        sys.msleep(10000)
        if app.front_bid() == "com.superdev.AMG" then
            local code = http.get("http://127.0.0.1:8080/cmd?fun=getCurrentRecordName");    
            if code ~= 200 then goto run_amg end
        else
            goto run_amg
        end
    end
end

-- 获取执行结果
function get_amg_result()
    local result_file = "/var/mobile/amgResult.txt"
    ::retry::
    sys.msleep(1000)
    if file.exists(result_file) then
        local res = file.get_line(result_file,1)
        if res == "0" then return false end
        if res == "1" then return true end
        if res == "2" then
            sys.toast("执行中...")
            sys.msleep(5000)
            goto retry
        end
    else
        sys.toast("未获取结果")
        sys.msleep(3000)
        goto retry
    end
end

-- AMG核心指令封装
function AMG_ori()  -- 原始机器
    Check_AMG()
    local code = http.get("http://127.0.0.1:8080/cmd?fun=originRecord");
    return code == 200 and get_amg_result()
end

function AMG_new()  -- 一键新机
    Check_AMG()
    local code = http.get("http://127.0.0.1:8080/cmd?fun=newRecord");
    return code == 200 and get_amg_result()
end

function AMG_getname()  -- 获取当前记录名
    Check_AMG()
    local code, res, body = http.get("http://127.0.0.1:8080/cmd?fun=getCurrentRecordName");    
    return code == 200 and get_amg_result() and body
end

4.2 自动切换IP的循环脚本



-- 获取外网IP
function get_ip()
    local c, h, b = http.get("https://ipinfo.io")
    if c == 200 then
        local tmp = json.decode(b)
        return tmp.ip
    end
end

local target_app = "com.google.chrome.ios"  -- 目标应用

-- 初始化
AMG_ori()
sys.msleep(3000)
AMG_first()
sys.msleep(3000)

-- 主循环
while true do
    -- 切换飞行模式刷新网络
    device.turn_on_airplane()
    sys.msleep(3000)
    device.turn_off_airplane()
    sys.msleep(10000)

    -- 获取IP(带重试机制)
    ::reget_ip::
    local ip = get_ip()
    if not ip then
        sys.toast("获取IP失败,重试")
        sys.msleep(5000)
        goto reget_ip
    else
        sys.toast("当前IP:"..ip)
        sys.msleep(3000)
    end

    -- 执行操作
    if AMG_getname() ~= "原始机器" then
        sys.toast("打开应用")
        app.run(target_app)
        sys.msleep(10000)  -- 停留时间
    else
        dialog("运行结束", 0)
        os.exit()
    end

    -- 切换到下一条记录
    AMG_next()
    sys.toast("切换到下一条记录")
    sys.msleep(3000)
end

4.3 新建谷歌地图记录并设置参数



-- 1. 创建新记录
AMG_new()
sys.msleep(3000)

-- 2. 重命名记录
local old_name = AMG_getname()
local new_name = "A0001"
if AMG_rename(old_name, new_name) then
    sys.toast("已重命名为:"..new_name)
end

-- 3. 设置GPS位置(基辅坐标)
local lon, lat = "30.523814", "50.450025"
local param_file = AMG_getparam()  -- 获取参数文件
if param_file then
    local params = plist.read(param_file)
    params["Longitude"] = lon  -- 经度
    params["Latitude"] = lat   -- 纬度
    plist.write(param_file, params)
    if AMG_setparam(param_file) then
        sys.toast("GPS设置完成:"..lon..","..lat)
    end
end

-- 4. 设置设备名
local device_name = "AK47"
local param_file = AMG_getparam()
if param_file then
    local params = plist.read(param_file)
    params["Name"] = device_name
    plist.write(param_file, params)
    if AMG_setparam(param_file) then
        sys.toast("设备名设置为:"..device_name)
    end
end

-- 5. 打开谷歌地图
app.run("com.google.Maps")

4.4 AMG记录备份脚本



-- 清理应用无用文件(根据实际需求修改)
function Clear_App() 
    -- 示例:清理冗余缓存,保留登录信息
    -- fdelete("/var/mobile/Containers/Data/Application/XXX/Library/Caches")
end

-- 1. 定义备份路径(按当天日期创建文件夹)
local current_date = os.date("%Y%m%d")
local backup_path = "/private/var/mobile/Media/1ferver/lua/scripts/"..current_date.."/"

-- 2. 创建备份目录(不存在则新建)
if file.exists(backup_path) == false then
    mkdir(backup_path)
end

-- 3. 修正目录权限
os.execute("chown -R mobile:mobile " .. backup_path)
os.execute("chmod -R 755 " .. backup_path)

-- 4. 遍历AMG记录并压缩备份
local AMG_record_path = "/private/var/mobile/Media/AMG/data/"
local record_list = file.list(AMG_record_path)
if record_list then
    for k, v in ipairs(record_list) do
        Clear_App() -- 备份前清理应用
        -- 压缩记录文件夹到备份路径(注意添加/rootfs前缀)
        os.execute("tar -cvzpf "..backup_path..v..".tar.gz ".."/rootfs"..AMG_record_path..v)
    end
    sys.toast("备份完成,路径:"..backup_path)
end

4.5 预留空模板



-- 可基于上述封装函数扩展功能
-- 示例场景:
-- 1. 批量启用/禁用记录
-- 2. 定时导出记录参数
-- 3. 多设备同步记录

-- 示例:批量启用名称包含"test"的记录
local all_records_file = AMG_getallrecord()
local all_records = file.read(all_records_file)
for record_name in string.gmatch(all_records, "[^\n]+") do
    if string.find(record_name, "test") then
        AMG_ena(record_name)
        sys.toast("启用记录:"..record_name)
        sys.msleep(1000)
    end
end