代码之家  ›  专栏  ›  技术社区  ›  Clinton Blackmore

是否可以替换Mac登录屏幕?

  •  6
  • Clinton Blackmore  · 技术社区  · 17 年前

    是否可以用自定义登录窗口应用程序替换mac os x登录窗口/system/library/coreservices/login window.app?( See my rational for doing so )

    恐怕我的可可编程技能还很初级。当我运行probe cgsession(即 a undocumented utility that performs fast user switching) 通过执行来查看它使用的函数

    nm -mg /System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession
    

    链接函数之一是:

    (undefined [lazy bound]) external _CGSCreateLoginSession (from ApplicationServices)
    

    我在ApplicationServices框架上找不到文档。我怀疑我正在深入研究服务提供者接口而不是应用程序程序员接口。

    我确实发现了这个非常有趣的片段:( google cache ( direct link to down page ;似乎站点正在重新组织)从一个声称切换到登录窗口的应用程序,即使禁用了快速用户切换。

    #include "CGSInternal.h"
    
    int main (int argc, const char * argv[]) {
        // switch to the login window
        CGSCreateLoginSession(NULL);
    
        return 0;
    }
    

    我把cg理解为coregraphics,不明白这与登录有什么关系(除了在当前用户的工作上设置登录对话框)。

    即使不可能实现对登录窗口的替换,我也有兴趣知道可以通过这些方式(由那些不为苹果工作的人)做些什么。

    2 回复  |  直到 16 年前
        1
  •  18
  •   diciu    17 年前

    登录窗口应用程序被定义为 /系统/library/launchdaemons/com.apple.loginwindow.plist .

    理论上,您可以用自己的登录窗口替换登录窗口,但我不知道您在新应用程序中必须做什么-我认为登录窗口比身份验证和设置用户会话要做得多一些->除其他外,它看起来像是在做一些与启动相关的工作。

    我编译了一个调用 CGS创建协作会话 一旦你运行它,它就会通过旋转的立方体转换到登录窗口。我想这就是它需要核心图形的原因——它只是一个在末尾调用注销的图形函数。

    您可以尝试一个输入管理器并看到它登录窗口加载代码-如果它加载了代码,则可以更改登录窗口nibw( 登录wondowui.nib )并添加一些按钮以显示带有用户浏览器的新窗口。一旦学生选择了他/她自己的照片,你就可以自动填充登录窗口中的用户名和密码字段。

    节点这都是理论,看起来 非常 脆弱和不安全。

    祝你好运。

    后期编辑

    请注意,这是非常不安全的,所以要小心使用-我在试用这个东西的时候用了几次软管。

    这里有一个概念实现的证明,它在LoginWindow中注入代码。

    #include <stdio.h>
    #include <unistd.h>
    #include <sys/time.h>
    #include <strings.h>
    #include <syslog.h>
    
    #import <Cocoa/Cocoa.h>
    
    #include <execinfo.h>
    
    @interface LLApp:NSApplication
    @end
    @implementation LLApp
    - (void)run
    {
        syslog(LOG_ERR, "LLApp being run");
        [super run];
    }
    @end
    
    void my_openlog(const char *ident, int logopt, int facility);
    
    typedef struct interpose_s 
    {
            void * new_func;
            void * orig_func;
    } interpose_t;
    
    int MyNSApplicationMain(int argc,  const char ** argv);
    
    
    static const interpose_t interposers[] __attribute__ ((section("__DATA, __interpose")))     = {
    { (void *) my_openlog, (void *) openlog },
    };
    
    void my_openlog(const char *ident, int logopt, int facility)
    {
            openlog(ident, logopt, facility);
    
        if(!strcmp(ident, "/System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow"))
        {
    
            [LLApp poseAsClass:[NSApplication class]];
        }
        else
        {
            syslog(LOG_ERR, "Ignoring unknown indent: >%s<", ident);
        }
        return;
    }
    

    代码编译为:

    gcc -Wall -dynamiclib -undefined dynamic_lookup -o ~/Desktop/libinterposers.dylib testin.m -framework Cocoa
    

    代码加载基于插入,因此LoginWindow的launchd定义必须包含一个附加条目(以启用动态链接器中的插入),即:

    <key>EnvironmentVariables</key>
    <dict>    
        <key>DYLD_INSERT_LIBRARIES</key>
        <string>path_to/Desktop/libinterposers.dylib</string>
    </dict>
    
        2
  •  3
  •   kent    17 年前

    是的,您可以使用sfauthorizationPluginView

    here the reference link at ADC