DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Languages
  4. Objective C vs. C/C++: Getting the Message

Objective C vs. C/C++: Getting the Message

A dev who works regularly with C/C++ examines how these languages differ from Objective-C and the implications of these differences.

Christopher Lamb user avatar by
Christopher Lamb
CORE ·
Apr. 09, 19 · Analysis
Like (4)
Save
Tweet
Share
11.17K Views

Join the DZone community and get the full member experience.

Join For Free

Most of the time, working in cybersecurity, when we're reverse engineering an application we're working either with C or C++. Both of these languages use function semantics for method or function calls. Objective C is different — instead of using function semantics, where you use a 'call' instruction to pass program execution and state to a specific section of memory, Objective C uses message passing semantics. Let's explore exactly what that is, and how it differs from function semantics. We'll start by outlining exactly what function semantics are and how they work. To do that, we'll need to outline use of the call instruction and name mangling in C++.

C code is pretty straightforward to analyze. A function call in C will look something like this:

call 0xffdf1342

Just a call instruction and an address. Now in a program, this could be an address in the program (for a local procedure) or an address in a global offset table (or similar construct) to access a shared library function. Either way, CALL does some very specific things — like JMP, CALL will begin execution at the location pointed to by the submitted address. It will also set up the stack prior to the call using conventions specific to the target processor architecture. This includes saving execution state in registers, the stack, or some combination thereof.

C++ code works similarly — class methods are called by address. There are additional complexities around checking the object vtable and how the class information is saved in a compiled function name (via that name mangling feature I mentioned), but the key point is that C++ code still uses function calls for class methods.

Objective C doesn't.

Objective C uses message passing instead of function calls. This increases the run-time cost of a given method invocation, usually a negligible amount, but in exchange provides a large amount of flexibility. A call into (or a message to) a given object makes a call into the Objective-C runtime using the function objc_msgSend(id self, SEL op, ...) where self is the object to which the message will be sent and the submitted selector (SEL) is the message itself. This provides some interesting capabilities and additional NULL safety. obj_msgSend(.) is a function that is always available to any Objective C program as it's supplied by the runtime itself. Because of this, you will never have a NULL pointer exception raised when passing a message to another class object as objc_msgSend(.) can implement protections against these kinds of errors. objc_msgSendcan validate data passed through the argument list as well.

You can also hook objc_msgSend. This allows you to inject arbitrary behavior into an application at runtime. You can use this to trace messages in a program, for example.

Objective C is not only different syntactically, it is different in essential design. Swift is interesting as well, as it's designed and implemented using concepts from Objective C (and is backward compatible with it). 

Objective C Objective-C++

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Iptables Basic Commands for Novice
  • How Do the Docker Client and Docker Servers Work?
  • Real-Time Stream Processing With Hazelcast and StreamNative
  • Fraud Detection With Apache Kafka, KSQL, and Apache Flink

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: