Skip to content

Instantly share code, notes, and snippets.

#define PCRE2_STATIC 1
#define PCRE2_CODE_UNIT_WIDTH 8
#define _CRT_SECURE_NO_WARNINGS 1
/*
* Mask Visa or Mastercard PAN in buffer
*
* pattern (4\\d{5}|5[12345]\\d{4})\\d{6}(\\d{4})
* subject "____5500000000000327____4000000000000001____5500000000000327__"
@agrandville
agrandville / Get-MSIFileInformation.ps1
Created March 7, 2024 10:52
How to get MSI file information with PowerShell
# https://msendpointmgr.com/2014/08/22/how-to-get-msi-file-information-with-powershell/
#
#.\Get-MSIFileInformation.ps1 -path C:\tmp\forticlient\FortiClient.msi
#
#Name Value
#---- -----
#Manufacturer Fortinet Technologies Inc
#ProductName FortiClient
#ProductLanguage 1033
#ProductVersion 7.2.4.0972
@agrandville
agrandville / index.js
Created December 8, 2023 15:03
node crypto - sign and check with certificate
var crypto = require('crypto');
// openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 365
// remove password
// openssl rsa -in key.pem -out priv.pem
// sign
// openssl dgst -sha256 -sign priv.pem -out sha256.sign myfile.txt
// extract public key
// openssl x509 -pubkey -in cert.pem -out pub.pem -noout
// verify
@agrandville
agrandville / main.rs
Created July 6, 2022 14:20
Rust windows API PathCchCanonicalizeEx call
# Normalize UNC path
# eg. \\?\UNC\server\share\project\mysite\config.toml => \\server\share\project\mysite\config.toml
let mut psz_path_out: [u16; 260] = [0; 260];
let s = "\\\\?\\UNC\\server\\share\\project\\*mysite\\config.toml";
let mut v: Vec<u16> = s.encode_utf16().collect();
v.push(0);
let psz_path_int = PCWSTR(v.as_ptr());
if let Err(err) = PathCchCanonicalizeEx(&mut psz_path_out, psz_path_int, dw_flags as u32) {
@agrandville
agrandville / index.html
Last active March 7, 2024 11:04
non-selectable numbering of table rows
<!DOCTTYPE html>
<html>
<head>
<style>
.blob-num::before {
content: attr(data-line-number)
}
</style>
</head>
@agrandville
agrandville / FindJansson.cmake
Created April 25, 2022 09:41
Try to find the jansson libraries
# Try to find the jansson libraries
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# Copyright (C) 2022 Arnaud Grandville France <agrandville@gmail.com>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
@agrandville
agrandville / basename.c
Created April 21, 2022 12:06
windows basename
#include <windows.h>
#include <shlwapi.h>
#pragma comment(lib, "Shlwapi.lib")
LPCSTR basename(LPCSTR filename) {
return PathFindFileName(filename);
}
@agrandville
agrandville / gist:31686d50b9f755980be78bda097ff8d6
Last active October 6, 2021 09:17
download lastest local-php-security-checker binary
curl -s https://api.github.com/repos/fabpot/local-php-security-checker/releases/latest |
jq '.assets[] | select(.name | test(".*linux_amd64$")) | .browser_download_url' |
xargs curl -sLo local-php-security-checker
get_cmake_property(_variableNames VARIABLES)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
@agrandville
agrandville / gist:bfdffc0016805a6517d6f41230a6f8df
Created January 14, 2021 16:53
Reading Maven Pom xml in Python2
#!/usr/bin/env python2
from xml.etree import ElementTree
from datetime import datetime
#if len(sys.argv) != 2:
# print("\033[0;31merror: version missiong")
# exit(1)
Outputformat='xml'
OutputExtension=".xml"