Skip to content

Instantly share code, notes, and snippets.

View ilyakurdyukov's full-sized avatar

Ilya Kurdyukov ilyakurdyukov

View GitHub Profile
@ilyakurdyukov
ilyakurdyukov / ips_patch.c
Created October 31, 2024 07:49
Program to apply IPS patches.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#if 0
#define DBG_LOG(...) fprintf(stderr, __VA_ARGS__)
#else
#define DBG_LOG(...) (void)0
#endif
@ilyakurdyukov
ilyakurdyukov / clang-wrapper.c
Created July 10, 2024 04:31
Example of a wrapper for Clang.
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#ifndef EXE_PATH
#define EXE_PATH "/usr/bin/clang"
#endif
static const uint8_t rom_01a[] = {
/* mode numbers */
#if 1
#define B1(x,n) (#x[7-n]!='.')<<n
#define X(x) B1(x,0)|B1(x,1)|B1(x,2)|B1(x,3)|B1(x,4)|B1(x,5)|B1(x,6)|B1(x,7),
X(.@@@@@..)X(........)X(.@....@.)X(.@...@..)X(...@@@..)X(@@@..@..)X(.@@@@@..)X(@.......)X(.@@.@@..)X(.@@..@..)
X(@.....@.)X(.@....@.)X(@....@@.)X(@..@..@.)X(..@..@..)X(@.@...@.)X(@..@..@.)X(@....@@.)X(@..@..@.)X(@..@..@.)
X(@.....@.)X(@@@@@@@.)X(@...@.@.)X(@..@..@.)X(.@...@..)X(@.@...@.)X(@..@..@.)X(@..@@...)X(@..@..@.)X(@..@..@.)
X(@.....@.)X(......@.)X(@..@..@.)X(@..@..@.)X(@@@@@@@.)X(@.@...@.)X(@..@..@.)X(@.@.....)X(@..@..@.)X(@..@..@.)
@ilyakurdyukov
ilyakurdyukov / csr-clean.patch
Created March 8, 2023 13:34
Ritmix RWA-350 fix for Ubuntu 22.04
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 8c41c76..9632251 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -1979,6 +1979,8 @@ static int btusb_setup_csr(struct hci_dev *hdev)
*/
set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks);
set_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks);
+ set_bit(HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL, &hdev->quirks);
+ set_bit(HCI_QUIRK_NO_SUSPEND_NOTIFIER, &hdev->quirks);
@ilyakurdyukov
ilyakurdyukov / godot_gdec.c
Created October 4, 2022 16:06
Godot Engine open_encrypted_with_pass() reader/writer in C (using the OpenSSL library).
// cc -O2 godot_gdec.c -o godot_gdec -lcrypto
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <openssl/evp.h>
// unsigned char hash[EVP_MAX_MD_SIZE]
@ilyakurdyukov
ilyakurdyukov / intel4004.c
Created August 24, 2022 05:49
Intel 4004 (mcs-4) emulator written from reading manual (not tested)
// looks correct but not tested at all
// temp
unsigned i, t, x;
// mcs-4 state
unsigned short pc, stack[3];
unsigned char r[16], a, c;
unsigned char test, ram, src, wpm_idx, sp;
unsigned char rom_out[16], rom_in[16], ram_out[4];
// 8 banks x 4 chips x 4 registers x (16 + 4) chars x 4 bits
@ilyakurdyukov
ilyakurdyukov / safesys.h
Last active January 19, 2022 04:32
Helper function for escaping special characters from user-provided strings to be used in calls to system().
#ifndef SAFESYS_H
#define SAFESYS_H
#include <stdlib.h>
#include <stdarg.h>
#ifndef SAFESYS_NOMEM
#include <errno.h>
#define SAFESYS_NOMEM ENOMEM
#endif
@ilyakurdyukov
ilyakurdyukov / faster_lzma_decoder_x86.patch
Last active June 18, 2023 17:04
Faster LZMA decoder for x86 CPUs (patch for XZ Utils).
From 387fd25f57f41009fc317f7922e957de9f370ff2 Mon Sep 17 00:00:00 2001
From: Ilya Kurdyukov <[email protected]>
Date: Tue, 14 Dec 2021 21:54:32 +0700
Subject: [PATCH] faster lzma_decoder for x86
Notice: Uses inline assembly with CMOV instruction.
Another change that removes the comparison with in_size can give a few
percent speedup for architectures with a small number of registers.
---
@ilyakurdyukov
ilyakurdyukov / main.c
Created November 22, 2021 09:47
SSE2 assembly to intrinsics convertor. Unfinished, but still useful for porting.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
static int is_mem(const char *s, int n) {
int a, i;
for (i = 0; i < n; i++) {
a = s[i];
if (a == '[' || a == ']') return 1;
}
@ilyakurdyukov
ilyakurdyukov / fizzbuzz.c
Created December 16, 2020 08:54
Imagine that you apply for a job at Obfuscate Inc. and they ask you to write a simple program to prove your skills. How will you write it?
#include <stdio.h>
i,x=1,y, z= 1,a;main (){((a<1
)& (x >y )?
++ i- 2< 99
?a=x=i %3 ?i %5
?z *= i+ 1>
z? 10 :1 :4
:0 ,y =i%5?i%3 ?0:4:8,1