Skip to content

Instantly share code, notes, and snippets.

@ArcaneNibble
ArcaneNibble / test.c
Created March 27, 2024 04:22
CH579 deblobbing WIP
#include <stdint.h>
#include <string.h>
#include "CH579SFR.h"
void write_str(const char *s) {
for (uint32_t i = 0; i < strlen(s); i++) {
while (!(R8_UART1_LSR & RB_LSR_TX_FIFO_EMP)) {}
R8_UART1_THR = s[i];
}
@ArcaneNibble
ArcaneNibble / notes.md
Created April 5, 2024 21:59
QingKe RISC-V XW opcode encoding

WCH QingKe RISC-V XW extension opcode encoding

This has been reverse engineered from the toolchain only and has not been tested on hardware.

The c.lbu, c.lhu, c.sb, and c.sh opcodes replace some standard opcodes (that the QingKe cores do not implement, as the replaced opcodes require the D extension), and they also appear to be compatible with "Huawei" extensions mentioned here.

The c.lbusp, c.lhusp, c.sbsp, and c.shsp opcodes exist in a "reserved" opcode block.

001 uimm[0] uimm[4:3] rs1` uimm[2:1] rd`  00			c.lbu		(replacing c.fld)
@ArcaneNibble
ArcaneNibble / jlcpcb_crypto.md
Last active February 21, 2025 01:42
JLCPCB Color Silkscreen Crypto

JLCPCB Color Silkscreen Crypto

JLCPCB color silkscreen files are encrypted using AES-128-GCM and RSA-2048 with OAEP padding with SHA-256 as the hash function. Unfortunately, this means that, although it is possible for tools other than EasyEDA to create files, only JLCPCB can decrypt the resulting files.

File structure

The structure of an encrypted file is as follows:

  1. 256 bytes RSA-encrypted AES key
  2. 256 bytes RSA-encrypted GCM nonce
@ArcaneNibble
ArcaneNibble / notes_pyo3_wasm_wasi.md
Last active October 30, 2024 18:49
Notes on compiling Python + Rust (PyO3) for wasm32-wasip1

Notes on compiling Python + Rust (PyO3) for wasm32-wasip1

Critical metadata

  • Date written: 2024-10-30
  • Python version: 3.12.7
  • Rust version: 1.82.0
  • PyO3 version: 0.22.5
  • zlib version: 1.3.1
@ArcaneNibble
ArcaneNibble / gf2_demo.py
Created January 6, 2025 06:32
GF(2^m) multiplication
def gf2_mult_intermed(a, b, m):
result = 0
for biti in range(m):
if a & (1 << biti):
result ^= (b << biti)
return result
def gf2_reduce(c, p, m):
# polynomial has an implicit, unspecified x^m term
c_bits = 2*m-1
@ArcaneNibble
ArcaneNibble / mcpy.txt
Created March 12, 2025 18:48
WCH `mcpy` opcode
mcpy r_end, r_sta(rt), r_dst
00000 00 00000 00000 11100000 0001111
r_dst r_sta r_end MISC-MEM
# https://deutsch.ucsd.edu/psychology/pages.php?i=201
import numpy as np
import scipy.io.wavfile
import scipy.special
f_s = 44100
duration = 10
note1 = 392
@ArcaneNibble
ArcaneNibble / spiflash.c
Created July 3, 2025 22:13
EV3 spi flash rw test
/**
* \file spi.c
*
* \brief This is a sample application file which invokes some APIs
* from the SPI device abstraction layer to perform configuration,
* transmission and reception operations.
*
*/
/*