AMG stores backup records in /var/mobile/AMG/. The example below uses TouchSprite and is provided as a reference. Adjust it for your device and the records you intend to use.
The API addresses, parameters, file paths, and return values follow the original AMG example. Adjust its wait times for the number of apps and backup size. With Smart Airplane Mode enabled, the original guide suggests waiting at least 15 seconds.
Lua example
-- AMG scripting example for TouchSprite.
-- Adjust this example for your setup before use.
require "TSLib"
local sz = require("sz");
local http = require("szocket.http");
if isFileExist(userPath().."/plugin/ts.so") == false then -- The ts.so plugin is not installed.
dialog("The ts.so plugin is missing. In TouchSprite, tap More and download the official ts.so plugin from Plugins.", 0)
lua_exit()
end
local ts = require("ts")
local plist = ts.plist
-- Place the definitions above the example calls.
-- Check whether AMG is in the foreground.
function Check_AMG()
if isFrontApp("com.superdev.AMG") == 0 then
runApp("com.superdev.AMG")
mSleep(3000)
end
end
-- Check the operation result.
function Check_AMG_Result()
::get_amg_result::
mSleep(3000) -- Increase the wait based on the number of selected apps and the backup size. With Smart Airplane Mode, wait at least 15 seconds. For scripted runs, the original guide recommends checking the IP address in the script instead.
local result_file = "/var/mobile/amgResult.txt"
if isFileExist(result_file) then
local amg_result = readFileString(result_file)
if amg_result == "0" then
return false
elseif amg_result == "1" then
return true
elseif amg_result == "2" then
toast("In progress",1)
goto get_amg_result
end
end
end
local AMG = {
Original = (function() -- Restore the original device profile.
Check_AMG()
local res, code = http.request("http://127.0.0.1:8080/cmd?fun=originRecord")
if code == 200 then
return Check_AMG_Result()
end
end),
New = (function() -- Run a one-tap reset.
Check_AMG()
local res, code = http.request("http://127.0.0.1:8080/cmd?fun=newRecord")
if code == 200 then
return Check_AMG_Result()
end
end),
Get_Name = (function() -- Get the current record name.
Check_AMG()
local res, code = http.request("http://127.0.0.1:8080/cmd?fun=getCurrentRecordName")
if code == 200 then
if Check_AMG_Result() == true then
return res
end
end
end),
Next = (function() -- Switch to the next record.
Check_AMG()
local res, code = http.request("http://127.0.0.1:8080/cmd?fun=nextRecord");
if code == 200 then
return Check_AMG_Result()
end
end),
First = (function() -- Restore the first record.
Check_AMG()
local res, code = http.request("http://127.0.0.1:8080/cmd?fun=firstRecord");
if code == 200 then
return Check_AMG_Result()
end
end),
Get_Param = (function() -- Get current record parameters and save them to the specified folder.
Check_AMG()
local param_file = userPath().."/lua/AMG_Param.plist" -- You can change this destination path and file name.
if isFileExist(param_file) then delFile(param_file) end
local res, code = http.request("http://127.0.0.1:8080/cmd?fun=getCurrentRecordParam&saveFilePath="..param_file);
if code == 200 then
if Check_AMG_Result() == true then
return param_file
end
end
end),
Set_Param = (function(param_file) -- Set parameters for the current record.
Check_AMG()
local res, code = http.request("http://127.0.0.1:8080/cmd?fun=setCurrentRecordParam&filePath="..param_file);
if code == 200 then
return Check_AMG_Result()
end
end),
Get_Spec_Param = (function(record_name) -- Get parameters for a named record and save them to the specified folder.
Check_AMG()
local param_file = userPath().."/lua/AMG_Param.plist" -- You can change this destination path and file name.
if isFileExist(param_file) then delFile(param_file) end
local res, code = http.request("http://127.0.0.1:8080/cmd?fun=getRecordParam&recordName="..record_name.."&saveFilePath="..param_file);
if code == 200 then
if Check_AMG_Result() == true then
return param_file
end
end
end),
Set_Spec_Param = (function(record_name,param_file) -- Set parameters for a named record.
Check_AMG()
local res, code = http.request("http://127.0.0.1:8080/cmd?fun=setRecordParam&recordName="..record_name.."&filePath="..param_file);
if code == 200 then
return Check_AMG_Result()
end
end),
Get_All_Record = (function() -- Write all record names to the specified file.
Check_AMG()
local all_record_file = userPath().."/lua/AMG_All_Record.plist" -- You can change this destination path and file name.
if isFileExist(all_record_file) then delFile(all_record_file) end
local res, code = http.request("http://127.0.0.1:8080/cmd?fun=getAllRecordNames&saveFilePath="..all_record_file);
if code == 200 then
if Check_AMG_Result() == true then
return all_record_file
end
end
end),
Recover = (function(record_name) -- Restore a named record.
Check_AMG()
local res, code = http.request("http://127.0.0.1:8080/cmd?fun=setRecord&recordName="..record_name);
if code == 200 then
return Check_AMG_Result()
end
end),
Rename = (function(old_name,new_name) -- Rename a record.
Check_AMG()
local res, code = http.request("http://127.0.0.1:8080/cmd?fun=setRecordName&oldName="..old_name.."&newName="..new_name);
if code == 200 then
return Check_AMG_Result()
end
end),
Delete = (function(record_name) -- Delete a named record.
Check_AMG()
local res, code = http.request("http://127.0.0.1:8080/cmd?fun=deleteRecord&recordName="..record_name);
if code == 200 then
return Check_AMG_Result()
end
end),
Delete_All = (function() -- Delete all records.
Check_AMG()
local res, code = http.request("http://127.0.0.1:8080/cmd?fun=deleteAllRecords");
if code == 200 then
return Check_AMG_Result()
end
end),
Disable = (function(record_name) -- Disable a named record.
Check_AMG()
local res, code = http.request("http://127.0.0.1:8080/cmd?fun=disableRecord&recordName="..record_name);
if code == 200 then
return Check_AMG_Result()
end
end),
Enable = (function(record_name) -- Enable a named record.
Check_AMG()
local res, code = http.request("http://127.0.0.1:8080/cmd?fun=enableRecord&recordName="..record_name);
if code == 200 then
return Check_AMG_Result()
end
end),
Disable_All = (function() -- Disable all records.
Check_AMG()
local res, code = http.request("http://127.0.0.1:8080/cmd?fun=disableAllRecord");
if code == 200 then
return Check_AMG_Result()
end
end),
Enable_All = (function() -- Enable all records.
Check_AMG()
local res, code = http.request("http://127.0.0.1:8080/cmd?fun=enableAllRecord");
if code == 200 then
return Check_AMG_Result()
end
end)
}
-- Place the definitions above the example calls.
-- Examples of calling the AMG functions.
if AMG.Original() == true then
toast("Original device", 3)
end
-- Run a one-tap reset.
if AMG.New() == true then
toast("One-tap reset", 3)
end
-- Restore the first record.
if AMG.First() == true then
toast("Restored the first record", 3)
end
-- Restore a named record.
local record_name = "A10086" -- Obtain a record name as needed. The named record must exist.
if AMG.Recover(record_name) == true then
toast("Switched to record "..record_name.."", 3)
end
-- Switch to the next record.
if AMG.Next() == true then
toast("Next record", 3)
end
-- Get the current record name.
local record_name = AMG.Get_Name()
if record_name then
toast("Current record: "..record_name, 3)
end
-- Rename the current record.
local old_name = AMG.Get_Name()
local new_name = "A1001"
if AMG.Rename(old_name,new_name) == true then
toast("Renamed current record "..old_name.." to "..new_name, 3)
end
-- Rename a named record.
local old_name = "2018-11-11-11-11-11-11" -- Obtain a record name as needed. The named record must exist.
local new_name = "A10010"
if AMG.Rename(old_name,new_name) == true then
toast("Renamed "..old_name.." to "..new_name, 3)
end
-- Advance to the next record and check whether it was the last.
if AMG.Next() == true then
if AMG.Get_Name() == "\229\142\159\229\167\139\230\156\186\229\153\168" then -- Original device record name returned by AMG.
toast("Last record", 3)
end
end
-- Get all record names.
local all_record_file = AMG.Get_All_Record()
if all_record_file then
toast("Saved all record names to "..all_record_file, 3)
end
-- Delete a named record.
local record_name = "2018-11-11-11-11-11-11" -- Obtain a record name as needed. The named record must exist.
if AMG.Delete(record_name) == true then
toast("Deleted record "..record_name.."", 3)
end
-- Delete all records except the current record.
if AMG.Delete_All() == true then
toast("Deleted all records except the current one", 3)
end
-- Restore the original device profile, then delete all records.
if AMG.Original() == true then
if AMG.Delete_All() == true then
toast("Deleted all records", 3)
end
end
-- Save current record parameters to the TouchSprite script folder and return the file path.
local param_file = AMG.Get_Param()
if param_file then
toast("Parameters saved to: "..param_file, 3)
mSleep(3000)
local amg_param = plist.read(param_file)
local devicetoken = amg_param["DeviceToken"] -- Read the DeviceToken parameter.
if devicetoken then toast("Current record device token = "..devicetoken, 3) end -- Show the device token.
end
-- Set current record parameters from a file path.
local param_file = AMG.Get_Param() -- Get the current record parameters first.
if param_file then
--toast("Parameters saved to: "..param_file, 3)
local amg_param = plist.read(param_file)
local param_name = "DeviceToken"
local param_value = "12345678900000000"
amg_param[param_name] = param_value
plist.write(param_file,amg_param) -- Write the parameters.
if AMG.Set_Param(param_file) == true then
toast("Set current record parameter "..param_name.." to "..param_value,3)
end
end
-- Set GPS coordinates for the current record.
local lon = "121.4997661114"
local lat = "31.2394855667"
local param_file = AMG.Get_Param() -- Get the current record parameters first.
if param_file then
--toast("Parameters saved to: "..param_file, 3)
local amg_param = plist.read(param_file)
amg_param["Longitude"] = lon
amg_param["Latitude"] = lat
plist.write(param_file,amg_param) -- Write the parameters.
if AMG.Set_Param(param_file) == true then
toast("Set current record location to ".."longitude "..lon..", latitude "..lat,3)
end
end
-- Save a named record to the TouchSprite script folder and return the file path.
local record_name = "2018-11-11-11-11-11-11" -- Obtain a record name as needed. The named record must exist.
local param_file = AMG.Get_Spec_Param(record_name)
if param_file then
toast("Parameters saved to: "..param_file, 3)
local amg_param = plist.read(param_file)
local devicetoken = amg_param["DeviceToken"] -- Read the DeviceToken parameter.
if devicetoken then toast("Read record "..record_name.." device token = "..devicetoken, 3) end -- Show the device token.
end
-- Set parameters using a record name and file path.
local record_name = "2018-11-11-11-11-11-11" -- Obtain a record name as needed. The named record must exist.
local param_file = AMG.Get_Spec_Param(record_name) -- Get the named record parameters first.
if param_file then
--toast("Parameters saved to: "..param_file, 3)
local amg_param = plist.read(param_file)
local param_name = "DeviceToken"
local param_value = "12345678900000000"
amg_param[param_name] = param_value
plist.write(param_file,amg_param) -- Write the parameters.
if AMG.Set_Spec_Param(record_name,param_file) == true then
toast("Set record "..record_name.." parameter "..param_name.." to "..param_value,3)
end
end
-- Disable a named record.
if AMG.Disable(record_name) == true then
toast("Disabled record "..record_name.."", 3)
end
-- Enable a named record.
if AMG.Enable(record_name) == true then
toast("Enabled record "..record_name.."", 3)
end
-- Disable all records.
if AMG.Disable_All() == true then
toast("Disabled all records", 3)
end
-- Enable all records.
if AMG.Enable_All() == true then
toast("Enabled all records", 3)
end
-- Configure device model and OS version.
-- Set a configuration switch.
function Set_AMG_Config(key,valus)
local config_file = "/private/var/mobile/Library/Preferences/AMG/config.plist"
local amg_config = plist.read(config_file)
amg_config[key] = valus
plist.write(config_file,amg_config)
end
-- Set the current device model.
function Set_Device_Model(iphone_model)
if iphone_model ~= nil then
Set_AMG_Config("fakeDeviceModel","1")
else
Set_AMG_Config("fakeDeviceModel","0")
end
local param_file = AMG.Get_Param() -- Get the current record parameters first.
if param_file then
local amg_param = plist.read(param_file)
local param_name = "Model"
local param_value = "nil"
if iphone_model ~= nil then
param_value = iphone_model
end
amg_param[param_name] = iphone_model
plist.write(param_file,amg_param) -- Write the parameters.
if AMG.Set_Param(param_file) == true then
toast("Set current record parameter "..param_name.." to "..param_value,3)
end
end
end
-- Set the current OS version.
function Set_SyetemVer(ios_ver)
if ios_ver ~= nil then
Set_AMG_Config("fakeSystemVer","1")
else
Set_AMG_Config("fakeSystemVer","0")
end
local param_file = AMG.Get_Param() -- Get the current record parameters first.
if param_file then
local amg_param = plist.read(param_file)
local param_name = "SystemVer"
local param_value = "nil"
if ios_ver ~= nil then
param_value = ios_ver
end
amg_param[param_name] = ios_ver
plist.write(param_file,amg_param) -- Write the parameters.
if AMG.Set_Param(param_file) == true then
toast("Set current record parameter "..param_name.." to "..param_value,3)
end
end
end
-- Example:
-- Set the current model to iPhone X.
local iphone_model = "iPhone X"
local ios_ver = "12.1.2"
-- Restore the original model.
local iphone_model = nil
local ios_ver = nil
Set_Device_Model(iphone_model)
Set_SyetemVer(ios_ver)