RLT
RLT

Reputation: 4287

Hooking Cocoa API?

I am trying to Hook Cocoa API.

I know cocoa provides a public api for hooking, so it’s possible to hook the system function and retrieve information like the current font settings of the context.

I am also trying to hook that draw api from cocoa.

Can somebody point me to details on how it can be achieved. Or some references which talks about hooking of Cocoa APIs?

By Hooking , I mean "A fundamental technique of getting control over a particular piece of code execution. It provides an straightforward mechanism that can easily alter the operating system's behavior as well as 3rd party products, without having their source code available."

My requirement is, if any application/system is drawing something, then I want those draw instructions should first come to me. Then I cant to store those commands, for some processing later.

Upvotes: 0

Views: 2168

Answers (4)

Peter Hosey
Peter Hosey

Reputation: 96363

You can't intercept another application's drawing as it happens, but you can capture the results after the fact. Use Quartz Window Services to take screenshots, and Quartz Display Services to find out when the screen gets updated.

Upvotes: 1

Chuck
Chuck

Reputation: 237100

The term you are looking for is something like "systemwide code injection," and Cocoa does not provide an API for any such thing. You'd need to take a look at something like mach_star or SIMBL. But honestly, this is one of those things where, if you have to ask, it's probably a little advanced for you. Modifying other processes' code is a gigantic PITA and even harder to do right, even with as much help as mach_star offers. If you want to see just how hard, take a look at Unsanity's site. That's the company that pioneered code injection on OS X, and their entire product line is based around it — and many of their programs are still not compatible with OS X 10.6.

Upvotes: 3

Stephen Furlani
Stephen Furlani

Reputation: 6856

Including...

#import <objc/objc.h>
#import <objc/runtime.h>

will allow you to have access to modifying the classes and objects at runtime. Although this is rather 'reckless.'

A much better Idea is to use Objective-C Categories for a more 'safe' access.

Upvotes: 1

Joshua Nozzi
Joshua Nozzi

Reputation: 61228

The words you choose and the very broad scope they cover suggest you need to start at the very beginning. There is a simple Cocoa Application tutorial here. It walks you through the basic process of creating a Cocoa application for the Mac. Start there, then post more specific questions as they arise.

Upvotes: 2

Related Questions