Ghidra is a software reverse engineering (SRE) framework
GP-1288: basic event/exc objects
d-millar2f1f78dc97eb
diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/DbgEventFilter.java b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/DbgEventFilter.javanew file mode 100644index 0000000000..007ef68206--- /dev/null+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/DbgEventFilter.java@@ -0,0 +1,22 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package agent.dbgeng.manager;++public interface DbgEventFilter {++ String getName();++}diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/DbgExceptionFilter.java b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/DbgExceptionFilter.javanew file mode 100644index 0000000000..a1fa35c9e9--- /dev/null+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/DbgExceptionFilter.java@@ -0,0 +1,22 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package agent.dbgeng.manager;++public interface DbgExceptionFilter {++ String getName();++}diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/impl/DbgManagerImpl.java b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/impl/DbgManagerImpl.javaindex 3d13198ac9..ef34b36f06 100644--- a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/impl/DbgManagerImpl.java+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/manager/impl/DbgManagerImpl.java@@ -1585,4 +1585,12 @@ public class DbgManagerImpl implements DbgManager {return processCount;}+ public CompletableFuture<Map<String, DbgEventFilter>> listEventFilters() {+ return CompletableFuture.completedFuture(new HashMap<String, DbgEventFilter>());+ }++ public CompletableFuture<Map<String, DbgExceptionFilter>> listExceptionFilters() {+ return CompletableFuture.completedFuture(new HashMap<String, DbgExceptionFilter>());+ }+}diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/iface2/DbgModelTargetEvent.java b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/iface2/DbgModelTargetEvent.javanew file mode 100644index 0000000000..dfbcc6eb35--- /dev/null+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/iface2/DbgModelTargetEvent.java@@ -0,0 +1,29 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package agent.dbgeng.model.iface2;++import agent.dbgeng.manager.DbgEventFilter;++public interface DbgModelTargetEvent extends DbgModelTargetObject {++ @Override+ public default String getDisplay() {+ return getName();+ }++ public DbgEventFilter getFilter();++}diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/iface2/DbgModelTargetEventContainer.java b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/iface2/DbgModelTargetEventContainer.javanew file mode 100644index 0000000000..4085880f94--- /dev/null+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/iface2/DbgModelTargetEventContainer.java@@ -0,0 +1,30 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package agent.dbgeng.model.iface2;++import ghidra.dbg.target.TargetAggregate;+import ghidra.dbg.target.schema.*;++@TargetObjectSchemaInfo(+ name = "EventContainer",+ elements = {+ @TargetElementType(type = DbgModelTargetEvent.class) },+ attributes = {+ @TargetAttributeType(type = Void.class) },+ canonicalContainer = true)+public interface DbgModelTargetEventContainer extends DbgModelTargetObject, TargetAggregate {++}diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/iface2/DbgModelTargetException.java b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/iface2/DbgModelTargetException.javanew file mode 100644index 0000000000..34c48922f4--- /dev/null+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/iface2/DbgModelTargetException.java@@ -0,0 +1,29 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package agent.dbgeng.model.iface2;++import agent.dbgeng.manager.DbgExceptionFilter;++public interface DbgModelTargetException extends DbgModelTargetObject {++ @Override+ public default String getDisplay() {+ return getName();+ }++ public DbgExceptionFilter getFilter();++}diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/iface2/DbgModelTargetExceptionContainer.java b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/iface2/DbgModelTargetExceptionContainer.javanew file mode 100644index 0000000000..6f0e06b6d6--- /dev/null+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/iface2/DbgModelTargetExceptionContainer.java@@ -0,0 +1,30 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package agent.dbgeng.model.iface2;++import ghidra.dbg.target.TargetAggregate;+import ghidra.dbg.target.schema.*;++@TargetObjectSchemaInfo(+ name = "EventContainer",+ elements = {+ @TargetElementType(type = DbgModelTargetException.class) },+ attributes = {+ @TargetAttributeType(type = Void.class) },+ canonicalContainer = true)+public interface DbgModelTargetExceptionContainer extends DbgModelTargetObject, TargetAggregate {++}diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/impl/DbgModelTargetDebugContainerImpl.java b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/impl/DbgModelTargetDebugContainerImpl.javaindex ed0c590045..be53560a77 100644--- a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/impl/DbgModelTargetDebugContainerImpl.java+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/impl/DbgModelTargetDebugContainerImpl.java@@ -31,6 +31,16 @@ import ghidra.dbg.target.schema.TargetObjectSchemaInfo;type = DbgModelTargetBreakpointContainerImpl.class,required = true,fixed = true),+ @TargetAttributeType(+ name = "Events",+ type = DbgModelTargetEventContainerImpl.class,+ required = true,+ fixed = true),+ @TargetAttributeType(+ name = "Exceptions",+ type = DbgModelTargetEventContainerImpl.class,+ required = true,+ fixed = true),@TargetAttributeType(type = Void.class)},canonicalContainer = true)@@ -38,6 +48,9 @@ public class DbgModelTargetDebugContainerImpl extends DbgModelTargetObjectImplimplements DbgModelTargetDebugContainer {protected final DbgModelTargetBreakpointContainerImpl breakpoints;+ protected final DbgModelTargetEventContainerImpl events;+ protected final DbgModelTargetExceptionContainerImpl exceptions;+private DbgModelTargetProcess process;public DbgModelTargetDebugContainerImpl(DbgModelTargetProcess process) {@@ -45,9 +58,13 @@ public class DbgModelTargetDebugContainerImpl extends DbgModelTargetObjectImplthis.process = process;this.breakpoints = new DbgModelTargetBreakpointContainerImpl(this);+ this.events = new DbgModelTargetEventContainerImpl(this);+ this.exceptions = new DbgModelTargetExceptionContainerImpl(this);changeAttributes(List.of(), List.of( //- breakpoints //+ breakpoints, //+ events, //+ exceptions //), Map.of(), "Initialized");}diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/impl/DbgModelTargetEventContainerImpl.java b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/impl/DbgModelTargetEventContainerImpl.javanew file mode 100644index 0000000000..f42a1bdbdd--- /dev/null+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/impl/DbgModelTargetEventContainerImpl.java@@ -0,0 +1,68 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package agent.dbgeng.model.impl;++import java.util.List;+import java.util.Map;+import java.util.concurrent.CompletableFuture;+import java.util.stream.Collectors;++import agent.dbgeng.manager.DbgEventFilter;+import agent.dbgeng.manager.impl.DbgManagerImpl;+import agent.dbgeng.model.iface2.*;+import ghidra.dbg.target.TargetObject;+import ghidra.dbg.target.schema.*;++@TargetObjectSchemaInfo(+ name = "EventContainer",+ elements = { //+ @TargetElementType(type = DbgModelTargetEvent.class) //+ },+ attributes = { //+ @TargetAttributeType(type = Void.class) //+ },+ canonicalContainer = true)+public class DbgModelTargetEventContainerImpl extends DbgModelTargetObjectImpl+ implements DbgModelTargetEventContainer {++ public DbgModelTargetEventContainerImpl(DbgModelTargetDebugContainer debug) {+ super(debug.getModel(), debug, "Events", "EventContainer");+ }++ public DbgModelTargetEvent getTargetEvent(DbgEventFilter info) {+ DbgModelImpl impl = (DbgModelImpl) model;+ TargetObject modelObject = impl.getModelObject(info);+ if (modelObject != null) {+ return (DbgModelTargetEvent) modelObject;+ }+ return new DbgModelTargetEventImpl(this, info);+ }++ @Override+ public CompletableFuture<Void> requestElements(boolean refresh) {+ DbgManagerImpl manager = getManager();+ return manager.listEventFilters().thenAccept(byName -> {+ List<TargetObject> filters;+ synchronized (this) {+ filters = byName.values()+ .stream()+ .map(this::getTargetEvent)+ .collect(Collectors.toList());+ }+ setElements(filters, Map.of(), "Refreshed");+ });+ }+}diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/impl/DbgModelTargetEventImpl.java b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/impl/DbgModelTargetEventImpl.javanew file mode 100644index 0000000000..394c9d8f3d--- /dev/null+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/impl/DbgModelTargetEventImpl.java@@ -0,0 +1,78 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package agent.dbgeng.model.impl;++import agent.dbgeng.manager.DbgEventFilter;+import agent.dbgeng.model.iface2.DbgModelTargetEvent;+import agent.dbgeng.model.iface2.DbgModelTargetEventContainer;+import ghidra.dbg.target.schema.*;+import ghidra.dbg.util.PathUtils;+import ghidra.program.model.address.Address;++@TargetObjectSchemaInfo(+ name = "Module",+ elements = {+ @TargetElementType(type = Void.class) },+ attributes = {+ @TargetAttributeType(+ name = "Symbols",+ type = DbgModelTargetSymbolContainerImpl.class,+ required = true,+ fixed = true),+ @TargetAttributeType(name = "BaseAddress", type = Address.class),+ @TargetAttributeType(name = "ImageName", type = String.class),+ @TargetAttributeType(name = "TimeStamp", type = Integer.class),+ @TargetAttributeType(name = "Len", type = String.class),+ @TargetAttributeType(type = Void.class) })+public class DbgModelTargetEventImpl extends DbgModelTargetObjectImpl+ implements DbgModelTargetEvent {+ protected static String indexFilter(DbgEventFilter filter) {+ return filter.getName();+ }++ protected static String keyFilter(DbgEventFilter filter) {+ return PathUtils.makeKey(indexFilter(filter));+ }++ private DbgEventFilter filter;++ public DbgModelTargetEventImpl(DbgModelTargetEventContainer events, DbgEventFilter filter) {+ super(events.getModel(), events, keyFilter(filter), "EventFilter");+ this.getModel().addModelObject(filter, this);+ this.filter = filter;++ /*+ changeAttributes(List.of(), List.of( //+ symbols //+ // sections.getName(), sections, //+ ), Map.of( //+ DISPLAY_ATTRIBUTE_NAME, getIndex(), //+ SHORT_DISPLAY_ATTRIBUTE_NAME, module.getName(), //+ MODULE_NAME_ATTRIBUTE_NAME, module.getImageName(), //+ "BaseAddress", space.getAddress(module.getKnownBase()), //+ "ImageName", module.getImageName(), //+ "TimeStamp", module.getTimeStamp(), //+ "Len", Integer.toHexString(module.getSize()) //+ ), "Initialized");+ */+ }++ @Override+ public DbgEventFilter getFilter() {+ return filter;+ }++}diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/impl/DbgModelTargetExceptionContainerImpl.java b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/impl/DbgModelTargetExceptionContainerImpl.javanew file mode 100644index 0000000000..c68955b824--- /dev/null+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/impl/DbgModelTargetExceptionContainerImpl.java@@ -0,0 +1,68 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package agent.dbgeng.model.impl;++import java.util.List;+import java.util.Map;+import java.util.concurrent.CompletableFuture;+import java.util.stream.Collectors;++import agent.dbgeng.manager.DbgExceptionFilter;+import agent.dbgeng.manager.impl.DbgManagerImpl;+import agent.dbgeng.model.iface2.*;+import ghidra.dbg.target.TargetObject;+import ghidra.dbg.target.schema.*;++@TargetObjectSchemaInfo(+ name = "ExceptionContainer",+ elements = { //+ @TargetElementType(type = DbgModelTargetEvent.class) //+ },+ attributes = { //+ @TargetAttributeType(type = Void.class) //+ },+ canonicalContainer = true)+public class DbgModelTargetExceptionContainerImpl extends DbgModelTargetObjectImpl+ implements DbgModelTargetEventContainer {++ public DbgModelTargetExceptionContainerImpl(DbgModelTargetDebugContainer debug) {+ super(debug.getModel(), debug, "Exceptions", "ExceptionContainer");+ }++ public DbgModelTargetException getTargetException(DbgExceptionFilter info) {+ DbgModelImpl impl = (DbgModelImpl) model;+ TargetObject modelObject = impl.getModelObject(info);+ if (modelObject != null) {+ return (DbgModelTargetException) modelObject;+ }+ return new DbgModelTargetExceptionImpl(this, info);+ }++ @Override+ public CompletableFuture<Void> requestElements(boolean refresh) {+ DbgManagerImpl manager = getManager();+ return manager.listExceptionFilters().thenAccept(byName -> {+ List<TargetObject> filters;+ synchronized (this) {+ filters = byName.values()+ .stream()+ .map(this::getTargetException)+ .collect(Collectors.toList());+ }+ setElements(filters, Map.of(), "Refreshed");+ });+ }+}diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/impl/DbgModelTargetExceptionImpl.java b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/impl/DbgModelTargetExceptionImpl.javanew file mode 100644index 0000000000..c93f807123--- /dev/null+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/impl/DbgModelTargetExceptionImpl.java@@ -0,0 +1,79 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package agent.dbgeng.model.impl;++import agent.dbgeng.manager.DbgExceptionFilter;+import agent.dbgeng.model.iface2.DbgModelTargetEventContainer;+import agent.dbgeng.model.iface2.DbgModelTargetException;+import ghidra.dbg.target.schema.*;+import ghidra.dbg.util.PathUtils;+import ghidra.program.model.address.Address;++@TargetObjectSchemaInfo(+ name = "Module",+ elements = {+ @TargetElementType(type = Void.class) },+ attributes = {+ @TargetAttributeType(+ name = "Symbols",+ type = DbgModelTargetSymbolContainerImpl.class,+ required = true,+ fixed = true),+ @TargetAttributeType(name = "BaseAddress", type = Address.class),+ @TargetAttributeType(name = "ImageName", type = String.class),+ @TargetAttributeType(name = "TimeStamp", type = Integer.class),+ @TargetAttributeType(name = "Len", type = String.class),+ @TargetAttributeType(type = Void.class) })+public class DbgModelTargetExceptionImpl extends DbgModelTargetObjectImpl+ implements DbgModelTargetException {+ protected static String indexFilter(DbgExceptionFilter filter) {+ return filter.getName();+ }++ protected static String keyFilter(DbgExceptionFilter filter) {+ return PathUtils.makeKey(indexFilter(filter));+ }++ private DbgExceptionFilter filter;++ public DbgModelTargetExceptionImpl(DbgModelTargetEventContainer events,+ DbgExceptionFilter filter) {+ super(events.getModel(), events, keyFilter(filter), "ExceptionFilter");+ this.getModel().addModelObject(filter, this);+ this.filter = filter;++ /*+ changeAttributes(List.of(), List.of( //+ symbols //+ // sections.getName(), sections, //+ ), Map.of( //+ DISPLAY_ATTRIBUTE_NAME, getIndex(), //+ SHORT_DISPLAY_ATTRIBUTE_NAME, module.getName(), //+ MODULE_NAME_ATTRIBUTE_NAME, module.getImageName(), //+ "BaseAddress", space.getAddress(module.getKnownBase()), //+ "ImageName", module.getImageName(), //+ "TimeStamp", module.getTimeStamp(), //+ "Len", Integer.toHexString(module.getSize()) //+ ), "Initialized");+ */+ }++ @Override+ public DbgExceptionFilter getFilter() {+ return filter;+ }++}