Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ledmington committed Sep 20, 2024
1 parent 31a4031 commit c3b482e
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@

import java.util.Objects;

/** A x86_64 specific unwind ELF section (such as '.eh_frame'). */
public final class X86_64_Unwind implements Section {

private final String name;
private final SectionHeader header;

/**
* Creates a x86_64 unwind section with the given data.
*
* @param name The name of this section.
* @param sectionHeader The header of this section.
*/
public X86_64_Unwind(final String name, final SectionHeader sectionHeader) {
this.name = Objects.requireNonNull(name);
this.header = Objects.requireNonNull(sectionHeader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public GnuVersionDefinitionSection(

int versionDefinitionEntryNum = 0;
{
Objects.requireNonNull(dynamicSection);
for (int i = 0; i < dynamicSection.getTableLength(); i++) {
if (dynamicSection.getEntry(i).getTag() == DynamicTableEntryTag.DT_VERDEFNUM) {
versionDefinitionEntryNum =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public GnuVersionRequirementsSection(

int versionRequirementsEntryNum = 0;
{
Objects.requireNonNull(dynamicSection);
for (int i = 0; i < dynamicSection.getTableLength(); i++) {
if (dynamicSection.getEntry(i).getTag() == DynamicTableEntryTag.DT_VERNEEDNUM) {
versionRequirementsEntryNum =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public final class GnuGoldVersion implements NoteSection {
private final SectionHeader header;
private final NoteSectionEntry[] entries;

/**
* Creates a .note.gnu.gold-version section with the given data.
*
* @param sectionHeader The header of this section.
* @param b The ReadOnlyByteBuffer to read data from.
*/
public GnuGoldVersion(final SectionHeader sectionHeader, final ReadOnlyByteBuffer b) {
this.header = Objects.requireNonNull(sectionHeader);

Expand Down
15 changes: 12 additions & 3 deletions emu-gui/src/main/java/com/ledmington/emu/AppConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ private AppConstants() {}
public static final String tmpDirectoryPath = System.getProperty("java.io.tmpdir");

/** Shorthand monospace font family. */
public static String MONOSPACE_FONT_FAMILY = Font.getFamilies().contains("Consolas")
private static String MONOSPACE_FONT_FAMILY = Font.getFamilies().contains("Consolas")
? "Consolas"
: Font.getDefault().getFamily();

public static String getDefaultMonospaceFont() {
return MONOSPACE_FONT_FAMILY;
}

public static void setDefaultMonospaceFont(final String monospaceFontFamily) {
Objects.requireNonNull(monospaceFontFamily);
if (monospaceFontFamily.isEmpty()
Expand All @@ -68,10 +72,15 @@ public static void setDefaultMonospaceFont(final String monospaceFontFamily) {
}

/** Shorthand default font size. */
public static int DEFAULT_FONT_SIZE = 12;
private static int DEFAULT_FONT_SIZE = 12;

public static int getDefaultFontSize() {
return DEFAULT_FONT_SIZE;
}

public static void setDefaultFontSize(final int newFontSize) {
if (newFontSize <= 1) {
final int minFontSize = 1;
if (newFontSize <= minFontSize) {
throw new IllegalArgumentException(String.format("Invalid font size: %,d", newFontSize));
}
DEFAULT_FONT_SIZE = newFontSize;
Expand Down
2 changes: 1 addition & 1 deletion emu-gui/src/main/java/com/ledmington/emu/ELFViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void loadFile(final File elfFile) {
sb.append('\n');
}
}
textArea.setFont(new Font(AppConstants.MONOSPACE_FONT_FAMILY, AppConstants.DEFAULT_FONT_SIZE));
textArea.setFont(new Font(AppConstants.getDefaultMonospaceFont(), AppConstants.getDefaultFontSize()));
this.textArea.setText(sb.toString());
}
}
14 changes: 9 additions & 5 deletions emu-gui/src/main/java/com/ledmington/emu/SettingsWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ public SettingsWindow() {
mainPane.getChildren().add(new Label("Font"));
fonts = new ComboBox<>();
for (final String fontFamily : Font.getFamilies()) {
final Label lbl = new Label(fontFamily);
lbl.setFont(
Font.font(fontFamily, FontWeight.NORMAL, FontPosture.REGULAR, AppConstants.DEFAULT_FONT_SIZE));
lbl.setTextFill(Color.BLACK);
final Label lbl = getFontLabel(fontFamily);
fonts.getItems().add(lbl);
if (fonts.getValue() == null) {
fonts.setValue(lbl);
Expand All @@ -59,7 +56,7 @@ public SettingsWindow() {
}
{
mainPane.getChildren().add(new Label("Font Size"));
fontSize = new Spinner<>(1, 20, AppConstants.DEFAULT_FONT_SIZE);
fontSize = new Spinner<>(1, 20, AppConstants.getDefaultFontSize());
mainPane.getChildren().add(fontSize);
}
bPane.setCenter(mainPane);
Expand All @@ -86,4 +83,11 @@ public SettingsWindow() {

Platform.runLater(this::requestFocus);
}

private Label getFontLabel(final String fontFamily) {
final Label lbl = new Label(fontFamily);
lbl.setFont(Font.font(fontFamily, FontWeight.NORMAL, FontPosture.REGULAR, AppConstants.getDefaultFontSize()));
lbl.setTextFill(Color.BLACK);
return lbl;
}
}
7 changes: 4 additions & 3 deletions readelf/src/main/java/com/ledmington/readelf/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,6 @@ private static void printGNUProperties(final NoteSectionEntry nse) {
v[i] = nse.getDescriptionByte(i);
}

// (wide ? "" : "\t") +
out.print(" Properties: ");

final ReadOnlyByteBuffer robb = new ReadOnlyByteBufferV1(v, true, 1L);
Expand All @@ -1002,7 +1001,8 @@ private static void printGNUProperties(final NoteSectionEntry nse) {
GNU_PROPERTY_X86_ISA_1_USED -> throw new UnsupportedOperationException(
"Unimplemented case: " + type);
case GNU_PROPERTY_X86_ISA_1_NEEDED -> {
if (robb.getPosition() > 8) {
final long expectedBytes = 8L;
if (robb.getPosition() > expectedBytes) {
out.print(wide ? "" : "\t");
}
out.print("x86 ISA needed: ");
Expand Down Expand Up @@ -1031,7 +1031,8 @@ private static void printGNUProperties(final NoteSectionEntry nse) {
out.println();
}
case GNU_PROPERTY_X86_FEATURE_1_AND -> {
if (robb.getPosition() > 8) {
final long expectedBytes = 8L;
if (robb.getPosition() > expectedBytes) {
out.print(wide ? "" : "\t");
}
out.print("x86 feature: ");
Expand Down

0 comments on commit c3b482e

Please sign in to comment.