Pages

Tuesday, October 28, 2008

Unlock protected blocks in Siemens SIMATIC Step 7

Recently I'd been called by Hindalco's Fabrication Plant division to unlock the protected blocks in Siemens SIMATIC Step 7. They were in need to unlock those blocks since an year because of 1 million Rupees of loss per month. They want to re-program those blocks but it was locked by the man who'd done the setup. From the people working in that department, I came to know that they were trying to call that man (someone from Italy) right here but he's not coming. Actually, what he'd done was that he'd locked some of the blocks and deleted the source file. And Siemens didn't provide any feature to unlock. Department people also told me that even the people working in Siemens don't know how to do it. Being a software engineer I know that any thing can be reverse engineered. So I took up the challenge.

How did I unlocked the blocks?

The first thing I'd done was searched about this software at Google and read about what is this software all about. After that I'd explored the software. A person (might be S7 programmer) told me about 'Generate source' and shown me a sample by doing it. Further on he'd shown me how do they lock a block via KNOW_HOW_PROTECT. It was amazing, they just write this line (KNOW_HOW_PROTECT) inside a program after begin statement and compile the code. The compiled code is known as blocks. The blocks are now protected which means the code inside the block can't be seen by other. Then delete the source and your blocks are now protected.

Now my objective was to unlock those blocks. So I'd followed the steps given below to unlock those blocks,

Step 1: Download *.dbf file editor. The free DOS based dbf editor is the one I'd used. You can download it from, http://www.ks-soft.net/download/other/dbf_edit.zip

Step 2: Extract dbf_edit.exe from the zipped file. Put it somewhere to easily access it. I'd put it inside a folder named dbfedit in C: drive. So path to run the editor is C:\DBFEDIT>dbfedit.exe

Step 3: To unlock the blocks, copy a file named SUBBLK.DBF from ..\PROJECT\ombstx\offline\00000001\ folder where PROJECT is the directory containing your S7 Project. Paste this file inside C:\DBFEDIT\ folder.

Step 4: Open Command Prompt (DOS window) via clicking on

Start  Run  type 'cmd'  press enter
or
Start  All Programs  Accessories  Command Prompt

Step 5: Follow these commands,

C:\>cd dbfedit
C:\DBFEDIT>dbfedit.exe subblk.dbf


A DOS based application will open. Search for the PASSWORD column. And change all 3 into 0 to unlock the blocks. Press Esc/F10 key to save and exit.

C:\DBFEDIT>exit

Step 6: Copy the SUBBLK.DBF file inside C:\DBFEDIT\ folder and paste it at it's original location. Always remember to make the backup of original SUBBLK.DBF.

Step 7: Now open the project in SIMATEC Step 7 software. All the blocks are unlocked.

So my objective is completed successfully.

It took me around 3 hours to complete this for the first time. But after that I can do it within 5 minutes.

Have fun!

Monday, September 15, 2008

Scrypt – An alternate writing system.

Introduction
Scrypt is an alternate writing system inspired from the 12480 Alphanumeric System. But it is completely different from 12480 system because of its most important feature, that its symbols can be derived from the one base symbol. So it is completely logical & does not require memorizing any symbol. Due to which it is very easy to encode & decode, by following the rules.

12480 Alphanumeric System
12480 was designed in 2002 by Bradley Tetzlaff from Waukesha, Wisconsin, USA. It was invented for both use in a computer game named Ecclemony (1E78) and as a basis for constructed languages. It was also designed to show how a true alphanumeric (it is used here to describe the combination of an alphabet and a numeral system) writing system looks and works.

References:


Logic behind the name – Scrypt
Scrypt is an alternate script in essence. So to represent this, the spelling of the word ‘script’ has been modified at one place, from ‘i’ to ‘y’, that represent alternate but it’ll pronounce similar to the original word ‘script’.

Key feature of Scrypt:
  • Completely based on ASCII value.
  • Doesn't require remembering any symbol, as the whole script is based on just one symbol.
  • Each symbol represents a byte, i.e., 8-bits.
  • 100% logical.
  • All the symbols are completely unambiguous.
  • Very easy to encode & decode.
  • Each symbol is made up on binary numbers.

Symbol Creation
Each symbol is made up on binary number logic of 0 & 1. More conveniently we can call it, Hide & Show logic, where, 0 represents Hide & 1 represents Show.

All the symbols are based on the Fig.1,

Each bit (from left to right) of a byte is represented by a line (Horizontal/Slant/Vertical), like in Fig.2, where each number denotes the position on bit in a byte. If a bit is 0 then hide the corresponding line otherwise it won't. Hence a blue print of a symbol is created. Now to give each line a uniqueness, put another line just after the line, as shown in Fig.3. A symbol is now near completion. Just increase the length of second line little bit, so as to touch the corner/center-of-edge of virtual square. In short it should fit in the Fig.1.

Let us take an example to create a symbol,

A → ASCII code → (65) base 10 → (01000001) base 2 →

Here in 01000001, at position 2 & 8 it is 1 and at rest of the position it is 0. Applying our hide/show rule in Fig.3 by hiding the 0 positions, we’ll get this symbol,

Sample Text:

In English,
ABCDEFGHIJKLMNOPQRSTUVWXYZ
In Scrypt,


In English,
0123456789
In Scrypt,


Sample Conversion:

The quick brown fox jumps over the lazy dog.


Demo: The English to Scrypt converter

Tuesday, September 2, 2008

How to download a video from youtube or google-video?

After going through this article, you'll be able to download any video from youtube or google-video without using any online site or software tool.

But before that you've to understand the concept behind showing video on internet browser.

Actually, whenever you open a web-page having video, a flash video player in the form of swf is downloaded in your system's cache. When you click on the button or link to play the video, the player starts downloading a .flv file from the site to your system's cache.

Note the flash video player can play only .flv files and is programmed to start playing video if even a bit of the whole video-file is downloaded. This technique is known as video streaming.

Your system capture this video stream in the cache, from where the flash video player plays it.

In Internet Explorer cache it is displayed as a filename 'get_video' with a suffix of very very long encrypted code.

But you don't have to worry about that.

Just open your internet cache and search for the file name having a string 'get_video'. If you have watched the whole video on flash video player then only you'll find the required full video file in the cache. Otherwise you'll get a file having video upto where it is downloaded.

When you'll find the required file then copy that file somewhere else as you can't play that file right there because Window doesn't give permission to do that.

After copying that file somewhere else, rename the file to something meaningful & add the extension .flv.

Now you need an flv player to play this file. For this purpose, VLC player would be the best.

You can get VLC player from this site, http://www.videolan.org/vlc/

So download & install VLC player at your system and play your .flv file whenever you want.

There is a problem you could face, if you have watched many videos. As in that case there will be many get_video file present in the cache. So to get rid of the headache of finding the required one either clear the cache before opening the selected video on web-page or copy all the get_video file that is present in the cache to somewhere else and watch one by one & search for the required one.

If you don't want to watch the video but want to download the video then you can do that by using Opera internet browser. As it provides some advanced features.

You can download Opera from this site, http://www.opera.com/download/

After downloading & installing the Opera browser, open it and type the required url and open the site. Click on play button. Open another tab. Then go to Tools>Advanced>Cache & click on it.

Now find "get_video" string via Ctrl+F. You'll get the link to that video file. Click on that link & after few minutes a download window will pop up. Download this file on your desktop and rename it to something meaningful with an extension .flv.

You can play this file with VLC player.

Enjoy!!!

Saturday, May 31, 2008

How to Draw & Show Raster-Graphics in Internet Explorer via Pure HTML

Have you ever thought that if it is possible to draw raster-graphics, i.e., pixel based graphics in HTML? Isn’t it interesting if it could be possible?

So be ready to be amazed, because with the method that I’m going to describe, it’ll become possible.

Let’s start with the number of ways we can show graphics in our web-page. As we know, the standard ways are by using image tag, i.e., <img src="img_name.jpg"> and by using flash file, i.e., *.swf file (advanced way).

There is two more ways of doing this; one of them is by using CSS. But it is not supported by most of the web browsers. And I’m not going to describe that, as you could get many articles related to this on internet. Anyways let’s come to the point.

The fourth, most interesting way is by using pure html. This is the least known method, in fact nobody else has ever written about it.

So technically, the credit of its invention/discovery goes to me. ;)

The Technique!

We can create an image purely in HTML format by making a table similar to the size of the image, say 100 x 100; and defining the size of the cell equal to the size of a pixel, i.e., 1.

For example,
 <table cellspacing=0 cellpadding=0>  
   <tr>  
     <td bgcolor=#FF0000 width=1></td>  
   </tr>  
 </table>
The above code will show a single pixel of red colour on IE (Internet Explorer).

So if we can create on pixel, then we can also create a matrix of pixels. That means we can create an image which is in fact a matrix of pixels.

The technique is to define a colour for each & every cell, i.e., , of the table.

How this has become possible?

By defining the width of the cell equal to 1 and making cellspacing & cellpadding equal to 0.

Is the technique to lengthy? No problem!

To ease this job, I’ve created few functions in PHP.

Required Functions:
 // This function converts the given 2-D array of colours into HTML table of coloured cell.
 function MatrixToPixel($Matrix)  
 {  
   $output = "<table cellspacing=\"0\" cellpadding=\"0\">";  
   for($i=0; $i<count($Matrix); $i++)  
   {  
     $output .= "<tr>";  
     for($j=0; $j<count($Matrix[$i]); $j++)  
     {  
       $output .= "<td bgcolor=\"".$Matrix[$i][$j]."\" width=\"1\"></td>";  
     }  
   $output .= "</tr>";  
   }  
   $output .= "</table>";  
   return $output;  
 }

 // This function formats the given 2-D array by changing null value into the given value.  
 function FormatMatrix($Matrix,$bgcolor)  
 {  
   for($i=0; $i<count($Matrix); $i++)  
   {  
     for($j=0; $j<count($Matrix[$i]); $j++)  
     {  
       $Matrix[$i][$j] = ($Matrix[$i][$j] == null)?$bgcolor:$Matrix[$i][$j];  
     }  
   }  
   return $Matrix;  
 }  
Now, you have to use this function for conversion purpose. See below.

Sample1:
 function setPixel($val,$x,$y,$arr)  
 {  
   $arr[$x][$y] = $val;  
   return $arr;  
 }  

 function circlePoints($cx, $cy, $x, $y, $pix,$arr)  
 {  
   $act = $pix; //"#FF0000";  
   if ($x == 0)  
   {  
     $arr = setPixel($act, $cx, $cy + $y,$arr);  
     $arr = setPixel($pix, $cx, $cy - $y,$arr);  
     $arr = setPixel($pix, $cx + $y, $cy,$arr);  
     $arr = setPixel($pix, $cx - $y, $cy,$arr);  
   }  
   else if ($x == $y)  
   {  
     $arr = setPixel($act, $cx + $x, $cy + $y,$arr);  
     $arr = setPixel($pix, $cx - $x, $cy + $y,$arr);  
     $arr = setPixel($pix, $cx + $x, $cy - $y,$arr);  
     $arr = setPixel($pix, $cx - $x, $cy - $y,$arr);  
   }  
   else if ($x < $y)  
   {  
     $arr = setPixel($act, $cx + $x, $cy + $y,$arr);  
     $arr = setPixel($pix, $cx - $x, $cy + $y,$arr);  
     $arr = setPixel($pix, $cx + $x, $cy - $y,$arr);  
     $arr = setPixel($pix, $cx - $x, $cy - $y,$arr);  
     $arr = setPixel($pix, $cx + $y, $cy + $x,$arr);  
     $arr = setPixel($pix, $cx - $y, $cy + $x,$arr);  
     $arr = setPixel($pix, $cx + $y, $cy - $x,$arr);  
     $arr = setPixel($pix, $cx - $y, $cy - $x,$arr);  
   }  
   return $arr;  
 }  

 function circleMidpoint($xCenter, $yCenter, $radius, $c)  
 {  
   $Matrix = array();  
   $pix = $c;  
   $x = 0;  
   $y = $radius;  
   $p = (5 - $radius*4)/4;  
   $Matrix = circlePoints($xCenter, $yCenter, $x, $y, $pix, $Matrix);  
   while ($x < $y)  
   {  
     $x++;  
     if ($p < 0)  
     {  
       $p += 2*$x+1;  
     }  
     else  
     {  
       $y--;  
       $p += 2*($x-$y)+1;  
     }  
     $Matrix = circlePoints($xCenter, $yCenter, $x, $y, $pix, $Matrix);  
   }  
   return $Matrix;  
 }  

 echo MatrixToPixel(FormatMatrix(circleMidpoint(50, 50, 50,"#FF0066"),"#FFFFFF"));  
This will draw a circle of pinkish-red colour.

Sample2:
 function lineSimple($x0, $y0, $x1, $y1, $pix)  
 {  
   $Matrix = array();  
   $dx = $x1 - $x0;  
   $dy = $y1 - $y0;  
   $Matrix[$x0][$y0] = $pix;  
   if ($dx != 0)  
   {  
     $m = $dy / $dx;  
     $b = $y0 - $m*$x0;  
     $dx = ($x1 > $x0) ? 1 : -1;  
     while ($x0 != $x1)  
     {  
       $x0 += $dx;  
       $y0 = round($m*$x0 + $b);  
       $Matrix[$x0][$y0] = $pix;  
     }  
   }  
   return $Matrix;  
 }  
 echo MatrixToPixel(FormatMatrix(lineSimple(10,10,100,100,"#FF0066"),"#FFFFFF"));  
This will draw a slant line of pinkish-red colour.

So you see we can draw graphics on Internet Explorer with pure HTML.

Fig: The screen-shot of the result generated by above code.

Fig: The screen-shot of the result generated by above code.

The only thing to keep in mind is this …

Drawbacks: Bigger the image, bigger will be its file size & longer will the processing time therefore longer would be loading time.

Limitations: It is supported by Internet Explorer only.

Usefulness: But it is useful in case of small images, say for about 10 x 10. As it could become highly dynamic with little more coding.