www.pudn.com > vseg1.rar > vseg1.cpp, change:2008-12-10,size:3541b


/* 
************************************************************************************************************************ 
** 
** this is a program for changing the binary file . I made it for changing the terminal code ,because the file is binary . 
** for more using ,you need change the source code ,because it free for everyone .runing in DOS mode . 
**                                                        by : 
**                                                            bill.zhang  
**															  2008.12.8 
** 
************************************************************************************************************************ 
*/ 
// 
 
#include "stdafx.h" 
#include "stdio.h" 
#include "stdlib.h" 
#include "string.h" 
#include "io.h" 
 
int _tmain(int argc, _TCHAR* argv[]) 
{ 
	FILE *pfile,*pfile1; 
	long LFileLength; 
	//char *CFileLength="hello world !"; 
	unsigned char ch1; 
	unsigned char pch1[0x10000];		 // attention please here ,please .the type must be unsigned char ,else will be error result; 
	unsigned int TERMIANL_CODE; 
	int i,j=1; 
	unsigned char UCSwap[4]; 
	int Judge_Enter; 
	//int rc; 
 
 
 
 
	printf("\r\nplease input the terminal code\r\n"); 
	printf("\(please input 9 bit decimal number\)\r\n:"); 
	scanf("%d",&TERMIANL_CODE); 
	printf("the terminal code is %d\r\n",TERMIANL_CODE); 
 
 
CHECKZERO_STYLE: 
	printf("\r\nplease select 1 for increasing 1 automatically,otherwise will exit the program\r\n :"); 
	scanf("%d",&Judge_Enter); 
	if (Judge_Enter==1) 
	{ 
		TERMIANL_CODE++; 
	} 
	else  
	{ 
		printf("\r\ndo nothing !\r\n"); 
		exit(1); 
	} 
	 
 
	printf("the terminal code is %d\r\n",TERMIANL_CODE); 
 
	// open the file named a.bin  ; 
	if ((pfile=fopen("a.bin","rb"))==NULL) 
	{ 
		printf("the a.bin can't open !\r\n"); 
		exit(1); 
	} 
	else  
	{ 
		printf("the a.bin was openned !\r\n"); 
	} 
 
	// open the file named b.bin 
	if ((pfile1=fopen("b.bin","w+b"))==NULL) 
	{ 
		printf("the b.bin can't open !\r\n"); 
		exit(1); 
	} 
	else 
	{ 
		printf("the b.bin was openned !\r\n"); 
	} 
 
	LFileLength=_filelength(_fileno(pfile)); 
	printf("the file length is %d\r\n",LFileLength); 
  
	// copy file to another file ; 
	//while( (rc = fread(pch1,sizeof(unsigned char), LFileLength,pfile)) != 0 )  
	//{ 
	//	fwrite( pch1, sizeof( unsigned char ), rc, pfile1 );  
	//}   
 
	// display binary code on the screen ; 
	//fread(pch1, sizeof(unsigned char), LFileLength, pfile); 
	//for (i=0;i<LFileLength;i++) 
	//{ 
	//	printf( "%3x", pch1[i]); 
	//	if (i==j*16) 
	//	{ 
	//		printf("\r\n"); 
	//		j++; 
	//	} 
	//} 
 
	if (pfile) 
	{ 
		if (fclose(pfile)) 
		{ 
			printf("\r\nthe file can't closed !\r\n"); 
			exit(1); 
		} 
		else  
		{ 
			printf("\r\nthe file was closed !\r\n"); 
		} 
	} 
 
	UCSwap[0]=(unsigned char)TERMIANL_CODE; 
	printf("the UCSwap1 is :%x\r\n",UCSwap[0]); 
	UCSwap[1]=(unsigned char)(TERMIANL_CODE >> 8); 
	printf("the UCSwap2 is :%x\r\n",UCSwap[1]); 
	UCSwap[2]=(unsigned char)(TERMIANL_CODE >> 16); 
	printf("the UCSwap3 is :%x\r\n",UCSwap[2]); 
	UCSwap[3]=(unsigned char)(TERMIANL_CODE >> 24); 
	printf("the UCSwap4 is :%x\r\n",UCSwap[3]); 
 
	//pch1[0x2fa3]=UCSwap[3]; 
	//pch1[0x2fa2]=UCSwap[2]; 
	pch1[0x5d41-1]=UCSwap[1]; 
	pch1[0x5d49-1]=UCSwap[0]; 
 
	fwrite( pch1, sizeof( unsigned char ), LFileLength, pfile1 ); 
 
	if (pfile1) 
	{ 
		if (fclose(pfile1)) 
		{ 
			printf("\r\nthe file can't closed !\r\n"); 
			exit(1); 
		} 
		else  
		{ 
			printf("\r\nthe file was closed !\r\n"); 
		} 
	} 
 
	goto CHECKZERO_STYLE ; 
 
	return 0; 
}