IDA C++ SDK 9.2
Loading...
Searching...
No Matches
fpro.h File Reference

System independent counterparts of FILE* related functions from Clib. More...

Go to the source code of this file.

Typedefs

typedef janitor_t< FILE * > file_janitor_t
 File janitor: will close a file at destruction-time.

Enumerations

enum  { QMOVE_CROSS_FS = 0x01 , QMOVE_OVERWRITE = 0x02 , QMOVE_OVR_RO = 0x04 }

Functions

idaman THREAD_SAFE ssize_t ida_export qgetline (qstring *buf, FILE *fp)
 Read line from file (the newline is removed from the output buffer)
idaman THREAD_SAFE int ida_export qrename (const char *oldfname, const char *newfname)
 Rename a file: 'newname' may exist, and will be deleted.
idaman THREAD_SAFE int ida_export qmove (const char *oldfname, const char *newfname, uint32 flags)
 Move a file - more powerful version of qrename.
idaman THREAD_SAFE int ida_export qcopyfile (const char *from, const char *to, bool overwrite=true, bool(idaapi *cb)(uint64 pos, uint64 total, void *ud)=nullptr, void *ud=nullptr, int flags=0)
 Copy a file.
idaman char *ida_export qtmpdir (char *buf, size_t bufsize)
 Get temporary directory name Returns absolute path.
idaman char *ida_export qtmpnam (char *buf, size_t bufsize)
 Get temporary file name.

File I/O

The following functions work just like their counterparts from Clib, only they are safer, system independent, and they set qerrno (see get_qerrno()).

idaman THREAD_SAFE const char * format
idaman THREAD_SAFE const char va_list va
int code = qvfprintf(fp, format, va)
idaman THREAD_SAFE FILE *ida_export qfopen (const char *file, const char *mode)
idaman THREAD_SAFE ssize_t ida_export qfread (FILE *fp, void *buf, size_t n)
idaman THREAD_SAFE ssize_t ida_export qfwrite (FILE *fp, const void *buf, size_t n)
idaman THREAD_SAFE qoff64_t ida_export qftell (FILE *fp)
idaman THREAD_SAFE int ida_export qfseek (FILE *fp, qoff64_t offset, int whence)
idaman THREAD_SAFE int ida_export qfclose (FILE *fp)
idaman THREAD_SAFE int ida_export qflush (FILE *fp)
idaman THREAD_SAFE int ida_export qfputc (int chr, FILE *fp)
idaman THREAD_SAFE int ida_export qfgetc (FILE *fp)
idaman THREAD_SAFE char *ida_export qfgets (char *s, size_t len, FILE *fp)
idaman THREAD_SAFE int ida_export qfputs (const char *s, FILE *fp)
idaman FILE *ida_export qtmpfile (void)
idaman THREAD_SAFE int ida_export qunlink (const char *fname)
idaman THREAD_SAFE int ida_export qaccess (const char *fname, int mode)
idaman THREAD_SAFE char *ida_export qgets (char *line, size_t linesize)
idaman THREAD_SAFE uint64 ida_export qfsize (FILE *fp)
idaman THREAD_SAFE AS_PRINTF (2, 0) int ida_export qvfprintf(FILE *fp
idaman THREAD_SAFE AS_PRINTF (1, 0) int ida_export qvprintf(const char *format
idaman THREAD_SAFE AS_SCANF (2, 0) int ida_export qvfscanf(FILE *fp
THREAD_SAFE AS_PRINTF (2, 3) inline int qfprintf(FILE *fp
 Display a dialog box and wait for the user to input an segment name (ui_ask_seg).
THREAD_SAFE const char va_start (va, format)
 va_end (va)
THREAD_SAFE AS_PRINTF (1, 2) inline int qprintf(const char *format
THREAD_SAFE AS_SCANF (2, 3) inline int qfscanf(FILE *fp

readbytes/writebytes

Add-ins for 2..32 byte read/writes.

Parameters
fppointer to file
resvalue read from file
sizesize of value in bytes (1..32)
mostfirstis MSB first? (0/1)
Return values
0All these functions return 0 on success
 fwrite2bytes
 uint16
 fwrite4bytes
 uint32
 fwrite8bytes
 uint64
idaman THREAD_SAFE int ida_export freadbytes (FILE *fp, void *res, int size, int mostfirst)
idaman THREAD_SAFE int ida_export fwritebytes (FILE *fp, const void *l, int size, int mostfirst)
 DEF_FREADBYTES (fread2bytes, fwrite2bytes, int16, 2) DEF_FREADBYTES(fread2bytes
 DEF_FREADBYTES (fread4bytes, fwrite4bytes, int32, 4) DEF_FREADBYTES(fread4bytes
 DEF_FREADBYTES (fread8bytes, fwrite8bytes, int64, 8) DEF_FREADBYTES(fread8bytes

Detailed Description

System independent counterparts of FILE* related functions from Clib.

You should not use C standard I/O functions in your modules. The reason: Each module compiled with Borland (and statically linked to Borland's library) will host a copy of the FILE * information.

So, if you open a file in the plugin and pass the handle to the kernel, the kernel will not be able to use it.

If you really need to use the standard functions, define USE_STANDARD_FILE_FUNCTIONS. In this case do not mix them with q... functions.

Typedef Documentation

◆ file_janitor_t

typedef janitor_t<FILE*> file_janitor_t

File janitor: will close a file at destruction-time.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
QMOVE_CROSS_FS 
QMOVE_OVERWRITE 
QMOVE_OVR_RO 

Function Documentation

◆ qgetline()

idaman THREAD_SAFE ssize_t ida_export qgetline ( qstring * buf,
FILE * fp )

Read line from file (the newline is removed from the output buffer)

Parameters
bufoutput buffer
fppointer to file
Returns
-1 or length of line

◆ qrename()

idaman THREAD_SAFE int ida_export qrename ( const char * oldfname,
const char * newfname )

Rename a file: 'newname' may exist, and will be deleted.

◆ qmove()

idaman THREAD_SAFE int ida_export qmove ( const char * oldfname,
const char * newfname,
uint32 flags )

Move a file - more powerful version of qrename.

Return values
0success
-1system error
elsea combination of flags to be given for successful move

◆ qcopyfile()

idaman THREAD_SAFE int ida_export qcopyfile ( const char * from,
const char * to,
bool overwrite = true,
bool(idaapi *cb)(uint64 pos, uint64 total, void *ud) = nullptr,
void * ud = nullptr,
int flags = 0 )

Copy a file.

Parameters
fromsource file name
todestination file name
overwriteoverwrite output if it exists?
cbuser callback. return false to abort the copy loop
uduser data passed back to cb
flagsreserved (should be zero)
Return values
-1input file not found
-2output file not writable
-3output file already exists while overwrite is false
-4write failure
-5interrupted from the callback

◆ qtmpdir()

idaman char *ida_export qtmpdir ( char * buf,
size_t bufsize )

Get temporary directory name Returns absolute path.

◆ qtmpnam()

idaman char *ida_export qtmpnam ( char * buf,
size_t bufsize )

Get temporary file name.

Returns absolute path (includes directory)

◆ freadbytes()

idaman THREAD_SAFE int ida_export freadbytes ( FILE * fp,
void * res,
int size,
int mostfirst )

◆ fwritebytes()

idaman THREAD_SAFE int ida_export fwritebytes ( FILE * fp,
const void * l,
int size,
int mostfirst )

◆ DEF_FREADBYTES() [1/3]

DEF_FREADBYTES ( fread2bytes ,
fwrite2bytes ,
int16 ,
2  )

◆ DEF_FREADBYTES() [2/3]

DEF_FREADBYTES ( fread4bytes ,
fwrite4bytes ,
int32 ,
4  )

◆ DEF_FREADBYTES() [3/3]

DEF_FREADBYTES ( fread8bytes ,
fwrite8bytes ,
int64 ,
8  )

Variable Documentation

◆ fwrite2bytes

fwrite2bytes

◆ uint16

◆ fwrite4bytes

fwrite4bytes

◆ uint32

◆ fwrite8bytes

fwrite8bytes

◆ uint64