Posts

Showing posts from November, 2019

Writing a keylogger application in Windows

Image
This post is a little bit of a side-step. I was looking through the linux programming interface and set myself a task to obtain keyboard input using only unix commands. One problem: I only have access to a windows PC at the moment! While I could use a virtual machine, I thought it would be interesting to try and do the same thing in Windows using various methods. The code for this post is on my git here . The first method was to avoid using the Windows API as much as possible. The second was to use the SetWindowsHookEx method. Method I If you look at the code on my github, inside the main function we have something like this while ( 1 ) { for ( char i = 0 ; i < 127 ; i ++ ) { if (GetAsyncKeyState(i) == - 32767 ) { of << i; of.flush(); } } } The only alien command is GetAsyncKeyState.  This obtains the current state of the key. Using  GetKeyState  would be the wrong thing to do as we are not...

Optimising matrix multiplication by exploiting cache lines

In order to keep hold of some sort of sanity, I had better start working on something interesting.  Here is solvant  ! Being naive  When working with matrices we usually translate directly the algorithm for matrix-matrix multiplication. And it works. Most of the time, we just don't care. So long as we get the result. But, if it's one thing I learned from working with AVX (see  here ) is that if we can work on data that is contiguous in memory the compiler will automatically apply vectorised operations or SIMD operations. In series notation, the matrix multiplication $\mathbf{C} = \mathbf{A}*\mathbf{B}$ looks like $$C_{i,j} = \sum_{k=0}^K{A_{i,k}B_{k,j}}.$$ Translating this directly into code gives us template < typename T, std :: size_t R, std :: size_t K, std :: size_t C > inline void matrix_prod( const matrix < T, R, K >& a, const matrix < T, K, C >& b, matrix < T, R, C >& c) { ...