KittyMemoryEx 1.0.0
Dedicated library for runtime code patching, memory scanning, tracing, injection and some more useful memory utilities. works for both Android and Linux
Loading...
Searching...
No Matches
KittyIOFile Class Reference

This class provides an interface for file operations. More...

#include <KittyIOFile.hpp>

Public Member Functions

 KittyIOFile ()
 Default constructor creating an uninitialized file object.
 KittyIOFile (const std::string &filePath, int flags, mode_t mode=0)
 Constructs a new KittyIOFile object with file path, flags, and optional mode.
 KittyIOFile (const KittyIOFile &)=delete
KittyIOFile & operator= (const KittyIOFile &)=delete
 KittyIOFile (KittyIOFile &&other) noexcept
 Move constructor. Transfers ownership of the file descriptor.
KittyIOFile & operator= (KittyIOFile &&other) noexcept
 Move assignment operator. Closes current file descriptor and transfers ownership.
bool open ()
 Opens the file.
bool close ()
 Closes the file.
int lastError () const
 Returns the last error.
std::string lastStrError () const
 Returns the last error message.
int fd () const
 Returns the file descriptor.
std::string path () const
 Returns the file path.
int flags () const
 Returns the file flags.
mode_t mode () const
 Returns the file mode.
ssize_t read (void *buffer, size_t len)
 Reads data from the file and advances file pointer.
ssize_t write (const void *buffer, size_t len)
 Writes data to the file and advances file pointer.
ssize_t pread (kt_off64_t offset, void *buffer, size_t len)
 Reads data from the file at a given offset without changing file pointer.
ssize_t pwrite (kt_off64_t offset, const void *buffer, size_t len)
 Writes data to the file at a given offset without changing file pointer.
bool exists () const
 Checks if the file exists.
bool canRead () const
 Checks if the file can be read.
bool canWrite () const
 Checks if the file can be written.
bool canExecute () const
 Checks if the file can be executed.
bool remove ()
 Removes the file.
kt_stat64_t info ()
 Retrieves information about the file.
bool isFile ()
 Checks if the file is a regular file.
bool readToString (std::string *str)
 Reads the contents of the file into a string.
bool readToBuffer (std::vector< char > *buf)
 Reads the contents of the file into a buffer.
bool copyToFile (const std::string &filePath)
 Copies the contents of the file to another file.
bool copyToFd (int fd)
 Writes the contents of the file to a file descriptor.

Static Public Member Functions

static bool readFileToString (const std::string &filePath, std::string *str)
 Reads the contents of a file into a string.
static bool readFileToBuffer (const std::string &filePath, std::vector< char > *buf)
 Reads the contents of a file into a buffer.
static bool copy (const std::string &srcFilePath, const std::string &dstFilePath)
 Copies the contents of a file to another file.
static bool listFilesCallback (const std::string &dir, std::function< bool(const std::string &)> cb)
 Lists files in a directory.
static bool createDirectoryRecursive (const std::string &path, mode_t mode=0755)
 Recursively creates a directory path.

Detailed Description

This class provides an interface for file operations.

Constructor & Destructor Documentation

◆ KittyIOFile()

KittyIOFile::KittyIOFile ( const std::string & filePath,
int flags,
mode_t mode = 0 )
inline

Constructs a new KittyIOFile object with file path, flags, and optional mode.

Parameters
filePathThe path to the file.
flagsThe flags for opening the file.
modeThe mode/permissions for opening the file (default: 0).
Here is the call graph for this function:

Member Function Documentation

◆ canExecute()

bool KittyIOFile::canExecute ( ) const
inline

Checks if the file can be executed.

Returns
true if the file can be executed, false otherwise.

◆ canRead()

bool KittyIOFile::canRead ( ) const
inline

Checks if the file can be read.

Returns
true if the file can be read, false otherwise.

◆ canWrite()

bool KittyIOFile::canWrite ( ) const
inline

Checks if the file can be written.

Returns
true if the file can be written, false otherwise.

◆ close()

bool KittyIOFile::close ( )

Closes the file.

Returns
true if the file was closed successfully, false otherwise.
Here is the caller graph for this function:

◆ copy()

bool KittyIOFile::copy ( const std::string & srcFilePath,
const std::string & dstFilePath )
inlinestatic

Copies the contents of a file to another file.

Parameters
srcFilePathThe source file path.
dstFilePathThe destination file path.
Returns
true if the file was copied successfully, false otherwise.
Here is the call graph for this function:

◆ copyToFd()

bool KittyIOFile::copyToFd ( int fd)

Writes the contents of the file to a file descriptor.

Parameters
fdThe file descriptor.
Returns
true if the file was written successfully, false otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ copyToFile()

bool KittyIOFile::copyToFile ( const std::string & filePath)
inline

Copies the contents of the file to another file.

Parameters
filePathThe file path to write to.
Returns
true if the file was written successfully, false otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ createDirectoryRecursive()

bool KittyIOFile::createDirectoryRecursive ( const std::string & path,
mode_t mode = 0755 )
static

Recursively creates a directory path.

This function creates all intermediate directories in the given path, similar to the behavior of mkdir -p on POSIX systems.

Parameters
pathThe full directory path to create (absolute or relative).
modeThe permissions to use when creating directories (default: 0755).
Returns
true if the directory exists or was successfully created, false if an error occurred.
Note
If a directory already exists, it is not treated as an error.
Warning
This function does not verify whether an existing path component is a directory or a file. If a file exists in the path, creation will fail.
See also
mkdir(2)
Here is the call graph for this function:

◆ exists()

bool KittyIOFile::exists ( ) const
inline

Checks if the file exists.

Returns
true if the file exists, false otherwise.

◆ fd()

int KittyIOFile::fd ( ) const
inline

Returns the file descriptor.

Returns
The file descriptor.
Here is the caller graph for this function:

◆ flags()

int KittyIOFile::flags ( ) const
inline

Returns the file flags.

Returns
The file flags.
Here is the caller graph for this function:

◆ info()

kt_stat64_t KittyIOFile::info ( )
inline

Retrieves information about the file.

Returns
The file information.
Here is the caller graph for this function:

◆ isFile()

bool KittyIOFile::isFile ( )
inline

Checks if the file is a regular file.

Returns
true if the file is a regular file, false otherwise.
Here is the call graph for this function:

◆ lastError()

int KittyIOFile::lastError ( ) const
inline

Returns the last error.

Returns
The last error code.

◆ lastStrError()

std::string KittyIOFile::lastStrError ( ) const
inline

Returns the last error message.

Returns
The last error message.

◆ listFilesCallback()

bool KittyIOFile::listFilesCallback ( const std::string & dir,
std::function< bool(const std::string &)> cb )
static

Lists files in a directory.

Parameters
dirThe directory path.
cbThe callback function to be called for each file.

◆ mode()

mode_t KittyIOFile::mode ( ) const
inline

Returns the file mode.

Returns
The file mode.
Here is the caller graph for this function:

◆ open()

bool KittyIOFile::open ( )

Opens the file.

Returns
true if the file was opened successfully, false otherwise.
Here is the caller graph for this function:

◆ path()

std::string KittyIOFile::path ( ) const
inline

Returns the file path.

Returns
The file path.
Here is the caller graph for this function:

◆ pread()

ssize_t KittyIOFile::pread ( kt_off64_t offset,
void * buffer,
size_t len )

Reads data from the file at a given offset without changing file pointer.

Parameters
offsetThe offset to read from.
bufferThe buffer to read into.
lenThe number of bytes to read.
Returns
The number of bytes read, or -1 on error.

◆ pwrite()

ssize_t KittyIOFile::pwrite ( kt_off64_t offset,
const void * buffer,
size_t len )

Writes data to the file at a given offset without changing file pointer.

Parameters
offsetThe offset to write to.
bufferThe buffer to write from.
lenThe number of bytes to write.
Returns
The number of bytes written, or -1 on error.

◆ read()

ssize_t KittyIOFile::read ( void * buffer,
size_t len )

Reads data from the file and advances file pointer.

Parameters
bufferThe buffer to read into.
lenThe number of bytes to read.
Returns
The number of bytes read, or -1 on error.

◆ readFileToBuffer()

bool KittyIOFile::readFileToBuffer ( const std::string & filePath,
std::vector< char > * buf )
inlinestatic

Reads the contents of a file into a buffer.

Parameters
filePathThe file path to read from.
bufThe buffer to read into.
Returns
true if the file was read successfully, false otherwise.
Here is the call graph for this function:

◆ readFileToString()

bool KittyIOFile::readFileToString ( const std::string & filePath,
std::string * str )
inlinestatic

Reads the contents of a file into a string.

Parameters
filePathThe file path to read from.
strThe string to read into.
Returns
true if the file was read successfully, false otherwise.
Here is the call graph for this function:

◆ readToBuffer()

bool KittyIOFile::readToBuffer ( std::vector< char > * buf)

Reads the contents of the file into a buffer.

Parameters
bufThe buffer to read into.
Returns
true if the file was read successfully, false otherwise.
Here is the caller graph for this function:

◆ readToString()

bool KittyIOFile::readToString ( std::string * str)

Reads the contents of the file into a string.

Parameters
strThe string to read into.
Returns
true if the file was read successfully, false otherwise.
Here is the caller graph for this function:

◆ remove()

bool KittyIOFile::remove ( )
inline

Removes the file.

Returns
true if the file was removed successfully, false otherwise.

◆ write()

ssize_t KittyIOFile::write ( const void * buffer,
size_t len )

Writes data to the file and advances file pointer.

Parameters
bufferThe buffer to write from.
lenThe number of bytes to write.
Returns
The number of bytes written, or -1 on error.

The documentation for this class was generated from the following file:
  • /home/runner/work/KittyMemoryEx/KittyMemoryEx/KittyMemoryEx/KittyIOFile.hpp