diff --git a/CMakeLists.txt b/CMakeLists.txt index 1201ddcb..8cd13e98 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ set(BLAKE3_SIMD_X86_INTRINSICS ON) include(FetchContent) FetchContent_Declare( googletest - URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip + URL https://github.com/google/googletest/archive/refs/tags/v1.15.2.zip ) # For Windows: Prevent overriding the parent project's compiler/linker settings diff --git a/src/_tst.net/Extensions.cs b/src/_tst.net/Extensions.cs index 62224362..0bbe7868 100644 --- a/src/_tst.net/Extensions.cs +++ b/src/_tst.net/Extensions.cs @@ -11,11 +11,11 @@ namespace _tst.net; public static class Extensions { - private const string EscapeSymbol = "\""; + private const char EscapeSymbol = '"'; public static void AddParameter(this StringBuilder builder, string parameter) { - if (parameter.Contains(" ")) + if (parameter.Contains(' ')) { builder.Append(EscapeSymbol); builder.Append(parameter); @@ -26,7 +26,7 @@ public static void AddParameter(this StringBuilder builder, string parameter) builder.Append(parameter); } - builder.Append(" "); + builder.Append(' '); } internal static string GetDirectoryName(this string path) => Path.GetDirectoryName(Path.GetFullPath(path)); diff --git a/src/hc/builtin.c b/src/hc/builtin.c index 590c41f5..b55e079d 100644 --- a/src/hc/builtin.c +++ b/src/hc/builtin.c @@ -14,6 +14,10 @@ #include "encoding.h" #include "intl.h" +#ifndef _MSC_VER +#include +#endif + static apr_pool_t* builtin_pool = NULL; static hash_definition_t* builtin_hash = NULL; @@ -60,8 +64,13 @@ apr_byte_t* builtin_hash_from_string(const char* string) { // some hashes like NTLM required unicode string so convert multi byte string to unicode one if(builtin_hash->use_wide_string_) { +#ifdef _MSC_VER wchar_t* str = enc_from_ansi_to_unicode(string, builtin_pool); builtin_hash->pfn_digest_(digest, str, wcslen(str) * sizeof(wchar_t)); +#else + char16_t* str = enc_from_ansi_to_wide_chars(string, builtin_pool); + builtin_hash->pfn_digest_(digest, str, strlen(string) * sizeof(char16_t)); +#endif } else { builtin_hash->pfn_digest_(digest, string, strlen(string)); } diff --git a/src/l2h/treeutil.c b/src/l2h/treeutil.c index de8b38ae..34f50cae 100644 --- a/src/l2h/treeutil.c +++ b/src/l2h/treeutil.c @@ -115,13 +115,8 @@ static asciinode_t* build_ascii_tree_recursive(fend_node_t* t) { } char* type = bend_create_label(t, tree_pool); - size_t len = strlen(node->label); -#ifdef __STDC_WANT_SECURE_LIB__ - sprintf_s(node->label, len, "%s", type); -#else - sprintf(node->label, "%s", type); -#endif - node->lablen = len; + lib_sprintf(node->label, "%s", type); + node->lablen = strnlen(node->label, 80); return node; } diff --git a/src/pgoptimize/pgtempl/Cargo.toml b/src/pgoptimize/pgtempl/Cargo.toml index e81e2cf7..c941eddd 100644 --- a/src/pgoptimize/pgtempl/Cargo.toml +++ b/src/pgoptimize/pgtempl/Cargo.toml @@ -6,6 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = { version = "3", features = ["std", "color", "suggestions", "cargo"] } +clap = { version = "4.5.21", features = ["std", "color", "suggestions", "cargo"] } serde = { version = "1.0", features = ["derive"] } -handlebars = "4.1.3" \ No newline at end of file +handlebars = "6.2.0" \ No newline at end of file diff --git a/src/pgoptimize/pgtempl/src/main.rs b/src/pgoptimize/pgtempl/src/main.rs index 9ad925f9..14566ab9 100644 --- a/src/pgoptimize/pgtempl/src/main.rs +++ b/src/pgoptimize/pgtempl/src/main.rs @@ -1,13 +1,17 @@ -use clap::{crate_name, crate_version, App, Arg}; +use clap::Arg; use handlebars::Handlebars; use serde::Serialize; use std::process::Command; +#[macro_use] +extern crate clap; + fn main() { let app = build_cli(); let matches = app.get_matches(); - let executable = matches.value_of("exe").unwrap_or("hc"); + let default = "hc".to_string(); + let executable = matches.get_one::("exe").unwrap_or(&default); let hashes = [ "crc32", @@ -122,8 +126,9 @@ pub struct Pgo { pub hashes: Vec, } -fn build_cli() -> App<'static> { - return App::new(crate_name!()) +fn build_cli() -> clap::Command { + #![allow(non_upper_case_globals)] + command!(crate_name!()) .version(crate_version!()) .author("egoroff ") .about("PGO template tool") @@ -131,10 +136,9 @@ fn build_cli() -> App<'static> { Arg::new("exe") .long("exe") .short('e') - .takes_value(true) .help("Executable path") .required(false), - ); + ) } const TEMPLATE: &str = r###" @@ -144,52 +148,51 @@ const TEMPLATE: &str = r###" * © 2009-2024 Alexander Egorov */ -namespace _tst.net +namespace _tst.net; + +public abstract class Hash { - public abstract class Hash - { - /// - /// Gets the hash of "123" string - /// - public abstract string HashString { get; } + /// + /// Gets the hash of "123" string + /// + public abstract string HashString { get; } - public abstract string EmptyStringHash { get; } + public abstract string EmptyStringHash { get; } - /// - /// Gets the hash of "12" string - /// - public abstract string StartPartStringHash { get; } + /// + /// Gets the hash of "12" string + /// + public abstract string StartPartStringHash { get; } - /// - /// Gets the hash of "2" string - /// - public abstract string MiddlePartStringHash { get; } + /// + /// Gets the hash of "2" string + /// + public abstract string MiddlePartStringHash { get; } - /// - /// Gets the hash of "23" string - /// - public abstract string TrailPartStringHash { get; } + /// + /// Gets the hash of "23" string + /// + public abstract string TrailPartStringHash { get; } - public abstract string Algorithm { get; } + public abstract string Algorithm { get; } - public string InitialString => "123"; - } - {{#each hashes}} + public string InitialString => "123"; +} +{{#each hashes}} - public class {{ class }} : Hash - { - public override string HashString => "{{ hash123 }}"; +public class {{ class }} : Hash +{ + public override string HashString => "{{ hash123 }}"; - public override string EmptyStringHash => "{{ hash_empty }}"; + public override string EmptyStringHash => "{{ hash_empty }}"; - public override string StartPartStringHash => "{{ hash_start }}"; + public override string StartPartStringHash => "{{ hash_start }}"; - public override string MiddlePartStringHash => "{{ hash_middle }}"; + public override string MiddlePartStringHash => "{{ hash_middle }}"; - public override string TrailPartStringHash => "{{ hash_trail }}"; + public override string TrailPartStringHash => "{{ hash_trail }}"; - public override string Algorithm => "{{ algo }}"; - } - {{/each}} + public override string Algorithm => "{{ algo }}"; } +{{/each}} "###; diff --git a/src/srclib/bf.c b/src/srclib/bf.c index 03d1446f..a52f5eb1 100644 --- a/src/srclib/bf.c +++ b/src/srclib/bf.c @@ -115,8 +115,13 @@ void bf_crack_hash(const char *dict, const char *hash, const uint32_t passmin, u const char *t = "123"; const size_t max_time_msg_size = 63; if (use_wide_pass) { +#ifdef _MSC_VER wchar_t *s = enc_from_ansi_to_unicode(t, pool); pfn_digest_function(digest, s, wcslen(s) * sizeof(wchar_t)); +#else + char16_t* s = enc_from_ansi_to_wide_chars(t, pool); + pfn_digest_function(digest, s, strlen(t) * sizeof(char16_t)); +#endif } else { pfn_digest_function(digest, t, strlen(t)); } @@ -299,6 +304,7 @@ char *bf_brute_force(const uint32_t passmin, const uint32_t passmax, const char if (thd_ctx[i]->use_wide_pass_) { if (thd_ctx[i]->wide_pass_ != NULL) { + // TODO: make correct implementation on Linux pass = (unsigned char *)enc_from_unicode_to_ansi(thd_ctx[i]->wide_pass_, pool); } } else { diff --git a/src/srclib/encoding.c b/src/srclib/encoding.c index a36eb813..a279b7fe 100644 --- a/src/srclib/encoding.c +++ b/src/srclib/encoding.c @@ -85,6 +85,35 @@ wchar_t *enc_from_ansi_to_unicode(const char *from, apr_pool_t *pool) { return enc_from_code_page_to_unicode(from, CP_ACP, pool); } +#ifndef _MSC_VER +/*! + * IMPORTANT: Memory allocated for result must be freed up by caller + */ +char16_t *enc_from_ansi_to_wide_chars(const char *from, apr_pool_t *pool) { + char16_t pc16 = 0; + mbstate_t state = { 0 }; + + size_t len = strlen(from); + char16_t* wide = (char16_t *)apr_pcalloc(pool, (len + 1) * sizeof(char16_t)); + + for (size_t i = 0; i < len; i++) + { + size_t rc = mbrtoc16(&pc16, &from[i], len - i + 1, &state); + if (rc == (size_t)-3) + continue; + else if (rc == (size_t) - 2) + break; + else if (rc == (size_t) - 1) + break; + else + { + wide[i] = pc16; + } + } + return wide; +} +#endif + /*! * IMPORTANT: Memory allocated for result must be freed up by caller */ diff --git a/src/srclib/encoding.h b/src/srclib/encoding.h index dd58c7d7..3530d2c4 100644 --- a/src/srclib/encoding.h +++ b/src/srclib/encoding.h @@ -35,6 +35,9 @@ typedef enum { bom_unknown = 0, bom_utf8 = 1, bom_utf16le = 2, bom_utf16be = 3, #define _UINT typedef unsigned int UINT; #endif + +#include + #endif /*! @@ -52,6 +55,13 @@ char *enc_from_ansi_to_utf8(const char *from, apr_pool_t *pool); */ wchar_t *enc_from_ansi_to_unicode(const char *from, apr_pool_t *pool); +#ifndef _MSC_VER +/*! + * IMPORTANT: Memory allocated for result must be freed up by caller + */ +char16_t *enc_from_ansi_to_wide_chars(const char *from, apr_pool_t *pool); +#endif + /*! * IMPORTANT: Memory allocated for result must be freed up by caller */