danieljon.es

normal solarized dark no css
index blog opinions interesting cgit
likes dislikes

Blog

Rambles about programming, technology and life.

prev 1 2 3 4 5 6 7 8 9 next
direct link

Analysing and explaining my source code.

26/12/2015

Let's face it, my blog is stale - rarely new content, and whenever there is new content it is often short and boring.
I've decided to try something different, I'm going to being walking you through snippets of my code, explaining what I'm doing and my though process, just for fun.
I'm going to start today with my latest mini project, the number storage program.
The first section of my value recording program is simple.
I first include some C standard libraries that I need:
stdio.h - used for standard IO such as printf etc
string.h - used for comparing strings
time.h - pretty simple, I use this library to determine the systems time
I then proceed to define two functions that I use later on, this is to ensure that the C compiler knows the functions exists - compilers are dumb.

 
/* database like program to record values */
#include stdio.h
#include string.h
#include time.h

/* functions */
void addRecord(char* value);
void readRecord();
 

Next up, just like every other C program in existence I define a main function and add code inside of it. The main function in any program is the first place any compiler looks for code - without the presence of this function your program WILL NOT compile.
To attempt to keep things slightly less complicated I shall post the source first and then explain it.
 
int main(int argc, char* argv[])
{
	if (argc < 2)
	{
		printf("Utility for recording and monitoring values\n");
        	printf("This utility requires arguments.\nusage: %s -l [list records] -i [insert record]\n", argv[0]);
                return 0;
        }
        int i;
        for (i = 1; i < argc; i++)
	{
		if (strcmp("-l", argv[i]) == 0)
                {
                        readRecord();
                        break;
                }

		if (strcmp("-i", argv[i]) == 0)
		{
			addRecord(argv[i+1]);
			break;
		}

        }
        return 0;
}
 

Now, this is about the time those of whom don't know at least a little programming should leave - I'm not here to teach you how to program, just to explain what I do!
I define the main function as an int - as you should know this is due to passing the OS an exit code upon completion. I also use the common "int argc, char* argv" to obtain CLI arguments as this is, of course a CLI only program.
I follow the definition by checking for arguments, if this program does not receive at least one argument I print to the screen usage instruction and end the program.
Once it has been confirmed that at least one argument has been passed I check them incrementally for specific key triggers - -l and -i. If none of these are found, the program ends silently - I could have told the user they didn't input a correct argument, but why bother.
If the correct arguments are found, I call the relating function (the same ones we defined earlier) and let them take over - after passing the correct values of course, which in -i's case is anything AFTER the -i (-i was to INSERT, -l was to LIST).
Once the functions are complete, we break out of the for loop and end the program - our job is done.
The final parts to be explained are the two functions we use.
 
void addRecord(char* value)
{
	printf("Adding record: %s\n", value);
	/* before we open our file, we want to get our date and time setup which we will also write */
	time_t rawtime;
	struct tm *timeinfo;
	time(&rawtime);
	timeinfo = localtime(&rawtime);
	/* open file for writing */
	FILE *fp;
	fp = fopen("values", "a"); /* a to append, not w - would overwrite */
	if (fp == NULL)
	{
		printf("Can't open the file for writing.");
	}
	else /* file open, write data */
	{
		fprintf(fp, "%s - %s\n", asctime(timeinfo), value);
		fclose(fp);
	}
}
 

Oh my, if you are new to programming close your eyes and run, this looks scary.
This function labelled "addRecord" does just that, it adds a record to the file we are using to store our data.
Now, I have to be honest, this is a simple ass way of storing values. I use no database, I just take whatever a user enters and append it to the end of a file - lazy, yes, but very convenient as I don't expect anyone to actually use this script, except myself.
I begin by informing the user of what record is being appended to the file. I follow it by some nice copy-pasta code for retrieving and converting the time and date to a human readable format that will also be appended to file.
At this point we are ready to append our data to file, so I generically create a FILE pointer and fopen the file we are using to store data. I open it with 'a' access to allow the data to be appended - using 'w' for write mode WILL OVERWRITE the file, we don't want this.
I then check to see if the file was opened successfully, if not I inform the user and the function ends there. If it was however opened correctly, I fprintf the data into the file we opened and then, of course then close it. The function then ends. Also note how I never delete the fp pointer, sue me.
The next function is awfully similar and just reads and displays the entire file to the screen.
 
void readRecord()
{
	/* open file for reading */
        FILE *fp;
        fp = fopen("values", "r");
        if (fp == NULL)
        {
                printf("Can't open the file for reading.\n");
        }
        else /* file open, read data */
        {
		char buff[1000];
		while (fgets(buff, 1000, fp) != NULL)
        		printf("%s", buff);
                fclose(fp);
        }

}
 

I use fgets to retrieve the files data into a buffer and then print it, etc
Awfully simple, yet quite nifty and useful.
Should I bother doing more of these? Probably not.

direct link

simple C CLI program for adding and monitoring values

21/12/2015

I had a personal reason for needing to insert, store and monitor specific values - I could have just used a text document or piece of paper - but that is boring, who likes boring?
The program in action is displayed below.
post14_1
The program allows only 2 arguments: -l (lists the values stored) and -i (insert values), everything else is ignored.
To compile and run the program simply enter in any Linux programming environment: gcc main.c -o valueStorage;./valueStorage
The program will compile and present you with an output describing your options.
The source code is located here for anyone to use: http://pastebin.com/027YH4Qi
As always, you can contact me via my email: admin@danieljon.es or via irc: danieljon.es:9090/?channels=#fun
(if you try to use the IRC server use a realistic name that identifies yourself, if not you will be kicked from #fun)


direct link

Been on Windows playing Fallout 4 - ashamed.

1/12/2015

But, i'm now back home doing what I love.
A new theme face lift, fancy background images and home security camera setup. Perfect.
Current work space - split over 2 1920*1080 monitors.
post13_1
I'm currently working on my RGB lighting program - more precisely, I'm working on the micro-controller side of things - fun!
So much for """"daily"""" media/posts.
You can always find me on my IRC server - http://danieljon.es:9090/?channels=#fun - I kick anyone that doesn't identify themselves.
Or, contact me via Email at: admin@danieljon.es


direct link

Game engines and OpenGL

6/10/2015

Lately I've been teaching myself OpenGL in C using GLUT, literally as low level and annoying as you can get.
Just today I've been playing with an engine known as 'Irrlicht'. It is an OpenGL C++ API for OpenGL.
At the moment i'm just simply loading meshes and maps from Quake, I hope soon to get a shooting game of sorts going, but that is quite a while away.
You can download a video of my current progress here


direct link

Langton's Ant

20/9/2015

Inspired by https://www.youtube.com/watch?v=NWBToaXK5T0 I've decided to embark on creating my own version of this simulation using Qt/C++.
Yet another boring weekend.
post11_1
Woo, I have a grid drawn, amazing.
2d graphics suck.


direct link

Card hand generator

17/8/2015

When not flicking them i'm randomly generating them, because why not.
It is written in C and is able to be compiled on any UNIX/Windows environment.
example use:
./CardsGrid hand 5
this generates a completely random hand of 5 cards. (seeded with the current time)
the code for this mini-project can be found here http://pastebin.com/1KyJBEB6
post10_1


direct link

Front panel PC device

12/6/2015

Recently I've been working on a front PC panel device.
Seeing as there are plenty of unused slots I've designed and created a display panel containing a 16*2 LCD display and a small OLED screen.
They are powered by an Arduino with the data coming from an application made in C++/Qt communicating via a serial connection via USB. Currently it can play a few songs through a piezo buzzer, and just for fun, I created a simple flappy birds clone.
The arduino has an internal controller made up of 3 buttons; however for external interaction I have added an infra-red reciever; this allows me to control the entire project with an IR controller - I have chosen and programmed my RGB LED controller -any controller can easily be added.
The arduino is currently sitting inside my PC and the mounting for the screens are ugly. But it isn't done; I plan to make it look better and add features such as CPU/RAM etc monitoring with graphs and a weather display.
Here is an image of the current application controlling the Arduino:
post9_1
And here is a horrible image of the display (shitty webcam):
post9_1
I'll repost any updates made.
update:
Have done some major work to the UIs back end.
It downloads a weeks worth of data for your location and stores it all etc.
Also allowed the user to display custom text on either screen, makes your computer look more personal.
post9_3
I've now published the code on GitHub and will update it regularly.
https://github.com/daniel-Jones/PC-Panel-Display


direct link

Services I run

5/6/2015

I've realised that I run quite a few things on my server, some useful, most not:
IRC (Internet Relay Chat) Server:
I run this server for myself and a few people to hang out in a free setting - http://irc.danieljon.es:6667
QWEBIRC - Online IRC Client (connects to my server):
I run this service to allow people without IRC client to connect to my server (derp* sucks) - http://danieljon.es:9090/
ZNC - IRC Bouncer:
This is a private bouncer using the ZNC software package, this allow myself and a few others to connect to multiple IRC servers using a fancy reverse DNS host (currently relaxing.in.the.stars.because-of.science)
IRSSI - IRC client:
IRSSI is a text based IRC client I run on my server inside a screen session.
Image Hosting Service:
I created an image hosting service from scratch because I figured it would be useful for assisting people with issues in #BeamNG, it turned out to just be a cool project for myself and others to use - http://upload.awful.pictures
Custom User Software:
I've also integrated the image hosting service with a register/login system custom made using PHP and MySQL, this allows you to register to services (I currently have a "Draw something" game made and a file uploading service) that are not available to the public. The database has critical information MD5 hashed with a custom salt accompanying it - your password is completely safe. - http://danieljon.es/login/
Blog:
You're here right now; I point all my domains here - http://danieljon.es
Domains:
I currently own and maintain one server with 3 domains:
danieljon.es - main domain used for most things - if you didn't notice it is my name, Daniel Jones - I bet you don't have your name as a domain
awful.pictures - I use this domain for my image hosting service
because-of.science - my server has a reverse DNS record that points here - it makes me look sup3r l33t in IRC.
Email server:
I currently have an email server setup - instead of using Gmail and having a something@gmail.com address I have something@danieljon.es - My main account admin@danieljon.es - this is where you can easily reach me (or IRC of course)
I will probably host a lot more in the future, but currently, this is all I need.


direct link

Simple server in C++/Qt

5/6/2015

I've been using sockets lately for serial communication between C++/Qt and my arduino. I figured I may as well try out a TCP server using sockets. It's quick and dirty, but pretty cool and holds many possibilities for projects. I connect via telnet in a running bash terminal - it doesn't actually do anything other than connect and communicate with each other.
post7_1


direct link

Phone SIM cards are easily exploitable and overly intrusive

27/5/2015

Phone SIM cards are easy to exploit and are overly intrusive

The life of an individual in 2015 is vastly different to that of other decades in the fact that everyone is lazy in some way or form; whether it be for work related purposes, or easy access to your social media accounts we all have a mobile phone that contains a piece of technology that is easily exploitable (taking advantage of software/hardware bugs/issues) and overly intrusive. Within our mobile phones, whether it be a smart phone or not, we have all conveniently placed an extraordinarily powerful and smart device that can allow a hacker to take complete control of your phone, a SIM card. A SIM (subscriber identity module) card1 is a piece of technology that everybody knows exists, yet hardly anyone can define what it actually does or how it works, they just know you need one to get onto Facebook; believe it or not the humble SIM card in your phone is a fully fledged computer and can host and run applications without your phone, thus yourself ever knowing. The alarming facts do not however end there; your phone, whether it be a 2005 flip phone, or the latest product from Apple with finger print identification to stop hackers allows your telecommunication providers, or in the worrying case, a hacker to run applications on your SIM card potentially allowing them to spy on your GSM2 traffic which includes your phone calls, SMS messages and Internet usage.

An eye opening speech3 by Karl Koscher and Eric Butler performed at Defcon 214 (an American based hacking conference) displayed, for the first time, the power and pure horror of what a SIM card is intentionally capable of doing when in the hands of a hacker. A single generic SIM card has the power similar to that of a basic Arduino5, with an alarmingly larger range of nefarious uses. These pieces of hardware contain an 8-bit AVR (micro controller, similar to a computers central processing unit), 256KB of ROM (program memory), 72KB of non-volatile (doesn't require power to store any data) EEPROM (flash based storage, this is where the SIM cards programming is stored), 6KB of RAM and operate at 20-30 MHz. These specifications, to anyone that has knowledge around computers and hardware are, to put it simply, astonishing; the possibilities of these devices are endless, and I can not exactly fathom how and why they have not yet been exploited on a large scale - as far as we know. As explained by Karl and Eric to modify and flash (upload your own code) a SIM card you need physical access to your victims card, along with some easily obtainable hardware to communicate with the card. However the flash based storage on most newer SIM cards can not be modified - so how can these devices be hacked in present day 2015? They explained that you must start from the beginning. Karl and Eric purchased blank SIM cards and flashed their own code onto them and gave them out to willing citizens who amazingly accepted free SIM cards, this was of-course a proof of concept operation and any recorded data was destroyed.

Unknown to many a programming language known as Java6 is found within most everyday pieces of hardware we take advantage of, especially those that have one main function such as a DVD player or the computer that controls the ice in a modern day refrigerator. A SIM card is no exception; these pieces of hardware run a variation of Java known as 'Java Card7'. This programming language creates applets (the final compiled version of your code) that leave a small memory footprint; perfect for the specifications of a SIM card. Oracle, the current owners of this software have released a free SDK8 (software development kit) to those of whom are interested in developing applets - this in theory is great for those of whom are interested in the technology and do not have the funds to purchase licences; it however allows malicious hackers to develop their own firmware for SIM cards that are intended to be distributed for free. SIM cards are given permission by the end users mobile phone to run applications both on the SIM card and devices background without the consent of the owner - this however is not an exploit or mistake; this is how GSM phones are designed and you are expected to have a legitimate SIM card. Early mobile phones are considered 'non-smart', this means only one thread/process can be run at any given time - think back to playing Snake on an old Samsung dot matrix phone, you are about to beat your personal high score when somebody calls you; your game is closed and score is lost. Due to a phone then being only single threaded your SIM card was important for processing incoming data such as phone calls and SMS messages, which would then alert your phone - this required a high level of permission and trust; sadly the technology and single-threaded 'mind-set' is still around today, even in modern day 'smart phones'. Try it for yourself; if you own an iPhone locate the menu item: settings->phone->SIM applications, if you are using an Android phone head to your application list and select the item "SIM toolkit" - these are applications that are currently installed on your SIM card and are running without your knowledge or permission. Having a malicious SIM card inserted into your phone will allow a hacker to run their own applets and intercept any incoming GSM data. Once you have an exploited card there is nothing that can be done with the exception of getting a new card - do not accept SIM cards from anyone unless they are behind a cash register and chewing gum; but you can not really trust them either.

The story of the exploitable SIM card will however not come to an end any time soon; they are simply too convenient to swap and replace and work exceptionally. Even with the chillingly confronting information provided, you as the audience will not cease to use the seemingly humble SIM card and ironically I myself will not either: we are the problem and the solution, we must want things to change before they actually will. However lets be honest, who actually cares about the alarming state of SIM card hacking, our service providers do not as the technology has not changed since the mid 1990's, you probably wont tonight or tomorrow either - by the way, I have a few spare SIM cards with free unlimited data plans, would you like one?

1http://www.imore.com/what-is-sim-card

2http://studenttravel.about.com/od/globalcommunication/a/stayconnected_3.htm

3https://www.youtube.com/watch?v=31D94QOo2gY

4https://www.defcon.org/

5http://en.wikipedia.org/wiki/Arduino

6http://java.com/en/


prev 1 2 3 4 5 6 7 8 9 next


page generated 2018-10-15 23:09:44 using sitegenerator