Repository navigation
Expand file tree
/
Copy pathobjc-raw.lisp
More file actions
349 lines (274 loc) · 9.09 KB
/
Copy pathobjc-raw.lisp
File metadata and controls
349 lines (274 loc) · 9.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
;;;; Raw Obj-C Runtime Bindings
;;; Copyright (C) 2025-2026 The Calendrical System
;;; SPDX-License-Identifier: 0BSD
;;; All symbols are internal, and function arguments are referenced by pointer.
;;; For utility purpose, but also handy :)
;;; Reference: https://developer.apple.com/documentation/objectivec/objective-c-runtime?language=objc
(defpackage "OBJC-RAW"
(:use "CL" "CFFI"))
(in-package "OBJC-RAW")
(eval-when (:compile-toplevel :load-toplevel :execute)
(define-foreign-library cocoa
(:darwin (:framework "Cocoa")))
(define-foreign-library foundation
(:darwin (:framework "Foundation")))
(define-foreign-library appkit
(:darwin (:framework "AppKit"))))
(use-foreign-library foundation)
(use-foreign-library cocoa)
(use-foreign-library appkit)
(defctype objc-class :pointer)
(defctype objc-selector :pointer)
(defctype objc-id :pointer)
(defctype objc-method :pointer)
(defctype objc-protocol :pointer)
(defctype objc-ivar :pointer)
(defctype objc-property :pointer)
(defctype objc-imp :pointer)
(defcstruct objc-property-attribute
(:name :string)
(:value :string))
(defcstruct objc-method-description
(:name :string)
(:types :string))
(defcfun (class-get-name "class_getName" :library foundation)
:string
(cls objc-class))
(defcfun (class-get-superclass "class_getSuperclass" :library foundation)
:pointer
(cls objc-class))
(defcfun (class-is-meta-class "class_isMetaClass" :library foundation)
:boolean
(cls objc-class))
(defcfun (objc-get-instance-size "class_getInstanceSize" :library foundation)
:unsigned-int
(cls objc-class))
(defcfun (class-get-instance-variable "class_getInstanceVariable" :library foundation)
objc-ivar
(cls objc-class)
(name :string))
(defcfun (class-get-class-variable "class_getClassVariable" :library foundation)
objc-ivar
(cls objc-class)
(name :string))
(defcfun (class-add-ivar "class_addIvar" :library foundation)
:boolean
(class :pointer)
(name :string)
(size :ulong)
(alignment :uint8)
(types :string))
(defcfun (class-copy-ivar-list "class_copyIvarList" :library foundation)
(:pointer objc-ivar)
(cls objc-class)
(out-count (:pointer :uint)))
(defcfun (class-get-ivar-layout "class_getIvarLayout" :library foundation)
(:pointer :uint8)
(cls objc-class))
(defcfun (class-set-ivar-layout "class_setIvarLayout" :library foundation)
:void
(cls objc-class)
(layout (:pointer :uint8)))
(defcfun (class-get-weak-ivar-layout "class_getWeakIvarLayout" :library foundation)
(:pointer :uint8)
(cls objc-class))
(defcfun (class-set-weak-ivar-layout "class_setWeakIvarLayout" :library foundation)
:void
(cls objc-class)
(layout (:pointer :uint8)))
(defcfun (class-get-property "class_getProperty" :library foundation)
objc-property
(cls objc-class)
(name :string))
(defcfun (class-copy-property-list "class_copyPropertyList" :library foundation)
:pointer
(cls objc-class)
(out-count (:pointer :uint)))
(defcfun (class-add-method "class_addMethod" :library foundation)
:boolean
(cls objc-class)
(name objc-selector)
(imp objc-imp)
(types :string))
(defcfun (class-get-instance-method "class_getInstanceMethod" :library foundation)
objc-method
(cls objc-class)
(name objc-selector))
(defcfun (class-get-class-method "class_getClassMethod" :library foundation)
objc-method
(cls objc-class)
(name objc-selector))
(defcfun (class-copy-method-list "class_copyMethodList" :library foundation)
:pointer
(cls objc-class)
(out-count (:pointer :uint)))
(defcfun (class-replace-method "class_replaceMethod" :library foundation)
objc-imp
(cls objc-class)
(name objc-selector)
(imp objc-imp)
(types :string))
(defcfun (class-get-method-implementation "class_getMethodImplementation" :library foundation)
;; WTF is the class_getMethodImplementation_stret ?
objc-imp
(cls objc-class)
(name objc-selector))
(defcfun (class-responds-to-selector "class_respondsToSelector" :library foundation)
:boolean
(cls objc-class)
(selector objc-selector))
(defcfun (class-add-property "class_addProperty" :library foundation)
:pointer
(cls objc-class)
(name :string)
(attributes (:pointer (:struct objc-property-attribute)))
(attribute-count :unsigned-int))
(defcfun (class-replace-property "class_replaceProperty" :library foundation)
:void
(cls objc-class)
(name :string)
(attributes (:pointer (:struct objc-property-attribute)))
(attribute-count :unsigned-int))
(defcfun (class-get-version "class_getVersion" :library foundation)
:int
(cls objc-class))
(defcfun (class-set-version "class_setVersion" :library foundation)
:void
(cls objc-class)
(version :int))
(defcfun (class-create-instance "class_createInstance" :library foundation)
objc-id
(cls objc-class)
(extra-bytes :uint))
(defcfun (objc-allocate-class-pair "objc_allocateClassPair" :library foundation)
objc-class
(superclass objc-class)
(name :string)
(extra-bytes :uint))
(defcfun (objc-dispose-class-pair "objc_disposeClassPair" :library foundation)
:void
(cls objc-class))
(defcfun (objc-register-class-pair "objc_registerClassPair" :library foundation)
:void
(cls objc-class))
(defcfun (objc-duplicate-class-pair "objc_duplicateClassPair" :library foundation)
objc-class
(original objc-class)
(name :string)
(extra-bytes :uint))
(defcfun (object-get-indexed-ivar "object_getIndexedIvars" :library foundation)
:void
(obj objc-id))
(defcfun (object-get-ivar "object_getIvar" :library foundation)
objc-id
(obj objc-id)
(ivar objc-ivar))
(defcfun (object-set-ivar "object_setIvar" :library foundation)
:void
(obj objc-id)
(ivar objc-ivar)
(value objc-id))
(defcfun (object-get-class-name "object_getClassName" :library foundation)
:string
(obj objc-id))
(defcfun (object-get-class "object_getClass" :library foundation)
objc-class
(obj objc-id))
(defcfun (object-set-class "object_setClass" :library foundation)
objc-class
(obj objc-id)
(cls objc-class))
(defcfun (objc-copy-class-list "objc_copyClassList" :library foundation)
objc-class
(out-count (:pointer :uint)))
(defcfun (objc-lookup-class "objc_lookUpClass" :library foundation)
objc-class
(name :string))
(defcfun (objc-get-class "objc_getClass" :library foundation)
objc-id
(name :string))
(defcfun (objc-get-required-class "objc_getRequiredClass" :library foundation)
objc-class
(name :string))
(defcfun (objc-get-meta-class "objc_getMetaClass" :library foundation)
objc-class
(name :string))
(defcfun (ivar-get-name "ivar_getName" :library foundation)
:string
(var objc-ivar))
(defcfun (ivar-get-type-encoding "ivar_getTypeEncoding" :library foundation)
:string
(var objc-ivar))
(defcfun (ivar-get-offset "ivar_getOffset" :library foundation)
:pointer
(var objc-ivar))
;; objc_setAssociatedObject
;; objc_getAssociatedObject
;; objc_removeAssociatedObjects
(defcfun (method-get-name "method_getName" :library foundation)
objc-selector
(method objc-method))
(defcfun (method-get-implementation "method_getImplementation" :library foundation)
objc-imp
(method objc-method))
(defcfun (method-get-type-encoding "method_getTypeEncoding" :library foundation)
:string
(method objc-method))
(defcfun (method-copy-return-type "method_copyReturnType" :library foundation)
:string
(method objc-method))
(defcfun (method-copy-argument-type "method_copyArgumentType" :library foundation)
:string
(method objc-method)
(index :uint))
;; method_getReturnType
(defcfun (method-get-number-of-arguments "method_getNumberOfArguments" :library foundation)
:uint
(method objc-method))
;; method_getArgumentType
;; method_getDescription
(defcfun (method-set-implementation "method_setImplementation" :library foundation)
objc-imp
(method objc-method)
(imp objc-imp))
(defcfun (method-exchange-implementation "method_exchangeImplementation" :library foundation)
:void
(method1 objc-method)
(method2 objc-method))
;; objc_copyImageNames
;; class_getImageName
;; objc_copyClassNamesForImage
(defcfun (sel-get-name "sel_getName" :library foundation)
:string
(sel objc-selector))
(defcfun (sel-register-name "sel_registerName" :library foundation)
objc-selector
(name :string))
(defcfun (sel-get-uid "sel_getUid" :library foundation)
objc-selector
(str :string))
;; sel_isEqual
(defcfun (property-get-name "property_getName" :library foundation)
:string
(prop objc-property))
(defcfun (property-copy-attribute-value "property_copyAttributeValue" :library foundation)
:string
(prop objc-property)
(name :string))
(defcfun (property-get-attributes "property_getAttributes" :library foundation)
:string
(prop objc-property))
(defcfun (property-copy-attribute-list "property_copyAttributeList" :library foundation)
(:pointer (:struct objc-property-attribute))
(prop objc-property)
(out-count (:pointer :uint)))
(defcfun (objc-msg-send "objc_msgSend" :library foundation)
:pointer
(instance objc-id)
(selector objc-selector)
&rest)
(defcfun (method-invoke "method_invoke" :library foundation)
:pointer
(object objc-id)
(method objc-method)
&rest)