DotSlashZero

FWMFW: A Simple Firewall Utility

2015 April 20

When I was trying to prevent an application from connecting to the internet, I found out that in many cases, adding the main executable is not enough -especially if this executable attempts to launch another executable and/or this certain executable is communicating with a different executable to perform network operations. I had to either add all of the related executables to the firewall rules or completely disconnect the machine from the internet. While the second solution is probably the most effective, I rather want to be able to still use the internet for other purposes while isolating other executables from connecting outside. Adding each and every of the related executable is very tedious so it becomes frustrating to keep doing it.

To solve this problem, I decided to write a simple utility called FWMFW. The name stands for “FireWall Manager For Windows”, but that is actually a little bit misleading at the moment. The current state of the utility does not provide a full working firewall manager for Windows (perhaps in the future). It is, however, enough to solve my problem as I mentioned earlier. I can simply provide a list of files and folders to this utility, and it will go through the list and add a firewall block rules for each of the items.

On this blog posting, I will discuss the internals of using COM Interop to achieve such functionality.

Read more →


Language Binding Tutorial Part 5: Objective-C

2015 March 21

We are continuing the next part of this series about language bindings. On this post’s topic is about creating a thin API layer for Objective-C. A good use case for this scenario is when one wants to use a native library (in C or C++) in an iOS project. Of course, one can simply use the C/C++ API directly within his/her Objective-C code, but I highly discourage this as it introduces high coupling. This is also a big issue when the C/C++ API gets updated (or some API gets deprecated).

This topic will be short as most of the concepts from the 1st and 2nd parts of this series will carry over here. So if you haven’t had the chance to read my article about C++ language bindings, please do so before continuing.

Read more →


Language Binding Tutorial Part 4: C#

2015 February 14

In the previous tutorial, we have covered how to make a thin Java API layer on top of an existing native library that we wrote. This is done by using the Java Native Interface (JNI) feature of the Java language. As we all know, Java uses a virtual machine to perform just in time compilation, so things a little more complex that adding a C++ layer over a native library.

This time we will be going over how to create an API binding library for C# (and other .NET languages as effect) on top of the native library we wrote. Just like the previous tutorials, some concepts here are started from previous topics.

Read more →


Language Binding Tutorial Part 3: Java

2014 December 22

We have covered the basics (and some advanced topics) in making a language binding for a native library. In our previous discussions, we wrote a simple native library in C (for higher compatibility) and provided the necessary middle layer so that the C objects can be used in C++ in an object oriented manner. In this article, we will go over adding an API for Java. We will be taking what we have worked on the previous topics and will be adding on top of it.

Read more →


Language Binding Tutorial Part 2: Advanced C++

2014 October 04

In the previous part of this series, we have covered basics on how to properly design a native library so that we can create a middle layer to allow it to be interfaced in other languages. Of course, the solution provided in the previous lesson (and any future lessons from here on in) are not silver bullet solutions. We just covered (and will continue to do so) necessary points that allows us to write a clean interface.

We have also created a simple native library in C and have written a C++ interface for this. On this part of the lesson, we will covering advanced topics about C++. In particular, we will be going over callback system.

Read more →


Language Binding Tutorial Part 1: C and C++

2014 September 18

Over the next few months, I will be posting a series of lessons about binding languages. What is a language binding? A language binding is a way to make an interface of a language communicate to another. For example, if we are provided with a C library, how can we use this in Python? This is where a middle layer must come to play. The role of this middle layer is provide a channel for C and Python to communicate with each other. The goal of this lesson series is to provide us with basic knowledge and starting point on how we would achieve such middle layer. This series is divided into the following parts (grouped by languages):

In my personal experience, once you get the hang of creating a middle layer between C/C++ and Java, the rest pretty much follows the same patterns and pre-cautions. As mentioned, these lessons are just simply to get the gears oiled. Not every case I will mention here is a silver bullet solution. The design and implementation varies and you will always need to evaluate your best option. I will, however, try to describe as much of the potential issues one commonly goes through when writing these middle layer module.

Read more →


Understanding Character/String Literals in C/C++

2014 August 22

In the latest published standard of C (ISO/IEC 9899:2011) and C++ (ISO/IEC 14882:2011), there are new character literal types introduced, these standards now give us 5 different character literal types. These are the following:

  1. char literal type (surrounded by single quotes, e.g. 'A').
  2. wchar_t literal type (surrounded by single quotes with L prefix, e.g. L'A').
  3. multi-character literal type (like char literal type, but has two characters instead, e.g. 'ABCD').
  4. char16_t literal type (surrounded by single quotes with u prefix, e.g. u'A').
  5. char32_t literal type (surrounded by single quotes with U prefix, e.g. U'A').

In addition to that, the standard has also added new string literal types. The following are ways to create string literal types in C11/C++11:

  1. char string literal type (surrounded by double quotes, e.g. "ABC").
  2. wchar_t string literal type (surrounded by double quotes with L prefix, e.g. L"ABC").
  3. UTF-8 string literal type (surrounded by double quotes with u8 prefix, e.g. u8"ABC"). This string literal’s character type is char, so to reference this literal, the variable must be of type const char*.
  4. char16_t string literal type (surrounded by double quotes with u prefix, e.g. u"ABC").
  5. char32_t string literal type (surrounded by double quotes with U prefix, e.g, U"ABC").

The goal of this blog post is to cover correct values/characters that can be used inside the character and/or string literal types. In particular, using Unicode characters will be given emphasis. All code snippets provided in this post have been verified with GCC 4.8.3 for C11 and clang 3.4 for C++11.

Read more →


2014 July 17

Printing, whether to standard output, file, network, or any other stream, is a big part of writing programs. After all, programs are supposed to interface with something and interfacing requires some form of I/O (I/O in a sense that data are exchanged). When we print a variable in C, we use the common functions:

Using any of these functions to print a variable requires us to know the type and the size of the variable we want to print, as well as how we will be presenting them. The table provided by cppreference.com shows a very good guide which format specifier must be used with the specific type to get the output that we want. In this blog post, we will look at ways to properly use these functions with the <stdint.h> header file.

Read more →


The Interesting State of Unicode in C

2014 May 21

My previous technical article discussed about Unicode in general. This time, I want to briefly cover the C (and C++) aspects of it. When I wrote project UniCString, I was looking for a way to include support for the new C11 character types, namely char16_t and char32_t. If you browse the source tree of project UniCString, you will notice that the core implementation does support these types, but the support is limited to how the project itself interprets the bits of char16_t and/or char32_t. In this blog post, I will quickly summarize my findings about these data types.

Read more →


Unicode: A Small Walkthrough

2014 May 17

I am not going to justify why you should learn Unicode or not. Joel Spolsky already provided more than enough rationale for you to do so. Here I will attempt to quickly explain how Unicode character sets are encoded in UTF-8, UTF-16, and UTF-32 encoding schemes. Of course, one can easily go to the following Wikipedia pages, but this post will put the three together for an easy reference.

So why cover those three encoding schemes? What about the others? I decided to cover the three as they are the most commonly used Unicode encoding schemes. UTF-8, which I am sure you are aware, are used in many websites. There are still non-Unicode pages in circulation, but UTF-8 is dominant in this area. UTF-16 is the most popular choice of storing Unicode character in memory (more to this later). And UTF-32 is a simple encoding scheme to represent a Unicode character which is gaining traction in usage.

Read more →



DotSlashZero © Vincent Ycasas 2014