CastAway1970
CastAway1970

Reputation: 85

How to create a codeless kernel extension?

I know how to load the driver in KEXT, and I know how to use xcode. The problem is, how do I create a codeless kext?

Assume I already have a text file and I can save it as a PLIST file? then what? how can I convert it (PLIST file) to a .KEXT file? using Xcode? or from command line? I am looking for step-by-step guidance.

Upvotes: 2

Views: 1817

Answers (1)

pmdj
pmdj

Reputation: 23438

A codeless kext is pretty much just a bunch of directories containing an Info.plist and from OS X 10.9 onwards, a cryptographic signature.

YourKextName.kext/
 + Contents/
    + Info.plist - Your plist file
    + _CodeSignature/ - The 'codesign' tool will create and fill this appropriately

You might also have some localisation data, but I don't know what use this would be in a codeless kext.

To create it, you have 2 options:

Manually create codeless kext

  • Create your Info.plist (Some hints on this further down.)
  • Create the directory tree (mkdir -p "$BUILD_DIR/YourKextName.kext/Contents")
  • Copy the Info.plist in (cp "$SOURCE_DIR/Info.plist" "$BUILD_DIR/YourKextName.kext/Contents/")
  • Sign it. (codesign -fs "Developer Id" "$BUILD_DIR/YourKextName.kext")

You can create an "Aggregate" target in Xcode and place all these commands (apart from the first) in the "Run Script" build phase of the target, if you'd like it as part of your Xcode build.

The Xcode way

If you want Xcode to pre-process your Info.plist as you'd have it do for a regular kext, you can also get Xcode to do the whole thing for you, no custom scripts required:

  • Create an "I/O Kit Driver" Xcode target in your project.
  • Delete the source code files Xcode will have automatically created. (Easiest: delete them in the project navigator, reply with "move to trash" when it asks. This will remove them both from the target's build and from your source tree.)
  • In the target's "Build Phases", remove the "Compile Sources" and "Link Libraries" phases. (Click the little x symbol on each) This is the bit that prevents an executable from being built and included in the kext.
  • Customise your Info.plist (see below)
  • If necessary, choose the Developer Id certificate which you'll use to sign the kext in the target's build settings.
  • Hit build (⌘B)

Codeless kext Info.plist tips

Your Info.plist is similar to any other I/O Kit kext's Info.plist, except:

  • There is no executable, so the CFBundleExecutable property must not exist.
  • You don't need/want an OSBundleLibraries property because there is no executable that needs linking.
  • Each personality in your IOKitPersonalities dictionary must have a CFBundleIdentifier property identifying another kext, one containing the executable that provides whatever IOClass you specified.

Upvotes: 5

Related Questions