Skip to content

Instantly share code, notes, and snippets.

@devilholk
devilholk / fix_ssh-copy-id.patch
Created October 12, 2020 03:39
Fix a problem with ssh-copy-id
--- /usr/bin/ssh-copy-id 2020-10-02 18:28:13.000000000 +0200
+++ ./test.sh 2020-10-12 05:34:42.469599079 +0200
@@ -247,7 +247,7 @@
# the -z `tail ...` checks for a trailing newline. The echo adds one if was missing
# the cat adds the keys we're getting via STDIN
# and if available restorecon is used to restore the SELinux context
- INSTALLKEYS_SH=$(tr '\t\n' ' ' <<-EOF)
+ INSTALLKEYS_SH=$(tr '\t\n' ' ' <<-EOF
cd;
umask 077;
@devilholk
devilholk / mount.py
Created September 25, 2020 12:24
Read /etc/mtab to a table
#some person on the internet: https://stackoverflow.com/a/9290177
#That is, /etc/mtab should be the convention
class MountTableRow:
def __init__(self, node, mount_point, fs_type, fs_options, fs_dump, fs_pass):
self.node = node
self.mount_point = mount_point
self.fs_type = fs_type
self.fs_options = fs_options
self.fs_dump = fs_dump
@devilholk
devilholk / fs_uuid_devnode.py
Last active September 25, 2020 12:42
Get filesystem ID from device node
import ctypes
lib = ctypes.CDLL('libblkid.so')
lib.blkid_new_probe_from_filename.argtypes = (ctypes.c_char_p,)
lib.blkid_new_probe_from_filename.restype = ctypes.c_void_p
lib.blkid_free_probe.argtypes = (ctypes.c_void_p,)
lib.blkid_do_probe.argtypes = (ctypes.c_void_p,)
@devilholk
devilholk / charge_control.py
Last active September 23, 2020 10:50
Script that controls an external circuit to keep the laptops battery voltage within nominal voltage. The DTR signal is used to control the circuit.
#/sys/bus/acpi/drivers/battery/PNP0C0A:00/power_supply/BAT0
#See https://i.imgur.com/yuVyiW7.png for picture of the böp this controls
import sys, serial, time
min_voltage = 3.5
max_voltage = 3.8
interval = 300 #Every 5 minutes
def read_num(filename):
with open(filename, 'r') as infile:
@devilholk
devilholk / uggly_bt_snoop.py
Last active August 30, 2020 23:02
Really uggly hack to get bluetooth snoop data from non rooted android. Will output raw data, pipe to hexeditor or file location.
import subprocess, base64, sys, time, struct, zlib
debug = False
#added stuff from https://android.googlesource.com/platform/system/bt/+/master/tools/scripts/btsnooz.py
def get_snoop():
p = subprocess.Popen(('adb', 'shell', 'dumpsys', 'bluetooth_manager'), stdout=subprocess.PIPE)
stdout, stderr = p.communicate()
extract = False
@devilholk
devilholk / af_unix_recv_fd.py
Created August 16, 2020 09:25
Test of receiving file descriptors from another process using AF_UNIX
AUTO_DELETE = False #Change this to True to delete the socket before usage in case it was never cleaned up for some reason
import socketserver, os, struct
from socket import *
class my_handler(socketserver.StreamRequestHandler):
def handle(self):
print('New request!', self.request)
while True:
msg, ancdata, flags, addr = self.request.recvmsg(1024, 1024)
@devilholk
devilholk / af_unix_send_fd.py
Created August 16, 2020 09:24
Test of sending file descriptors to another process using AF_UNIX
from socket import *
import struct
#Open a file (opens itself now)
this_script = open(__file__, 'r')
#List of file descriptors to send
fd_list = [this_script.fileno()]
#Prepare ancillary data
void uart_send_data(volatile void* data, int length) {
dma_channel_reset(DMA1, DMA_CHANNEL4);
dma_set_peripheral_address(DMA1, DMA_CHANNEL4, (uint32_t) &USART1_DR);
dma_set_memory_address(DMA1, DMA_CHANNEL4, (uint32_t) data);
dma_set_number_of_data(DMA1, DMA_CHANNEL4, length);
dma_set_read_from_memory(DMA1, DMA_CHANNEL4);
dma_enable_memory_increment_mode(DMA1, DMA_CHANNEL4);
dma_set_peripheral_size(DMA1, DMA_CHANNEL4, DMA_CCR_PSIZE_8BIT);
dma_set_memory_size(DMA1, DMA_CHANNEL4, DMA_CCR_MSIZE_8BIT);
import ansi_standalone, sys
ansi_standalone.install_colored_stdout_retabulator()
def F2():
with sys.stdout.indented:
print('This is F2')
print('We had two lines to say today')
import colorsys, sys
def bold(text):
return f'\x1b[1m{text}\x1b[21m'
def italics(text):
return f'\x1b[3m{text}\x1b[23m'
class color:
black = lambda text: f'\x1b[30m{text}\x1b[38m'
red = lambda text: f'\x1b[31m{text}\x1b[38m'