How do I enable modules programatically #965
-
In order to enable modules and scopes (apps) programatically, I can modify the But LSposed doesn't recognize the changes until I reboot the device. How can I restart the LSposed service manager or whatever it is to make it notice the changes without a reboot? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 14 replies
-
We are still working on this API. |
Beta Was this translation helpful? Give feedback.
-
Here's what I come up with in my codebase for the temporary workaround if it helps anyone. Of course, this can easily break if anything changes with how LSPosed does things, so of course I'll happily switch to an API once available, especially if a CLI tool is provided. class Lsposed
MODULES_CONFIG_SQL_FILENAME = "/data/adb/lspd/config/modules_config.db".freeze
def modules_config_sql(mymodule_apk_path, rootcloak_apk_path, pkg_names)
fail ::ArgumentError, "modules_config_sql: mymodule_apk_path cannot be blank" if mymodule_apk_path.blank?
fail ::ArgumentError, "modules_config_sql: rootcloak_apk_path cannot be blank" if rootcloak_apk_path.blank?
fail ::ArgumentError, "modules_config_sql: pkg_names cannot be nil" if pkg_names.nil?
<<~SQL_LINES
BEGIN;
DELETE FROM config;
DELETE FROM scope;
DELETE FROM modules;
DELETE FROM sqlite_sequence;
INSERT INTO sqlite_sequence VALUES ('modules', 3);
INSERT INTO modules VALUES (1, 'com.example.mymodule', '#{mymodule_apk_path}', 1);
INSERT INTO modules VALUES (2, 'com.devadvance.rootcloak2', '#{rootcloak_apk_path}', 1);
#{scope_sql(1, pkg_names)}
#{scope_sql(2, pkg_names)}
COMMIT;
SQL_LINES
end
private
def scope_sql(module_id, pkg_names)
pkg_names.sort.map { |pkg_name| "INSERT INTO scope VALUES (#{module_id}, '#{pkg_name}', 0);" }.join("\n")
end
end class Device
def update_lsposed_enabled_modules_and_apps
mymodule_apk_path = adb.app_apk_path!(MYMODULE_PACKAGE_NAME)
rootcloak_apk_path = adb.app_apk_path!(ROOTCLOAK_PACKAGE_NAME)
pkg_names = ::Packages.pluck(:pkg_name)
sql = ::Lsposed.new.modules_config_sql(mymodule_apk_path, rootcloak_apk_path, pkg_names)
sql_path = adb.android_temp_filename
::Tempfile.create do |f|
f.write(sql)
f.close
adb.push_file_safe!(f.path, sql_path)
end
adb.process_sql_file(sql_path, ::Lsposed::MODULES_CONFIG_SQL_FILENAME)
adb.stop_lsposed!
adb.start_lsposed!
end
end class Adb
def app_apk_path!(package_name)
# If needed this can be changed to use `cmd package list packages -f` and filter the results.
adb_shell("ls", "/data/app/#{package_name}-*/base.apk").chomp
end
def process_sql_file!(sql_path, db_path)
adb_shell("/system/bin/sqlite3", "-init", sql_path, db_path)
end
def start_lsposed!
adb_shell("PATH=/sbin/.magisk/busybox:$PATH", "/system/bin/sh", "/data/adb/modules/riru_lsposed/service.sh")
end
def stop_lsposed!
adb_shell("killall", "lspd")
end
end |
Beta Was this translation helpful? Give feedback.
-
@yujincheng08 This strategy is no longer working with the latest version of LSposed (v1.8.4; using zygisk_lsposed) because invoking service.sh causes the device to reboot. Can you help? Here are some lines from the LSposed log:
|
Beta Was this translation helpful? Give feedback.
#9
We are still working on this API.