mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 10:19:23 +02:00
GT-2842 correct minor bugs and improve handling of ASCII char strings
when char-size is greater than 1
This commit is contained in:
parent
b90e7cf868
commit
64deecced9
4 changed files with 29 additions and 252 deletions
|
@ -187,11 +187,10 @@ public class StringDataInstance {
|
|||
this.buf = buf;
|
||||
this.charsetName = getCharsetNameFromDataTypeOrSettings(dataType, settings);
|
||||
this.charSize = CharsetInfo.getInstance().getCharsetCharSize(charsetName);
|
||||
// TODO: determine padding of char data type from the dataOrg()
|
||||
this.paddedCharSize = charSize; // stringDataType.getPaddedCharSize(charSize);
|
||||
|
||||
// NOTE: for now only handle padding for charSize == 1
|
||||
this.paddedCharSize =
|
||||
charSize == 1 ? getDataOrganization(dataType).getCharSize() : charSize;
|
||||
this.stringLayout = getLayoutFromDataType(dataType);
|
||||
|
||||
this.showTranslation = TRANSLATION.isShowTranslated(settings);
|
||||
this.translatedValue = TRANSLATION.getTranslatedValue(settings);
|
||||
this.renderSetting = RENDER.getEnumValue(settings);
|
||||
|
@ -214,6 +213,17 @@ public class StringDataInstance {
|
|||
this.endianSetting = copyFrom.endianSetting;
|
||||
}
|
||||
|
||||
private static DataOrganization getDataOrganization(DataType dataType) {
|
||||
// The dataType should be correspond to the target program
|
||||
if (dataType != null) {
|
||||
DataTypeManager dtm = dataType.getDataTypeManager();
|
||||
if (dtm != null) {
|
||||
return dtm.getDataOrganization();
|
||||
}
|
||||
}
|
||||
return DataOrganizationImpl.getDefaultOrganization();
|
||||
}
|
||||
|
||||
private static StringLayoutEnum getLayoutFromDataType(DataType dataType) {
|
||||
if (dataType instanceof AbstractStringDataType) {
|
||||
return ((AbstractStringDataType) dataType).getStringLayout();
|
||||
|
|
|
@ -66,7 +66,7 @@ public class AcyclicCallGraphBuilder {
|
|||
public AcyclicCallGraphBuilder(Program program, Collection<Function> functions,
|
||||
boolean killThunks) {
|
||||
this.program = program;
|
||||
functionSet = new HashSet<Address>();
|
||||
functionSet = new HashSet<>();
|
||||
for (Function function : functions) {
|
||||
if (killThunks) {
|
||||
if (function.isThunk()) {
|
||||
|
@ -87,9 +87,9 @@ public class AcyclicCallGraphBuilder {
|
|||
public DependencyGraph<Address> getDependencyGraph(TaskMonitor monitor)
|
||||
throws CancelledException {
|
||||
|
||||
DependencyGraph<Address> graph = new DependencyGraph<Address>();
|
||||
DependencyGraph<Address> graph = new DependencyGraph<>();
|
||||
Deque<Address> startPoints = findStartPoints();
|
||||
Set<Address> unprocessed = new TreeSet<Address>(functionSet); // reliable processing order
|
||||
Set<Address> unprocessed = new TreeSet<>(functionSet); // reliable processing order
|
||||
|
||||
while (!unprocessed.isEmpty()) {
|
||||
monitor.checkCanceled();
|
||||
|
@ -111,7 +111,7 @@ public class AcyclicCallGraphBuilder {
|
|||
}
|
||||
|
||||
private Deque<Address> findStartPoints() {
|
||||
Deque<Address> startPoints = new LinkedList<Address>();
|
||||
Deque<Address> startPoints = new LinkedList<>();
|
||||
|
||||
// populate startPoints with functions that have no callers or are an entry point
|
||||
for (Address address : functionSet) {
|
||||
|
@ -131,7 +131,7 @@ public class AcyclicCallGraphBuilder {
|
|||
node.children[0] = thunkedfunc.getEntryPoint();
|
||||
return;
|
||||
}
|
||||
ArrayList<Address> children = new ArrayList<Address>();
|
||||
ArrayList<Address> children = new ArrayList<>();
|
||||
ReferenceManager referenceManager = program.getReferenceManager();
|
||||
AddressIterator referenceSourceIterator =
|
||||
referenceManager.getReferenceSourceIterator(function.getBody(), true);
|
||||
|
@ -142,7 +142,7 @@ public class AcyclicCallGraphBuilder {
|
|||
Address toAddr = ref.getToAddress();
|
||||
if (ref.getReferenceType().isCall()) {
|
||||
Function childfunc = fmanage.getFunctionAt(toAddr);
|
||||
if (killThunks) {
|
||||
if (childfunc != null && killThunks) {
|
||||
if (childfunc.isThunk()) {
|
||||
childfunc = childfunc.getThunkedFunction(true);
|
||||
toAddr = childfunc.getEntryPoint();
|
||||
|
@ -205,7 +205,7 @@ public class AcyclicCallGraphBuilder {
|
|||
|
||||
private static Set<Address> findFunctions(Program program, AddressSetView set,
|
||||
boolean killThunks) {
|
||||
Set<Address> functionStarts = new HashSet<Address>();
|
||||
Set<Address> functionStarts = new HashSet<>();
|
||||
|
||||
FunctionIterator functions = program.getFunctionManager().getFunctions(set, true);
|
||||
for (Function function : functions) {
|
||||
|
@ -227,14 +227,15 @@ public class AcyclicCallGraphBuilder {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return address == null ? "" : address.toString() +
|
||||
(children == null ? " <no children>" : " " + Arrays.toString(children));
|
||||
return address == null ? ""
|
||||
: address.toString() +
|
||||
(children == null ? " <no children>" : " " + Arrays.toString(children));
|
||||
}
|
||||
}
|
||||
|
||||
private static class VisitStack {
|
||||
private Set<Address> inStack = new HashSet<Address>();
|
||||
private Deque<StackNode> stack = new LinkedList<StackNode>();
|
||||
private Set<Address> inStack = new HashSet<>();
|
||||
private Deque<StackNode> stack = new LinkedList<>();
|
||||
|
||||
public VisitStack(Address functionEntry) {
|
||||
push(functionEntry);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue