Skip to content

Commit 51a4ad7

Browse files
committed
wip
1 parent b34ce6f commit 51a4ad7

File tree

4 files changed

+17
-33
lines changed

4 files changed

+17
-33
lines changed

view/sharedcache/core/SharedCacheController.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,29 +144,24 @@ bool SharedCacheController::IsRegionLoaded(const CacheRegion &region) const
144144

145145
bool SharedCacheController::LoadImage(BinaryView& view, const CacheImage& image)
146146
{
147-
view.BeginBulkAddSegments();
148147
// TODO: Check m_loadedImages? This seems redundant...
149148
// TODO: Will this load the header for the image as well?
150149
// Load all regions of an image and mark the image as loaded.
151150
bool loadedRegion = false;
152151
for (const auto& regionStart : image.regionStarts)
153152
if (LoadRegionAtAddress(view, regionStart))
154153
loadedRegion = true;
155-
view.EndBulkAddSegments();
156154

157155
// If there was no loaded regions than we just want to forgo loading the image.
158156
if (!loadedRegion)
159157
return false;
160158

161159
// TODO: This is at the entry level, we must have some accessor on the file that can do this for us.
162-
auto base = m_cache.GetBaseAddress();
163160
auto entry = m_cache.GetEntryWithImage(image);
164161
if (!entry.has_value())
165162
return false;
166163

167-
view.BeginBulkModifySymbols();
168-
169-
SlideInfoProcessor slideInfoProcessor = SlideInfoProcessor(base);
164+
SlideInfoProcessor slideInfoProcessor = SlideInfoProcessor(m_cache.GetBaseAddress());
170165
slideInfoProcessor.ProcessEntryInfo(*entry);
171166

172167
if (image.header)
@@ -184,8 +179,6 @@ bool SharedCacheController::LoadImage(BinaryView& view, const CacheImage& image)
184179
objcProcessor.ProcessCFStrings(image.GetName());
185180
}
186181

187-
view.EndBulkModifySymbols();
188-
189182
m_loadedImages.insert(image.headerAddress);
190183

191184
// TODO: Partial failure state (i.e. 2 regions loaded, one failed)

view/sharedcache/core/ffi.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,9 @@ extern "C" {
371371
auto entries = controller->object->GetCache().GetEntries();
372372
*count = entries.size();
373373
BNSharedCacheEntry* apiEntries = new BNSharedCacheEntry[*count];
374-
for (size_t i = 0; i < *count; i++)
375-
{
376-
auto b = entries[i];
377-
apiEntries[i] = EntryToApi(b);
378-
}
374+
size_t idx = 0;
375+
for (const auto &[_, entry]: entries)
376+
apiEntries[idx++] = EntryToApi(entry);
379377
return apiEntries;
380378
}
381379

view/sharedcache/ui/SharedCacheUINotifications.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ void UINotifications::init()
2121
UIContext::registerNotification(m_instance);
2222
}
2323

24-
2524
void UINotifications::OnViewChange(UIContext* context, ViewFrame* frame, const QString& type)
2625
{
2726
if (!frame)
@@ -40,31 +39,31 @@ void UINotifications::OnViewChange(UIContext* context, ViewFrame* frame, const Q
4039
if (ah->isBoundAction("Load Image by Name"))
4140
return;
4241

43-
static auto loadRegionAtAddr = [view](uint64_t addr) {
44-
auto controller = SharedCacheController::GetController(*view);
42+
static auto loadRegionAtAddr = [](BinaryView& view, uint64_t addr) {
43+
auto controller = SharedCacheController::GetController(view);
4544
if (!controller)
4645
return;
4746
if (auto foundRegion = controller->GetRegionContaining(addr))
4847
{
4948
// If we did not load the region, then we don't need to run analysis.
50-
if (!controller->LoadRegion(*view, *foundRegion))
49+
if (!controller->LoadRegion(view, *foundRegion))
5150
return;
52-
view->AddAnalysisOption("linearsweep");
53-
view->UpdateAnalysis();
51+
view.AddAnalysisOption("linearsweep");
52+
view.UpdateAnalysis();
5453
}
5554
};
5655

57-
static auto loadImageAtAddr = [view](uint64_t addr) {
58-
auto controller = SharedCacheController::GetController(*view);
56+
static auto loadImageAtAddr = [](BinaryView& view, uint64_t addr) {
57+
auto controller = SharedCacheController::GetController(view);
5958
if (!controller)
6059
return;
6160
if (auto foundImage = controller->GetImageContaining(addr))
6261
{
6362
// If we did not load the image, then we don't need to run analysis.
64-
if (!controller->LoadImage(*view, *foundImage))
63+
if (!controller->LoadImage(view, *foundImage))
6564
return;
66-
view->AddAnalysisOption("linearsweep");
67-
view->UpdateAnalysis();
65+
view.AddAnalysisOption("linearsweep");
66+
view.UpdateAnalysis();
6867
}
6968
};
7069

@@ -77,20 +76,20 @@ void UINotifications::OnViewChange(UIContext* context, ViewFrame* frame, const Q
7776
if (GetAddressInput(addr, "Address", "Address"))
7877
{
7978
BackgroundThread::create(ctx.context->mainWindow())
80-
->thenBackground([addr](){ loadRegionAtAddr(addr); })
79+
->thenBackground([ctx, addr](){ loadRegionAtAddr(*ctx.binaryView, addr); })
8180
->start();
8281
}
8382
};
8483

8584
auto loadRegionTokenAction = [](const UIActionContext& ctx) {
8685
BackgroundThread::create(ctx.context->mainWindow())
87-
->thenBackground([ctx](){ loadRegionAtAddr(ctx.token.token.value); })
86+
->thenBackground([ctx](){ loadRegionAtAddr(*ctx.binaryView, ctx.token.token.value); })
8887
->start();
8988
};
9089

9190
auto loadImageTokenAction = [](const UIActionContext& ctx) {
9291
BackgroundThread::create(ctx.context->mainWindow())
93-
->thenBackground([ctx](){ loadImageAtAddr(ctx.token.token.value); })
92+
->thenBackground([ctx](){ loadImageAtAddr(*ctx.binaryView, ctx.token.token.value); })
9493
->start();
9594
};
9695

view/sharedcache/ui/dsctriage.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ DSCTriageView::DSCTriageView(QWidget* parent, BinaryViewRef data) : QWidget(pare
7777
const std::string initialLoad = fmt::format("Loading images... (0/{})", images.size());
7878
auto imageLoadTask = BackgroundTask(initialLoad, true);
7979

80-
// this->getData()->BeginBulkAddSegments();
81-
this->getData()->BeginBulkModifySymbols();
82-
8380
for (const auto& [addr, image] : images)
8481
{
8582
if (imageLoadTask.IsCancelled())
@@ -91,9 +88,6 @@ DSCTriageView::DSCTriageView(QWidget* parent, BinaryViewRef data) : QWidget(pare
9188
}
9289
imageLoadTask.Finish();
9390

94-
// this->getData()->EndBulkAddSegments();
95-
this->getData()->EndBulkModifySymbols();
96-
9791
// We have loaded images, lets make sure to update analysis!
9892
this->m_data->AddAnalysisOption("linearsweep");
9993
this->m_data->UpdateAnalysis();

0 commit comments

Comments
 (0)