Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6687805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:19:53+00:00 2026-05-26T05:19:53+00:00

I am linking a executable with a plist using -sectcreate __TEXT linker flags. Reason

  • 0

I am linking a executable with a plist using -sectcreate __TEXT linker flags. Reason for this is mainly to use the SMJobBless() method. But I need to read plist linked from another application. This is only because I need to install the same privileged application on a 10.5 system and I can’t use SMJobBless() on 10.5.

How do I read this linked plist using Objective-C so I can copy it to /Library/LaunchDaemons/ myself?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:19:54+00:00Added an answer on May 26, 2026 at 5:19 am

    otool

    You can use otool(1) to dump the contents of the section containing the embedded plist:

    otool -s __TEXT __info_plist /path/to/executable
    

    and then pipe its output to xxd(1) in order to obtain the corresponding ASCII representation:

    otool -X -s __TEXT __info_plist /path/to/executable | xxd -r
    

    However, otool is only available in machines where Xcode has been installed.

    NSBundle

    For the cases where a program needs to read its own embedded plist, NSBundle can be used:

    id someValue = [[NSBundle mainBundle] objectForInfoDictionaryKey:someKey];
    

    Mach-O

    For the cases where a program needs to read the embedded plist of an arbitrary file without resorting to otool, the program can parse the Mach-O information in the file and extract its embedded plist as follows:

    #include <fcntl.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <unistd.h>
    #include <mach-o/loader.h>
    #include <sys/mman.h>
    #include <sys/stat.h>
    #import <Foundation/Foundation.h>
    
    id embeddedPlist(NSURL *executableURL) {
        id plist = nil;
        int fd;
        struct stat stat_buf;
        size_t size;
    
        char *addr = NULL;
        char *start_addr = NULL;
        struct mach_header_64 *mh = NULL;
        struct load_command *lc = NULL;
        struct segment_command_64 *sc = NULL;
        struct section_64 *sect = NULL;
    
        // Open the file and get its size
        fd = open([[executableURL path] UTF8String], O_RDONLY);
        if (fd == -1) goto END_FUNCTION;
        if (fstat(fd, &stat_buf) == -1) goto END_FILE;
        size = stat_buf.st_size;
    
        // Map the file to memory
        addr = start_addr = mmap(0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, fd, 0);
        if (addr == MAP_FAILED) goto END_FILE;
    
        // The first bytes are the Mach-O header
        mh = (struct mach_header_64 *)addr;
    
        // Load commands follow the header
        addr += sizeof(struct mach_header_64);
    
        for (int icmd = 0; icmd < mh->ncmds; icmd++) {
            lc = (struct load_command *)addr;
    
            if (lc->cmd != LC_SEGMENT_64) {
                addr += lc->cmdsize;
                continue;
            }
    
            if (lc->cmdsize == 0) continue;
    
            // It's a 64-bit segment
            sc = (struct segment_command_64 *)addr;
    
            if (strcmp("__TEXT", sc->segname) != 0 || sc->nsects == 0) {
                addr += lc->cmdsize;
                continue;
            }
    
            // It's the __TEXT segment and it has at least one section
            // Section data follows segment data
            addr += sizeof(struct segment_command_64);
            for (int isect = 0; isect < sc->nsects; isect++) {
                sect = (struct section_64 *)addr;
                addr += sizeof(struct section_64);
    
                if (strcmp("__info_plist", sect->sectname) != 0) continue;
    
                // It's the __TEXT __info_plist section
                NSData *data = [NSData dataWithBytes:(start_addr + sect->offset)
                                              length:sect->size];
                plist = [NSPropertyListSerialization propertyListWithData:data
                                                                  options:NSPropertyListImmutable
                                                                   format:NULL
                                                                    error:NULL];
                goto END_MMAP;
            }
        }
    
    END_MMAP:
        munmap(addr, size);
    
    END_FILE:
        close(fd);
    
    END_FUNCTION:
        return plist;
    }
    

    and:

    NSURL *url = [NSURL fileURLWithPath:@"/path/to/some/file"];
    id plist = embeddedPlist(url);
    if ([plist isKindOfClass:[NSDictionary class]]) {
        NSDictionary *info = plist;
        id someValue = [info objectForKey:someKey];
    }
    

    Note that embeddedPlist() has some limitations: it expects the file to be a thin Mach-O file (i.e., it will crash with non-Mach-O files and it won’t work with fat files containing, for example, both i386 and x86_64 Mach-O data); it only works with x86_64 files; it doesn’t report errors.

    I went ahead and released BVPlistExtractor under the MIT licence. It detects whether the file is indeed a thin Mach-O file or a fat/universal file, and works with both i386 and x86_64.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code compiles, but no surprises, it fails while linking (no main found): Listing
In linking a sports event to two teams, at first this seemed to make
//deep linking $.fn.ajaxAnim = function() { $(this).animW(); $(this).html('<div class=load-prog>loading...</div>'); } $(document).ready(function(){ contM = $('#main-content');
When linking an executable, if it does not make reference to any of the
I have a C++ executable and I'm dynamically linking against several libraries (Boost, Xerces-c
I currently have a single solution with a single project and this generates executable
I'm a complete beginner, and this is how I understand linking: Static linking copies
When linking a static library against an executable, unreferenced symbols are normally discarded. In
I'm trying to cross-compile a 64-bit executable on a 32-bit ubuntu system. This works
I get to the very last linking command (the actual executable is being linked)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.