Package ghidra.program.database.mem
Class FileBytes
- java.lang.Object
-
- ghidra.program.database.mem.FileBytes
-
public class FileBytes extends java.lang.Object
FileBytes provides access to the all the byte values (both original and modified) from an imported file.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
java.lang.String
getFilename()
Returns the name of the file that supplied the bytes.long
getFileOffset()
Returns the offset in the original file from where these bytes originated.byte
getModifiedByte(long offset)
Returns the (possibly modified) byte at the given offset for this file bytes object.int
getModifiedBytes(long offset, byte[] b)
Tries to get b.length (possibly modified) bytes from this FileBytes entry at the given offset into the file bytes.int
getModifiedBytes(long offset, byte[] b, int off, int length)
Tries to get length (possibly modified) bytes from the files starting at the given offset and put them into the given byte array at the specified offset into the byte array.byte
getOriginalByte(long offset)
Returns the original byte value at the given offset for this file bytes object.int
getOriginalBytes(long offset, byte[] b)
Tries to get b.length original bytes from this FileBytes entry at the given offset into the file bytes.int
getOriginalBytes(long offset, byte[] b, int off, int length)
Tries to get length (original) bytes from the files starting at the given offset and put them into the given byte array at the specified offset into the byte array.long
getSize()
Returns the number of bytes from the original source file that are stored in the database.int
hashCode()
java.lang.String
toString()
-
-
-
Constructor Detail
-
FileBytes
public FileBytes(ghidra.program.database.mem.FileBytesAdapter adapter, Record record) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
getFilename
public java.lang.String getFilename()
Returns the name of the file that supplied the bytes.- Returns:
- the name of the file that supplied the bytes.
-
getFileOffset
public long getFileOffset()
Returns the offset in the original file from where these bytes originated. Normally this will be 0, but in the case where the program is actually a piece in some other file (e.g. tar,zip), this will be the offset into the file corresponding to the first byte in this FileBytes object.- Returns:
- the offset in the original file from where these bytes originated.
-
getSize
public long getSize()
Returns the number of bytes from the original source file that are stored in the database.- Returns:
- the number of bytes from the original source file that are stored in the database.
-
getModifiedByte
public byte getModifiedByte(long offset) throws java.io.IOException
Returns the (possibly modified) byte at the given offset for this file bytes object.- Parameters:
offset
- the offset into the file bytes for the byte to retrieve.- Returns:
- the (possibly modified) byte at the given offset for this file bytes object.
- Throws:
java.io.IOException
- if there is a problem reading the database.java.lang.IndexOutOfBoundsException
- if the given offset is invalid.
-
getOriginalByte
public byte getOriginalByte(long offset) throws java.io.IOException
Returns the original byte value at the given offset for this file bytes object.- Parameters:
offset
- the offset into the file bytes for the byte to retrieve.- Returns:
- the original byte at the given offset for this file bytes object.
- Throws:
java.io.IOException
- if there is a problem reading the database.java.lang.IndexOutOfBoundsException
- if the given offset is invalid.
-
getModifiedBytes
public int getModifiedBytes(long offset, byte[] b) throws java.io.IOException
Tries to get b.length (possibly modified) bytes from this FileBytes entry at the given offset into the file bytes. May return fewer bytes if the requested length is beyond the end of the file bytes.- Parameters:
offset
- the offset into the files bytes to start.b
- the byte array to populate.- Returns:
- the number of bytes actually populated.
- Throws:
java.io.IOException
- if there is an error reading from the database
-
getOriginalBytes
public int getOriginalBytes(long offset, byte[] b) throws java.io.IOException
Tries to get b.length original bytes from this FileBytes entry at the given offset into the file bytes. May return fewer bytes if the requested length is beyond the end of the file bytes.- Parameters:
offset
- the offset into the files bytes to start.b
- the byte array to populate.- Returns:
- the number of bytes actually populated.
- Throws:
java.io.IOException
- if there is an error reading from the database
-
getModifiedBytes
public int getModifiedBytes(long offset, byte[] b, int off, int length) throws java.io.IOException
Tries to get length (possibly modified) bytes from the files starting at the given offset and put them into the given byte array at the specified offset into the byte array. May return fewer bytes if the requested length is beyond the end of the file bytes.- Parameters:
offset
- the offset into the files bytes to start.b
- the byte array to populate.off
- the offset into the byte array.length
- the number of bytes to get.- Returns:
- the number of bytes actually populated.
- Throws:
java.io.IOException
- if there is an error reading from the databasejava.lang.IndexOutOfBoundsException
- if the destination offset and length would exceed the size of the buffer b.
-
getOriginalBytes
public int getOriginalBytes(long offset, byte[] b, int off, int length) throws java.io.IOException
Tries to get length (original) bytes from the files starting at the given offset and put them into the given byte array at the specified offset into the byte array. May return fewer bytes if the requested length is beyond the end of the file bytes.- Parameters:
offset
- the offset into the files bytes to start.b
- the byte array to populate.off
- the offset into the byte array.length
- the number of bytes to get.- Returns:
- the number of bytes actually populated.
- Throws:
java.io.IOException
- if there is an error reading from the databasejava.lang.IndexOutOfBoundsException
- if the destination offset and length would exceed the size of the buffer b.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
-