Lucciefr
Lua code caving, injection and exploration framework
util_win.h
Go to the documentation of this file.
1 
3 #ifndef UTIL_WIN_H
4 # define UTIL_WIN_H
5 # if _WINDOWS
6 
7 #include "bool.h"
8 #include <windows.h>
9 
10 #define DEFAULT_CODEPAGE CP_ACP /* default: system ANSI code page */
11 // Normally the error messages should be 'ANSI' too (CP_ACP), but we
12 // might CP_OEMCP, as that's what the (Windows') console output expects.
13 #define ERROR_CODEPAGE CP_ACP
14 
15 int wide_to_str(char* *output, const UINT codepage, const wchar_t *wstr, int wlen);
16 int str_to_wide(wchar_t* *output, const UINT codepage, const char *str, int len);
17 int str_to_str(char* *output, const UINT codepage_from, const UINT codepage_to, const char *str, int len);
18 
19 // string <-> wide wrappers
20 #define wide_to_ansi(output, wstr, wlen) wide_to_str(output, CP_ACP, wstr, wlen)
21 #define wide_to_cp1252(output, wstr, wlen) wide_to_str(output, 1252, wstr, wlen)
22 #define wide_to_utf8(output, wstr, wlen) wide_to_str(output, CP_UTF8, wstr, wlen)
23 #define ansi_to_wide(output, str, len) str_to_wide(output, CP_ACP, str, len)
24 #define cp1252_to_wide(output, str, len) str_to_wide(output, 1252, str, len)
25 #define utf8_to_wide(output, str, len) str_to_wide(output, CP_UTF8, str, len)
26 
27 // str_to_str (codepage conversion) wrappers
28 #define ansi_to_oem(output, str, len) str_to_str(output, CP_ACP, CP_OEMCP, str, len)
29 #define ansi_to_utf8(output, str, len) str_to_str(output, CP_ACP, CP_UTF8, str, len)
30 #define cp1252_to_utf8(output, str, len) str_to_str(output, 1252, CP_UTF8, str, len)
31 #define utf8_to_ansi(output, str, len) str_to_str(output, CP_UTF8, CP_ACP, str, len)
32 #define utf8_to_cp1252(output, str, len) str_to_str(output, CP_UTF8, 1252, str, len)
33 #define utf8_to_oem(output, str, len) str_to_str(output, CP_UTF8, CP_OEMCP, str, len)
34 
35 // Windows error message (optionally formatted if "decorate" == true)
36 char *win_error(DWORD code, const UINT codepage, bool decorate);
37 
38 # endif // _WINDOWS
39 #endif // UTIL_WIN_H
int str_to_str(char **output, const UINT codepage_from, const UINT codepage_to, const char *str, int len)
"string to string" Convert a "multibyte" string between given codepages.
Definition: codepage.c:57
int str_to_wide(wchar_t **output, const UINT codepage, const char *str, int len)
"string to wide".
Definition: codepage.c:37
int wide_to_str(char **output, const UINT codepage, const wchar_t *wstr, int wlen)
"wide to string".
Definition: codepage.c:18
char * win_error(DWORD code, const UINT codepage, bool decorate)
Format error message.
Definition: errmsg.c:65
boolean data type and constants/macros