Skip to content

Instantly share code, notes, and snippets.

@jiulongw
jiulongw / PromptForUserCredentials.cs
Last active August 29, 2015 14:06
Prompt user for name and password with windows cred API
private static NetworkCredential PromptForUserCredentials(string preferredUserName, Uri serverUri)
{
    Unmanaged.CREDUI_INFO uiInfo = new Unmanaged.CREDUI_INFO()
    {
        cbSize = Marshal.SizeOf(typeof(Unmanaged.CREDUI_INFO)),
        pszCaptionText = serverUri.Host,
        pszMessageText = string.Format(Resources.DeployWebResources_CredentialPromptMessage, serverUri.Host)
    };
    uint autoPackage = 0;
@jiulongw
jiulongw / GetDomainUserSID.ps1
Created September 14, 2014 20:32
Powershell: Get domain user SID
$objUser = New-Object System.Security.Principal.NTAccount("<domain>","<user name>")
$objUser.Translate([System.Security.Principal.SecurityIdentifier]).Value
@jiulongw
jiulongw / FastByteArrayCompare.cs
Created September 14, 2014 20:34
Fast Byte Array Compare
/// <summary>
/// Compare if given two byte arrays are identical.
/// </summary>
/// <param name="x">byte array to compare.</param>
/// <param name="y">byte array to compare.</param>
/// <returns>true if x and y are identical.</returns>
public unsafe static bool ByteArrayCompare(byte[] x, byte[] y)
{
if (x == null || y == null || x.Length != y.Length)
{
@jiulongw
jiulongw / FindComInterface.cs
Last active August 29, 2015 14:06
COM interface finder
foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
{
try
{
foreach (Type t in a.GetExportedTypes())
{
try
{
IntPtr pUnk = Marshal.GetIUnknownForObject(ProjectCfgObject);
@jiulongw
jiulongw / printStacktrace.js
Last active August 29, 2015 14:06
Javascript print stacktrace
function printStackTrace() {
var callstack = [];
var isCallstackPopulated = false;
try {
i.dont.exist+=0; //doesn't exist- that's the point
} catch(e) {
if (e.stack) { //Firefox
var lines = e.stack.split('\n');
for (var i=0, len=lines.length; i&lt;len; i++) {
if (lines[i].match(/^\s*[A-Za-z0-9\-_\$]+\(/)) {
@jiulongw
jiulongw / UrlNormalizer.scala
Created November 18, 2015 19:38
URL Normalizer
import java.net.URI
import java.util.regex.{Pattern, Matcher}
import scala.annotation.tailrec
object UrlNormalizer {
/**
* URI.normalize handles path normalization. Doc: http://docs.oracle.com/javase/7/docs/api/java/net/URI.html#normalize()
* e.g. /a/b/../c will become /a/c
* Fragment is also removed.
@jiulongw
jiulongw / arch-init.sh
Created October 11, 2016 04:44
Arch install scripts
# errexit on
set -e
echo Distroying /dev/sda and creating partition. Press Ctrl+C to exit
read -n1 -r -p "Press any key to continue"
sgdisk -Z --new=0:0:0 --typecode=0:8300 --new=0:0:0 --typecode=0:EF02 /dev/sda
mkfs.ext4 /dev/sda1
mkfs.ext4 /dev/sda2
@jiulongw
jiulongw / mesh.cs
Created December 10, 2016 01:46
Create mesh sample
private void CreateMesh()
{
var start = Quaternion.AngleAxis(-45, Vector3.up) * Vector3.forward * 6f;
var end = Quaternion.AngleAxis(45, Vector3.up) * Vector3.forward * 6f;
var control = Vector3.forward * 6f;
var points1 = GetPointsInCurve(start, end, control, 20);
start = Quaternion.AngleAxis(15, Vector3.right) * start;
end = Quaternion.AngleAxis(15, Vector3.right) * end;
@jiulongw
jiulongw / sss.py
Created February 27, 2017 17:02
Sample pwntool usage
# Credits to https://losfuzzys.github.io/writeup/2017/02/27/bkpctf2017-signed-shell-server/
from pwn import * # noqa
import string
import random
velf = ELF("./sss")
# this is the byte we'd need...
last_byte = velf.symbols['exec_command'] & 0xff
log.info("last byte of exec_command 0x{:x}".format(last_byte))
# curl -L goo.gl/pJHMCG | bash
sudo pacman -Syu --noconfirm
sudo pacman -S --noconfirm --needed \
calc \
firefox \
git \
gvim \
gnu-netcat \
python \