Skip to content

Instantly share code, notes, and snippets.

View abiusx's full-sized avatar

AbiusX abiusx

View GitHub Profile
@abiusx
abiusx / zval_id.php
Created April 25, 2016 16:21
Provides a unique identifier for each zval. Same zvals should have same identifier.
<?php
/**
* This is a hacky zval_id implementation.
* It tries to be as fast as possible,
* and can only detect unique arrays, leaving them
* modified
* When in doubt, assumes it's a new zval!
* @param mixed &$zval
* @return integer
*/
@abiusx
abiusx / is_ref.php
Created April 25, 2016 16:22
An implementation of is_ref in PHP
<?php
/**
* This is a hacky is_ref function.
* Determines whether a variable is a reference or not
* by using var_dump on its symbol table and
* checking whether it has '&' before its value or not.
* @param array $defined_vars should send get_defined_vars() to this. enforced.
* @param mixed $var any variable, should be a variable and not a expression
* @return boolean
*/
@abiusx
abiusx / is_ref.phpx
Created April 25, 2016 16:23
An implementation of is_ref for PHP in C (for extensions)
ZEND_BEGIN_ARG_INFO_EX(phpx_byref_arginfo,
1 /*pass_rest_by_reference*/,
0/*return_reference*/,
1/*required_num_args*/)
ZEND_ARG_PASS_INFO(1/*by_ref*/)
ZEND_END_ARG_INFO();
PHP_FUNCTION(is_ref)
{
zval *z;
@abiusx
abiusx / zval_id.phpx
Created April 25, 2016 16:24
An implementation of zval_id in C for PHP extensions
ZEND_BEGIN_ARG_INFO_EX(phpx_byref_arginfo,
1 /*pass_rest_by_reference*/,
0/*return_reference*/,
1/*required_num_args*/)
ZEND_ARG_PASS_INFO(1/*by_ref*/)
ZEND_END_ARG_INFO();
PHP_FUNCTION(zval_id)
{
//computes the address of first zval sent to it,
@abiusx
abiusx / typed_php.php
Last active August 30, 2016 16:38
Type Checked PHP (methods, functions are not yet supported)
<?php
class TypedPHPException extends Exception {
function __construct($msg,$file,$line)
{
parent::__construct($msg);
$this->file=$file;
$this->line=$line;
}
}
@abiusx
abiusx / stdlib.php
Last active April 17, 2017 05:10
Standard PHP Library
<?php
function grep_r($str,$find)
{
return substr($str,$r=strpos($str,$find)+strlen($find),strpos($str,PHP_EOL,$r)-1-$r);
}
function curl($url,$postparams=[],$headers=[],$additional_opts=[])
{
$opts=[
CURLOPT_COOKIEJAR => 'stdlib.cookie',
CURLOPT_COOKIEFILE => 'stdlib.cookie',
@abiusx
abiusx / honeypot_ls.sh
Last active February 9, 2018 23:27
Honepyt ls
#!/bin/bash
LOGFILE="/tmp/lslog"
ORIGINAL_LS="/bin/LS"
#chmod 777 "${LOGFILE}"
WHOAMI=$(whoami)
TTY=$(tty)
CWD="$(pwd)"
PARENT_COMMAND="$(ps -o comm= $PPID)"
@abiusx
abiusx / latency.txt
Created February 20, 2018 16:19 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@abiusx
abiusx / deepcopy.php
Last active August 5, 2018 00:36
Deep Copy an array (or variable) in PHP
<?php
/**
* PHP Deep Copy
* @version 3.1.1:
* _zval_id_accurate now receives its zval pool instead of having it static.
* if is_ref and zval_id are available
* in PHP core, we will use them.
* otherwise, we will use PHP based implementations of these
* functions.
*
@abiusx
abiusx / docker-php.sh
Last active September 16, 2018 04:19
Quick PHP-Apache Docker environment
#!/bin/sh
if [[ $# -lt 1 ]]; then
echo "Usage: $0 NAME [PORT]";
exit 1
fi
NAME=$1
PORT=${2:-80}
if [ "${PWD##*/}" != "${NAME}" ]; then
mkdir -p "${NAME}"
cd "${NAME}"