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-2026 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
43idaman void ida_export get_install_root(qstring *out);
44
45
58
59idaman THREAD_SAFE char *ida_export getsysfile(
60 char *buf,
61 size_t bufsize,
62 const char *filename,
63 const char *subdir);
64
68#define CFG_SUBDIR "cfg"
69#define IDC_SUBDIR "idc"
70#define IDS_SUBDIR "ids"
71#define IDP_SUBDIR "procs"
72#define LDR_SUBDIR "loaders"
73#define SIG_SUBDIR "sig"
74#define TIL_SUBDIR "til"
75#define PLG_SUBDIR "plugins"
76#define THM_SUBDIR "themes"
78
86
87idaman THREAD_SAFE const char *ida_export get_user_idadir(void);
88
89
100
101idaman THREAD_SAFE int ida_export get_ida_subdirs(qstrvec_t *dirs, const char *subdir, int flags=0);
102
106#define IDA_SUBDIR_IDP 0x0001
107#define IDA_SUBDIR_IDADIR_FIRST 0x0002
108#define IDA_SUBDIR_ONLY_EXISTING 0x0004
110
111
114
115idaman THREAD_SAFE bool ida_export get_special_folder(char *buf, size_t bufsize, int csidl);
116
120#ifndef CSIDL_PERSONAL
121#define CSIDL_PERSONAL 0x0005
122#endif
123#ifndef CSIDL_APPDATA
124#define CSIDL_APPDATA 0x001a
125#endif
126#ifndef CSIDL_LOCAL_APPDATA
127#define CSIDL_LOCAL_APPDATA 0x001c
128#endif
129#ifndef CSIDL_PROFILE
130#define CSIDL_PROFILE 0x0028
131#endif
132#ifndef CSIDL_PROGRAM_FILES
133#define CSIDL_PROGRAM_FILES 0x0026
134#endif
135#ifndef CSIDL_PROGRAM_FILES_COMMON
136#define CSIDL_PROGRAM_FILES_COMMON 0x002b
137#endif
138#ifndef CSIDL_PROGRAM_FILESX86
139#define CSIDL_PROGRAM_FILESX86 0x002a
140#endif
142
157
159{
160 virtual int visit_file(const char *file) = 0;
162};
163
164idaman THREAD_SAFE int ida_export enumerate_files(
165 char *answer,
166 size_t answer_size,
167 const char *path,
168 const char *fname,
170
171
172
173//-------------------------------------------------------------------------
174// O P E N / R E A D / W R I T E / C L O S E F I L E S
175//-------------------------------------------------------------------------
176
183
187
188idaman THREAD_SAFE FILE *ida_export fopenWT(const char *file);
189
190
194
195idaman THREAD_SAFE FILE *ida_export fopenWB(const char *file);
196
197
200
201idaman THREAD_SAFE FILE *ida_export fopenRT(const char *file);
202
203
206
207idaman THREAD_SAFE FILE *ida_export fopenRB(const char *file);
208
209
212
213idaman THREAD_SAFE FILE *ida_export fopenM(const char *file);
214
215
218
219idaman THREAD_SAFE FILE *ida_export fopenA(const char *file);
220
221
224
225idaman THREAD_SAFE FILE *ida_export openR(const char *file);
226
227
230
231idaman THREAD_SAFE FILE *ida_export openRT(const char *file);
232
233
236
237idaman THREAD_SAFE FILE *ida_export openM(const char *file);
238
239
241
242//-------------------------------------------------------------------------
243// F I L E S I Z E / D I S K S P A C E
244//-------------------------------------------------------------------------
245
250
251idaman THREAD_SAFE void ida_export echsize(FILE *fp, uint64 size);
252
253
256
257idaman THREAD_SAFE uint64 ida_export get_free_disk_space(const char *path);
258
259
260//-------------------------------------------------------------------------
261// I / O P O R T D E F I N I T I O N S F I L E
262//-------------------------------------------------------------------------
271
274{
279 void *userdata;
280
282 : address(0), userdata(nullptr)
283 {
284 }
285};
288
319
321{
327 virtual bool handle(qstring *errbuf, const ioports_t &ports, const char *line) = 0;
328};
329
330idaman THREAD_SAFE ssize_t ida_export read_ioports(
331 ioports_t *ports,
332 qstring *device,
333 const char *file,
334 ioports_fallback_t *callback=nullptr);
335
336
353
354idaman THREAD_SAFE bool ida_export choose_ioport_device(
355 qstring *_device,
356 const char *file,
357 const char *(idaapi *parse_params)(
358 qstring *buf,
359 const char *line)=nullptr);
360
362{
367 virtual bool parse(qstring *param, const char *line) = 0;
368};
369
370idaman THREAD_SAFE bool ida_export choose_ioport_device2(
371 qstring *_device,
372 const char *file,
373 choose_ioport_parser_t *parse_params);
374
376#define IOPORT_SKIP_DEVICE ((const char *)(-1))
377
378
380
381idaman THREAD_SAFE const ioport_t *ida_export find_ioport(const ioports_t &ports, ea_t address);
382
383
385
386idaman THREAD_SAFE const ioport_bit_t *ida_export find_ioport_bit(const ioports_t &ports, ea_t address, size_t bit);
387
388
389//-------------------------------------------------------------------------
390// S Y S T E M S P E C I F I C C A L L S
391//-------------------------------------------------------------------------
392
398
399idaman THREAD_SAFE int ida_export call_system(const char *command);
400
401
402//-------------------------------------------------------------------------
403// 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
404//-------------------------------------------------------------------------
405
412
413class linput_t;
414
415
425
426
431
432idaman void ida_export lread(linput_t *li, void *buf, size_t size);
433
434
437
438idaman ssize_t ida_export qlread(linput_t *li, void *buf, size_t size);
439
440
443
444idaman char *ida_export qlgets(char *s, size_t len, linput_t *li);
445
446
449
450idaman int ida_export qlgetc(linput_t *li);
451
452
460
461idaman int ida_export lreadbytes(linput_t *li, void *buf, size_t size, bool mf);
462
464#define DEF_LREADBYTES(read, type, size) \
465 \
466inline int idaapi read(linput_t *li, type *res, bool mf) \
467 { return lreadbytes(li, res, size, mf); }
468DEF_LREADBYTES(lread2bytes, int16, 2)
469DEF_LREADBYTES(lread2bytes, uint16, 2)
470DEF_LREADBYTES(lread4bytes, int32, 4)
471DEF_LREADBYTES(lread4bytes, uint32, 4)
472DEF_LREADBYTES(lread8bytes, int64, 8)
473DEF_LREADBYTES(lread8bytes, uint64, 8)
474#undef DEF_LREADBYTES
475
476
479
480idaman char *ida_export qlgetz(
481 linput_t *li,
482 int64 fpos,
483 char *buf,
484 size_t bufsize);
485
486
488
489idaman int64 ida_export qlsize(linput_t *li);
490
491
494
495idaman qoff64_t ida_export qlseek(linput_t *li, qoff64_t pos, int whence=SEEK_SET);
496
497
499
500inline qoff64_t idaapi qltell(linput_t *li) { return qlseek(li, 0, SEEK_CUR); }
501
502
504
505idaman linput_t *ida_export open_linput(const char *file, bool remote);
506
507
509
510idaman THREAD_SAFE void ida_export close_linput(linput_t *li);
511
512
517
518idaman THREAD_SAFE FILE *ida_export qlfile(linput_t *li);
519
520
525//lint -sem(make_linput,custodial(1))
526
527idaman THREAD_SAFE linput_t *ida_export make_linput(FILE *fp);
528
530
531idaman THREAD_SAFE void ida_export unmake_linput(linput_t *li);
532
533
537{
550 virtual ssize_t idaapi read(qoff64_t off, void *buffer, size_t nbytes) = 0;
551 virtual ~generic_linput_t() {}
552};
553
558
559idaman THREAD_SAFE linput_t *ida_export create_generic_linput(generic_linput_t *gl);
560
562
563idaman THREAD_SAFE linput_t *ida_export create_bytearray_linput(const uchar *start, size_t size);
564
565
571
572idaman linput_t *ida_export create_memory_linput(ea_t start, asize_t size);
573
575
576inline THREAD_SAFE linput_type_t idaapi get_linput_type(linput_t *li)
577{
578 return li != nullptr ? *(linput_type_t *)li : LINPUT_NONE;
579}
580
585{
587}
588
589//---------------------------------------------------------------------------
593{
594public:
595 linput_buffer_t(linput_t *linput, int64 size=0): li(linput), lsize(size) {}
596 ssize_t read(void *buf, size_t n)
597 {
598 return qlread(li, buf, n);
599 }
600 bool eof()
601 {
602 if ( lsize == 0 )
603 lsize = qlsize(li);
604 return qltell(li) >= lsize;
605 }
606protected:
607 linput_t *li;
608private:
609 int64 lsize;
610};
611
613
614
622
623
624#endif // _DISKIO_HPP
linput_buffer_t(linput_t *linput, int64 size=0)
Definition diskio.hpp:595
ssize_t read(void *buf, size_t n)
Definition diskio.hpp:596
linput_t * li
Definition diskio.hpp:607
bool eof()
Definition diskio.hpp:600
Reimplementation of vector class from STL.
Definition pro.h:2262
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:473
THREAD_SAFE linput_type_t idaapi get_linput_type(linput_t *li)
Get linput type.
Definition diskio.hpp:576
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:287
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:270
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:500
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:471
janitor_t< linput_t * > linput_janitor_t
Object that will free an linput_t at destruction-time.
Definition diskio.hpp:582
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:617
@ LOC_KEEP
do nothing
Definition diskio.hpp:620
@ LOC_UNMAKE
unmake the inner linput
Definition diskio.hpp:619
@ LOC_CLOSE
close the inner linput
Definition diskio.hpp:618
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 void ida_export get_install_root(qstring *out)
Get the directory where IDA is installed.
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:418
@ LINPUT_LOCAL
local file
Definition diskio.hpp:420
@ LINPUT_GENERIC
generic linput
Definition diskio.hpp:423
@ LINPUT_RFILE
remote file ( debugger_t::open_file, debugger_t::read_file)
Definition diskio.hpp:421
@ LINPUT_PROCMEM
debugged process memory (read_dbg_memory())
Definition diskio.hpp:422
@ LINPUT_NONE
invalid linput
Definition diskio.hpp:419
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:1000
char * answer
Definition kernwin.hpp:8465
int nbytes
Definition kernwin.hpp:3037
idaman int64 pos
Definition kernwin.hpp:1398
idaman size_t len
Definition kernwin.hpp:1389
asize_t size
Definition kernwin.hpp:6701
unsigned __int64 uint64
Definition llong.hpp:13
__int64 int64
Definition llong.hpp:14
qvector< qstring > qstrvec_t
Definition lumina.hpp:831
This is the first header included in the IDA project.
unsigned short uint16
unsigned 16 bit value
Definition pro.h:350
unsigned int uint32
unsigned 32 bit value
Definition pro.h:352
uint64 asize_t
Definition pro.h:427
short int16
signed 16 bit value
Definition pro.h:349
uint64 ea_t
Definition pro.h:425
int int32
signed 32 bit value
Definition pro.h:351
unsigned char uchar
unsigned 8 bit value
Definition pro.h:341
idaman size_t bufsize
Definition pro.h:604
ptrdiff_t ssize_t
Signed size_t - used to check for size overflows when the counter becomes negative.
Definition pro.h:385
_qstring< char > qstring
regular string
Definition pro.h:3771
Definition diskio.hpp:362
virtual ~choose_ioport_parser_t()
Definition diskio.hpp:363
virtual bool parse(qstring *param, const char *line)=0
Enumerate files in the specified directory.
Definition diskio.hpp:159
virtual int visit_file(const char *file)=0
virtual ~file_enumerator_t()
Definition diskio.hpp:161
Generic linput class - may be used to create a linput_t instance for any data source.
Definition diskio.hpp:537
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:542
virtual ~generic_linput_t()
Definition diskio.hpp:551
uint64 filesize
input file size
Definition diskio.hpp:541
Describes an I/O port bit.
Definition diskio.hpp:265
qstring name
name of the bit
Definition diskio.hpp:266
qstring cmt
comment
Definition diskio.hpp:267
Describes an I/O port.
Definition diskio.hpp:274
qstring cmt
comment
Definition diskio.hpp:277
qstring name
name of the port
Definition diskio.hpp:276
ioport_t()
Definition diskio.hpp:281
ea_t address
address of the port
Definition diskio.hpp:275
ioport_bits_t bits
bit names
Definition diskio.hpp:278
void * userdata
arbitrary data. initialized to nullptr.
Definition diskio.hpp:279
Read i/o port definitions from a config file.
Definition diskio.hpp:321
virtual ~ioports_fallback_t()
Definition diskio.hpp:322
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:4579
linput_t *& resource
Definition pro.h:4584
~janitor_t()
Definition diskio.hpp:584