Skip to content

Commit

Permalink
Add test/64bit for gnu build attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Chwedczuk committed Dec 24, 2021
1 parent a7927cf commit d2a5f0b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public Object buildAttributeValue() {
case '$': {
StringBuilder value = new StringBuilder();
for (int curr = valueStart; curr < nameBytes.length; curr++) {
if (nameBytes[curr] == 0) break;
value.append((char)nameBytes[curr]);
}
return value.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,8 @@ public ElfGnuVersionDefinitionsSection<NATIVE_WORD> asGnuVersionDefinitionsSecti
public ElfGnuWarningSection<NATIVE_WORD> asGnuWarningSection() {
return (ElfGnuWarningSection<NATIVE_WORD>) this;
}

public ElfNotesSection<NATIVE_WORD> asNotesSection() {
return (ElfNotesSection<NATIVE_WORD>) this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pl.marcinchwedczuk.elfviewer.elfreader.elf.*;
import pl.marcinchwedczuk.elfviewer.elfreader.elf.shared.*;
import pl.marcinchwedczuk.elfviewer.elfreader.elf.shared.notes.ElfNoteGnuABITag;
import pl.marcinchwedczuk.elfviewer.elfreader.elf.shared.notes.ElfNoteGnuBuildAttribute;
import pl.marcinchwedczuk.elfviewer.elfreader.elf.shared.notes.ElfNoteGnuBuildId;
import pl.marcinchwedczuk.elfviewer.elfreader.elf.shared.sections.*;
import pl.marcinchwedczuk.elfviewer.elfreader.elf.shared.segments.ElfProgramHeader;
Expand All @@ -19,7 +20,9 @@
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static pl.marcinchwedczuk.elfviewer.elfreader.elf.shared.ElfDynamicTagType.INIT;
import static pl.marcinchwedczuk.elfviewer.elfreader.elf.shared.ElfDynamicTagType.NEEDED;
Expand Down Expand Up @@ -568,4 +571,36 @@ void elf64_gnu_warning() {
assertThat(warningSection.warning())
.isEqualTo("the `gets' function is dangerous and should not be used.");
}

@Test
void elf64_gnu_build_attributes() {
ElfFile<Long> elfFile = ElfReader.readElf64(arm64libc);

ElfNotesSection<Long> notesSection = elfFile
.sectionWithName(ElfSectionNames.GNU_BUILD_ATTRIBUTES)
.get()
.asNotesSection();

List<ElfNoteGnuBuildAttribute> buildAttributes = notesSection.notes().stream()
.map(ElfNoteGnuBuildAttribute.class::cast)
.collect(toList());

// annobin version - String value
assertThat(buildAttributes.get(1).buildAttributeName())
.isEqualTo("build tool version");
assertThat(buildAttributes.get(1).buildAttributeValue())
.isEqualTo("annobin gcc 11.0.0 20210210");

// FORTIFY - Numeric value
assertThat(buildAttributes.get(6).buildAttributeName())
.isEqualTo("FORTIFY");
assertThat(buildAttributes.get(6).buildAttributeValue())
.isEqualTo((Object)0xfeL);

// GLIBCXX_ASSERTIONS - Boolean True Value
assertThat(buildAttributes.get(7).buildAttributeName())
.isEqualTo("GLIBCXX_ASSERTIONS");
assertThat(buildAttributes.get(7).buildAttributeValue())
.isEqualTo(Boolean.TRUE);
}
}

0 comments on commit d2a5f0b

Please sign in to comment.