鸿蒙系统安全之访问未导出接口

admin 2025年1月1日11:46:25评论38 views字数 4906阅读16分21秒阅读模式
上篇文章中,我们分析了app如何通过sdk访问系统服务。但是经常遇到一个情况是napi定义了某个接口,但是在应用开发中却找不到这个接口,我称之为未导出接口。那如何才能访问到这些未导出接口呢?
以system/lib64/module/enterprise/libadminmanager.z.so为例,来讲解如何调用未导出接口。
鸿蒙系统安全之访问未导出接口
调用napi_define_properties函数定义了13个js native函数,分别是
adminManager.jsapi
enableAdmin, disableAdmin, isAdminEnabled, disableSuperAdmin, getEnterpriseInfo, setEnterpriseInfo, isSuperAdmin, authorizeAdmin, getSuperAdmin, subscribeManagedEvent, unsubscribeManagedEvent,subscribeManagedEventSync, unsubscribeManagedEventSync
而在sdk中只导出了三个函数
declare namespace adminManager {/**     * Enum for managed event     *     * @enum { number }     * @syscap SystemCapability.Customization.EnterpriseDeviceManager     * @since 12     */export enum ManagedEvent {/**         * The event of bundle added.         *         * @syscap SystemCapability.Customization.EnterpriseDeviceManager         * @since 12         */        MANAGED_EVENT_BUNDLE_ADDED = 0,/**         * The event of bundle removed.         *         * @syscap SystemCapability.Customization.EnterpriseDeviceManager         * @since 12         */        MANAGED_EVENT_BUNDLE_REMOVED = 1,/**         * The event of app start.         *         * @syscap SystemCapability.Customization.EnterpriseDeviceManager         * @since 12         */        MANAGED_EVENT_APP_START = 2,/**         * The event of app stop.         *         * @syscap SystemCapability.Customization.EnterpriseDeviceManager         * @since 12         */        MANAGED_EVENT_APP_STOP = 3,/**         * The event of system update.         *         * @syscap SystemCapability.Customization.EnterpriseDeviceManager         * @since 12         */        MANAGED_EVENT_SYSTEM_UPDATE = 4    }/**     * Disables a current administrator ability.     * Only apps with the ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN permission or the shell uid can call this method.     *     * @permission ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN     * @param { Want } admin - admin indicates the enterprise admin extension ability information.     * The admin must have the corresponding permission.     * @param { number } [userId] - userId indicates the user ID or do not pass user ID.     * @returns { Promise<void> } the promise returned by the disableAdmin.     * @throws { BusinessError } 9200005 - Failed to deactivate the administrator application of the device.     * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;     * 2. Incorrect parameter types; 3. Parameter verification failed.     * @syscap SystemCapability.Customization.EnterpriseDeviceManager     * @StageModelOnly     * @since 12     */functiondisableAdmin(admin: Want, userId?: number): Promise<void>;    /**     * Subscribesthemanagedeventofadmin.     *     * @permissionohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT     * @param{ Want } admin - admin indicates the administrator ability information.     * @param { Array<ManagedEvent> } managedEvents - managedEvents indicates the managed events to subscribe.     * @throws { BusinessError } 9200001 - The application is not an administrator application of the device.     * @throws { BusinessError } 9200008 - The specified system event is invalid.     * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;     * 2. Incorrect parameter types; 3. Parameter verification failed.     * @syscap SystemCapability.Customization.EnterpriseDeviceManager     * @StageModelOnly     * @since 12     */    function subscribeManagedEventSync(admin: Want, managedEvents: Array<ManagedEvent>): void;    /**     * Unsubscribes the managed event of admin.     *     * @permission ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT     * @param { Want } admin - admin indicates the administrator ability information.     * @param { Array<ManagedEvent> } managedEvents - managedEvents indicates the managed events to subscribe.     * @throws { BusinessError } 9200001 - The application is not an administrator application of the device.     * @throws { BusinessError } 9200008 - The specified system event is invalid.     * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;     * 2. Incorrect parameter types; 3. Parameter verification failed.     * @syscap SystemCapability.Customization.EnterpriseDeviceManager     * @StageModelOnly     * @since 12     */    function unsubscribeManagedEventSync(admin: Want, managedEvents: Array<ManagedEvent>): void;}export default adminManager;
从IDE中看也是如此:
鸿蒙系统安全之访问未导出接口
相应的路径在
/Applications/DevEco-Studio.app/Contents/sdk/default/openharmony/js/api/@ohos.enterprise.adminManager.d.ts
如OHOS::EDM::AdminManager::EnableAdmin,接受至少三个以上的参数,分别是json,json,number
然后在@ohos.enterprise.adminManager.d.ts新增函数的声明:
function enableAdmin(admin: Want, info?: any, userId?: number): Promise<void>;
就可以在 app 中直接调用了
import {adminManager} from'@kit.MDMKit'

let want:Want = {
bundleName"com.huawei.hms.gameservice",
abilityName"GamePlayerService"
};

adminManager.enableAdmin(want, {"name":"test""description""test"}, 1);
即可实现对enableAdmin函数的调用
鸿蒙系统安全之访问未导出接口

原文始发于微信公众号(大山子雪人):鸿蒙系统安全之访问未导出接口

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2025年1月1日11:46:25
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   鸿蒙系统安全之访问未导出接口https://cn-sec.com/archives/3578039.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息