This repository was archived by the owner on Jul 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Initial support for analyzing categories. #45
Draft
fabianfreyer
wants to merge
1
commit into
jonpalmisc:dev
Choose a base branch
from
fabianfreyer:categories
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary |
||
| #include <ObjectiveNinjaCore/Analyzers/CategoryAnalyzer.h> | ||
|
|
||
| #include <ObjectiveNinjaCore/TypeParser.h> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also unnecessary to |
||
|
|
||
| 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is also missing a copyright header