diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/ByteProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/ByteProvider.java index 0e41572d2c..2e37141ccd 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/ByteProvider.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/ByteProvider.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -28,7 +28,7 @@ public interface ByteProvider extends Closeable { /** * A static re-usable empty {@link ByteProvider} instance. */ - public static final ByteProvider EMPTY_BYTEPROVIDER = new EmptyByteProvider(); + ByteProvider EMPTY_BYTEPROVIDER = new EmptyByteProvider(); /** * Returns the {@link FSRL} of the underlying file for this byte provider, @@ -37,7 +37,7 @@ public interface ByteProvider extends Closeable { * @return The {@link FSRL} of the underlying {@link File}, or null if no associated * {@link File}. */ - default public FSRL getFSRL() { + default FSRL getFSRL() { File f = getFile(); return (f != null) ? FileSystemService.getInstance().getLocalFSRL(f) : null; } @@ -48,14 +48,14 @@ public interface ByteProvider extends Closeable { * * @return the underlying file for this byte provider */ - public File getFile(); + File getFile(); /** * Returns the name of the {@link ByteProvider}. For example, the underlying file name. * * @return the name of the {@link ByteProvider} or null if there is no name */ - public String getName(); + String getName(); /** * Returns the absolute path (similar to, but not a, URI) to the {@link ByteProvider}. @@ -64,28 +64,22 @@ public interface ByteProvider extends Closeable { * @return the absolute path to the {@link ByteProvider} or null if not associated with a * {@link File}. */ - public String getAbsolutePath(); + String getAbsolutePath(); /** * Returns the length of the {@link ByteProvider} * * @return the length of the {@link ByteProvider} - * @throws IOException if an I/O error occurs */ - public long length() throws IOException; + long length(); /** * Returns true if this ByteProvider does not contain any bytes. * * @return boolean true if this provider is empty, false if contains bytes */ - default public boolean isEmpty() { - try { - return length() == 0; - } - catch (IOException e) { - return true; - } + default boolean isEmpty() { + return length() == 0; } /** @@ -94,7 +88,7 @@ public interface ByteProvider extends Closeable { * @param index the index in the byte provider to check * @return true if the specified index is valid */ - public boolean isValidIndex(long index); + boolean isValidIndex(long index); /** * Releases any resources the {@link ByteProvider} may have occupied @@ -102,7 +96,7 @@ public interface ByteProvider extends Closeable { * @throws IOException if an I/O error occurs */ @Override - public void close() throws IOException; + void close() throws IOException; /** * Reads a byte at the specified index @@ -111,7 +105,7 @@ public interface ByteProvider extends Closeable { * @return the byte read from the specified index * @throws IOException if an I/O error occurs */ - public byte readByte(long index) throws IOException; + byte readByte(long index) throws IOException; /** * Reads a byte array at the specified index @@ -121,7 +115,7 @@ public interface ByteProvider extends Closeable { * @return the byte array read from the specified index * @throws IOException if an I/O error occurs */ - public byte[] readBytes(long index, long length) throws IOException; + byte[] readBytes(long index, long length) throws IOException; /** * Returns an input stream to the underlying byte provider starting at the specified index. @@ -135,7 +129,7 @@ public interface ByteProvider extends Closeable { * @return the {@link InputStream} * @throws IOException if an I/O error occurs */ - default public InputStream getInputStream(long index) throws IOException { + default InputStream getInputStream(long index) throws IOException { if (index < 0 || index > length()) { throw new IOException("Invalid start position: " + index); } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/ByteProviderWrapper.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/ByteProviderWrapper.java index c882b33959..3e02dbb681 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/ByteProviderWrapper.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/ByteProviderWrapper.java @@ -103,7 +103,7 @@ public class ByteProviderWrapper implements ByteProvider { } @Override - public long length() throws IOException { + public long length() { return subLength; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/FileByteProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/FileByteProvider.java index 0893196f4d..bb2d26a812 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/FileByteProvider.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/FileByteProvider.java @@ -106,7 +106,7 @@ public class FileByteProvider implements MutableByteProvider { } @Override - public long length() throws IOException { + public long length() { return currentLength; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/InputStreamByteProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/InputStreamByteProvider.java index b5c8b70884..f6ded3d200 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/InputStreamByteProvider.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/InputStreamByteProvider.java @@ -72,7 +72,7 @@ public class InputStreamByteProvider implements ByteProvider { } @Override - public long length() throws IOException { + public long length() { return length; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/MemoryByteProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/MemoryByteProvider.java index 1f38a3109a..94f629c626 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/MemoryByteProvider.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/MemoryByteProvider.java @@ -219,7 +219,7 @@ public class MemoryByteProvider implements ByteProvider { } @Override - public long length() throws IOException { + public long length() { if (isEmtpy) { return 0; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/RangeMappedByteProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/RangeMappedByteProvider.java index ad3a572c16..105f03ef01 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/RangeMappedByteProvider.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/RangeMappedByteProvider.java @@ -129,7 +129,7 @@ public class RangeMappedByteProvider implements ByteProvider { } @Override - public long length() throws IOException { + public long length() { return length; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/SynchronizedByteProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/SynchronizedByteProvider.java index 8f67f7b198..ff90d8aba4 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/SynchronizedByteProvider.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/SynchronizedByteProvider.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -55,7 +55,7 @@ public class SynchronizedByteProvider implements ByteProvider { } @Override - public synchronized long length() throws IOException { + public synchronized long length() { return provider.length(); } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfHeader.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfHeader.java index 02ba8459c1..c89f5e4fd5 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfHeader.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfHeader.java @@ -1067,12 +1067,7 @@ public class ElfHeader implements StructConverter { * @return true if provider contains specified byte offset range */ private boolean providerContainsRegion(long offset, int length) { - try { - return offset >= 0 && (offset + length) <= provider.length(); - } - catch (IOException e) { - return false; - } + return offset >= 0 && (offset + length) <= provider.length(); } protected void parseSectionHeaders() throws IOException { diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/BinaryLoader.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/BinaryLoader.java index 8b01e66fe0..f34ac34a0a 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/BinaryLoader.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/BinaryLoader.java @@ -27,7 +27,6 @@ import ghidra.program.model.address.*; import ghidra.program.model.lang.*; import ghidra.program.model.listing.Program; import ghidra.program.model.mem.Memory; -import ghidra.util.Msg; import ghidra.util.NumericUtilities; import ghidra.util.exception.CancelledException; @@ -94,12 +93,7 @@ public class BinaryLoader extends AbstractProgramLoader { long fileOffset = 0; long origFileLength; boolean isOverlay = false; - try { - origFileLength = provider.length(); - } - catch (IOException e) { - return "Error determining length: " + e.getMessage(); - } + origFileLength = provider.length(); for (Option option : options) { String optName = option.getName(); @@ -352,13 +346,7 @@ public class BinaryLoader extends AbstractProgramLoader { public List