Skip to content

Instantly share code, notes, and snippets.

View rjzak's full-sized avatar

Richard Zak rjzak

View GitHub Profile
@rjzak
rjzak / PyUtils.cpp
Last active April 16, 2024 09:00
Convert between Python list/tuples and C++ vectors
#include <Python.h> // Must be first
#include <vector>
#include <stdexcept>
#include "PyUtils.h"
using namespace std;
// =====
// LISTS
// =====
@rjzak
rjzak / progressbar.cpp
Created May 31, 2013 20:09
A progress bar in C/C++
#include <string>
#include <iostream>
#include <cstdlib>
using namespace std;
void printProgBar( int percent );
int main(int argc, char* argv[]) {
int N = 100;
@rjzak
rjzak / randFile.c
Created July 24, 2013 14:19
Generate & store random data in a file. Designed to create a large random file to use as a key file for TrueCrypt.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char* argv[] ) {
if (argc != 3) {
printf("Error, you must provide a destination file and number of iterations\n");
return -1;
}
FILE *fp;
@rjzak
rjzak / pageLoadMiddleware.py
Created November 26, 2013 22:45
Use this middleware for Django to append the load time to each page. Add it to the middleware config in your settings.py file. If you wish to disable it for a given view, use the @PageLoadExempt decorator.
from django.utils.decorators import decorator_from_middleware, available_attrs
from functools import wraps
import time
class PageLoadTimerMiddleware:
def __init__(self):
self.initTime = time.clock()
self.disabled = False
def process_request(self, request):
@rjzak
rjzak / tlock.c
Last active January 1, 2016 18:49
A simple terminal locking application for Linux. Compile with: gcc -o tlock tlock.c -lpam -lpam_misc
#include <security/pam_appl.h>
#include <security/pam_misc.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
/**
* Code adapted from:
* PAM: http://www.makelinux.net/alp/084
@rjzak
rjzak / searchCollect.py
Last active March 1, 2021 21:21
Search and Collect scrapes all the Windows executables (PE files) in a Windows system and copies the files into the destination directory. This is the Python version of the code at https://github.com/IOActive/SearchAndCollect.
#!/usr/bin/python
import os, sys, hashlib, shutil
sha256 = lambda data: hashlib.sha256(data).hexdigest()
def searchAndCollect(src, dest):
print "Searching %s for .exe's, saving to %s" % (src, dest)
for dirpath, dirnames, filenames in os.walk(src):
if src in dirnames:
@rjzak
rjzak / magic.py
Last active January 2, 2016 17:39
Compare magic numbers (or the first 32 bytes of a file) with the output from the file command (which also uses magic numbers). The intention is to discover magic numbers for different file types. For example, to be able to distinguish between different MS Office document types, since libmagic just says "CDF V2 Document, Little Endian, Os" or "Zi…
#!/usr/bin/python
import sys, os, subprocess
def fileType(filePath):
return subprocess.Popen("""/usr/bin/file "%s" """ % filePath, shell=True, stdout=subprocess.PIPE).communicate()[0].split(":")[1].strip()
def idMSFile(filePath):
if os.path.isdir(filePath):
for fileInDir in os.listdir(filePath):
@rjzak
rjzak / utils.py
Created January 30, 2014 22:37
Ends and ends
import os
import random
import string
def recursiveDirectoryContents(dir):
for root, dirs, files in os.walk(dir):
for file in files:
yield os.path.join(root, file)
def randomString(length=10):
@rjzak
rjzak / ramdisk.sh
Created July 14, 2014 20:53
Make a ramdisk on Linux
#!/bin/bash
if [ $# -eq 2 ]
then
mkdir $1
mount -t tmpfs -o size=$2 tmpfs $1
else
echo "Proper use: $0 <RAMDISK_DIR> <RAMDISK_SIZE>"
echo "Example: $0 /mnt/ramdisk 4096m"
fi
@rjzak
rjzak / metascap.py
Created October 23, 2014 20:20
Python interface to Meta Scan https://www.metascan-online.com
#!/usr/bin/python
import os
import json
import time
import hashlib
import httplib
class Result: