Skip to content

Commit

Permalink
Merge pull request #218 from aegoroff/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
aegoroff authored Nov 30, 2024
2 parents 64ace7f + 7579b3d commit 4b367f8
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 53 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/_tst.net/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
Expand Down
9 changes: 9 additions & 0 deletions src/hc/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#include "encoding.h"
#include "intl.h"

#ifndef _MSC_VER
#include <uchar.h>
#endif

static apr_pool_t* builtin_pool = NULL;
static hash_definition_t* builtin_hash = NULL;

Expand Down Expand Up @@ -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));
}
Expand Down
9 changes: 2 additions & 7 deletions src/l2h/treeutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/pgoptimize/pgtempl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
handlebars = "6.2.0"
83 changes: 43 additions & 40 deletions src/pgoptimize/pgtempl/src/main.rs
Original file line number Diff line number Diff line change
@@ -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::<String>("exe").unwrap_or(&default);

let hashes = [
"crc32",
Expand Down Expand Up @@ -122,19 +126,19 @@ pub struct Pgo {
pub hashes: Vec<Hash>,
}

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 <egoroff@gmail.com>")
.about("PGO template tool")
.arg(
Arg::new("exe")
.long("exe")
.short('e')
.takes_value(true)
.help("Executable path")
.required(false),
);
)
}

const TEMPLATE: &str = r###"
Expand All @@ -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
{
/// <summary>
/// Gets the hash of "123" string
/// </summary>
public abstract string HashString { get; }
/// <summary>
/// Gets the hash of "123" string
/// </summary>
public abstract string HashString { get; }
public abstract string EmptyStringHash { get; }
public abstract string EmptyStringHash { get; }
/// <summary>
/// Gets the hash of "12" string
/// </summary>
public abstract string StartPartStringHash { get; }
/// <summary>
/// Gets the hash of "12" string
/// </summary>
public abstract string StartPartStringHash { get; }
/// <summary>
/// Gets the hash of "2" string
/// </summary>
public abstract string MiddlePartStringHash { get; }
/// <summary>
/// Gets the hash of "2" string
/// </summary>
public abstract string MiddlePartStringHash { get; }
/// <summary>
/// Gets the hash of "23" string
/// </summary>
public abstract string TrailPartStringHash { get; }
/// <summary>
/// Gets the hash of "23" string
/// </summary>
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}}
"###;
6 changes: 6 additions & 0 deletions src/srclib/bf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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 {
Expand Down
29 changes: 29 additions & 0 deletions src/srclib/encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
10 changes: 10 additions & 0 deletions src/srclib/encoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <uchar.h>

#endif

/*!
Expand All @@ -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
*/
Expand Down

0 comments on commit 4b367f8

Please sign in to comment.