Friday, June 21, 2019

IORegistryExplorer on macOS Dark Mode issue fix

IO Registry Explorer is a utility developed by Apple which allows you to watch the I/O Registry on your macOS.
A sample I/O Registry Explorer window

If you are using the IORegistryExplorer on macOS while working with Dark Mode enabled, then you probably noticed the fact that the explorer doesn't fit the new DarkMode, hence the UI might look like that:

Which makes it hard to read the content.

I found this article which shows you how to disable DarkMode for a specific application.

Running the following commands:

osascript -e 'id of app "IORegistryExplorer"'
defaults write NSRequiresAquaSystemAppearance -bool yes

Solves the issue and make it usable again.

Have fun,
Tal Kain

Saturday, May 18, 2019

Standalone IPython using PyInstaller and VirtualEnv

I decided that I want to create a standalone IPython executable that I can distribute.
This executable should be:

  • Run as a standalone, even if there is no Python installed on the machine
  • Have all required packages even if they aren't installed on the machine
  • Doesn't have extra packages in it (just what needed)
  • Single executable (no shared objects)

In order to achieve this task I used PyInstaller, which according to this StackOverflow post seems like one of the good options to do so.

I also wanted to make my environment as clean as possible, so I installed virtualenv:

virtualenv ipython_env/
source ipython_env/bin/activate

Inside this environment, I ran the following pip command to install PyInstaller and IPython:

pip install pyinstaller
pip install ipython 

Following rgtk's comment:, I created the following script:

from IPython import embed

and called it

From PyInstaller help manual:
  -F, --onefile         Create a one-file bundled executable.
then, I ran:
pyinstaller -F

The output of the script generated a (default named) directory called dist which the output binary was in.

$ file dist/ipython
dist/ipython: Mach-O 64-bit executable x86_64

$ otool -L ./dist/ipython
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)

Running this binary:
$ ./dist/ipython
Python 2.7.16 (default, Apr 12 2019, 15:32:40)
Type "copyright", "credits" or "license" for more information.
IPython 5.8.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
In [1]:

That's all for today.

Good luck!
Tal Kain

Wednesday, September 21, 2016

Compiling lsof for iOS device on Mac OSX

I started making a small research on my jailbroken iOS device and I was wondering which files does a specific process touches while I was using it.
In order to do so, I wanted to use the famous lsof, so I downloaded the package from saurik's packages using Cydia, only to find out that the given lsof is not working on my device:

lsof: PID 40 information error: Cannot allocate memory
lsof: PID 39 information error: Cannot allocate memory
lsof: PID 38 information error: Cannot allocate memory
lsof: PID 37 information error: Cannot allocate memory
lsof: PID 36 information error: Cannot allocate memory
lsof: PID 35 information error: Cannot allocate memory
lsof: PID 33 information error: Cannot allocate memory
lsof: PID 31 information error: Cannot allocate memory
After trying to figure it out, I decided that it would be the best to just try compiling my own lsof and use it on the device (I also liked the challenge :-) )

So my journey begins with downloading lsof from Apple's site:
(tarballs can be found here: while sources can be found here: )

$ wget
$ tar zvxf lsof-53.tar.gz

Inside the lsof directory, I ran the configure script:
$ ./Configure darwin

I tried several ways to compile the executable for my iPhone, and while doing so I got several errors.
Using Gregory Pakosz post from here, running:

make CC="$(xcrun --sdk iphoneos --find clang) -isysroot $(xcrun --sdk iphoneos --show-sdk-path) -arch armv7 -arch armv7s -arch arm64"

Gave me a list of errors of missing headers, for example:

In file included from usage.c:39:
In file included from ./lsof.h:195:
./dlsof.h:56:10: fatal error: 'netinet/tcp_fsm.h' file not found                          
#include <netinet/tcp_fsm.h>                                                            
1 error generated.
make: *** [usage.o] Error 1

What I did, following this answer was to create my own copy of the SDK headers' folder, adding the missing headers from /usr/include:

  • netinet/tcp_fsm.h
  • rpc/pmap_prot.h
  • libproc.h
  • sys/proc_info.h
  • sys/kern_control.h
  • net/route.h

I also looked at emonti's missing_headers folder from here to make sure I am on the right track.

Trying to build it again gave me the following linking error:

ld: library not found for -lcrt1.3.1.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Then, I found this SO post that used the -miphoneos-version-min flag, so I added the flag:

$ make CC="$(xcrun --sdk iphoneos --find clang) -isysroot /Users/talkain/tmp/sdk -arch armv7 -arch armv7s -arch arm64 -miphoneos-version-min=8.1"

Which successfully created the executable.

$ otool -L lsof
lsof (architecture armv7):
        /usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.0.0)
lsof (architecture armv7s):
        /usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.0.0)
lsof (architecture arm64):                                                                                                                            /usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)                                     /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.0.0)

$ file lsof

lsof: Mach-O universal binary with 3 architectures
lsof (for architecture armv7):  Mach-O executable arm
lsof (for architecture armv7s): Mach-O executable arm
lsof (for architecture arm64):  Mach-O 64-bit executable 

Trying to run it on the phone - SUCCESS! The binary was successfully compiled on my OSX for the iOS 8.1 which I was using (Note that the bare minimum I managed to compile it with no errors was to iOS 6.0) and I managed to get the output I was looking for.

That was fun.

Credits goes to:

Till next time,
Tal Kain

Saturday, December 5, 2015

Upgrading all the brew cask packages in one command

Here is a nice (and simple) way to upgrade all your Homebrew cask packages at a single command.

All credits goes to Yann-R that wrote here the following command:
brew cask install `brew cask list`

Works perfectly.

Note that you can also run this command using the -f flag (force) to force installation.

- Tal Kain

Wednesday, September 16, 2015

ipython && tmux - saving history to a file


I had an ipython console open inside a tmux split window and I needed to save the history to a file.
Since I can't copy & paste the data from the screen (I was in the middle of a session, so the next time I would configure it correctly using this).

So I found a quicker way, Roberto Z wrote in his comment that in order to save the session's history you can use readline package:

import readline

This works like a charm in Ubuntu.

- Tal Kain

Wednesday, September 9, 2015

Linux: iptables: Removing a collection of iptables rules at once

Here is a small trick for removing several iptables rules at once,

Let's assume we would like to add some rules:
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
I can use the comment match and add a comment to this line:
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE -m comment --comment "SOME_COMMENT"

Now, cleaning all the relevant rules in a simple command would be:

# iptables-save | grep -v SOME_COMMENT | iptables-restore

 Probably not the best way to do it, but it's simple and fast.

Have fun,
-Tal Kain

Wednesday, September 2, 2015

Installing NVIDIA CUDA on an Amazon Web Services (AWS) machine (Ubuntu 14.04)

Disclaimer: I wrote this post several months ago and did not publish it for unknown reason, I assume that the information below is still relevant and correct.

While trying to install the machine, I started my research by reading Traun Leyden's great blog post: (you should too)

Amazon offers two types of machines that includes GPUs (
High-performance NVIDIA GPUs, each with 1,536 CUDA cores and 4GB of video memory
While writing this post, I used the g2.2xlarge machine, but you can also use the 8xlarge.

This will be quick and simple:

1. Make sure you are fully up-to-date
sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade
 When prompted, choose the "install maintainer package...."

2. Reboot the machine (so it will load the new kernel)
3. Install the kernel's header files
sudo apt-get install -y linux-image-extra-virtual linux-headers-`uname -r`
3. Configure the xorg-edgers PPA

sudo add-apt-repository ppa:xorg-edgers/ppa
sudo apt-get update
4. Install the NVIDIA's CUDA repository package
wget -O ${OUTPUT_PATH}
dpkg -i ${OUTPUT_PATH}

 5. Update the package manager and install CUDA
sudo apt-get update
sudo apt-get install cuda
6. Make sure everything is installed as expected:
sudo nvidia-smi -a

7. You can also compile and run a sample to make sure everything is ready:
cd /usr/local/cuda/samples/1_Utilities/deviceQuery

That's all!

- Tal Kain