From dd89bb8ad4fe184a34b5dbdda237e640fc82121b Mon Sep 17 00:00:00 2001 From: midipix Date: Mon, 27 Jul 2015 04:01:18 -0400 Subject: entered advanced internal development stage. --- src/string/ntapi_tt_string_null_offset.c | 93 ++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/string/ntapi_tt_string_null_offset.c (limited to 'src/string/ntapi_tt_string_null_offset.c') diff --git a/src/string/ntapi_tt_string_null_offset.c b/src/string/ntapi_tt_string_null_offset.c new file mode 100644 index 0000000..3565acb --- /dev/null +++ b/src/string/ntapi_tt_string_null_offset.c @@ -0,0 +1,93 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013,2014,2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#include +#include +#include "ntapi_impl.h" + +size_t __cdecl __ntapi_tt_string_null_offset_multibyte( + __in const char * str) +{ + const char * cap; + const uintptr_t * ptr; + + #define HIGH_BIT_TEST (uintptr_t)0x0101010101010101 + #define AND_BITS (uintptr_t)0x8080808080808080 + + cap = str; + while ((uintptr_t)cap % sizeof(uintptr_t)) { + if (!(*cap)) + return cap - str; + cap++; + } + + ptr = (uintptr_t *)cap; + while (!((*ptr - HIGH_BIT_TEST) & ~(*ptr) & AND_BITS)) + ptr++; + + cap = (const char *)ptr; + while (*cap) + cap++; + + return cap - str; +} + + +size_t __cdecl __ntapi_tt_string_null_offset_short( + __in const int16_t * str) +{ + const int16_t * cap; + + cap = str; + while (*cap) + cap++; + + return (size_t)cap - (size_t)str; +} + + +size_t __cdecl __ntapi_tt_string_null_offset_dword( + __in const int32_t * str) +{ + const int32_t * cap; + + cap = str; + while (*cap) + cap++; + + return (size_t)cap - (size_t)str; +} + +size_t __cdecl __ntapi_tt_string_null_offset_qword( + __in const int64_t * str) +{ + const int64_t * cap; + + cap = str; + while (*cap) + cap++; + + return (size_t)cap - (size_t)str; +} + +size_t __cdecl __ntapi_tt_string_null_offset_ptrsize( + __in const intptr_t *str) +{ + const intptr_t * cap; + + cap = str; + while (*cap) + cap++; + + return (size_t)cap - (size_t)str; +} + +size_t __cdecl __ntapi_wcslen(const wchar16_t * str) +{ + size_t len; + len = __ntapi_tt_string_null_offset_short((const int16_t *)str); + return len / 2; +} -- cgit v1.2.3