summaryrefslogtreecommitdiff
path: root/examples/workflows
diff options
context:
space:
mode:
authorKyleMiles <krm504@nyu.edu>2022-01-27 22:43:28 -0500
committerKyleMiles <krm504@nyu.edu>2022-01-28 00:24:06 -0500
commit6812c973c9fa9b4ad642ab81856c05f87bd6fcc4 (patch)
treedace4156d03148bcaf02df138ab4e0d93e61bc6f /examples/workflows
parent519c9db22367f2659d1a54599fab47e6313be06e (diff)
Format All Files
Diffstat (limited to 'examples/workflows')
-rw-r--r--examples/workflows/inliner/inliner.cpp32
-rw-r--r--examples/workflows/objectivec/objectivec.cpp25
-rw-r--r--examples/workflows/tailcall/tailcall.cpp14
3 files changed, 41 insertions, 30 deletions
diff --git a/examples/workflows/inliner/inliner.cpp b/examples/workflows/inliner/inliner.cpp
index 4ce05a31..da54fbc2 100644
--- a/examples/workflows/inliner/inliner.cpp
+++ b/examples/workflows/inliner/inliner.cpp
@@ -18,7 +18,7 @@ using namespace BinaryNinja;
using namespace std;
#if defined(_MSC_VER)
-#define snprintf _snprintf
+ #define snprintf _snprintf
#endif
@@ -68,7 +68,8 @@ extern "C"
if (instr.operation != LLIL_CALL)
{
- LogWarn("Failed to inline function at: 0x%" PRIx64 ". Mapping to LLIL_CALL Failed!", instr.address);
+ LogWarn(
+ "Failed to inline function at: 0x%" PRIx64 ". Mapping to LLIL_CALL Failed!", instr.address);
continue;
}
@@ -79,14 +80,17 @@ extern "C"
platformAddr = target.value;
else
{
- LogWarn("Failed to inline function at: 0x%" PRIx64 ". Destination not Constant!", instr.address);
+ LogWarn(
+ "Failed to inline function at: 0x%" PRIx64 ". Destination not Constant!", instr.address);
continue;
}
size_t opLen = data->Read(opcode, instr.address, arch->GetMaxInstructionLength());
if (!opLen || !arch->GetInstructionInfo(opcode, instr.address, opLen, iInfo))
continue;
- Ref<Platform> platform = iInfo.archTransitionByTargetAddr ? function->GetPlatform()->GetAssociatedPlatformByAddress(platformAddr) : function->GetPlatform();
+ Ref<Platform> platform = iInfo.archTransitionByTargetAddr ?
+ function->GetPlatform()->GetAssociatedPlatformByAddress(platformAddr) :
+ function->GetPlatform();
if (platform)
{
Ref<Function> targetFunc = data->GetAnalysisFunction(platform, platformAddr);
@@ -145,21 +149,21 @@ extern "C"
// }, inlinerIsValid);
PluginCommand::RegisterForFunction(
- "Optimizer\\Inline Function at Current Call Site",
- "Inline function call at current call site.",
- [](BinaryView* view, Function* func) {
- // TODO func->Inform("inlinedCallSites")
- // TODO resolve multiple embedded inlines
- std::lock_guard<std::mutex> lock(g_mutex);
- g_callSiteInlines[view->GetObject()][func->GetStart()].insert(view->GetCurrentOffset());
- func->Reanalyze();
- }, inlinerIsValid);
+ "Optimizer\\Inline Function at Current Call Site", "Inline function call at current call site.",
+ [](BinaryView* view, Function* func) {
+ // TODO func->Inform("inlinedCallSites")
+ // TODO resolve multiple embedded inlines
+ std::lock_guard<std::mutex> lock(g_mutex);
+ g_callSiteInlines[view->GetObject()][func->GetStart()].insert(view->GetCurrentOffset());
+ func->Reanalyze();
+ },
+ inlinerIsValid);
Ref<Workflow> inlinerWorkflow = Workflow::Instance()->Clone("InlinerWorkflow");
inlinerWorkflow->RegisterActivity(new Activity("extension.functionInliner", &FunctionInliner));
inlinerWorkflow->Insert("core.function.translateTailCalls", "extension.functionInliner");
Workflow::RegisterWorkflow(inlinerWorkflow,
- R"#({
+ R"#({
"title" : "Function Inliner (Example)",
"description" : "This analysis stands in as an example to demonstrate Binary Ninja's extensible analysis APIs. ***Note** this feature is under active development and subject to change without notice.",
"capabilities" : []
diff --git a/examples/workflows/objectivec/objectivec.cpp b/examples/workflows/objectivec/objectivec.cpp
index b3272f94..b5ce26c1 100644
--- a/examples/workflows/objectivec/objectivec.cpp
+++ b/examples/workflows/objectivec/objectivec.cpp
@@ -17,7 +17,7 @@ using namespace BinaryNinja;
using namespace std;
#if defined(_MSC_VER)
-#define snprintf _snprintf
+ #define snprintf _snprintf
#endif
@@ -46,7 +46,7 @@ extern "C"
return;
BinaryReader reader(data);
- reader.SetEndianness(data->GetDefaultEndianness()); // TODO fix GetDefaultEndianness for non-elf formats
+ reader.SetEndianness(data->GetDefaultEndianness()); // TODO fix GetDefaultEndianness for non-elf formats
reader.Seek(constSection->GetStart());
reader.Read32();
@@ -62,13 +62,13 @@ extern "C"
reader.Read64();
uint32_t methodListFlags = reader.Read32();
uint32_t methodListCount = reader.Read32();
- for (uint32_t i = 0; i < methodListCount; i++) // section end/symbol validation
+ for (uint32_t i = 0; i < methodListCount; i++) // section end/symbol validation
{
uint64_t selector = reader.Read64();
uint64_t typePtr = reader.Read64();
uint64_t impPtr = reader.Read64();
- //string methodName = reader.ReadCString(selector);
- string typeEncoding = "";//reader.ReadCString(typePtr);
+ // string methodName = reader.ReadCString(selector);
+ string typeEncoding = ""; // reader.ReadCString(typePtr);
g_classData[data->GetObject()].insert_or_assign(selector, std::forward_as_tuple(typeEncoding, impPtr));
}
@@ -118,11 +118,13 @@ extern "C"
if (msgSendAddr == (uint64_t)destExpr.GetValue().value)
{
auto params = instr.GetParameterExprs<LLIL_CALL_SSA>();
- if ((params.size() >= 2) && (params[0].operation == LLIL_REG_SSA) && (params[1].operation == LLIL_REG_SSA))
+ if ((params.size() >= 2) && (params[0].operation == LLIL_REG_SSA)
+ && (params[1].operation == LLIL_REG_SSA))
{
auto selfSSAReg = params[0].GetSourceSSARegister<LLIL_REG_SSA>();
auto selSSAReg = params[1].GetSourceSSARegister<LLIL_REG_SSA>();
- if (auto itr = classData.find(ssa->GetSSARegisterValue(selSSAReg).value); itr != classData.end())
+ if (auto itr = classData.find(ssa->GetSSARegisterValue(selSSAReg).value);
+ itr != classData.end())
{
size_t llilIndex = ssa->GetNonSSAInstructionIndex(instrIndex);
LowLevelILInstruction llilInstr = llilFunc->GetInstruction(llilIndex);
@@ -130,12 +132,13 @@ extern "C"
const auto& [typeEncoding, impPtr] = itr->second;
destExpr.Replace(llilFunc->ConstPointer(destExpr.size, impPtr, destExpr));
llilInstr.Replace(llilFunc->Call(destExpr.exprIndex, llilInstr));
- analysisContext->Inform("directRefs", "insert", impPtr, i->GetArchitecture(), instr.address);
+ analysisContext->Inform(
+ "directRefs", "insert", impPtr, i->GetArchitecture(), instr.address);
updated = true;
}
// else
- // LogError("ObjectiveC Workflow: missing classData for __objc_methname entry: 0x%" PRIx64 " at: 0x%" PRIx64,
- // ssa->GetSSARegisterValue(selSSAReg).value, instr.address);
+ // LogError("ObjectiveC Workflow: missing classData for __objc_methname entry: 0x%" PRIx64 "
+ // at: 0x%" PRIx64, ssa->GetSSARegisterValue(selSSAReg).value, instr.address);
}
// else
// LogError("Unhandled _objc_msgSend: 0x%" PRIx64, instr.address);
@@ -157,7 +160,7 @@ extern "C"
objectiveCWorkflow->RegisterActivity(new Activity("extension.objectiveC", &ObjectiveCAnalysis));
objectiveCWorkflow->Insert("core.function.translateTailCalls", "extension.objectiveC");
Workflow::RegisterWorkflow(objectiveCWorkflow,
- R"#({
+ R"#({
"title" : "Objective C Meta-Analysis (Example)",
"description" : "This analysis stands in as an example to demonstrate Binary Ninja's extensible analysis APIs. ***Note** this feature is under active development and subject to change without notice.",
"capabilities" : []
diff --git a/examples/workflows/tailcall/tailcall.cpp b/examples/workflows/tailcall/tailcall.cpp
index 3d8613c4..01190987 100644
--- a/examples/workflows/tailcall/tailcall.cpp
+++ b/examples/workflows/tailcall/tailcall.cpp
@@ -17,7 +17,7 @@ using namespace BinaryNinja;
using namespace std;
#if defined(_MSC_VER)
-#define snprintf _snprintf
+ #define snprintf _snprintf
#endif
@@ -52,7 +52,8 @@ extern "C"
RegisterValue target = destExpr.GetValue();
if (target.IsConstant())
platformAddr = target.value;
- else if (target.state == ImportedAddressValue) // Call to imported function, look up type from import symbol
+ else if (target.state
+ == ImportedAddressValue) // Call to imported function, look up type from import symbol
platformAddr = target.value;
else if (target.state == ExternalPointerValue && target.offset == 0)
platformAddr = target.value;
@@ -62,7 +63,9 @@ extern "C"
size_t opLen = data->Read(opcode, instr.address, arch->GetMaxInstructionLength());
if (!opLen || !arch->GetInstructionInfo(opcode, instr.address, opLen, iInfo))
continue;
- Ref<Platform> platform = iInfo.archTransitionByTargetAddr ? function->GetPlatform()->GetAssociatedPlatformByAddress(platformAddr) : function->GetPlatform();
+ Ref<Platform> platform = iInfo.archTransitionByTargetAddr ?
+ function->GetPlatform()->GetAssociatedPlatformByAddress(platformAddr) :
+ function->GetPlatform();
if (platform)
{
bool canReturn = true;
@@ -72,7 +75,8 @@ extern "C"
DataVariable var;
if (data->GetDataVariableAtAddress(target.value, var))
{
- if (var.type && (var.type->GetClass() == PointerTypeClass) && (var.type->GetChildType()->GetClass() == FunctionTypeClass))
+ if (var.type && (var.type->GetClass() == PointerTypeClass)
+ && (var.type->GetChildType()->GetClass() == FunctionTypeClass))
canReturn = var.type->GetChildType()->CanReturn().GetValue();
}
}
@@ -119,7 +123,7 @@ extern "C"
customTailCallWorkflow->Replace("core.function.translateTailCalls", "extension.translateTailCalls");
customTailCallWorkflow->Remove("core.function.translateTailCalls");
Workflow::RegisterWorkflow(customTailCallWorkflow,
- R"#({
+ R"#({
"title" : "Tail Call Translation (Example)",
"description" : "This analysis stands in as an example to demonstrate Binary Ninja's extensible analysis APIs. ***Note** this feature is under active development and subject to change without notice.",
"capabilities" : []