Pages

Search

Tuesday, May 26, 2009

how to bypass Pc Security all versions

hi all,
about 6 months ago in our college they decided to restrict us with some kind of software which is its task is to lock folders and drives and so many other cool things.
well on that time I wasn't so curious about that until one of my friend told me that he is in trouble with these kind of crappy restrictions.

after that I start to investigation on "pc security" and the solution was simple and funny.

when you install this s/w on your computer it will put 2 exe files in your windows directory and startup called:

winwd.exe
sdeamon.exe

and if you bring on the task manager you gonna find them there and if you try to end task these two files you will see they gonna start their job again.

well at first try I start to rename them from windows directory and then try to kill them from task manager and BINGO it was successful try.
it is quite easy first try to rename or delete these two files from windows directory then kill them from task manager.
I also write a tiny c++ code for automating this task :

//code in vc++.net 2008
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR windiro[INFO_BUFFER_SIZE];
TCHAR windir[INFO_BUFFER_SIZE];
TCHAR exec[8];
TCHAR s1[]=_T("\\sdeamon.exe");
TCHAR s2[]=_T("\\winwd.exe");
_tprintf(_T("bypassing pcsecurity \n"));




GetWindowsDirectory(windir,INFO_BUFFER_SIZE);
GetWindowsDirectory(windiro,INFO_BUFFER_SIZE);
_tcscat(windir,s1);
_tcscat(windiro,s2);
_tprintf(windir);
_tprintf(windiro);

DeleteFile(windir);
DeleteFile(windiro);
HINSTANCE nr = ShellExecute(NULL,_T("open"),_T("taskkill"),_T("/f /im sdaemon.exe"),_T("C:\\"),SW_SHOWNA);
HINSTANCE nr1 = ShellExecute(NULL,_T("open"),_T("taskkill"),_T("/f /im winwd.exe"),_T("C:\\"),SW_SHOWNA);
if (nr == 0)
_tprintf(_T("successful"));
else
_tprintf(_T("unsuccessful"));
int i;
_tscanf(exec);
return 0;

}

Njoy.

how to execute asp.net files with different extension

Hi again.
You might be wondering that sometimes some websites choose different extensions for their web pages as an instance their web site is build by asp.net and you are supposed to see aspx extension at the end of their address but it is not like that you will see something like acme.

Well here I'm gonna show you how to make change.
thanks to the Microsoft and his new understanding of how to build our life easier, this job will done only in matter of 5 minutes or less .

go to your WINDOWS\Microsoft.NET\Framework\{frame work version}\CONFIG

here you will find the heart of your asp.net config files such as machine.config , web.config , etc...

open web.config

and follow the below XML file





<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>

<handlers>
<add name="ASPNETLikeHandler-Classic" path="*.acme"
verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll"
requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness32"
/>
<add name="ASPNETLikeHandler" path="*.acme"
verb="GET,HEAD,POST,DEBUG" type="System.Web.UI.PageHandlerFactory" modules="ManagedPipelineHandler"
requireAccess="Script" preCondition="integratedMode" />
</handlers>

<validation validateIntegratedModeConfiguration="false" />
</system.webServer>

<system.web>
<compilation>
<buildProviders>

<add extension=".acme" type="System.Web.Compilation.PageBuildProvider"
/>
</buildProviders>
</compilation>
<httpHandlers>

<add path="*.acme" type="System.Web.UI.PageHandlerFactory"
verb="*" />
</httpHandlers>
</system.web>
</configuration>




I assume that your familiar with how to make changes in web.config.
ciao.

Monday, May 25, 2009

catching captcha image part 1 C#

Hey there,
Today I had a nice experience with a spammer software which was written by c#.net and it was packed by .net reactor .
I was astonished that how come the programmer was able to trick blog site according to their captcha system.
because their way of implementing the captcha system is horribly hard to expose , sometimes I was thinking by myself that how can I mess with this captcha thing.
Well today I was lucky and got my answer and that poor programmer was unlucky .
I unpack his code and understand several things which I'm going to sum up them :
1- if you wana write a spammer most of the times you can't use webclient or webrequest classes well you should do it by the help of webBrowser or shdocvw which ever you are comfortable with.

2-suppose you navigate a site , something like "www.acmeblog.com" you should wait until the document load full in your container how can we wait that much?
using DocumentCompleted event
or
using something like following:
while (webBrowser.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
until it is loaded it is not going to do anything except loading your page.

I cross my heart that just two things I've learnt from that lame programmer, I got rest of these tips by my own A$$:

3-In some websites getting captcha picture is a hard job first of all maybe it's not going to show itself at first until you fire some other events like focusing on some textbox or clicking a button well you should use a bit of knowledge of how to deal with javascript and how to find the badboy in a goodplace, well I did it by the help of firefox and firebug to find the which script was being run (I'm not gonna teach how to use firebug).

to execute the script by your self and on your own way you can accomplish this task by using :
WebBrowser.Document.InvokeScript("your_script_name");

4-sometimes the web designers fantasize that they are very clever and they can do something that no one else can do that in all around the world !
can you imagine how stupid they are???
well they are going to show captcha image without any name or id tag i mean something like below:


< src="hxxp://acmeblog.com/comments/Captcha.ashx?6233633">



as you can see there is no clue that gonna help us to get the src tag.
well how can we overcome this problem? easy peasy japanesey

with the help of foreach{} statement and search inside htmlelement we can find out our sweat captcha , you can see in the following :

foreach (HtmlElement img in wb.Document.Images)
{

isitcaptcha = img.OuterHtml.IndexOf("Captcha", 0);
if (isitcaptcha > 0)
{
captchaimg = img.OuterHtml.ToString();
.
.
.

5-well we've got our captcha source till now, then we have to be nimble and show this captcha quickly otherwise again the web designer will think that he was much smarter than you.
by showing the image inside a webBrowser you can have a copy of that captch on your own.

6-last and worth one : how to save that goddamn captch image out of my webbrowser?
believe me or not it is a very tedious job I was searching around 6 hours through the libraries (I mean .net library not a goddamn ordinary library where people going there and read Harry Potter)
Internet and my books until I found this useful webblog and his tricky way of saving webbrowser pictures.

below you can find a very first edition of what I've done :

http://rapidshare.com/files/237216229/spam_test.rar


inside code you will find a bunch of comments nonsense don't worry they are written in Persian and they won't harm you ;)

next episode I will teach you how to OCR captcha and retrieve it as a text :D

ciao.

Tuesday, March 24, 2009

How to draw rectangles from a given graph removing the common vertical lines using JavaScript.

Please refer
Draw line using third party java script file

As explained in above post that the third party java script file makes our task very easier to draw objects.
Now by using this java script file, I would like to share my HTML page and java script code to generate below.
Output:



Note : This is a basic HTML page, so it is not specific to technology
Input :-
User enters number of rectangles in input text box and clicks on “Generate rectangles”, to generate random rectangles.
It should generate mentioned number of rectangles with random height and width but base lined bottoms (similar to a graph).



When user clicks on “Generate button” giving number of input rectangles as 10.



Now output: When user clicks on “Generate Output”, we should draw those rectangles as shown below.




Removing the vertical lines between rectangles to display as union but at last the area of all these output rectangles should be same as are of all input rectangles.
Note:
If you would like to copy the below HTML page to run, Make sure that the third party graphics JavaScript file is downloaded into your machine and placed in this application folder where you are creating this HTML page.
Down third party JavaScript file by clicking here
wz_jsgraphics.zip download
HTML File :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Rectangles</title>
<link rel="stylesheet" type="text/css" href="Styles/Stylesheet.css" />
</head>
<body>
<div id="Canvas" style="position:relative;height:5px;width:5px;"></div>
<script type="text/javascript" language="javascript" src="wz_jsgraphics.js"></script>
<script type="text/javascript" language="javascript">
var jg = new jsGraphics("Canvas"); // Use the "Canvas" div for drawing
</script>
<script type="text/javascript" language="javascript">
var orgX=50;
var orgY=200;
var minWdth=20;
var minHght=30;
var maxWdth=60;
var maxHght=120;
var rndFactor=10;
var opShft=150;
var lnCntr=0;
var tmr=50;
var iprects=null;
var oprects=null;
var argCnt;
var inpCntr=0;
var rects=new Array();
var ipTmr=50;
var optmr=50;
var recCntr=0;
function rect()
{
var width;
var height;
var id;
var x1;
var y1;
}
function generaterectangles_clk()
{
var txtRec=document.getElementById('txtRects');
if(txtRec.value=='')
{
alert('Please enter number of rectangles to generate');
txtRec.focus();
return;
}
if(!IsNumber(txtRec.value))
{
alert('Please enter numeric value');
txtRec.focus();
return;
}
var numRects=txtRec.value;
if(numRects<3 || numRects>30)
{
alert('Number of rectangles to generate should be between 3 and 30');
txtRec.focus();
return;
}
orgX=50;
orgY=400;
argCnt=numRects;
inpCntr=0;
rects=new Array();
GenerateRects();
}

function GenerateRects()
{
inpCntr++;
if(inpCntr<=argCnt)
{
var rand_no;
var recWth,recHgt;
rand_no = Math.random();
recWth=Math.floor(minWdth+(maxWdth-minWdth)*rand_no);
recHgt=Math.floor(minHght+(maxHght-minHght)*rand_no);
var objRect=new rect();
objRect.width=recWth;
objRect.height=recHgt;
objRect.id=(inpCntr);
rects[rects.length]=objRect;
DefineRects(rects);
setTimeout('GenerateRects();',ipTmr);
}
else
{
var divdisp=document.getElementById('div_recIndx');
divdisp.style.display='none';
divdisp.innerText='';
}
}
function dispRecIndex(x1,y1,txt)
{
var divdisp=document.getElementById('div_recIndx');
divdisp.style.display='block';
divdisp.innerText=txt;
divdisp.style.left=x1;
divdisp.style.top=y1;
}
function DefineRects(argRects)
{
jg.clear();
var x1=orgX;
var y1=orgY;
var buf=5;
var crd=findPosition(document.getElementById('div_map'));
var maxY=crd[1]-buf;
var maxX=document.getElementById('div_map').offsetWidth+crd[0]-buf;
var minY=crd[1]-document.getElementById('div_map').offsetHeight;
var minX=crd[0];
var objRect=new rect();
for(i=0;i<argRects.length;i++)
{
objRect=argRects[i];
if(x1<maxX && x1>minX)
{
objRect.x1=x1;
objRect.y1=y1;
x1+=objRect.width;
}
else
{
for(j=i;j<argRects.length;j++)
argRects[j]=null;
break;
}
if(y1<maxY && y1>minY)
{
objRect.y1=maxY;
}
argRects[i]=objRect;
}
iprects=argRects;
for(i=0;i<argRects.length;i++)
{
if(argRects[i]==null)
break;
objRect=argRects[i];
var xc=new Array();
var yc=new Array();
xc[0]=objRect.x1;
yc[0]=objRect.y1;
xc[1]=objRect.x1+objRect.width;
yc[1]=objRect.y1;
xc[2]=objRect.x1+objRect.width;
yc[2]=objRect.y1-objRect.height;
xc[3]=objRect.x1;
yc[3]=objRect.y1-objRect.height;
xc[4]=objRect.x1;
yc[4]=objRect.y1;
clr=clr1;
dispRecIndex((xc[0]+xc[1])/2,(yc[0]+yc[2])/2,(i+1));
drawRect(xc,yc);
}
}




function generateoutput_clk()
{
if(iprects==null)
return;
var argRects=new Array();
for(i=0;i<iprects.length;i++)
{
if(iprects[i]==null )
break;
var objRect=iprects[i];
var obj=new rect();
obj.x1=objRect.x1;
obj.y1=objRect.y1;
obj.width=objRect.width;
obj.height=objRect.height;
obj.id=objRect.id;
argRects[i]=obj;
}
var prx1,pry1,crx1,cry1;
for(i=0;i<argRects.length;i++)
{
if(argRects[i]==null )
continue;
var currect=argRects[i];
for(var j=i-1;j>=0;j--)
{
if(argRects[j]==null)
continue;
var prvrect=argRects[j];
if(iprects[j].height<=iprects[i].height)
break;
if(prvrect.y1!=currect.y1)
continue;
if(iprects[j].height==iprects[i].height && j==i-1)
{
currect.width=currect.width+iprects[j].width;
iprects[j]=null;
argRects[j]=null;
continue;
}
currect.x1=prvrect.x1;
currect.y1=prvrect.y1;
currect.width=currect.width+prvrect.width;
if(prvrect.y1-prvrect.height<=currect.y1-currect.height)
{
prvrect.y1=currect.y1-currect.height;
prvrect.height=prvrect.height-currect.height;
}
argRects[i]=currect;
}
for(var j=i+1;j<argRects.length;j++)
{
if(argRects[j]==null)
continue;
var nxtrect=argRects[j];
if(nxtrect.y1!=currect.y1)
continue;
if(iprects[j].height<iprects[i].height)
break;
if(iprects[j].height==iprects[i].height && j==i+1)
{
currect.width=currect.width+iprects[j].width;
iprects[j]=null;
argRects[j]=null;
continue;
}
currect.width=currect.width+iprects[j].width;
if(nxtrect.y1-nxtrect.height<=currect.y1-currect.height)
{
nxtrect.y1=currect.y1-currect.height;
nxtrect.height=nxtrect.height-currect.height;
}
argRects[i]=currect;

}
}

oprects=argRects;
recCntr=0;
drawOp();
}
function drawOp()
{
var argRects=oprects;
if(oprects==null)
return;
var i=recCntr;
if(argRects[i]!=null)
{
objRect=argRects[i];
var xc=new Array();
var yc=new Array();
xc[0]=objRect.x1;
yc[0]=objRect.y1+opShft;
xc[1]=objRect.x1+objRect.width;
yc[1]=objRect.y1+opShft;
xc[2]=objRect.x1+objRect.width;
yc[2]=objRect.y1-objRect.height+opShft;
xc[3]=objRect.x1;
yc[3]=objRect.y1-objRect.height+opShft;
xc[4]=objRect.x1;
yc[4]=objRect.y1+opShft;
clr=clr1;
drawRect(xc,yc);
dispRecIndex((xc[0]+xc[1])/2,(yc[0]+yc[2])/2,(i+1));
}
else
{
var divdisp=document.getElementById('div_recIndx');
divdisp.style.display='none';
divdisp.innerText='';
}
recCntr++;
if(recCntr<=argRects.length)
setTimeout('drawOp();',optmr);
}
</script>

<script type="text/javascript" language="javascript">
function IsNumber(argText)
{
var nums='0123456789';
for(i=0;i<argText.length;i++)
{
if(nums.indexOf(argText.charAt(i))==-1)
return false;
}
return true;
}

var clr="red";
var clr1='red';
var clr2='green';
var clr3='blue';
var strk=2;
function drawRect(xc,yc)
{
jg.setStroke(strk);
jg.setColor(clr);
jg.drawPolygon(xc,yc);
jg.paint();
}

function findPosition(element)
{
var left = 0;
var top = 0;

if (element != null)
{
while (element.offsetParent)
{
left += element.offsetLeft;
if (element.offsetParent.scrollLeft) {left -= element.offsetParent.scrollLeft; }
top += element.offsetTop;
if (element.offsetParent.scrollTop) { top -= element.offsetParent.scrollTop; }
element = element.offsetParent;
}
left += element.offsetLeft + document.body.scrollLeft - document.body.clientLeft + 7;
top += element.offsetTop + document.body.scrollTop - document.body.clientTop;
}

return [left,top];
}

</script>
<script type="text/javascript" language="javascript">
function DisplayText(argText)
{
var obj=document.getElementById('div_map');
var divdwn=document.getElementById('div_download');
divdwn.style.display='block';
divdwn.innerText=argText;
var crd=findPosition(obj);
divdwn.style.left=crd[0];
divdwn.style.top=crd[1]+40;
document.getElementById('btnDisp').style.display='block';
}
</script>


<table id="maintable" style="width:800px;">
<tr class="tr_header">
<td style="width:40%;text-align:right;">Number of Input Rectangles :</td><td><input type="text" id="txtRects" /> 
</td>
</tr>
<tr>
<td class="tr_header" style="text-align:center;" colspan="2">
<input type="button" value="Generate Rectangles" class="cssbutton" style="width:200px" onclick="generaterectangles_clk();"/>
<input type="button" value="Generate Output" class="cssbutton" style="width:200px;" onclick="generateoutput_clk();"/>
 
</td>

</tr>
<tr>
<td colspan="2">
 <br />
<div id="div_map" style="width:800px;height:600px;border: 3px solid #ccc; " >

</div>
</td></tr>
</table>
<div id="div_download" class="div_down" style="position:absolute;height:500;display:none"></div>
<div id="div_recIndx" style="position:absolute;height:50;display:none"></div>
</body>
</html>

Auto amount format using java script

I would like to share my java script function that validates user input while entering amount in a specific amount field text box.
Things to validate
1) Is it always positive amount?
2) Should not allow user to enter characters other than (0123456789-.).
3) Should not allow user to type “.”, if value in text box already has “.”.
4) Should not allow user to type “-”, if value in text box already has “-”.
5) Should insert “-“at zero (0) index when user types “-“at index other than zero.


HTML Page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<script type="text/javascript" language="javascript">
//list of characters that are to be allowed for a valid double value (either positive or negative)
var PosDoubleChars=".0123456789";
var NegDoubleChars="-.0123456789";
//function that add's events to the given text box control to handle it for amount validations
function AmountControl(obj,msg,blnNeg)
{
//Checking if textbox control should allow negative or positive double values
if(blnNeg)
AllowNegDouble(obj);
else
AllowPosDouble(obj);
//setting on focus out event to automatically format given input anount
obj.onfocusout=function(){ValidateAmount(obj,msg,blnNeg);};
}

function AllowNegDouble(obj)
{
AllowChars(obj,NegDoubleChars);
}

function AllowPosDouble(obj)
{
AllowChars(obj,PosDoubleChars);
}

function AllowChars(obj,argChrs)
{
//adding key press evet to restrict user from entering characters other than mentioned list
//of double characters
obj.onkeypress=function(){return CheckChar(obj,event.keyCode,argChrs);}
}

//checking the character code to allow it.

function CheckChar(obj,kyCd,argChrs)
{
if(argChrs==PosDoubleChars)
{
if(kyCd>=46 && kyCd<=58 )
{
if(kyCd==47)
{
return false;
}
if(kyCd==46)
{
for(var i=0;i<obj.value.length;i++)
{
if(obj.value.charAt(i)=='.')
{
return false;
}
}
}
return true;

}
return false;
}
if(argChrs==NegDoubleChars)
{
if((kyCd>=46 && kyCd<=58) || (kyCd==45))
{
if(kyCd==47)
{
return false;
}
if(kyCd==45)
{
if(obj.value.indexOf('-')!=-1)
{
return false;
}
else
{
obj.value='-'+obj.value;
return false;
}
}
if(kyCd==46)
{
for(var i=0;i<obj.value.length;i++)
{
if(obj.value.charAt(i)=='.')
{
return false;
}
}
}
return true;

}
return false;
}
}

//validating and fomratting amount
function ValidateAmount(obj,msg,blnNeg)
{
obj.value=replaceAll(obj.value,',','');
var amtval=obj.value;
if(amtval=='')
return true;
var numb=obj.value.substr(0,obj.value.indexOf('.'));
if(numb.length<=16)
obj.value=FormatAmount(parseFloat(obj.value).toFixed(4));
if(obj.value=="NaN")
obj.value="0.00";
return true;
}
//to replace specific character with speific character in given input string
function replaceAll(wrd,frm,to)
{
var Char;
var fnl='';
for (i = 0; i < wrd.length ; i++)
{
if (wrd.charAt(i)==frm)
{
fnl+=to;
}
else
fnl+=wrd.charAt(i);
}
return fnl;
}
//auto formatting
function FormatAmount(nStr)
{
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
</script>
</head>
<body>
Amount : <input type="text" id="txtAmount" />
<script>
//I am calling the above created function saying ‘txtAmount’ as amount control //that should handle all above validations.
//It should allow negative decimals as I said true
AmountControl(document.getElementById('txtAmount'),'Please enter valid amount',true);
</script>
</body>

</html>
UI :



Intput:





1) It it allowing me to enter negative value but if once"-" is typed in middle it is automatically getting inserted at beginning and not allowing to type “-“ again if the amount is already negative.
2) It is allowing me to type "." But if amount is already having decimal it is not allowing to type “." again if the amount is already negative.

3) Not allowing me to type characters other than specified (0123456789-.).

4) Automatically formatting amount by rounding off to 4 decimals if user focuses out from the amount text box.
Output:




How to draw layout of a rectangular graph using Javascript ?

Please refer
Draw line using third party java script file
As explained in above post that the third party java script file makes our task very easier to draw objects.
Now by using this java script file, I would like to share my HTML page and java script code to generate below.
Output:




Note : This is a basic HTML page, so it is not specific to technology
Input :-
User enters number of rectangles in input text box and clicks on “Generate rectangles”, to generate random rectangles.
It should generate mentioned number of rectangles with random height and width but base lined bottoms (similar to a graph).



When user clicks on “Generate button” giving number of input rectangles as 10.



Now output: When user clicks on Display Layout, we should draw only the outline or layout of the given input graph.



Note:
If you would like to copy the below HTML page to run, Make sure that the third party graphics JavaScript file is downloaded into your machine and placed in this application folder where you are creating this HTML page.
Down third party JavaScript file by clicking here
wz_jsgraphics.zip download

HTML File :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Rectangles</title>
<link rel="stylesheet" type="text/css" href="Styles/Stylesheet.css" />
</head>
<body>
<div id="Canvas" style="position:relative;height:5px;width:5px;"></div>
<script type="text/javascript" language="javascript" src="wz_jsgraphics.js"></script>
<script type="text/javascript" language="javascript">
var jg = new jsGraphics("Canvas"); // Use the "Canvas" div for drawing
</script>
<script type="text/javascript" language="javascript">
var orgX=50;
var orgY=200;
var minWdth=20;
var minHght=30;
var maxWdth=60;
var maxHght=120;
var rndFactor=10;
var lnCntr=0;
var tmr=50;
var iprects=null;
var argCnt;
var inpCntr=0;
var rects=new Array();
var ipTmr=50;
var optmr=50;
var recCntr=0;
function rect()
{
var width;
var height;
var id;
var x1;
var y1;
}
function generaterectangles_clk()
{
var txtRec=document.getElementById('txtRects');
if(txtRec.value=='')
{
alert('Please enter number of rectangles to generate');
txtRec.focus();
return;
}
if(!IsNumber(txtRec.value))
{
alert('Please enter numeric value');
txtRec.focus();
return;
}
var numRects=txtRec.value;
if(numRects<3 || numRects>30)
{
alert('Number of rectangles to generate should be between 3 and 30');
txtRec.focus();
return;
}
orgX=50;
orgY=400;
argCnt=numRects;
inpCntr=0;
rects=new Array();
GenerateRects();
}

function GenerateRects()
{
inpCntr++;
if(inpCntr<=argCnt)
{
var rand_no;
var recWth,recHgt;
rand_no = Math.random();
recWth=Math.floor(minWdth+(maxWdth-minWdth)*rand_no);
recHgt=Math.floor(minHght+(maxHght-minHght)*rand_no);
var objRect=new rect();
objRect.width=recWth;
objRect.height=recHgt;
objRect.id=(inpCntr);
rects[rects.length]=objRect;
DefineRects(rects);
setTimeout('GenerateRects();',ipTmr);
}
else
{
var divdisp=document.getElementById('div_recIndx');
divdisp.style.display='none';
divdisp.innerText='';
}
}
function dispRecIndex(x1,y1,txt)
{
var divdisp=document.getElementById('div_recIndx');
divdisp.style.display='block';
divdisp.innerText=txt;
divdisp.style.left=x1;
divdisp.style.top=y1;
}
function DefineRects(argRects)
{
jg.clear();
var x1=orgX;
var y1=orgY;
var buf=5;
var crd=findPosition(document.getElementById('div_map'));
var maxY=crd[1]-buf;
var maxX=document.getElementById('div_map').offsetWidth+crd[0]-buf;
var minY=crd[1]-document.getElementById('div_map').offsetHeight;
var minX=crd[0];
var objRect=new rect();
for(i=0;i<argRects.length;i++)
{
objRect=argRects[i];
if(x1<maxX && x1>minX)
{
objRect.x1=x1;
objRect.y1=y1;
x1+=objRect.width;
}
else
{
for(j=i;j<argRects.length;j++)
argRects[j]=null;
break;
}
if(y1<maxY && y1>minY)
{
objRect.y1=maxY;
}
argRects[i]=objRect;
}
iprects=argRects;
for(i=0;i<argRects.length;i++)
{
if(argRects[i]==null)
break;
objRect=argRects[i];
var xc=new Array();
var yc=new Array();
xc[0]=objRect.x1;
yc[0]=objRect.y1;
xc[1]=objRect.x1+objRect.width;
yc[1]=objRect.y1;
xc[2]=objRect.x1+objRect.width;
yc[2]=objRect.y1-objRect.height;
xc[3]=objRect.x1;
yc[3]=objRect.y1-objRect.height;
xc[4]=objRect.x1;
yc[4]=objRect.y1;
clr=clr1;
dispRecIndex((xc[0]+xc[1])/2,(yc[0]+yc[2])/2,(i+1));
drawRect(xc,yc);
}
}



</script>

<script type="text/javascript" language="javascript">
function IsNumber(argText)
{
var nums='0123456789';
for(i=0;i<argText.length;i++)
{
if(nums.indexOf(argText.charAt(i))==-1)
return false;
}
return true;
}

var clr="red";
var clr1='red';
var clr2='green';
var clr3='blue';
var strk=2;
function drawRect(xc,yc)
{
jg.setStroke(strk);
jg.setColor(clr);
jg.drawPolygon(xc,yc);
jg.paint();
}

function findPosition(element)
{
var left = 0;
var top = 0;

if (element != null)
{
while (element.offsetParent)
{
left += element.offsetLeft;
if (element.offsetParent.scrollLeft) {left -= element.offsetParent.scrollLeft; }
top += element.offsetTop;
if (element.offsetParent.scrollTop) { top -= element.offsetParent.scrollTop; }
element = element.offsetParent;
}
left += element.offsetLeft + document.body.scrollLeft - document.body.clientLeft + 7;
top += element.offsetTop + document.body.scrollTop - document.body.clientTop;
}

return [left,top];
}

</script>
<script type="text/javascript" language="javascript">
function DisplayText(argText)
{
var obj=document.getElementById('div_map');
var divdwn=document.getElementById('div_download');
divdwn.style.display='block';
divdwn.innerText=argText;
var crd=findPosition(obj);
divdwn.style.left=crd[0];
divdwn.style.top=crd[1]+40;
document.getElementById('btnDisp').style.display='block';
}
</script>

<script type="text/javascript" language="javascript">
function rect()
{
var x1,y1,x2,y2,x3,y3,x4,y4;
}
function GetRectangles()
{
if(iprects==null)
return;
var rectCrds=new Array();
for(i=0;i<iprects.length;i++)
{
var objRect=iprects[i];
var objrect=new rect();
objrect.x3=objRect.x1;
objrect.y3=objRect.y1-objRect.height;
objrect.x2=objRect.x1+objRect.width;
objrect.y2=objRect.y1;
objrect.x1=objrect.x3;
objrect.y1=objrect.y2;
objrect.x4=objrect.x2;
objrect.y4=objrect.y3;
rectCrds[i]=objrect;
}
return rectCrds;
}
function sortRects(rects)
{
for(var c=0;c<rects.length;c++)
{
var rect=rects[c];
for(var k=c+1;k<rects.length;k++)
{
var tmprect=rects[k];
if(tmprect.x1<rect.x1)
{
rects[c]=tmprect;
rects[k]=rect;
}
}
}
return rects;
}
function DisplayLayout()
{
lnCntr=0;
var rectCrds=GetRectangles();
rectCrds=sortRects(rectCrds);
var xc=new Array();
var yc=new Array();
var cnt=-1;
var prevRect=null;
var nextRect=null;
for(var c=0;c<rectCrds.length;c++)
{
var actRec=rectCrds[c];
if(c+1==rectCrds.length)
nextRect=null;
else
nextRect=rectCrds[c+1];
if(c==0)
{
cnt++;
xc[cnt]=actRec.x1;
yc[cnt]=actRec.y1;
cnt++;
xc[cnt]=actRec.x3;
yc[cnt]=actRec.y3;
if(nextRect!=null && nextRect.x1<actRec.x4)
{
cnt++;
xc[cnt]=nextRect.x1;
yc[cnt]=actRec.y3;
}
else
{
cnt++;
xc[cnt]=actRec.x4;
yc[cnt]=actRec.y4;
}
}
if(nextRect!=null)
{
if((nextRect.x1/actRec.x2)==1 && (actRec.y2/nextRect.y1)==1)
{
cnt++;
xc[cnt]=nextRect.x3;
yc[cnt]=nextRect.y3;
cnt++;
xc[cnt]=nextRect.x4;
yc[cnt]=nextRect.y4;
}
else
{

if(nextRect!=null)
{

if(nextRect.x3==actRec.x4)
{
cnt++;
xc[cnt]=nextRect.x3;
yc[cnt]=nextRect.y3;
cnt++;
xc[cnt]=nextRect.x4;
yc[cnt]=nextRect.y4;
}
else if(nextRect.x3<actRec.x4)
{
if(nextRect.y3<actRec.y3)
{
xc[cnt]=nextRect.x3;
yc[cnt]=actRec.y3;
cnt++;
xc[cnt]=nextRect.x3;
yc[cnt]=nextRect.y3;
cnt++;
xc[cnt]=nextRect.x4;
yc[cnt]=nextRect.y4;
}
else
{
cnt++;
xc[cnt]=actRec.x4;
yc[cnt]=actRec.y4;
if(actRec.x4<nextRect.x4)
{
cnt++;
xc[cnt]=actRec.x4;
yc[cnt]=nextRect.y3;
cnt++;
xc[cnt]=nextRect.x4;
yc[cnt]=nextRect.y4;
}
else
{
cnt++;
xc[cnt]=actRec.x2;
yc[cnt]=actRec.y2;
c++;
}

}
}
else
{
if(prevRect!=null && prevRect.x2>actRec.x2)
{
cnt++;
xc[cnt]=actRec.x2;
yc[cnt]=prevRect.y3;
cnt++;
xc[cnt]=nextRect.x1;
yc[cnt]=prevRect.y3;
}
else
{
cnt++;
xc[cnt]=actRec.x2;
yc[cnt]=actRec.y2;
cnt++;
xc[cnt]=nextRect.x1;
yc[cnt]=nextRect.y1;
}
cnt++;
xc[cnt]=nextRect.x3;
yc[cnt]=nextRect.y3;
cnt++;
xc[cnt]=nextRect.x4;
yc[cnt]=nextRect.y4;

}


}

}
}
else
{
if(prevRect!=null && actRec.x2>prevRect.x2)
{
cnt++;
xc[cnt]=actRec.x2;
yc[cnt]=actRec.y2;
}
}
prevRect=actRec;

}
cnt++;
xc[cnt]=xc[0];
yc[cnt]=yc[0];
lyx=xc;
lyy=yc;

drawLines();
}
var lyx=new Array();
var lyy=new Array();
var lyclr="black";
var lystrk=4;
function drawLines()
{
jg.setColor(lyclr);
jg.setStroke(lystrk);
jg.drawLine(lyx[lnCntr],lyy[lnCntr],lyx[lnCntr+1],lyy[lnCntr+1]);
lnCntr++;
jg.paint();
if(lnCntr<lyx.length)
{
setTimeout("drawLines()",tmr);
}
}

</script>
<table id="maintable" style="width:800px;">
<tr class="tr_header">
<td style="width:40%;text-align:right;">Number of Input Rectangles :</td><td><input type="text" id="txtRects" /> 
</td>
</tr>
<tr>
<td class="tr_header" style="text-align:center;" colspan="2">
<input type="button" value="Generate Rectangles" class="cssbutton" style="width:200px" onclick="generaterectangles_clk();"/>
 
<input type="button" value="Display Layout" id="btnLayout" onclick="DisplayLayout();" style="width:200px" class="cssbutton"/>
</td>

</tr>
<tr>
<td colspan="2">
 <br />
<div id="div_map" style="width:800px;height:600px;border: 3px solid #ccc; " >

</div>
</td></tr>
</table>
<div id="div_download" class="div_down" style="position:absolute;height:500;display:none"></div>
<div id="div_recIndx" style="position:absolute;height:50;display:none"></div>
</body>
</html>

How to draw lines using java script?

I have goggled about this and found an excellent third party JavaScript file which is when referred helps to create a line or poly line (continuous lines with start and end point) very easily.
Please click on this link to down load Third party JavaScript file.
wz_jsgraphics.zip download

Please click on this link to explore the members this third party javascript file has
wz_jsgraphics members

Ex:-

I would like to write an HTML file that draws a line on button click using above down loaded JavaScript file.
Note:
If you would like to copy the below HTML page to run, Make sure that the third party graphics JavaScript file is downloaded into your machine and placed in this application folder where you are creating this HTML page.
Down third party JavaScript file by clicking here
wz_jsgraphics.zip download

Html File :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Line</title>
</head>
<body>
<div id="Canvas" style="position:relative;height:5px;width:5px;"></div>
<script type="text/javascript" language="javascript" src="wz_jsgraphics.js"></script>
<script type="text/javascript" language="javascript">
var jg = new jsGraphics("Canvas"); // Use the "Canvas" div for drawing
function btn_Draw_Clk()
{
jg.setStroke(2);
jg.setColor('red');
jg.drawLine(10,50,300,200);
jg.paint();
}
</script>

<input type="button" value="Draw Line" id="btnDraw" onclick="btn_Draw_Clk();" />
<div id="div_map" style="width:800px;height:1000px;border: 3px solid #ccc; " >

</div>
</body>
</html>

User interface:




When user clicks on the “Draw Line” button:







There is nothing great on my side to draw a line :), but I was just referring the third party JavaScript file. We can also draw many other objects like rectangle, polygon, point, eclipse, circle.

I would like to share my more work examples using this third party in next posts.