commit 0bd46f72baece21a76c484bbad0e9880f96c0732 Author: Edouard Dupin Date: Wed Jul 20 11:13:44 2011 +0200 Basic creation of the hexViewer repository diff --git a/Makefile b/Makefile new file mode 100755 index 0000000..6bee092 --- /dev/null +++ b/Makefile @@ -0,0 +1,93 @@ +################################################################################################################## +# # +# Fichier : Makefile # +# # +# Type : Makefile d'un programme complet # +# # +# Auteur : Heero Yui # +# # +# Evolutions : Date Auteur Raison # +# 2010-01-29 Heero Yui Mise en place d'un makefile ultra simple # +# # +# Concu Pour le projet hexViwer # +# # +################################################################################################################## +export F_GRAS= +export F_INVERSER= +export F_SOUSLIGNER= +export F_NORMALE= +export F_NOIR= +export F_ROUGE= +export F_VERT= +export F_MARRON= +export F_BLUE= +export F_VIOLET= +export F_CYAN= +export F_GRIS= +export CADRE_HAUT_BAS=' $(F_INVERSER) $(F_NORMALE)' +export CADRE_COTERS=' $(F_INVERSER) $(F_NORMALE) $(F_INVERSER) $(F_NORMALE)' + + +CFLAGS= -g -Wall -D_REENTRANT + +LDFLAGS= + +LIB= -lpthread -lm + +CC= g++ $(CFLAGS) +LD= g++ + +# Liste des fichiers +SRC=main.c \ + display.c \ + parameter.c + +# Liste des objets +OBJ= $(SRC:.c=.o) + +# Liste des dépendances +DEP= $(SRC:.c=.d) + + +# +BIN=hexViewer + +.PHONY: all +all: encadrer $(BIN) + + +encadrer: +ifneq ($(COLOR),normal) + @echo $(CADRE_HAUT_BAS) + @echo $(CADRE_COTERS) + @echo ' DEBUT DE COMPILATION DU PROGRAMME :'$(CADRE_COTERS) + @echo ' $(F_VIOLET)$(BIN)$(F_NORMALE) '$(CADRE_COTERS) + @echo $(CADRE_COTERS) + @echo ' $(F_GRIS) Heero Yui Makefile 29-01-2010$(F_NORMALE)'$(CADRE_COTERS) + @echo $(CADRE_HAUT_BAS) +endif + + +# +%.o: %.c + @echo $(F_VERT)" (.o) $<"$(F_NORMALE) + @$(CC) -o $@ -c $< + +%.d: %.c + @echo $(F_BLUE)" (.d) $<"$(F_NORMALE) + @$(CC) -MM -MD -o $@ $< + + +.PHONY: clean +clean: + rm -f $(BIN) $(OBJ) $(DEP) *.i *.s *.bck + +$(BIN):$(OBJ) + @echo $(F_ROUGE)" (bin) $@"$(F_NORMALE) + @$(LD) -o $@ $^ $(LIB) + + + +# inclusion des dependances +-include $(DEP) + diff --git a/README b/README new file mode 100644 index 0000000..a74299e --- /dev/null +++ b/README @@ -0,0 +1,21 @@ +HexViewer (Hexadevimal Viewer) is a FREE software. + +This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. + +Terms of license: + +You can: + - Redistribute the sources code and binaries. + - Modify the Sources code. + - Use a part of the sources (less than 50%) in an other software, just write somewhere "HexViewer is great" visible by the user (on your product or on your website with a link to my page). + - Redistribute the modification only if you want. + - Send me the bug-fix (it could be great). + - Pay me a beer or some other things. + - Print the source code on WC paper ... +You can NOT: + - Earn money with this Software (But I can). + - Add malware in the Sources. + - Do something bad with the sources. + - Use it to travel in the space with a toaster. + +I reserve the right to change this licence. If it change the version of the copy you have keep its own license diff --git a/display.c b/display.c new file mode 100755 index 0000000..c0d7087 --- /dev/null +++ b/display.c @@ -0,0 +1,854 @@ +/** + ******************************************************************************* + * @file display.c + * @brief Editeur De N'ours : + * @author Edouard DUPIN + * @date 05/02/2011 + * @par Project + * Edn tool : hexViewer + * + * @par Copyright + * Copyright 2010 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * You can not earn money with this Software (if the source extract from Edn + * represent less than 50% of original Sources) + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ +#include "display.h" + +extern FILE *filePointer[2]; +extern char fileName[2][2096]; +void showConfiguration(void) +{ + showType_te myType = getType(); + showTypeSize_te mySize = getTypeSize(); + + printf(GO_TOP); + printf(COLOR_BOLD_GREEN"----------------------------------------------------------------------------------------------------------------------------\n"COLOR_NORMAL); + printf(COLOR_GREEN); + printf("| hewViewer | ofset : %7d octets | ", (int)getOfsetFile()); + printf(" Type (t) : "); + switch(myType) + { + case SHOW_TYPE_HEX: + printf("Hexadecimal "); + break; + case SHOW_TYPE_DECIMAL_SIGNED: + printf("Decimal Signed "); + break; + case SHOW_TYPE_DECIMAL_UNSIGNED: + printf("Decimal Unsigned"); + break; + default : + printf("? "); + break; + } + printf(" | "); + printf(" Size (s) : "); + switch(mySize) + { + case SHOW_TYPE_SIZE_8: + printf(" 8 bits "); + break; + case SHOW_TYPE_SIZE_16: + printf(" 16 bits "); + break; + case SHOW_TYPE_SIZE_32: + printf(" 32 bits "); + break; + case SHOW_TYPE_SIZE_64: + printf(" 64 bits "); + break; + case SHOW_TYPE_SIZE_128: + printf("128 bits "); + break; + default : + printf(" ? bits "); + break; + } + printf(COLOR_NORMAL"\n"); + printf(COLOR_BOLD_GREEN"----------------------------------------------------------------------------------------------------------------------------\n"COLOR_NORMAL); + + printf(COLOR_BOLD_GREEN" \r "); + switch(myType) + { + case SHOW_TYPE_DECIMAL_SIGNED: + switch(mySize) + { + case SHOW_TYPE_SIZE_8: + printf(" | "); + + break; + case SHOW_TYPE_SIZE_16: + printf(" | "); + break; + case SHOW_TYPE_SIZE_32: + printf(" | "); + break; + default: + break; + } + break; + case SHOW_TYPE_DECIMAL_UNSIGNED: + switch(mySize) + { + case SHOW_TYPE_SIZE_8: + printf(" | "); + break; + case SHOW_TYPE_SIZE_16: + printf(" | "); + break; + case SHOW_TYPE_SIZE_32: + printf(" | "); + break; + default: + break; + } + break; + case SHOW_TYPE_HEX: + default : + switch(mySize) + { + case SHOW_TYPE_SIZE_8: + printf(" | "); + break; + case SHOW_TYPE_SIZE_16: + printf(" | "); + break; + case SHOW_TYPE_SIZE_32: + printf(" | "); + break; + default: + break; + } + break; + } + printf("file : %s\r", fileName[1]); + printf(" | file : %s", fileName[0]); + printf(COLOR_NORMAL"\n"); + printf(COLOR_BOLD_GREEN"----------------------------------------------------------------------------------------------------------------------------\n"COLOR_NORMAL); +} + + + +void showFile(FILE *filePointer ,I32 CurentFilePosition) +{ + /* + U16 data[NB_DATA_PER_LINE]; + U32 i; + U32 j; + + showConfiguration(); + + // Display the main show + printf(COLOR_BOLD_YELLOW"Ofset : |"); + for (i = 0; i< NB_DATA_PER_LINE; i++) + { + printf(" +%x",(unsigned int)i); + } + printf(COLOR_NORMAL"\n"); + // Display the main show + printf(COLOR_BOLD_YELLOW"------------"); + for (i = 0; i< NB_DATA_PER_LINE; i++) + { + printf("------"); + } + printf(COLOR_NORMAL"\n"); + for (j=0; j < NB_MAX_LINE; j++) + { + + if (fread(data, sizeof(I8), NB_DATA_PER_LINE, filePointer) != NB_DATA_PER_LINE) + { + printf("No More Data in the file"); + j = NB_MAX_LINE; + } + else + { + U32 lineNumber = 0; + lineNumber = (j ) * NB_DATA_PER_LINE + CurentFilePosition; + printf(COLOR_BOLD_YELLOW"0x%08x | "COLOR_NORMAL, (unsigned int)lineNumber); + for (i = 0; i< NB_DATA_PER_LINE; i++) + { + //printf("%04x ", data[i]); + printf("%5d ", data[i]); + } + } + printf(COLOR_NORMAL"\n"); + } + */ +} + +void print_U32(U32 data) +{ + +} + + +void print_I32(I32 data) +{ + +} + + + +void printNoElement(showType_te localType, showTypeSize_te localSize) +{ + switch(localType) + { + case SHOW_TYPE_HEX: + switch(localSize) + { + case SHOW_TYPE_SIZE_8: + printf(" "); + break; + case SHOW_TYPE_SIZE_16: + printf(" "); + break; + case SHOW_TYPE_SIZE_32: + printf(" "); + break; + case SHOW_TYPE_SIZE_64: + //printf("%08x%08x"COLOR_NORMAL" ", (unsigned int)((U32)(data>>32)), (unsigned int)((U32)data)); + break; + default: + break; + } + break; + case SHOW_TYPE_DECIMAL_SIGNED: + switch(localSize) + { + case SHOW_TYPE_SIZE_8: + printf(" "); + break; + case SHOW_TYPE_SIZE_16: + printf(" "); + break; + case SHOW_TYPE_SIZE_32: + printf(" "); + break; + case SHOW_TYPE_SIZE_64: + //printf("%08x%08x"COLOR_NORMAL" ", (unsigned int)((U32)(data>>32)), (unsigned int)((U32)data)); + break; + default: + break; + } + + break; + case SHOW_TYPE_DECIMAL_UNSIGNED: + switch(localSize) + { + case SHOW_TYPE_SIZE_8: + printf(" "); + break; + case SHOW_TYPE_SIZE_16: + printf(" "); + break; + case SHOW_TYPE_SIZE_32: + printf(" "); + break; + case SHOW_TYPE_SIZE_64: + //printf("%08x%08x"COLOR_NORMAL" ", (unsigned int)((U32)(data>>32)), (unsigned int)((U32)data)); + break; + default: + break; + } + break; + default: + break; + } + +} + +void printElement(U64 data, showType_te localType, showTypeSize_te localSize, bool error) +{ + if (true == error) + { + printf(COLOR_BOLD_RED); + } + switch(localType) + { + case SHOW_TYPE_HEX: + switch(localSize) + { + case SHOW_TYPE_SIZE_8: + printf("%02x"COLOR_NORMAL" ", (unsigned int)((U8)data)); + break; + case SHOW_TYPE_SIZE_16: + printf("%04x"COLOR_NORMAL" ", (unsigned int)((U16)data)); + break; + case SHOW_TYPE_SIZE_32: + printf("%08x"COLOR_NORMAL" ", (unsigned int)((U32)data)); + break; + case SHOW_TYPE_SIZE_64: + //printf("%08x%08x"COLOR_NORMAL" ", (unsigned int)((U32)(data>>32)), (unsigned int)((U32)data)); + break; + default: + break; + } + break; + case SHOW_TYPE_DECIMAL_SIGNED: + switch(localSize) + { + case SHOW_TYPE_SIZE_8: + printf("%4d"COLOR_NORMAL"", ((I8)data)); + break; + case SHOW_TYPE_SIZE_16: + printf("%6d"COLOR_NORMAL" ", ((I16)data)); + break; + case SHOW_TYPE_SIZE_32: + printf("%9d"COLOR_NORMAL" ", (int)((I32)data)); + break; + case SHOW_TYPE_SIZE_64: + //printf("%08x%08x"COLOR_NORMAL" ", (unsigned int)((U32)(data>>32)), (unsigned int)((U32)data)); + break; + default: + break; + } + + break; + case SHOW_TYPE_DECIMAL_UNSIGNED: + switch(localSize) + { + case SHOW_TYPE_SIZE_8: + printf("%3d"COLOR_NORMAL" ", ((U8)data)); + break; + case SHOW_TYPE_SIZE_16: + printf("%5d"COLOR_NORMAL" ", ((U16)data)); + break; + case SHOW_TYPE_SIZE_32: + printf("%9d"COLOR_NORMAL" ", (unsigned int)((U32)data)); + break; + case SHOW_TYPE_SIZE_64: + //printf("%08x%08x"COLOR_NORMAL" ", (unsigned int)((U32)(data>>32)), (unsigned int)((U32)data)); + break; + default: + break; + } + break; + default: + break; + } + +} +typedef union { + U8 data_8 [16]; + U16 data_16 [8]; + U32 data_32 [4]; + U64 data_64 [2]; +}inputData_tu; + +void compareFile(FILE *filePointer1, FILE *filePointer2 ,I32 CurentFilePosition) +{ + inputData_tu data1; + inputData_tu data2; + U32 i; + U32 j; + + + showConfiguration(); + + showTypeSize_te mySize = getTypeSize(); + showType_te myType = getType(); + + // Display the main show + printf(COLOR_BOLD_YELLOW"Ofset : | | "); + switch(myType) + { + case SHOW_TYPE_DECIMAL_SIGNED: + for (i = 0 ; i<2 ; i++ ) + { + switch(mySize) + { + case SHOW_TYPE_SIZE_8: + for (j=0; j<2 ; j++ ) { + printf(" +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F | "); + } + break; + case SHOW_TYPE_SIZE_16: + for (j=0; j<2 ; j++ ) { + printf(" +0 +2 +4 +6 +8 +A +C +E | "); + } + break; + case SHOW_TYPE_SIZE_32: + for (j=0; j<2 ; j++ ) { + printf(" +0 +4 +8 +C | "); + } + break; + default: + break; + } + if (i == 0) + { + printf(COLOR_NORMAL"\n"); + printf(COLOR_BOLD_MAGENTA" | ofset | "); + } + } + break; + case SHOW_TYPE_DECIMAL_UNSIGNED: + for (i = 0 ; i<2 ; i++ ) + { + switch(mySize) + { + case SHOW_TYPE_SIZE_8: + for (j=0; j<2 ; j++ ) { + printf(" +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F | "); + } + break; + case SHOW_TYPE_SIZE_16: + for (j=0; j<2 ; j++ ) { + printf(" +0 +2 +4 +6 +8 +A +C +E | "); + } + break; + case SHOW_TYPE_SIZE_32: + for (j=0; j<2 ; j++ ) { + printf(" +0 +4 +8 +C | "); + } + break; + default: + break; + } + if (i == 0) + { + printf(COLOR_NORMAL"\n"); + printf(COLOR_BOLD_MAGENTA" | ofset | "); + } + } + break; + case SHOW_TYPE_HEX: + default : + for (i = 0 ; i<2 ; i++ ) + { + switch(mySize) + { + case SHOW_TYPE_SIZE_8: + for (j=0; j<2 ; j++ ) { + printf("+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F | "); + } + break; + case SHOW_TYPE_SIZE_16: + for (j=0; j<2 ; j++ ) { + printf(" +0 +2 +4 +6 +8 +A +C +E | "); + } + break; + case SHOW_TYPE_SIZE_32: + for (j=0; j<2 ; j++ ) { + printf(" +0 +4 +8 +C | "); + } + break; + default: + break; + } + if (i == 0) + { + printf(COLOR_NORMAL"\n"); + printf(COLOR_BOLD_MAGENTA" | ofset | "); + } + } + break; + } + printf(COLOR_NORMAL"\n"); + + + // Display the main show + printf(COLOR_BOLD_YELLOW"------------"); + for (i = 0; i< 16; i++) + { + printf("---"); + } + printf("---"); + for (i = 0; i< 16; i++) + { + printf("---"); + } + printf(COLOR_NORMAL"\n"); + for (j=0; j < NB_MAX_LINE; j++) + { + U32 readFile1 = 0; + U32 readFile2 = 0; + U32 lineNumber = 0; + U32 numberOfCycle; + // read data in files : + readFile1 = fread(data1.data_8, sizeof(U8), 16, filePointer1); + readFile2 = fread(data2.data_8, sizeof(U8), 16, filePointer2); + // display the line number + lineNumber = j * (NB_DATA_PER_LINE*4) + CurentFilePosition; + printf(COLOR_BOLD_YELLOW"0x%08x | "COLOR_NORMAL, (unsigned int)lineNumber); + switch(mySize) + { + case SHOW_TYPE_SIZE_8: + printf(COLOR_BOLD_MAGENTA"%5d | "COLOR_NORMAL, (int)(lineNumber)); + break; + case SHOW_TYPE_SIZE_16: + printf(COLOR_BOLD_MAGENTA"%5d | "COLOR_NORMAL, (int)(lineNumber/2)); + break; + case SHOW_TYPE_SIZE_32: + printf(COLOR_BOLD_MAGENTA"%5d | "COLOR_NORMAL, (int)(lineNumber/4)); + break; + default: + break; + } + if (readFile1 == 0) + { + switch(mySize) + { + case SHOW_TYPE_SIZE_8: + numberOfCycle = 16; + break; + case SHOW_TYPE_SIZE_16: + numberOfCycle = 8; + break; + case SHOW_TYPE_SIZE_32: + numberOfCycle = 4; + break; + case SHOW_TYPE_SIZE_64: + numberOfCycle = 2; + break; + default : + numberOfCycle = 0; + break; + } + //printf("no more data"); + for (i = 0; i< numberOfCycle; i++) + { + printNoElement(myType, mySize); + } + } + else // TODO : mettre les octet qui reste a la fin si ce n'est pas complet + { + i = 0; + numberOfCycle = 16; + while (i< numberOfCycle) + { + switch(mySize) + { + case SHOW_TYPE_SIZE_8: + numberOfCycle = 16; + for (i = 0; i< numberOfCycle; i++) + { + if (readFile1 >= (i+1)) + { + printElement((U64)data1.data_8[i], myType, mySize, (data1.data_8[i] != data2.data_8[i])); + } + else + { + printNoElement(myType, mySize); + } + } + break; + case SHOW_TYPE_SIZE_16: + numberOfCycle = 8; + for (i = 0; i< numberOfCycle; i++) + { + if ((readFile1/2) >= (i+1)) + { + printElement((U64)data1.data_16[i], myType, mySize, (data1.data_16[i] != data2.data_16[i])); + } + else + { + printNoElement(myType, mySize); + } + } + break; + case SHOW_TYPE_SIZE_32: + numberOfCycle = 4; + for (i = 0; i< numberOfCycle; i++) + { + if ((readFile1/4) >= (i+1)) + { + printElement((U64)data1.data_32[i], myType, mySize, (data1.data_32[i] != data2.data_32[i])); + } + else + { + printNoElement(myType, mySize); + } + } + break; + case SHOW_TYPE_SIZE_64: + numberOfCycle = 2; + for (i = 0; i< numberOfCycle; i++) + { + if ((readFile1/8) >= (i+1)) + { + printElement((U64)data1.data_64[i], myType, mySize, (data1.data_8[i] != data2.data_64[i])); + } + else + { + printNoElement(myType, mySize); + } + } + break; + default : + numberOfCycle = 0; + break; + } + i++; + } + } + printf(" | "); + if (readFile2 == 0) + { + switch(mySize) + { + case SHOW_TYPE_SIZE_8: + numberOfCycle = 16; + break; + case SHOW_TYPE_SIZE_16: + numberOfCycle = 8; + break; + case SHOW_TYPE_SIZE_32: + numberOfCycle = 4; + break; + case SHOW_TYPE_SIZE_64: + numberOfCycle = 2; + break; + default : + numberOfCycle = 0; + break; + } + //printf("no more data"); + for (i = 0; i< numberOfCycle; i++) + { + printNoElement(myType, mySize); + } + } + else + { + i = 0; + numberOfCycle = 16; + while (i< numberOfCycle) + { + switch(mySize) + { + case SHOW_TYPE_SIZE_8: + numberOfCycle = 16; + for (i = 0; i< numberOfCycle; i++) + { + if (readFile2 >= (i+1)) + { + printElement((U64)data2.data_8[i], myType, mySize, (data1.data_8[i] != data2.data_8[i])); + } + else + { + printNoElement(myType, mySize); + } + } + break; + case SHOW_TYPE_SIZE_16: + numberOfCycle = 8; + for (i = 0; i< numberOfCycle; i++) + { + if ((readFile2/2) >= (i+1)) + { + printElement((U64)data2.data_16[i], myType, mySize, (data1.data_16[i] != data2.data_16[i])); + } + else + { + printNoElement(myType, mySize); + } + } + break; + case SHOW_TYPE_SIZE_32: + numberOfCycle = 4; + for (i = 0; i< numberOfCycle; i++) + { + if ((readFile2/4) >= (i+1)) + { + printElement((U64)data2.data_32[i], myType, mySize, (data1.data_32[i] != data2.data_32[i])); + } + else + { + printNoElement(myType, mySize); + } + } + break; + case SHOW_TYPE_SIZE_64: + numberOfCycle = 2; + for (i = 0; i< numberOfCycle; i++) + { + if ((readFile2/8) >= (i+1)) + { + printElement((U64)data2.data_64[i], myType, mySize, (data1.data_8[i] != data2.data_64[i])); + } + else + { + printNoElement(myType, mySize); + } + } + break; + default : + numberOfCycle = 0; + break; + } + i++; + } + } + printf(COLOR_NORMAL"\n"); + + /* + if ( fread(data1.data_8, sizeof(U8), 16, filePointer1) != 16 + || fread(data2.data_8, sizeof(U8), 16, filePointer2) != 16) + { + printf("No More Data in the file \n"); + for (;j < NB_MAX_LINE; j++) + { + printf(" \n"); + } + } + else + { + U32 lineNumber = 0; + U32 numberOfCycle; + lineNumber = j * (NB_DATA_PER_LINE*4) + CurentFilePosition; + printf(COLOR_BOLD_YELLOW"0x%08x | "COLOR_NORMAL, (unsigned int)lineNumber); + switch(mySize) + { + case SHOW_TYPE_SIZE_8: + printf(COLOR_BOLD_MAGENTA"%5d | "COLOR_NORMAL, (int)(lineNumber)); + break; + case SHOW_TYPE_SIZE_16: + printf(COLOR_BOLD_MAGENTA"%5d | "COLOR_NORMAL, (int)(lineNumber/2)); + break; + case SHOW_TYPE_SIZE_32: + printf(COLOR_BOLD_MAGENTA"%5d | "COLOR_NORMAL, (int)(lineNumber/4)); + break; + default: + break; + } + i = 0; + numberOfCycle = 16; + while (i< numberOfCycle) + { + switch(mySize) + { + case SHOW_TYPE_SIZE_8: + numberOfCycle = 16; + for (i = 0; i< numberOfCycle; i++) + { + printElement((U64)data1.data_8[i], myType, mySize, (data1.data_8[i] != data2.data_8[i])); + } + break; + case SHOW_TYPE_SIZE_16: + numberOfCycle = 8; + for (i = 0; i< numberOfCycle; i++) + { + printElement((U64)data1.data_16[i], myType, mySize, (data1.data_16[i] != data2.data_16[i])); + } + break; + case SHOW_TYPE_SIZE_32: + numberOfCycle = 4; + for (i = 0; i< numberOfCycle; i++) + { + printElement((U64)data1.data_32[i], myType, mySize, (data1.data_32[i] != data2.data_32[i])); + } + break; + case SHOW_TYPE_SIZE_64: + numberOfCycle = 2; + for (i = 0; i< numberOfCycle; i++) + { + printElement((U64)data1.data_64[i], myType, mySize, (data1.data_8[i] != data2.data_64[i])); + } + break; + default : + numberOfCycle = 0; + break; + } + i++; + } + printf(" | "); + i = 0; + numberOfCycle = 16; + while (i< numberOfCycle) + { + switch(mySize) + { + case SHOW_TYPE_SIZE_8: + numberOfCycle = 16; + for (i = 0; i< numberOfCycle; i++) + { + printElement((U64)data2.data_8[i], myType, mySize, (data1.data_8[i] != data2.data_8[i])); + } + break; + case SHOW_TYPE_SIZE_16: + numberOfCycle = 8; + for (i = 0; i< numberOfCycle; i++) + { + printElement((U64)data2.data_16[i], myType, mySize, (data1.data_16[i] != data2.data_16[i])); + } + break; + case SHOW_TYPE_SIZE_32: + numberOfCycle = 4; + for (i = 0; i< numberOfCycle; i++) + { + printElement((U64)data2.data_32[i], myType, mySize, (data1.data_32[i] != data2.data_32[i])); + } + break; + case SHOW_TYPE_SIZE_64: + numberOfCycle = 2; + for (i = 0; i< numberOfCycle; i++) + { + printElement((U64)data2.data_64[i], myType, mySize, (data1.data_8[i] != data2.data_64[i])); + } + break; + default : + numberOfCycle = 0; + break; + } + i++; + } + } + */ + } +} + + + + + + + + +/* Fonction pour le thread du magasin. */ +void * threadDisplay (void * p_data) +{ + while (1) + { + if (getParamModification()) + { + U32 CurentFilePosition = getOfsetFile(); + fseek ( filePointer[0] , CurentFilePosition , SEEK_SET ); + if (NULL != filePointer[1]) + { + fseek ( filePointer[1] , CurentFilePosition , SEEK_SET ); + } + + + if ( NULL != filePointer[0] + && NULL == filePointer[1] ) + { + showFile(filePointer[0],CurentFilePosition); + } + else if ( NULL != filePointer[0] + && NULL != filePointer[1] ) + { + compareFile(filePointer[0],filePointer[1], CurentFilePosition); + } + } + else + { + usleep(10000); + } + } + + return NULL; +} + + + diff --git a/display.h b/display.h new file mode 100755 index 0000000..12a77b5 --- /dev/null +++ b/display.h @@ -0,0 +1,40 @@ +/** + ******************************************************************************* + * @file display.h + * @brief Editeur De N'ours : + * @author Edouard DUPIN + * @date 05/02/2011 + * @par Project + * Edn tool : hexViewer + * + * @par Copyright + * Copyright 2010 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * You can not earn money with this Software (if the source extract from Edn + * represent less than 50% of original Sources) + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ +#ifndef __DISPLAY_H__ +#define __DISPLAY_H__ + +#include "generalDefine.h" +#include "parameter.h" + + + + + +void * threadDisplay (void * p_data); + + + +#endif + diff --git a/generalDefine.h b/generalDefine.h new file mode 100755 index 0000000..f317180 --- /dev/null +++ b/generalDefine.h @@ -0,0 +1,105 @@ +/** + ******************************************************************************* + * @file generalDefine.h + * @brief Editeur De N'ours : + * @author Edouard DUPIN + * @date 05/02/2011 + * @par Project + * Edn tool : hexViewer + * + * @par Copyright + * Copyright 2010 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * You can not earn money with this Software (if the source extract from Edn + * represent less than 50% of original Sources) + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + +#ifndef __GENERAL_DEFINE_H__ +#define __GENERAL_DEFINE_H__ + +#include +#include +#include +#include +#include + +typedef unsigned char U8; +typedef signed char I8; +typedef unsigned short int U16; +typedef signed short int I16; +typedef unsigned long int U32; +typedef signed long int I32; +typedef unsigned long long int U64; +typedef signed long long int I64; +//typedef unsigned long long long int U128; +//typedef signed long long long int I128; + +//regular colors +#define COLOR_BLACK "\e[0;30m" +#define COLOR_RED "\e[0;31m" +#define COLOR_GREEN "\e[0;32m" +#define COLOR_YELLOW "\e[0;33m" +#define COLOR_BLUE "\e[0;34m" +#define COLOR_MAGENTA "\e[0;35m" +#define COLOR_CYAN "\e[0;36m" +#define COLOR_WHITE "\e[0;37m" + +//emphasized (bolded) colors +#define COLOR_BOLD_BLACK "\e[1;30m" +#define COLOR_BOLD_RED "\e[1;31m" +#define COLOR_BOLD_GREEN "\e[1;32m" +#define COLOR_BOLD_YELLOW "\e[1;33m" +#define COLOR_BOLD_BLUE "\e[1;34m" +#define COLOR_BOLD_MAGENTA "\e[1;35m" +#define COLOR_BOLD_CYAN "\e[1;36m" +#define COLOR_BOLD_WHITE "\e[1;37m" + +//background colors +#define COLOR_BG_BLACK "\e[40m" +#define COLOR_BG_RED "\e[41m" +#define COLOR_BG_GREEN "\e[42m" +#define COLOR_BG_YELLOW "\e[43m" +#define COLOR_BG_BLUE "\e[44m" +#define COLOR_BG_MAGENTA "\e[45m" +#define COLOR_BG_CYAN "\e[46m" +#define COLOR_BG_WHITE "\e[47m" +// Return to the normal color setings +#define COLOR_NORMAL "\e[0m" + + + +//go to the Top of bash +#define GO_TOP "\e[0;0f" + + +#define NB_DATA_PER_LINE (4) +#define NB_MAX_LINE (50) + + + +typedef enum { + SHOW_TYPE_HEX, + SHOW_TYPE_DECIMAL_SIGNED, + SHOW_TYPE_DECIMAL_UNSIGNED +} showType_te; + + +typedef enum { + SHOW_TYPE_SIZE_8, + SHOW_TYPE_SIZE_16, + SHOW_TYPE_SIZE_32, + SHOW_TYPE_SIZE_64, + SHOW_TYPE_SIZE_128 +} showTypeSize_te; + + +#endif diff --git a/main.c b/main.c new file mode 100755 index 0000000..720800b --- /dev/null +++ b/main.c @@ -0,0 +1,409 @@ +/** + ******************************************************************************* + * @file main.c + * @brief Editeur De N'ours : + * @author Edouard DUPIN + * @date 05/02/2011 + * @par Project + * Edn tool : hexViewer + * + * @version $Id$ + * + * @par Copyright + * Copyright 2010 Edouard DUPIN, all right reserved + * + * This is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 3 of the License, or (at your option) any later + * version. + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + ******************************************************************************* + */ +#include "generalDefine.h" +#include "parameter.h" +#include "display.h" + + + +FILE *filePointer[2] = {NULL, NULL}; +U32 filesize[2] = {0, 0}; +char fileName[2][2096] = {"",""}; + +void usage(void) +{ + printf("usage : hexViwer [file_1] [file_2]\n"); + printf("\t[file_1] : Show the first file only\n"); + printf("\t[file_2] : if it was precise : Show the comparaison with the first file\n"); + printf("\t\n"); + printf("\tInside Usage : \n"); + printf("\t\t[a] Go to the start of the files\n"); + printf("\t\t[z] Go to the end of the files (the first push is the File 1, the second push is the file 2) \n"); + printf("\t\t[q] Quit the curent program\n"); + printf("\t\t[s] Change the view of the propram of the size of interpretation (8 bits, 16 bits, 32 bits)\n"); + printf("\t\t[t] Change the interpretation of Data (hexedecimal, Signed Decimal, Unigned Decimal)\n"); + printf("\t\t[f] Find the first Error when comparing the two files\n"); + printf("\t\t[UP] Go up 5 line in the view\n"); + printf("\t\t[DOWN] Go down 5 line in the view\n"); + printf("\t\t[LEFT] Go up 50 line in the view (one screen)\n"); + printf("\t\t[RIGHT] Go down 50 line in the view (one screen)\n"); + printf("\t\n"); + printf("\tTODO : \n"); + printf("\t\t- The print of 128 bytes\n"); + printf("\t\t- The print in Octal\n"); + printf("\t\t- The print in Binary\n"); + printf("\t\t- The Modification of the file\n"); + printf("\t\t- The Saving of the file\n"); + printf("\t\t- The information that one of the files has been update\n"); + printf("\t\t- To reload the two files ==> [U]\n"); + printf("\t\t- The windows scroling with the mouse\n"); + printf("\t\t- The selection with the mouse\n"); + printf("\t\t- The display on char view\n"); + printf("\t\t- The scroling Bar on the right\n"); + printf("\t\t- Add to the croling bar the differences in the two files\n"); + printf("\t\t- The research of a sequency in the two files ==> [R]\n"); + printf("\t\t- The jump to an offset directly ==> [J] \n"); + /*printf("\t\t- \n");*/ +} + + + + + + + + + + +I32 findFirstDiff(void) +{ + U8 data1, data2; + I32 offset = 0; + + while ( fread(&data1, sizeof(U8), 1, filePointer[0]) == 1 + && fread(&data2, sizeof(U8), 1, filePointer[1]) == 1) + { + offset ++; + if (data1 != data2) + { + return offset; + } + } + return -1; +} + + +int main (int argc, char**argv) +{ + I32 first_Error = 0; + if (2 == argc) + { + filePointer[0] = fopen(argv[1], "rb"); + strcpy(fileName[0], argv[1]); + if ( NULL == filePointer[0]) + { + printf("Can not Open [File_1] = %s\n", argv[1]); + usage(); + return -1; + } + } + else if (3 == argc) + { + filePointer[0] = fopen(argv[1], "rb"); + strcpy(fileName[0], argv[1]); + filePointer[1] = fopen(argv[2], "rb"); + strcpy(fileName[1], argv[2]); + fseek ( filePointer[0] , 0 , SEEK_END ); + fseek ( filePointer[1] , 0 , SEEK_END ); + filesize[0] = ftell (filePointer[0]); + filesize[1] = ftell (filePointer[1]); + fseek ( filePointer[0] , 0 , SEEK_SET ); + fseek ( filePointer[1] , 0 , SEEK_SET ); + first_Error = findFirstDiff(); + } + else + { + usage(); + return -1; + } + + // rendre la lecture des données non canonique + system("stty -icanon"); + // supression de l'écho des caractères + system("stty -echo"); + + system("clear"); + + + /* + + printf(GO_TOP); + + if ( NULL != filePointer[0] + && NULL == filePointer[1] ) + { + showFile(filePointer[0] ,CurentFilePosition); + } + else if ( NULL != filePointer[0] + && NULL != filePointer[1] ) + { + compareFile(filePointer[0],filePointer[1] ,CurentFilePosition); + } + */ + + + + + + int ret = 0; + pthread_t HangleThreadDisplay; + + + // Creation du thread du magasin. + //printf ("Creation du thread du magasin !\n"); + ret = pthread_create ( & HangleThreadDisplay, NULL, threadDisplay, NULL ); + if (! ret) + { + while (1) + { + U32 inputValue; + inputValue = getc (stdin); + //printf("\n get data : 0x%08x ..... : \n", (unsigned int)inputValue); + switch(inputValue) + { + case 'q': + case 'Q': + goto exit_programme; + break; + //case 0x1B: + case '\e': + inputValue = getc (stdin); + //printf("\n get data : 0x%08x ..... : \n", (unsigned int)inputValue); + if (inputValue == 0x5B) + { + inputValue = getc (stdin); + //printf("\n get data : 0x%08x ..... : \n", (unsigned int)inputValue); + if ( inputValue == 0x41 + || inputValue == 0x42 + || inputValue == 0x43 + || inputValue == 0x44) + { + if (inputValue == 0x41) + { + upDownOfsetFile(-5); + } + else if ( inputValue == 0x42) + { + upDownOfsetFile(5); + } + else if ( inputValue == 0x43) + { + upDownOfsetFile(NB_MAX_LINE); + } + else if ( inputValue == 0x44) + { + upDownOfsetFile(-NB_MAX_LINE); + } + } + } + break; + // change the type of interpretation the file + case 't': + case 'T': + nextType(); + break; + // change the size of showing the file + case 's': + case 'S': + nextTypeSize(); + break; + // find the first ERROR + case 'f': + case 'F': + setOfsetFile((first_Error/16)*16 - 256); + break; + // find the first ERROR + case 'a': + case 'A': + setOfsetFile(0); + break; + // go to the end of the file (File 1 and next File 2) + case 'z': + case 'Z': + { + static bool whichElement = false; + if (whichElement == false) + { + whichElement = true; + setOfsetFile((filesize[0]/16)*16 - 256); + } + else + { + whichElement = false; + setOfsetFile((filesize[1]/16)*16 - 256); + } + } + break; + } + } + } + else + { + fprintf (stderr, "%s", strerror (ret)); + } + +exit_programme : + if (NULL != filePointer[0]) + { + fclose(filePointer[0]); + } + if (NULL != filePointer[1]) + { + fclose(filePointer[1]); + } + + // remettre la lecture des données canonique + system("stty icanon"); + // repositionnement de l'écho des caractères + system("stty echo"); + return 0; +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +void displayCouleurBash(void) +{ + /* Initialise the main variables + * colour: for the 256 colours (0-255) + * space: to insert space or newline + */ + + int colour = 0; + int espace = 0; + + /* Print the 16 first colours, known as colours system */ + + printf("System colours:\n"); + for( ; colour < 16; colour++) + { + printf("\e[48;5;%dm ", colour); + } + printf("\e[0m\n\n"); + + /* The 216 colours */ + + printf("Color cube: 6x6x6\n"); + for ( ; colour < 232; colour++, espace++) + { + if ((espace%6) == 0) + { + printf("\e[0m "); + } + if ((espace%36 == 0)) + { + printf("\e[0m\n"); + } + printf("\e[48;5;%dm ", colour); + } + printf("\e[0m\n\n"); + + /* And the grey colours */ + + printf("Greyscale ramp\n"); + for ( ; colour < 256; colour++) + { + printf("\e[48;5;%dm ", colour); + } + printf("\e[0m\n\n"); + + /* Initialise the main variables + * colour: for the 256 colours (0-255) + * space: to insert space or newline + */ + + + /* Print the 16 first colours, known as colours system */ + + printf("System colours:\n"); + for( ; colour < 16; colour++) + { + printf("\e[48;5;%dm ", colour); + } + printf("\e[0m\n\n"); + + /* The 216 colours */ + + printf("Color cube: 6x6x6\n"); + for ( ; colour < 232; colour++, espace++) + { + if ((espace%6) == 0) + { + printf("\e[0m "); + } + if ((espace%36 == 0)) + { + printf("\e[0m\n"); + } + printf("\e[48;5;%dm ", colour); + } + printf("\e[0m\n\n"); + + /* And the grey colours */ + + printf("Greyscale ramp\n"); + for ( ; colour < 256; colour++) + { + printf("\e[48;5;%dm ", colour); + } + printf("\e[0m\n\n"); + + +} + + + diff --git a/parameter.c b/parameter.c new file mode 100755 index 0000000..2c97fd8 --- /dev/null +++ b/parameter.c @@ -0,0 +1,148 @@ +/** + ******************************************************************************* + * @file parameter.c + * @brief Editeur De N'ours : + * @author Edouard DUPIN + * @date 05/02/2011 + * @par Project + * Edn tool : hexViewer + * + * @par Copyright + * Copyright 2010 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * You can not earn money with this Software (if the source extract from Edn + * represent less than 50% of original Sources) + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + +#include "parameter.h" +// Parameter Local Value : + +static U32 fileOfset = 0; +static bool parmamModifier = true; + + +static showType_te curentType = SHOW_TYPE_HEX; +static showTypeSize_te curentTypeSize = SHOW_TYPE_SIZE_8; + + +extern U32 filesize[2]; + +void setOfsetFile(I32 offset) +{ + if (0 > offset) + { + offset = 0; + } + if ( offset > (I32)filesize[0] + && offset > (I32)filesize[1]) + { + // nothing to do + return; + } + if (offset != (I32)fileOfset) + { + fileOfset = (U32)offset; + parmamModifier = true; + } +} + +void upDownOfsetFile(I32 offset) +{ + I32 tmp; + tmp = fileOfset + (16 * offset); + if (0 > tmp) + { + setOfsetFile(0); + } + else + { + setOfsetFile(tmp); + } +} + +U32 getOfsetFile(void) +{ + return fileOfset; +} + +bool getParamModification() +{ + if (parmamModifier == true) + { + parmamModifier = false; + return true; + } + else + { + return false; + } +} + + + +void nextType(void) +{ + switch(curentType) + { + case SHOW_TYPE_HEX: + curentType = SHOW_TYPE_DECIMAL_SIGNED; + break; + case SHOW_TYPE_DECIMAL_SIGNED: + curentType = SHOW_TYPE_DECIMAL_UNSIGNED; + break; + case SHOW_TYPE_DECIMAL_UNSIGNED: + curentType = SHOW_TYPE_HEX; + break; + default : + curentType = SHOW_TYPE_HEX; + break; + } + system("clear"); + parmamModifier = true; +} + +showType_te getType(void) +{ + return curentType; +} + +void nextTypeSize(void) +{ + switch(curentTypeSize) + { + case SHOW_TYPE_SIZE_8: + curentTypeSize = SHOW_TYPE_SIZE_16; + break; + case SHOW_TYPE_SIZE_16: + curentTypeSize = SHOW_TYPE_SIZE_32; + break; + case SHOW_TYPE_SIZE_32: + curentTypeSize = SHOW_TYPE_SIZE_8; + break; + case SHOW_TYPE_SIZE_64: + curentTypeSize = SHOW_TYPE_SIZE_8; + break; + case SHOW_TYPE_SIZE_128: + curentTypeSize = SHOW_TYPE_SIZE_8; + break; + default : + curentTypeSize = SHOW_TYPE_SIZE_8; + break; + } + system("clear"); + parmamModifier = true; +} + +showTypeSize_te getTypeSize(void) +{ + return curentTypeSize; +} diff --git a/parameter.h b/parameter.h new file mode 100755 index 0000000..2234138 --- /dev/null +++ b/parameter.h @@ -0,0 +1,46 @@ +/** + ******************************************************************************* + * @file parameter.h + * @brief Editeur De N'ours : + * @author Edouard DUPIN + * @date 05/02/2011 + * @par Project + * Edn tool : hexViewer + * + * @version $Id$ + * + * @par Copyright + * Copyright 2010 Edouard DUPIN, all right reserved + * + * This is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 3 of the License, or (at your option) any later + * version. + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + ******************************************************************************* + */ + +#ifndef __PARAMETER_H__ +#define __PARAMETER_H__ + +#include "generalDefine.h" + +void setOfsetFile(I32 offset); +void upDownOfsetFile(I32 offset); +U32 getOfsetFile(void); + +bool getParamModification(); + +void nextType(void); +showType_te getType(void); + +void nextTypeSize(void); +showTypeSize_te getTypeSize(void); + +#endif +