Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-1288: optimization for known sizes

d-millar4cb046077b79
diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/dbgeng/DebugControl.java b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/dbgeng/DebugControl.java
index 46dfa561f1..de7aedd7e5 100644
--- a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/dbgeng/DebugControl.java
+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/dbgeng/DebugControl.java
@@ -422,9 +422,9 @@ public interface DebugControl extends DebugControlReentrant {
DebugFilterInformation getNumberEventFilters();
- String getEventFilterText(int index);
+ String getEventFilterText(int index, int size);
- String getEventFilterCommand(int index);
+ String getEventFilterCommand(int index, int size);
void setEventFilterCommand(int index, String text);
@@ -432,7 +432,7 @@ public interface DebugControl extends DebugControlReentrant {
void setSpecificFilterParameters(int start, int count, DebugSpecificFilterInformation info);
- String getSpecificFilterArgument(int index);
+ String getSpecificFilterArgument(int index, int size);
void setSpecificFilterArgument(int index, String arg);
@@ -440,7 +440,7 @@ public interface DebugControl extends DebugControlReentrant {
void setExceptionFilterParameters(int count, DebugExceptionFilterInformation info);
- String getExceptionFilterSecondCommand(int index);
+ String getExceptionFilterSecondCommand(int index, int size);
void setExceptionFilterSecondCommand(int index, String cmd);
diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/impl/dbgeng/control/DebugControlImpl1.java b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/impl/dbgeng/control/DebugControlImpl1.java
index 495f5bfcf8..63ca444e04 100644
--- a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/impl/dbgeng/control/DebugControlImpl1.java
+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/impl/dbgeng/control/DebugControlImpl1.java
@@ -315,24 +315,31 @@ public class DebugControlImpl1 implements DebugControlInternal {
}
@Override
- public String getEventFilterText(int index) {
+ public String getEventFilterText(int index, int size) {
ULONG ulIndex = new ULONG(index);
+ ULONG ulBufferSize = new ULONG(size);
ULONGByReference ulTextSize = new ULONGByReference();
- COMUtils.checkRC(jnaControl.GetEventFilterText(ulIndex, null, new ULONG(0), ulTextSize));
- byte[] buffer = new byte[ulTextSize.getValue().intValue()];
- ULONG ulBufferSize = ulTextSize.getValue();
+ if (size == 0) {
+ COMUtils.checkRC(
+ jnaControl.GetEventFilterText(ulIndex, null, new ULONG(0), ulTextSize));
+ ulBufferSize = ulTextSize.getValue();
+ }
+ byte[] buffer = new byte[ulBufferSize.intValue()];
COMUtils.checkRC(jnaControl.GetEventFilterText(ulIndex, buffer, ulBufferSize, null));
return Native.toString(buffer);
}
@Override
- public String getEventFilterCommand(int index) {
+ public String getEventFilterCommand(int index, int size) {
ULONG ulIndex = new ULONG(index);
+ ULONG ulBufferSize = new ULONG(size);
ULONGByReference ulCommandSize = new ULONGByReference();
- COMUtils.checkRC(
- jnaControl.GetEventFilterCommand(ulIndex, null, new ULONG(0), ulCommandSize));
- byte[] buffer = new byte[ulCommandSize.getValue().intValue()];
- ULONG ulBufferSize = ulCommandSize.getValue();
+ if (size == 0) {
+ COMUtils.checkRC(
+ jnaControl.GetEventFilterCommand(ulIndex, null, new ULONG(0), ulCommandSize));
+ ulBufferSize = ulCommandSize.getValue();
+ }
+ byte[] buffer = new byte[ulBufferSize.intValue()];
COMUtils.checkRC(jnaControl.GetEventFilterCommand(ulIndex, buffer, ulBufferSize, null));
return Native.toString(buffer);
}
@@ -362,17 +369,20 @@ public class DebugControlImpl1 implements DebugControlInternal {
}
@Override
- public String getSpecificFilterArgument(int index) {
+ public String getSpecificFilterArgument(int index, int size) {
ULONG ulIndex = new ULONG(index);
+ ULONG ulBufferSize = new ULONG(size);
ULONGByReference ulArgumentSize = new ULONGByReference();
- HRESULT hr =
- jnaControl.GetSpecificFilterArgument(ulIndex, null, new ULONG(0), ulArgumentSize);
- if (hr.equals(COMUtilsExtra.E_INVALID_PARAM)) {
- return null;
+ if (size == 0) {
+ HRESULT hr =
+ jnaControl.GetSpecificFilterArgument(ulIndex, null, ulBufferSize, ulArgumentSize);
+ if (hr.equals(COMUtilsExtra.E_INVALID_PARAM)) {
+ return null;
+ }
+ COMUtils.checkRC(hr);
+ ulBufferSize = ulArgumentSize.getValue();
}
- COMUtils.checkRC(hr);
- byte[] buffer = new byte[ulArgumentSize.getValue().intValue()];
- ULONG ulBufferSize = ulArgumentSize.getValue();
+ byte[] buffer = new byte[ulBufferSize.intValue()];
COMUtils.checkRC(
jnaControl.GetSpecificFilterArgument(ulIndex, buffer, ulBufferSize, null));
return Native.toString(buffer);
@@ -410,13 +420,17 @@ public class DebugControlImpl1 implements DebugControlInternal {
}
@Override
- public String getExceptionFilterSecondCommand(int index) {
+ public String getExceptionFilterSecondCommand(int index, int size) {
ULONG ulIndex = new ULONG(index);
+ ULONG ulBufferSize = new ULONG(size);
ULONGByReference ulCommandSize = new ULONGByReference();
- COMUtils.checkRC(
- jnaControl.GetExceptionFilterSecondCommand(ulIndex, null, new ULONG(0), ulCommandSize));
- byte[] buffer = new byte[ulCommandSize.getValue().intValue()];
- ULONG ulBufferSize = ulCommandSize.getValue();
+ if (size == 0) {
+ COMUtils.checkRC(
+ jnaControl.GetExceptionFilterSecondCommand(ulIndex, null, ulBufferSize,
+ ulCommandSize));
+ ulBufferSize = ulCommandSize.getValue();
+ }
+ byte[] buffer = new byte[ulBufferSize.intValue()];
COMUtils.checkRC(
jnaControl.GetExceptionFilterSecondCommand(ulIndex, buffer, ulBufferSize, null));
return Native.toString(buffer);
diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/cmd/DbgListEventFiltersCommand.java b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/cmd/DbgListEventFiltersCommand.java
index d985ba429a..8fff92de76 100644
--- a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/cmd/DbgListEventFiltersCommand.java
+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/cmd/DbgListEventFiltersCommand.java
@@ -45,10 +45,10 @@ public class DbgListEventFiltersCommand
DebugSpecificFilterInformation exc =
control.getSpecificFilterParameters(0, info.getNumberEvents());
for (int i = 0; i < info.getNumberEvents(); i++) {
- String text = control.getEventFilterText(i);
- String cmd = control.getEventFilterCommand(i);
- String arg = control.getSpecificFilterArgument(i);
DEBUG_SPECIFIC_FILTER_PARAMETERS p = exc.getParameter(i);
+ String text = control.getEventFilterText(i, p.TextSize.intValue());
+ String cmd = control.getEventFilterCommand(i, p.CommandSize.intValue());
+ String arg = control.getSpecificFilterArgument(i, p.ArgumentSize.intValue());
DbgEventFilterImpl f =
new DbgEventFilterImpl(i, text, cmd, arg, p.ExecutionOption.intValue(),
p.ContinueOption.intValue());
diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/cmd/DbgListExceptionFiltersCommand.java b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/cmd/DbgListExceptionFiltersCommand.java
index 27a19a04c6..0fe8c61f0b 100644
--- a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/cmd/DbgListExceptionFiltersCommand.java
+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/cmd/DbgListExceptionFiltersCommand.java
@@ -44,14 +44,14 @@ public class DbgListExceptionFiltersCommand
DebugFilterInformation info = control.getNumberEventFilters();
int nEvents = info.getNumberEvents();
int nExcs = info.getNumberSpecificExceptions();
- //DebugSpecificFilterInformation spec = control.getSpecificFilterParameters(0, nEvents);
DebugExceptionFilterInformation exc =
control.getExceptionFilterParameters(nEvents, null, nExcs);
for (int i = 0; i < exc.getParameters().length; i++) {
DEBUG_EXCEPTION_FILTER_PARAMETERS p = exc.getParameter(i);
- String text = control.getEventFilterText(nEvents + i);
- String cmd = control.getEventFilterCommand(nEvents + i);
- String cmd2 = control.getExceptionFilterSecondCommand(nEvents + i);
+ String text = control.getEventFilterText(nEvents + i, p.TextSize.intValue());
+ String cmd = control.getEventFilterCommand(nEvents + i, p.CommandSize.intValue());
+ String cmd2 = control.getExceptionFilterSecondCommand(nEvents + i,
+ p.SecondCommandSize.intValue());
DbgExceptionFilterImpl filter = new DbgExceptionFilterImpl(i, text, cmd, cmd2,
p.ExecutionOption.intValue(), p.ContinueOption.intValue(),
p.ExceptionCode.longValue());