- glibc 2.29
> struct _IO_FILE
구조체는 /libio/bits/types/struct_FILE.h에 정의되어 있다.
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
struct _IO_FILE
{
int _flags; /* High-order word is _IO_MAGIC; rest is flags. */
/* The following pointers correspond to the C++ streambuf protocol. */
char *_IO_read_ptr; /* Current read pointer */
char *_IO_read_end; /* End of get area. */
char *_IO_read_base; /* Start of putback+get area. */
char *_IO_write_base; /* Start of put area. */
char *_IO_write_ptr; /* Current put pointer. */
char *_IO_write_end; /* End of put area. */
char *_IO_buf_base; /* Start of reserve area. */
char *_IO_buf_end; /* End of reserve area. */
/* The following fields are used to support backing up and undo. */
char *_IO_save_base; /* Pointer to start of non-current get area. */
char *_IO_backup_base; /* Pointer to first valid character of backup area */
char *_IO_save_end; /* Pointer to end of non-current get area. */
struct _IO_marker *_markers;
struct _IO_FILE *_chain;
int _fileno;
int _flags2;
__off_t _old_offset; /* This used to be _offset but it's too small. */
/* 1+column number of pbase(); 0 is unknown. */
unsigned short _cur_column;
signed char _vtable_offset;
char _shortbuf[1];
_IO_lock_t *_lock;
#ifdef _IO_USE_OLD_IO_FILE
};
struct _IO_FILE_complete
{
struct _IO_FILE _file;
#endif
__off64_t _offset;
/* Wide character stream stuff. */
struct _IO_codecvt *_codecvt;
struct _IO_wide_data *_wide_data;
struct _IO_FILE *_freeres_list;
void *_freeres_buf;
size_t __pad5;
int _mode;
/* Make sure we don't get into trouble again. */
char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)];
};
|
1. int _flags
상위 2바이트는 0xFBAD의 매직 워드를 가진다. (_IO_MAGIC)
하위 2바이트는 플래그 정보를 담고 있다. 플래그는 /libio/libio.h에 define 되어 있다.
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/* Magic number and bits for the _flags field. The magic number is
mostly vestigial, but preserved for compatibility. It occupies the
high 16 bits of _flags; the low 16 bits are actual flag bits. */
#define _IO_MAGIC 0xFBAD0000 /* Magic number */
#define _IO_MAGIC_MASK 0xFFFF0000
#define _IO_USER_BUF 0x0001 /* Don't deallocate buffer on close. */
#define _IO_UNBUFFERED 0x0002
#define _IO_NO_READS 0x0004 /* Reading not allowed. */
#define _IO_NO_WRITES 0x0008 /* Writing not allowed. */
#define _IO_EOF_SEEN 0x0010
#define _IO_ERR_SEEN 0x0020
#define _IO_DELETE_DONT_CLOSE 0x0040 /* Don't call close(_fileno) on close. */
#define _IO_LINKED 0x0080 /* In the list of all open files. */
#define _IO_IN_BACKUP 0x0100
#define _IO_LINE_BUF 0x0200
#define _IO_TIED_PUT_GET 0x0400 /* Put and get pointer move in unison. */
#define _IO_CURRENTLY_PUTTING 0x0800
#define _IO_IS_APPENDING 0x1000
#define _IO_IS_FILEBUF 0x2000
/* 0x4000 No longer used, reserved for compat. */
#define _IO_USER_LOCK 0x8000
|
2. char *_IO_read_ptr
읽기를 처리할 위치를 가리키는 포인터다.
3. char *_IO_read_end
읽을 데이터가 있는 영역의 끝을 가리키는 포인터다. EOF라고 보면 될 듯 하다.
4. char *_IO_read_base
읽고 있는 데이터의 시작을 가리키는 포인터다.
5. char *_IO_write_base
데이터를 쓸 영역의 시작 위치를 가리키는 포인터다.
6. char *_IO_write_ptr
현재 데이터를 쓸 곳을 가리키는 포인터다.
7. char *_IO_write_end
데이터를 쓸 영역의 끝을 가리키는 포인터다.
8. char *_IO_buf_base
버퍼의 시작 주소를 가리킨다.
9. char *_IO_buf_end
버퍼의 끝 주소를 가리킨다.
10. char *_IO_save_base
11. char *_IO_backup_base
12. char *_IO_save_end
13. struct _IO_marker *_markers
14. struct _IO_FILE *_chain
15. int _fileno
16. int _flags2
17. __off_t _old_offset
18. unsigned short _cur_column
19. signed char _vtable_offset
19. char _shortbuf[1]
20. _IO_lock_t *_lock
21. struct _IO_codecvt *_codecvt
22. struct _IO_wide_data *_wide_data
23. struct _IO_FILE *_freeres_list
24. void *_freeres_buf
25. size_t __pad5
26. char _unused2[15 * sizeof(int) - 4 * sizeof(void *) - sizeof(size_t)]
glibc 코드 진짜 그지같다 읽는게 너무 힘들다
'Pwn_Others > Concepts' 카테고리의 다른 글
[glibc] tcache (0) | 2020.04.24 |
---|---|
[glibc] ptmalloc2 (0) | 2020.04.13 |