Skip to content

Commit 7cd96ee

Browse files
committed
[SharedCache] Refactor Shared Cache
In absence of a better name, this commit refactors the shared cache code.
1 parent 7f255c9 commit 7cd96ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+7521
-9370
lines changed

docs/dev/workflows.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ You can query the list of all registered workflows or filter them by type using
145145
# List all Module and Function workflows
146146
list(Workflow)
147147
[<Workflow: core.function.baseAnalysis>,
148-
<Workflow: core.function.dsc>,
148+
<Workflow: core.function.sharedCache>,
149149
<Workflow: core.function.metaAnalysis>,
150150
<Workflow: core.function.objectiveC>,
151151
<Workflow: core.module.baseAnalysis>,
@@ -157,7 +157,7 @@ Settings().query_property_string_list("analysis.workflows.moduleWorkflow", "enum
157157

158158
# List all function workflows from the Settings API
159159
>>> Settings().query_property_string_list("analysis.workflows.functionWorkflow", "enum")
160-
['core.function.baseAnalysis', 'core.function.dsc', 'core.function.metaAnalysis', 'core.function.objectiveC']
160+
['core.function.baseAnalysis', 'core.function.sharedCache', 'core.function.metaAnalysis', 'core.function.objectiveC']
161161
```
162162

163163
Once you've queried the available workflows, you can create your own by cloning and modifying an existing workflow. Below are some simple examples that demonstrate how to modify module-level analysis.

objectivec/objc.cpp

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,12 +1509,22 @@ void ObjCProcessor::ProcessCFStrings(std::optional<std::string> imageName)
15091509
uint8_t* rawData = static_cast<uint8_t*>(data.GetData());
15101510
uint8_t* offsetAddress = rawData + bufferOff;
15111511
uint16_t c = *reinterpret_cast<uint16_t*>(offsetAddress);
1512-
if (c == 0x20)
1512+
if (c == 0x20) {
15131513
str.push_back('_');
1514-
else if (c < 0x80)
1514+
} else if (c == '\r') {
1515+
str.push_back('\\');
1516+
str.push_back('r');
1517+
} else if (c == '\n') {
1518+
str.push_back('\\');
1519+
str.push_back('n');
1520+
} else if (c == '\t') {
1521+
str.push_back('\\');
1522+
str.push_back('t');
1523+
} else if (c > 0x20 && c < 0x80) {
15151524
str.push_back(c);
1516-
else
1525+
} else {
15171526
str.push_back('?');
1527+
}
15181528
}
15191529
DefineObjCSymbol(
15201530
DataSymbol, Type::ArrayType(Type::WideCharType(2), size + 1), "ustr_" + str, strLoc, true);
@@ -1524,11 +1534,26 @@ void ObjCProcessor::ProcessCFStrings(std::optional<std::string> imageName)
15241534
else // UTF8 / ASCII
15251535
{
15261536
reader->Seek(strLoc);
1527-
str = reader->ReadCString();
1528-
for (auto& c : str)
1537+
std::string rawStr = reader->ReadCString(size + 1);
1538+
str = "";
1539+
for (signed char c : rawStr)
15291540
{
1530-
if (c == ' ')
1531-
c = '_';
1541+
if (c == 0x20) {
1542+
str.push_back('_');
1543+
} else if (c == '\r') {
1544+
str.push_back('\\');
1545+
str.push_back('r');
1546+
} else if (c == '\n') {
1547+
str.push_back('\\');
1548+
str.push_back('n');
1549+
} else if (c == '\t') {
1550+
str.push_back('\\');
1551+
str.push_back('t');
1552+
} else if (c > 0x20 || c < 0) {
1553+
str.push_back(c);
1554+
} else {
1555+
str.push_back('?');
1556+
}
15321557
}
15331558
DefineObjCSymbol(DataSymbol, Type::ArrayType(Type::IntegerType(1, true), str.size() + 1), "cstr_" + str,
15341559
strLoc, true);

objectivec/objc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ namespace BinaryNinja {
166166
\throws Exception
167167
\return the string
168168
*/
169-
virtual std::string ReadCString() = 0;
169+
virtual std::string ReadCString(size_t maxLength = -1) = 0;
170170

171171
/*! Read a uint8_t from the current cursor position and advance the cursor by 1 byte
172172

view/macho/objc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ void MachoObjCReader::Read(void* dest, size_t len)
1111
m_reader.Read(dest, len);
1212
}
1313

14-
std::string MachoObjCReader::ReadCString()
14+
std::string MachoObjCReader::ReadCString(size_t maxLength)
1515
{
16-
return m_reader.ReadCString();
16+
return m_reader.ReadCString(maxLength);
1717
}
1818

1919
uint8_t MachoObjCReader::Read8()

view/macho/objc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace BinaryNinja {
1010

1111
public:
1212
void Read(void* dest, size_t len) override;
13-
std::string ReadCString() override;
13+
std::string ReadCString(size_t maxLength = -1) override;
1414
uint8_t Read8() override;
1515
uint16_t Read16() override;
1616
uint32_t Read32() override;

view/sharedcache/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ endif()
3333
set(HARD_FAIL_MODE OFF CACHE BOOL "Enable hard fail mode")
3434
set(SLIDEINFO_DEBUG_TAGS OFF CACHE BOOL "Enable debug tags in slideinfo")
3535
set(VIEW_NAME "DSCView" CACHE STRING "Name of the view")
36+
# TODO: Remove this, if we want to keep a metadata version around we must have this in the source.
3637
set(METADATA_VERSION 5 CACHE STRING "Version of the metadata")
3738

3839
add_subdirectory(core)

view/sharedcache/HeadlessPlugin.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include <binaryninjaapi.h>
2-
#include "DSCView.h"
3-
#include "SharedCache.h"
2+
#include "SharedCacheView.h"
43

54
#ifdef __cplusplus
6-
extern "C" {
5+
extern "C"
6+
{
77
#endif
88
extern void RegisterSharedCacheWorkflow();
99
#ifdef __cplusplus
@@ -16,7 +16,7 @@ extern "C"
1616

1717
BINARYNINJAPLUGIN bool CorePluginInit()
1818
{
19-
InitDSCViewType();
19+
SharedCacheViewType::Register();
2020
RegisterSharedCacheWorkflow();
2121
return true;
2222
}

0 commit comments

Comments
 (0)