Skip to content

Instantly share code, notes, and snippets.

@tmr232
tmr232 / FunctionBinding.js
Created November 16, 2012 14:27
Javascript function binding crap
// Define a class with a method
function MyClass(value) {
this.value = value;
this.function = function() {
return this.value;
};
}
// Instanciate the class
my_class = new MyClass("my value");
@tmr232
tmr232 / loop_label.py
Created March 4, 2014 19:42
Loop Labels - Python hack for breaking out of nested loops.
class LoopLabel(object):
def __init__(self):
super(LoopLabel, self).__init__()
class MyLoopLabel(Exception): pass
self._label_exception = MyLoopLabel
def __enter__(self):
return self._label_exception
@tmr232
tmr232 / defaults.py
Created March 4, 2014 19:44
Decorator to enable changing the values of default arguments in python functions.
from functools import wraps
class Default(object):
def __init__(self, name):
super(Default, self).__init__()
self.name = name
def set_defaults(defaults):
@tmr232
tmr232 / bitmapper.html
Created November 8, 2014 14:57
View a file as an image
<html>
<body>
<style>
#byte_content {
margin: 5px 0;
max-height: 100px;
overflow-y: auto;
overflow-x: hidden;
}
#byte_range { margin-top: 5px; }
def _remove_visual_c_ref(self, manifest_file):
try:
# Remove references to the Visual C runtime, so they will
# fall through to the Visual C dependency of Python.exe.
# This way, when installed for a restricted user (e.g.
# runtimes are not in WinSxS folder, but in Python's own
# folder), the runtimes do not need to be in every folder
# with .pyd's.
# Returns either the filename of the modified manifest or
# None if no manifest should be embedded.
@tmr232
tmr232 / settrace.py
Last active August 29, 2015 14:11
sys.settrace usage sample
import sys
import inspect
class Tracer(object):
def __init__(self):
self._indentation_level = 0
@property
def indentation_level(self):
@tmr232
tmr232 / construct.py
Last active August 29, 2015 14:14
New Construct Syntax
import operator
import construct
class ConstructGetter(object):
def __init__(self):
self._index = 0
def __getattr__(self, name):
@tmr232
tmr232 / abbreviate.py
Created March 23, 2015 09:16
Python WTF - Attribute Abbreviation
"""Attribute Abbreviation.
This file contains a metaclass that can be used to abbreviate attribute names for a class.
This is a POC made for fun.
Do yourself a favor and NEVER do this in actual code.
You've been warned.
"""
class AbbreviationError(Exception):
@tmr232
tmr232 / demo.py
Created April 2, 2015 11:30
Construct Suggestion - Ordered Keyword Arguments
from easy_construct import cs, struct, Container
MyStruct = struct("MyStruct",
_0=cs.Magic("EZConstruct"),
variable=cs.UBInt32,
another_var=cs.UBInt16,
_1=cs.Padding(0x4),
array=cs.Bytes(13),
_2=cs.Magic("MagicEndsHere"),
)
@tmr232
tmr232 / bitmapper.py
Last active January 9, 2021 00:16
Bitmapper - Visual Reverse Engineering
"""Bitmapper
Usage:
bitmapper.py <input> <output> [<width>]
Options:
-h --help Show this screen.
<input> The input binary file.
<output> The output bitmap.
<width> The width of the bitmap in pixels. Optional.