Simple python diffing script

The one of the first thing to do in case of n-day vulnerability analysis of an open sourced software is to find out the location of patched code. In some cases this is trivial step which is done just by looking into commits of git repositories, however in some cases, the intention is to hide the security patch or there is no repository available at all.

When there are multiple files within the folder or even the subfolders manual work of identifying changed files one by one is not only boring but also inefficient.

I was trying to find out some software that solves that problem at first but after one disappointing attempt I've decided to write simple python script that solves my problem.

The provided script is not intended to be perfect as there are some limitations by design but it provides an extendable baseline. I believe there are also better solutions for the problem, so if you have a tip don't hesitate to give a comment what you use.

Here is an example of script output from real case scenario..

python cmpfolder.py _Drupal/2018-075/gathercontent/ _Drupal/2018-075/gathercontent-2/ -d
_Drupal/2018-075/gathercontent/gathercontent.install   <--->  _Drupal/2018-075/gathercontent-2/gathercontent.install
441,448d440
<  * Fix permissions on views.
<  */
< function gathercontent_update_7311() {
<   ctools_include('object-cache');
<   ctools_object_cache_clear('view', 'mapping');
< }
< 
< /**

_Drupal/2018-075/gathercontent/gathercontent.module   <--->  _Drupal/2018-075/gathercontent-2/gathercontent.module
540c540
<             $handler = entity_translation_get_handler('node', $node->value());
---
>             $handler = entity_translation_get_handler('node', $node);

_Drupal/2018-075/gathercontent/gathercontent.info   <--->  _Drupal/2018-075/gathercontent-2/gathercontent.info
37,38c37,38
< ; Information added by Drupal.org packaging script on 2018-11-28
< version = "7.x-3.5"
---
> ; Information added by Drupal.org packaging script on 2018-08-07
> version = "7.x-3.4"
41c41
< datestamp = "1543419184"
---
> datestamp = "1533634986"

_Drupal/2018-075/gathercontent/views/gathercontent.views_default.inc   <--->  _Drupal/2018-075/gathercontent-2/views/gathercontent.views_default.inc
21,22c21
<   $handler->display->display_options['access']['type'] = 'perm';
<   $handler->display->display_options['access']['perm'] = 'administer gathercontent';
---
>   $handler->display->display_options['access']['type'] = 'none';
263,264c262
<   $handler->display->display_options['access']['type'] = 'perm';
<   $handler->display->display_options['access']['perm'] = 'administer gathercontent';
---
>   $handler->display->display_options['access']['type'] = 'none';

The script

import os
import hashlib
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("dir1", help="directory1", type=str, action="store")
parser.add_argument("dir2", help="directory2", type=str, action="store")
parser.add_argument("-d", action="store_true", required=False, help="perform diff on files")

args = parser.parse_args()

def getFileHash(path):
    with open(path, "rb") as fH:
        h = hashlib.sha256()
        data = fH.read()
        h.update(data)
        return h.hexdigest().upper()

def findDiff(src, dst):
    srcContent = os.listdir(src)
    dstContent = os.listdir(dst)

    for i in srcContent:
        srcPth = src + os.sep + i
        dstPth = dst + os.sep + i

        if os.path.isfile(srcPth):
            if os.path.isfile(dstPth):
                if getFileHash(srcPth) != getFileHash(dstPth):
                    print ("\n{0}   <--->  {1}".format(srcPth, dstPth))
                    if args.d:
                        os.system("diff {0} {1}".format(srcPth, dstPth))
            else:
                print ("{0} is missing".format(dstPth))
        elif os.path.isdir(srcPth) and os.path.isdir(dstPth):
            findDiff(srcPth, dstPth)

findDiff(args.dir1, args.dir2)

Kid dream part X: Terrain texturing

As you might know I am able to generate interesting terrain meshes, now it is time to get some real look, so how? The answer  is simple - apply appropriate texture to the terrain mesh :-). How to get it? I bet that the best solution is to generate it procedurally, since the terrain is generated the same way..

The basic step is to generate terrain mesh, the mesh should be smooth. If not the result will be similar as on the following images.

base_mesh
rock_cover

Continue reading

Kid dream part IX: Map and terrain generation

It has been a while since my last post. During that time I was trying to understand terrain generation techniques which I  will describe in this blogpost. It is the most interesting part that I've learned during the game development.

Main objective
The main goal is to advance from Transport Tycoon style map on first picture to map style which  you can see on the second picture.

The actual Map Editor eroded_fourier
transport tycoon style new style

The big question is: "How to achieve it?" Well there are several options how to do that. However, I didn't want to do a lot of handwork. So instead tile based map as I was trying to use this in the first Map Editor I was looking for something more cool. Continue reading

Kid dream part VIII: Multi-platform game loop

This article will be more technical then the previous ones and as I promised it will be about creating multi-platform game loop. I will set up objectives which I want to achieve then I describe some available options and finally tell you about my solution.

Objective
The main goal is to create game that will run on Windows, Linux, Mac OS X as well. I would like to keep it simple and with minimum platform dependent code. The first step is to render simple screen covered by "space" texture and displayed text on the bottom of the screen.

Continue reading