#include "stdafx.h"
#include "EditIo.h"
#include "stdio.h"
#include "stdlib.h"
#include "io.h"
#include "fcntl.h"
#include "math.h"
#include <winsock2.h>
#include <windows.h>
#include <conio.h>

#pragma comment (lib, "ws2_32") 

#pragma comment(lib, "advapi32")

#define NTAPI       __stdcall
#define FCHK(a)     if (!(a)) {printf(#a " failed\n"); return 0;}

typedef int NTSTATUS;

typedef enum _SYSDBG_COMMAND
{
  SysDbgSysReadIoSpace = 14,
  SysDbgSysWriteIoSpace = 15
}SYSDBG_COMMAND, *PSYSDBG_COMMAND;

typedef NTSTATUS (NTAPI * PZwSystemDebugControl) (
    SYSDBG_COMMAND ControlCode,
    PVOID InputBuffer,
    ULONG InputBufferLength,
    PVOID OutputBuffer,
    ULONG OutputBufferLength,
    PULONG ReturnLength
    );

PZwSystemDebugControl ZwSystemDebugControl = NULL;

typedef struct _IO_STRUCT
{
    DWORD IoAddr;       // IN: Aligned to NumBYTEs,I/O address
    DWORD Reserved1;    // Never accessed by the kernel
    PVOID pBuffer;      // IN (write) or OUT (read): Ptr to buffer
    DWORD NumBYTEs;     // IN: # BYTEs to read/write. Only use 1, 2, or 4.
    DWORD Reserved4;    // Must be 1
    DWORD Reserved5;    // Must be 0
    DWORD Reserved6;    // Must be 1
    DWORD Reserved7;    // Never accessed by the kernel
}
IO_STRUCT, *PIO_STRUCT;



// 全局的设备句柄
HANDLE hMyPort;
unsigned char Port[1] = {0X0A};

unsigned char EditPort[2225] = {
0X4D,0X5A,0X90,0X00,0X03,0X00,0X00,0X00,0X04,0X00,0X00,0X00,0XFF,0XFF,0X00,0X00,
0XB8,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X40,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XC0,0X00,0X00,0X00,
0X0E,0X1F,0XBA,0X0E,0X00,0XB4,0X09,0XCD,0X21,0XB8,0X01,0X4C,0XCD,0X21,0X54,0X68,
0X69,0X73,0X20,0X70,0X72,0X6F,0X67,0X72,0X61,0X6D,0X20,0X63,0X61,0X6E,0X6E,0X6F,
0X74,0X20,0X62,0X65,0X20,0X72,0X75,0X6E,0X20,0X69,0X6E,0X20,0X44,0X4F,0X53,0X20,
0X6D,0X6F,0X64,0X65,0X2E,0X0D,0X0A,0X24,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XFD,
0XEF,0X92,0XC3,0XB9,0X8E,0XFC,0X90,0XB9,0X8E,0XFC,0X90,0XB9,0X8E,0XFC,0X90,0XB9,
0X8E,0XFD,0X90,0XB2,0X8E,0XFC,0X90,0XE0,0XAD,0XEF,0X90,0XBA,0X8E,0XFC,0X90,0X51,
0X91,0XF6,0X90,0XB8,0X8E,0XFC,0X90,0X52,0X69,0X63,0X68,0XB9,0X8E,0XFC,0X90,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X50,
0X45,0X00,0X00,0X4C,0X01,0X05,0X00,0X57,0X8C,0X0C,0X40,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0XE0,0X00,0X0E,0X01,0X0B,0X01,0X05,0X0C,0X40,0X03,0X00,0X00,0X80,
0X01,0X00,0X00,0X00,0X00,0X00,0X00,0X80,0X02,0X00,0X00,0X80,0X02,0X00,0X00,0X40,
0X04,0X00,0X00,0X00,0X00,0X01,0X00,0X20,0X00,0X00,0X00,0X20,0X00,0X00,0X00,0X05,
0X00,0X00,0X00,0X05,0X00,0X00,0X00,0X05,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X40,
0X07,0X00,0X00,0X80,0X02,0X00,0X00,0X0E,0X32,0X00,0X00,0X01,0X00,0X00,0X00,0X00,
0X00,0X04,0X00,0X00,0X10,0X00,0X00,0X00,0X00,0X10,0X00,0X00,0X10,0X00,0X00,0X00,
0X00,0X00,0X00,0X10,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X60,
0X05,0X00,0X00,0X28,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XE0,
0X06,0X00,0X00,0X30,0X00,0X00,0X00,0X70,0X04,0X00,0X00,0X54,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X40,0X04,0X00,0X00,0X30,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X2E,0X74,0X65,0X78,0X74,0X00,0X00,0X00,0XAA,
0X01,0X00,0X00,0X80,0X02,0X00,0X00,0XC0,0X01,0X00,0X00,0X80,0X02,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X20,0X00,0X00,0X68,0X2E,
0X72,0X64,0X61,0X74,0X61,0X00,0X00,0XF2,0X00,0X00,0X00,0X40,0X04,0X00,0X00,0X00,
0X01,0X00,0X00,0X40,0X04,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X40,0X00,0X00,0X48,0X2E,0X64,0X61,0X74,0X61,0X00,0X00,0X00,0X04,
0X00,0X00,0X00,0X40,0X05,0X00,0X00,0X20,0X00,0X00,0X00,0X40,0X05,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X40,0X00,0X00,0XC8,0X49,
0X4E,0X49,0X54,0X00,0X00,0X00,0X00,0X62,0X01,0X00,0X00,0X60,0X05,0X00,0X00,0X80,
0X01,0X00,0X00,0X60,0X05,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X20,0X00,0X00,0XE2,0X2E,0X72,0X65,0X6C,0X6F,0X63,0X00,0X00,0X44,
0X00,0X00,0X00,0XE0,0X06,0X00,0X00,0X60,0X00,0X00,0X00,0XE0,0X06,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X40,0X00,0X00,0X42,0X55,
0X8B,0XEC,0X83,0XEC,0X14,0X56,0X57,0X68,0X00,0X20,0X00,0X00,0XFF,0X15,0X40,0X04,
0X01,0X00,0X8B,0XF8,0X85,0XFF,0X89,0X3D,0X40,0X05,0X01,0X00,0X75,0X0B,0XB8,0X9A,
0X00,0X00,0XC0,0XE9,0X8A,0X00,0X00,0X00,0XB9,0X00,0X08,0X00,0X00,0X33,0XC0,0XF3,
0XAB,0X6A,0X01,0XFF,0X15,0X54,0X04,0X01,0X00,0X50,0XE8,0X64,0X01,0X00,0X00,0XFF,
0X35,0X40,0X05,0X01,0X00,0X6A,0X01,0XE8,0X51,0X01,0X00,0X00,0X8B,0X35,0X48,0X04,
0X01,0X00,0X8D,0X45,0XF4,0X68,0XC4,0X04,0X01,0X00,0X50,0XFF,0XD6,0X8D,0X45,0XEC,
0X68,0XF8,0X04,0X01,0X00,0X50,0XFF,0XD6,0X8B,0X75,0X08,0X8D,0X45,0XFC,0X50,0X6A,
0X00,0X6A,0X00,0X8D,0X45,0XF4,0X68,0X80,0XE8,0X00,0X00,0X50,0X6A,0X00,0X56,0XFF,
0X15,0X44,0X04,0X01,0X00,0X85,0XC0,0X7C,0X29,0X8D,0X45,0XF4,0X50,0X8D,0X45,0XEC,
0X50,0XFF,0X15,0X58,0X04,0X01,0X00,0X85,0XC0,0X7C,0X17,0XB8,0X3A,0X03,0X01,0X00,
0XC7,0X46,0X34,0XDA,0X03,0X01,0X00,0X89,0X46,0X70,0X89,0X46,0X40,0X89,0X46,0X38,
0X33,0XC0,0X5F,0X5E,0XC9,0XC2,0X08,0X00,0XCC,0X55,0X8B,0XEC,0X8B,0X4D,0X0C,0X56,
0X8B,0X41,0X60,0X83,0X61,0X18,0X00,0X83,0X61,0X1C,0X00,0X8B,0X71,0X0C,0X80,0X38,
0X0E,0X75,0X74,0X8B,0X40,0X0C,0X3D,0X2C,0X32,0X80,0XE8,0X74,0X59,0X3D,0X30,0X32,
0X80,0XE8,0X74,0X49,0X3D,0X34,0X32,0X80,0XE8,0X74,0X38,0X3D,0X38,0X32,0X80,0XE8,
0X74,0X26,0X3D,0X3C,0X32,0X80,0XE8,0X74,0X19,0X3D,0X40,0X32,0X80,0XE8,0X74,0X09,
0XC7,0X41,0X18,0X0D,0X00,0X00,0XC0,0XEB,0X3E,0X66,0X8B,0X16,0X8B,0X46,0X04,0XEF,
0XEB,0X35,0X66,0X8B,0X16,0XED,0XEB,0X25,0X66,0X8B,0X16,0X66,0X8B,0X46,0X04,0X66,
0XEF,0XEB,0X24,0X66,0X8B,0X16,0X66,0XED,0X0F,0XB7,0XC0,0XEB,0X10,0X66,0X8B,0X16,
0X8A,0X46,0X04,0XEE,0XEB,0X11,0X66,0X8B,0X16,0XEC,0X0F,0XBE,0XC0,0X89,0X46,0X04,
0XC7,0X41,0X1C,0X08,0X00,0X00,0X00,0X8B,0X71,0X18,0X32,0XD2,0XFF,0X15,0X5C,0X04,
0X01,0X00,0X8B,0XC6,0X5E,0X5D,0XC2,0X08,0X00,0X55,0X8B,0XEC,0X51,0X51,0XA1,0X40,
0X05,0X01,0X00,0X85,0XC0,0X74,0X0C,0X68,0X00,0X20,0X00,0X00,0X50,0XFF,0X15,0X68,
0X04,0X01,0X00,0X8D,0X45,0XF8,0X68,0XF8,0X04,0X01,0X00,0X50,0XFF,0X15,0X48,0X04,
0X01,0X00,0X8D,0X45,0XF8,0X50,0XFF,0X15,0X64,0X04,0X01,0X00,0X8B,0X45,0X08,0XFF,
0X70,0X04,0XFF,0X15,0X60,0X04,0X01,0X00,0XC9,0XC2,0X04,0X00,0XCC,0XFF,0X25,0X4C,
0X04,0X01,0X00,0XFF,0X25,0X50,0X04,0X01,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X40,
0X06,0X00,0X00,0XD0,0X05,0X00,0X00,0XE2,0X05,0X00,0X00,0XFA,0X05,0X00,0X00,0X10,
0X06,0X00,0X00,0X2A,0X06,0X00,0X00,0XB8,0X05,0X00,0X00,0X5C,0X06,0X00,0X00,0X72,
0X06,0X00,0X00,0X84,0X06,0X00,0X00,0X9C,0X06,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X57,0X8C,0X0C,0X40,0X00,0X00,0X00,0X00,0X04,0X00,0X00,0X00,0X10,
0X01,0X00,0X00,0X00,0X00,0X00,0X00,0X40,0X07,0X00,0X00,0X00,0X00,0X00,0X00,0X57,
0X8C,0X0C,0X40,0X00,0X00,0X00,0X00,0X03,0X00,0X00,0X00,0X30,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X50,0X08,0X00,0X00,0X00,0X00,0X00,0X00,0X57,0X8C,0X0C,0X40,0X00,
0X00,0X00,0X00,0X02,0X00,0X00,0X00,0X32,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X80,
0X08,0X00,0X00,0X5C,0X00,0X44,0X00,0X65,0X00,0X76,0X00,0X69,0X00,0X63,0X00,0X65,
0X00,0X5C,0X00,0X52,0X00,0X65,0X00,0X64,0X00,0X64,0X00,0X72,0X00,0X61,0X00,0X67,
0X00,0X6F,0X00,0X6E,0X00,0X66,0X00,0X6C,0X00,0X79,0X00,0X50,0X00,0X6F,0X00,0X72,
0X00,0X74,0X00,0X00,0X00,0X00,0X00,0X5C,0X00,0X44,0X00,0X6F,0X00,0X73,0X00,0X44,
0X00,0X65,0X00,0X76,0X00,0X69,0X00,0X63,0X00,0X65,0X00,0X73,0X00,0X5C,0X00,0X52,
0X00,0X65,0X00,0X64,0X00,0X64,0X00,0X72,0X00,0X61,0X00,0X67,0X00,0X6F,0X00,0X6E,
0X00,0X66,0X00,0X6C,0X00,0X79,0X00,0X50,0X00,0X6F,0X00,0X72,0X00,0X74,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X88,
0X05,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XB4,0X06,0X00,0X00,0X40,
0X04,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X40,0X06,0X00,0X00,0XD0,0X05,0X00,0X00,0XE2,
0X05,0X00,0X00,0XFA,0X05,0X00,0X00,0X10,0X06,0X00,0X00,0X2A,0X06,0X00,0X00,0XB8,
0X05,0X00,0X00,0X5C,0X06,0X00,0X00,0X72,0X06,0X00,0X00,0X84,0X06,0X00,0X00,0X9C,
0X06,0X00,0X00,0X00,0X00,0X00,0X00,0X21,0X01,0X49,0X6F,0X43,0X72,0X65,0X61,0X74,
0X65,0X53,0X79,0X6D,0X62,0X6F,0X6C,0X69,0X63,0X4C,0X69,0X6E,0X6B,0X00,0X00,0X1B,
0X01,0X49,0X6F,0X43,0X72,0X65,0X61,0X74,0X65,0X44,0X65,0X76,0X69,0X63,0X65,0X00,
0X00,0X64,0X03,0X52,0X74,0X6C,0X49,0X6E,0X69,0X74,0X55,0X6E,0X69,0X63,0X6F,0X64,
0X65,0X53,0X74,0X72,0X69,0X6E,0X67,0X00,0X00,0X9F,0X01,0X4B,0X65,0X33,0X38,0X36,
0X53,0X65,0X74,0X49,0X6F,0X41,0X63,0X63,0X65,0X73,0X73,0X4D,0X61,0X70,0X00,0X9D,
0X01,0X4B,0X65,0X33,0X38,0X36,0X49,0X6F,0X53,0X65,0X74,0X41,0X63,0X63,0X65,0X73,
0X73,0X50,0X72,0X6F,0X63,0X65,0X73,0X73,0X00,0X3A,0X01,0X49,0X6F,0X47,0X65,0X74,
0X43,0X75,0X72,0X72,0X65,0X6E,0X74,0X50,0X72,0X6F,0X63,0X65,0X73,0X73,0X00,0X32,
0X02,0X4D,0X6D,0X41,0X6C,0X6C,0X6F,0X63,0X61,0X74,0X65,0X4E,0X6F,0X6E,0X43,0X61,
0X63,0X68,0X65,0X64,0X4D,0X65,0X6D,0X6F,0X72,0X79,0X00,0X95,0X01,0X49,0X6F,0X66,
0X43,0X6F,0X6D,0X70,0X6C,0X65,0X74,0X65,0X52,0X65,0X71,0X75,0X65,0X73,0X74,0X00,
0X00,0X25,0X01,0X49,0X6F,0X44,0X65,0X6C,0X65,0X74,0X65,0X44,0X65,0X76,0X69,0X63,
0X65,0X00,0X00,0X27,0X01,0X49,0X6F,0X44,0X65,0X6C,0X65,0X74,0X65,0X53,0X79,0X6D,
0X62,0X6F,0X6C,0X69,0X63,0X4C,0X69,0X6E,0X6B,0X00,0X00,0X3D,0X02,0X4D,0X6D,0X46,
0X72,0X65,0X65,0X4E,0X6F,0X6E,0X43,0X61,0X63,0X68,0X65,0X64,0X4D,0X65,0X6D,0X6F,
0X72,0X79,0X00,0X6E,0X74,0X6F,0X73,0X6B,0X72,0X6E,0X6C,0X2E,0X65,0X78,0X65,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X30,0X00,0X00,0X00,0X8F,0X32,0X99,0X32,0XB6,0X32,0XC2,0X32,0XCF,
0X32,0XD7,0X32,0XE2,0X32,0X02,0X33,0X14,0X33,0X1D,0X33,0X24,0X33,0XCF,0X33,0XE0,
0X33,0XF0,0X33,0XF8,0X33,0XFF,0X33,0X09,0X34,0X15,0X34,0X20,0X34,0X26,0X34,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X01,
0X00,0X00,0X00,0X10,0X01,0X00,0X00,0X00,0X00,0X00,0X00,0X2E,0X5C,0X69,0X33,0X38,
0X36,0X5C,0X45,0X64,0X69,0X74,0X50,0X6F,0X72,0X74,0X2E,0X73,0X79,0X73,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X80,
0X02,0X00,0X00,0XB9,0X00,0X00,0X00,0X06,0X00,0X00,0X00,0X02,0X00,0X08,0XD2,0X3A,
0X03,0X00,0X00,0XA0,0X00,0X00,0X00,0X01,0X00,0X00,0X00,0X02,0X00,0X07,0XD1,0XDA,
0X03,0X00,0X00,0X43,0X00,0X00,0X00,0X03,0X00,0X00,0X00,0X01,0X00,0X05,0XD0,0X4E,
0X42,0X31,0X30,0X00,0X00,0X00,0X00,0X57,0X8C,0X0C,0X40,0X01,0X00,0X00,0X00,0X44,
0X3A,0X5C,0X52,0X65,0X64,0X64,0X72,0X61,0X67,0X6F,0X6E,0X66,0X6C,0X79,0X5C,0X69,
0X33,0X38,0X36,0X5C,0X45,0X64,0X69,0X74,0X50,0X6F,0X72,0X74,0X2E,0X70,0X64,0X62,
0X00};

unsigned char buf[512];
unsigned char bufbak[512];
unsigned char sendbuf[512];
unsigned char hqtchk[512];
unsigned char LMJ_buf[512];
char ibuf[1024];
int D_flag=0, Error_Flag=0;  //D_flag=1表示驱动加载成功，Error_Flsg=1表示错误
int Test_Flag =0;
int hqtliang=0;
int LMJNum=1;
int E_Flag = 0, Mj_Flag = 0, W_Flag =0, Wr_Flag = 0,Wr_Flag1 = 0,H_Flag=0;
int Zhl_Move = 0;
int ZHL = 2;
int F_E = 0;
int Flag_xp=0;
unsigned int zhlwy_flag = 0;
unsigned int Move_Num = 0;
unsigned long int AllSectors = 0;
unsigned long int wy_sabn = 0;
unsigned long int LMJ_Cylinds = 0;
unsigned long int LMJ_Heads = 0;
unsigned long int LMJ_Sectors = 1;
unsigned long int LMJW_addr = 0, LMJW_end =0, LMJW_num =0;
unsigned int key_flag = 0;
HANDLE Q_hOut=0;
WORD Q_wOldColorAttrs=0;
int Net_Flag=0; 
int Net_Client=0;
int Net_Server=0;
int Netzhlwy_flag = 0; //网络物理磁盘0和1标志 
int Ide_flag = 0;

char addr_string[20];
char start_string[20];
char end_string[50];
//char zyn_string[];


unsigned long int H_c = 0;
unsigned long int H_h = 0;
unsigned long int H_s = 1;

// 安装驱动并启动服务
// lpszDriverPath:  驱动程序路径
// lpszServiceName: 服务名 
BOOL StartDriver(LPCTSTR lpszDriverPath, LPCTSTR lpszServiceName)
{
	SC_HANDLE hSCManager;		// 服务控制管理器句柄
	SC_HANDLE hService;			// 服务句柄
//	DWORD dwLastError;
	BOOL bResult = FALSE;		// 返回值

	// 打开服务控制管理器
	hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);

	if(hSCManager)
	{
		// 创建服务
		hService = CreateService(hSCManager,
					lpszServiceName,
					lpszServiceName,
					SERVICE_ALL_ACCESS,
					SERVICE_KERNEL_DRIVER,
					SERVICE_DEMAND_START,
					SERVICE_ERROR_NORMAL,
					lpszDriverPath,
					NULL,
					NULL,
					NULL,
					NULL,
					NULL);

		if(hService == NULL)
		{
			if(::GetLastError() == ERROR_SERVICE_EXISTS)
			{
				hService = ::OpenService(hSCManager, lpszServiceName, SERVICE_ALL_ACCESS);
			}
		}

		if(hService)
		{
			// 启动服务
		    bResult = StartService(hService, 0, NULL);

			// 关闭服务句柄
			CloseServiceHandle(hService);
		}
  
		// 关闭服务控制管理器句柄
		CloseServiceHandle(hSCManager);
	}

	return bResult;
}

// 停止服务并卸下驱动
// lpszServiceName: 服务名 
BOOL StopDriver(LPCTSTR lpszServiceName)
{
	SC_HANDLE hSCManager;		// 服务控制管理器句柄
	SC_HANDLE hService;			// 服务句柄
	BOOL bResult;				// 返回值
	SERVICE_STATUS ServiceStatus;

	bResult = FALSE;

	// 打开服务控制管理器
	hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);


	if(hSCManager)
	{
		// 打开服务
     	hService = OpenService(hSCManager, lpszServiceName, SERVICE_ALL_ACCESS);
        
		if(hService)
		{
			// 停止服务
			bResult = ControlService(hService, SERVICE_CONTROL_STOP, &ServiceStatus);

			// 删除服务
			bResult = bResult && DeleteService(hService);

			// 关闭服务句柄
			CloseServiceHandle(hService);
		}

		// 关闭服务控制管理器句柄
		CloseServiceHandle(hSCManager);
	}

	return bResult;
}


// 打开设备
// lpszDevicePath: 设备的路径
HANDLE OpenDevice(LPCTSTR lpszDevicePath)
{
	HANDLE hDevice;

	// 打开设备
	hDevice= ::CreateFile(lpszDevicePath,			// 设备路径
			GENERIC_READ | GENERIC_WRITE,			// 读写方式
			FILE_SHARE_READ | FILE_SHARE_WRITE,		// 共享方式
			NULL,									// 默认的安全描述符
			OPEN_EXISTING,							// 创建方式
			0,										// 不需设置文件属性
			NULL);									// 不需参照模板文件

	return hDevice;
}

// 打开端口驱动
BOOL OpenMyPort()
{
	BOOL bResult;

	// 设备名为"EditPort"，驱动程序位于Windows的"system32\drivers"目录中
	bResult = StartDriver("EditPort.sys", "ReddragonflyPort");

	// 设备路径为"\\.\ReddragonflyPort"
	if(bResult) hMyPort=OpenDevice("\\\\.\\ReddragonflyPort");

	return (bResult && hMyPort!=INVALID_HANDLE_VALUE);
}

// 关闭端口驱动
BOOL CloseMyPort_1()
{
	return (StopDriver("ReddragonflyPort"));
}

BOOL CloseMyPort()
{
	return (CloseHandle(hMyPort) && StopDriver("ReddragonflyPort"));
}


// 从指定端口读一个字节
// port: 端口
BYTE ReadPortByte(WORD port)
{
	DWORD buf[2];			// 输入输出缓冲区			
	DWORD dwOutBytes;		// IOCTL输出数据长度

	buf[0] = port;			// 第一个DWORD是端口
//	buf[1] = 0;				// 第二个DWORD是数据

	// 用IOCTL_MYPORT_READ_BYTE读端口
	::DeviceIoControl(hMyPort,				// 设备句柄
			IOCTL_MYPORT_READ_BYTE,			// 取设备属性信息
			buf, sizeof(buf),				// 输入数据缓冲区
			buf, sizeof(buf),				// 输出数据缓冲区
			&dwOutBytes,					// 输出数据长度
			(LPOVERLAPPED)NULL);			// 用同步I/O	

	return (BYTE)buf[1];
}

// 从指定端口读一个字
// port: 端口

WORD ReadPortWord(WORD port)
{
	DWORD buf[2];			// 输入输出缓冲区			
	DWORD dwOutBytes;		// IOCTL输出数据长度

	buf[0] = port;			// 第一个DWORD是端口
//	buf[1] = 0;				// 第二个DWORD是数据

	// 用IOCTL_MYPORT_READ_BYTE读端口
	::DeviceIoControl(hMyPort,				// 设备句柄
			IOCTL_MYPORT_READ_WORD,			// 取设备属性信息
			buf, sizeof(buf),				// 输入数据缓冲区
			buf, sizeof(buf),				// 输出数据缓冲区
			&dwOutBytes,					// 输出数据长度
			(LPOVERLAPPED)NULL);			// 用同步I/O	

	return (WORD)buf[1];
}


// 将一个字节写到指定端口
// port: 端口
// data: 字节数据
void WritePortByte(WORD port, BYTE data)
{
	DWORD buf[2];			// 输入输出缓冲区			
	DWORD dwOutBytes;		// IOCTL输出数据长度

	buf[0] = port;			// 第一个DWORD是端口
	buf[1] = data;			// 第二个DWORD是数据

	// 用IOCTL_MYPORT_WRITE_BYTE写端口
	::DeviceIoControl(hMyPort,				// 设备句柄
			IOCTL_MYPORT_WRITE_BYTE,		// 取设备属性信息
			buf, sizeof(buf),				// 输入数据缓冲区
			buf, sizeof(buf),				// 输出数据缓冲区
			&dwOutBytes,					// 输出数据长度
			(LPOVERLAPPED)NULL);			// 用同步I/O
}



// 将一个字写到指定端口
// port: 端口
// data: 字数据
void WritePortWord(WORD port, WORD data)
{
	DWORD buf[2];			// 输入输出缓冲区			
	DWORD dwOutBytes;		// IOCTL输出数据长度

	buf[0] = port;			// 第一个DWORD是端口
	buf[1] = data;			// 第二个DWORD是数据

	// 用IOCTL_MYPORT_WRITE_BYTE写端口
	::DeviceIoControl(hMyPort,				// 设备句柄
			IOCTL_MYPORT_WRITE_WORD,		// 取设备属性信息
			buf, sizeof(buf),				// 输入数据缓冲区
			buf, sizeof(buf),				// 输出数据缓冲区
			&dwOutBytes,					// 输出数据长度
			(LPOVERLAPPED)NULL);			// 用同步I/O
}




BOOL EnablePrivilege (PCSTR name)
{
    HANDLE hToken;
    BOOL rv;
    
    TOKEN_PRIVILEGES priv = { 1, {0, 0, SE_PRIVILEGE_ENABLED} };
    LookupPrivilegeValue (
        0,
        name,
        &priv.Privileges[0].Luid
    );
    
    OpenProcessToken(
        GetCurrentProcess (),
        TOKEN_ADJUST_PRIVILEGES,
        &hToken
    );
    
    AdjustTokenPrivileges (
        hToken,
        FALSE,
        &priv,
        sizeof priv,
        0,
        0
    );
    rv = GetLastError () == ERROR_SUCCESS;
    
    CloseHandle (hToken);
    return rv;
}

BYTE InPortB (int Port)
{
    BYTE Value;
    IO_STRUCT io;
    
    io.IoAddr = Port;
    io.Reserved1 = 0;
    io.pBuffer = (PVOID) (PULONG) & Value;
    io.NumBYTEs = sizeof (BYTE);
    io.Reserved4 = 1;
    io.Reserved5 = 0;
    io.Reserved6 = 1;
    io.Reserved7 = 0;
    
    ZwSystemDebugControl 
    (
        SysDbgSysReadIoSpace,
          &io,
          sizeof (io),
          NULL,
          0,
          NULL
    );
    return Value;
}


WORD InPortW (int Port)
{
    WORD Value;
    IO_STRUCT io;
    
    io.IoAddr = Port;
    io.Reserved1 = 0;
    io.pBuffer = (PVOID) (PULONG) & Value;
    io.NumBYTEs = sizeof (WORD);
    io.Reserved4 = 1;
    io.Reserved5 = 0;
    io.Reserved6 = 1;
    io.Reserved7 = 0;
    
    ZwSystemDebugControl 
    (
        SysDbgSysReadIoSpace,
          &io,
          sizeof (io),
          NULL,
          0,
          NULL
    );
    return Value;
}


void OutPortB (int Port, BYTE Value)
{
    IO_STRUCT io;
    
    io.IoAddr = Port;
    io.Reserved1 = 0;
    io.pBuffer = (PVOID) (PULONG) & Value;
    io.NumBYTEs = sizeof (BYTE);
    io.Reserved4 = 1;
    io.Reserved5 = 0;
    io.Reserved6 = 1;
    io.Reserved7 = 0;
    
    ZwSystemDebugControl 
    (
        SysDbgSysWriteIoSpace,
        &io,
        sizeof (io),
        NULL,
        0,
        NULL
    );
};

void OutPortW (int Port, WORD Value)
{
    IO_STRUCT io;
    
    io.IoAddr = Port;
    io.Reserved1 = 0;
    io.pBuffer = (PVOID) (PULONG) & Value;
    io.NumBYTEs = sizeof (WORD);
    io.Reserved4 = 1;
    io.Reserved5 = 0;
    io.Reserved6 = 1;
    io.Reserved7 = 0;
    
    ZwSystemDebugControl 
    (
        SysDbgSysWriteIoSpace,
        &io,
        sizeof (io),
        NULL,
        0,
        NULL
    );
};



int check_xp (void)
{
    HMODULE hNtdll;
//  ULONG ReturnLength;
    OSVERSIONINFO OSVersionInfo;
    OSVersionInfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);

    EnablePrivilege (SE_DEBUG_NAME);

    FCHK ((hNtdll = LoadLibrary ("ntdll.dll")) != NULL);
    FCHK ((ZwSystemDebugControl = (PZwSystemDebugControl) 
           GetProcAddress (hNtdll, "ZwSystemDebugControl")) != NULL);
    FCHK ((void *) GetVersionEx (&OSVersionInfo) != NULL);

    if (OSVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT &&
        OSVersionInfo.dwMajorVersion >= 5 &&
        OSVersionInfo.dwMinorVersion >= 1)    //Windows XP以上
    {
        Flag_xp=1;
    }
    else
    {
        Flag_xp=0;
    }
    return 0;
}



//对IDE接口所有磁盘读写函数
int RW_Ide_Disk_Sec(BYTE ide,BYTE wrwv, unsigned long int Zyn_Sectors)
{
    unsigned int F3data = 0, F4data = 0, F5data = 0, F6data = 0;
	int j;

    unsigned int kk ;
	unsigned char kk_buf[512];
    unsigned int dddd = 0;
	int Disk_Error = 0;
	int Disk_num = 0;  

    F6data = Zyn_Sectors/(unsigned long)0x1000000;
    
	F5data = (Zyn_Sectors%(unsigned long)0x1000000)/0x10000;
    
	F4data = ((Zyn_Sectors%(unsigned long)0x1000000)%0x10000)/0x100;
    
	F3data = ((Zyn_Sectors%(unsigned long)0x1000000)%0x10000)%0x100;

if( ide == 0)
{	
	if (Flag_xp == 0)
	while (::ReadPortByte (0X1F7) != 0X50);
    else 
    while (::InPortB (0X1F7) != 0X50);
    
	if (Flag_xp == 0)
	{
	if (zhlwy_flag == 1 )
	   ::WritePortByte (0x1f6, 0xF0+F6data);
    else 
       ::WritePortByte (0x1f6, 0xE0+F6data);
    
	::WritePortByte (0x1f2, 1);
    ::WritePortByte (0x1f3, F3data);
    ::WritePortByte (0x1f4, F4data);
    ::WritePortByte (0x1f5, F5data);
	
	
	}
	else
	{
	if (zhlwy_flag == 1 )
	  OutPortB (0x1f6, 0xF0+F6data);
    else 
      OutPortB (0x1f6, 0xE0+F6data);
     
	OutPortB (0x1f2, 1);
    OutPortB (0x1f3, F3data);
    OutPortB (0x1f4, F4data);
    OutPortB (0x1f5, F5data);
	

	}

	
	if (wrwv == 2)
     {
       if (Flag_xp == 0)
		::WritePortByte (0x1f7, wrwv*0x10);
	   else
		   OutPortB (0x1f7, wrwv*0x10);

	   if (Flag_xp == 0)
	   {
		do
		{
		  dddd++;
		  if (dddd > 10000) 
		  {
			  Disk_Error = 1;
		      dddd = 0;
		      Disk_num++;
		  }
	  
         if(Disk_num > 10) return -1;
		}
        while (::ReadPortByte (0x1f7) != 0x58);
	   }
	   else
	   {
	    do
		{
		  dddd++;
		  if (dddd > 10000) 
		  {
			  Disk_Error = 1;
		      dddd = 0;
		      Disk_num++;
		  }
	  
         if(Disk_num > 10) return -1;
		}
        while ( InPortB (0x1f7) != 0x58);
	   }

      if (Flag_xp == 0)
	  {
          if(::ReadPortByte (0x1f7) != 0x58) Disk_Error = 1;
      }
	  else
      {
          if(InPortB (0x1f7) != 0x58) Disk_Error = 1;
      }
 	 
	  if (Flag_xp == 0)
      {
	  if(::ReadPortByte (0x1f1) == 0x00 )
      {
      for (j = 0; j < 256; j++)
       {
           kk = ::ReadPortWord (0x1f0);
           kk_buf[j*2] = (unsigned char)kk;
           kk_buf[j*2+1] = (unsigned char)(kk>>8);
		   
        }
       for (j = 0; j < 512; j++)
           buf[j] = kk_buf[j];
   	   
	  if (Disk_Error == 1) return -1;
	  else  return 0;
	  }
	  else 
	  	  return -1;
	  }

	  else
	  {
        if(InPortB (0x1f1) == 0x00 )
      {
      for (j = 0; j < 256; j++)
       {
           kk = InPortW (0x1f0);
	       kk_buf[j*2] = (unsigned char)kk;
           kk_buf[j*2+1] = (unsigned char)(kk>>8);
		   
        }
       for (j = 0; j < 512; j++)  buf[j] = kk_buf[j];
        
	   
	  if (Disk_Error == 1) return -1;
	  else  return 0;
	  }
	  else 
	  	  return -1;
	  
	  }
	}
	

     if (wrwv == 3)
     { 
      if (Flag_xp == 0)
	      ::WritePortByte (0x1f7, wrwv*0x10);
      else
		   OutPortB (0x1f7, wrwv*0x10);
	     
	  if (Flag_xp == 0)
	  {
	  do
	  {
		  dddd++;
		  if (dddd > 10000) 
		  {
			  Disk_Error = 1;
		      dddd = 0;
	          Disk_num++;
		  }
	  
         if(Disk_num > 10) return -1;
	  
	  
	  }
      while (::ReadPortByte (0x1f7) != 0x58 );
	 
	  if(::ReadPortByte (0x1f7) != 0x58) Disk_Error = 1;

	  if(::ReadPortByte (0x1f1) == 0x00 )
      {
      for (j = 0; j < 512; j++)
      kk_buf[j] = buf[j];
      for (j = 0; j < 256; j++)
       {
         kk = kk_buf[j*2+1]*0x100+kk_buf[j*2];
         ::WritePortWord (0x1f0, kk);
       }
      if (Disk_Error == 1) return -1;
	  else	  return 0;
	  
	  }
	  else  
		return -1;
	  }
	  
	  else
	  {
	    do
	  {
		  dddd++;
		  if (dddd > 10000) 
		  {
			  Disk_Error = 1;
		      dddd = 0;
	          Disk_num++;
		  }
	  
         if(Disk_num > 10) return -1;
	  
	  
	  }
      while (InPortB (0x1f7) != 0x58 );
	 
	  if (InPortB (0x1f7) != 0x58) Disk_Error = 1;
	  
      if (InPortB (0x1f1) == 0x00 )
      {
      for (j = 0; j < 512; j++)
      kk_buf[j] = buf[j];
      for (j = 0; j < 256; j++)
       {
         kk = kk_buf[j*2+1]*0x100+kk_buf[j*2];
         OutPortW (0x1f0, kk);
       }
      if (Disk_Error == 1) return -1;
	  else	  return 0;
	  
	  }
	  else  
		return -1;
	  
	   
	  }
	 }
 }

if ( ide == 1)
{	
	if (Flag_xp == 0)
	while (::ReadPortByte (0X177) != 0X50);
    else 
    while (::InPortB (0X177) != 0X50);
    
	if (Flag_xp == 0)
	{
	if (zhlwy_flag == 1 )
	   ::WritePortByte (0x176, 0xF0+F6data);
    else 
       ::WritePortByte (0x176, 0xE0+F6data);
    
	::WritePortByte (0x172, 1);
    ::WritePortByte (0x173, F3data);
    ::WritePortByte (0x174, F4data);
    ::WritePortByte (0x175, F5data);
	
	
	}
	else
	{
	if (zhlwy_flag == 1 )
	  OutPortB (0x176, 0xF0+F6data);
    else 
      OutPortB (0x176, 0xE0+F6data);
     
	OutPortB (0x172, 1);
    OutPortB (0x173, F3data);
    OutPortB (0x174, F4data);
    OutPortB (0x175, F5data);
	

	}

	
	if (wrwv == 2)
     {
       if (Flag_xp == 0)
		::WritePortByte (0x177, wrwv*0x10);
	   else
		   OutPortB (0x177, wrwv*0x10);

	   if (Flag_xp == 0)
	   {
		do
		{
		  dddd++;
		  if (dddd > 10000) 
		  {
			  Disk_Error = 1;
		      dddd = 0;
		      Disk_num++;
		  }
	  
         if(Disk_num > 10) return -1;
		}
        while (::ReadPortByte (0x177) != 0x58);
	   }
	   else
	   {
	    do
		{
		  dddd++;
		  if (dddd > 10000) 
		  {
			  Disk_Error = 1;
		      dddd = 0;
		      Disk_num++;
		  }
	  
         if(Disk_num > 10) return -1;
		}
        while ( InPortB (0x177) != 0x58);
	   }

      if (Flag_xp == 0)
	  {
          if(::ReadPortByte (0x177) != 0x58) Disk_Error = 1;
      }
	  else
      {
          if(InPortB (0x177) != 0x58) Disk_Error = 1;
      }
 	 
	  if (Flag_xp == 0)
      {
	  if(::ReadPortByte (0x171) == 0x00 )
      {
      for (j = 0; j < 256; j++)
       {
           kk = ::ReadPortWord (0x170);
           kk_buf[j*2] = (unsigned char)kk;
           kk_buf[j*2+1] = (unsigned char)(kk>>8);
		   
        }
       for (j = 0; j < 512; j++)
           buf[j] = kk_buf[j];
     	   
	  if (Disk_Error == 1) return -1;
	  else  return 0;
	  }
	  else 
	  	  return -1;
	  }

	  else
	  {
        if(InPortB (0x171) == 0x00 )
      {
      for (j = 0; j < 256; j++)
       {
           kk = InPortW (0x170);
           kk_buf[j*2] = (unsigned char)kk;
           kk_buf[j*2+1] = (unsigned char)(kk>>8);
		   
        }
       for (j = 0; j < 512; j++)  buf[j] = kk_buf[j];
        
	   
	  if (Disk_Error == 1) return -1;
	  else  return 0;
	  }
	  else 
	  	  return -1;
	  
	  }
	}
	

     if (wrwv == 3)
     { 
      if (Flag_xp == 0)
	      ::WritePortByte (0x177, wrwv*0x10);
      else
		   OutPortB (0x177, wrwv*0x10);
	     
	  if (Flag_xp == 0)
	  {
	  do
	  {
		  dddd++;
		  if (dddd > 10000) 
		  {
			  Disk_Error = 1;
		      dddd = 0;
	          Disk_num++;
		  }
	  
         if(Disk_num > 10) return -1;
	  
	  
	  }
      while (::ReadPortByte (0x177) != 0x58 );
	 
	  if(::ReadPortByte (0x177) != 0x58) Disk_Error = 1;

	  if(::ReadPortByte (0x171) == 0x00 )
      {
      for (j = 0; j < 512; j++)
      kk_buf[j] = buf[j];
      for (j = 0; j < 256; j++)
       {
         kk = kk_buf[j*2+1]*0x100+kk_buf[j*2];
         ::WritePortWord (0x170, kk);
       }
      if (Disk_Error == 1) return -1;
	  else	  return 0;
	  
	  }
	  else  
		return -1;
	  }
	  
	  else
	  {
	    do
	  {
		  dddd++;
		  if (dddd > 10000) 
		  {
			  Disk_Error = 1;
		      dddd = 0;
	          Disk_num++;
		  }
	  
         if(Disk_num > 10) return -1;
	  
	  
	  }
      while (InPortB (0x177) != 0x58 );
	 
	  if (InPortB (0x177) != 0x58) Disk_Error = 1;
	  
      if (InPortB (0x171) == 0x00 )
      {
      for (j = 0; j < 512; j++)
      kk_buf[j] = buf[j];
      for (j = 0; j < 256; j++)
       {
         kk = kk_buf[j*2+1]*0x100+kk_buf[j*2];
         OutPortW (0x170, kk);
       }
      if (Disk_Error == 1) return -1;
	  else	  return 0;
	  
	  }
	  else  
		return -1;
	  
	   
	  }
	 }
 }

 return 0; 
}







BOOL DiskIo_InitInstance()
{
	
	 

	if(!::OpenMyPort())
	{
		printf("\nCannot open ReddragonflyPort driver!\n");

		return FALSE;   // 调试过后一定去掉前面的//
	
	}

	
	return TRUE;
}


int DiskIo_ExitInstance() 
{
	// TODO: Add your specialized code here and/or call the base class
	
	::CloseMyPort();

	return 0;
}


void D_View();
void LMJ_inputs();
void zyn_abcd();
void get_key(int ggg);
void E_help();
void thank();
void WR_sectors();
unsigned long  dtoh();
unsigned long  numkk(unsigned char aanum);
void WriteCmos();
void chang_disk(BYTE ide_change);
void show(int Z_color,char *lmjzhl);
void ReadCmos();
void show_1(int ZZ_color);

void StreamServer(short nPort);
void net_main();

void StreamClient(char *szServer, short nPort);
void client_main();

void zchar(); // 512  转 1024 字符转换函数
void zhlchar(); // 1024 转 512
int Readpasswd();

//磁盘D命令显示界面

void Disk_Read_view(unsigned long int Wynsecs, int x)
{
 unsigned char *fpbak;
 int i, j, zch;

 hqtliang = x-1;
 
 printf("Bytes   : 128  Move  : %d -> %d  Page : %d\n\n", hqtliang*128, (hqtliang+1)*128-1, hqtliang+1);
 
 if (D_flag == 1)
  {
    if((Net_Flag ==0) || (Net_Flag ==1 && Net_Server ==1))
	{
	 if(RW_Ide_Disk_Sec(Ide_flag,2, Wynsecs) == 0);
	 else 
	 {
		show(12,"Read or Write disk error!!!\n");
	    return;
	 }
	 if(Net_Server == 1)
	 {
		 for(i = 0; i < 512; i++)   sendbuf[i]=buf[i];
	 }
	}

	printf ("---- ");
	printf ("===================  16HEX  =================== ");
    printf (" ===== ASCII ====\n");

	if(Net_Flag == 1 && Net_Client == 1)
	{
	  for(i = 0; i < 512; i++) buf[i]=bufbak[i];
	}

//	 printf("Net_Flag=%d client=%d",Net_Flag,Net_Client);
  
	for (i = 0; i < 512; i++) hqtchk[i] = buf[i];
 // if (x == 0) x = 0;
 // if (x1 == 0) x1 = 8;
  
  

  for (i = 0; i < 8; i++)
  { 
      if (i == 0) printf ("%04X ",i+128*hqtliang);
	  else printf ("%04X ",i*16+128*hqtliang);
	  for (j = 0; j < 16; j++)
	  {  
	  fpbak=&hqtchk[i*16+j+128*hqtliang];
	  zch=*fpbak;
      printf("%02X ",zch);
	   if(j==7) printf("\b-");
	  }
      printf(" ");

     for(j=0;j<16;j++)
      {
	if(hqtchk[i*16+j+128*hqtliang]==0x09||hqtchk[i*16+j+128*hqtliang]==0x0A||hqtchk[i*16+j+128*hqtliang]==0x0d||hqtchk[i*16+j+128*hqtliang]==0x07||hqtchk[i*16+j+128*hqtliang]==0x08)
	   printf(".");
	else 
		if (hqtchk[i*16+j+128*hqtliang] == 0xFF)
		printf(" ");
		else putchar(hqtchk[i*16+j+128*hqtliang]);
      }
   printf ("\n");
  } 
 }
}

//磁盘Z命令扇区清零
void Disk_Sectorzero(unsigned long int Sectorzero)
{
	int i;
	unsigned char zero_buf[512];

	for (i = 0; i < 512; i++) zero_buf[i] = 0;
    if (D_flag == 1)
	{
		for (i = 0; i < 512; i++) buf[i] = zero_buf[i];
		RW_Ide_Disk_Sec(Ide_flag,3, Sectorzero);
        printf("\nSector %u data 512 bytes is losted!!!\n",Sectorzero+1);
	}

}

//网络磁盘Z命令清扇区数据 2006-06-20
void NetDisk_Sectorzero(unsigned long int Sectorzero)
{
	int i;
	unsigned char zero_buf[512];

	for (i = 0; i < 512; i++) zero_buf[i] = bufbak[i];

    if (D_flag == 1)
	{
		printf("\nSector %u data 512 bytes is losted!!!\n",Sectorzero+1);
	}
   
}



//磁盘E命令写扇区

void Disk_Write_view(unsigned long int W_sec, int W_x)
{
	int i = 0;
    unsigned char Lw_buf[512];

	for (i = 0; i < 512; i++) Lw_buf[i] = 0;

   if (D_flag == 1)
   {
    RW_Ide_Disk_Sec(Ide_flag,2, W_sec);
	
    for (i = 0; i < 512; i++)
	{
		Lw_buf[i] = buf[i];
		hqtchk[i] = buf[i];
	}

    if (W_x != 0)
    {
	for (i = 0; i < ((W_x + 1)/3); i++)
	{
		if ( (Move_Num+i) <= 511) 
		Lw_buf[Move_Num+i] = LMJ_buf[i];
		//else printf ("test error");
	}
	//printf ("\nMove_Num = %d, Zhl = %d" ,Move_Num, W_x);
	//for (i = 0; i <= ((W_x + 1)/3); i++)
	//printf ("\n buf =%02X ",Lw_buf[Move_Num+i]);
    for (i = 0; i < 512; i++) buf[i] = Lw_buf[i];
	RW_Ide_Disk_Sec(Ide_flag,3, W_sec);
    
    
	printf ("Write Bytes . . . ");
	printf ("\n%04X : ", Move_Num);
	for (i = 0; i < ((W_x + 1)/3); i++)
	{
		if( (Move_Num+i) <= 511)	  
		printf ("%02X->%02X ", hqtchk[Move_Num+i], Lw_buf[Move_Num+i]);
	}
	   printf ("\nWrite Sector Successful!\n");
	}
    
   
	else
	{
       printf ("Write Sector Error!\n");
	}
    
   }
   else printf("Can't Loading EditPort Driver!!!");
}


//网络编辑函数显示信息

void NetDisk_Write_view(unsigned long int W_sec, int W_x)
{
	int i = 0;
    unsigned char Lw_buf[512];

   for (i = 0; i < 512; i++) Lw_buf[i] = 0;

  // if (D_flag == 1)
   //{
    //RW_Ide_Disk_Sec(Ide_flag,2, W_sec);
	
    for (i = 0; i < 512; i++)
	{
		Lw_buf[i] = bufbak[i];
		hqtchk[i] = bufbak[i];
	}

    if (W_x != 0)
    {
	for (i = 0; i < ((W_x + 1)/3); i++)
	{
		if ( (Move_Num+i) <= 511) 
		Lw_buf[Move_Num+i] = LMJ_buf[i];
		//else printf ("test error");
	}
	//printf ("\nMove_Num = %d, Zhl = %d" ,Move_Num, W_x);
	//for (i = 0; i <= ((W_x + 1)/3); i++)
	//printf ("\n buf =%02X ",Lw_buf[Move_Num+i]);
    for (i = 0; i < 512; i++) buf[i] = Lw_buf[i];
	//RW_Ide_Disk_Sec(Ide_flag,3, W_sec);
    
    
	printf ("Write Bytes . . . ");
	printf ("\n%04X : ", Move_Num);
	for (i = 0; i < ((W_x + 1)/3); i++)
	{
		if( (Move_Num+i) <= 511)	  
		printf ("%02X->%02X ", hqtchk[Move_Num+i], Lw_buf[Move_Num+i]);
	}
	    printf ("\nWrite Sector Successful!\n");
	}
    
   
	else
	{
       printf ("Write Sector Error!\n");
	}
    
   
   //else printf("Can't Loading EditPort Driver!!!");
}




/* ======================================= */
/*   读取硬盘内部出厂数据函数及初始化(新)  */
/* ======================================= */
void Ide_Disk_Init(BYTE ide,int Info_Flag)
{
 

  unsigned int i,j;
  unsigned char p;
  WORD Disk_Info[512];
  unsigned int  cache=0;
  unsigned char s[21];
  unsigned char v[9];
  unsigned char t[41];
  float T_Sectors;
  
  i = 0; j = 0; p = 0;
  
  
 if (ide == 0)
 {	 
  while (p != 0x40)
   {
    j++;
    if(j == 0xffff) break;
	if (Flag_xp == 0)
       p = ::ReadPortByte (0x1f7);
	else
       p = InPortB (0x1f7);
	
    p &= 0xc0;
   }

  if (Flag_xp == 0)
  {
	  ::WritePortByte (0x3f6,0);
      for(i = 0; i < 5; i++) ::WritePortByte (0x1f1+i, 0);
  }
  else
  { 
	  OutPortB (0x3f6,0);
      for(i = 0; i < 5; i++) OutPortB (0x1f1+i, 0);
  }
  
  if (zhlwy_flag == 1 )
  {
   if (Flag_xp == 0)
   {
       ::WritePortByte (0x1f6, 0xb0);
       ::WritePortByte (0x1f7, 0xec);
   }
   else
   {
	   ::OutPortB (0x1f6, 0xb0);
       ::OutPortB (0x1f7, 0xec);
   }
  }
  else
  {
   if (Flag_xp == 0)
   {
       ::WritePortByte (0x1f6, 0xa0);
       ::WritePortByte (0x1f7, 0xec);
   }
   else
   {
	   ::OutPortB (0x1f6, 0xa0);
       ::OutPortB (0x1f7, 0xec);
   }
  
  }
  i = 0; j = 0; p = 0;

  while (p != 0x8)
   {
     j++;
     if (j == 0xffff)	break;
     
	 if (Flag_xp == 0)
       p = ::ReadPortByte (0x1f7);
	 else
       p = InPortB (0x1f7);
		
     p &= 0x88;
   }

  if (Flag_xp == 0)
  {
	  for (i = 0; i < 512; i++)  
	  {
	  Disk_Info[i] = ::ReadPortWord (0x1f0);
	  }
  }
  else
  {
	  for (i = 0; i < 512; i++)  
	  {
	  Disk_Info[i] = InPortW (0x1f0);
	  }
  }
  if (Info_Flag == 1) 
  {

	  if ( Disk_Info[83] & 0x400 ) 	  AllSectors = (unsigned long)(Disk_Info [103] * 65536) * (unsigned long)65536 *(unsigned long) 65536 + 
					(unsigned long)(Disk_Info [102] * 65536) *(unsigned long) 65536 + 
					(unsigned long)(Disk_Info [101] * 65536) + 
					(unsigned long)(Disk_Info [100]);
		  
	  else AllSectors = (unsigned long)(Disk_Info[61]*65536) + (unsigned long)(Disk_Info[60]);

	  if (AllSectors == 0) AllSectors = Disk_Info[1]*Disk_Info[3]*Disk_Info[6];
     
	 


	  if (AllSectors > 10000) 
	  {
		  if ( Disk_Info[1] == 0X3FFF)
		  {
             LMJ_Sectors = 63;
			 LMJ_Heads = 255;
             LMJ_Cylinds = AllSectors/255/63;
		  }
		  else
		  {
			 LMJ_Sectors = Disk_Info[6];
			 LMJ_Heads = Disk_Info[3];
			 LMJ_Cylinds = Disk_Info[1];
		  }

	  }
  }

  s[20]='\0';
  v[8]='\0';
  t[40]='\0';
  cache = Disk_Info[21]/2;

  for (i = 0; i < 10; i++)
   {
     j = Disk_Info[10+i];
     s[i*2] = (unsigned char)(j>>8);
     s[i*2+1] = (unsigned char)j;
   }

  for (i = 0; i < 4; i++)
   {
     j = Disk_Info[23+i];
     v[i*2] = (unsigned char)(j>>8);
     v[i*2+1] = (unsigned char)j;
   }

  for(i = 0; i < 20; i++)
   {
     j = Disk_Info[27+i];
     t[i*2] = (unsigned char)(j>>8);
     t[i*2+1] = (unsigned char)j;
   }
  
   T_Sectors = (float)AllSectors;


  if (Info_Flag ==2 || Info_Flag==3)
  {  
  
     if (zhlwy_flag == 1 ) show (15,"\nPhysical Disk 2 ");
     else show (15,"\nPhysical Disk 1 ");
     printf ("\nDrive Serial Number : %-40s",t);
   	 
	 printf ("\nDrive Model Number  : %-20s",s);
	 printf ("\nDrive Controller Revision Number : %-8s",v);
     printf ("\nDrive Controller Buffer Size     : %u K", cache);
     printf ("\nPhysical Geometry   : ");  
     printf ("Cylind [%u C]   ", Disk_Info[1]);
     printf ("Head [%u H]   ", Disk_Info[3]);
     printf ("Sector [%u S]", Disk_Info[6]);
     
     printf ("\nLogical Theoretical : ");
     printf ("Cylind [%u C]   ", LMJ_Cylinds);
     printf ("Head [%u H]   ", LMJ_Heads);
     printf ("Sector [%u S]", LMJ_Sectors);
     printf ("\nPhysical Total Sectors : %u ", AllSectors);
     printf ("\nDisk Content Size      : %7.2f G", T_Sectors/1024/2048);
     printf ("\n");
  }
  if (Info_Flag == 3) //为3时加入网络发送数据功能
  {
   for(i = 0; i < 256; i++) 
   {
	   //v[i*2] = (unsigned char)(j>>8);
      //v[i*2+1] = (unsigned char)j;
	   sendbuf[i*2] = (unsigned char)(Disk_Info[i]);
       sendbuf[i*2+1] = (unsigned char)(Disk_Info[i]>>8);
   }
  }
        
  }

 if (ide == 1)
 {	 
  while (p != 0x40)
   {
    j++;
    if(j == 0xffff) break;
	if (Flag_xp == 0)
       p = ::ReadPortByte (0x177);
	else
       p = InPortB (0x177);
	
    p &= 0xc0;
   }

  if (Flag_xp == 0)
  {
	  ::WritePortByte (0x3f6,0);
      for(i = 0; i < 5; i++) ::WritePortByte (0x171+i, 0);
  }
  else
  { 
	  OutPortB (0x3f6,0);
      for(i = 0; i < 5; i++) OutPortB (0x171+i, 0);
  }
  
  if (zhlwy_flag == 1 )
  {
   if (Flag_xp == 0)
   {
       ::WritePortByte (0x176, 0xb0);
       ::WritePortByte (0x177, 0xec);
   }
   else
   {
	   ::OutPortB (0x176, 0xb0);
       ::OutPortB (0x177, 0xec);
   }
  }
  else
  {
   if (Flag_xp == 0)
   {
       ::WritePortByte (0x176, 0xa0);
       ::WritePortByte (0x177, 0xec);
   }
   else
   {
	   ::OutPortB (0x176, 0xa0);
       ::OutPortB (0x177, 0xec);
   }
  
  }
  i = 0; j = 0; p = 0;

  while (p != 0x8)
   {
     j++;
     if (j == 0xffff)	break;
     
	 if (Flag_xp == 0)
       p = ::ReadPortByte (0x177);
	 else
       p = InPortB (0x177);
		
     p &= 0x88;
   }

  if (Flag_xp == 0)
  {
	  for (i = 0; i < 512; i++)  
	  {
	  Disk_Info[i] = ::ReadPortWord (0x170);
	  }
  }
  else
  {
	  for (i = 0; i < 512; i++)  
	  {
	  Disk_Info[i] = InPortW (0x170);
	  }
  }
  if (Info_Flag == 1) 
  {

	  if ( Disk_Info[83] & 0x400 ) 	  AllSectors = (unsigned long)(Disk_Info [103] * 65536) * (unsigned long)65536 *(unsigned long) 65536 + 
					(unsigned long)(Disk_Info [102] * 65536) *(unsigned long) 65536 + 
					(unsigned long)(Disk_Info [101] * 65536) + 
					(unsigned long)(Disk_Info [100]);
		  
	  else AllSectors = (unsigned long)(Disk_Info[61]*65536) + (unsigned long)(Disk_Info[60]);

	  if (AllSectors == 0) AllSectors = Disk_Info[1]*Disk_Info[3]*Disk_Info[6];
     
	 


	  if (AllSectors > 10000) 
	  {
		  if ( Disk_Info[1] == 0X3FFF)
		  {
             LMJ_Sectors = 63;
			 LMJ_Heads = 255;
             LMJ_Cylinds = AllSectors/255/63;
		  }
		  else
		  {
			 LMJ_Sectors = Disk_Info[6];
			 LMJ_Heads = Disk_Info[3];
			 LMJ_Cylinds = Disk_Info[1];
		  }

	  }
  }

  s[20]='\0';
  v[8]='\0';
  t[40]='\0';
  cache = Disk_Info[21]/2;

  for (i = 0; i < 10; i++)
   {
     j = Disk_Info[10+i];
     s[i*2] = (unsigned char)(j>>8);
     s[i*2+1] = (unsigned char)j;
   }

  for (i = 0; i < 4; i++)
   {
     j = Disk_Info[23+i];
     v[i*2] = (unsigned char)(j>>8);
     v[i*2+1] = (unsigned char)j;
   }

  for(i = 0; i < 20; i++)
   {
     j = Disk_Info[27+i];
     t[i*2] = (unsigned char)(j>>8);
     t[i*2+1] = (unsigned char)j;
   }
  
   T_Sectors = (float)AllSectors;

  if (Info_Flag ==2 || Info_Flag==3)
  {  
  
     if (zhlwy_flag == 1 ) show (15,"\nPhysical Disk 4 ");
     else show (15,"\nPhysical Disk 3 ");
     printf ("\nDrive Serial Number : %-40s",t);
   
	 printf ("\nDrive Model Number  : %-20s",s);
	 printf ("\nDrive Controller Revision Number : %-8s",v);
     printf ("\nDrive Controller Buffer Size     : %u K", cache);
     printf ("\nPhysical Geometry   : ");  
     printf ("Cylind [%u C]   ", Disk_Info[1]);
     printf ("Head [%u H]   ", Disk_Info[3]);
     printf ("Sector [%u S]", Disk_Info[6]);
     
     printf ("\nLogical Theoretical : ");
     printf ("Cylind [%u C]   ", LMJ_Cylinds);
     printf ("Head [%u H]   ", LMJ_Heads);
     printf ("Sector [%u S]", LMJ_Sectors);
     printf ("\nPhysical Total Sectors : %u ", AllSectors);
     printf ("\nDisk Content Size      : %7.2f G", T_Sectors/1024/2048);
     printf ("\n");
  }
  if (Info_Flag == 3) //为3时加入网络发送数据功能
  {
   for(i = 0; i < 256; i++) 
   {
	   //v[i*2] = (unsigned char)(j>>8);
      //v[i*2+1] = (unsigned char)j;
	   sendbuf[i*2] = (unsigned char)(Disk_Info[i]);
       sendbuf[i*2+1] = (unsigned char)(Disk_Info[i]>>8);
   }
  }
        
  }

}




void NetDisk_Init()
{
 

  unsigned int i,j;
  unsigned char p;
  WORD Disk_Info[512];
  unsigned int  cache=0;
  unsigned char s[21];
  unsigned char v[9];
  unsigned char t[41];
  float T_Sectors;
  unsigned long NetAllSectors=0;
  unsigned long NetLMJ_Sectors = 0;
  unsigned long NetLMJ_Heads = 0;
  unsigned long NetLMJ_Cylinds = 0;
  
  i = 0; j = 0; p = 0;
  
  

  for (i = 0; i < 256; i++)  
  {
	  Disk_Info[i] = (unsigned int)(bufbak[i*2])+(unsigned int)(bufbak[2*i+1]<<8);
  }

   if ( Disk_Info[83] & 0x400 ) 	  NetAllSectors = (unsigned long)(Disk_Info [103] * 65536) * (unsigned long)65536 *(unsigned long) 65536 + 
					(unsigned long)(Disk_Info [102] * 65536) *(unsigned long) 65536 + 
					(unsigned long)(Disk_Info [101] * 65536) + 
					(unsigned long)(Disk_Info [100]);
		  
	  else NetAllSectors = (unsigned long)(Disk_Info[61]*65536) + (unsigned long)(Disk_Info[60]);

	  if (NetAllSectors == 0) AllSectors = Disk_Info[1]*Disk_Info[3]*Disk_Info[6];
     
	 


	  if (NetAllSectors > 10000) 
	  {
		  if ( Disk_Info[1] == 0X3FFF)
		  {
             NetLMJ_Sectors = 63;
			 NetLMJ_Heads = 255;
             NetLMJ_Cylinds = NetAllSectors/255/63;
		  }
		  else
		  {
			 NetLMJ_Sectors = Disk_Info[6];
			 NetLMJ_Heads = Disk_Info[3];
			 NetLMJ_Cylinds = Disk_Info[1];
		  }

	  }
  

  s[20]='\0';
  v[8]='\0';
  t[40]='\0';
  cache = Disk_Info[21]/2;

  for (i = 0; i < 10; i++)
   {
     j = Disk_Info[10+i];
     s[i*2] = (unsigned char)(j>>8);
     s[i*2+1] = (unsigned char)j;
   }

  for (i = 0; i < 4; i++)
   {
     j = Disk_Info[23+i];
     v[i*2] = (unsigned char)(j>>8);
     v[i*2+1] = (unsigned char)j;
   }

  for(i = 0; i < 20; i++)
   {
     j = Disk_Info[27+i];
     t[i*2] = (unsigned char)(j>>8);
     t[i*2+1] = (unsigned char)j;
   }
  
   T_Sectors = (float)NetAllSectors;

     show(15,"\nNetwork Disk");
     printf ("\nDrive Serial Number : %-40s",t);
   
	 
	 printf ("\nDrive Model Number  : %-20s",s);
	 printf ("\nDrive Controller Revision Number : %-8s",v);
     printf ("\nDrive Controller Buffer Size     : %u K", cache);
     printf ("\nPhysical Geometry   : ");  
     printf ("Cylind [%u C]   ", Disk_Info[1]);
     printf ("Head [%u H]   ", Disk_Info[3]);
     printf ("Sector [%u S]", Disk_Info[6]);
     
     printf ("\nLogical Theoretical : ");
     printf ("Cylind [%u C]   ", NetLMJ_Cylinds);
     printf ("Head [%u H]   ", NetLMJ_Heads);
     printf ("Sector [%u S]", NetLMJ_Sectors);
     printf ("\nPhysical Total Sectors : %u ", NetAllSectors);
     printf ("\nDisk Content Size      : %7.2f G", T_Sectors/1024/2048);
     printf ("\n");
  //}
 
}

 





void D_View()
{
  int letter, cl= 8;
//  int wy_flag = 0;
  char string[200];
  //char command_string[2];

  char ch, LMJ_ch; 

  int  i = 0, I_i =0, I_i1=0, I_i2 = 0;
  
  

   printf ("\n-");

  if( D_flag == 1)
  {
	 //有个 printf ("\n-") 移到上面了
   do
   {
		 
         I_i = 0, I_i1= 0, I_i2 = 0; 
		 F_E = 0;
		 
		 for (i = 0; i < 20; i++) 
		  {
              addr_string[i] = 0;
	          start_string[i] = 0;
	          end_string[i] = 0;
		  }
	     for (i = 0; i < 50; i++) end_string[i] = 0;
		 for (i = 0; i < 200; i++) string[i] = 0;
		 i=0;
		 ch = 0;
		 for (i = 0; i < 150; i++)
		 {
		 while ( (letter = toupper(getchar())) != '\n')
         {
			 string[i++] = letter;
		 }
		  i = 1000;
		 }
		 ch = string[0]; 
      if (string[2] == 0x20 || string[2] == 0x00) F_E = 0;
	  else F_E = 1;

	  if (string[1] == 0x20)
	  { 
         Error_Flag = 0; 
		 for (i = 0; i<10; i++)
		 {
           LMJ_ch = string[i+2];
		   addr_string[i] = LMJ_ch;
		   addr_string[i+1] = 0;
           if (string[i+2] == 0x20 || string[i+2] == 0) 
		   {
			   I_i = i;
			   i = 10;
                 
			   break;
		   }
		   if (!((string[i+2] <= 0x39 && string [i+2] >= 0x30) ||
			   (string[i+2] == 0x20) || ((string[i+2] == 'H') && (string[i+3] == 0x00 || string[i+3] == 0x20)
			   ) || (string[i+2] <= 0x46 && string [i+2] >= 0x41)))
		   {
		   i=10;
		   Error_Flag=1;
		   break;
		   }
		 }
	
		if (Error_Flag == 0)
		{
         for (i = 0; i < 10; i++)
		 {
			 start_string[i] = string[2+I_i+1+i];
			 start_string[i+1] = 0;
             if (string[2+I_i+1+i] == 0x20 || string[2+I_i+1+i] == 0) 
			 {
			   I_i1 = 2+I_i+1+i;
			   i = 10;
			   break;
			 }
			 if (ZHL == 1)
			 {
              if (!((string[2+I_i+1+i] <= 0x39 && string [2+I_i+1+i] >= 0x30) || (string[2+I_i+1+i] == 0x20)))
			  {
		        i=10;
		        Error_Flag=1;
				break;
			  }
			 }
			 if (ZHL == 2)
			 {
              if (!((string[2+I_i+1+i] <= 0x39 && string [2+I_i+1+i] >= 0x30) || (string[2+I_i+1+i] == 0x20) ||
			        (string[2+I_i+1+i] <= 0x46 && string [2+I_i+1+i] >= 0x41)))
			  {
		        i=10;
		        Error_Flag=1;
				break;
			  }
			 }
		 }
		}
		
//		 printf("\nError2: %d ", Error_Flag);

      if (Error_Flag == 0)
		{
         for (i = 0; i < 48; i++)
		 {
			 end_string[i] = string[I_i1+1+i];
			 end_string[i+1] = 0;
             if (string[I_i1+1+i] == 0x00) 
			 {
			   I_i2 = I_i1+1+i;
			   i = 48;
			   
			   break;
			 }
             if (!((string[I_i1+1+i] <= 0x39 && string [I_i1+1+i] >= 0x30) || (string[I_i1+1+i] == 0x20)||
				   (string[I_i1+1+i] <= 0x46 && string [I_i1+1+i] >= 0x41)))
			 {
		        i=48;
		        Error_Flag=1;
			    break;	
			 }
			 
		 }
		}

      

	  }
	  else
	  {
		  if (string[1] != 0) Error_Flag = 1;
	      if (string[1] == 0) Error_Flag = 0;
	  }

//	printf("\n Error3 : %d",Error_Flag);
//  printf("\n Ii=%d, Ii1=%d, Ii2=%d",I_i,I_i1,I_i2);
//	printf("\n addr_string= ");
//    for (i =0; i < 10; i++)
//	{
//	    printf("%c",addr_string[i]);
//	}
//	printf ("\nstart_string= ");
//  for (i =0; i<10; i++)
//	{
//	    printf("%c",start_string[i]);
//	}
//    printf ("\nend_start= ");
//    for (i =0; i<30; i++)
//	{
//	    printf("%c",end_string[i]);
//	}
      switch(ch)
	  {
	     //已经使用：Y,S,R,C,Q,E,D,W,Z,M,A,H,T,O,X,I
	     case 'Y':
		            cl = 7;
                    if (Error_Flag == 0 && F_E == 0)
					{
						Readpasswd();
                    }
					else
					{
                       show(12,"\nCommand Error!\n");
					}

					printf("\n-");
		            break;
         case 'S':
		            cl = 7;
                    if (Error_Flag == 0 && F_E == 0)
					{
						net_main();
						//printf("\n-");
                    }
					else
					{
                       show(12,"\nCommand Error!\n");
					}

					//printf("\n-");
		            break;

		 case 'C':
		            cl = 7;
                    if (Error_Flag == 0 && F_E == 0)
					{
						client_main();
						//printf("\n-");
                    }
					else
					{
                       show(12,"\nCommand Error!\n");
					}

					printf("\n-");
		            break;


		 case 'R':
		            cl = 7;
                    if (Error_Flag == 0 && F_E == 0)
					{
						ReadCmos();
                    }
					else
					{
                       show(12,"\nCommand Error!\n");
					}

					printf("\n-");
		            break;
         case 'X':
		            cl = 7;
                    if (Error_Flag == 0 && F_E == 0)
					{
						chang_disk(Ide_flag);
                    }
					else
					{
                       //printf("\nCommand Error!\n");
					   show(12,"\nCommand Error!\n");
					}

					printf("\n-");
		            break;
         case 'I':
		            cl = 7;
                    if (Error_Flag == 0 && F_E == 0)
					{
						if(Ide_flag ==0) Ide_flag = 1;
						else Ide_flag = 0;
						chang_disk(Ide_flag);
                    }
					else
					{
                       //printf("\nCommand Error!\n");
					   show(12,"\nCommand Error!\n");
					}

					printf("\n-");
		            break;
	     case 'Q':
		            if (Error_Flag == 0 && F_E == 0)
			        cl = 8;
                    else
					{
                       cl = 7;
                       //printf("\nCommand Error!\n");
					   show(12,"\nCommand Error!\n");
					   printf("\n-");
					}

					
					break;
         case 'E':  
			        cl = 7;
					if (Error_Flag == 0)
					{
                      
					 LMJ_inputs();
                      
					 if (Error_Flag == 0 && E_Flag == 0 && H_Flag == 0)
					 {
                     Disk_Write_view(wy_sabn, Zhl_Move);
					 }
					 else
					 {
                        printf("\nError: Unknow Error!\n");
					 }

					}
					else
					{
						//printf("\nCommand Error!\n");
						show(12,"\nCommand Error!\n");
					}

					

					printf("\n-");
					break;
         case 'D':
		            cl = 7;
			//		printf("Error_Flag=%d",Error_Flag);
					if (Error_Flag == 0)
					{
					LMJ_inputs();
                      
					 if (Error_Flag == 0 && Test_Flag == 0 && Mj_Flag ==0 && H_Flag == 0)
					 {
                     Disk_Read_view(wy_sabn,LMJNum);
					 }
					 else
					 {
                        printf("\nError: Sectors is too large or other error!\n");
					 }

					}
					else
					{
						//printf("\nCommand Error!\n");
						show(12,"\nCommand Error!\n");
					}
					printf("\n-");
				
					break;

        case 'W':  
			        cl = 7;
					if (Error_Flag == 0)
					{
                      
					 LMJ_inputs();
                      
					 if (Wr_Flag == 1 && Wr_Flag1 == 1)
					 {
                        get_key(2);
   					    if (key_flag == 1) WR_sectors();
					 }
					 else
					 {
                        printf("\nError: Unknow Error!\n");
					 }

					}
					else
					{
						//printf("\nCommand Error!\n");
						show(12,"\nCommand Error!\n");
					}

					printf("\n-");
					break;
		 case 'Z':
		            cl = 7;
		    		if (Error_Flag == 0)
					{
					 LMJ_inputs();
                      
					 if (Error_Flag == 0 && W_Flag == 0)
					 {
						 get_key(1);

						 if (key_flag == 1)	 Disk_Sectorzero(wy_sabn);
                    // Disk_Read_view(wy_sabn,LMJNum);
					 }
					 else
					 {
                        printf("\nError: Sectors is too large or other error!\n");
					 }

					}
					else
					{
						//printf("\nCommand Error!\n");
						show(12,"\nCommand Error!\n");
					}
					printf("\n-");
				
					break;
		 case 'M':
			        cl = 7;
					if (Error_Flag == 0 && F_E == 0)
                    {
					Ide_Disk_Init(Ide_flag,2);
					}
					else
					{
                       //printf("\nCommand Error!\n");
						show(12,"\nCommand Error!\n");
					}
                    
					printf("\n-");
					break;
        case 'H':
			        cl = 7;
					if (Error_Flag == 0 && F_E == 0)
                    {
					   E_help();
					}
					else
					{
                       //printf("\nCommand Error!\n");
						show(12,"\nCommand Error!\n");
					}
                    
					printf("\n-");
					break;
        case 'T':
			        cl = 7;
					if (Error_Flag == 0 && F_E == 0)
                    {
					   thank();
					}
					else
					{
                       //printf("\nCommand Error!\n");
						show(12,"\nCommand Error!\n");
					}
                    
					printf("\n-");
					break;

         case 'O':
			        cl = 7;
					if (Error_Flag == 0 && F_E == 0)
                    {
                       get_key(3);
					   if (key_flag == 1) WriteCmos();
					}
					else
					{
                       //printf("\nCommand Error!\n");
						show(12,"\nCommand Error!\n");
					}
                    
					printf("\n-");
					break;
		 case 'A':
			        cl = 7;
					if (Error_Flag == 0 && F_E == 0)
                    {
					zyn_abcd();
					}
					else
					{
                       //printf("\nCommand Error!\n");
					   show(12,"\nCommand Error!\n");
					}
					printf("\n-");
					break;
        case 0x00: 
			        cl = 7;
					printf("\n-");
					break;
		default  :  
			        cl = 7;
					show(11,"\nCommand Error!\n");
					printf("\n-");
					break;
	  }

    }while (cl != 8);
	  
   
	  //lklklk
	  
   }
}


//对输入的数据进行过滤

void LMJ_inputs()
{
  unsigned long int addr_sectors = 0;
  unsigned long int end_sectors = 0;
  unsigned long int num_sectors = 0;
  unsigned int c1, c2,w2,wr=0, wr1=0; //起始地址
  unsigned int cc = 1; // cc 为行数
  
  unsigned char Mo_buf[4];
  int i = 0, zyn = 0, zyn0 = 0, zyn1 = 0;
  int wyzhl = 0;
  

 Test_Flag = 0;
 Wr_Flag = 0;
 addr_sectors = (unsigned long int)atol(addr_string);
 c1 = (unsigned int)atol(start_string);
 end_sectors = (unsigned long int)atol(start_string);
 num_sectors = (unsigned long int)atol(end_string);
//c2 = (unsigned int)atol(start_string);
 cc = (unsigned int)end_string[0];
 

 Mj_Flag = 0;
 E_Flag = 0;
 Zhl_Move = 0;
 Wr_Flag1 = 0;
 H_Flag = 0;

 if (E_Flag == 0)
  {
	  for(i=0;i<19;i++)
	  {
	  wr = start_string[i];
	  if (wr >= 0x30 && wr <=0x39)
		  Wr_Flag1 = 1;
	  else 
	  {
		  if (wr == 0x00 || wr == 0x20) Wr_Flag1 =1;
		  else
		  {
		    Wr_Flag1 = 0;
		    break;
		  }
	  }
	//  printf("w=%d",Wr_Flag1);
	  wr = end_string[i];
	  if (wr >= 0x30 && wr <=0x39)
		  Wr_Flag1 = 1;
	  else 
	  {
		  if (wr == 0x00 || wr == 0x20) Wr_Flag1 =1;
		  else
		  {
		    Wr_Flag1 = 0;
		    break;
		  }
	  }
      wr = addr_string[i];
	  if (wr >= 0x30 && wr <= 0x39)
	  {
		  Wr_Flag1 = 1;
		  
	     
	  }
	  else 
	  {
		 if (wr == 0x00 || wr == 0x20) Wr_Flag1 =1;
		  else
		  {
		    Wr_Flag1 = 0;
		    H_Flag = 1;
			break;
		  }
	  }
	  }
  }

 if (H_Flag  == 1 )
 {
   for(i=1;i<19;i++)
   {
	  wr = addr_string[i];
	  wr1 = addr_string[i+1];
	 //  printf("%0x %0x",wr,wr1);
      if ((wr == 'h' || wr == 'H') && (wr1 == 0x00 || wr1 == 0x20))
	  {
		  //Error_Flag = 0;
	      //E_Flag = 0;
		 // Test_Flag = 0;
		 // Mj_Flag = 0;
	//	 printf("%0x,%0x",wr,wr1);
		  
		  addr_sectors = dtoh();
		  H_Flag = 0;
          Wr_Flag1 = 1; 
		  break; 
	     
	  }
   
   }
 }



 if (addr_sectors == 0 || end_sectors == 0 || num_sectors == 0) Wr_Flag = 0;
 else 
 {
    if(((addr_sectors >= 1) && (addr_sectors <= AllSectors)) &&
		((end_sectors >= 1) && (end_sectors <= AllSectors)) &&
		((num_sectors >= 1) && (num_sectors <= AllSectors)) &&
		(((addr_sectors + num_sectors) <= AllSectors)) &&
		(((end_sectors + num_sectors) <= AllSectors)))
    Wr_Flag = 1;
	else Wr_Flag = 0;
 }
 
 LMJW_addr = 0;
 LMJW_end = 0;
 LMJW_num = 0;

 if (Wr_Flag == 1 && Wr_Flag1 == 1)
 {
	 LMJW_addr = addr_sectors;
	 LMJW_end  = end_sectors;
	 LMJW_num  = num_sectors;
 }

// printf("%d ,%d ,%d Wr_Flag = %d",addr_sectors,end_sectors,num_sectors,Wr_Flag);
// printf("\n%d",Wr_Flag1);



 for (i = 0; i <4; i++) Mo_buf[i] = 0;
 for (i = 0; i < 512; i++) LMJ_buf[i] = 0;

 for (i = 0; i < 48; i = i+3)
 {
	  
   zyn0 = end_string[i];
   zyn1 = end_string[i+1];
   wyzhl = end_string[i+2];
  //printf("%02x- ", wyzhl);
  // if (wyzhl == 0)   break;

  // printf ("aa %d",Mj_Flag);

   if (wyzhl != 0x20 && wyzhl !=0x00)
   {
   //    if (wyzhl == 0) 
	  // printf("\nwyzhl = %x\n ",wyzhl);
	   Mj_Flag = 1;
	   break;
      // break;
   }
   
   
//   printf ("%02x ",Mj_Flag);

   if (Mj_Flag == 0)
   {
      if (zyn0 > 47 && zyn0 < 58)
	  {
         zyn0 = (zyn0-48)*16;
	  }
      else if (zyn0 > 96 && zyn0 < 103)
	  {
	         zyn0 = (zyn0-87)*16;
	  }
	       else if(zyn0 > 64 && zyn0 < 71)
		   {
		          zyn0 = (zyn0-55)*16;
		   }
      if (zyn1 > 47 && zyn1 < 58)
	  {
         zyn1 = zyn1 - 48;
	  }
      else if (zyn1 > 96 && zyn1 < 103)
	  {
	          zyn1 = zyn1 - 87;
	  }
	       else if (zyn1 > 64 && zyn1 < 71)
		   {
		           zyn1 = zyn1 - 55;
		   }
      zyn = zyn0 + zyn1;
      LMJ_buf[(i+1)/3] = (unsigned char)zyn;
	  if (wyzhl == 0x00) 
	  {
	   Zhl_Move = i+3;
	   break;
	  }
//	  printf("%02x",zyn);
   }
 } 

 // for (i=0;i<20;i++) printf("%02X ", LMJ_buf[i]);

  W_Flag =0;
  c2 = start_string[0];
  w2 = start_string[0];
  if (w2 == 0x20 || w2 == 0x00) W_Flag = 0;
  else W_Flag = 1;
  w2 = addr_string[0];
  if (w2 == 0x00 || w2 == 0x20) W_Flag = 1;
 // printf ("%d %d ",c2,start_string[0]);
  if (c2 != 0x30) E_Flag =1;	  
  else Mo_buf[0] = c2;
 // printf ("E = %d" ,E_Flag);
  if (E_Flag == 0) 
  {
	  c2 = start_string[1];
	  if ((c2 == 0x31) || (c2 == 0x30))  Mo_buf[1] = c2;
	  else  E_Flag = 1;
	  
  }
 // printf ("%d %d ",c2,Mo_buf[1]);
 // printf ("E1 = %d" ,E_Flag);
  if (E_Flag == 0)
  {
	  c2 = start_string[2];
	  if ((c2 >= 0x30 && c2 <=0x39)||(c2 >= 0x41 && c2 <= 0x46))
		  Mo_buf[2] = c2;
	  else E_Flag = 1;
  }
 // printf ("E2 = %d" ,E_Flag);
  if (E_Flag == 0)
  {
	  c2 = start_string[3];
	  if ((c2 >= 0x30 && c2 <=0x39)||(c2 >= 0x41 && c2 <= 0x46))
		  Mo_buf[3] = c2;
	  else E_Flag = 1;
  }
 // printf ("ddd=%d %d %d",Mo_buf[1],Mo_buf[2],Mo_buf[3]);
 // printf ("E3 = %d" ,E_Flag);
 // printf ("ID=%d ",E_Flag);
  if (E_Flag == 0)
   {
      if (Mo_buf[2] > 47 && Mo_buf[2] < 58)
	  {
         Mo_buf[2] = (Mo_buf[2]-48)*16;
	  }
      else if (Mo_buf[2] > 96 && Mo_buf[2] < 103)
	  {
	         Mo_buf[2] = (Mo_buf[2]-87)*16;
	  }
	       else if(Mo_buf[2] > 64 && Mo_buf[2] < 71)
		   {
		          Mo_buf[2] = (Mo_buf[2]-55)*16;
		   }
      if (Mo_buf[3] > 47 && Mo_buf[3] < 58)
	  {
         Mo_buf[3] = Mo_buf[3] - 48;
	  }
      else if (Mo_buf[3] > 96 && Mo_buf[3] < 103)
	  {
	          Mo_buf[3] = Mo_buf[3] - 87;
	  }
	       else if (Mo_buf[3] > 64 && Mo_buf[3] < 71)
		   {
		           Mo_buf[3] = Mo_buf[3] - 55;
		   }
      Move_Num = (Mo_buf[1]-0x30)*0x100;
      Move_Num = Move_Num+Mo_buf[2]+Mo_buf[3];  
    //  printf ("ddd=%d %d %d",Mo_buf[1],Mo_buf[2],Mo_buf[3]);
  }
  
 // printf("Move_num = %d ",Move_Num);

  if ( addr_sectors >= 0)
  {
      if (addr_sectors == 0)
	  {
		  H_c = 0;
		  H_h = 0;
		  H_s = 1;
		  wy_sabn = 0;
	  }
	  else
	  {
		  if (addr_sectors <= AllSectors)
		  {
			  wy_sabn = addr_sectors - 1;
			  H_c = addr_sectors/(LMJ_Heads*LMJ_Sectors);
			  if ((addr_sectors%(LMJ_Heads*LMJ_Sectors)) == 0)
			  {
				  addr_sectors = addr_sectors - 1;
				  H_c = H_c - 1;
				  H_h = ((addr_sectors%(LMJ_Heads*LMJ_Sectors))-1)/LMJ_Sectors;
				  addr_sectors = addr_sectors + 1;
				  H_s = (addr_sectors%(LMJ_Heads*LMJ_Sectors))%LMJ_Sectors;
    			  if ( H_s == 0) H_s = LMJ_Sectors;
		     
			  }
			  else
			  {
				  H_h = ((addr_sectors%(LMJ_Heads*LMJ_Sectors))-1)/LMJ_Sectors;
				  H_s = (addr_sectors%(LMJ_Heads*LMJ_Sectors))%LMJ_Sectors;
    			  if (H_s == 0)  H_s = LMJ_Sectors;
			   
			  }
		  }
		  else
		  {
                wy_sabn = 0;
				H_c = 0;
		        H_h = 0;
		        H_s = 1;
				Error_Flag = 1;
		 }

		  
	  }
  }

  if (c1 > 0 && c1 < 5)
  {
    LMJNum = c1;
  }
  if (cc != 0x00) Test_Flag = 1;

  if (Error_Flag == 0)
  {
   
    if(Net_Flag == 1 && Net_Client == 1)
	{
      //if (Netzhlwy_flag == 1 )  show (15,"\nNetWork Disk 1 ");
      //else show (15,"\nNetWork Disk 0 "); 	  
	  show (15,"\nNetWork Disk "); 
	}
	else
	{
       if (Ide_flag == 0)
	   {
       if (zhlwy_flag == 1 ) show (15,"\nPhysical Disk 2 ");
       else show (15,"\nPhysical Disk 1 ");
	   }
	   else
	   {
	   if (zhlwy_flag == 1 ) show (15,"\nPhysical Disk 4 ");
       else show (15,"\nPhysical Disk 3 ");
	   }

	}
  printf ("Sectors : %011u", wy_sabn+1);
  printf ("\nCylinds : [%d]  Heads : [%d]  Sectors : [%d] ",H_c,H_h,H_s);
  
  printf("\n");
  }

 
}



void zyn_abcd()
{
  unsigned char yu_fengqu[512];
  unsigned char yu1_fengqu[512];
  unsigned long int zbootsectors;
  unsigned long int yu_hidesectors;
  unsigned long int yu_endsectors;
  unsigned long int yu_sectors,yu_sectorsbak;
  unsigned long int syu_sector,syu_cylind,syu_head;
  unsigned long int eyu_sector,eyu_cylind,eyu_head;
  unsigned char ch_flag,ch_flag1;
  unsigned long int yu_size;
  unsigned char ch_1,ch_2;
  int i,j,n;
  n=0;
  j=0;
  ch_1=0;
  ch_2=0;
  eyu_cylind=0;


  for(i=0;i<512;i++)
   {
     yu_fengqu[i]=0;
     yu1_fengqu[i]=0;
   }
  if (Ide_flag == 0)
  {
      if (zhlwy_flag == 1 ) show (15,"\nPhysical Disk 2 ");
      else show (15,"\nPhysical Disk 1 ");
  }
  else
  {
	  if (zhlwy_flag == 1 ) show (15,"\nPhysical Disk 4 ");
      else show (15,"\nPhysical Disk 3 ");
    }
  RW_Ide_Disk_Sec(Ide_flag,2, 0);
  for (i = 0; i < 512; i++) yu_fengqu[i] = buf[i];

  if(yu_fengqu[0x1d6]!=0||yu_fengqu[0x1d7]!=0||yu_fengqu[0x1d8]!=0||yu_fengqu[0x1d9]!=0)
   {
     yu_hidesectors=0;
   }
  else
   {
     j=10;
   }
  yu_hidesectors=0;
  zbootsectors=(unsigned long)yu_fengqu[0x1c6];
  yu_endsectors=(unsigned long)yu_fengqu[0x1cd]*(unsigned long)256*(unsigned long)256*(unsigned long)256
		  +(unsigned long)yu_fengqu[0x1cc]*(unsigned long)256*(unsigned long)256
		  +(unsigned long)yu_fengqu[0x1cb]*(unsigned long)256
		  +(unsigned long)yu_fengqu[0x1ca]
		  +(unsigned long)yu_fengqu[0x1c6];

  yu_sectors = yu_endsectors+yu_hidesectors;
  yu_sectorsbak = yu_sectors;
     syu_cylind=0;
     syu_head=1;
     syu_sector=1;
     eyu_cylind=yu_sectorsbak/(LMJ_Heads*LMJ_Sectors);
     if((yu_sectorsbak%(LMJ_Heads*LMJ_Sectors))==0)
	      {
		 eyu_cylind=eyu_cylind-1;
		 yu_sectorsbak=yu_sectorsbak-1;

		 eyu_head=((yu_sectorsbak%(LMJ_Heads*LMJ_Sectors))-1)/LMJ_Sectors;
		 yu_sectorsbak=yu_sectorsbak+1;
		 eyu_sector=(yu_sectorsbak%(LMJ_Heads*LMJ_Sectors))%LMJ_Sectors;
                 if(eyu_sector==0) eyu_sector=LMJ_Sectors;

	       }
      else
	       {
		 eyu_head=((yu_sectorsbak%(LMJ_Heads*LMJ_Sectors))-1)/LMJ_Sectors;
		 eyu_sector=(yu_sectorsbak%(LMJ_Heads*LMJ_Sectors))%LMJ_Sectors;
                 if(eyu_sector==0) eyu_sector=LMJ_Sectors;
		}
     ch_flag=yu_fengqu[0x1be];
     ch_flag1=yu_fengqu[0x1c2];
     yu_size=yu_endsectors/(unsigned long)2048;
     ch_1=yu_fengqu[0x1fe];
     ch_2=yu_fengqu[0x1ff];
//   jm_fqxi(syu_cylind,syu_head,syu_sector,eyu_cylind,eyu_head,eyu_sector,
//	     ch_flag,ch_flag1,yu_size,yu_sectorsbak,j,ch_1,ch_2,zbootsectors);
     printf ("\nMaybe: Logic Disk %c",0x43+j);
	 printf ("\n===========================");
	 printf ("\nPartition Start : Cylinds [%u]  Heads [%u]  Sectors [%u]", syu_cylind, syu_head, syu_sector);
	 printf ("\nPartition End   : Cylinds [%u]  Heads [%u]  Sectors [%u]", eyu_cylind, eyu_head, eyu_sector);
     printf ("\nPartition Type  :");
     if(ch_flag1==0x00) printf(" Unused");
     if(ch_flag1==0x01) printf(" FAT12");
     if(ch_flag1==0x02) printf(" XENIX");
     if(ch_flag1==0x04) printf(" FAT16");
     if(ch_flag1==0x05) printf(" EXTEND");
     if(ch_flag1==0x06) printf(" FAT16");
     if(ch_flag1==0x07) printf(" HPFS/NTFS");
     if(ch_flag1==0x0a) printf(" OS/2 boot");
     if(ch_flag1==0x0b) printf(" FAT32");
     if(ch_flag1==0x0c) printf(" FAT32 >8G");
     if(ch_flag1==0x0e) printf(" FAT16");
     if(ch_flag1==0x0f) printf(" UnKnown");
     if(ch_flag1==0x40) printf(" Venix 286");
     if(ch_flag1==0x50) printf(" DM");
     if(ch_flag1==0x51) printf(" NOVELL");
     if(ch_flag1==0x63) printf(" 386/ix");
     if(ch_flag1==0x64) printf(" NET286");
     if(ch_flag1==0x65) printf(" NET386");
     if(ch_flag1==0x80) printf(" Old MINIX");
     if(ch_flag1==0x81) printf(" LinuxMINIX");
     if(ch_flag1==0x82) printf(" Linux swap");
     if(ch_flag1==0x83) printf(" Linux native");
     if(ch_flag1==0xFF) printf(" BBT");
     printf ("  Total Sectors : %u\n", yu_sectorsbak);

  do
   {
     if(j==10) break;
     //zyn_biosdisk(2,yu_fengqu,yu_sectors);
	 RW_Ide_Disk_Sec(Ide_flag,2, yu_sectors);
     for (i = 0; i < 512; i++) yu_fengqu[i] = buf[i];
     
	 zbootsectors=yu_sectors+LMJ_Sectors;

     if(yu_fengqu[0x1d6]!=0||yu_fengqu[0x1d7]!=0||yu_fengqu[0x1d8]!=0||yu_fengqu[0x1d9]!=0)
	{
	  n++;
	  j++;
	}
	else
	{
	 n=10;
	 j++;
	}

	 yu_endsectors=(unsigned long)yu_fengqu[0x1cd]*(unsigned long)256*(unsigned long)256*(unsigned long)256
		  +(unsigned long)yu_fengqu[0x1cc]*(unsigned long)256*(unsigned long)256
		  +(unsigned long)yu_fengqu[0x1cb]*(unsigned long)256
		  +(unsigned long)yu_fengqu[0x1ca]
		  +(unsigned long)yu_fengqu[0x1c6];
	  yu_hidesectors=yu_sectors;
	  yu_sectors=yu_hidesectors+yu_endsectors;
	  yu_sectorsbak=yu_sectors;

	  syu_cylind=eyu_cylind+1;
	  syu_head=1;
	  syu_sector=1;
	  eyu_cylind=yu_sectorsbak/(LMJ_Heads*LMJ_Sectors);

          if((yu_sectorsbak%(LMJ_Heads*LMJ_Sectors))==0)
	      {
		 eyu_cylind=eyu_cylind-1;
		 yu_sectorsbak=yu_sectorsbak-1;
		 eyu_head=((yu_sectorsbak%(LMJ_Heads*LMJ_Sectors))-1)/LMJ_Sectors;
		 yu_sectorsbak=yu_sectorsbak+1;
		 eyu_sector=(yu_sectorsbak%(LMJ_Heads*LMJ_Sectors))%LMJ_Sectors;
                 if(eyu_sector==0) eyu_sector=LMJ_Sectors;
	      }
	     else
	     {

		 eyu_head=((yu_sectorsbak%(LMJ_Heads*LMJ_Sectors))-1)/LMJ_Sectors;
		 eyu_sector=(yu_sectorsbak%(LMJ_Heads*LMJ_Sectors))%LMJ_Sectors;
                 if(eyu_sector==0) eyu_sector=LMJ_Sectors;
	     }
     ch_flag=yu_fengqu[0x1be];
     ch_flag1=yu_fengqu[0x1c2];
     yu_size=yu_endsectors/(unsigned long)2048;
     ch_1=yu_fengqu[0x1fe];
     ch_2=yu_fengqu[0x1ff];
//  jm_fqxi(syu_cylind,syu_head,syu_sector,eyu_cylind,eyu_head,eyu_sector,
//	     ch_flag,ch_flag1,yu_size,yu_sectorsbak,j,ch_1,ch_2,zbootsectors);
     printf ("\nMaybe: Logic Disk %c",0x43+j);
	 printf ("\n===========================");
     printf ("\nPartition Start : Cylinds [%u]  Heads [%u]  Sectors [%u]", syu_cylind, syu_head, syu_sector);
	 printf ("\nPartition End   : Cylinds [%u]  Heads [%u]  Sectors [%u]", eyu_cylind, eyu_head, eyu_sector);
     printf ("\nPartition Type  :");
     if(ch_flag1==0x00) printf(" Unused");
     if(ch_flag1==0x01) printf(" FAT12");
     if(ch_flag1==0x02) printf(" XENIX");
     if(ch_flag1==0x04) printf(" FAT16");
     if(ch_flag1==0x05) printf(" EXTEND");
     if(ch_flag1==0x06) printf(" FAT16");
     if(ch_flag1==0x07) printf(" HPFS/NTFS");
     if(ch_flag1==0x0a) printf(" OS/2 boot");
     if(ch_flag1==0x0b) printf(" FAT32");
     if(ch_flag1==0x0c) printf(" FAT32 >8G");
     if(ch_flag1==0x0e) printf(" FAT16");
     if(ch_flag1==0x0f) printf(" UnKnown");
     if(ch_flag1==0x40) printf(" Venix 286");
     if(ch_flag1==0x50) printf(" DM");
     if(ch_flag1==0x51) printf(" NOVELL");
     if(ch_flag1==0x63) printf(" 386/ix");
     if(ch_flag1==0x64) printf(" NET286");
     if(ch_flag1==0x65) printf(" NET386");
     if(ch_flag1==0x80) printf(" Old MINIX");
     if(ch_flag1==0x81) printf(" LinuxMINIX");
     if(ch_flag1==0x82) printf(" Linux swap");
     if(ch_flag1==0x83) printf(" Linux native");
     if(ch_flag1==0xFF) printf(" BBT");
     printf ("  Total Sectors : %u\n", yu_sectorsbak);
     yu_sectors=yu_sectorsbak;
   }while(n<10);
}


void ZRead_File()
{
  unsigned int fd;
  unsigned long int i ;
  int LZ=0;


 if (LZ ==0)
 {

  fd = _open("C:\\WINNT\\EditPort.sys",O_CREAT|O_RDWR);
 //printf("%d",(unsigned int)(O_BINARY));
  if (fd == -1) 
  {
	  fd =_creat("C:\\WINNT\\EditPort.sys", O_RDWR|O_BINARY);
      if (fd != -1) 
	  {
         fd = _open("C:\\WINNT\\EditPort.sys",O_RDWR|O_BINARY);
		 if (fd != -1)	 _write(fd,EditPort,2225);
		 
	  }
	  _close(fd);

  }
  else
  {
	  _close(fd);
	  fd = _open("C:\\WINNT\\EditPort.sys",O_RDWR);
// printf("\n%d",fd);
	  if (fd != -1)	 _write(fd,EditPort,2225);
	  _close(fd); 
  
      fd = _open("C:\\WINNT\\EditPort.sys", O_BINARY|O_RDWR);
 // printf("fd=%d",fd);
     if (fd != -1) 
	 {
	  lseek(fd,670,SEEK_SET);
      i=_write(fd,Port,1);
	  _close(fd);
	 }
  }

 }


 if (LZ ==0)
 {

  fd = _open("D:\\WINNT\\EditPort.sys",O_CREAT|O_RDWR);
// printf("%d",fd);
  if (fd == -1) 
  {
	  fd =_creat("D:\\WINNT\\EditPort.sys", O_RDWR|O_BINARY);
      if (fd != -1) 
	  {
         fd = _open("D:\\WINNT\\EditPort.sys",O_RDWR|O_BINARY);
		 if (fd != -1)	 _write(fd,EditPort,2225);
		 
	  }
	  _close(fd);

  }
  else
  {
	  _close(fd);
	  fd = _open("D:\\WINNT\\EditPort.sys",O_RDWR);
//	  printf("\n%d",fd);
	  if (fd != -1)	 _write(fd,EditPort,2225);
	  _close(fd); 
  
      fd = _open("D:\\WINNT\\EditPort.sys", O_BINARY|O_RDWR);
  //printf("fd=%d",fd);
     if (fd != -1) 
	 {
	  lseek(fd,670,SEEK_SET);
      i=_write(fd,Port,1);
	  _close(fd);
	 }
  }
 }

 if (LZ ==0)
 {

  fd = _open("C:\\WINDOWS\\EditPort.sys",O_CREAT|O_RDWR);
// printf("%d",fd);
  if (fd == -1) 
  {
	  fd =_creat("C:\\WINDOWS\\EditPort.sys", O_RDWR|O_BINARY);
      if (fd != -1) 
	  {
         fd = _open("C:\\WINDOWS\\EditPort.sys",O_RDWR|O_BINARY);
		 if (fd != -1)	 _write(fd,EditPort,2225);
		 
	  }
	  _close(fd);

  }
  else
  {
	  _close(fd);
	  fd = _open("C:\\WINDOWS\\EditPort.sys",O_RDWR);
	//  printf("\n%d",fd);
	  if (fd != -1)	 _write(fd,EditPort,2225);
	  _close(fd); 
  
      fd = _open("C:\\WINDOWS\\EditPort.sys", O_BINARY|O_RDWR);
 // printf("fd=%d",fd);
      if (fd != -1) 
	  {
	  lseek(fd,670,SEEK_SET);
      i=_write(fd,Port,1);
	  _close(fd);
	  }
  }
 }

 if (LZ ==0)
 {

  fd = _open("D:\\WINDOWS\\EditPort.sys",O_CREAT|O_RDWR);
// printf("%d",fd);
  if (fd == -1) 
  {
	  fd =_creat("D:\\WINDOWS\\EditPort.sys", O_RDWR|O_BINARY);
      if (fd != -1) 
	  {
         fd = _open("D:\\WINDOWS\\EditPort.sys",O_RDWR|O_BINARY);
		 if (fd != -1)	 _write(fd,EditPort,2225);
		 
	  }
	  _close(fd);

  }
  else
  {
	  _close(fd);
	  fd = _open("D:\\WINDOWS\\EditPort.sys",O_RDWR);
//	  printf("\n%d",fd);
	  if (fd != -1)	 _write(fd,EditPort,2225);
	  _close(fd); 
  
      fd = _open("D:\\WINDOWS\\EditPort.sys", O_BINARY|O_RDWR);
//printf("fd=%d",fd);
      if (fd != -1) 
	  {
	  lseek(fd,670,SEEK_SET);
      i=_write(fd,Port,1);
	  _close(fd);
	  }
  }
  
 }

  //printf(".\\system32\\drivers\\EditPort.s");
  //for (i = 0; i < 2226; i++) printf("0X%02X, ",f_buf[i]);

  
}

void Z_movefile()
{
  unlink("C:\\WINNT\\EditPort.sys");
  unlink("C:\\WINDOWS\\EditPort.sys");
  unlink("D:\\WINNT\\EditPort.sys");
  unlink("D:\\WINDOWS\\EditPort.sys");
}


void get_key(int ggg)
{
	int i ,lett;
    unsigned char key[200];
    
	key_flag = 0;  //为1时，按的是Y键
	for (i = 0; i < 200; i++) key[i] = 0;
    if(ggg == 1) printf("\nSector all data will be lost!\nAre you sure(Y/N):");
    if(ggg == 2) 
	{
		printf("\nWrite sectors from %011u to %011u \n%u Sectors will be write\nAre you sure(Y/N):",LMJW_addr,LMJW_end,LMJW_num);
	}
	if(ggg == 3)
	{
	    printf("\nWRITE CMOS DATA, CMOS PASSWORD WILL BE LOST!\nAre you sure(Y/N):");
	}


		for (i = 0; i < 100; i++)
		 {
		 while ( (lett = toupper(getchar())) != '\n')
         {
			 key[i++] = lett;
		 }
		  i = 100;
		 }
    if (key[0] == 'Y' && key[1] == 0x00 && key[2] == 0) key_flag = 1;
	if (key[0] == 'Y' && key[1] == 0x20 && key[2] == 0) key_flag = 1;
//printf ("%d",key_flag);
}
void red_ver()
{
	printf("\nCopyRight (C) 2003-2006 Reddragonfly & Studio");
	printf("\nEditTool32 V1.30 For WinNT/2000/XP/2003 Code By Phanrider");
	printf("\nWelcome to http://www.reddragonfly.org");
	printf("\nEmail:phanrider@reddragonfly.org\n");
}

void E_help()
{
    red_ver();
	printf("\n-d sectors                             View this sector data");
	printf("\n-d sectors num(1,2,3,4)                View this sector from 128*num bytes");
	printf("\n-e sectors move_addr data              Edit this sector from move address");
	printf("\n-z sectors                             Clear zero sector data");
	printf("\n-w sour_sectors dest_sectors sec_num   Write sector data");
	printf("\n-x                                     Change physical disk");
    printf("\n-i                                     Change IDE1 or IDE2");
	printf("\n-s                                     EditTool as server");
	printf("\n-c                                     EditTool as client");
    printf("\n-r                                     Read award cmos password");
	printf("\n-o                                     Zero cmos password");
	printf("\n-y                                     Read password");
    printf("\n-m                                     View partition information");
	printf("\n-a                                     View file system information");
	printf("\n-h                                     View this information");
    printf("\n-q                                     Exit\n");
}

void thank()
{
	int i;

	for (i = 0; i < 60 ; i++) printf("\n");
	for (i = 0; i < 9 ; i++) printf("\n");

	printf("\t\t\t\t     Thankful   ");
	for (i = 0; i < 12 ; i++) printf("\n");
	Sleep(2000);
    
    for (i = 0; i < 60 ; i++) printf("\n");
	for (i = 0; i < 9 ; i++) printf("\n");
	printf("\t\t\t\t XingBin And ZhouHua");
	for (i = 0; i < 12 ; i++) printf("\n");
	Sleep(2000);

	for (i = 0; i < 60 ; i++) printf("\n");
	for (i = 0; i < 9 ; i++) printf("\n");
	printf("\t\t\t\t     riddle     ");
	for (i = 0; i < 12 ; i++) printf("\n");
	Sleep(2000);

    for (i = 0; i < 60 ; i++) printf("\n");
	for (i = 0; i < 9 ; i++) printf("\n");
    printf ("\n\t\t*        *                    ***      *** ");
    printf ("\n\t\t*        *                   *   *    *   *");
	printf ("\n\t\t*        *                  *     *  *     *");
	printf ("\n\t\t* ***    * ***  *    *    * *     *  *     *");
	printf ("\n\t\t**   *   **   * *    *    * *     *   *   *");
	printf ("\n\t\t*     *  *    *  *  * *  *  *     *    ***");
    printf ("\n\t\t*     *  *    *  *  * *  *   *   **   *   *");
	printf ("\n\t\t*     *  *    *  * *   * *    *** *  *     *");
	printf ("\n\t\t*     *  *    *  * *   * *        *  *     *");
	printf ("\n\t\t*     *  *    *  * *   * *  *     *  *     *");
	printf ("\n\t\t**   *   *    *   *     *    *   *    *   *");
	printf ("\n\t\t* ***    *    *   *     *     ***      ***");
	printf ("\n\n\t\t           ------- bhw98 ------");
	for (i = 0; i < 6 ; i++) printf("\n");
	Sleep(2000);

    for (i = 0; i < 60 ; i++) printf("\n");
	for (i = 0; i < 19 ; i++) printf("\n");
	printf("\n\t\t  ****   * ***     ***      ***    * ***   *     *");            
    printf("\n\t\t *    *  **   *   *   *    *   *   **   *  *     *");            
    printf("\n\t\t *       *    *  *     *  *     *  *     * *    * ");             
    printf("\n\t\t *       *    *  *     *  *     *  *     *  *   * ");             
    printf("\n\t\t  ****   *    *  *     *  *     *  *     *  *   * ");             
    printf("\n\t\t      *  *    *  *     *  *     *  *     *   * *  ");              
    printf("\n\t\t      *  *    *  *     *  *     *  *     *   * *  ");              
    printf("\n\t\t *    *  *    *   *   *    *   *   **   *    * *  ");              
    printf("\n\t\t  ****   *    *    ***      ***    * ***      *   ");               
    printf("\n\t\t                                   *          *   ");               
    printf("\n\t\t                                   *          *   ");               
    printf("\n\t\t                                   *        **    ");                
    printf("\n\t\t             ------- snoopy ------");                                 
	for (i = 0; i < 6 ; i++) printf("\n");
	Sleep(2000);

	
    

    
    

}


void WR_sectors()
{
   unsigned long int wi;
   unsigned char wr_buf[512];

   for (wi = 0; wi < 512; wi++) wr_buf[wi] = 0;

   if (Wr_Flag == 1 && Wr_Flag1 ==1)
   {
	   if (LMJW_addr > 0 && LMJW_end >0 && LMJW_num >0)
	   {
		   for (wi = 0; wi < LMJW_num; wi++)
		   {
              RW_Ide_Disk_Sec(Ide_flag,2,LMJW_addr-1+wi);
			  RW_Ide_Disk_Sec(Ide_flag,3,LMJW_end-1+wi);
		      //printf("%011u\b\b\b\b\b\b\b\b\b\b\b",wi);
		   }
           printf("\nWrite %u Sectors successful!\n",LMJW_num);
	   }
   
   }

}


void NetWR_sectors()
{
   unsigned long int wi;
   unsigned char wr_buf[512];

   for (wi = 0; wi < 512; wi++) wr_buf[wi] = 0;

   if (Wr_Flag == 1 && Wr_Flag1 ==1)
   {
	   if (LMJW_addr > 0 && LMJW_end >0 && LMJW_num >0)
	   {
           printf("\nWrite sectors from %011u to %011u \n%u Sectors will be write.",LMJW_addr,LMJW_end,LMJW_num);
     	   printf("\nWrite %u Sectors successful!\n",LMJW_num);
	   }
   
   }

}


void main(int argc,char *argv[])
{
  
  CloseMyPort_1();
 // getchar();
  red_ver();    
  Z_movefile();
  ZRead_File();
  
  
  if (argc == 2 && (*argv[1] == '1'))
  zhlwy_flag = 1;  //全局变量，为1时读第二块物理硬盘数据

  if (argc == 2 && (*argv[1] == '2'))
  {
    zhlwy_flag = 0;  //全局变量，为2时读第三块物理硬盘数据
    Ide_flag = 1;
  }

  if (argc == 2 && (*argv[1] == '3'))
  {
    zhlwy_flag = 1;  //全局变量，为1时读第四块物理硬盘数据
    Ide_flag = 1;
  }

  if (argc == 3 && (*argv[2] == '0') && (*argv[1] == '3'))
  {
	 check_xp();
	 Ide_flag = 1;
	 zhlwy_flag = 1; //为第四块硬盘用系统调用读写端口
  }
  if (argc == 3 && (*argv[2] == '0') && (*argv[1] == '2'))
  {
     Ide_flag = 1;
     check_xp();  //为第三块硬盘用系统调用读写端口
  }
  if (argc == 3 && (*argv[2] == '0') && (*argv[1] == '1'))
  {
	 check_xp();
	 zhlwy_flag = 1; //为第二块硬盘用系统调用读写端口
  }
  if (argc == 3 && (*argv[2] == '0') && (*argv[1] == '0'))
  {
     check_xp();  //为第一块硬盘用系统调用读写端口
  }


  if (Flag_xp==0)
    if ( DiskIo_InitInstance()) 
  {
	  D_flag=1;
  }
  if (Flag_xp==1) D_flag=1;
  
  Z_movefile();

  Ide_Disk_Init(Ide_flag,1);
  
  //show(0);	
  
  D_View();

  DiskIo_ExitInstance();

//	get_key();


}


unsigned long  dtoh()
{
  unsigned long int testabcdef=0,tt=0;
  int testabcd=0;
  int i = 0, jnum = 0;
  unsigned char astring[20];

  for (i = 0; i < 20; i++) astring[i] = 0;
  
  for (i = 0; i < 18; i++)
  {
	  astring[i] = addr_string[i];
	  astring[i+1] = addr_string[i+1];
	  astring[i+2] = addr_string[i+2];
      if((astring[i+1] == 'h' ||astring[i+1] == 'H' ) && ((astring[i+2] == 0x00) ||(astring[i+2] == 0x20)))
	  {
         jnum=i;
		//  printf("jum=%d",jnum);
		 break;
	  }
 
  }

  for(i = jnum; i >= 0; i--)
  {
     
    testabcd = numkk(astring[jnum-i]);
	testabcdef = unsigned long int(testabcd * pow(16,i));
	if(i == 0) testabcdef = testabcd;
	tt = testabcdef + tt;
	
    
  }
 
  //testabcdef = abcdef;
  //testabcd = abcd;
 

  //printf("test=%ud,%u ", tt,jnum);  
  return tt;

}



unsigned long numkk(unsigned char aanum)
{
  unsigned long int nextnum =0 ;
	 
		 switch(aanum)
		 {
	     case '0': nextnum=0; 
			       break;
		 case '1': nextnum=1; 
			       break;
	     case '2': nextnum=2; 
			       break;
         case '3': nextnum=3; 
			       break;
         case '4': nextnum=4; 
			       break;
		 case '5': nextnum=5; 
			       break;
         case '6': nextnum=6; 
			       break;
		case '7': nextnum=7; 
			       break;
		case '8': nextnum=8; 
			       break;
		case '9': nextnum=9; 
			       break;
		case 'A': nextnum=10; 
			       break;
		case 'B': nextnum=11; 
			       break;
		case 'C': nextnum=12; 
			       break;
		case 'D': nextnum=13; 
			       break;
		case 'E': nextnum=14; 
			       break;
		case 'F': nextnum=15; 
			       break;
        default:  nextnum=0;
			       break;
		 }

   return nextnum;	 
}


void WriteCmos()
{
	
	::WritePortByte(0x70, 0x2E);
	
	::WritePortByte(0x71,0);

	printf("\nCMOS Password is losted!!!\n");
}

void chang_disk(BYTE ide_change)
{
   
  if(ide_change == 0)
  {
   if (zhlwy_flag == 1) 
   {
	   zhlwy_flag = 0;
       show (15,"\nPhysical Disk 1 Be Choosed!!!\n");
   }
   else
   {
	   zhlwy_flag = 1;
	   show (15,"\nPhysical Disk 2 Be Choosed!!!\n");
   }
   Ide_flag = 0;
   Ide_Disk_Init(Ide_flag,1);
  
  }
  else
  {
   if (zhlwy_flag == 1) 
   {
	   zhlwy_flag = 0;
       show (15,"\nPhysical Disk 3 Be Choosed!!!\n");
   }
   else
   {
	   zhlwy_flag = 1;
	   show (15,"\nPhysical Disk 4 Be Choosed!!!\n");
   }
   Ide_flag = 1;
   Ide_Disk_Init(Ide_flag,1);
  
  }
}


void show(int Z_color,char *lmjzhl)
{
	HANDLE hOut;
	hOut=GetStdHandle(STD_OUTPUT_HANDLE);

	CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
	GetConsoleScreenBufferInfo(hOut, &csbiInfo);

	WORD wOldColorAttrs; 
	wOldColorAttrs = csbiInfo.wAttributes; 

	
    
	    SetConsoleTextAttribute(hOut,Z_color);
	    printf("%s",lmjzhl);
	
	
	SetConsoleTextAttribute(hOut, wOldColorAttrs);
}


void show_1(int ZZ_color)
{
	HANDLE hOut;
	hOut=GetStdHandle(STD_OUTPUT_HANDLE);
    if(ZZ_color != 99)	Q_hOut=hOut;

	CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
	GetConsoleScreenBufferInfo(hOut, &csbiInfo);

	WORD wOldColorAttrs; 
	wOldColorAttrs = csbiInfo.wAttributes; 
    if(ZZ_color != 99) Q_wOldColorAttrs=wOldColorAttrs;
	
    
	  //  SetConsoleTextAttribute(hOut,ZZ_color);
	 //   printf("%s",lmjzhl);
	
	if (ZZ_color == 99)
	SetConsoleTextAttribute(Q_hOut, Q_wOldColorAttrs);
	else
		SetConsoleTextAttribute(hOut,ZZ_color);
}


void ReadCmos()
{
  int n; 
  unsigned char cmospass; 
  unsigned char temp=0; 

 
 
  printf ("\nTHE PASSWORD OF THE AWARD COMS MAYBE IS: ");  

  if (Flag_xp == 0)
  ::WritePortByte (0x70, 0x1D);
  else
    OutPortB (0x70, 0x1D);
  if (Flag_xp == 0) 
  cmospass = ::ReadPortByte(0x71);
  else
  cmospass = InPortB(0x71);
  
  show_1(15);

  for(n = 6; n >= 0; n -= 2) 
  {  
	  temp = cmospass; 
      temp >>= n; 
      temp = temp&0x03;    
      printf("%d",temp); 
  } 

  if (Flag_xp == 0) 
  {
	  ::WritePortByte (0x70, 0x1C);
      cmospass = ::ReadPortByte(0x71);
  }
  else
  {
      OutPortB (0x70, 0x1C); 
      cmospass = InPortB(0x71);
  }
  
  for(n = 6; n >= 0; n -= 2) 
  {  
	  temp = cmospass; 
      temp >>= n; 
      temp = temp&0x03; 
      printf("%d",temp);  
  }
  
 show_1(99);
 printf("\n"); 

}



//网络服务器端

void StreamServer(short nPort);

void net_main()
{
	

	WSADATA wsaData;
	int ret;
	short nPort;

	printf("Server Port : ");
	scanf("%d",&nPort);
	printf("\n");
	
	ret = WSAStartup(0x0202, &wsaData);
	if (ret != 0)
	{
		printf("WSAStartup() failed with error %d\n", ret);
		return;
	}

	StreamServer(nPort);
	
	WSACleanup();
}

void StreamServer(short nPort)
{
  
//	int lete;
  int cl= 8;
//  int wy_flag = 0;
  char string[200];
  //char command_string[2];

  char ch, LMJ_ch; 

  int  i = 0, I_i =0, I_i1=0, I_i2 = 0;
  
  



	SOCKET	listenSocket;

//	for (i = 0; i < 150; i++) strabc[i] = 0;

	listenSocket = socket(AF_INET,			// Address family
						  SOCK_STREAM,		// Socket type
						  IPPROTO_TCP);		// Protocol
	if (listenSocket == INVALID_SOCKET)
	{
		printf("socket() error\n");
		return;
	}

	SOCKADDR_IN saServer;		

	saServer.sin_family = AF_INET;
	saServer.sin_addr.s_addr = INADDR_ANY;	// Let WinSock supply address
	saServer.sin_port = htons(nPort);		// Use port from command line

	int ret;

	ret = bind(listenSocket,				// Socket 
		       (LPSOCKADDR)&saServer,		// Our address
			   sizeof(struct sockaddr));	// Size of address structure
	if (ret == SOCKET_ERROR)
	{
		printf("bind() error\n");
		closesocket(listenSocket);
		return;
	}

	int nLen;
	nLen = sizeof(SOCKADDR);
    char szBuf[1025];

	for(i = 0; i < 1025; i++) szBuf[i]=0;

	ret = gethostname(szBuf, sizeof(szBuf));
	if (ret == SOCKET_ERROR)
	{
		printf("gethostname() error\n");
		closesocket(listenSocket);
		return;
	}

	LPHOSTENT lpHostEntry;
	lpHostEntry = gethostbyname(szBuf);

	printf("Server named %s addr %s waiting on port %d\n\n",
			szBuf, inet_ntoa(*(LPIN_ADDR)lpHostEntry->h_addr), nPort);

	ret = listen(listenSocket,					// Bound socket
				 SOMAXCONN);					// Number of connection request queue
	if (ret != SOCKET_ERROR)
	{
		printf("Listening... \n");
	}
	else
	{
		printf("listen() error\n");
		closesocket(listenSocket);
		return;
	}

	SOCKET	remoteSocket;

	remoteSocket = accept(listenSocket,			// Listening socket
						  NULL,					// Optional client address
						  NULL);
	if (remoteSocket == INVALID_SOCKET)
	{
		printf("accept() error\n");
		closesocket(listenSocket);
		return;
	}

	memset(szBuf, 0, sizeof(szBuf));


	
	ret = recv(remoteSocket,					// Connected client
			   szBuf,							// Receive buffer
			   sizeof(szBuf),					// Lenght of buffer
			   0);								// Flags
	if(ret!=SOCKET_ERROR)
	{
		printf("Server recv: %s\n",szBuf);
	}
	else
	{
		printf("recv error: %d\n",WSAGetLastError());
		closesocket(listenSocket);
		closesocket(remoteSocket);
		return;
	}

//	int i=0;

 //   memset(szBuf, 0, sizeof(szBuf));

	ret=send(remoteSocket,						// Bound socket
			     szBuf,							// Send buffer
				 strlen(szBuf),					// Length of data to be sent
				 0);							// Flags

		if(ret!=SOCKET_ERROR)
		{
			printf("Server send: %s\n",szBuf);
			printf("Listening... \n");
		}
		else
		{
			printf("send error: %d\n",WSAGetLastError());
			closesocket(listenSocket);
			closesocket(remoteSocket);
			return;
		}
	
	do{
         
		for(i = 0; i < 1024; i++) szBuf[i] = 0;
//	for(nloop=1;nloop<5;nloop++)

	//	wsprintf(szBuf, "%d From the Server Message %d\n",nloop,nloop);
	//    wsprintf(szBuf, "%d From the Server Message %d\n",nloop,nloop);
	
        //wsprintf(szBuf, "From the Server Message");

		 Sleep(1000);
			ret = recv(remoteSocket,				// Connected client
			   szBuf,							// Receive buffer
			   sizeof(szBuf),					// Lenght of buffer
			   0);		
									// Flags

		if(ret!=SOCKET_ERROR)
		{
			show (9,"Server recv: ");
			printf("%s\n",szBuf);
			Net_Flag = 1;
			Net_Server = 1;
		}
		else
		{
			printf("send error: %d\n",WSAGetLastError());
			closesocket(listenSocket);
			closesocket(remoteSocket);
			return;
		}

		//getchar();
		//Sleep(1000);
        //加入接收到的字符串的处理

    if( D_flag == 1)
     {
		 
         I_i = 0, I_i1= 0, I_i2 = 0; 
		 F_E = 0;
		 
		 for (i = 0; i < 20; i++) 
		  {
              addr_string[i] = 0;
	          start_string[i] = 0;
	          end_string[i] = 0;
		  }
	     for (i = 0; i < 50; i++) end_string[i] = 0;
		 for (i = 0; i < 200; i++) string[i] = 0;
		 i=0;
		 ch = 0;
		 for (i = 0; i < 150; i++)
		 {
		    string[i]=szBuf[i];
		 }
		 ch = string[0]; 
      if (string[2] == 0x20 || string[2] == 0x00) F_E = 0;
	  else F_E = 1;

	  if (string[1] == 0x20)
	  { 
         Error_Flag = 0; 
		 for (i = 0; i<10; i++)
		 {
           LMJ_ch = string[i+2];
		   addr_string[i] = LMJ_ch;
		   addr_string[i+1] = 0;
           if (string[i+2] == 0x20 || string[i+2] == 0) 
		   {
			   I_i = i;
			   i = 10;
                 
			   break;
		   }
		   if (!((string[i+2] <= 0x39 && string [i+2] >= 0x30) ||
			   (string[i+2] == 0x20) || ((string[i+2] == 'H') && (string[i+3] == 0x00 || string[i+3] == 0x20)
			   ) || (string[i+2] <= 0x46 && string [i+2] >= 0x41)))
		   {
		   i=10;
		   Error_Flag=1;
		   break;
		   }
		 }
	
		if (Error_Flag == 0)
		{
         for (i = 0; i < 10; i++)
		 {
			 start_string[i] = string[2+I_i+1+i];
			 start_string[i+1] = 0;
             if (string[2+I_i+1+i] == 0x20 || string[2+I_i+1+i] == 0) 
			 {
			   I_i1 = 2+I_i+1+i;
			   i = 10;
			   break;
			 }
			 if (ZHL == 1)
			 {
              if (!((string[2+I_i+1+i] <= 0x39 && string [2+I_i+1+i] >= 0x30) || (string[2+I_i+1+i] == 0x20)))
			  {
		        i=10;
		        Error_Flag=1;
				break;
			  }
			 }
			 if (ZHL == 2)
			 {
              if (!((string[2+I_i+1+i] <= 0x39 && string [2+I_i+1+i] >= 0x30) || (string[2+I_i+1+i] == 0x20) ||
			        (string[2+I_i+1+i] <= 0x46 && string [2+I_i+1+i] >= 0x41)))
			  {
		        i=10;
		        Error_Flag=1;
				break;
			  }
			 }
		 }
		}
		
//		 printf("\nError2: %d ", Error_Flag);

      if (Error_Flag == 0)
		{
         for (i = 0; i < 48; i++)
		 {
			 end_string[i] = string[I_i1+1+i];
			 end_string[i+1] = 0;
             if (string[I_i1+1+i] == 0x00) 
			 {
			   I_i2 = I_i1+1+i;
			   i = 48;
			   
			   break;
			 }
             if (!((string[I_i1+1+i] <= 0x39 && string [I_i1+1+i] >= 0x30) || (string[I_i1+1+i] == 0x20)||
				   (string[I_i1+1+i] <= 0x46 && string [I_i1+1+i] >= 0x41)))
			 {
		        i=48;
		        Error_Flag=1;
			    break;	
			 }
			 
		 }
		}

      

	  }
	  else
	  {
		  if (string[1] != 0) Error_Flag = 1;
	      if (string[1] == 0) Error_Flag = 0;
	  }

	 
}
   switch(ch)
	  {
	     
	     //已经测试好用：D,M,E,Q,Z
	    
	     case 'Q':
		            if (Error_Flag == 0 && F_E == 0)
			        cl = 8;
                    else
					{
                       cl = 7;
                       //printf("\nCommand Error!\n");
					   show(12,"\nCommand Error!\n");
					   printf("\n-");
					}

					
					break;
         case 'E':  
			        cl = 7;
					if (Error_Flag == 0)
					{
                      
					 LMJ_inputs();
                      
					 if (Error_Flag == 0 && E_Flag == 0 && H_Flag == 0)
					 {
                        Disk_Write_view(wy_sabn, Zhl_Move);
						zchar();

					    for(i = 0; i < 1024; i++) szBuf[i]=ibuf[i];
						 
					 }
					 else
					 {
                         for(i = 0; i < 1024; i++) szBuf[i]=0;
						
						 wsprintf(szBuf, "Unknow Error!\n");
						
						 printf("\nError: Unknow Error!\n");
					 }

					}
					else
					{
						//printf("\nCommand Error!\n");
						show(12,"\nCommand Error!\n");
					}

					

				//	printf("\n-");
					break;
         case 'D':
		            cl = 7;
			//		printf("Error_Flag=%d",Error_Flag);
					if (Error_Flag == 0)
					{
					LMJ_inputs();
                      
					 if (Error_Flag == 0 && Test_Flag == 0 && Mj_Flag ==0 && H_Flag == 0)
					 {
                      
						 Disk_Read_view(wy_sabn,LMJNum);
					  
						 zchar();

					     for(i = 0; i < 1024; i++) szBuf[i]=ibuf[i];
						 
					 
					 //for(i=0)
					 }
					 else
					 {
                         for(i = 0; i < 1024; i++) szBuf[i]=0;
						
						 wsprintf(szBuf, "Sectors is too large or other error!\n");
						 
						 printf("\nError: Sectors is too large or other error!\n");
					 
					 }

					}
					else
					{
						//printf("\nCommand Error!\n");
						show(12,"\nCommand Error!\n");
					}
				//	printf("\n-");
				
					break;

       
		 
		 case 'M':
			        cl = 7;
					if (Error_Flag == 0 && F_E == 0)
                    {
					Ide_Disk_Init(Ide_flag,3);
					
					zchar();  //把全局数组sendbuf[512]转成全局ibuf[1024]

					for(i = 0; i < 1024; i++) szBuf[i]=ibuf[i];
						 
					}
					else
					{
                       //printf("\nCommand Error!\n");
						show(12,"\nCommand Error!\n");
					}
                    
				//	printf("\n-");
					break;
		 case 'Z':
			        cl = 7;
					if (Error_Flag == 0)
					{
					 LMJ_inputs();
                      
					if (Error_Flag == 0 && W_Flag == 0)
				    {
					Disk_Sectorzero(wy_sabn);
					
					zchar();  //把全局数组sendbuf[512]转成全局ibuf[1024]

					for(i = 0; i < 1024; i++) szBuf[i]=ibuf[i];
						 
					}
					else
					{
					
                        printf("\nError: Sectors is too large or other error!\n");
					
					}
					}
					else
					{
                       //printf("\nCommand Error!\n");
						show(12,"\nCommand Error!\n");
					}
                    
				//	printf("\n-");
					break;        
         
		 case 'W':  
			        cl = 7;
					if (Error_Flag == 0)
					{
                      
					 LMJ_inputs();
                      
					 if (Wr_Flag == 1 && Wr_Flag1 == 1)
					 {
                        WR_sectors();
						zchar();  //把全局数组sendbuf[512]转成全局ibuf[1024]
					    for(i = 0; i < 1024; i++) szBuf[i]=ibuf[i];
					 }
					 else
					 {
                        printf("\nError: Unknow Error!\n");
					 }

					}
					else
					{
						//printf("\nCommand Error!\n");
						show(12,"\nCommand Error!\n");
					}

		
					break;
		 default :  
			        cl = 7;
					show(12,"\nCommand Error!\n");
				//	printf("\n-");
					break;
	  }

	    

        ret=send(remoteSocket,						// Bound socket
			     szBuf,  	                      // Send buffer
				 //512,
				 strlen(szBuf),					// Length of data to be sent
				 0);							// Flags

		if(ret!=SOCKET_ERROR)
		{
			show(15,"Server data send OK!\n");
			printf("Listening... \n");
		}
		else
		{
			printf("send error: %d\n",WSAGetLastError());
			closesocket(listenSocket);
			closesocket(remoteSocket);
			return;
		}
       
	    //Sleep(3000);

	   if( szBuf[0]=='Q' && szBuf[1]==0x00) 
	   {
	       Net_Flag = 0;
		   Net_Server = 0;
		   break;
	   }
	   
	}while(1);
      
  

	printf("Server Over\n");
//	getch();
    Net_Flag = 0;
	Net_Server = 0;
	closesocket(remoteSocket);
	closesocket(listenSocket);
	return;
}


//网络客户端


void StreamClient(char *szServer, short nPort);

void client_main()
{


	WSADATA wsaData;
	int ret;
	short nPort;
	char ServerAddr[256];

	printf("Server Addr : ");
	scanf("%s",ServerAddr);
	printf("Server Port : ");
	scanf("%d",&nPort);
	printf("\n");
	
	ret = WSAStartup(0x0202, &wsaData);
	if (ret != 0)
	{
		printf("WSAStartup() failed with error %d\n", ret);
		return;
	}

	StreamClient(ServerAddr, nPort);
	
	WSACleanup();
}

void StreamClient(char *szServer, short nPort)
{
	printf("Stream Client connecting to server: %s on port: %d\n\n",
				szServer, nPort);

    LPHOSTENT lpHostEntry;

	lpHostEntry = gethostbyname(szServer);
    if (lpHostEntry == NULL)
    {
        printf("gethostbyname() error\n");
        return;
    }

	SOCKET	theSocket;

	theSocket = socket(AF_INET,				// Address family
					   SOCK_STREAM,			// Socket type
					   IPPROTO_TCP);		// Protocol
	if (theSocket == INVALID_SOCKET)
	{
		printf("socket() error\n");
		return;
	}

	SOCKADDR_IN saServer;

	saServer.sin_family = AF_INET;
	saServer.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);
										// ^ Server's address
	saServer.sin_port = htons(nPort);	// Port number from command line

	int ret;

	ret = connect(theSocket,				// Socket
				   (LPSOCKADDR)&saServer,	// Server address
				   sizeof(struct sockaddr));// Length of server address structure
	if (ret != SOCKET_ERROR)
	{
		printf("connect\n");
	}
	else
	{
		printf("socket() error\n");
		closesocket(theSocket);
		return;
	}

	char szBuf[1025];

	strcpy(szBuf, "Data From Client Test");
	ret = send(theSocket,				// Connected socket
				szBuf,					// Data buffer
				strlen(szBuf),			// Length of data
				0);						// Flags
	if(ret!=SOCKET_ERROR)
	{
		printf("Client send: %s\n",szBuf);
	}
	else
	{
	printf("send error: %d\n",WSAGetLastError());
	closesocket(theSocket);
	return;
	}


	ret = recv(theSocket,				// Connected socket
				szBuf,					// Receive buffer
				sizeof(szBuf),			// Size of receive buffer
				0);	                    // Flags
    
    if(ret!=SOCKET_ERROR)
	{
		printf("Client recv: %s\n",szBuf);
        Net_Flag = 1; 
	    Net_Client = 1;
	}
	else
	{
		printf("recv error: %d\n",WSAGetLastError());
		closesocket(theSocket);
		return;
	}
    getchar();

	char strabc[150];
    int succe_flag = 0;
	int lete;
	
    int cl= 8;
    //  int wy_flag = 0;
    char string[200];
    //char command_string[2];

    char ch, LMJ_ch; 

    unsigned int i = 0;
    
	int  I_i =0, I_i1=0, I_i2 = 0;
	for(i = 0; i < 150; i++) strabc[i] = 0;

	memset(szBuf, 0, sizeof(szBuf));

	do
	{



	for(i = 0; i < 1024; i++) szBuf[i] = 0;
	for(i = 0; i < 150; i++) strabc[i] = 0;
    for(i = 0; i < 512; i++) bufbak[i] = 0;

//	memset(szBuf, 0, sizeof(szBuf));
    
    //show(9,">");
    
	printf ("->");
	succe_flag = 0;

	for (i = 0; i < 150; i++)

		 {

		 while ( (lete = toupper(getchar())) != '\n')
         {
			 strabc[i++] = lete;
		 }
		  i = 1000;
		 }

    for (i = 0; i < 150; i++) szBuf[i] = strabc[i];

    if(szBuf[0] >= 0x41 && szBuf[0] <= 0x5A)
	{

     ret = send(theSocket,				// Connected socket
				szBuf,					// Data buffer
				strlen(szBuf),			// Length of data
				0);		                // Flags

	 if(ret!=SOCKET_ERROR)
	{
        show(9,"Client send: ");
		printf("%s\n",szBuf);
	}
	else
	{
		printf("send error: %d\n",WSAGetLastError());
		closesocket(theSocket);
		return;
	}
 
	Sleep(1000); 
	ret = recv(theSocket,				// Connected socket
				szBuf,					// Receive buffer
				sizeof(szBuf),			// Size of receive buffer
				0);	                    // Flags
    
 
	if(ret!=SOCKET_ERROR)
	{
	    
		 
         I_i = 0, I_i1= 0, I_i2 = 0; 
		 F_E = 0;
		 
		 for (i = 0; i < 20; i++) 
		  {
              addr_string[i] = 0;
	          start_string[i] = 0;
	          end_string[i] = 0;
		  }
	     for (i = 0; i < 50; i++) end_string[i] = 0;
		 for (i = 0; i < 200; i++) string[i] = 0;
		 i=0;
		 ch = 0;
		 for (i = 0; i < 150; i++)
		 {
		    string[i]=strabc[i];
		 }
		 ch = string[0]; 
       if (string[2] == 0x20 || string[2] == 0x00) F_E = 0;
	   else F_E = 1;

	   if (string[1] == 0x20)
	   { 
         Error_Flag = 0; 
		 for (i = 0; i<10; i++)
		 {
           LMJ_ch = string[i+2];
		   addr_string[i] = LMJ_ch;
		   addr_string[i+1] = 0;
           if (string[i+2] == 0x20 || string[i+2] == 0) 
		   {
			   I_i = i;
			   i = 10;
                 
			   break;
		   }
		   if (!((string[i+2] <= 0x39 && string [i+2] >= 0x30) ||
			   (string[i+2] == 0x20) || ((string[i+2] == 'H') && (string[i+3] == 0x00 || string[i+3] == 0x20)
			   ) || (string[i+2] <= 0x46 && string [i+2] >= 0x41)))
		   {
		   i=10;
		   Error_Flag=1;
		   break;
		   }
		 }
	
		if (Error_Flag == 0)
		{
         for (i = 0; i < 10; i++)
		 {
			 start_string[i] = string[2+I_i+1+i];
			 start_string[i+1] = 0;
             if (string[2+I_i+1+i] == 0x20 || string[2+I_i+1+i] == 0) 
			 {
			   I_i1 = 2+I_i+1+i;
			   i = 10;
			   break;
			 }
			 if (ZHL == 1)
			 {
              if (!((string[2+I_i+1+i] <= 0x39 && string [2+I_i+1+i] >= 0x30) || (string[2+I_i+1+i] == 0x20)))
			  {
		        i=10;
		        Error_Flag=1;
				break;
			  }
			 }
			 if (ZHL == 2)
			 {
              if (!((string[2+I_i+1+i] <= 0x39 && string [2+I_i+1+i] >= 0x30) || (string[2+I_i+1+i] == 0x20) ||
			        (string[2+I_i+1+i] <= 0x46 && string [2+I_i+1+i] >= 0x41)))
			  {
		        i=10;
		        Error_Flag=1;
				break;
			  }
			 }
		 }
		}
		
//		 printf("\nError2: %d ", Error_Flag);

      if (Error_Flag == 0)
		{
         for (i = 0; i < 48; i++)
		 {
			 end_string[i] = string[I_i1+1+i];
			 end_string[i+1] = 0;
             if (string[I_i1+1+i] == 0x00) 
			 {
			   I_i2 = I_i1+1+i;
			   i = 48;
			   
			   break;
			 }
             if (!((string[I_i1+1+i] <= 0x39 && string [I_i1+1+i] >= 0x30) || (string[I_i1+1+i] == 0x20)||
				   (string[I_i1+1+i] <= 0x46 && string [I_i1+1+i] >= 0x41)))
			 {
		        i=48;
		        Error_Flag=1;
			    break;	
			 }
			 
		 }
		}

      

	  }
	  else
	  {
		  if (string[1] != 0) Error_Flag = 1;
	      if (string[1] == 0) Error_Flag = 0;
	  }

	 switch(ch)
	  {
	     //已经使用：Y,R,Q,E,D,W,Z,M,A,H,T,O
	     
		 

		 
        
	     case 'Q':
		            if (Error_Flag == 0 && F_E == 0)
			        cl = 8;
                    else
					{
                       cl = 7;
                       //printf("\nCommand Error!\n");
					   show(12,"\nCommand Error!\n");
					   printf("\n-");
					}

					
					break;
         case 'E':  
			        cl = 7;
					if (Error_Flag == 0)
					{
                      
					 LMJ_inputs();
                      
					 if (Error_Flag == 0 && E_Flag == 0 && H_Flag == 0)
					 {
                         for(i = 0; i < 1024; i++) ibuf[i] = szBuf[i];
						 
						 zhlchar();

						 NetDisk_Write_view(wy_sabn, Zhl_Move);
						 succe_flag = 1;   
					 }
					 else
					 {
                        printf("\nError: Unknow Error!\n");
					 }

					}
					else
					{
						//printf("\nCommand Error!\n");
						show(12,"\nCommand Error!\n");
					}

					

				//	printf("\n-");
					break;
         case 'D':
		            cl = 7;
			//		printf("Error_Flag=%d",Error_Flag);
					if (Error_Flag == 0)
					{
					LMJ_inputs();
                      
					 if (Error_Flag == 0 && Test_Flag == 0 && Mj_Flag ==0 && H_Flag == 0)
					 {
                        
						 
						 for(i = 0; i < 1024; i++) ibuf[i] = szBuf[i];
						 
						 zhlchar();

						 Disk_Read_view(wy_sabn,LMJNum);
                         
						 succe_flag = 1;                      
						
					 }
					 else
					 {
                        printf("\nError: Sectors is too large or other error!\n");
					 }

					}
					else
					{
						//printf("\nCommand Error!\n");
						show(12,"\nCommand Error!\n");
						succe_flag = 0;
					}
					printf("\n");
				    
					break;

       
		 
		 case 'M':
			        cl = 7;
					if (Error_Flag == 0 && F_E == 0)
                    {
					     for(i = 0; i < 1024; i++) ibuf[i] = szBuf[i];
						 
						 zhlchar();
 
						 NetDisk_Init();
						 succe_flag = 1;
					}
					else
					{
                       //printf("\nCommand Error!\n");
						show(12,"\nCommand Error!\n");
					}
                    
				//	printf("\n-");
					break;
		 case 'Z':
			        cl = 7;
					if (Error_Flag == 0)
					{
					 LMJ_inputs();
                      
					 if (Error_Flag == 0 && W_Flag == 0)
					 {
				                 
					     for(i = 0; i < 1024; i++) ibuf[i] = szBuf[i];
						 
						 zhlchar();
 
						 NetDisk_Sectorzero(wy_sabn);
						 succe_flag = 1;
					}
					 else
					{
					
                        printf("\nError: Sectors is too large or other error!\n");
					
					}
					}
					else
					{
                       //printf("\nCommand Error!\n");
						show(12,"\nCommand Error!\n");
					}
					
				//	printf("\n-");
					break;        
				
         case 'W':  
			        cl = 7;
					if (Error_Flag == 0)
					{
                      
					 LMJ_inputs();
                      
					 if (Wr_Flag == 1 && Wr_Flag1 == 1)
					 {
                         for(i = 0; i < 1024; i++) ibuf[i] = szBuf[i];
						 zhlchar();
						 NetWR_sectors();
						 succe_flag = 1;
					 }
					 else
					 {
                        printf("\nError: Unknow Error!\n");
					 }

					}
					else
					{
						//printf("\nCommand Error!\n");
						show(12,"\nCommand Error!\n");
					}

					//printf("\n-");
					break;
		 
		 default :  
			        cl = 7;
					show(12,"\nCommand Error!\n");
				//	printf("\n-");
					break;
	  }
        if(succe_flag == 0)
		printf("Client recv: %s\n",szBuf);
	}
	else
	{
		printf("recv error: %d\n",WSAGetLastError());
		closesocket(theSocket);
		return;
	}
 
    }
	 if (szBuf[0] =='Q' && szBuf[1]==0x00) 
	 {
		 Net_Flag = 0;
         Net_Client = 0;
		 break;
	 }
	 

	}while(1);

	printf("Client Over\n");
	//getch();
     
 
	closesocket(theSocket);
	Net_Flag = 0;
	Net_Client = 0;
	return;
}

//数据转换函数

void zchar()
{
  
  int i ;
  char numbuf[512];

  
  for(i=0;i<512;i++)  
  {
	  ibuf[i*2] = 0;
	  ibuf[i*2+1] = 0;
      numbuf[i] = 0;
  }
  for(i = 0; i < 512; i++) numbuf[i] = sendbuf[i];

  for (i = 0; i < 512; i++)
  {
      if( numbuf[i] >= 0 && numbuf[i] <= 10)
	  {
             ibuf[2*i] = 0X18;  //字符小于10的转换标志
             ibuf[2*i+1] = 0X20 + numbuf[i];         
      }
      else
	  {
		     ibuf[2*i] = 0X28;  //其他字符不要转换标志
             ibuf[2*i+1] = numbuf[i];         
	  }
  }
  
 
}


void zhlchar()
{
  unsigned int i ;
  char numbuf[1024];

  
  for(i = 0; i < 1024; i++)  
  {
	   numbuf[i] = 0;
  }
  for(i = 0; i < 1024; i++) numbuf[i] = ibuf[i];

  for (i = 0; i < 512; i++)
  {
      if( numbuf[i*2] == 0x18)
	  {
           //  ibuf[2*i] = 0X18;  //字符小于10的转换标志
             bufbak[i] =  numbuf[i*2+1]-0x20;         
      }
      else
	  {
		      if(numbuf[i*2] == 0x28)
		      bufbak[i] = numbuf[2*i+1];         
	  }
  }
  
}

//读取还原精灵的PASSWORD

int Readpasswd()
{
   int i,result;
   unsigned char password[9],buffer[512];
   
   
   for(i = 0; i < 512; i++) buffer[i] = 0;
   for(i = 0; i < 9; i++) password[i] = 0;
  
   result = ::RW_Ide_Disk_Sec(Ide_flag,2, 7);

   if(result != 0) return 0;

   for(i = 0; i < 512; i++) buffer[i] = buf[i];
  
   for (i = 0; i < 8; i++)
     {
      if (buffer[0x4F+i] == '\0')
        {
          password[i] = '\0';
          break;
         }
       password[i] = buffer[0x4F+i]^0xA5;
     }
  
   password[8]='\0';
   
   if(password[0] != 0)   printf("\nThe password is:%s\n",password);
   else   printf("\nNot find password!\n");
 
   return 0;
}