fxos: remove claims from Disassembly

This commit is contained in:
Lephenixnoir 2023-10-07 15:08:23 +02:00
parent f2c1ce50fe
commit ede0a79b33
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
4 changed files with 4 additions and 186 deletions

View File

@ -123,48 +123,6 @@ struct OldFunction
std::vector<uint32_t> callTargets;
};
//---
// Dynamic claims
//
// Claims are small bits of information associated with sections of the virtual
// space, indicating what the data is used for. Typically it's either owned by
// a function, auxiliary function data, or some actual storage.
//---
struct Claim
{
enum {
Function = 1,
FunctionAuxiliary = 2,
Data = 3,
Zero = 4,
Special = 5,
};
/* Start address within the virtual space */
uint32_t address;
/* Size (bytes) */
uint16_t size;
/* Type */
int16_t type;
/* Function address, when relevant (eg. function) */
uint32_t owner;
/* Utility to check for intersections */
bool intersects(Claim const &other) const;
/* Check equality of claims (raw equality) */
bool operator==(Claim const &other) const;
/* String representation */
std::string str() const;
};
constexpr bool operator<(Claim const &c1, Claim const &c2)
{
return c1.address < c2.address;
}
//---
// Storage for disassembled data
//---
@ -201,30 +159,6 @@ struct Disassembly
OldFunction *getOrCreateFunctionAt(uint32_t pc);
// Claim information
std::set<Claim> claims;
/* Access the claim that owns the address, if there is one */
Claim const *getClaimAt(uint32_t address);
/* Find the first claim that overlaps this region, if any */
Claim const *findClaimConflict(uint32_t address, int size);
/* Find all (or up to max ≥ 0) claims that overlaps this region */
std::vector<Claim const *> findClaimConflicts(
uint32_t address, int size, int max = -1);
/* Add a new exclusive claim. If there is any intersection with previous
claims which do not compare equal to c, this fails. */
bool addExclusiveClaim(Claim const &c);
/* Get all claims owned by a certain address. */
std::vector<Claim const *> findClaimsOwnedBy(uint32_t address);
// TODO: Add non-exclusive claims/handle collisions
// TODO: We don't want to deal with instructions loaded without a minimum
// amount of analysis; can we tie instruction loading to some analysis?
};

View File

@ -61,10 +61,6 @@ public:
over relevant parts of the binary. */
bool exploreFunction(uint32_t pc);
/* Access the set of claims generated by the last call to
exploreFunctions(). */
std::set<Claim> resultClaims();
private:
/* Last explored function */
uint32_t m_lastFunction;

View File

@ -60,52 +60,12 @@ OldFunction::OldFunction(uint32_t pc): address {pc}
{
}
//---
// Dynamic claims
//---
bool Claim::intersects(Claim const &other) const
{
/* Compute the actual intersection */
uint32_t inter_start = std::max(this->address, other.address);
uint32_t inter_end
= std::min(this->address + this->size, other.address + other.size);
return inter_start < inter_end;
}
bool Claim::operator==(Claim const &other) const
{
return this->address == other.address && this->size == other.size
&& this->type == other.type && this->owner == other.owner;
}
std::string Claim::str() const
{
std::string details = format(" (claim 0x%08x:%d)", address, size);
switch(type) {
case Claim::Function:
return format("function at 0x%08x", owner) + details;
case Claim::FunctionAuxiliary:
return std::string("auxiliary data") + details;
case Claim::Data:
return std::string("data") + details;
case Claim::Zero:
return std::string("zero region") + details;
case Claim::Special:
return format("special region at 0x%08x", address) + details;
default:
return format("<type %d>", type) + details;
}
}
//---
// Storage for disassembled data
//---
Disassembly::Disassembly(VirtualSpace &_vspace):
vspace {_vspace}, instructions {}, functions {}, claims {}
vspace {_vspace}, instructions {}, functions {}
{
}
@ -164,6 +124,8 @@ OldFunction *Disassembly::getOrCreateFunctionAt(uint32_t pc)
return this->getFunctionAt(pc);
}
#if 0
// TODO: Reuse this for object intersections
std::vector<Claim const *> Disassembly::findClaimConflicts(
uint32_t address, int size, int max)
{
@ -196,51 +158,7 @@ std::vector<Claim const *> Disassembly::findClaimConflicts(
return conflicts;
}
Claim const *Disassembly::findClaimConflict(uint32_t address, int size)
{
auto claims = findClaimConflicts(address, size, 1);
return claims.size() > 0 ? claims[0] : nullptr;
}
Claim const *Disassembly::getClaimAt(uint32_t address)
{
return findClaimConflict(address, 1);
}
bool Disassembly::addExclusiveClaim(Claim const &c)
{
auto conflicts = this->findClaimConflicts(c.address, c.size);
bool exclusive = true;
for(auto conflict: conflicts) {
/* Allow declaring the same claim twice */
if(*conflict == c)
continue;
FxOS_log(ERR, "exclusive claim for %s conflicts with %s", c.str(),
conflicts[0]->str());
exclusive = false;
}
if(exclusive)
this->claims.insert(c);
return exclusive;
}
std::vector<Claim const *> Disassembly::findClaimsOwnedBy(uint32_t address)
{
std::vector<Claim const *> claims;
/* Since we don't order by owner we have to tank the linear search */
for(auto const &c: this->claims) {
if(c.owner == address)
claims.push_back(&c);
}
return claims;
}
#endif
//---
// DisassemblyPass

View File

@ -142,34 +142,4 @@ bool CfgPass::exploreFunction(uint32_t pc)
return true;
}
std::set<Claim> CfgPass::resultClaims()
{
Claim base;
base.address = 0xffffffff;
base.size = 0;
base.type = Claim::Function;
base.owner = m_lastFunction;
std::set<Claim> set;
Claim c = base;
for(uint32_t pc: m_claimedInstructions) {
if(pc == c.address + c.size) {
c.size += 2;
}
else {
if(c.size > 0)
set.insert(c);
c = base;
c.address = pc;
c.size = 2;
}
}
if(c.size > 0)
set.insert(c);
return set;
}
} /* namespace FxOS */