Skip to content

Instantly share code, notes, and snippets.

View tniessen's full-sized avatar

Tobias Nießen tniessen

View GitHub Profile
@tniessen
tniessen / service.md
Created October 1, 2016 11:46
Using the "service" tool with ADB and why to avoid it

As it turns out, it is not trivial to control the audio volume of an Android device using ADB. At the time of writing, the only way appears to be using the service tool. Actually, the service command allows to "connect" to a number of services (104 on Android 6.0.1) and invoke functions. Not knowing much about this tool, I managed to completely mute all sounds and speakers of my Nexus 5, and I was stuck without any sound for quite some time. I did not find a way to unmute the sound from within the system UI, so I got to dive a little deeper into this.

If you know which service you want to use, you then need to find its interface declaration. The command

service list

gives you a list of all services with the associated interfaces, if applicable:

...

26 backup: [android.app.backup.IBackupManager]

@tniessen
tniessen / cryptokey-instanceof-frames.html
Created May 12, 2021 12:39
Tests the behavior of instanceof on CryptoKey instances shared across frames
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
</head>
<body>
<iframe src="iframe.html" width="100%" height="300"></iframe>
<pre id="parent"></pre>
<script type="text/javascript" src="test.js"></script>
<script type="text/javascript">
@tniessen
tniessen / json_escape.cmake
Created March 27, 2022 21:48
Proper JSON escaping for CMake 3.19 and above
# CMake does not support escaping string values for use in JSON. However, it
# does properly escape keys in JSON object literals. We use that fact to escape
# string values by constructing a JSON object with a single named property,
# whose key is the string that we want to escape. Then we strip away all of the
# stringified JSON object except said key.
function(json_esc ret_var val_str)
string(JSON tmp_json SET "{}" "${val_str}" "0")
string(REGEX REPLACE "^\\{[ \t\r\n]*" "" tmp_json "${tmp_json}")
string(REGEX REPLACE "[ \t\r\n]*:[ \t\r\n]*0[ \t\r\n]*\\}$" "" tmp_json "${tmp_json}")
if(NOT "${tmp_json}" MATCHES "^\"[^\n]*\"")
@tniessen
tniessen / fix-ssh-config-for-hyper-v-hosts.ps1
Created May 14, 2022 18:10
Updates the HostName property of SSH hosts that are Hyper-V virtual machines to the (dynamic) IPv4 addresses of their network interfaces
$ErrorActionPreference = "Inquire"
$SshConfigPath = "C:\Users\Tobias\.ssh\config"
$lines = Get-Content -Path $SshConfigPath
for ($i = 0; $i -le $lines.Count; $i++) {
if ($lines[$i] -notmatch '^# auto-fix: (?<VirtualMachineName>[^ ]+) (?<NetworkAdapterName>[^ ]+)$') {
continue
}
$VirtualMachineName = $Matches.VirtualMachineName
@tniessen
tniessen / stm32-cmox-crypto-crc-aes-gcm.md
Created December 28, 2023 21:09
How CMOX (X-CUBE-CRYPTOLIB) uses the STM32's CRC unit for AES encryption and decryption

X-CUBE-CRYPTOLIB (CMOX) and the STM32's CRC unit

This write-up is about the STM32 cryptographic firmware library X-CUBE-CRYPTOLIB, also known as the Cortex-M Optimized Crypto Stack (CMOX). It is a cryptographic library developed by STMicroelectronics (ST) for their series of STM32 processors, which are based on the ARM Cortex-M family.

Hardware features vary across different STM32 processors. Because CRC checksums are widely used in embedded systems, most (if not all) STM32 processors feature a hardware CRC unit that is supposed to accelerate CRC computations.

Introduction

Interestingly, on the page "Getting started with the Cryptographic Library", ST claims: