Skip to content

Commit

Permalink
Gate ARC Cleanup behind a setting (default true)
Browse files Browse the repository at this point in the history
  • Loading branch information
0cyn committed Apr 10, 2023
1 parent faaa543 commit a4465a1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions MessageHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const std::set<std::string> arcFunctionNames = {
MessageHandler::MessageHandler(Ref<BinaryView> data)
: m_data(data)
{
m_shouldCleanupARCCode = BinaryNinja::Settings::Instance()->Get<bool>("objc.cleanupARCCode");

std::unique_lock<std::recursive_mutex> lock(m_stubMutex);

m_authStubsSection = data->GetSectionByName("__auth_stubs");
Expand Down
3 changes: 3 additions & 0 deletions MessageHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
class MessageHandler : public BinaryNinja::BinaryDataNotification {

BinaryNinja::Ref<BinaryNinja::BinaryView> m_data;
bool m_shouldCleanupARCCode;

BinaryNinja::Ref<BinaryNinja::Section> m_authStubsSection;
BinaryNinja::Ref<BinaryNinja::Section> m_stubsSection;
Expand Down Expand Up @@ -32,6 +33,8 @@ class MessageHandler : public BinaryNinja::BinaryDataNotification {

void functionWasAnalyzed(uint64_t addr);

bool ShouldCleanupARCCode() const { return m_shouldCleanupARCCode; }

std::set<uint64_t> getMessageSendFunctions() const { return m_msgSendFunctions; }
bool hasMessageSendFunctions() const { return m_msgSendFunctions.size() != 0; }
bool isMessageSend(uint64_t);
Expand Down
12 changes: 12 additions & 0 deletions Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ BINARYNINJAPLUGIN bool CorePluginInit()
Workflow::registerActivities();
Commands::registerCommands();

BinaryNinja::Ref<BinaryNinja::Settings> settings = BinaryNinja::Settings::Instance();
settings->RegisterGroup("objc", "Objective-C");

settings->RegisterSetting("objc.cleanupARCCode",
R"({
"title" : "ARC Cleanup",
"type" : "boolean",
"default" : true,
"description" : "Remove ARC related code, i.e. calls to _objc_release, _objc_retain, and other ARC functions, from ILs"
})");


std::vector<BinaryNinja::Ref<BinaryNinja::Architecture>> targets = {
BinaryNinja::Architecture::GetByName("aarch64"),
BinaryNinja::Architecture::GetByName("x86_64")
Expand Down
2 changes: 1 addition & 1 deletion Workflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void Workflow::inlineMethodCalls(AnalysisContextRef ac)
&& params[0].operation == LLIL_REG_SSA
&& params[1].operation == LLIL_REG_SSA)
rewriteMethodCall(ssa, insnIndex);
} else if (messageHandler->isARCFunction(callExpr.GetValue().value)) {
} else if (messageHandler->isARCFunction(callExpr.GetValue().value) && messageHandler->ShouldCleanupARCCode()) {
auto nonSSAIdx = ssa->GetNonSSAInstructionIndex(insnIndex);
auto targetInsn = llil->GetInstruction(nonSSAIdx);
if (insn.operation == LLIL_CALL_SSA)
Expand Down

0 comments on commit a4465a1

Please sign in to comment.