Author image

Pointer to Implementation (Pimpl) - Bridge Design Pattern


In the non-C++ world Pimpl is otherwise known as the Bridge design pattern, with the following definition:

Decouple an abstraction from its implementation so that the two can be extended independently.

In the vain of Bridge, in C++, when anything in a header file class definition changes, all users of that class must be recompiled - even if the only change was to the private class members that the users/clients of the class cannot even access. This is because C++'s build model is based on textual inclusion, and because C++ assumes that callers know two main things about a class that can be affected by private members: 1. Size and Layout 2. Functions

Because private data members of a class participate in its object representation, affecting size and layout, and because private member functions of a class participate in overload resolution (which takes place before member access checking), any change to those implementation...

Author image

Prototype Design Pattern


Implementing Prototype Design Pattern like a boss and then laughing it off.
Bonus: coool way of spawning arrays of objects from a prototypical instance (check spawnMonsterArray).

The prototype pattern is a creational software design pattern, that is used when the type of object(s) to create is determined by a prototypical instance, which is cloned to produce new objects. This pattern is used to:

  • avoid subclasses of an object creator, like the factory pattern does
  • avoid the inherent cost of creating a new object in the standard way (like using new) when it can be prohibitively expensive for a given application

Design

  • define an abstract Prototype class with a clone() method that returns a copy of itself
  • create subclasses of Prototype . These will...

Author image

Builder Design Pattern


An introduction to the Builder software design pattern along with a fancy example, which will make you go from Zero-to-Hero in no time on becoming a master Bob the Builder!

The Builder pattern is designed to provide a flexible solution to various object creation problems in OOP. We intend to separate the construction of a complex object from its representation.

Advantages

It provides control over the individual steps in the object construction process such that we can better customize object representation. This benefit really shine when we have big complicated classes.

Disadvantages

It requires a separate Builder class for each type of such complex object and it makes dependency injection harder to work with since introducing many dependencies can get things out of hand.

Also it increases code size and almost doubles the amount of memory required since almost all variables...

Author image

Factory Design Pattern


Definition:

Define an interface for creating an object, but let subclasses decide which class to instantiate.

Description

The factory function is used to create an object of any type of subclass of a base class.
Instead of creating objects like this:

ObjectType* o = new SubObjectType{args};

we create them like this:

ObjectType* o = newSubObjectType{args};

Where newSubObjectType is the factory function's name. Yes, the factory is nothing more but a construction function for objects; it's typically a global/free function (not a method).

You might wonder, what is the usefulness of this design pattern?

Well, that's a legitimate question. I use the Factory pattern, when all the potential classes I'd like to create are in the same subclass hierarchy, but...

Author image

Alien Space Battle - Space Invaders lookalike Game


Want to get familiar with Python Pygame library (like I did)? Then check this "2d Space Invaders game clone" out! Pygame hides many of the down and dirty implementation details and all you're basically left to do is create the game logic. If you want to do something similar this project will surely help you.

Author image

Memory Allocators Galore

Allocators are strange creatures in the C++ bestiary, but they are key to understanding the language internals. Are you fascinated by memory allocation in the lower level? Well you've come to the right place!

This projects encompasses my efforts around creating some of the most popular memory allocators and it will serve as a reference point henceforth:

  1. Pre-C++11 default allocator (DefaultAllocator & TrackingAllocator projects)
  2. C++11 compatible allocator replacements (Allocators & AlignedAllocator projects)
  3. Linear (aka Arena) allocator (LinearAllocatorproject)
  4. Stack Allocator (StackAllocator &...

Author image

Buffer Overflow Tutorial


This is a Buffer overflow tutorial using linux Ubuntu and C programming. There is full explanation and code in Greek only at the moment in “Nikos_Lazaridis_M1485_Project#2_ΥΣ13_ΕΑΡΙΝΟ_2017.pdf”. I may be motivated to translate this in English if I see any traffic.

! During Buffer Overflow:
The ultimate goal of a Buffer overflow attack is replacing the return address of a vulnerable/unsecure function with another one of our choosing. The latter function will have "ASCII shellcode" placed into it, which will execute the attacker's desired code (WE are the attacker here); the sky's the limit with what the attacker can do (more like the imagination of the attacker). “Buffer Overflow” occurs the moment where a single byte is written in the return address...

Author image

Code Injection


Code injection is a technique where you can insert code into a process and then reroute its execution to traverse through your injected custom code segment.

Working from a debugger eg. OllyDbg, we can search for “code caves”, ie. sequences of nop (or "DB 00" in Olly) instructions that are large enough to "fit" our custom code.

Alternatively we can also allocate more memory in the target process to store the code. This is what we will do in this case.

One of the best ways to inject code is via dlls, because they are meant to be loaded by multiple processes at runtime.

Compulsory ingredients:

  1. injector process - DLLInjector project - the process that will "inject" the code,
  2. the process to inject - ProcessToInject project - the...

Author image

English Greek Dictionary C++ Program - Serialization


C++ console implementation of an English - Greek Dictionary.

Depends on Boost serialization module which is included.

There is no Gui - everything is done in the console, for the time being.

Incomplete. There's a bug currently I've yet to correct.

The tricky aspect of this program is proper support of UTF-8 and Unicode, which is a pain beyond imagination in Windows. Despite that, I've managed to succeed (check this SO post -made by me- for this issue ), but I'm also victim of another obscure serialization error which I haven't had much time to dedicate in fixing it.

This is what it looks like. I provide a demo with some sample words.

Author image

Function Reference


My implementation of a functionRef/functionView variant. Why? I desperately wanted to know just how std::function<> works. So I scoured the tutorials, books what have you, in order to find more information and ended up creating a sort of lightweight variant of it.

The skills you need to have under your belt before attempting this tutorial are:

  1. Type erasure.
  2. callable objects
  3. std::invoke
  4. higher order functions
  5. lambda calculus - just a smattering knowledge

Based on std::function, functionRef is a non-owning wrapper for an arbitrary callable object.

Implementation notes:

  • A primary template is used to match the complete type of a callable, say void( int, int ) or int. The primary template remains an empty struct.
  • We want to differentiate the function type...

1 2 3 4 5