Daniele Esposti's Blog

Disassembly C code for fun – Part 9: arrays

Arrays are a list of fixed number of elements of the same type stored into a continuos block of memory. String are a type of array with a fixed number of char with a NULL as the last element of the array. The assembly generated by an array will be...


Mocking objects in unit tests

Unit testing is important to ensure the stability and the correctness of the code throughout all lifespan of the project. However, testing some code requires a connection to external services (like SMTP, web, etc.) which in all cases must be avoided to simplify the test and development environment and to...


Disassembly C code for fun – Part 8: strings

Following the last post about the buffer overflow protection, today we finally talk about strings. Strings We’ll start back from the last piece of code used in the previous post: #include <stdio.h> int main() { char text[] = "hello world"; return 0; } and its disassembly: 0x0000000100000ed0 <main+0>: push %rbp...


Detect if a number is power of 2

Easy post today: simple method to detect if a number is a power of 2 in O(1) complexity. Yes, O(1), no naive loops involved :-). The code is very simple: bool powerof2(unsigned int n) { return n > 0 & !(n & (n - 1)); } The code looks cryptic,...


Cross-compile 64-bit code on 32-bit machine

Now that I have a spare machine where I can do all my experiments, I can start again to write posts about Disassembly C code for fun but, wait, my current hardware is a 32-bit Pentium-M CPU and I want to build and disassembly 64-bit code! Let’s set up my...