Lucciefr
Lua code caving, injection and exploration framework
Functions
codepage.c File Reference

Windows codepage / character (set) conversions. More...

Functions

int wide_to_str (char **output, const UINT codepage, const wchar_t *wstr, int wlen)
 "wide to string". More...
 
int str_to_wide (wchar_t **output, const UINT codepage, const char *str, int len)
 "string to wide". More...
 
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. More...
 

Detailed Description

Windows codepage / character (set) conversions.

Note
Windows code page identifiers are listed at https://msdn.microsoft.com/en-us/library/windows/desktop/dd317756%28v=vs.85%29.aspx.
Some 'pseudo' CP_* constants can also be found/included via <winnls.h>.

Function Documentation

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.

You could e.g. use this to translate between ANSI and UTF-8. output receives the (char*) result allocated with malloc, make sure you free() it later!

Returns
the number of chars that were successfully written to *output
int str_to_wide ( wchar_t **  output,
const UINT  codepage,
const char *  str,
int  len 
)

"string to wide".

Convert a "multibyte" string from given codepage to a wide (UTF-16) string. You can use this to translate from UTF-8 with codepage == CP_UTF8. Pass codepage == 0 (or CP_ACP) to use the default "ansi" codepage of the system. output receives the (wchar_t*) result allocated with malloc, make sure you free() it later!

Returns
the number of widechars that were successfully transferred to *output
int wide_to_str ( char **  output,
const UINT  codepage,
const wchar_t *  wstr,
int  wlen 
)

"wide to string".

Convert a wide (UTF-16) string to a "multibyte" string with a given codepage. You can use this to translate to UTF-8 with codepage == CP_UTF8. Pass codepage == 0 (or CP_ACP) to use the default "ansi" codepage of the system. output receives the (char*) result allocated with malloc, make sure you free() it later!

Returns
the number of bytes that were successfully transferred to *output