From 918d22c5a20e579c9c9e32ff41bfdcb11c350d2c Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 13 Feb 2026 23:59:41 +0800 Subject: add haiku ci --- core/src/tbox/tbox | 2 +- core/src/xmake/string/lower.c | 162 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 162 insertions(+), 2 deletions(-) (limited to 'core/src') diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox index ef851bcb6..75c90b4c4 160000 --- a/core/src/tbox/tbox +++ b/core/src/tbox/tbox @@ -1 +1 @@ -Subproject commit ef851bcb6589b6092f5bd3fca4625631237f9bdd +Subproject commit 75c90b4c4313f84f8247867c99721882e390f401 diff --git a/core/src/xmake/string/lower.c b/core/src/xmake/string/lower.c index 71f8408dc..07ae4bff4 100644 --- a/core/src/xmake/string/lower.c +++ b/core/src/xmake/string/lower.c @@ -23,6 +23,166 @@ * includes */ #include "prefix.h" +# include + +static __tb_inline__ tb_bool_t tb_unicode_tolower_try(tb_uint32_t ch, tb_uint32_t* out) +{ + // builtin, locale-independent case mapping for some common unicode ranges: + // - Basic Latin (ASCII) + // - Latin-1 Supplement (partial) + // - Latin Extended-A (partial) + // - Greek (partial) + // - Cyrillic (partial) + if (sizeof(tb_wchar_t) == 2 && ch >= 0xd800 && ch <= 0xdfff) return tb_false; + + // Basic Latin (ASCII) + if (ch <= 0x7f) + { + tb_trace_i("basic: %x", ch); + *out = tb_tolower(ch); + return tb_true; + } + + // Latin-1 Supplement: U+00C0..U+00D6, U+00D8..U+00DE + if ((ch >= 0x00c0 && ch <= 0x00d6) || (ch >= 0x00d8 && ch <= 0x00de)) { *out = ch + 0x20; return tb_true; } + // Latin-1 Supplement: U+00E0..U+00F6, U+00F8..U+00FE + if ((ch >= 0x00e0 && ch <= 0x00f6) || (ch >= 0x00f8 && ch <= 0x00fe)) { *out = ch; return tb_true; } + + // Latin-1 Supplement: U+0178 <-> U+00FF + if (ch == 0x0178) { *out = 0x00ff; return tb_true; } + if (ch == 0x00ff) { *out = ch; return tb_true; } + + // Latin Extended Additional: U+1E9E <-> U+00DF + if (ch == 0x1e9e) { *out = 0x00df; return tb_true; } + if (ch == 0x00df) { *out = ch; return tb_true; } + + // Latin Extended-A: many letters have alternating upper/lower code points + if (ch >= 0x0100 && ch <= 0x012f) { *out = (ch & 0x1) ? ch : (ch + 1); return tb_true; } + if (ch >= 0x0132 && ch <= 0x0137) { *out = (ch & 0x1) ? ch : (ch + 1); return tb_true; } + if (ch >= 0x0139 && ch <= 0x0148) { *out = (ch & 0x1) ? (ch + 1) : ch; return tb_true; } + if (ch >= 0x014a && ch <= 0x0177) { *out = (ch & 0x1) ? ch : (ch + 1); return tb_true; } + if (ch >= 0x0179 && ch <= 0x017e) { *out = (ch & 0x1) ? (ch + 1) : ch; return tb_true; } + // Latin Extended-A: long s (already lowercase) + if (ch == 0x017f) { *out = ch; return tb_true; } + + // Greek and Coptic (partial): U+0391..U+03A1, U+03A3..U+03AB + if ((ch >= 0x0391 && ch <= 0x03a1) || (ch >= 0x03a3 && ch <= 0x03ab)) { *out = ch + 0x20; return tb_true; } + // Greek and Coptic (partial): U+03B1..U+03C1, U+03C3..U+03CB, and U+03C2 + if ((ch >= 0x03b1 && ch <= 0x03c1) || (ch >= 0x03c3 && ch <= 0x03cb) || ch == 0x03c2) { *out = ch; return tb_true; } + + // Cyrillic (partial): U+0401/U+0451 and U+0410..U+042F + if (ch == 0x0401) { *out = 0x0451; return tb_true; } + if (ch == 0x0451) { *out = ch; return tb_true; } + if (ch >= 0x0402 && ch <= 0x040f) { *out = ch + 0x50; return tb_true; } + if (ch >= 0x0452 && ch <= 0x045f) { *out = ch; return tb_true; } + if (ch >= 0x0410 && ch <= 0x042f) { *out = ch + 0x20; return tb_true; } + + if (ch >= 0x0430 && ch <= 0x044f) { + *out = ch; + return tb_true; + } + + return tb_false; +} + +tb_wchar_t tb_towlower_test(tb_wchar_t c) +{ + tb_trace_i("towlower: %x, wchar: %d", (tb_uint32_t)c, sizeof(tb_wchar_t)); + tb_uint32_t ch = tb_bits_wchar_to_u32_le(c); + tb_uint32_t out; + if (__tb_likely__(tb_unicode_tolower_try(ch, &out))) { + tb_trace_i("towlower: out: %x", out); + return tb_bits_u32_le_to_wchar(out); + } + + tb_trace_i("towlower xxx: %x", (tb_uint32_t)c); + return (tb_wchar_t)towlower((tb_uint32_t)c); +} + +static tb_wchar_t* tb_wcslwr_test(tb_wchar_t* s) +{ + // check + tb_assert_and_check_return_val(s, tb_null); + + // set local locale + tb_setlocale(); + + tb_wchar_t* p = s; + while (*p) + { + *p = tb_towlower_test(*p); + p++; + } + + // set default locale + tb_resetlocale(); + + return s; +} + +static tb_size_t tb_mbstowcs_charset(tb_wchar_t* s1, tb_char_t const* s2, tb_size_t n) +{ + // check + tb_assert_and_check_return_val(s1 && s2, 0); + + // init + tb_size_t e = (sizeof(tb_wchar_t) == 4) ? TB_CHARSET_TYPE_UTF32 : TB_CHARSET_TYPE_UTF16; + tb_long_t r = tb_charset_conv_cstr(TB_CHARSET_TYPE_UTF8, e | TB_CHARSET_TYPE_LE, s2, + (tb_byte_t*)s1, n * sizeof(tb_wchar_t)); + if (r > 0) r /= sizeof(tb_wchar_t); + + // strip + if (r >= 0) s1[r] = L'\0'; + + tb_trace_i("tb_mbstowcs_charset: %ld", r); + // ok? + return r >= 0 ? r : -1; +} + +static tb_long_t tb_charset_utf8_tolower_test(tb_char_t* s, tb_size_t n) +{ + tb_assert_and_check_return_val(s, -1); + + tb_trace_i("s: %s: %d", s, n); + + // try ascii tolower first + tb_char_t* p = s; + tb_char_t* e = s + n; + while (p < e && *p) + { + if ((*p) & 0x80) { + break; + } + tb_trace_i("old: %c -> %x", *p); + *p = tb_tolower(*p); + tb_trace_i("new: %c -> %x", *p); + p++; + } + tb_trace_i("test: %d %d", p == e, !*p); + + if (p == e || !*p) return p - s; + + // convert the suffix to wchar_t + tb_long_t r = -1; + tb_size_t wn = e - p + 1; + tb_wchar_t wb[256]; + tb_wchar_t* w = (wn <= 256)? wb : (tb_wchar_t*)tb_malloc(wn * sizeof(tb_wchar_t)); + if (w) + { + tb_trace_i("tb_mbstowcs 111"); + if (tb_mbstowcs_charset(w, p, wn) != -1) + { + tb_trace_i("tb_wcslwr_test 111"); + tb_wcslwr_test(w); + r = tb_wcstombs(p, w, wn); + if (r != -1) r += (p - s); + } + + tb_trace_i("tb_free 111"); + if (w != wb) tb_free(w); + } + return r; +} /* ////////////////////////////////////////////////////////////////////////////////////// * implementation @@ -58,7 +218,7 @@ tb_int_t xm_string_lower(lua_State *lua) { buffer[size] = '\0'; // to lower - tb_long_t real_size = tb_charset_utf8_tolower(buffer, size); + tb_long_t real_size = tb_charset_utf8_tolower_test(buffer, size); // push result if (real_size >= 0) { -- cgit v1.3.1 From ffc3348ba6cc87402f24b4755ecfd8a505b52787 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 14 Feb 2026 16:34:49 +0800 Subject: enable force-utf8 for haiku --- core/src/tbox/inc/haiku/tbox.config.h | 2 +- core/src/tbox/inc/iphoneos/tbox.config.h | 2 +- core/src/tbox/inc/solaris/tbox.config.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'core/src') diff --git a/core/src/tbox/inc/haiku/tbox.config.h b/core/src/tbox/inc/haiku/tbox.config.h index 8a9e72ad8..dc61fce45 100644 --- a/core/src/tbox/inc/haiku/tbox.config.h +++ b/core/src/tbox/inc/haiku/tbox.config.h @@ -16,7 +16,7 @@ /*#undef TB_CONFIG_MICRO_ENABLE*/ /*#undef TB_CONFIG_TYPE_HAVE_WCHAR*/ #define TB_CONFIG_TYPE_HAVE_FLOAT 1 -/*#undef TB_CONFIG_FORCE_UTF8*/ +#define TB_CONFIG_FORCE_UTF8 1 /*#undef TB_CONFIG_API_HAVE_DEPRECATED*/ /*#undef TB_CONFIG_EXCEPTION_ENABLE*/ diff --git a/core/src/tbox/inc/iphoneos/tbox.config.h b/core/src/tbox/inc/iphoneos/tbox.config.h index 290786a50..43aa10c8b 100755 --- a/core/src/tbox/inc/iphoneos/tbox.config.h +++ b/core/src/tbox/inc/iphoneos/tbox.config.h @@ -16,7 +16,7 @@ /* #undef TB_CONFIG_MICRO_ENABLE */ /* #undef TB_CONFIG_TYPE_HAVE_WCHAR */ #define TB_CONFIG_TYPE_HAVE_FLOAT 1 -/* #undef TB_CONFIG_FORCE_UTF8 */ +#define TB_CONFIG_FORCE_UTF8 1 /* #undef TB_CONFIG_API_HAVE_DEPRECATED */ /* #undef TB_CONFIG_EXCEPTION_ENABLE */ diff --git a/core/src/tbox/inc/solaris/tbox.config.h b/core/src/tbox/inc/solaris/tbox.config.h index 89bce47bc..25bafd9f6 100644 --- a/core/src/tbox/inc/solaris/tbox.config.h +++ b/core/src/tbox/inc/solaris/tbox.config.h @@ -16,7 +16,7 @@ /*#undef TB_CONFIG_MICRO_ENABLE*/ /*#undef TB_CONFIG_TYPE_HAVE_WCHAR*/ #define TB_CONFIG_TYPE_HAVE_FLOAT 1 -/*#undef TB_CONFIG_FORCE_UTF8*/ +#define TB_CONFIG_FORCE_UTF8 1 /*#undef TB_CONFIG_API_HAVE_DEPRECATED*/ /*#undef TB_CONFIG_EXCEPTION_ENABLE*/ -- cgit v1.3.1 From 947c09b57f3a2bd14dbd05e1cb6f12c3c815e533 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 14 Feb 2026 16:38:02 +0800 Subject: update tbox --- core/src/tbox/tbox | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/src') diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox index 75c90b4c4..ddc363161 160000 --- a/core/src/tbox/tbox +++ b/core/src/tbox/tbox @@ -1 +1 @@ -Subproject commit 75c90b4c4313f84f8247867c99721882e390f401 +Subproject commit ddc363161ce6aed86109dcd665b63fb9a810e3a3 -- cgit v1.3.1 From 021f8144f2686305795b61a90ef040ee98f139ef Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 14 Feb 2026 16:39:19 +0800 Subject: update lower --- core/src/xmake/string/lower.c | 162 +----------------------------------------- 1 file changed, 1 insertion(+), 161 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/string/lower.c b/core/src/xmake/string/lower.c index 07ae4bff4..71f8408dc 100644 --- a/core/src/xmake/string/lower.c +++ b/core/src/xmake/string/lower.c @@ -23,166 +23,6 @@ * includes */ #include "prefix.h" -# include - -static __tb_inline__ tb_bool_t tb_unicode_tolower_try(tb_uint32_t ch, tb_uint32_t* out) -{ - // builtin, locale-independent case mapping for some common unicode ranges: - // - Basic Latin (ASCII) - // - Latin-1 Supplement (partial) - // - Latin Extended-A (partial) - // - Greek (partial) - // - Cyrillic (partial) - if (sizeof(tb_wchar_t) == 2 && ch >= 0xd800 && ch <= 0xdfff) return tb_false; - - // Basic Latin (ASCII) - if (ch <= 0x7f) - { - tb_trace_i("basic: %x", ch); - *out = tb_tolower(ch); - return tb_true; - } - - // Latin-1 Supplement: U+00C0..U+00D6, U+00D8..U+00DE - if ((ch >= 0x00c0 && ch <= 0x00d6) || (ch >= 0x00d8 && ch <= 0x00de)) { *out = ch + 0x20; return tb_true; } - // Latin-1 Supplement: U+00E0..U+00F6, U+00F8..U+00FE - if ((ch >= 0x00e0 && ch <= 0x00f6) || (ch >= 0x00f8 && ch <= 0x00fe)) { *out = ch; return tb_true; } - - // Latin-1 Supplement: U+0178 <-> U+00FF - if (ch == 0x0178) { *out = 0x00ff; return tb_true; } - if (ch == 0x00ff) { *out = ch; return tb_true; } - - // Latin Extended Additional: U+1E9E <-> U+00DF - if (ch == 0x1e9e) { *out = 0x00df; return tb_true; } - if (ch == 0x00df) { *out = ch; return tb_true; } - - // Latin Extended-A: many letters have alternating upper/lower code points - if (ch >= 0x0100 && ch <= 0x012f) { *out = (ch & 0x1) ? ch : (ch + 1); return tb_true; } - if (ch >= 0x0132 && ch <= 0x0137) { *out = (ch & 0x1) ? ch : (ch + 1); return tb_true; } - if (ch >= 0x0139 && ch <= 0x0148) { *out = (ch & 0x1) ? (ch + 1) : ch; return tb_true; } - if (ch >= 0x014a && ch <= 0x0177) { *out = (ch & 0x1) ? ch : (ch + 1); return tb_true; } - if (ch >= 0x0179 && ch <= 0x017e) { *out = (ch & 0x1) ? (ch + 1) : ch; return tb_true; } - // Latin Extended-A: long s (already lowercase) - if (ch == 0x017f) { *out = ch; return tb_true; } - - // Greek and Coptic (partial): U+0391..U+03A1, U+03A3..U+03AB - if ((ch >= 0x0391 && ch <= 0x03a1) || (ch >= 0x03a3 && ch <= 0x03ab)) { *out = ch + 0x20; return tb_true; } - // Greek and Coptic (partial): U+03B1..U+03C1, U+03C3..U+03CB, and U+03C2 - if ((ch >= 0x03b1 && ch <= 0x03c1) || (ch >= 0x03c3 && ch <= 0x03cb) || ch == 0x03c2) { *out = ch; return tb_true; } - - // Cyrillic (partial): U+0401/U+0451 and U+0410..U+042F - if (ch == 0x0401) { *out = 0x0451; return tb_true; } - if (ch == 0x0451) { *out = ch; return tb_true; } - if (ch >= 0x0402 && ch <= 0x040f) { *out = ch + 0x50; return tb_true; } - if (ch >= 0x0452 && ch <= 0x045f) { *out = ch; return tb_true; } - if (ch >= 0x0410 && ch <= 0x042f) { *out = ch + 0x20; return tb_true; } - - if (ch >= 0x0430 && ch <= 0x044f) { - *out = ch; - return tb_true; - } - - return tb_false; -} - -tb_wchar_t tb_towlower_test(tb_wchar_t c) -{ - tb_trace_i("towlower: %x, wchar: %d", (tb_uint32_t)c, sizeof(tb_wchar_t)); - tb_uint32_t ch = tb_bits_wchar_to_u32_le(c); - tb_uint32_t out; - if (__tb_likely__(tb_unicode_tolower_try(ch, &out))) { - tb_trace_i("towlower: out: %x", out); - return tb_bits_u32_le_to_wchar(out); - } - - tb_trace_i("towlower xxx: %x", (tb_uint32_t)c); - return (tb_wchar_t)towlower((tb_uint32_t)c); -} - -static tb_wchar_t* tb_wcslwr_test(tb_wchar_t* s) -{ - // check - tb_assert_and_check_return_val(s, tb_null); - - // set local locale - tb_setlocale(); - - tb_wchar_t* p = s; - while (*p) - { - *p = tb_towlower_test(*p); - p++; - } - - // set default locale - tb_resetlocale(); - - return s; -} - -static tb_size_t tb_mbstowcs_charset(tb_wchar_t* s1, tb_char_t const* s2, tb_size_t n) -{ - // check - tb_assert_and_check_return_val(s1 && s2, 0); - - // init - tb_size_t e = (sizeof(tb_wchar_t) == 4) ? TB_CHARSET_TYPE_UTF32 : TB_CHARSET_TYPE_UTF16; - tb_long_t r = tb_charset_conv_cstr(TB_CHARSET_TYPE_UTF8, e | TB_CHARSET_TYPE_LE, s2, - (tb_byte_t*)s1, n * sizeof(tb_wchar_t)); - if (r > 0) r /= sizeof(tb_wchar_t); - - // strip - if (r >= 0) s1[r] = L'\0'; - - tb_trace_i("tb_mbstowcs_charset: %ld", r); - // ok? - return r >= 0 ? r : -1; -} - -static tb_long_t tb_charset_utf8_tolower_test(tb_char_t* s, tb_size_t n) -{ - tb_assert_and_check_return_val(s, -1); - - tb_trace_i("s: %s: %d", s, n); - - // try ascii tolower first - tb_char_t* p = s; - tb_char_t* e = s + n; - while (p < e && *p) - { - if ((*p) & 0x80) { - break; - } - tb_trace_i("old: %c -> %x", *p); - *p = tb_tolower(*p); - tb_trace_i("new: %c -> %x", *p); - p++; - } - tb_trace_i("test: %d %d", p == e, !*p); - - if (p == e || !*p) return p - s; - - // convert the suffix to wchar_t - tb_long_t r = -1; - tb_size_t wn = e - p + 1; - tb_wchar_t wb[256]; - tb_wchar_t* w = (wn <= 256)? wb : (tb_wchar_t*)tb_malloc(wn * sizeof(tb_wchar_t)); - if (w) - { - tb_trace_i("tb_mbstowcs 111"); - if (tb_mbstowcs_charset(w, p, wn) != -1) - { - tb_trace_i("tb_wcslwr_test 111"); - tb_wcslwr_test(w); - r = tb_wcstombs(p, w, wn); - if (r != -1) r += (p - s); - } - - tb_trace_i("tb_free 111"); - if (w != wb) tb_free(w); - } - return r; -} /* ////////////////////////////////////////////////////////////////////////////////////// * implementation @@ -218,7 +58,7 @@ tb_int_t xm_string_lower(lua_State *lua) { buffer[size] = '\0'; // to lower - tb_long_t real_size = tb_charset_utf8_tolower_test(buffer, size); + tb_long_t real_size = tb_charset_utf8_tolower(buffer, size); // push result if (real_size >= 0) { -- cgit v1.3.1 From 66ab9eb3c4a176c4d92acd88d76f99d27b06f632 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 14 Feb 2026 17:40:04 +0800 Subject: update tbox --- core/src/tbox/tbox | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/src') diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox index ddc363161..de475fef0 160000 --- a/core/src/tbox/tbox +++ b/core/src/tbox/tbox @@ -1 +1 @@ -Subproject commit ddc363161ce6aed86109dcd665b63fb9a810e3a3 +Subproject commit de475fef05346a7603efea54d77afead7a16daca -- cgit v1.3.1 From 1e15fe7013857315471598237635198d2e1c0c55 Mon Sep 17 00:00:00 2001 From: Saikari Date: Sun, 15 Feb 2026 19:45:00 +0300 Subject: add winos.file_signature function to retrieve file signature information --- core/src/xmake/engine.c | 2 + core/src/xmake/winos/file_signature.c | 244 ++++++++++++++++++++++++++++++++++ 2 files changed, 246 insertions(+) create mode 100644 core/src/xmake/winos/file_signature.c (limited to 'core/src') diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index 1a542bc7c..b93b29bb0 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -280,6 +280,7 @@ tb_int_t xm_winos_registry_values(lua_State *lua); tb_int_t xm_winos_short_path(lua_State *lua); tb_int_t xm_winos_processes(lua_State* lua); tb_int_t xm_winos_set_error_mode(lua_State *lua); +tb_int_t xm_winos_file_signature(lua_State *lua); #endif // the utf8 functions @@ -487,6 +488,7 @@ static luaL_Reg const g_winos_functions[] = { { "short_path", xm_winos_short_path }, { "processes", xm_winos_processes }, { "set_error_mode", xm_winos_set_error_mode }, + { "file_signature", xm_winos_file_signature }, { tb_null, tb_null }, }; #endif diff --git a/core/src/xmake/winos/file_signature.c b/core/src/xmake/winos/file_signature.c new file mode 100644 index 000000000..8df13f4f7 --- /dev/null +++ b/core/src/xmake/winos/file_signature.c @@ -0,0 +1,244 @@ +/*!A cross-platform build utility based on Lua + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Copyright (C) 2015-present, Xmake Open Source Community. + * + * @author ruki + * @file file_signature.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "file_signature" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" +#include +#include +#include +#include + +/* ////////////////////////////////////////////////////////////////////////////////////// + * types + */ +/// the file signature info type +typedef struct __tb_file_signature_info_t +{ + /// is the file digitally signed? + tb_bool_t is_signed; + + /// is the signature valid and trusted by the OS? + tb_bool_t is_trusted; + + /// the name of the signer (e.g., "Microsoft Corporation") + /// tbox uses UTF-8 by default for tb_char_t + tb_char_t signer_name[256]; + +}tb_file_signature_info_t; + +/* ////////////////////////////////////////////////////////////////////////////////////// + * private implementation + */ +static tb_wchar_t* tb_path_to_wchar(tb_char_t const* path, tb_wchar_t* buffer, tb_size_t size) +{ + // check + tb_assert_and_check_return_val(path && buffer && size, tb_null); + + // convert + if (MultiByteToWideChar(CP_UTF8, 0, path, -1, buffer, (int)size) > 0) + return buffer; + + return tb_null; +} + +static tb_bool_t tb_file_get_signature_info(tb_char_t const* filepath, tb_file_signature_info_t* info) +{ + // check + tb_assert_and_check_return_val(filepath && info, tb_false); + + // init info + tb_memset(info, 0, sizeof(tb_file_signature_info_t)); + + // convert path + tb_wchar_t wide_path[TB_PATH_MAXN]; + if (!tb_path_to_wchar(filepath, wide_path, TB_PATH_MAXN)) return tb_false; + + // init file info + WINTRUST_FILE_INFO file_data = {0}; + file_data.cbStruct = sizeof(file_data); + file_data.pcwszFilePath = wide_path; + file_data.hFile = NULL; + file_data.pgKnownSubject = NULL; + + // init trust data + WINTRUST_DATA trust_data = {0}; + trust_data.cbStruct = sizeof(trust_data); + trust_data.dwUIChoice = WTD_UI_NONE; + trust_data.fdwRevocationChecks = WTD_REVOKE_NONE; + trust_data.dwUnionChoice = WTD_CHOICE_FILE; + trust_data.dwStateAction = WTD_STATEACTION_VERIFY; + trust_data.hWVTStateData = NULL; + trust_data.pwszURLReference = NULL; + trust_data.dwProvFlags = WTD_SAFER_FLAG; + trust_data.dwUIContext = 0; + trust_data.pFile = &file_data; + + // verify trust + GUID guid_action = WINTRUST_ACTION_GENERIC_VERIFY_V2; + LONG status = WinVerifyTrust(NULL, &guid_action, &trust_data); + + // clean up + trust_data.dwStateAction = WTD_STATEACTION_CLOSE; + WinVerifyTrust(NULL, &guid_action, &trust_data); + + // check status + if (status == ERROR_SUCCESS) + { + info->is_signed = tb_true; + info->is_trusted = tb_true; + } + else if (status == TRUST_E_NOSIGNATURE) + { + return tb_true; + } + else if (status == TRUST_E_EXPLICIT_DISTRUST || status == TRUST_E_SUBJECT_NOT_TRUSTED) + { + info->is_signed = tb_true; + info->is_trusted = tb_false; + } + else + { + return tb_false; + } + + // extract signer name + if (info->is_signed) + { + HCERTSTORE hStore = NULL; + HCRYPTMSG hMsg = NULL; + DWORD dwEncoding = 0; + DWORD dwContentType = 0; + DWORD dwFormatType = 0; + PCMSG_SIGNER_INFO pSignerInfo = NULL; + PCCERT_CONTEXT pCertContext = NULL; + BOOL bResult = FALSE; + + bResult = CryptQueryObject(CERT_QUERY_OBJECT_FILE, + wide_path, + CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED, + CERT_QUERY_FORMAT_FLAG_BINARY, + 0, + &dwEncoding, + &dwContentType, + &dwFormatType, + &hStore, + &hMsg, + NULL); + + if (bResult) + { + DWORD cbSignerInfo = 0; + if (CryptMsgGetParam(hMsg, CMSG_SIGNER_INFO_PARAM, 0, NULL, &cbSignerInfo)) + { + pSignerInfo = (PCMSG_SIGNER_INFO)tb_malloc(cbSignerInfo); + if (pSignerInfo) + { + if (CryptMsgGetParam(hMsg, CMSG_SIGNER_INFO_PARAM, 0, (void*)pSignerInfo, &cbSignerInfo)) + { + CERT_INFO certInfo; + certInfo.Issuer = pSignerInfo->Issuer; + certInfo.SerialNumber = pSignerInfo->SerialNumber; + + pCertContext = CertFindCertificateInStore(hStore, + (X509_ASN_ENCODING | PKCS_7_ASN_ENCODING), + 0, + CERT_FIND_SUBJECT_CERT, + (PVOID)&certInfo, + NULL); + + if (pCertContext) + { + tb_wchar_t wName[256] = {0}; + if (CertGetNameStringW(pCertContext, + CERT_NAME_SIMPLE_DISPLAY_TYPE, + 0, + NULL, + wName, + 256)) + { + WideCharToMultiByte(CP_UTF8, 0, wName, -1, info->signer_name, sizeof(info->signer_name), NULL, NULL); + } + CertFreeCertificateContext(pCertContext); + } + } + tb_free(pSignerInfo); + } + } + } + + if (hStore) CertCloseStore(hStore, 0); + if (hMsg) CryptMsgClose(hMsg); + } + + return tb_true; +} + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ + +/* get the file signature info + * + * local info = winos.file_signature(filepath) + * { + * is_signed = true, + * is_trusted = true, + * signer_name = "Microsoft Corporation" + * } + */ +tb_int_t xm_winos_file_signature(lua_State *lua) { + + // check + tb_assert_and_check_return_val(lua, 0); + + // get the arguments + tb_char_t const *filepath = luaL_checkstring(lua, 1); + tb_check_return_val(filepath, 0); + + // get signature info + tb_file_signature_info_t info = {0}; + if (tb_file_get_signature_info(filepath, &info)) { + lua_newtable(lua); + lua_pushstring(lua, "is_signed"); + lua_pushboolean(lua, info.is_signed); + lua_settable(lua, -3); + + lua_pushstring(lua, "is_trusted"); + lua_pushboolean(lua, info.is_trusted); + lua_settable(lua, -3); + + if (info.is_signed) { + lua_pushstring(lua, "signer_name"); + lua_pushstring(lua, info.signer_name); + lua_settable(lua, -3); + } + return 1; + } + return 0; +} -- cgit v1.3.1 From 1aa5abae9c4b86715c48ac5137d6411c6517e283 Mon Sep 17 00:00:00 2001 From: Saikari Date: Sun, 15 Feb 2026 20:32:34 +0300 Subject: retry --- core/src/cli/xmake.lua | 2 +- core/xmake.lua | 2 +- xmake/core/sandbox/modules/winos.lua | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'core/src') diff --git a/core/src/cli/xmake.lua b/core/src/cli/xmake.lua index 2e4b1aea9..98e86b128 100644 --- a/core/src/cli/xmake.lua +++ b/core/src/cli/xmake.lua @@ -29,7 +29,7 @@ target("cli") -- add links if is_plat("windows") then - add_syslinks("ws2_32", "advapi32", "shell32") + add_syslinks("ws2_32", "advapi32", "shell32", "wintrust", "crypt32") add_ldflags("/export:malloc", "/export:free", "/export:memmove") elseif is_plat("android") then add_syslinks("m", "c") diff --git a/core/xmake.lua b/core/xmake.lua index f9e387ad5..114f8bbdb 100644 --- a/core/xmake.lua +++ b/core/xmake.lua @@ -41,7 +41,7 @@ end]] -- for the windows platform (msvc) if is_plat("windows") then set_runtimes("MT") - add_links("kernel32", "user32", "gdi32") + add_links("kernel32", "user32", "gdi32", "wintrust", "crypt32") end -- for mode coverage diff --git a/xmake/core/sandbox/modules/winos.lua b/xmake/core/sandbox/modules/winos.lua index 2ed01245d..65603897b 100644 --- a/xmake/core/sandbox/modules/winos.lua +++ b/xmake/core/sandbox/modules/winos.lua @@ -34,6 +34,7 @@ sandbox_winos.console_output_cp = winos.console_output_cp sandbox_winos.logical_drives = winos.logical_drives sandbox_winos.cmdargv = winos.cmdargv sandbox_winos.processes = winos.processes +sandbox_winos.file_signature = winos.file_signature sandbox_winos.inherit_handles_safely = winos.inherit_handles_safely sandbox_winos.set_error_mode = winos.set_error_mode -- cgit v1.3.1 From a8a2c629923dd5143297d2acd64b11eb589e94cc Mon Sep 17 00:00:00 2001 From: Saikari Date: Sun, 15 Feb 2026 20:58:57 +0300 Subject: retry MinGW --- core/src/cli/xmake.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'core/src') diff --git a/core/src/cli/xmake.lua b/core/src/cli/xmake.lua index 98e86b128..e239776c6 100644 --- a/core/src/cli/xmake.lua +++ b/core/src/cli/xmake.lua @@ -36,6 +36,7 @@ target("cli") elseif is_plat("macosx") and is_config("runtime", "luajit") then add_ldflags("-all_load", "-pagezero_size 10000", "-image_base 100000000") elseif is_plat("mingw") then + add_syslinks("wintrust", "crypt32") add_ldflags("-static-libgcc", {force = true}) elseif is_plat("haiku") then add_syslinks("pthread", "network", "m", "c") -- cgit v1.3.1 From 8d8bceff498ab535dd35db3ad9616d185bd5f909 Mon Sep 17 00:00:00 2001 From: Saikari Date: Sun, 15 Feb 2026 21:16:22 +0300 Subject: retry for mingw --- core/src/cli/xmake.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/src') diff --git a/core/src/cli/xmake.sh b/core/src/cli/xmake.sh index 12fffe1af..6ae33ef16 100755 --- a/core/src/cli/xmake.sh +++ b/core/src/cli/xmake.sh @@ -19,7 +19,7 @@ target "cli" if is_plat "macosx" && is_config "runtime" "luajit"; then add_ldflags "-all_load" "-pagezero_size 10000" "-image_base 100000000" elif is_plat "mingw"; then - add_ldflags "-static-libgcc" + add_ldflags "-static-libgcc" "-lwintrust" "-lcrypt32" fi # add install files -- cgit v1.3.1 From b82ccd6f714b59c4dd518d7dc2b07558a72d7a50 Mon Sep 17 00:00:00 2001 From: Saikari Date: Sun, 15 Feb 2026 21:26:52 +0300 Subject: Clear --- core/src/cli/xmake.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'core/src') diff --git a/core/src/cli/xmake.lua b/core/src/cli/xmake.lua index e239776c6..98e86b128 100644 --- a/core/src/cli/xmake.lua +++ b/core/src/cli/xmake.lua @@ -36,7 +36,6 @@ target("cli") elseif is_plat("macosx") and is_config("runtime", "luajit") then add_ldflags("-all_load", "-pagezero_size 10000", "-image_base 100000000") elseif is_plat("mingw") then - add_syslinks("wintrust", "crypt32") add_ldflags("-static-libgcc", {force = true}) elseif is_plat("haiku") then add_syslinks("pthread", "network", "m", "c") -- cgit v1.3.1 From 86b1f8b1211116c718c789146033f70cd14a0c65 Mon Sep 17 00:00:00 2001 From: Saikari Date: Mon, 16 Feb 2026 19:18:02 +0300 Subject: try wrap to style --- core/src/xmake/winos/file_signature.c | 45 +++++++++++------------------------ 1 file changed, 14 insertions(+), 31 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/winos/file_signature.c b/core/src/xmake/winos/file_signature.c index 8df13f4f7..3c79d78d4 100644 --- a/core/src/xmake/winos/file_signature.c +++ b/core/src/xmake/winos/file_signature.c @@ -38,8 +38,7 @@ * types */ /// the file signature info type -typedef struct __tb_file_signature_info_t -{ +typedef struct __tb_file_signature_info_t { /// is the file digitally signed? tb_bool_t is_signed; @@ -55,8 +54,7 @@ typedef struct __tb_file_signature_info_t /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static tb_wchar_t* tb_path_to_wchar(tb_char_t const* path, tb_wchar_t* buffer, tb_size_t size) -{ +static tb_wchar_t* tb_path_to_wchar(tb_char_t const* path, tb_wchar_t* buffer, tb_size_t size) { // check tb_assert_and_check_return_val(path && buffer && size, tb_null); @@ -67,8 +65,7 @@ static tb_wchar_t* tb_path_to_wchar(tb_char_t const* path, tb_wchar_t* buffer, t return tb_null; } -static tb_bool_t tb_file_get_signature_info(tb_char_t const* filepath, tb_file_signature_info_t* info) -{ +static tb_bool_t tb_file_get_signature_info(tb_char_t const* filepath, tb_file_signature_info_t* info) { // check tb_assert_and_check_return_val(filepath && info, tb_false); @@ -108,28 +105,20 @@ static tb_bool_t tb_file_get_signature_info(tb_char_t const* filepath, tb_file_s WinVerifyTrust(NULL, &guid_action, &trust_data); // check status - if (status == ERROR_SUCCESS) - { + if (status == ERROR_SUCCESS) { info->is_signed = tb_true; info->is_trusted = tb_true; - } - else if (status == TRUST_E_NOSIGNATURE) - { + } else if (status == TRUST_E_NOSIGNATURE) { return tb_true; - } - else if (status == TRUST_E_EXPLICIT_DISTRUST || status == TRUST_E_SUBJECT_NOT_TRUSTED) - { + } else if (status == TRUST_E_EXPLICIT_DISTRUST || status == TRUST_E_SUBJECT_NOT_TRUSTED) { info->is_signed = tb_true; info->is_trusted = tb_false; - } - else - { + } else { return tb_false; } // extract signer name - if (info->is_signed) - { + if (info->is_signed) { HCERTSTORE hStore = NULL; HCRYPTMSG hMsg = NULL; DWORD dwEncoding = 0; @@ -151,16 +140,12 @@ static tb_bool_t tb_file_get_signature_info(tb_char_t const* filepath, tb_file_s &hMsg, NULL); - if (bResult) - { + if (bResult) { DWORD cbSignerInfo = 0; - if (CryptMsgGetParam(hMsg, CMSG_SIGNER_INFO_PARAM, 0, NULL, &cbSignerInfo)) - { + if (CryptMsgGetParam(hMsg, CMSG_SIGNER_INFO_PARAM, 0, NULL, &cbSignerInfo)) { pSignerInfo = (PCMSG_SIGNER_INFO)tb_malloc(cbSignerInfo); - if (pSignerInfo) - { - if (CryptMsgGetParam(hMsg, CMSG_SIGNER_INFO_PARAM, 0, (void*)pSignerInfo, &cbSignerInfo)) - { + if (pSignerInfo) { + if (CryptMsgGetParam(hMsg, CMSG_SIGNER_INFO_PARAM, 0, (void*)pSignerInfo, &cbSignerInfo)) { CERT_INFO certInfo; certInfo.Issuer = pSignerInfo->Issuer; certInfo.SerialNumber = pSignerInfo->SerialNumber; @@ -172,16 +157,14 @@ static tb_bool_t tb_file_get_signature_info(tb_char_t const* filepath, tb_file_s (PVOID)&certInfo, NULL); - if (pCertContext) - { + if (pCertContext) { tb_wchar_t wName[256] = {0}; if (CertGetNameStringW(pCertContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, NULL, wName, - 256)) - { + 256)) { WideCharToMultiByte(CP_UTF8, 0, wName, -1, info->signer_name, sizeof(info->signer_name), NULL, NULL); } CertFreeCertificateContext(pCertContext); -- cgit v1.3.1 From 994c838e48bfabace4b6deda4d5dc51ee0e101a0 Mon Sep 17 00:00:00 2001 From: Saikari Date: Tue, 17 Feb 2026 22:55:54 +0300 Subject: todo --- core/src/xmake/winos/file_signature.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/winos/file_signature.c b/core/src/xmake/winos/file_signature.c index 3c79d78d4..d9d262544 100644 --- a/core/src/xmake/winos/file_signature.c +++ b/core/src/xmake/winos/file_signature.c @@ -37,19 +37,19 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * types */ -/// the file signature info type +// the file signature info type typedef struct __tb_file_signature_info_t { - /// is the file digitally signed? + // is the file digitally signed? tb_bool_t is_signed; - /// is the signature valid and trusted by the OS? + // is the signature valid and trusted by the OS? tb_bool_t is_trusted; - /// the name of the signer (e.g., "Microsoft Corporation") - /// tbox uses UTF-8 by default for tb_char_t + /* the name of the signer (e.g., "Microsoft Corporation") + tbox uses UTF-8 by default for tb_char_t*/ tb_char_t signer_name[256]; -}tb_file_signature_info_t; +} tb_file_signature_info_t; /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation @@ -74,7 +74,7 @@ static tb_bool_t tb_file_get_signature_info(tb_char_t const* filepath, tb_file_s // convert path tb_wchar_t wide_path[TB_PATH_MAXN]; - if (!tb_path_to_wchar(filepath, wide_path, TB_PATH_MAXN)) return tb_false; + if (!tb_path_absolute_w(filepath, wide_path, TB_PATH_MAXN)) return tb_false; // init file info WINTRUST_FILE_INFO file_data = {0}; @@ -87,7 +87,7 @@ static tb_bool_t tb_file_get_signature_info(tb_char_t const* filepath, tb_file_s WINTRUST_DATA trust_data = {0}; trust_data.cbStruct = sizeof(trust_data); trust_data.dwUIChoice = WTD_UI_NONE; - trust_data.fdwRevocationChecks = WTD_REVOKE_NONE; + trust_data.fdwRevocationChecks = WTD_REVOKE_WHOLECHAIN; trust_data.dwUnionChoice = WTD_CHOICE_FILE; trust_data.dwStateAction = WTD_STATEACTION_VERIFY; trust_data.hWVTStateData = NULL; -- cgit v1.3.1 From 387e1c258a5c4bef446b6d18fcffd93cc25c1543 Mon Sep 17 00:00:00 2001 From: Saikari Date: Tue, 17 Feb 2026 22:57:47 +0300 Subject: tb_wtoa --- core/src/xmake/winos/file_signature.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/src') diff --git a/core/src/xmake/winos/file_signature.c b/core/src/xmake/winos/file_signature.c index d9d262544..e16cb4949 100644 --- a/core/src/xmake/winos/file_signature.c +++ b/core/src/xmake/winos/file_signature.c @@ -165,7 +165,7 @@ static tb_bool_t tb_file_get_signature_info(tb_char_t const* filepath, tb_file_s NULL, wName, 256)) { - WideCharToMultiByte(CP_UTF8, 0, wName, -1, info->signer_name, sizeof(info->signer_name), NULL, NULL); + tb_wtoa(info->signer_name, wName, sizeof(info->signer_name)); } CertFreeCertificateContext(pCertContext); } -- cgit v1.3.1 From 97a4ee37a0057c670ba09003dc67ed50bc35fae4 Mon Sep 17 00:00:00 2001 From: Saikari Date: Fri, 20 Feb 2026 17:58:04 +0300 Subject: resolve gemini --- core/src/xmake/winos/file_signature.c | 10 ---------- xmake/modules/detect/tools/find_gcc.lua | 16 ++-------------- 2 files changed, 2 insertions(+), 24 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/winos/file_signature.c b/core/src/xmake/winos/file_signature.c index e16cb4949..2efa8bd8c 100644 --- a/core/src/xmake/winos/file_signature.c +++ b/core/src/xmake/winos/file_signature.c @@ -54,16 +54,6 @@ typedef struct __tb_file_signature_info_t { /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static tb_wchar_t* tb_path_to_wchar(tb_char_t const* path, tb_wchar_t* buffer, tb_size_t size) { - // check - tb_assert_and_check_return_val(path && buffer && size, tb_null); - - // convert - if (MultiByteToWideChar(CP_UTF8, 0, path, -1, buffer, (int)size) > 0) - return buffer; - - return tb_null; -} static tb_bool_t tb_file_get_signature_info(tb_char_t const* filepath, tb_file_signature_info_t* info) { // check diff --git a/xmake/modules/detect/tools/find_gcc.lua b/xmake/modules/detect/tools/find_gcc.lua index 83ee0fe59..d658ca1ff 100644 --- a/xmake/modules/detect/tools/find_gcc.lua +++ b/xmake/modules/detect/tools/find_gcc.lua @@ -44,20 +44,8 @@ end -- @see https://github.com/xmake-io/xmake/issues/5629 function _check_gcc_on_windows(program, opt) opt = opt or {} - if path.is_absolute(program) then - if check_gcc_gigabyte(program) then - raise("gcc.exe signed by GIGA-BYTE is not allowed!") - end - else - local paths = path.splitenv(vformat("$(env PATH)")) - if paths then - for _, p in ipairs(paths) do - local prog = path.join(p, program) - if os.isfile(prog) and check_gcc_gigabyte(prog) then - raise("gcc.exe signed by GIGA-BYTE is not allowed!") - end - end - end + if check_gcc_gigabyte(program) then + raise("gcc.exe signed by GIGA-BYTE is not allowed!") end return os.runv(program, {"--version"}, {envs = opt.envs, shell = opt.shell}) end -- cgit v1.3.1 From b59a11005353e771c35d001991ad106d7cb57684 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 20 Feb 2026 23:04:21 +0800 Subject: Update file_signature.c --- core/src/xmake/winos/file_signature.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/winos/file_signature.c b/core/src/xmake/winos/file_signature.c index 2efa8bd8c..3e617294c 100644 --- a/core/src/xmake/winos/file_signature.c +++ b/core/src/xmake/winos/file_signature.c @@ -37,6 +37,7 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * types */ + // the file signature info type typedef struct __tb_file_signature_info_t { // is the file digitally signed? @@ -46,9 +47,9 @@ typedef struct __tb_file_signature_info_t { tb_bool_t is_trusted; /* the name of the signer (e.g., "Microsoft Corporation") - tbox uses UTF-8 by default for tb_char_t*/ + tbox uses UTF-8 by default for tb_char_t + */ tb_char_t signer_name[256]; - } tb_file_signature_info_t; /* ////////////////////////////////////////////////////////////////////////////////////// @@ -56,7 +57,6 @@ typedef struct __tb_file_signature_info_t { */ static tb_bool_t tb_file_get_signature_info(tb_char_t const* filepath, tb_file_signature_info_t* info) { - // check tb_assert_and_check_return_val(filepath && info, tb_false); // init info @@ -64,8 +64,10 @@ static tb_bool_t tb_file_get_signature_info(tb_char_t const* filepath, tb_file_s // convert path tb_wchar_t wide_path[TB_PATH_MAXN]; - if (!tb_path_absolute_w(filepath, wide_path, TB_PATH_MAXN)) return tb_false; - + if (!tb_path_absolute_w(filepath, wide_path, TB_PATH_MAXN)) { + return tb_false; + } + // init file info WINTRUST_FILE_INFO file_data = {0}; file_data.cbStruct = sizeof(file_data); @@ -186,8 +188,6 @@ static tb_bool_t tb_file_get_signature_info(tb_char_t const* filepath, tb_file_s * } */ tb_int_t xm_winos_file_signature(lua_State *lua) { - - // check tb_assert_and_check_return_val(lua, 0); // get the arguments -- cgit v1.3.1 From 733bfe40bb7a210c1d291607ee118b957fe09c29 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 23 Feb 2026 23:06:38 +0800 Subject: update tbox to fix start process on win7 --- core/src/tbox/tbox | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/src') diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox index de475fef0..d0138aad7 160000 --- a/core/src/tbox/tbox +++ b/core/src/tbox/tbox @@ -1 +1 @@ -Subproject commit de475fef05346a7603efea54d77afead7a16daca +Subproject commit d0138aad74d1dda1fffbee2f6fc0a8f869d8481c -- cgit v1.3.1