From 4fccb2c8c9673247bfb9ba176021c9889ce680e8 Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Thu, 4 Sep 2025 19:21:48 -0700 Subject: [ObjC] Propagate type information from calls to `[super init]` Calls to `objc_msgSendSuper2` with a selector in the `init` family are detected and their arguments are analyzed to determine the receiver class. A call type adjustment is added to update the return type. This handles most calls to `[super init]` from Objective-C code as the compiler generates a straightforward code sequence for these calls. Some calls from Swift are handled, but the Swift compiler generates more varied code so additional work is needed for complete coverage. --- plugins/workflow_objc/src/workflow.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'plugins/workflow_objc/src/workflow.rs') diff --git a/plugins/workflow_objc/src/workflow.rs b/plugins/workflow_objc/src/workflow.rs index 090a8e5e..f411951b 100644 --- a/plugins/workflow_objc/src/workflow.rs +++ b/plugins/workflow_objc/src/workflow.rs @@ -2,6 +2,14 @@ use binaryninja::workflow::{activity, Activity, AnalysisContext, Workflow}; use crate::{activities, error::WorkflowRegistrationError}; +/// Base confidence levels for types applied by each of the activities in this workflow. +/// These are ordered such that later activities can override types applied by earlier activities. +#[repr(u8)] +pub enum Confidence { + ObjCMsgSend = 96, + SuperInit = 100, +} + const WORKFLOW_INFO: &str = r#"{ "title": "Objective-C", "description": "Enhanced analysis for Objective-C code.", @@ -48,9 +56,23 @@ pub fn register_activities() -> Result<(), WorkflowRegistrationError> { run(activities::inline_stubs::process), ); + let super_init_activity = Activity::new_with_action( + activity::Config::action( + "core.function.objectiveC.types.superInit", + "Obj-C: Adjust return types of [super init…] calls", + "Adjust the return type of calls to objc_msgSendSuper2 where the selector is in the init family.", + ) + .eligibility( + activity::Eligibility::auto().predicate( + activity::ViewType::in_(["Mach-O", "DSCView"]), + )), + run(activities::super_init::process), + ); + workflow .activity_after(&inline_stubs_activity, "core.function.translateTailCalls")? .activity_after(&objc_msg_send_calls_activity, &inline_stubs_activity.name())? + .activity_after(&super_init_activity, "core.function.generateMediumLevelIL")? .register_with_config(WORKFLOW_INFO)?; Ok(()) -- cgit v1.3.1