Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
717ec8e
Merge branch 'develop' into 'master'
mbenson1 May 26, 2024
0bd9bc9
Merge branch 'develop'
mbenson1 May 26, 2024
911817a
Merge branch 'develop'
mbenson1 May 26, 2024
523888c
-Write macro records correctly. Fixes #7
lorenzo-gomez-windhover May 31, 2024
32f52e6
-Cleanup
lorenzo-gomez-windhover May 31, 2024
dfed942
Merge branch 'develop' into 'master'
lorenzo-gomez-windhover Sep 20, 2024
60c6ea1
Merge remote-tracking branch 'origin/develop' into 7-write-macro-reco…
lorenzo-gomez-windhover Dec 12, 2024
38f7960
Merge branch '7-write-macro-records-correctly' into 'master'
lorenzo-gomez-windhover Dec 12, 2024
8b97106
-Add namespaces unit test. WIP.
lorenzo-gomez-windhover Dec 18, 2024
39b667c
-Add namespaces unit test. WIP.
lorenzo-gomez-windhover Dec 18, 2024
bc1222c
-Add namespaces. WIP.
lorenzo-gomez-windhover Dec 19, 2024
77797ba
-Add namespaces table
lorenzo-gomez-windhover Dec 19, 2024
8f6656f
-Add namespace child and parent. Might be better to represent this as…
lorenzo-gomez-windhover Dec 20, 2024
46e03f1
-Refactor namespace class. Return name as reference rather than copy.
lorenzo-gomez-windhover Jan 7, 2025
a031a0b
-Namespace implementation almost complete
lorenzo-gomez-windhover Jan 7, 2025
04c6433
-Minimally working impl of namespaces.
lorenzo-gomez-windhover Jan 9, 2025
2f4577d
-Minimally working impl for namespaces. Needs to be cleaned up and li…
lorenzo-gomez-windhover Jan 10, 2025
2cf67db
-Update unit tests for namespaces
lorenzo-gomez-windhover Jan 10, 2025
da5d37c
-Format code
lorenzo-gomez-windhover Jan 10, 2025
273e766
-Cleanup
lorenzo-gomez-windhover Jan 10, 2025
8df859a
-Cleanup
lorenzo-gomez-windhover Jan 10, 2025
8a308e5
-Refactor and cleanup process_DW_TAG_namespace
lorenzo-gomez-windhover Jan 10, 2025
b2f6c14
-Link namespaces to symbols. WIP.
lorenzo-gomez-windhover Jan 10, 2025
c2a62cf
-Get fqn from DIE up to root. Needs cleanup.
lorenzo-gomez-windhover Jan 14, 2025
fec8702
-Add getPathForTargetDie. Useful for finding the tree path to structs…
lorenzo-gomez-windhover Jan 14, 2025
bb35ffa
-Minimally functional implementation of namespaces. Needs to be docum…
lorenzo-gomez-windhover Jan 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 65 additions & 8 deletions src/ElfFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,37 @@ std::string ElfFile::getMD5() const { return md5; }
*nonetheless. Will re-evaluate. Visit https://en.cppreference.com/w/cpp/utility/optional
*and https://en.cppreference.com/w/cpp/utility/tuple for details.
*/
Symbol* ElfFile::getSymbol(std::string& name)
Symbol* ElfFile::getSymbol(std::string& name, Namespace* ns)
{
Symbol* returnSymbol = nullptr;

for (auto&& symbol : symbols)
{
if (symbol->getName() == name)
if (ns != nullptr && symbol->getNamespace() != nullptr)
{
returnSymbol = symbol.get();
if (symbol->getName() == name && symbol->getNamespace()->getFullyQualifiedName() == ns->getFullyQualifiedName())
{
returnSymbol = symbol.get();
}
}

else if (ns == nullptr && symbol->getNamespace() == nullptr)
{
{
if (symbol->getName() == name)
{
returnSymbol = symbol.get();
}
}
}
}

return returnSymbol;
}

Symbol* ElfFile::addSymbol(std::string& inName, uint32_t inByteSize, Artifact newArtifact, Symbol* targetSymbol)
Symbol* ElfFile::addSymbol(std::string& inName, uint32_t inByteSize, Artifact newArtifact, Symbol* targetSymbol, Namespace* symbolNamepace)
{
Symbol* symbol = getSymbol(inName);
Symbol* symbol = getSymbol(inName, symbolNamepace);

if (symbol == nullptr)
{
Expand All @@ -102,13 +115,14 @@ Symbol* ElfFile::addSymbol(std::string& inName, uint32_t inByteSize, Artifact ne
return symbol;
}

Symbol* ElfFile::addSymbol(std::string& inName, uint32_t inByteSize, Artifact newArtifact)
Symbol* ElfFile::addSymbol(std::string& inName, uint32_t inByteSize, Artifact newArtifact, Namespace* symbolNamepace)
{
Symbol* symbol = getSymbol(inName);
Symbol* symbol = getSymbol(inName, symbolNamepace);

if (symbol == nullptr)
{
std::unique_ptr<Symbol> newSymbol = std::make_unique<Symbol>(*this, inName, inByteSize, newArtifact);
newSymbol->setNamespace(symbolNamepace);

symbols.push_back(std::move(newSymbol));

Expand Down Expand Up @@ -238,4 +252,47 @@ void ElfFile::setElfClass(int newelfClass)
}
}

int ElfFile::getElfClass() { return elfClass; }
int ElfFile::getElfClass() { return elfClass; }

void ElfFile::addNamespace(Namespace newNamespace)
{
// Check if the namespace already exists
// for (auto&& namespace_ : namespaces)
// {
// if (namespace_->getName() == newNamespace.getName())
// {
// // Logger::getInstance().logError("Namespace already exists in the list");
// return;
// }
// }
namespaces.push_back(std::make_unique<Namespace>(newNamespace));
}

void ElfFile::addNamespace(std::unique_ptr<Namespace> newNamespace)
{
// Check if the namespace already exists
for (auto&& namespace_ : namespaces)
{
if (namespace_->getFullyQualifiedName() == newNamespace->getFullyQualifiedName())
{
// Logger::getInstance().logError("Namespace already exists in the list");
return;
}
}
namespaces.push_back(std::move(newNamespace));
}

Namespace* ElfFile::getNamespace(std::string name)
{
for (auto&& namespace_ : namespaces)
{
if (namespace_->getFullyQualifiedName() == name)
{
return namespace_.get();
}
}

return nullptr;
}

std::vector<std::unique_ptr<Namespace>>& ElfFile::getNamespaces() { return namespaces; }
51 changes: 30 additions & 21 deletions src/ElfFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
#include "Field.h"
#include "Juicer.h"
#include "Logger.h"
#include "Namespace.hpp"
#include "Variable.h"
#include "dwarf.h"

class Symbol;
class Field;
class Enumeration;
class Variable;
class Namespace;

/**
* The elf class contains an "module" with a user-defined name.
Expand All @@ -46,25 +48,25 @@ class ElfFile
public:
ElfFile(std::string &name);
virtual ~ElfFile();
std::vector<std::unique_ptr<Symbol>> &getSymbols();

std::string getName() const;
uint32_t getId(void) const;
void setId(uint32_t newId);
Symbol *addSymbol(std::string &name, uint32_t byte_size, Artifact newArtifact);
Symbol *addSymbol(std::string &inName, uint32_t inByteSize, Artifact newArtifact, Symbol *targetSymbol);
std::vector<Field *> getFields();
std::vector<Enumeration *> getEnumerations();
Symbol *getSymbol(std::string &name);
const std::string &getDate() const;
void setDate(const std::string &date);
bool isLittleEndian() const;
void isLittleEndian(bool littleEndian);
void setMD5(std::string newID);
std::string getMD5() const;
void addDefineMacro(DefineMacro newMacro);

const std::vector<DefineMacro> &getDefineMacros() const;
std::vector<std::unique_ptr<Symbol>> &getSymbols();

std::string getName() const;
uint32_t getId(void) const;
void setId(uint32_t newId);
Symbol *addSymbol(std::string &name, uint32_t byte_size, Artifact newArtifact, Namespace *symbolNamepace);
Symbol *addSymbol(std::string &inName, uint32_t inByteSize, Artifact newArtifact, Symbol *targetSymbol, Namespace *symbolNamepace);
std::vector<Field *> getFields();
std::vector<Enumeration *> getEnumerations();
Symbol *getSymbol(std::string &name, Namespace *ns);
const std::string &getDate() const;
void setDate(const std::string &date);
bool isLittleEndian() const;
void isLittleEndian(bool littleEndian);
void setMD5(std::string newID);
std::string getMD5() const;
void addDefineMacro(DefineMacro newMacro);

const std::vector<DefineMacro> &getDefineMacros() const;

const std::map<std::string, std::vector<uint8_t>> &getInitializedSymbolData() const;

Expand All @@ -91,6 +93,11 @@ class ElfFile

void setElfClass(int newelfClass);

void addNamespace(Namespace newNamespace);
void addNamespace(std::unique_ptr<Namespace> newNamespace);
std::vector<std::unique_ptr<Namespace>> &getNamespaces();
Namespace *getNamespace(std::string name);

private:
std::string md5;
/**
Expand Down Expand Up @@ -155,7 +162,7 @@ class ElfFile

};

Encoding &getDWARFEncoding();
Encoding &getDWARFEncoding();

/**
* @brief elfClass
Expand All @@ -164,7 +171,9 @@ class ElfFile
* #define ELFCLASS32 1 32-bit objects
* #define ELFCLASS64 2 64-bit objects
*/
int elfClass{ELFCLASSNONE};
int elfClass{ELFCLASSNONE};

std::vector<std::unique_ptr<Namespace>> namespaces{};
};

#endif /* ElfFile_H_ */
Loading
Loading