IDA C++ SDK 9.2
Loading...
Searching...
No Matches
diskio.hpp
Go to the documentation of this file.
1/*
2 * Interactive disassembler (IDA).
3 * Copyright (c) 1990-2025 Hex-Rays
4 * ALL RIGHTS RESERVED.
5 *
6 */
7
8#ifndef _DISKIO_HPP
9#define _DISKIO_HPP
10
11#include <stdio.h>
12#include <functional>
13#include <pro.h>
14
24
25//-------------------------------------------------------------------------
26#define VAULT_CACHE_SUBDIR ".vault"
27#define VAULT_CACHE_FNAME ".vault_cache"
28
29//-------------------------------------------------------------------------
30// S E A R C H F O R F I L E S
31//-------------------------------------------------------------------------
32
33
36
37idaman THREAD_SAFE const char *ida_export idadir(const char *subdir);
38
39
52
53idaman THREAD_SAFE char *ida_export getsysfile(
54 char *buf,
55 size_t bufsize,
56 const char *filename,
57 const char *subdir);
58
62#define CFG_SUBDIR "cfg"
63#define IDC_SUBDIR "idc"
64#define IDS_SUBDIR "ids"
65#define IDP_SUBDIR "procs"
66#define LDR_SUBDIR "loaders"
67#define SIG_SUBDIR "sig"
68#define TIL_SUBDIR "til"
69#define PLG_SUBDIR "plugins"
70#define THM_SUBDIR "themes"
72
80
81idaman THREAD_SAFE const char *ida_export get_user_idadir(void);
82
83
94
95idaman THREAD_SAFE int ida_export get_ida_subdirs(qstrvec_t *dirs, const char *subdir, int flags=0);
96
100#define IDA_SUBDIR_IDP 0x0001
101#define IDA_SUBDIR_IDADIR_FIRST 0x0002
102#define IDA_SUBDIR_ONLY_EXISTING 0x0004
104
105
108
109idaman THREAD_SAFE bool ida_export get_special_folder(char *buf, size_t bufsize, int csidl);
110
114#ifndef CSIDL_APPDATA
115#define CSIDL_APPDATA 0x001a
116#endif
117#ifndef CSIDL_LOCAL_APPDATA
118#define CSIDL_LOCAL_APPDATA 0x001c
119#endif
120#ifndef CSIDL_PROGRAM_FILES
121#define CSIDL_PROGRAM_FILES 0x0026
122#endif
123#ifndef CSIDL_PROGRAM_FILES_COMMON
124#define CSIDL_PROGRAM_FILES_COMMON 0x002b
125#endif
126#ifndef CSIDL_PROGRAM_FILESX86
127#define CSIDL_PROGRAM_FILESX86 0x002a
128#endif
130
145
147{
148 virtual int visit_file(const char *file) = 0;
150};
151
152idaman THREAD_SAFE int ida_export enumerate_files(
153 char *answer,
154 size_t answer_size,
155 const char *path,
156 const char *fname,
158
159
160
161//-------------------------------------------------------------------------
162// O P E N / R E A D / W R I T E / C L O S E F I L E S
163//-------------------------------------------------------------------------
164
171
175
176idaman THREAD_SAFE FILE *ida_export fopenWT(const char *file);
177
178
182
183idaman THREAD_SAFE FILE *ida_export fopenWB(const char *file);
184
185
188
189idaman THREAD_SAFE FILE *ida_export fopenRT(const char *file);
190
191
194
195idaman THREAD_SAFE FILE *ida_export fopenRB(const char *file);
196
197
200
201idaman THREAD_SAFE FILE *ida_export fopenM(const char *file);
202
203
206
207idaman THREAD_SAFE FILE *ida_export fopenA(const char *file);
208
209
212
213idaman THREAD_SAFE FILE *ida_export openR(const char *file);
214
215
218
219idaman THREAD_SAFE FILE *ida_export openRT(const char *file);
220
221
224
225idaman THREAD_SAFE FILE *ida_export openM(const char *file);
226
227
229
230//-------------------------------------------------------------------------
231// F I L E S I Z E / D I S K S P A C E
232//-------------------------------------------------------------------------
233
238
239idaman THREAD_SAFE void ida_export echsize(FILE *fp, uint64 size);
240
241
244
245idaman THREAD_SAFE uint64 ida_export get_free_disk_space(const char *path);
246
247
248//-------------------------------------------------------------------------
249// I / O P O R T D E F I N I T I O N S F I L E
250//-------------------------------------------------------------------------
259
262{
267 void *userdata;
268
270 : address(0), userdata(nullptr)
271 {
272 }
273};
276
307
309{
315 virtual bool handle(qstring *errbuf, const ioports_t &ports, const char *line) = 0;
316};
317
318idaman THREAD_SAFE ssize_t ida_export read_ioports(
319 ioports_t *ports,
320 qstring *device,
321 const char *file,
322 ioports_fallback_t *callback=nullptr);
323
324
341
342idaman THREAD_SAFE bool ida_export choose_ioport_device(
343 qstring *_device,
344 const char *file,
345 const char *(idaapi *parse_params)(
346 qstring *buf,
347 const char *line)=nullptr);
348
350{
355 virtual bool parse(qstring *param, const char *line) = 0;
356};
357
358idaman THREAD_SAFE bool ida_export choose_ioport_device2(
359 qstring *_device,
360 const char *file,
361 choose_ioport_parser_t *parse_params);
362
364#define IOPORT_SKIP_DEVICE ((const char *)(-1))
365
366
368
369idaman THREAD_SAFE const ioport_t *ida_export find_ioport(const ioports_t &ports, ea_t address);
370
371
373
374idaman THREAD_SAFE const ioport_bit_t *ida_export find_ioport_bit(const ioports_t &ports, ea_t address, size_t bit);
375
376
377//-------------------------------------------------------------------------
378// S Y S T E M S P E C I F I C C A L L S
379//-------------------------------------------------------------------------
380
386
387idaman THREAD_SAFE int ida_export call_system(const char *command);
388
389
390//-------------------------------------------------------------------------
391// L O A D E R I N P U T S O U R C E F U N C T I O N S
392//-------------------------------------------------------------------------
393
400
401class linput_t;
402
403
413
414
419
420idaman void ida_export lread(linput_t *li, void *buf, size_t size);
421
422#ifdef TESTABLE_BUILD
423#endif
424
425
428
429idaman ssize_t ida_export qlread(linput_t *li, void *buf, size_t size);
430
431
434
435idaman char *ida_export qlgets(char *s, size_t len, linput_t *li);
436
437
440
441idaman int ida_export qlgetc(linput_t *li);
442
443
451
452idaman int ida_export lreadbytes(linput_t *li, void *buf, size_t size, bool mf);
453
455#define DEF_LREADBYTES(read, type, size) \
456 \
457inline int idaapi read(linput_t *li, type *res, bool mf) \
458 { return lreadbytes(li, res, size, mf); }
459DEF_LREADBYTES(lread2bytes, int16, 2)
460DEF_LREADBYTES(lread2bytes, uint16, 2)
461DEF_LREADBYTES(lread4bytes, int32, 4)
462DEF_LREADBYTES(lread4bytes, uint32, 4)
463DEF_LREADBYTES(lread8bytes, int64, 8)
464DEF_LREADBYTES(lread8bytes, uint64, 8)
465#undef DEF_LREADBYTES
466
467
470
471idaman char *ida_export qlgetz(
472 linput_t *li,
473 int64 fpos,
474 char *buf,
475 size_t bufsize);
476
477
479
480idaman int64 ida_export qlsize(linput_t *li);
481
482
485
486idaman qoff64_t ida_export qlseek(linput_t *li, qoff64_t pos, int whence=SEEK_SET);
487
488
490
491inline qoff64_t idaapi qltell(linput_t *li) { return qlseek(li, 0, SEEK_CUR); }
492
493
495
496idaman linput_t *ida_export open_linput(const char *file, bool remote);
497
498
500
501idaman THREAD_SAFE void ida_export close_linput(linput_t *li);
502
503
508
509idaman THREAD_SAFE FILE *ida_export qlfile(linput_t *li);
510
511
516//lint -sem(make_linput,custodial(1))
517
518idaman THREAD_SAFE linput_t *ida_export make_linput(FILE *fp);
519
521
522idaman THREAD_SAFE void ida_export unmake_linput(linput_t *li);
523
524
528{
541 virtual ssize_t idaapi read(qoff64_t off, void *buffer, size_t nbytes) = 0;
542 virtual ~generic_linput_t() {}
543};
544
549
550idaman THREAD_SAFE linput_t *ida_export create_generic_linput(generic_linput_t *gl);
551
553
554idaman THREAD_SAFE linput_t *ida_export create_bytearray_linput(const uchar *start, size_t size);
555
556
562
563idaman linput_t *ida_export create_memory_linput(ea_t start, asize_t size);
564
566
567inline THREAD_SAFE linput_type_t idaapi get_linput_type(linput_t *li)
568{
569 return li != nullptr ? *(linput_type_t *)li : LINPUT_NONE;
570}
571
576{
578}
579
580//---------------------------------------------------------------------------
584{
585public:
586 linput_buffer_t(linput_t *linput, int64 size=0): li(linput), lsize(size) {}
587 ssize_t read(void *buf, size_t n)
588 {
589 return qlread(li, buf, n);
590 }
591 bool eof()
592 {
593 if ( lsize == 0 )
594 lsize = qlsize(li);
595 return qltell(li) >= lsize;
596 }
597protected:
598 linput_t *li;
599private:
600 int64 lsize;
601};
602
604
605
613
614
615#endif // _DISKIO_HPP
linput_buffer_t(linput_t *linput, int64 size=0)
Definition diskio.hpp:586
ssize_t read(void *buf, size_t n)
Definition diskio.hpp:587
linput_t * li
Definition diskio.hpp:598
bool eof()
Definition diskio.hpp:591
Reimplementation of vector class from STL.
Definition pro.h:2250
idaman THREAD_SAFE FILE *ida_export openM(const char *file)
Open a file for read/write in binary mode or die, deny write.
idaman int ida_export lreadbytes(linput_t *li, void *buf, size_t size, bool mf)
Read multiple bytes and swap if necessary.
idaman THREAD_SAFE FILE *ida_export fopenA(const char *file)
Open a file for append in text mode, deny none.
idaman ssize_t ida_export qlread(linput_t *li, void *buf, size_t size)
Read the input source.
uint64
Definition diskio.hpp:464
THREAD_SAFE linput_type_t idaapi get_linput_type(linput_t *li)
Get linput type.
Definition diskio.hpp:567
idaman THREAD_SAFE FILE *ida_export openR(const char *file)
Open a file for read in binary mode or die, deny none.
idaman THREAD_SAFE void ida_export close_linput(linput_t *li)
Close loader input.
idaman THREAD_SAFE FILE *ida_export fopenRB(const char *file)
Open a file for read in binary mode, deny none.
DEF_LREADBYTES(lread2bytes, int16, 2) DEF_LREADBYTES(lread2bytes
idaman char *ida_export qlgetz(linput_t *li, int64 fpos, char *buf, size_t bufsize)
Read a zero-terminated string from the input.
idaman THREAD_SAFE FILE *ida_export openRT(const char *file)
Open a file for read in text mode or die, deny none.
idaman THREAD_SAFE FILE *ida_export fopenWT(const char *file)
Open a new file for write in text mode, deny write.
qvector< ioport_t > ioports_t
Definition diskio.hpp:275
idaman THREAD_SAFE char *ida_export getsysfile(char *buf, size_t bufsize, const char *filename, const char *subdir)
Search for IDA system file.
qvector< ioport_bit_t > ioport_bits_t
Definition diskio.hpp:258
idaman THREAD_SAFE int ida_export enumerate_files(char *answer, size_t answer_size, const char *path, const char *fname, file_enumerator_t &fv)
idaman THREAD_SAFE const char *ida_export get_user_idadir(void)
Get user ida related directory.
idaman int64 ida_export qlsize(linput_t *li)
Get the input source size.
idaman qoff64_t ida_export qlseek(linput_t *li, qoff64_t pos, int whence=SEEK_SET)
Set input source position.
idaman THREAD_SAFE FILE *ida_export qlfile(linput_t *li)
Get FILE* from the input source.
qoff64_t idaapi qltell(linput_t *li)
Get input source position.
Definition diskio.hpp:491
idaman linput_t *ida_export create_memory_linput(ea_t start, asize_t size)
Create a linput for process memory.
idaman THREAD_SAFE FILE *ida_export fopenWB(const char *file)
Open a new file for write in binary mode, deny read/write.
idaman THREAD_SAFE bool ida_export choose_ioport_device(qstring *_device, const char *file, const char *(idaapi *parse_params)(qstring *buf, const char *line)=nullptr)
Allow the user to choose the ioport device.
idaman THREAD_SAFE const ioport_t *ida_export find_ioport(const ioports_t &ports, ea_t address)
Find ioport in the array of ioports.
idaman THREAD_SAFE const ioport_bit_t *ida_export find_ioport_bit(const ioports_t &ports, ea_t address, size_t bit)
Find ioport bit in the array of ioports.
idaman THREAD_SAFE FILE *ida_export fopenM(const char *file)
Open a file for read/write in binary mode, deny write.
uint32
Definition diskio.hpp:462
janitor_t< linput_t * > linput_janitor_t
Object that will free an linput_t at destruction-time.
Definition diskio.hpp:573
idaman void ida_export lread(linput_t *li, void *buf, size_t size)
Read the input source.
idaman THREAD_SAFE linput_t *ida_export create_bytearray_linput(const uchar *start, size_t size)
Trivial memory linput.
linput_close_code_t
Upon closing outer linput, perform one of these actions.
Definition diskio.hpp:608
@ LOC_KEEP
do nothing
Definition diskio.hpp:611
@ LOC_UNMAKE
unmake the inner linput
Definition diskio.hpp:610
@ LOC_CLOSE
close the inner linput
Definition diskio.hpp:609
idaman char *ida_export qlgets(char *s, size_t len, linput_t *li)
Read one line from the input source.
idaman THREAD_SAFE linput_t *ida_export make_linput(FILE *fp)
Convert FILE* to input source.
idaman THREAD_SAFE const char *ida_export idadir(const char *subdir)
Get IDA directory (if subdir==nullptr) or the specified subdirectory (see IDA subdirectories)
idaman THREAD_SAFE FILE *ida_export fopenRT(const char *file)
Open a file for read in text mode, deny none.
idaman THREAD_SAFE bool ida_export get_special_folder(char *buf, size_t bufsize, int csidl)
Get a folder location by CSIDL (see Common CSIDLs).
idaman THREAD_SAFE void ida_export unmake_linput(linput_t *li)
Free an linput_t object (also see make_linput())
idaman THREAD_SAFE void ida_export echsize(FILE *fp, uint64 size)
Change size of file or die.
idaman THREAD_SAFE uint64 ida_export get_free_disk_space(const char *path)
Get free disk space in bytes.
idaman THREAD_SAFE ssize_t ida_export read_ioports(ioports_t *ports, qstring *device, const char *file, ioports_fallback_t *callback=nullptr)
idaman linput_t *ida_export open_linput(const char *file, bool remote)
Open loader input.
idaman THREAD_SAFE int ida_export call_system(const char *command)
Execute a operating system command.
idaman THREAD_SAFE int ida_export get_ida_subdirs(qstrvec_t *dirs, const char *subdir, int flags=0)
Get list of directories in which to find a specific IDA resource (see IDA subdirectories).
linput_type_t
loader input source
Definition diskio.hpp:406
@ LINPUT_LOCAL
local file
Definition diskio.hpp:408
@ LINPUT_GENERIC
generic linput
Definition diskio.hpp:411
@ LINPUT_RFILE
remote file ( debugger_t::open_file, debugger_t::read_file)
Definition diskio.hpp:409
@ LINPUT_PROCMEM
debugged process memory (read_dbg_memory())
Definition diskio.hpp:410
@ LINPUT_NONE
invalid linput
Definition diskio.hpp:407
DECLARE_TYPE_AS_MOVABLE(ioport_bit_t)
idaman THREAD_SAFE bool ida_export choose_ioport_device2(qstring *_device, const char *file, choose_ioport_parser_t *parse_params)
idaman THREAD_SAFE linput_t *ida_export create_generic_linput(generic_linput_t *gl)
Create a generic linput.
idaman int ida_export qlgetc(linput_t *li)
Read one character from the input source.
idaman size_t n
Definition pro.h:997
char * answer
Definition kernwin.hpp:8023
int nbytes
Definition kernwin.hpp:2861
idaman int64 pos
Definition kernwin.hpp:1365
idaman size_t len
Definition kernwin.hpp:1356
asize_t size
Definition kernwin.hpp:6339
unsigned __int64 uint64
Definition llong.hpp:13
__int64 int64
Definition llong.hpp:14
This is the first header included in the IDA project.
unsigned short uint16
unsigned 16 bit value
Definition pro.h:346
unsigned int uint32
unsigned 32 bit value
Definition pro.h:348
uint64 asize_t
Definition pro.h:423
short int16
signed 16 bit value
Definition pro.h:345
uint64 ea_t
Definition pro.h:421
int int32
signed 32 bit value
Definition pro.h:347
unsigned char uchar
unsigned 8 bit value
Definition pro.h:337
idaman size_t bufsize
Definition pro.h:600
ptrdiff_t ssize_t
Signed size_t - used to check for size overflows when the counter becomes negative.
Definition pro.h:381
_qstring< char > qstring
regular string
Definition pro.h:3694
qvector< qstring > qstrvec_t
vector of strings
Definition pro.h:3697
Definition diskio.hpp:350
virtual ~choose_ioport_parser_t()
Definition diskio.hpp:351
virtual bool parse(qstring *param, const char *line)=0
Enumerate files in the specified directory.
Definition diskio.hpp:147
virtual int visit_file(const char *file)=0
virtual ~file_enumerator_t()
Definition diskio.hpp:149
Generic linput class - may be used to create a linput_t instance for any data source.
Definition diskio.hpp:528
virtual ssize_t idaapi read(qoff64_t off, void *buffer, size_t nbytes)=0
uint32 blocksize
preferred block size to work with read/write sizes will be in multiples of this number.
Definition diskio.hpp:533
virtual ~generic_linput_t()
Definition diskio.hpp:542
uint64 filesize
input file size
Definition diskio.hpp:532
Describes an I/O port bit.
Definition diskio.hpp:253
qstring name
name of the bit
Definition diskio.hpp:254
qstring cmt
comment
Definition diskio.hpp:255
Describes an I/O port.
Definition diskio.hpp:262
qstring cmt
comment
Definition diskio.hpp:265
qstring name
name of the port
Definition diskio.hpp:264
ioport_t()
Definition diskio.hpp:269
ea_t address
address of the port
Definition diskio.hpp:263
ioport_bits_t bits
bit names
Definition diskio.hpp:266
void * userdata
arbitrary data. initialized to nullptr.
Definition diskio.hpp:267
Read i/o port definitions from a config file.
Definition diskio.hpp:309
virtual ~ioports_fallback_t()
Definition diskio.hpp:310
virtual bool handle(qstring *errbuf, const ioports_t &ports, const char *line)=0
Resource janitor to facilitate use of the RAII idiom.
Definition pro.h:4486
linput_t *& resource
Definition pro.h:4491
~janitor_t()
Definition diskio.hpp:575