/* * $Id: register.c,v 1.7 2004/04/21 07:04:10 andrew_belov Exp $ * --------------------------------------------------------------------------- * This optional utility writes registration data to ARJ.EXE (or not .EXE). * */ #include "arj.h" #include /* Local definitions */ #define REG_BLOCK_SIZE 8192 /* Sequental processing block */ /* Global registration types */ #define REG_TYPE_DEFAULT 0 /* Registers a single user-specified file */ #define REG_TYPE_ARJ 1 /* Registers ARJ or ARJ/2 package */ #define REG_TYPE_ARJ32 2 /* Registers ARJ32 package */ DEBUGHDR(__FILE__) /* Debug information block */ /* Local variables */ static char reg_fname[]="register.dat"; /* User registration data */ static char end_marker[]=""; static char *reg_list[]={"arj" EXE_EXTENSION, "arjs" EXE_EXTENSION, "dearj" EXE_EXTENSION, "rearj" EXE_EXTENSION, end_marker}; static char *reg_list_32[]={"arj32" EXE_EXTENSION, "arjs32" EXE_EXTENSION, "rearj32" EXE_EXTENSION, end_marker}; static char integrity_pattern[]={0xB1, 0x03, 0xB0, 0x02, 0xB0, 0x03, 0xB0, 0x04, 0xB0, 0x05, 0}; static char reg_pattern[]="aRj sOfTwArE"; static char reg_pad[STD_REG_LEN]; static char proc_block[REG_BLOCK_SIZE]; static unsigned int file_ctr; /* Writes four bytes to the file */ static int _fput_dword(unsigned long l, FILE *stream) { #ifdef WORDS_BIGENDIAN fputc(l&0xFF, stream); fputc(l>>8, stream); fputc(l>>16, stream); return fputc(l>>24, stream)==EOF; #else return fwrite(&l,4,1,stream)!=4; #endif } static void _mput_dword(unsigned long d, char *p) { #ifdef WORDS_BIGENDIAN #define _mput_byte(b,p) (*(p)=(b)&0xFF) _mput_byte(d , p ); _mput_byte(d>>8, p+1); _mput_byte(d>>16, p+2); _mput_byte(d>>24, p+3); #undef _mput_byte #else *(unsigned long *)p=d; #endif } /* Writes registration data to the given file */ static void write_reg_data(char *name) { FILE *stream; int rp_len; long cur_pos, wr_pos; int bytes_read, byte_ctr; char *pb_ptr; long fsize; int c; if((stream=fopen(name, m_rbp))==NULL) error(M_CANTOPEN, name); rp_len=strlen(reg_pattern); cur_pos=0L; while(1) { fseek(stream, cur_pos, SEEK_SET); if((bytes_read=fread(proc_block, 1, REG_BLOCK_SIZE, stream))==0) error(M_PATCH_NOT_FOUND); bytes_read-=rp_len; pb_ptr=proc_block; byte_ctr=0; while(byte_ctr1) printf(M_REG_TOTALS, file_ctr); return(REGISTER_ERL_SUCCESS); }