summaryrefslogtreecommitdiffhomepage
path: root/src/ntcon.c
blob: 5ad9223e4c37a75349d68916e6db1332fd46de3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/********************************************************/
/*  ntcon: free-standing console interface definitions  */
/*  Copyright (C) 2013,2014,2015  Z. Gilboa             */
/*  Released under GPLv2 and GPLv3; see COPYING.NTCON.  */
/********************************************************/

#include <pemagine/pemagine.h>
#include <ntcon/ntcon.h>

#define NT_STATUS_SUCCESS		0x00000000
#define NT_STATUS_INTERNAL_ERROR	0xC00000E5

#define NTCON_PTR_INIT(x,y) pvtbl->x = \
	(ntcon_##x *)pe_get_procedure_address(hkernel, #y)

ntcon_api
int32_t __fastcall ntcon_vtbl_init(ntcon_vtbl * pvtbl)
{
	void *	hkernel;

	if (!(hkernel = pe_get_kernel32_module_handle()))
		return NT_STATUS_INTERNAL_ERROR;

	/* console handles */
	NTCON_PTR_INIT(alloc_console,				AllocConsole);
	NTCON_PTR_INIT(attach_console,				AttachConsole);
	NTCON_PTR_INIT(free_console,				FreeConsole);
	NTCON_PTR_INIT(get_std_handle,				GetStdHandle);

	/* read/write using std handles */
	NTCON_PTR_INIT(get_number_of_console_input_events,	GetNumberOfConsoleInputEvents);
	NTCON_PTR_INIT(flush_console_input_buffer,		FlushConsoleInputBuffer);
	NTCON_PTR_INIT(peek_console_input_ansi,			PeekConsoleInputA);
	NTCON_PTR_INIT(peek_console_input_utf16,		PeekConsoleInputW);
	NTCON_PTR_INIT(read_console_ansi,			ReadConsoleA);
	NTCON_PTR_INIT(read_console_utf16,			ReadConsoleW);
	NTCON_PTR_INIT(read_console_input_ansi,			ReadConsoleInputA);
	NTCON_PTR_INIT(read_console_input_utf16,		ReadConsoleInputW);
	NTCON_PTR_INIT(read_console_output_ansi,		ReadConsoleOutputA);
	NTCON_PTR_INIT(read_console_output_utf16,		ReadConsoleOutputW);
	NTCON_PTR_INIT(write_console_ansi,			WriteConsoleA);
	NTCON_PTR_INIT(write_console_utf16,			WriteConsoleW);
	NTCON_PTR_INIT(write_console_input_ansi,		WriteConsoleInputA);
	NTCON_PTR_INIT(write_console_input_utf16,		WriteConsoleInputW);
	NTCON_PTR_INIT(write_console_output_ansi,		WriteConsoleOutputA);
	NTCON_PTR_INIT(write_console_output_utf16,		WriteConsoleOutputW);

	/* screen buffers */
	NTCON_PTR_INIT(create_console_screen_buffer,		CreateConsoleScreenBuffer);
	NTCON_PTR_INIT(get_console_screen_buffer_info,		GetConsoleScreenBufferInfo);
	NTCON_PTR_INIT(get_console_screen_buffer_info_ex,	GetConsoleScreenBufferInfoEx);
	NTCON_PTR_INIT(set_console_screen_buffer_info_ex,	SetConsoleScreenBufferInfoEx);
	NTCON_PTR_INIT(set_console_screen_buffer_size,		SetConsoleScreenBufferSize);
	NTCON_PTR_INIT(set_console_active_screen_buffer,	SetConsoleActiveScreenBuffer);
	NTCON_PTR_INIT(set_console_window_info,			SetConsoleWindowInfo);
	NTCON_PTR_INIT(scroll_console_screen_buffer_ansi,	ScrollConsoleScreenBufferA);
	NTCON_PTR_INIT(scroll_console_screen_buffer_utf16,	ScrollConsoleScreenBufferW);

	/* code page */
	NTCON_PTR_INIT(get_console_code_page,			GetConsoleCP);
	NTCON_PTR_INIT(set_console_code_page,			SetConsoleCP);

	/* console control */
	NTCON_PTR_INIT(generate_console_ctrl_event,		GenerateConsoleCtrlEvent);
	NTCON_PTR_INIT(set_console_ctrl_handler,		SetConsoleCtrlHandler);

	/* interface mode */
	NTCON_PTR_INIT(get_console_mode,			GetConsoleMode);
	NTCON_PTR_INIT(set_console_mode,			SetConsoleMode);

	/* console process list */
	NTCON_PTR_INIT(get_console_process_list,		GetConsoleProcessList);

	/* aliases */
	NTCON_PTR_INIT(add_console_alias_ansi,			AddConsoleAliasA);
	NTCON_PTR_INIT(add_console_alias_utf16,			AddConsoleAliasW);
	NTCON_PTR_INIT(get_console_alias_ansi,			GetConsoleAliasA);
	NTCON_PTR_INIT(get_console_alias_utf16,			GetConsoleAliasW);
	NTCON_PTR_INIT(get_console_aliases_ansi,		GetConsoleAliasesA);
	NTCON_PTR_INIT(get_console_aliases_utf16,		GetConsoleAliasesW);
	NTCON_PTR_INIT(get_console_aliases_length_ansi,		GetConsoleAliasesLengthA);
	NTCON_PTR_INIT(get_console_aliases_length_utf16,	GetConsoleAliasesLengthW);
	NTCON_PTR_INIT(get_console_alias_exes_ansi,		GetConsoleAliasExesA);
	NTCON_PTR_INIT(get_console_alias_exes_utf16,		GetConsoleAliasExesW);
	NTCON_PTR_INIT(get_console_alias_exes_length_ansi,	GetConsoleAliasExesLengthA);
	NTCON_PTR_INIT(get_console_alias_exes_length_utf16,	GetConsoleAliasExesLengthW);

	/* output attributes */
	NTCON_PTR_INIT(fill_console_output_attribute,		FillConsoleOutputAttribute);
	NTCON_PTR_INIT(read_console_output_attribute,		ReadConsoleOutputAttribute);
	NTCON_PTR_INIT(write_console_output_attribute,		WriteConsoleOutputAttribute);

	/* output characters */
	NTCON_PTR_INIT(fill_console_output_character_ansi,	FillConsoleOutputCharacterA);
	NTCON_PTR_INIT(fill_console_output_character_utf16,	FillConsoleOutputCharacterW);
	NTCON_PTR_INIT(read_console_output_character_ansi,	ReadConsoleOutputCharacterA);
	NTCON_PTR_INIT(read_console_output_character_utf16,	ReadConsoleOutputCharacterW);
	NTCON_PTR_INIT(write_console_output_character_ansi,	WriteConsoleOutputCharacterA);
	NTCON_PTR_INIT(write_console_output_character_utf16,	WriteConsoleOutputCharacterW);

	/* output code page */
	NTCON_PTR_INIT(get_console_output_code_page,		GetConsoleOutputCP);
	NTCON_PTR_INIT(set_console_output_code_page,		SetConsoleOutputCP);

	/* text attributes */
	NTCON_PTR_INIT(set_console_text_attribute,		SetConsoleTextAttribute);

	/* cursor info */
	NTCON_PTR_INIT(get_console_cursor_info,			GetConsoleCursorInfo);
	NTCON_PTR_INIT(set_console_cursor_info,			SetConsoleCursorInfo);
	NTCON_PTR_INIT(set_console_cursor_position,		SetConsoleCursorPosition);

	/* selection info */
	NTCON_PTR_INIT(get_console_selection_info,		GetConsoleSelectionInfo);

	/* history info */
	NTCON_PTR_INIT(get_console_history_info,		GetConsoleHistoryInfo);
	NTCON_PTR_INIT(set_console_history_info,		SetConsoleHistoryInfo);

	/* font info */
	NTCON_PTR_INIT(get_console_font_size,			GetConsoleFontSize);
	NTCON_PTR_INIT(get_current_console_font,		GetCurrentConsoleFont);
	NTCON_PTR_INIT(get_current_console_font_ex,		GetCurrentConsoleFontEx);
	NTCON_PTR_INIT(set_current_console_font_ex,		SetCurrentConsoleFontEx);

	/* mouse capabilities */
	NTCON_PTR_INIT(get_number_of_console_mouse_buttons,	GetNumberOfConsoleMouseButtons);

	/* window information */
	NTCON_PTR_INIT(get_console_window,			GetConsoleWindow);
	NTCON_PTR_INIT(get_largest_console_window_size,		GetLargestConsoleWindowSize);

	/* console api: display mode */
	NTCON_PTR_INIT(get_console_display_mode,		GetConsoleDisplayMode);
	NTCON_PTR_INIT(set_console_display_mode,		SetConsoleDisplayMode);

	/* console title */
	NTCON_PTR_INIT(get_console_title_ansi,			GetConsoleTitleA);
	NTCON_PTR_INIT(get_console_title_utf16,			GetConsoleTitleW);
	NTCON_PTR_INIT(set_console_title_ansi,			SetConsoleTitleA);
	NTCON_PTR_INIT(set_console_title_utf16,			SetConsoleTitleW);
	NTCON_PTR_INIT(get_console_original_title_ansi,		GetConsoleOriginalTitleA);
	NTCON_PTR_INIT(get_console_original_title_utf16,	GetConsoleOriginalTitleW);

	return NT_STATUS_SUCCESS;
}