mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 03:50:02 +02:00
Merge remote-tracking branch 'origin/GP-1602-dragonmacher-decompiler-brace-stack-trace'
This commit is contained in:
commit
0fc8055c77
1 changed files with 37 additions and 32 deletions
|
@ -354,8 +354,7 @@ public class DecompilerUtils {
|
||||||
public static AddressSet findClosestAddressSet(Program program, AddressSpace functionSpace,
|
public static AddressSet findClosestAddressSet(Program program, AddressSpace functionSpace,
|
||||||
List<ClangToken> tokenList) {
|
List<ClangToken> tokenList) {
|
||||||
AddressSet addressSet = new AddressSet();
|
AddressSet addressSet = new AddressSet();
|
||||||
for (int i = 0; i < tokenList.size(); ++i) {
|
for (ClangToken tok : tokenList) {
|
||||||
ClangToken tok = tokenList.get(i);
|
|
||||||
addTokenAddressRangeToSet(addressSet, tok, functionSpace);
|
addTokenAddressRangeToSet(addressSet, tok, functionSpace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -574,33 +573,39 @@ public class DecompilerUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
Stack<ClangSyntaxToken> braceStack = new Stack<>();
|
Stack<ClangSyntaxToken> braceStack = new Stack<>();
|
||||||
for (int i = 0; i < list.size(); ++i) {
|
for (ClangNode element : list) {
|
||||||
ClangToken token = (ClangToken) list.get(i);
|
ClangToken token = (ClangToken) element;
|
||||||
if (token instanceof ClangSyntaxToken) {
|
if (!(token instanceof ClangSyntaxToken)) {
|
||||||
ClangSyntaxToken syntaxToken = (ClangSyntaxToken) token;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (startToken == syntaxToken) {
|
ClangSyntaxToken syntaxToken = (ClangSyntaxToken) token;
|
||||||
// found our starting token, take the current value on the stack
|
if (startToken == syntaxToken) {
|
||||||
ClangSyntaxToken matchingBrace = braceStack.pop();
|
|
||||||
return matchingBrace;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isBrace(syntaxToken)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (braceStack.isEmpty()) {
|
if (braceStack.isEmpty()) {
|
||||||
braceStack.push(syntaxToken);
|
return null; // this can happen if the start token has a bad parent values
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ClangSyntaxToken lastToken = braceStack.peek();
|
// found our starting token, take the current value on the stack
|
||||||
if (isMatchingBrace(lastToken, syntaxToken)) {
|
ClangSyntaxToken matchingBrace = braceStack.pop();
|
||||||
braceStack.pop();
|
return matchingBrace;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
braceStack.push(syntaxToken);
|
if (!isBrace(syntaxToken)) {
|
||||||
}
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (braceStack.isEmpty()) {
|
||||||
|
braceStack.push(syntaxToken);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClangSyntaxToken lastToken = braceStack.peek();
|
||||||
|
if (isMatchingBrace(lastToken, syntaxToken)) {
|
||||||
|
braceStack.pop();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
braceStack.push(syntaxToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue