Skip to content

Commit

Permalink
Remove 32 address and offset
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Chwedczuk committed Dec 19, 2021
1 parent 99234ab commit c7eac28
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 105 deletions.
1 change: 0 additions & 1 deletion elf-reader/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
exports pl.marcinchwedczuk.elfviewer.elfreader.elf;
exports pl.marcinchwedczuk.elfviewer.elfreader.elf.shared;

exports pl.marcinchwedczuk.elfviewer.elfreader.elf32;
exports pl.marcinchwedczuk.elfviewer.elfreader.elf32.intel32;

exports pl.marcinchwedczuk.elfviewer.elfreader.io;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import pl.marcinchwedczuk.elfviewer.elfreader.elf.shared.sections.ElfSectionFactory;
import pl.marcinchwedczuk.elfviewer.elfreader.elf.shared.segments.ElfProgramHeader;
import pl.marcinchwedczuk.elfviewer.elfreader.elf.shared.segments.ElfSegmentFactory;
import pl.marcinchwedczuk.elfviewer.elfreader.elf32.*;
import pl.marcinchwedczuk.elfviewer.elfreader.endianness.BigEndian;
import pl.marcinchwedczuk.elfviewer.elfreader.endianness.Endianness;
import pl.marcinchwedczuk.elfviewer.elfreader.endianness.LittleEndian;
Expand Down Expand Up @@ -275,9 +274,9 @@ private static List<ElfProgramHeader<Integer>> readElf32ProgramHeaders(

private static ElfProgramHeader<Integer> readElf32ProgramHeader(StructuredFile32 headerFile) {
ElfSegmentType type = ElfSegmentType.fromValue(headerFile.readUnsignedInt());
Elf32Offset fileOffset = headerFile.readOffset();
Elf32Address virtualAddress = headerFile.readAddress();
Elf32Address physicalAddress = headerFile.readAddress();
ElfOffset<Integer> fileOffset = headerFile.readOffset();
ElfAddress<Integer> virtualAddress = headerFile.readAddress();
ElfAddress<Integer> physicalAddress = headerFile.readAddress();
int fileSize = headerFile.readUnsignedInt();
int memorySize = headerFile.readUnsignedInt();
ElfSegmentFlags flags = new ElfSegmentFlags(headerFile.readUnsignedInt());
Expand Down Expand Up @@ -372,8 +371,8 @@ private static ElfSectionHeader<Integer> readElf32SectionHeader(
StringTableIndex sectionNameIndex = new StringTableIndex(headerFile.readUnsignedInt());
ElfSectionType type = ElfSectionType.fromValue(headerFile.readUnsignedInt());
SectionAttributes flags = new SectionAttributes(headerFile.readUnsignedInt());
Elf32Address inMemoryAddress = headerFile.readAddress();
Elf32Offset offsetInFile = headerFile.readOffset();
ElfAddress<Integer> inMemoryAddress = headerFile.readAddress();
ElfOffset<Integer> offsetInFile = headerFile.readOffset();
int sectionSize = headerFile.readUnsignedInt();
int link = headerFile.readUnsignedInt();
int info = headerFile.readUnsignedInt();
Expand All @@ -384,7 +383,7 @@ private static ElfSectionHeader<Integer> readElf32SectionHeader(
.map(st -> st.getStringAtIndex(sectionNameIndex))
.orElse("(not-resolved)");

return new ElfSectionHeader<Integer>(
return new ElfSectionHeader<>(
sectionNameIndex,
sectionName,
type,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package pl.marcinchwedczuk.elfviewer.elfreader.elf.arch;

import pl.marcinchwedczuk.elfviewer.elfreader.elf.shared.ElfAddress;
import pl.marcinchwedczuk.elfviewer.elfreader.elf.shared.ElfOffset;
import pl.marcinchwedczuk.elfviewer.elfreader.elf.shared.ElfRelocation;
import pl.marcinchwedczuk.elfviewer.elfreader.elf.shared.ElfRelocationAddend;
import pl.marcinchwedczuk.elfviewer.elfreader.elf32.Elf32Address;
import pl.marcinchwedczuk.elfviewer.elfreader.elf32.Elf32Offset;
import pl.marcinchwedczuk.elfviewer.elfreader.elf.shared.*;
import pl.marcinchwedczuk.elfviewer.elfreader.io.StructuredFile;

import java.util.stream.IntStream;
Expand All @@ -18,12 +13,12 @@ public NativeWordType type() {

@Override
public ElfOffset<Integer> zeroOffset() {
return Elf32Offset.ZERO;
return new ElfOffsetAny<>(0);
}

@Override
public ElfAddress<Integer> zeroAddress() {
return new Elf32Address(0);
return new ElfAddressAny<>(0);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package pl.marcinchwedczuk.elfviewer.elfreader.elf.shared;

import pl.marcinchwedczuk.elfviewer.elfreader.elf32.Elf32Address;

import java.util.Objects;

import static java.util.Objects.requireNonNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pl.marcinchwedczuk.elfviewer.elfreader.elf.shared;

// @ElfApi("Elf32_Addr")
public class ElfAddressAny<
NATIVE_WORD extends Number & Comparable<NATIVE_WORD>
> extends ElfAddress<NATIVE_WORD> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package pl.marcinchwedczuk.elfviewer.elfreader.elf.shared;

import pl.marcinchwedczuk.elfviewer.elfreader.elf32.Elf32Address;
import pl.marcinchwedczuk.elfviewer.elfreader.elf32.intel32.Intel386RelocationType;
import pl.marcinchwedczuk.elfviewer.elfreader.meta.ElfApi;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package pl.marcinchwedczuk.elfviewer.elfreader.elf.shared.notes;

import pl.marcinchwedczuk.elfviewer.elfreader.elf32.Elf32Offset;
import pl.marcinchwedczuk.elfviewer.elfreader.endianness.LittleEndian;
import pl.marcinchwedczuk.elfviewer.elfreader.io.InMemoryFile;
import pl.marcinchwedczuk.elfviewer.elfreader.io.StructuredFile32;
Expand Down Expand Up @@ -32,7 +31,7 @@ public String minSupportedKernelVersion() {
StructuredFile32 sf = new StructuredFile32(
new InMemoryFile(descriptor()),
new LittleEndian(),
Elf32Offset.ZERO);
0L);

if (descriptorLength() != 16 || sf.readUnsignedInt() != 0) {
throw new IllegalStateException("Invalid OS signature or descriptor.");
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package pl.marcinchwedczuk.elfviewer.elfreader.io;

import pl.marcinchwedczuk.elfviewer.elfreader.ElfReaderException;
import pl.marcinchwedczuk.elfviewer.elfreader.elf.shared.ElfOffset;
import pl.marcinchwedczuk.elfviewer.elfreader.elf32.Elf32Offset;

import static java.util.Objects.requireNonNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package pl.marcinchwedczuk.elfviewer.elfreader.io;

import pl.marcinchwedczuk.elfviewer.elfreader.elf.shared.ElfFile;
import pl.marcinchwedczuk.elfviewer.elfreader.elf.shared.ElfOffset;
import pl.marcinchwedczuk.elfviewer.elfreader.elf32.Elf32Address;
import pl.marcinchwedczuk.elfviewer.elfreader.elf32.Elf32Offset;
import pl.marcinchwedczuk.elfviewer.elfreader.elf.shared.*;
import pl.marcinchwedczuk.elfviewer.elfreader.endianness.Endianness;

public class StructuredFile32 extends StructuredFile<Integer> {
Expand All @@ -25,25 +22,20 @@ public StructuredFile32(ElfFile<Integer> file, ElfOffset<Integer> offset) {

@Override
protected ElfOffset<Integer> mkOffset(long offset) {
return new Elf32Offset(Math.toIntExact(offset));
return new ElfOffsetAny<>(Math.toIntExact(offset));
}

@Override
public Elf32Offset readOffset() {
public ElfOffset<Integer> readOffset() {
byte[] addressBytes = readNext(4);
int address = endianness.toUnsignedInt(addressBytes);
return new Elf32Offset(address);
return new ElfOffsetAny<>(address);
}

@Override
public Elf32Address readAddress() {
public ElfAddress<Integer> readAddress() {
byte[] addressBytes = readNext(4);
int address = endianness.toUnsignedInt(addressBytes);
return new Elf32Address(address);
}

@Override
public Elf32Offset currentPositionInFile() {
return (Elf32Offset) super.currentPositionInFile();
return new ElfAddressAny<>(address);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import pl.marcinchwedczuk.elfviewer.elfreader.elf.shared.ElfAddress;
import pl.marcinchwedczuk.elfviewer.elfreader.elf.shared.ElfOffset;
import pl.marcinchwedczuk.elfviewer.elfreader.elf32.Elf32Address;
import pl.marcinchwedczuk.elfviewer.elfreader.elf32.Elf32Offset;

public class StructureFieldDto {
private final String fieldName;
Expand Down

0 comments on commit c7eac28

Please sign in to comment.