mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-28 17:11:11 -09:00
GP-0: Adding more synchronization to static mappings service
This commit is contained in:
@@ -411,11 +411,6 @@ public class DebuggerStaticMappingServicePlugin extends Plugin
|
|||||||
return new AddressRangeImpl(min, max);
|
return new AddressRangeImpl(min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Program openStaticProgram() {
|
|
||||||
return ProgramURLUtils.openHackedUpGhidraURL(programManager, tool.getProject(),
|
|
||||||
mapping.getStaticProgramURL(), ProgramManager.OPEN_VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isStaticProgramOpen() {
|
public boolean isStaticProgramOpen() {
|
||||||
return program != null;
|
return program != null;
|
||||||
}
|
}
|
||||||
@@ -587,31 +582,22 @@ public class DebuggerStaticMappingServicePlugin extends Plugin
|
|||||||
return Collections.unmodifiableMap(result);
|
return Collections.unmodifiableMap(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void openAndCollectPrograms(AddressRange rng, Range<Long> span,
|
protected void collectMappedProgramURLsInView(AddressRange rng, Range<Long> span,
|
||||||
Set<Program> result, Set<Exception> failures) {
|
Set<URL> result) {
|
||||||
TraceAddressSnapRange tatr = new ImmutableTraceAddressSnapRange(rng, span);
|
TraceAddressSnapRange tatr = new ImmutableTraceAddressSnapRange(rng, span);
|
||||||
for (Entry<TraceAddressSnapRange, MappingEntry> out : outbound.entrySet()) {
|
for (Entry<TraceAddressSnapRange, MappingEntry> out : outbound.entrySet()) {
|
||||||
if (!out.getKey().intersects(tatr)) {
|
if (!out.getKey().intersects(tatr)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
MappingEntry me = out.getValue();
|
MappingEntry me = out.getValue();
|
||||||
try {
|
result.add(me.getStaticProgramURL());
|
||||||
result.add(me.openStaticProgram());
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
if (failures == null) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
failures.add(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Program> openMappedProgramsInView(AddressSetView set, Range<Long> span,
|
public Set<URL> getMappedProgramURLsInView(AddressSetView set, Range<Long> span) {
|
||||||
Set<Exception> failures) {
|
Set<URL> result = new HashSet<>();
|
||||||
Set<Program> result = new HashSet<>();
|
|
||||||
for (AddressRange rng : set) {
|
for (AddressRange rng : set) {
|
||||||
openAndCollectPrograms(rng, span, result, failures);
|
collectMappedProgramURLsInView(rng, span, result);
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableSet(result);
|
return Collections.unmodifiableSet(result);
|
||||||
}
|
}
|
||||||
@@ -1154,20 +1140,24 @@ public class DebuggerStaticMappingServicePlugin extends Plugin
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Program> getOpenMappedProgramsAtSnap(Trace trace, long snap) {
|
public Set<Program> getOpenMappedProgramsAtSnap(Trace trace, long snap) {
|
||||||
InfoPerTrace info = requireTrackedInfo(trace);
|
synchronized (lock) {
|
||||||
if (info == null) {
|
InfoPerTrace info = requireTrackedInfo(trace);
|
||||||
return null;
|
if (info == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return info.getOpenMappedProgramsAtSnap(snap);
|
||||||
}
|
}
|
||||||
return info.getOpenMappedProgramsAtSnap(snap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProgramLocation getOpenMappedLocation(TraceLocation loc) {
|
public ProgramLocation getOpenMappedLocation(TraceLocation loc) {
|
||||||
InfoPerTrace info = requireTrackedInfo(loc.getTrace());
|
synchronized (lock) {
|
||||||
if (info == null) {
|
InfoPerTrace info = requireTrackedInfo(loc.getTrace());
|
||||||
return null;
|
if (info == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return info.getOpenMappedLocations(loc.getAddress(), loc.getLifespan());
|
||||||
}
|
}
|
||||||
return info.getOpenMappedLocations(loc.getAddress(), loc.getLifespan());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected long getNonScratchSnap(TraceProgramView view) {
|
protected long getNonScratchSnap(TraceProgramView view) {
|
||||||
@@ -1176,75 +1166,106 @@ public class DebuggerStaticMappingServicePlugin extends Plugin
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProgramLocation getStaticLocationFromDynamic(ProgramLocation loc) {
|
public ProgramLocation getStaticLocationFromDynamic(ProgramLocation loc) {
|
||||||
loc = ProgramLocationUtils.fixLocation(loc, true);
|
synchronized (lock) {
|
||||||
TraceProgramView view = (TraceProgramView) loc.getProgram();
|
loc = ProgramLocationUtils.fixLocation(loc, true);
|
||||||
Trace trace = view.getTrace();
|
TraceProgramView view = (TraceProgramView) loc.getProgram();
|
||||||
TraceLocation tloc = new DefaultTraceLocation(trace, null,
|
Trace trace = view.getTrace();
|
||||||
Range.singleton(getNonScratchSnap(view)), loc.getByteAddress());
|
TraceLocation tloc = new DefaultTraceLocation(trace, null,
|
||||||
ProgramLocation mapped = getOpenMappedLocation(tloc);
|
Range.singleton(getNonScratchSnap(view)), loc.getByteAddress());
|
||||||
if (mapped == null) {
|
ProgramLocation mapped = getOpenMappedLocation(tloc);
|
||||||
return null;
|
if (mapped == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return ProgramLocationUtils.replaceAddress(loc, mapped.getProgram(),
|
||||||
|
mapped.getByteAddress());
|
||||||
}
|
}
|
||||||
return ProgramLocationUtils.replaceAddress(loc, mapped.getProgram(),
|
|
||||||
mapped.getByteAddress());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<TraceLocation> getOpenMappedLocations(ProgramLocation loc) {
|
public Set<TraceLocation> getOpenMappedLocations(ProgramLocation loc) {
|
||||||
InfoPerProgram info = requireTrackedInfo(loc.getProgram());
|
synchronized (lock) {
|
||||||
if (info == null) {
|
InfoPerProgram info = requireTrackedInfo(loc.getProgram());
|
||||||
return null;
|
if (info == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return info.getOpenMappedTraceLocations(loc.getByteAddress());
|
||||||
}
|
}
|
||||||
return info.getOpenMappedTraceLocations(loc.getByteAddress());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TraceLocation getOpenMappedLocation(Trace trace, ProgramLocation loc, long snap) {
|
public TraceLocation getOpenMappedLocation(Trace trace, ProgramLocation loc, long snap) {
|
||||||
InfoPerProgram info = requireTrackedInfo(loc.getProgram());
|
synchronized (lock) {
|
||||||
if (info == null) {
|
InfoPerProgram info = requireTrackedInfo(loc.getProgram());
|
||||||
return null;
|
if (info == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return info.getOpenMappedTraceLocation(trace, loc.getByteAddress(), snap);
|
||||||
}
|
}
|
||||||
return info.getOpenMappedTraceLocation(trace, loc.getByteAddress(), snap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProgramLocation getDynamicLocationFromStatic(TraceProgramView view,
|
public ProgramLocation getDynamicLocationFromStatic(TraceProgramView view,
|
||||||
ProgramLocation loc) {
|
ProgramLocation loc) {
|
||||||
TraceLocation tloc = getOpenMappedLocation(view.getTrace(), loc, getNonScratchSnap(view));
|
synchronized (lock) {
|
||||||
if (tloc == null) {
|
TraceLocation tloc =
|
||||||
return null;
|
getOpenMappedLocation(view.getTrace(), loc, getNonScratchSnap(view));
|
||||||
|
if (tloc == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return ProgramLocationUtils.replaceAddress(loc, view, tloc.getAddress());
|
||||||
}
|
}
|
||||||
return ProgramLocationUtils.replaceAddress(loc, view, tloc.getAddress());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<Program, Collection<MappedAddressRange>> getOpenMappedViews(Trace trace,
|
public Map<Program, Collection<MappedAddressRange>> getOpenMappedViews(Trace trace,
|
||||||
AddressSetView set, long snap) {
|
AddressSetView set, long snap) {
|
||||||
InfoPerTrace info = requireTrackedInfo(trace);
|
synchronized (lock) {
|
||||||
if (info == null) {
|
InfoPerTrace info = requireTrackedInfo(trace);
|
||||||
return null;
|
if (info == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return info.getOpenMappedViews(set, Range.singleton(snap));
|
||||||
}
|
}
|
||||||
return info.getOpenMappedViews(set, Range.singleton(snap));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<TraceSnap, Collection<MappedAddressRange>> getOpenMappedViews(Program program,
|
public Map<TraceSnap, Collection<MappedAddressRange>> getOpenMappedViews(Program program,
|
||||||
AddressSetView set) {
|
AddressSetView set) {
|
||||||
InfoPerProgram info = requireTrackedInfo(program);
|
synchronized (lock) {
|
||||||
if (info == null) {
|
InfoPerProgram info = requireTrackedInfo(program);
|
||||||
return null;
|
if (info == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return info.getOpenMappedViews(set);
|
||||||
}
|
}
|
||||||
return info.getOpenMappedViews(set);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Program> openMappedProgramsInView(Trace trace, AddressSetView set, long snap,
|
public Set<Program> openMappedProgramsInView(Trace trace, AddressSetView set, long snap,
|
||||||
Set<Exception> failures) {
|
Set<Exception> failures) {
|
||||||
InfoPerTrace info = requireTrackedInfo(trace);
|
Set<URL> urls;
|
||||||
if (info == null) {
|
synchronized (lock) {
|
||||||
return null;
|
InfoPerTrace info = requireTrackedInfo(trace);
|
||||||
|
if (info == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
urls = info.getMappedProgramURLsInView(set, Range.singleton(snap));
|
||||||
}
|
}
|
||||||
return info.openMappedProgramsInView(set, Range.singleton(snap), failures);
|
Set<Program> result = new HashSet<>();
|
||||||
|
for (URL url : urls) {
|
||||||
|
try {
|
||||||
|
Program program = ProgramURLUtils.openHackedUpGhidraURL(programManager,
|
||||||
|
tool.getProject(), url, ProgramManager.OPEN_VISIBLE);
|
||||||
|
result.add(program);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
if (failures == null) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
failures.add(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String normalizePath(String path) {
|
protected String normalizePath(String path) {
|
||||||
|
|||||||
Reference in New Issue
Block a user