Skip to content

Instantly share code, notes, and snippets.

@UserUnknownFactor
UserUnknownFactor / unity_typetree_to_kaitai_conv.py
Last active February 24, 2024 07:59
Converts TypeTree generated by UnityPy reflection generator to .ksy format of KaitaiStruct for parsing analysys
from sys import argv
import json, re
from ctypes import c_uint32
from tqdm import tqdm
# For usage with KaitaiStruct visualisers
# (like https://userunknownfactor.github.io/ for example)
extract_class = "ClassName"
@UserUnknownFactor
UserUnknownFactor / patch_binary.cmd
Last active March 15, 2025 14:53
Example patching script for binary executables written in PowerShell and running from a cmd batch file
@powershell.exe -ExecutionPolicy Bypass -Command "$_=((Get-Content \"%~f0\") -join \"`n\");$script=$_.Substring($_.IndexOf(\"goto :\"+\"EOF\")+9); &([ScriptBlock]::Create($script)) %*"
@goto :EOF
# PowerShell script starts here, we can also pass parameters like this since they are passed to the script block
param($parameter1, $parameter2, $parameter3)
$fileName = "game.exe" // game file
$fileHashString = "abcdef12345678901111111111111111" // the file's MD5 hash
function To-Utf16 {
@UserUnknownFactor
UserUnknownFactor / check_disk_errors.py
Last active March 3, 2025 13:09
Python Windows utility to check what NTFS files correspond to what bad sectors on disk that showed up as failed in System Log (also corresponds to bad physical sector reads in low-level disk checking tools that use native Windows API).
import win32evtlog # requires pywin32 preinstalled: pip install pywin32
import os, sys, platform, tempfile, subprocess, base64, hashlib
from struct import unpack
import ctypes
from ctypes.wintypes import HANDLE
from ctypes.wintypes import BOOL
from ctypes.wintypes import HWND
from ctypes.wintypes import DWORD
from ctypes.wintypes import ULONG
from ctypes.wintypes import USHORT
@UserUnknownFactor
UserUnknownFactor / textutf16y.py
Last active September 16, 2023 02:10
Convert a group of files with unknown encodings to UTF-16 (Python)
import os, sys
from glob import iglob
work_dir = os.getcwd()
file_list = (
[f for f in iglob(os.path.join(work_dir, '**/*.ks'), recursive=True) if os.path.isfile(f)] +
[f for f in iglob(os.path.join(work_dir, '**/*.tjs'), recursive=True) if os.path.isfile(f)]
)
all_codecs = ['utf_16', 'utf_8_sig', 'ascii', 'cp932', 'utf_8', 'shift_jis', 'shift_jis_2004', 'shift_jisx0213']
@UserUnknownFactor
UserUnknownFactor / pck_unpack.py
Last active April 8, 2023 15:10
Godot Engine 3 .pck file unpacker/repacker (unencrypted only)
import io, os, argparse, sys, textwrap, re, enum
from struct import unpack, pack
# NOTE: Repacking mode adds file to the end of the previous archive if it's
# larger than old or replaces old one if less.
# WARNING: It MODIFIES ORIGINAL FILE on repack so BACKUP it BEFORE REPACKING!!!
class EndianBinaryReader:
endian: str
Length: int
@UserUnknownFactor
UserUnknownFactor / furiganizer.user.js
Last active June 9, 2022 14:08
GreaseMonkey browser userscript to add furigana to some kanji and kana on web-pages
// ==UserScript==
// @name Furiganizer
// @description Romanize hiragana/katakana in selected sites
// @match https://ja.wikipedia.org/*
// @version v1
// @grant none
// @run-at document-body
// ==/UserScript==
(function() {
@UserUnknownFactor
UserUnknownFactor / xor2.py
Last active June 19, 2022 08:50
XOR two files in Python
#!/usr/bin/env python
# coding: utf-8
#####################################################################
# Python XOR 2 Files (xor.py)
# Use: xor.py file1 file2 [outputFile]
# Example: xor.py a.txt b.txt C:\result.txt
#####################################################################
import sys, os, re
@UserUnknownFactor
UserUnknownFactor / Disable_Charms_Panel.reg
Last active January 8, 2024 07:26
Various useful Windows batches
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ImmersiveShell\EdgeUI]
"DisableCharmsHint"=dword:00000001
"DisableTRCorner"=dword:00000001
@UserUnknownFactor
UserUnknownFactor / unity_dump.py
Created October 23, 2020 08:17
Unity game translation tools
import os, sys
from glob import glob
from UnityPy import AssetsManager
from collections import Counter
import zipfile
from string import Template
from filetranslate.service_fn import write_csv_list
USE_YAML = False
try:
@UserUnknownFactor
UserUnknownFactor / HDDGeometry.md
Last active September 8, 2022 12:55
Discovering Hard Disk Physical Geometry through Microbenchmarking

Discovering Hard Disk Physical Geometry through Microbenchmarking

By Henry, on September 6th, 2019

Modern hard drives store an incredible amount of data in a small space, and are still the default choice for high-capacity (though not highest-performance) storage. While hard drives have been around since the 1950s, the current 3.5″ form factor (actually 4″ wide) appeared in the early 1980s. Since then, the capacity of a 3.5″ drive has increased by about 106 times (from 10 MB to about 10 TB), sequential throughput by about 103 times, and access times by about 101 times. Although the basic concept of spinning magnetic disks accessed by a movable stack of disk heads has not changed, hard drives have become much more complex to enable the increased density and performance. Early drives had tens of thousands of sectors arranged in hundreds of concentric tracks (sparse enough for a stepper motor to accurately position the disk head), while current d