Package ghidra.pcode.emu.sys

# Interface EmuFileContents<T>

Type Parameters:
  `T` - the type of values in the file

All Known Implementing Classes:
  `BytesEmuFileContents`, `PairedEmuFileContents`, `TaintEmuUnixFileSystem.ReadOnlyTaintArrayFileContents`, `TaintEmuUnixFileSystem.UntaintedFileContents`

public interface EmuFileContents<T>
The content store to back a simulated file

TODO: Could/should this just be the same interface as an execute state? If so, we'd need to formalize the store interface and require one for each address space in the state. Sharing that interface may not be a good idea.... I think implementors can use a common realization if that suits them.

TODO: Actually, a better idea might be to introduce an address factory with custom spaces into the emulator. Then a library/file could just create an address space and use the state to store and retrieve the file contents. Better yet, when written down, those contents and markings could appear in the user's trace.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `long`
  `read(long offset, T buf, long fileSize)`
  Copy values from the file into the given buffer
  `void`
  `truncate()`
  Erase the contents
  `long`
  `write(long offset, T buf, long curSize)`
  Write values from the given buffer into the file

- ## Method Details

  - ### read

    long read(long offset, T buf, long fileSize)
    Copy values from the file into the given buffer
    Parameters:
      `offset` - the offset in the file to read
      `buf` - the destination buffer, whose size must be known
      `fileSize` - the size of the file
    Returns:
      the number of bytes (not necessarily concrete) read

  - ### write

    long write(long offset, T buf, long curSize)
    Write values from the given buffer into the file
    Parameters:
      `offset` - the offset in the file to write
      `buf` - the source buffer, whose size must be known
      `curSize` - the current size of the file
    Returns:
      the number of bytes (not necessarily concrete) written

  - ### truncate

    void truncate()
    Erase the contents

    Note that the file's size will be set to 0, so actual erasure of the contents may not be necessary, but if the contents are expensive to store, they ought to be disposed.