mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 10:49:34 +02:00
Merge branch 'GP-1806_ryanmkurtz_PR-4021_benstone_pe-resource-menu-track-depth'
This commit is contained in:
commit
5195a648d0
2 changed files with 43 additions and 26 deletions
|
@ -638,17 +638,18 @@ public class ResourceDataDirectory extends DataDirectory {
|
||||||
private String setExtraCommentForMenuResource(Data data) throws MemoryAccessException {
|
private String setExtraCommentForMenuResource(Data data) throws MemoryAccessException {
|
||||||
|
|
||||||
short MF_POPUP = 0x0010;
|
short MF_POPUP = 0x0010;
|
||||||
short LAST = 0x0090;
|
short MF_END = 0x0080;
|
||||||
|
|
||||||
DumbMemBufferImpl buffer = new DumbMemBufferImpl(data.getMemory(), data.getAddress());
|
DumbMemBufferImpl buffer = new DumbMemBufferImpl(data.getMemory(), data.getAddress());
|
||||||
|
|
||||||
StringBuilder comment = new StringBuilder();
|
StringBuilder comment = new StringBuilder();
|
||||||
if (data.getBaseDataType().getName().equals("MenuResource")) {
|
if (data.getBaseDataType().getName().equals("MenuResource")) {
|
||||||
|
|
||||||
//get first structure
|
short menuItemOption = 0;
|
||||||
|
Stack<Short> parentItemOptions = new Stack<>();
|
||||||
|
parentItemOptions.push((short) 0);
|
||||||
|
|
||||||
int numComponents = data.getNumComponents();
|
int numComponents = data.getNumComponents();
|
||||||
boolean topLevel = false;
|
|
||||||
for (int i = 0; i < numComponents; i++) {
|
for (int i = 0; i < numComponents; i++) {
|
||||||
DataType dt = data.getComponent(i).getBaseDataType();
|
DataType dt = data.getComponent(i).getBaseDataType();
|
||||||
int offset = data.getComponent(i).getRootOffset();
|
int offset = data.getComponent(i).getRootOffset();
|
||||||
|
@ -667,26 +668,20 @@ public class ResourceDataDirectory extends DataDirectory {
|
||||||
|
|
||||||
}
|
}
|
||||||
if (dt.getName().equals("word")) {
|
if (dt.getName().equals("word")) {
|
||||||
short option = buffer.getShort(offset);
|
menuItemOption = buffer.getShort(offset);
|
||||||
|
|
||||||
if (option == MF_POPUP) {
|
if ((menuItemOption & MF_POPUP) == 0) {
|
||||||
topLevel = true; //this type has no mtID to skip
|
|
||||||
}
|
|
||||||
else if (option == LAST) {
|
|
||||||
topLevel = true;
|
|
||||||
i++; //skip the mtID
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
topLevel = false;
|
|
||||||
i++; //skip the mtID
|
i++; //skip the mtID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dt.getName().equals("unicode")) {
|
if (dt.getName().equals("unicode")) {
|
||||||
if (topLevel) {
|
int depth = parentItemOptions.size() - 1;
|
||||||
|
if (depth == 0) {
|
||||||
comment.append("\n");
|
comment.append("\n");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
comment.append(" ");
|
comment.append(" ".repeat(2 * depth));
|
||||||
}
|
}
|
||||||
|
|
||||||
String menuString = fixupStringRepForDisplay(
|
String menuString = fixupStringRepForDisplay(
|
||||||
|
@ -698,6 +693,19 @@ public class ResourceDataDirectory extends DataDirectory {
|
||||||
else {
|
else {
|
||||||
comment.append(menuString + "\n");
|
comment.append(menuString + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((menuItemOption & MF_POPUP) == MF_POPUP) {
|
||||||
|
// Increase the current depth
|
||||||
|
parentItemOptions.push(menuItemOption);
|
||||||
|
}
|
||||||
|
else if ((menuItemOption & MF_END) == MF_END) {
|
||||||
|
// Decrease the current depth until we have found a parent menu item that isn't the last item in its parent
|
||||||
|
short parentOptions = parentItemOptions.pop();
|
||||||
|
while ((parentOptions & MF_END) == MF_END) {
|
||||||
|
parentOptions = parentItemOptions.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package ghidra.program.model.data;
|
package ghidra.program.model.data;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import ghidra.docking.settings.Settings;
|
import ghidra.docking.settings.Settings;
|
||||||
import ghidra.program.model.address.Address;
|
import ghidra.program.model.address.Address;
|
||||||
|
@ -30,7 +29,6 @@ public class MenuResourceDataType extends DynamicDataType {
|
||||||
|
|
||||||
private static short MF_POPUP = 0x0010;
|
private static short MF_POPUP = 0x0010;
|
||||||
private static short MF_END = 0x0080;
|
private static short MF_END = 0x0080;
|
||||||
private static short LAST = 0x0090;
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ClassTranslator.put("ghidra.app.plugin.prototype.data.MenuResourceDataType",
|
ClassTranslator.put("ghidra.app.plugin.prototype.data.MenuResourceDataType",
|
||||||
|
@ -68,7 +66,6 @@ public class MenuResourceDataType extends DynamicDataType {
|
||||||
protected DataTypeComponent[] getAllComponents(MemBuffer mbIn) {
|
protected DataTypeComponent[] getAllComponents(MemBuffer mbIn) {
|
||||||
List<DataTypeComponent> comps = new ArrayList<>();
|
List<DataTypeComponent> comps = new ArrayList<>();
|
||||||
int tempOffset = 0;
|
int tempOffset = 0;
|
||||||
boolean lastMenuItem = false;
|
|
||||||
MemBuffer memBuffer = mbIn;
|
MemBuffer memBuffer = mbIn;
|
||||||
short option;
|
short option;
|
||||||
|
|
||||||
|
@ -81,18 +78,30 @@ public class MenuResourceDataType extends DynamicDataType {
|
||||||
|
|
||||||
//loop through menu items and add them
|
//loop through menu items and add them
|
||||||
boolean lastItem = false;
|
boolean lastItem = false;
|
||||||
|
|
||||||
|
// keep options from parent popup menu items
|
||||||
|
Stack<Short> parentItemOptions = new Stack<>();
|
||||||
|
parentItemOptions.push((short) 0);
|
||||||
|
|
||||||
while (!lastItem) {
|
while (!lastItem) {
|
||||||
option = memBuffer.getShort(tempOffset);
|
option = memBuffer.getShort(tempOffset);
|
||||||
tempOffset = addMenuItemTemplate(memBuffer, comps, tempOffset, option);
|
tempOffset = addMenuItemTemplate(memBuffer, comps, tempOffset, option);
|
||||||
//last item in a menu
|
|
||||||
if (option == MF_END) {
|
if ((option & MF_POPUP) == MF_POPUP) {
|
||||||
if (lastMenuItem == true) {
|
// Increase the depth
|
||||||
lastItem = true;
|
parentItemOptions.push(option);
|
||||||
|
}
|
||||||
|
else if ((option & MF_END) == MF_END) {
|
||||||
|
// Decrease the depth until we have found a parent menu item that isn't also the last item
|
||||||
|
short parentOptions = parentItemOptions.pop();
|
||||||
|
while ((parentOptions & MF_END) == MF_END) {
|
||||||
|
parentOptions = parentItemOptions.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//last menu
|
|
||||||
if (option == LAST) {
|
// We have finished when there are no more parent menu items
|
||||||
lastMenuItem = true;
|
if (parentItemOptions.size() == 0) {
|
||||||
|
lastItem = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue