forked from Vector35/workflow_objc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCommands.cpp
68 lines (55 loc) · 2.26 KB
/
Commands.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Copyright (c) 2022-2023 Jon Palmisciano. 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.
*/
#include "Commands.h"
#include "Constants.h"
#include "CustomTypes.h"
#include "GlobalState.h"
#include "InfoHandler.h"
#include "Performance.h"
#include "Core/AnalysisProvider.h"
#include "Core/BinaryViewFile.h"
void Commands::defineTypes(BinaryViewRef bv)
{
CustomTypes::defineAll(std::move(bv));
}
void Commands::analyzeStructures(BinaryViewRef bv)
{
if (GlobalState::hasFlag(bv, Flag::DidRunWorkflow)
|| GlobalState::hasFlag(bv, Flag::DidRunStructureAnalysis)) {
auto result = BinaryNinja::ShowMessageBox("Error",
"Structure analysis has already been performed on this binary. "
"Repeated analysis may cause unexpected behavior.* Continue?\n\n"
"*If you undid analysis, this message can be safely ignored.",
BNMessageBoxButtonSet::YesNoButtonSet,
BNMessageBoxIcon::QuestionIcon);
if (result != BNMessageBoxButtonResult::YesButton)
return;
}
SharedAnalysisInfo info;
CustomTypes::defineAll(bv);
try {
auto file = std::make_shared<ObjectiveNinja::BinaryViewFile>(bv);
auto start = Performance::now();
info = ObjectiveNinja::AnalysisProvider::infoForFile(file);
auto elapsed = Performance::elapsed<std::chrono::milliseconds>(start);
const auto log = BinaryNinja::LogRegistry::GetLogger(PluginLoggerName);
log->LogInfo("Structures analyzed in %lu ms", elapsed.count());
InfoHandler::applyInfoToView(info, bv);
} catch (...) {
const auto log = BinaryNinja::LogRegistry::GetLogger(PluginLoggerName);
log->LogError("Structure analysis failed; binary may be malformed.");
log->LogError("Objective-C analysis will not be applied due to previous errors.");
}
GlobalState::setFlag(bv, Flag::DidRunStructureAnalysis);
}
void Commands::registerCommands()
{
BinaryNinja::PluginCommand::Register("Objective-C \\ Define Types",
"", Commands::defineTypes);
BinaryNinja::PluginCommand::Register("Objective-C \\ Analyze Structures",
"", Commands::analyzeStructures);
}