Tuesday, 16 April 2013

Extracting ZLIB compressed data from any file

This is very usefull for analysing file formats that contain compressed data.

You can use a handy tool by Luigi Auriemma found here http://aluigi.altervista.org/mytoolz.htm#offzip

Extract it and put it in a directory somewhere, for example

Make sure you choose a drive with lots of space.

In the directory, make a bat file called extract.bat
With these contents

mkdir %1.out\
offzip -a %1 %1.out\ 0

this will make a directory for your extracted data to go into so things don't get messy it will be the file name with .out at the end of it.
Then it will instruct offzip to find all compressed data it can in your file and extract the parts out into the directory made. It will start from offset 0

You can see the address the compressed data was found at in its filename.

Quite handy.

I also came across a great blog here, http://www.se7ensins.com/forums/threads/tut-how-to-mod-darksiders-using-offzip-and-packzip.153898/
Which shows how you can, extract->Edit->pack back in to edit game save files.

Writing Node.js modules

So from making a server side emulator for a mmorpg in node.js I have learnt some ways to make modules.

Here I will be sharing some of the ways to write them

<script type="syntaxhighlighter" class="brush: js"><![CDATA[

(function() {
// Put any requires your module needs here

var YourObject = function(func) { // Has example of passing in a callback,
// Any private values you could put here
var something = 1;

// Here is where you can put public propertys and what not
   this.Something = 1; // public propertys here

   if (func) this.func = func; // Overrides the prototype func

// You can also put public/protected functions here using prototype
YourObject.prototype = {
        func: function() { console.log('Not yet implemented'); } // Used if func not passed in as paramater :)
getID: function() { return this.ID; },
getName: function() { return this.Name; },

module.exports = YourObject;

//To make it work on web client and node.js server
var obj = new YourObject();
//Or you could use reference to your object rather than an instance of it depending if you want to create more of it or only have 1

if(typeof module !== "undefined" && module.exports) {
    module.exports = obj;
if(typeof window !== "undefined") {
    window.YourObject = obj;

Simple eh. In node to have private functions I guess you could put them in the scope outside your object.
But in web browsers this may pollute the global scope.