Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Computation of section entropies for ELF, MACHO and PE (in progress) #501

Closed
wants to merge 39 commits into from

Conversation

JakubPruzinec
Copy link
Contributor

@JakubPruzinec JakubPruzinec commented Feb 14, 2019

#502
I've implemented extraction of section entropies for various file formats.
Tests are not implemented yet, thus the "in progress" status.

@s3rvac
Copy link
Member

s3rvac commented Feb 15, 2019

It seems that this branch is based on the branch for #440 (it contains the same commits). Shouldn't it be based on master?

@JakubPruzinec
Copy link
Contributor Author

right, i'll fix that

{
const auto overlaySize = getOverlaySize();
const auto declSize = getDeclaredFileLength();
const auto bytes = getBytes();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beware that storing the result of

const std::vector<unsigned char>& getBytes() const;

into

const auto bytes = getBytes();

causes the vector to be copied, i.e. the type of bytes will be const std::vector<unsigned char>. I believe what you want is

const auto &bytes = getBytes();

which will store a reference, i.e. the type of bytes will be const std::vector<unsigned char> &.

return;
}

auto data = reinterpret_cast<const uint8_t *>(bytes.data());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a reinterpret_cast cast for this? Doesn't a static_cast suffice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -118,6 +119,10 @@ void MachODetector::getSections()
fsec.setMemoryAlignment(pow(2, mSec->getAlignment()));
fsec.setRelocationsOffset(mSec->getRelocationOffset());
fsec.setNumberOfRelocations(mSec->getNumberOfRelocations());
if(sec->getEntropy(entropy))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest defining double entropy; right before if(sec->getEntropy(entropy)), not 14 lines before. It is generally a good practice to define variables as close to their first use, especially when they are not initialized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants