This repository has been archived by the owner on Jul 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial support for analyzing categories.
- Loading branch information
1 parent
b983689
commit 3daacc9
Showing
8 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include <ObjectiveNinjaCore/Analyzers/ClassAnalyzer.h> | ||
#include <ObjectiveNinjaCore/Analyzers/CategoryAnalyzer.h> | ||
|
||
#include <ObjectiveNinjaCore/TypeParser.h> | ||
|
||
using namespace ObjectiveNinja; | ||
|
||
|
||
CategoryAnalyzer::CategoryAnalyzer(SharedAnalysisInfo info, | ||
SharedAbstractFile file) | ||
: Analyzer(std::move(info), std::move(file)) | ||
{ | ||
} | ||
|
||
MethodListInfo CategoryAnalyzer::analyzeMethodList(uint64_t address) | ||
{ | ||
MethodListInfo mli; | ||
mli.address = address; | ||
mli.flags = m_file->readInt(mli.address); | ||
|
||
auto methodCount = m_file->readInt(mli.address + 0x4); | ||
auto methodSize = mli.hasRelativeOffsets() ? 12 : 24; | ||
|
||
for (unsigned i = 0; i < methodCount; ++i) { | ||
MethodInfo mi; | ||
mi.address = mli.address + 8 + (i * methodSize); | ||
|
||
m_file->seek(mi.address); | ||
|
||
if (mli.hasRelativeOffsets()) { | ||
mi.nameAddress = mi.address + static_cast<int32_t>(m_file->readInt()); | ||
mi.typeAddress = mi.address + 4 + static_cast<int32_t>(m_file->readInt()); | ||
mi.implAddress = mi.address + 8 + static_cast<int32_t>(m_file->readInt()); | ||
} else { | ||
mi.nameAddress = arp(m_file->readLong()); | ||
mi.typeAddress = arp(m_file->readLong()); | ||
mi.implAddress = arp(m_file->readLong()); | ||
} | ||
|
||
if (!mli.hasRelativeOffsets() || mli.hasDirectSelectors()) { | ||
mi.selector = m_file->readStringAt(mi.nameAddress); | ||
} else { | ||
auto selectorNamePointer = arp(m_file->readLong(mi.nameAddress)); | ||
mi.selector = m_file->readStringAt(selectorNamePointer); | ||
} | ||
|
||
mi.type = m_file->readStringAt(mi.typeAddress); | ||
|
||
m_info->methodImpls[mi.nameAddress] = mi.implAddress; | ||
|
||
mli.methods.emplace_back(mi); | ||
} | ||
|
||
return mli; | ||
} | ||
|
||
void CategoryAnalyzer::run() | ||
{ | ||
const auto sectionStart = m_file->sectionStart("__objc_catlist"); | ||
const auto sectionEnd = m_file->sectionEnd("__objc_catlist"); | ||
if (sectionStart == 0 || sectionEnd == 0) | ||
return; | ||
|
||
for (auto address = sectionStart; address < sectionEnd; address += 8) { | ||
CategoryInfo ci; | ||
ci.listPointer = address; | ||
ci.address = arp(m_file->readLong(address)); | ||
ci.nameAddress = arp(m_file->readLong(ci.address)); | ||
ci.name = m_file->readStringAt(ci.nameAddress); | ||
ci.instanceMethodListAddress = arp(m_file->readLong(ci.address + 0x10)); | ||
ci.classMethodListAddress = arp(m_file->readLong(ci.address + 0x18)); | ||
|
||
if (ci.instanceMethodListAddress) | ||
ci.instanceMethods = analyzeMethodList(ci.instanceMethodListAddress); | ||
|
||
if (ci.classMethodListAddress) | ||
ci.classMethods = analyzeMethodList(ci.classMethodListAddress); | ||
|
||
m_info->categories.emplace_back(ci); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2022 Fabian Freyer. All rights reserved. | ||
* | ||
* Use of this source code is governed by the BSD 3-Clause license; the full | ||
* terms of the license can be found in the LICENSE.txt file. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <ObjectiveNinjaCore/Analyzer.h> | ||
|
||
namespace ObjectiveNinja { | ||
|
||
/** | ||
* Analyzer for extracting Objective-C class information. | ||
*/ | ||
class CategoryAnalyzer : public Analyzer { | ||
/** | ||
* Analyze a method list. | ||
*/ | ||
MethodListInfo analyzeMethodList(uint64_t); | ||
|
||
public: | ||
CategoryAnalyzer(SharedAnalysisInfo, SharedAbstractFile); | ||
|
||
void run() override; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters