Skip to content

Instantly share code, notes, and snippets.

View iglosiggio's full-sized avatar
🍙
Rice's theorem denier

Ignacio Esteban Losiggio iglosiggio

🍙
Rice's theorem denier
View GitHub Profile
@iglosiggio
iglosiggio / emv_qrcps_encoder.js
Created January 30, 2024 00:16
EMV QRCPS Parser/Encoder
const crc_table = [
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5,
0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b,
0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x0210,
0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c,
0xf3ff, 0xe3de, 0x2462, 0x3443, 0x0420, 0x1401,
0x64e6, 0x74c7, 0x44a4, 0x5485, 0xa56a, 0xb54b,
0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6,
@iglosiggio
iglosiggio / proba-2023-2c-1p-ej6.md
Created November 3, 2023 23:55
Ejercicio 6 del primer parcial de Probabilidades y Estadística tomado durante el segundo cuatrimestre del 2023

Ejercicio 6a

  1. Dado $X \sim \mathcal{P}(\lambda)$ probar $\mathbb{E}(X) = \lambda$ $$\mathbb{E}(X) = \sum_{i=0}^\infty i \frac {\lambda^i}{i!} e^{-\lambda}$$
  2. Como vale $0$ en $i=0$ puedo decir $$\mathbb{E}(X) = \sum_{i=1}^\infty i \frac {\lambda^i}{i!} e^{-\lambda}$$
  3. Simplifico $i$ con $i!$ $$\mathbb{E}(X) = \sum_{i=1}^\infty \frac {\lambda^i}{(i-1)!} e^{-\lambda}$$
  4. Cambio de índices $$\mathbb{E}(X) = \sum_{i=0}^\infty \frac {\lambda^{i+i}}{i!} e^{-\lambda}$$
  5. Saco constantes

Lets say you want to limit access to arbitrary code execution from a regular python runtime. What do you need to limit? This is a list of examples on how that is a futile mission (unless you REALLY want to limit the power of python).

Examples

  1. 01_using_os.py: The simplest thing, just do os.spawn
  2. 02_using_subprocess.py: The os module was deprecated a loooong time ago. Why don't we use a modern library?
  3. 03_using_ctypes.py: It's obvious to any well meaning programmer that os and subprocess are hairy modules. But do you remember that ctypes exists?
  4. 04_using_mmap.py: Woah! We can create executable memory FROM INSIDE python? That sounds incredible cursed.
  5. 05_using_open.py: ... just open? How? What do you mean with "/proc/self/mem bypasses memory protections"?

References

@iglosiggio
iglosiggio / Makefile
Created November 12, 2022 04:51
Dumb (SH|J)IT in 300LOC
main: main.c lib.o
lib.o: lib.asm
nasm $< -f elf64 -o $@
clean:
rm -f lib.o main
#include "keyboard_input.h"
#include "screen.h"
static void unrecognized_scancode(uint8_t scancode);
#define TOGGLE_SHIFT_IDX 1
static void toggle_shift(uint8_t);
#define MOVE_DOWN_IDX 2
static void move_down(uint8_t);
#define MOVE_UP_IDX 3
static void move_up(uint8_t);
@iglosiggio
iglosiggio / trie.c
Last active January 9, 2022 20:15
A dumb trie implementation with addition over an arbitrary range.
#include <stdint.h>
#include <limits.h>
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
typedef uint32_t trie_key_t;
typedef float trie_value_t;
#define BRANCHING_FACTOR_LOG2 (CHAR_BIT)
@iglosiggio
iglosiggio / duplication_automata.js
Last active August 19, 2021 01:51
A finite deterministic automata that duplicates natural numbers
function duplication_automata() {
const digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
const vertices = [{type: 'start'}, {type: 'stop'}]
const edges = []
for (const digit of digits)
vertices.push({type: 'internal', digit})
for (const v of vertices) {
const add_edge = (to, match, output) =>
@iglosiggio
iglosiggio / umi.c
Last active August 19, 2020 23:09
Universal Machine Interpreter (ICFP 2006)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
struct segment {
unsigned len;
unsigned next_free_segment;
unsigned* data;
};
#--------------------- game.py
#--------------------- header.py
instrucciones = [
"You are the memory allocator: your job is to place code segments in RAM",
"Place the segments before the user loses her patience",
"Use space or right click to rotate memory segments",
"The score will increase as you optimize the space by making rectangular areas",
"When a segment is not yet optimized you can still move it",
"You get higher scores if your areas are more 'square'",
"When a memory segment is no longer needed it will be released by the GC",
@iglosiggio
iglosiggio / url-open
Last active January 24, 2020 04:58
Simple shell script that opens an http/https after querying the server for the Content-Type
#!/bin/sh
# If you want to query the server for the mime uncomment the following line
#mime="$(curl -s -I "$1" | sed '/^content-type/I{s/content-type: //I; s/;.*$//; p};d' | tr -d '\r\n')"
# If you want to guess the mime uncomment the following line (requires perl-file-mimeinfo)
mime=$(mimetype -b "$1")
app="$(xdg-mime query default "${mime:-text/html}")"
gtk-launch "$app" $@