Skip to content

Instantly share code, notes, and snippets.

View pavel-a's full-sized avatar

Pavel A. pavel-a

View GitHub Profile
@pavel-a
pavel-a / USBWriteProtect1.js
Created April 28, 2023 21:42
Windows; toggle write protection on inserted USB drives (wsh)
//-----------------------------------------------------------------------------
// Toggle write protection on USB drives
//
// See http://support.microsoft.com/kb/555443
// [ HKLM\System\CurrentControlSet\Control\StorageDevicePolicies\WriteProtect: reg_dw: 1 ]
//
// NOTES:
// - This registry hack (KB555443) works only starting from XP SP2; I don't check for the SP.
// - If a drive is already attached, write enable seems to come in effect immediately;
// Write disable becomes effective only after the drive is re-attached.
@pavel-a
pavel-a / bin2hexp.py
Last active August 6, 2022 16:05
Binary file converter to Intel hex (python script)
#!/usr/bin/python3
'''
Converts a binary file into an intel hex file
Usage: Bin2Hex.py [-A base_address] [-n] [-F yes|no] -b <binary_file> -o <hex_to_be_created>
pavel_a@fastmail.fm 05-aug-2022
Original: https://community.silabs.com/s/article/converting-binary-firmware-image-files-to-intel-hex-files-bin-to-hex-x
'''
@pavel-a
pavel-a / tcp_echoclient.py
Last active December 23, 2019 20:12
Simple TCP, UDP Echo clients in Python. Generate random messages of random length. To test some bare metal embedded thingy.
#!/usr/bin/python3
"""
Echo client / TCP
Parameters: set below: server IP address, port=7, timeouts
Message random generated, binary; length and data random : see make_random_msg()
NOTE: First message takes very long time, don't set REPLY_TIMEOUT too short!
pa01 23-dec-2019
"""
import socket
// Phys monitor control via DDC/CI or VESA commands
// (David Lowndes)
// From https://social.msdn.microsoft.com/Forums/en-US/5437ddb8-af86-4cf0-8061-798e6601e08e/how-to-control-system-brightness-using-windows-api-?forum=windowsgeneraldevelopmentissues#554b7b7f-0aab-429d-9c36-fd39608979b0
#include <Windows.h>
#include <physicalmonitorenumerationapi.h>
#include <highlevelmonitorconfigurationapi.h>
#pragma comment( lib, "Dxva2.lib" )
void
@pavel-a
pavel-a / edid_dump.cs
Created March 25, 2019 22:52
A little program to dump display EDIDs in hex. Gets extension blocks.
// Read EDIDs from all displays via WMI ...
// https://docs.microsoft.com/en-us/windows/desktop/wmicoreprov/wmimonitorraweedidv1block
using System;
using System.Management;
namespace edid_dump {
class edid_dump
{
static void Main(string[] args)
// Detect the proper COM ports for paired BT devices by name prefix
// pavel_a@fastmail.fm 12-feb-2019
#include "pch.h"
#define _CRT_SECURE_NO_WARNINGS 1
#include <vector>
#include <tuple>
#include <string>
#include <process.h>
#include <iostream>
@pavel-a
pavel-a / chkspaces.bat
Created May 20, 2018 23:47
Windows path sanitize (de-space, shorten)
: Pass path to sanitize as arg 1
@echo off
echo Original path=[%~1]
call :chkspaces "%~1"
if /I NOT "%_sp%" == "%~1" call :shrt "%~1"
echo uglified=[%_sp%]
goto :EOF
:chkspaces
@pavel-a
pavel-a / winKdPrintUm.h
Created April 10, 2018 21:08
Print to the Windows kernel debugger from usermode
////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Print to kernel debugger from user mode
///
/// Usage:
///
/// ULONG getKdPrintPointers(void);
/// int isKdPrintAvailable(void);
///
/// ULONG KdPrintEx((ULONG ComponentId, ULONG Level, PCHAR Format, ...));
/// ULONG KdPrintExWithPrefix((PCHAR prefix, ULONG ComponentId, ULONG Level, PCHAR Format, ...));
@pavel-a
pavel-a / KbdRuPh3.klc
Last active August 10, 2017 14:11
Keyboard Layout - Russian Translit For Windows, MAC OS X
KBD KbdRuPh "Russian Phonetic Smile v1 (Linux style)"
COPYRIGHT "(c) 2006-2008 pavel_a@live.com"
COMPANY "pavel_a@live.com"
LOCALENAME "ru-RU"
LOCALEID "00000419"
@pavel-a
pavel-a / dbg_preprocessor.README
Last active August 6, 2017 17:24
Preprocessor that converts C printf-like statements to something like Linux bprintf and extracts format strings. Can be used in small embedded systems to save memory and processing time on target.
This is a preprocessor that converts C printf-like statements in C code to something like Linux bprintf and extracts format strings.
It can be used in small embedded systems to save memory and processing time on target.
The following describes our custom implementation for a 32-bit LE machine (Tensilica Xtensa CPU & xcc toolchain). One can tweak it as needed.
Limitations:
* Limitation of the parser: ...... see in the py file
* Limitation of codegen: ....... ditto.
Mainly, all arguments must be scalar.
Format %s is supported only for constant strings (string literals, __func__ or __FUNCTION__)