GP-4742 Added addr='next' to pspec labels. Constrained address spaces for heuristic references

This commit is contained in:
emteere 2024-07-29 17:46:50 -04:00
parent f854828f73
commit bceb82f733
8 changed files with 319 additions and 81 deletions

View file

@ -4,9 +4,9 @@
* 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.
@ -384,28 +384,30 @@ void ArchitectureGhidra::buildSymbols(DocumentStorage &store)
{
const Element *symtag = store.getTag(ELEM_DEFAULT_SYMBOLS.getName());
if (symtag == (const Element *)0) return;
XmlDecode decoder(this,symtag);
if (symtag == (const Element*) 0)
return;
XmlDecode decoder(this, symtag);
uint4 el = decoder.openElement(ELEM_DEFAULT_SYMBOLS);
while(decoder.peekElement() != 0) {
Address lastAddr(Address::m_minimal);
int4 lastSize = -1;
while (decoder.peekElement() != 0) {
uint4 subel = decoder.openElement(ELEM_SYMBOL);
string addrString;
string name;
int4 size = 0;
int4 volatileState = -1;
for(;;) {
for (;;) {
uint4 attribId = decoder.getNextAttributeId();
if (attribId == 0) break;
if (attribId == 0)
break;
if (attribId == ATTRIB_NAME)
name = decoder.readString();
name = decoder.readString();
else if (attribId == ATTRIB_ADDRESS) {
addrString = decoder.readString();
}
else if (attribId == ATTRIB_VOLATILE) {
volatileState = decoder.readBool() ? 1 : 0;
}
else if (attribId == ATTRIB_SIZE)
size = decoder.readSignedInteger();
addrString = decoder.readString();
} else if (attribId == ATTRIB_VOLATILE) {
volatileState = decoder.readBool() ? 1 : 0;
} else if (attribId == ATTRIB_SIZE)
size = decoder.readSignedInteger();
}
decoder.closeElement(subel);
if (name.size() == 0)
@ -417,14 +419,21 @@ void ArchitectureGhidra::buildSymbols(DocumentStorage &store)
// feed the global symbol to the decompiler on a per function basic.
if (volatileState < 0)
continue;
Address addr = parseAddressSimple(addrString);
Address addr;
if (addrString == "next" && lastSize != -1) {
addr = lastAddr + lastSize;
} else {
addr = parseAddressSimple(addrString);
}
if (size == 0)
size = addr.getSpace()->getWordSize();
Range range(addr.getSpace(),addr.getOffset(),addr.getOffset() + (size-1));
Range range(addr.getSpace(), addr.getOffset(), addr.getOffset() + (size - 1));
if (volatileState == 0)
symboltab->clearPropertyRange(Varnode::volatil, range);
else
symboltab->setPropertyRange(Varnode::volatil, range);
lastAddr = addr;
lastSize = size;
}
decoder.closeElement(el);
}

View file

@ -4,9 +4,9 @@
* 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.
@ -267,28 +267,36 @@ void SleighArchitecture::buildSymbols(DocumentStorage &store)
{
const Element *symtag = store.getTag(ELEM_DEFAULT_SYMBOLS.getName());
if (symtag == (const Element *)0) return;
XmlDecode decoder(this,symtag);
if (symtag == (const Element*) 0)
return;
XmlDecode decoder(this, symtag);
uint4 el = decoder.openElement(ELEM_DEFAULT_SYMBOLS);
while(decoder.peekElement() != 0) {
Address lastAddr(Address::m_minimal);
int4 lastSize = -1;
while (decoder.peekElement() != 0) {
uint4 subel = decoder.openElement(ELEM_SYMBOL);
Address addr;
string name;
string description;
int4 size = 0;
int4 volatileState = -1;
for(;;) {
for (;;) {
uint4 attribId = decoder.getNextAttributeId();
if (attribId == 0) break;
if (attribId == 0)
break;
if (attribId == ATTRIB_NAME)
name = decoder.readString();
name = decoder.readString();
else if (attribId == ATTRIB_ADDRESS) {
addr = parseAddressSimple(decoder.readString());
}
else if (attribId == ATTRIB_VOLATILE) {
volatileState = decoder.readBool() ? 1 : 0;
}
else if (attribId == ATTRIB_SIZE)
size = decoder.readSignedInteger();
string addrStr = decoder.readString();
if (addrStr == "next" && lastSize != -1) {
addr = lastAddr + lastSize;
} else {
addr = parseAddressSimple(addrStr);
}
} else if (attribId == ATTRIB_VOLATILE) {
volatileState = decoder.readBool() ? 1 : 0;
} else if (attribId == ATTRIB_SIZE)
size = decoder.readSignedInteger();
}
decoder.closeElement(subel);
if (name.size() == 0)
@ -298,15 +306,17 @@ void SleighArchitecture::buildSymbols(DocumentStorage &store)
if (size == 0)
size = addr.getSpace()->getWordSize();
if (volatileState >= 0) {
Range range(addr.getSpace(),addr.getOffset(),addr.getOffset() + (size-1));
Range range(addr.getSpace(), addr.getOffset(), addr.getOffset() + (size - 1));
if (volatileState == 0)
symboltab->clearPropertyRange(Varnode::volatil, range);
symboltab->clearPropertyRange(Varnode::volatil, range);
else
symboltab->setPropertyRange(Varnode::volatil, range);
symboltab->setPropertyRange(Varnode::volatil, range);
}
Datatype *ct = types->getBase(size, TYPE_UNKNOWN);
Address usepoint;
symboltab->getGlobalScope()->addSymbol(name, ct, addr, usepoint);
lastAddr = addr;
lastSize = size;
}
decoder.closeElement(el);
}