Code related to this article: github.com/arjun024/memalloc This article is about writing a simple memory allocator in C. We will implement malloc() , calloc() , realloc() and free() . This is a beginner level article, so I will not spell out every detail. This memory allocator will not be fast and efficient, we will not adjust allocated memory to align to a page boundary, but we will build a…
We hear the term JPEG all the time. What really is JPEG? How does it work? I will try to give a brief overview of what JPEG is and how it works. This is a beginner level article, so we will not dwell too much on the details. First, JPEG is not a file format. It’s a compression method. The term JPEG is an acronym for the Joint Photographic Experts Group, which created the standard. Most of…
Code related to this article: hide-data-in-ptr When we write C code, pointers are everywhere. We can make a little extra use of pointers and sneak in some extra information in them. To pull this trick off, we exploit the natural alignment of data in memory. Data in memory is not stored at any arbitrary address. The processor always reads memory in chunks at the same size as its word size; and thus…
In my previous article Kernels 101 - Let’s write a Kernel , I wrote how we can build a rudimentary x86 kernel that boots up using GRUB, runs in protected mode and prints a string on the screen. Today, we will extend that kernel to include keyboard driver that can read the characters a-z and 0-9 from the keyboard and print them on screen. Source code used for this article is available at my Github…
Hello World, Let us write a simple kernel which could be loaded with the GRUB bootloader on an x86 system. This kernel will display a message on the screen and then hang. How does an x86 machine boot Before we think about writing a kernel, let’s see how the machine boots up and transfers control to the kernel: Most registers of the x86 CPU have well defined values after power-on. The…
I was once writing a program similar to the following. But I made a little mistake which led me to something interesting. #include <stdio.h> int main() { char ch[256]; scanf("%s", ch); if (ch == 'a') { printf("Your sentence begins with %c.\n", *ch); } return 0; } In this code, I am supposedly reading a string from stdin , checking if it begins with the character literal 'a' and if it does, print…
Hi, i wrote a simple php wrapper for making OAuth requests to a url. Here’s the code on github . Include the library file in your code first: require('oauthRequest.php'); Now, you can use the oauthRequest method which returns the response text: $output = oauthRequest(<url>);
jQuery is probably the best thing to have happened to an otherwise lousy language JavaScript. Just a couple of things I felt that doesn’t fare well with jQuery. XSS !!! Suppose you want to create an HTML element on the fly, you could use the $() method and pass to it a string that looks like HTML. If the string matches the regex for an HTML tag, then the string is internally passed to the…
Hi folks, I wanted to host some files on my this website which i host on tumblr. So, i decided to put them on dropbox and write a simple python app hosted on google app engine that serves them. Finally, pointed one of my subdomains to the python app - so i can host stuff in my domain like files.arjunsreedharan.org/test I have put the code on Github: arjun024/pystorage To use for your website, all…
Hey folks, Long time no C. Generally in C, this is how we find the length of an array arr : n = sizeof(arr) / sizeof(arr[0]); Here we take the size of the array in bytes; then divide it by the size of an individual array element. What if I tell you that we can get rid of sizeof and have a cooler way to calculate size? like this: n = (&arr)[1] - arr; Alright, let’s see how that could be…
Does “roodkcableoj28840ybtide” mean anything to you? By the time you read through this article, you will understand that it is not gibberish exactly. The Tux Talking about backdoors, I’d like to write about an attempted planting of backdoor in the linux kernel. It was the year 2003 and linux kernel was still maintained on BitKeeper. The backdoor was just 2 lines added to the…
Some time ago, I dropped by the Times of India website and entered a “vector” string as a query in the search field. Then, the page heading read as below ( Arjun024 being my twitter handle): News: All twitter followers of Arjun024 to be awarded gold coins Later someday, I searched Google for “ arjun024 Times of India ”. To my astonishment, Google indexed the link with the…
Hey folks, I just wrote a tiny script to print Facebook Friends Ranking Score in a table. (UPDATE [Jan 23, 2016 and June 5, 2014 and Dec 18, 2013]: Code and Link updated since Facebook changed some of their code ) Drag and drop the link in following page to your browser’s bookmarks bar: code.arjunsreedharan.org/facebook-friends-ranking-score Log in to your facebook and then click on the…
You don’t have root access to your Google Nexus 4, which y ou spent your hard earned money to buy?? Don’t worry!! Rooting your Nexus 4 is but a piece of Cake. (Do at your own risk though!) First things first – THE PROCEDURE BELOW WILL WIPE ALL YOUR DATA CLEAN . 1. Take a Backup of your personal files, contacts, messages etc (only if you want to :P). 2. Download Google Nexus 4 USB drivers (…