Monday, August 28, 2006

Does machine have JAVA

My friend can up with a curious problem.

To run an applet a prerequiste is to actually check whether JRE(or JVM) is actually present on the machine. Although applet inherits the intelligence to actually point the browser to the web location.

However if the application has to be in total control then how??????

In short for Non-IE browsers then navigator.mimeTypes gets the registry values for the installed runtimes.
But alas IE does not implement mimetypes. So an activeX document to implement the same.


Here is a small snippet of the code written in javascript.


if(navigator.mimeTypes) {
//For non-IE browsers
for (i=0; i < navigator.mimeTypes.length; i++) {
if( (navigator.mimeTypes[ i].type != null)
&& (navigator.mimeTypes[ i].type.indexOf(
"application/x-java-applet;jpi-version=1.5") != -1) ) {
pluginDetected = true;
break;
}

}
}
} else if (is_ie5up) {
var javaVersion;
var shell;
try {
// Create WSH(WindowsScriptHost) shell, available on Windows only
shell = new ActiveXObject("WScript.Shell");

if (shell != null) {
// Read JRE version from Window Registry
try {
javaVersion = shell.regRead("HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\CurrentVersion");
} catch(e) {
// handle exceptions raised by 'shell.regRead(...)' here
// so that the outer try-catch block would receive only
// exceptions raised by 'shell = new ActiveXObject(...)'
}
}
} catch(e) {
}
My friend can up with a curious problem.

To run an applet a prerequiste is to actually check whether JRE(or JVM) is actually present on the machine. Although applet inherits the intelligence to actually point the browser to the web location.

However if the application has to be in total control then how??????

In short for Non-IE browsers then navigator.mimeTypes gets the registry values for the installed runtimes.
But alas IE does not implement mimetypes. So an activeX document to implement the same.


Here is a small snippet of the code written in javascript.


if(navigator.mimeTypes) {
//For non-IE browsers
for (i=0; i < navigator.mimeTypes.length; i++) {
if( (navigator.mimeTypes[ i].type != null)
&& (navigator.mimeTypes[ i].type.indexOf(
"application/x-java-applet;jpi-version=1.5") != -1) ) {
pluginDetected = true;
break;
}

}
}
} else if (is_ie5up) {
var javaVersion;
var shell;
try {
// Create WSH(WindowsScriptHost) shell, available on Windows only
shell = new ActiveXObject("WScript.Shell");

if (shell != null) {
// Read JRE version from Window Registry
try {
javaVersion = shell.regRead("HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment\\CurrentVersion");
} catch(e) {
// handle exceptions raised by 'shell.regRead(...)' here
// so that the outer try-catch block would receive only
// exceptions raised by 'shell = new ActiveXObject(...)'
}
}
} catch(e) {
}

Tuesday, August 22, 2006

Extract Windows Product Key !

Just came across this while searching something on "Google", looked very interesting.
Everyone will be wondering how to get this product key if not mentioned it on the CD label.
But I haven't tried this yet, cause am not a windows programmer ;)
Let me know the results about this!

BSTR GetProductKey()
/*
Window Product Key Extract

*/
{
CString strResult; //Return a Window Product Key

HKEY hRegistryKey; //Registry Handler
BYTE *DigitalProductID; //Digital Product Key Value
DWORD DataLength; //Digital Product Key Length

BYTE ProductKeyExtract [15]; //Extract Key

char sCDKey [256]; //Temp, adding a Window Product Key

long ByteCounter; //Counter
long ByteConvert; //Convert

int nCur; //XOR calculate


char *KeyChars[] = {
"B","C","D","F","G","H","J","K","M","P","Q","R","T","V","W","X","Y",
"2","3","4","6","7","8","9",NULL
};

// HKLM\\SOFTWARE\\MICROSOFT\\Windows NT\\CurrentVersion 열기
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, NT_CURRENT,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, &hRegistryKey) == ERROR_SUCCESS)
{

DataLength = 164;

//Allocate Memory
DigitalProductID = (BYTE *)malloc(DataLength);

//Memory Initializationd
memset(DigitalProductID, 0, DataLength);

//Digital Product Key Open

if(RegQueryValueEx(hRegistryKey, "DigitalProductId",
NULL, NULL, DigitalProductID, &DataLength) == ERROR_SUCCESS)
{
//reading a value start position 52, by 66
for(ByteCounter=52; ByteCounter<=66; ByteCounter++)
{
ProductKeyExtract[ByteCounter - 52] = DigitalProductID[ByteCounter];
}

//Last Indexer
ProductKeyExtract[sizeof(ProductKeyExtract)] = NULL;
}
}

//Start Converting job, Next Step

memset(sCDKey, 0, sizeof(sCDKey));

for(ByteCounter=24; ByteCounter>=0; ByteCounter--)
{
nCur = 0;

for(ByteConvert=14; ByteConvert>=0; ByteConvert--)
{

nCur = (nCur * 256) ^ ProductKeyExtract[ByteConvert]; //XOR계산
ProductKeyExtract[ByteConvert] = nCur / 24;
nCur = nCur % 24;
}

strrev(sCDKey);
strcat(sCDKey, KeyChars[nCur]);
strrev(sCDKey);

//Insert "-"

if(!(ByteCounter % 5) && (ByteCounter))
{
strrev(sCDKey);

strcat(sCDKey, "-");

strrev(sCDKey);
}
}

//Insert Product Key into Return value

strResult.Format("%s", sCDKey);

//Close Registry
RegCloseKey(hRegistryKey);

//Relese Memory
if(DigitalProductID) free(DigitalProductID);

return strResult.AllocSysString();
}

Note: Please mention the results in the comments section.

Thursday, August 17, 2006

Richard Stallman @IISc

Title: Free Software: current status and challenges

Time: 19 Aug (Sat) 11am
Place: Faculty Hall

Speaker: Richard Stallman,
Founder of GNU project and FSF (Free Software Foundation)


Abstract:
Richard Stallman will give a talk on free software and current status on
aspects such as GPLv3, DRM (digital rights mgmt), DMCA, etc.

Bio:
Richard Stallman is the founder of the GNU Project, launched in 1984 to
develop the free software operating system GNU. The name ``GNU'' is a
recursive acronym for ``GNU's Not Unix''.

Stallman graduated from Harvard in 1974 with a BA in physics. During his
college years, he also worked as a staff hacker at the MIT Artificial
Intelligence Lab, learning operating system development by doing it. He
wrote the first extensible Emacs text editor there in 1975. He also
developed the AI technique of dependency-directed backtracking, also
known as truth maintenance. In January 1984 he resigned from MIT to
start the GNU project.

Stallman received the Grace Hopper award for 1991 from the Association
for Computing Machinery, for his development of the first Emacs editor.
In 1990 he was awarded a Macarthur foundation fellowship, and in 1996 an
honorary doctorate from the Royal Institute of Technology in Sweden. In
1998 he received the Electronic Frontier Foundation's pioneer award
along with Linus Torvalds. In 1999 he received the Yuri Rubinski award.
In 2001 he received a second honorary doctorate, from the University of
Glasgow, and shared the Takeda award for social/economic betterment with
Torvalds and Ken Sakamura. In 2002 he was elected to the US National
Academy of Engineering, and in 2003 to the American Academy of Arts and
Sciences. In 2003 he was named an honorary professor of the Universidad
Nacional de Ingenieria in Peru, and received an honorary doctorate from
the Free University of Brussels. In 2004 he received an honorary
doctorate from the Universidad Nacional de Salta, in Argentina.

About GNU:

GNU is free software: everyone is free to copy it and redistribute it,
as well as to make changes either large or small. Non-free software
keeps users divided and helpless, forbidden to share it and unable to
change it. A free operating system is essential for people to be able to
use computers in freedom.

Today, Linux-based variants of the GNU system, based on the kernel Linux
developed by Linus Torvalds, are in widespread use. There are estimated
to be some 20 million users of GNU/Linux systems today.

Richard Stallman is the principal author of the GNU Compiler Collection,
a portable optimizing compiler which was designed to support diverse
architectures and multiple languages. The compiler now supports over 30
different architectures and 7 programming languages.

Stallman also wrote the GNU symbolic debugger (gdb), GNU Emacs, and
various other programs for the GNU operating system.

Monday, August 07, 2006

Is this methods fool proof?

Does this method make a valid check for even numbers?

public static boolean isEven(int i) {
return i % 2 == 1;
}

Thursday, August 03, 2006

http://localhost/Wiki/

Imagine finding yourself in the middle of nowhere wanting to browse wiki :))

Wikipedia offers whole of their content as a huge xml dump file, which you can download and host wikipedia on your local machine. There are filters such as WikiFilter available which can read this XML dump and render html dynamically. It also provides indexing and search features, So virtually you won't find any diffrerence when you are browsing the local version, except that you wont be seeing the images on the wiki page. (actually you can get a dump of even the image links, just that you got to have a 100 GB hard disk! ).

The whole xml dump file is just about 1.4 gb (compressed ver) and came to about 6.4 gb after decompressing.You can also get a sql dump which you can host using mysql which will obviously take less hard disk space, but I couldn't get anything which renders dynamic html out of it and can also provide search capabilities.

Aha...Its information about anything under the sun literally at your fingertips. All for free . Screw internet. Screw Encarta. Happy Wiki'ing !

Wednesday, August 02, 2006

Nice Article on troublshooting

Check this out

I liked the following points discussed

1)Use of strings for printing the strings of printable characters in files.

2)Apt examples of gdb,strace & ldd

Also this very useful tip. I ran into this , for finding out what is used of "OR-ing" in javascript.

"Google normally removes common words like 'and', 'or', 'when' etc from the search patten. To forcefully include them in the search, use a '+' just before the word. ( +word_to_be_included)"