Skip to content

matan1008/objc-types-decoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

objc-types-decoder

Python application Pypi version Downloads

A type decoder for Objective-C types.

It translates the encoded Objective-C type notation, the notation that the @encode function returns, into a readable form that tries to be as close as possible to the original type definition.

For example, lets look at the following @encode:

NSLog(@"%s", @encode(float **)); // "^^f" will be printed.

Using our decoder, we can "reverse" the process:

from objc_types_decoder.decode import decode

print(decode('^^f'))  # 'float * *' will be printed.

Installation

In order to install this package, just use a regular pip installation:

pip install objc_types_decoder

Usage

In order to use the decoder, just run the main with your desired encoded type:

>> py -m objc_types_decoder ^f
float *

You can also decode by importing it in your python code:

>> from objc_types_decoder.decode import decode
>> decode('{NSObject=#}')
'struct NSObject { Class x0; }'

Sometimes, you might want to keep the tail of the parsed data. For this case, you can use decode_with_tail.

>> from objc_types_decoder.decode import decode_with_tail
>> decode_with_tail('fyour boat')
('float', 'your boat')