summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2017-09-10 18:18:18 (GMT)
committermidipix <writeonce@midipix.org>2017-09-11 03:08:06 (GMT)
commita4031208e5dea11cbb0bbc95c402b57b662a94a1 (patch)
tree7e112df61f2a271f5fff985fffeffb0cc57e6be6
parent72ef7534b06e26796b5f608773cf4fb9febab59b (diff)
downloadntapi-a4031208e5.tar.bz2
ntapi-a4031208e5.tar.xz
envp primitives: integrated __ntapi_tt_get_env_var_meta_utf8().
-rw-r--r--include/ntapi/nt_argv.h19
-rw-r--r--include/ntapi/ntapi.h1
-rw-r--r--src/argv/ntapi_tt_env_vars.c34
-rw-r--r--src/internal/ntapi.c1
-rw-r--r--src/internal/ntapi_fnapi.h1
5 files changed, 54 insertions, 2 deletions
diff --git a/include/ntapi/nt_argv.h b/include/ntapi/nt_argv.h
index db52e95..de149dc 100644
--- a/include/ntapi/nt_argv.h
+++ b/include/ntapi/nt_argv.h
@@ -12,11 +12,12 @@
#include "nt_abi.h"
-/* ntapi_tt_get_argv_envp_utf16 flag bits */
+/* ntapi_tt_get_argv_envp flag bits */
#define NT_GET_ARGV_ENVP_USE_INTERNAL_BUFFER (0x0000)
#define NT_GET_ARGV_ENVP_USE_CALLER_BUFFER (0x0001)
#define NT_GET_ARGV_ENVP_COPY_ENVIRONMENT (0x0002)
-#define NT_GET_ARGV_ENVP_VALIDATE_UTF16 (0x0004)
+#define NT_GET_ARGV_ENVP_VALIDATE_UTF8 (0x0004)
+#define NT_GET_ARGV_ENVP_VALIDATE_UTF16 (0x0008)
/* ntapi_tt_program_option flag bits */
#define NT_OPTION_SHORT (0x0001)
@@ -44,6 +45,14 @@ typedef struct _nt_program_options_meta {
} nt_program_options_meta;
+typedef struct _nt_env_var_meta_utf8 {
+ char * name;
+ char * value;
+ int envp_index;
+ uint32_t flags;
+} nt_env_var_meta_utf8;
+
+
typedef struct _nt_env_var_meta_utf16 {
wchar16_t * name;
wchar16_t * value;
@@ -133,6 +142,12 @@ typedef int32_t __stdcall ntapi_tt_get_argv_envp_utf16(
__out void * reserved __optional);
+typedef int32_t __stdcall ntapi_tt_get_env_var_meta_utf8(
+ __in char * env_var_name,
+ __in char ** envp,
+ __out nt_env_var_meta_utf8 * env_var_meta);
+
+
typedef int32_t __stdcall ntapi_tt_get_env_var_meta_utf16(
__in wchar16_t * env_var_name,
__in wchar16_t ** envp,
diff --git a/include/ntapi/ntapi.h b/include/ntapi/ntapi.h
index 8d2b26a..528ab69 100644
--- a/include/ntapi/ntapi.h
+++ b/include/ntapi/ntapi.h
@@ -521,6 +521,7 @@ typedef struct _ntapi_vtbl {
ntapi_tt_parse_cmd_line_args_utf16 * tt_parse_cmd_line_args_utf16;
ntapi_tt_get_argv_envp_utf8 * tt_get_argv_envp_utf8;
ntapi_tt_get_argv_envp_utf16 * tt_get_argv_envp_utf16;
+ ntapi_tt_get_env_var_meta_utf8 * tt_get_env_var_meta_utf8;
ntapi_tt_get_env_var_meta_utf16 * tt_get_env_var_meta_utf16;
ntapi_tt_array_copy_utf8 * tt_array_copy_utf8;
ntapi_tt_array_copy_utf16 * tt_array_copy_utf16;
diff --git a/src/argv/ntapi_tt_env_vars.c b/src/argv/ntapi_tt_env_vars.c
index 9c62eb5..9b671b6 100644
--- a/src/argv/ntapi_tt_env_vars.c
+++ b/src/argv/ntapi_tt_env_vars.c
@@ -8,6 +8,40 @@
#include <ntapi/ntapi.h>
#include "ntapi_impl.h"
+int32_t __stdcall __ntapi_tt_get_env_var_meta_utf8(
+ __in char * env_var_name,
+ __in char ** envp,
+ __out nt_env_var_meta_utf8 * env_var_meta)
+{
+ char ** penv;
+ char * ch;
+
+ /* lookup */
+ for (penv=envp; *penv; penv++) {
+ for (ch=penv[0]; *ch && (*ch != '='); )
+ ch++;
+
+ if (*ch != '=')
+ return NT_STATUS_INVALID_USER_BUFFER;
+
+ if ((ch > *penv) && !(__ntapi->tt_strncmp_multibyte(
+ *penv,
+ env_var_name,
+ ch - *penv))) {
+ /* match */
+ env_var_meta->name = *penv;
+ env_var_meta->value = ++ch;
+ env_var_meta->envp_index = penv - envp;
+ env_var_meta->flags = 0;
+
+ return NT_STATUS_SUCCESS;
+ }
+ }
+
+ return NT_STATUS_NOT_FOUND;
+}
+
+
int32_t __stdcall __ntapi_tt_get_env_var_meta_utf16(
__in wchar16_t * env_var_name,
__in wchar16_t ** envp,
diff --git a/src/internal/ntapi.c b/src/internal/ntapi.c
index 0e9e6e0..1047606 100644
--- a/src/internal/ntapi.c
+++ b/src/internal/ntapi.c
@@ -311,6 +311,7 @@ static int32_t __fastcall __ntapi_init_once(ntapi_vtbl ** pvtbl)
__ntapi->tt_parse_cmd_line_args_utf16 = __ntapi_tt_parse_cmd_line_args_utf16;
__ntapi->tt_get_argv_envp_utf8 = __ntapi_tt_get_argv_envp_utf8;
__ntapi->tt_get_argv_envp_utf16 = __ntapi_tt_get_argv_envp_utf16;
+ __ntapi->tt_get_env_var_meta_utf8 = __ntapi_tt_get_env_var_meta_utf8;
__ntapi->tt_get_env_var_meta_utf16 = __ntapi_tt_get_env_var_meta_utf16;
__ntapi->tt_array_copy_utf16 = __ntapi_tt_array_copy_utf16;
__ntapi->tt_array_copy_utf8 = __ntapi_tt_array_copy_utf8;
diff --git a/src/internal/ntapi_fnapi.h b/src/internal/ntapi_fnapi.h
index 8bafdbc..05ff9ab 100644
--- a/src/internal/ntapi_fnapi.h
+++ b/src/internal/ntapi_fnapi.h
@@ -182,6 +182,7 @@ ntapi_tt_get_peb_env_block_utf16 __ntapi_tt_get_peb_env_block_utf16;
ntapi_tt_parse_cmd_line_args_utf16 __ntapi_tt_parse_cmd_line_args_utf16;
ntapi_tt_get_argv_envp_utf8 __ntapi_tt_get_argv_envp_utf8;
ntapi_tt_get_argv_envp_utf16 __ntapi_tt_get_argv_envp_utf16;
+ntapi_tt_get_env_var_meta_utf8 __ntapi_tt_get_env_var_meta_utf8;
ntapi_tt_get_env_var_meta_utf16 __ntapi_tt_get_env_var_meta_utf16;
ntapi_tt_array_copy_utf8 __ntapi_tt_array_copy_utf8;
ntapi_tt_array_copy_utf16 __ntapi_tt_array_copy_utf16;