summaryrefslogtreecommitdiff
path: root/examples/workflows/objectivec/objectivec.cpp
diff options
context:
space:
mode:
authorBrian Potchik <brian@vector35.com>2021-08-25 22:59:50 -0400
committerBrian Potchik <brian@vector35.com>2021-08-25 22:59:50 -0400
commit84124764143d4f35961e2c61494d97640ac7f99f (patch)
tree0b1f18b04daa79f5e83b297dbea2510fdd7b52a8 /examples/workflows/objectivec/objectivec.cpp
parent11ca2c9f4057e00a69a87e77376ff8c0b2e44830 (diff)
Update workflows c++ examples.
Diffstat (limited to 'examples/workflows/objectivec/objectivec.cpp')
-rw-r--r--examples/workflows/objectivec/objectivec.cpp33
1 files changed, 20 insertions, 13 deletions
diff --git a/examples/workflows/objectivec/objectivec.cpp b/examples/workflows/objectivec/objectivec.cpp
index e967c5e3..f6cc4e47 100644
--- a/examples/workflows/objectivec/objectivec.cpp
+++ b/examples/workflows/objectivec/objectivec.cpp
@@ -25,6 +25,10 @@ extern "C"
{
BN_DECLARE_CORE_ABI_VERSION
+ // TODO: Replace with analysis cache opaque datastore.
+ std::mutex g_mutex;
+ unordered_map<void*, unordered_map<uint64_t, tuple<string, uint64_t>>> g_classData;
+
// TODO
// * __objc_const missing xrefs to implementations
void ObjectiveCAnalysis(Ref<AnalysisContext> analysisContext)
@@ -32,9 +36,10 @@ extern "C"
Ref<Function> function = analysisContext->GetFunction();
Ref<BinaryView> data = function->GetView();
- static unordered_map<uint64_t, tuple<string, uint64_t>> classData;
- static bool sInit = false;
- if (!sInit) // TODO move to module-based workflow activity with run-once semantics
+ // TODO 1) Move this to run-once workflow activity 2) stash data in analysis cache opaque datastore.
+ std::unique_lock<std::mutex> lock(g_mutex);
+ auto gItr = g_classData.find(data->GetObject());
+ if (gItr == g_classData.end())
{
auto constSection = data->GetSectionByName("__objc_const");
if (!constSection)
@@ -64,25 +69,27 @@ extern "C"
uint64_t impPtr = reader.Read64();
//string methodName = reader.ReadCString(selector);
string typeEncoding = "";//reader.ReadCString(typePtr);
- classData.insert_or_assign(selector, std::forward_as_tuple(typeEncoding, impPtr));
+ g_classData[data->GetObject()].insert_or_assign(selector, std::forward_as_tuple(typeEncoding, impPtr));
}
- reader.Seek(namePtr);
- string className = reader.ReadCString();
-
- auto cfStringSection = data->GetSectionByName("__cfstring");
- if (!cfStringSection)
- return;
+ // TODO cfstring
+ // reader.Seek(namePtr);
+ // string className = reader.ReadCString();
- sInit = true;
+ // auto cfStringSection = data->GetSectionByName("__cfstring");
+ // if (!cfStringSection)
+ // return;
}
+ auto& classData = gItr->second;
+ lock.unlock();
+
bool updated = false;
uint8_t opcode[BN_MAX_INSTRUCTION_LENGTH];
InstructionInfo iInfo;
- // // if (m_owner->IsAborted())
- // // return;
+ // if (m_owner->IsAborted())
+ // return;
// TODO fix this....
auto sym = data->GetSymbolByRawName("_objc_msgSend");