Skip to content

Instantly share code, notes, and snippets.

@Ayrx
Ayrx / IntegerArrayType.java
Created August 6, 2013 12:23
A custom UserType that enables Hibernate to map a Java integer array to a PostgreSQL integer array.
public class IntegerArrayType implements UserType {
protected static final int SQLTYPE = java.sql.Types.ARRAY;
@Override
public Object nullSafeGet(final ResultSet rs, final String[] names, final SessionImplementor sessionImplementor, final Object owner) throws HibernateException, SQLException {
Array array = rs.getArray(names[0]);
Integer[] javaArray = (Integer[]) array.getArray();
return ArrayUtils.toPrimitive(javaArray);
}
@Ayrx
Ayrx / safeLongToInt.java
Created August 20, 2013 13:53
A function to safely cast a long to an int without relying on any external libraries. From the brilliant Jon Skeet @ http://stackoverflow.com/questions/1590831/safely-casting-long-to-int-in-java
public static int safeLongToInt(long l) {
if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
throw new IllegalArgumentException
(l + " cannot be cast to int without changing its value.");
}
return (int) l;
}
@Ayrx
Ayrx / getenvaddr.c
Created August 28, 2013 05:49
A simple piece of C code to print out the memory address of a specific environmental variable.
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
char *addr;
if (argc < 2) {
printf("Usage:\n%s <environment variable name>\n", argv[0]);
exit(0);
}
@Ayrx
Ayrx / case_sensitive_path.py
Created September 12, 2013 11:51
A code snippet to find the case sensitive version of path name on the system given a case insensitive version.
import os
def get_case_sensitive_pathname(path, top):
for root, dirs, files in os.walk(top):
for d in dirs:
if os.path.join(root, d).lower() == path.lower():
return os.path.join(root, d)
for f in files:
if os.path.join(root, f).lower() == path.lower():
return os.path.join(root, f)
@Ayrx
Ayrx / enum.py
Created October 10, 2013 03:17
Code snippet for using enum in Python 2. http://stackoverflow.com/a/1695250/1170681
def enum(**enums):
return type('Enum', (), enums)
@Ayrx
Ayrx / aslr_dep.py
Created October 11, 2013 14:16
Script to check if a DLL has been compiled with ASLR and DEP support. Inspired by http://security.stackexchange.com/questions/43681/how-can-i-detect-or-inventory-all-dlls-that-dont-use-aslr
import argparse
import os
import pefile
class DllCharacteristics():
def __init__(self):
self.IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE = False
self.IMAGE_DLLCHARACTERISTICS_WDM_DRIVER = False
self.IMAGE_DLLCHARACTERISTICS_NO_BIND = False
@Ayrx
Ayrx / constant_compare.py
Created November 29, 2013 11:53
Function for constant time string comparison.
def is_equal(a, b):
if len(a) != len(b):
return False
result = 0
for x, y in zip(a, b):
result |= x ^ y
return result == 0
@Ayrx
Ayrx / memdump.py
Created April 6, 2014 05:53 — forked from ntrrgc/memdump.py
#!/usr/bin/env python
from __future__ import print_function
import sys
import os
import re
import ctypes
import argparse
ulseek = ctypes.cdll['libc.so.6'].lseek
ulseek.restype = ctypes.c_uint64
@Ayrx
Ayrx / foo.c
Last active March 26, 2019 03:27
Frida Stalker Crash
#include <stdio.h>
#include <unistd.h>
int main() {
while (1) {
printf("hello\n");
sleep(1);
}
}
@Ayrx
Ayrx / repro.js
Created April 23, 2020 04:30
Frida Bug?
var m = "python2.7";
var ex = "PyTraceBack_Type";
var module = Process.getModuleByName(m)
console.log(JSON.stringify(module));
for (var e of module.enumerateExports()) {
if (e.name == ex) {
console.log(JSON.stringify(e));
}