Directly Executing Chunks Of Memory: Function Pointers In C

In the first part of this series, we covered the basics of pointers in C, and went on to more complex arrangements and pointer arithmetic in the second part. Both times, we focused solely on pointers representing data in memory.

But data isn’t the only thing residing in memory. All the program code is accessible through either the RAM or some other executable type of memory, giving each function a specific address inside that memory as entry point. Once again, pointers are simply memory addresses, and to fully utilize this similarity, C provides the concept of function pointers. Function pointers provide us with ways to make conditional code execution faster, implement callbacks to make code more modular, and even provide a foothold into the running machine code itself for reverse engineering or exploitation. So read on!

Function Pointers

In general, function pointers aren’t any more mysterious than data pointers: the main difference is that one references variables and the other references functions. If you recall from last time how arrays decay into pointers to their first element, a function equally decays into a pointer to the address of its entry point, with the () operator executing whatever is at that address. As a result, we can declare a function pointer variable fptr and assign a function func() to it: fptr = func;. Calling fptr(); will then resolve to the entry point of function func() and execute it.

Admittedly, the idea of turning a function into a variable may seem strange at first and might require some getting used to, but it gets easier with time and it can be a very useful idiom. The same is true for the function pointer syntax, which can be intimidating and confusing in the beginning. But let’s have a look at that ourselves.

Continue reading “Directly Executing Chunks Of Memory: Function Pointers In C”

Accessing Blockchain On ESP8266 Using The NodeMCU Board

Blockchains claim to be public, distributed, effectively immutable ledgers. Unfortunately, they also tend to get a little bit huge – presently the Bitcoin blockchain is 194GB and Ethereum weighs in at 444GB. That poses quite an inconvenience for me, as I was looking at making some fun ‘Ethereum blockchain aware’ gadgets and that’s several orders of magnitude too much data to deal with on a microcontroller, not to mention the bandwidth cost if using 3G.

Having imagined a thin device that I could integrate into my mobile phone cover (or perhaps… a wallet?) dealing with the whole blockchain was clearly not a possibility. I could use a VPS or router to efficiently download the necessary data and respond to queries, but even that seemed like a lot of overhead, so I investigated available APIs.

As it turns out, several blockchain explorers offer APIs that do what I want. My efforts get an ESP8266 involved with the blockchain began with two of the available APIs: Ethplorer and Etherscan.

Continue reading “Accessing Blockchain On ESP8266 Using The NodeMCU Board”

The Anxiety Of Open Source: Why We Struggle With Putting It Out There

You’ve just finished your project. Well, not finished, but it works and you’ve solved all the problems worth solving, and you have a thing that works for you. Then you think about sharing your creation with the world. “This is cool” you think. “Other people might think it’s cool, too.” So you have to take pictures and video, and you wish you had documented some more of the assembly steps, and you have to do a writeup, and comment your code, and create a repository for it, maybe think about licensing. All of a sudden, the actual project was only the beginning, and now you’re stressing out about all the other things involved in telling other people about your project, because you know from past experience that there are a lot of haters out there who are going to tear it down unless it’s perfect, or even if it is, and even if people like it they are going to ask you for help or to make one for them, and now it’s 7 years later and people are STILL asking you for the source code for some quick little thing you did and threw up on YouTube when you were just out of college, and of course it won’t work anymore because that was on Windows XP when people still used Java.

Take a deep breath. We’ve all been there. This is an article about finding a good solution to sharing your work without dealing with the hassle. If you read the previous paragraph and finished with a heart rate twice what you started, you know the problem. You just want to share something with the world, but you don’t want to support that project for the rest of your life; you want to move on to new and better and more interesting projects. Here are some tips.

Continue reading “The Anxiety Of Open Source: Why We Struggle With Putting It Out There”

Decellularization: Apples To Earlobes

Our bodies are not like LEGO blocks or computers because we cannot swap out our parts in the living room while watching television. Organ transplants and cosmetic surgery are currently our options for upgrades, repairs, and augments, but post-transplant therapy can be a lifelong commitment because of rejection. Elective surgery costs more than a NIB Millenium Falcon LEGO set. Laboratories have been improving the processes and associated treatments for decades but experimental labs and even home laboratories are getting in on the action as some creative minds take the stage. These folks aren’t performing surgeries, but they are expanding what is possible to for people to do and learn without a medical license.

One promising gateway to human building blocks is the decellularization and recellularization of organic material. Commercial scaffolds exist but they are expensive, so the average tinkerer isn’t going to be buying a few to play with over a holiday weekend.

Let’s explore what all this means. When something is decellularized, it means that the cells are removed, but the structure holding the cells in place remains. Recellularizing is the process where new cells are grown in that area. Decellularizing is like stripping a Hilton hotel down to the girders. The remaining structures are the ECM or the Extra Cellular Matrix, usually referred to as scaffolding. The structure has a shape but no functionality, like a stripped hotel. The scaffolding can be repopulated with new cells in the same way that our gutted hotel can be rebuilt as a factory, office building, or a hospital.

Continue reading “Decellularization: Apples To Earlobes”

Mechanisms: The Lever, It’s Everywhere

Levers are literally all around us. You body uses them to move, pick up a pen to sign your name and you’ll use mechanical advantage to make that ballpoint roll, and that can of soda doesn’t open without a cleverly designed lever.

I got onto this topic quite by accident. I was making an ornithopter and it was having trouble lifting its wings. For the uninitiated, ornithopters are machines which fly by flapping their wings. The problem was that the lever arm was too short. To be honest, as I worked I wasn’t even thinking in terms of levers, and only realized that there was one after I’d fine-tuned its length by trial and error. After that, the presence of a lever was embarrassingly obvious.

I can probably be excused for not seeing a lever right away because it wasn’t the type we most often experience. There are different classes of levers and it’s safe to say that most people aren’t even aware of this. Let’s take a closer look at these super useful, and sometimes hidden mechanisms known as levers.

Continue reading “Mechanisms: The Lever, It’s Everywhere”

Émilie Du Châtelet: An Energetic Life

Émilie du Châtelet lived a wild, wild life. She was a brilliant polymath who made important contributions to the Enlightenment, including adding a mathematical statement of conservation of energy into her French translation of Newton’s Principia, debunking the phlogiston theory of fire, and suggesting that what we would call infrared light carried heat.

She had good company; she was Voltaire’s lover and companion for fifteen years, and she built a private research institution out of a château with him before falling in love with a younger poet. She was tutored in math by Maupertuis and corresponded with Bernoulli and Euler. She was an avid gambler and handy with a sword. She died early, at 41 years, but those years that she did live were pretty amazing. Continue reading “Émilie Du Châtelet: An Energetic Life”

Hackaday guide to Lathes

A Buyer’s Guide To Lathe Options

Lathes are complicated machines, and buying one requires weighing a lot of options. We’ve already talked about buying new Asian, or old American machines (with apologies to the Germans, British, Swiss, and all the other fine 20th century machine tool making-countries). We also talked about bed length and swing, and you ain’t got nothin’ if you ain’t got that swing. Let’s talk about the feature set now. If you’re buying new, you’ll shop on these details. If you’re buying used, knowing the differences will help you pick a good project machine.

Continue reading “A Buyer’s Guide To Lathe Options”