IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

MFC Discussion :

générer un CRC


Sujet :

MFC

  1. #21
    Membre à l'essai
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    76
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 76
    Points : 20
    Points
    20
    Par défaut
    Citation Envoyé par farscape
    salut,
    bien tu enchaînes la lecture fichier après fichier pour obtenir un crc global
    ok
    et je lance bien la lecture des .dll et du .exe (pas les fichiers de code) ?

  2. #22
    Membre à l'essai
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    76
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 76
    Points : 20
    Points
    20
    Par défaut
    et... je ne vois pas dans ton code où tu indiques quel fichier lire...

  3. #23
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    salut,avec ca devrait etre bon (j'ai pas teste)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
     
    char *aszFileName[]={"nom1.exe","nom2.exe"};
    unsigned long    original_crc=CRC_MASK; 
    FILE*  stream;
    int i=0;
     
       // utilisation 
       BuildCRCTable();// initialisation    
       for(int i=0;i<sizeof(aszFileName)/sizeof(char *);i++)
       {
    		stream = fopen(aszFileName[i],"rb");
    		fseek( stream, 0L, SEEK_SET);		
    		while(!feof( stream ))
    		{
    			original_crc=UpdateCharacterCRC32(original_crc,fgetc( stream )); 			
    		}
    		fclose(stream);
       }			   
       original_crc^=CRC_MASK;

  4. #24
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    salut,
    projet simple complet dispo sous :
    http://farscape-dev.chez.tiscali.fr/download.htm
    prendre CRC32.

  5. #25
    Membre à l'essai
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    76
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 76
    Points : 20
    Points
    20
    Par défaut
    Citation Envoyé par farscape
    salut,
    projet simple complet dispo sous :
    http://farscape-dev.chez.tiscali.fr/download.htm
    prendre CRC32.
    ok
    c'est gentil mais le zip est corrompu quand je le download.

    J'ai intégré ton code. Ca marche bien sauf que je pensais qu'un CRC32 était de la forme A4B2 par exemple (8x4 = 32). Là, j'ai un CRC du genre 51BBE4B4... dois-je modifier le MASK ?

  6. #26
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    mince pour le zip c'est mon prog ftp qui a foiré ca sera reparé ce soir.
    Ca marche bien sauf que je pensais qu'un CRC32 était de la forme A4B2 par exemple (8x4 = 32). Là, j'ai un CRC du genre 51BBE4B4... dois-je modifier le MASK ?
    par contre la je comprends pas le sens de ta question .
    le crc resultant peut etre afficher sous forme de chaine hexadecimale:
    en utilisant %X ou à un format fixe %10X
    dans tous les cas c'est le resultat du calcul du polynome .changer la valeur du mask me semble hasardeux sauf à en maitriser le calcul ce qui n'est pas mon cas!

  7. #27
    Membre à l'essai
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    76
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 76
    Points : 20
    Points
    20
    Par défaut
    Citation Envoyé par farscape
    mince pour le zip c'est mon prog ftp qui a foiré ca sera reparé ce soir.
    Ca marche bien sauf que je pensais qu'un CRC32 était de la forme A4B2 par exemple (8x4 = 32). Là, j'ai un CRC du genre 51BBE4B4... dois-je modifier le MASK ?
    par contre la je comprends pas le sens de ta question .
    le crc resultant peut etre afficher sous forme de chaine hexadecimale:
    en utilisant %X ou à un format fixe %10X
    dans tous les cas c'est le resultat du calcul du polynome .changer la valeur du mask me semble hasardeux sauf à en maitriser le calcul ce qui n'est pas mon cas!
    oui ben je l'affiche avec %.4X mais il est trop grand et s'affiche sur 8 caractères hexa : 51BBE4B4

  8. #28
    Membre à l'essai
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    76
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 76
    Points : 20
    Points
    20
    Par défaut
    euh... scuse, là c'est moi qui déconne...

    en fait, j'avais besoin d'un CRC 16 bits

  9. #29
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    FF 8 bits char
    FFFF 16 bits short integer (en mode 32bits)
    FFFF-FFFF 32 bits.... long ou un int
    maintenant si tu veux un crc 16 bits je peux trouver ça mais il faut savoir que la precision est moins bonne.

  10. #30
    Membre à l'essai
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    76
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 76
    Points : 20
    Points
    20
    Par défaut
    Citation Envoyé par farscape
    FF 8 bits char
    FFFF 16 bits short integer (en mode 32bits)
    FFFF-FFFF 32 bits.... long ou un int
    maintenant si tu veux un crc 16 bits je peux trouver ça mais il faut savoir que la precision est moins bonne.
    oui je veux bien un algo sur 16
    (m'en fiche de la précision)

  11. #31
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    mon message est arrivé apres le tiens !

    je regarde pour le 16bits reponse dans pas longtemps.

  12. #32
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
     
    unsigned short int Ccitt16Table[ 256 ];
    void BuildTable16( ) 
    {
        int i;
        int j;
        int k;
        int crc;
     
        for ( i = 0 ; i < 256 ; i++ ) {
            k = i << 8;
            crc = 0;
            for ( j = 0 ; j < 8 ; j++ ) {
                if ( ( crc ^ k ) & 0x8000 )
                    crc = ( crc << 1 ) ^ 0x1021;
                else
                    crc <<= 1;
                k <<= 1;
            }
            Ccitt16Table[ i ] = crc;
        }
    }
    #define  CalculateCharacterCRC16(crc,c) (unsigned short int) ( ( crc << 8 ) ^ Ccitt16Table[ (crc >> 8 ) ^ c ] )
    voila !

  13. #33
    Membre à l'essai
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    76
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 76
    Points : 20
    Points
    20
    Par défaut
    j'ai modifié :
    #define CRC_MASK 0xFFFFFFFFL
    par :
    #define CRC_MASK 0xFFFFL

    résultat : nickel !

    et je dirais :
    merci tu m'as sauvé la vie ! (comme toujours)

  14. #34
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    valeur initial du Mask 0.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    crc=0;
    crc=CalculateCharacterCRC16(crc,c)

  15. #35
    Membre à l'essai
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    76
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 76
    Points : 20
    Points
    20
    Par défaut
    ok merci !

  16. #36
    Membre à l'essai
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    76
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 76
    Points : 20
    Points
    20
    Par défaut
    original_crc^=CRC_MASK;

    se transforme aussi en original_crc^=0; ??? t'es sûr ?

  17. #37
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    apparement il y pas besoin de le faire à la fin.

  18. #38
    Membre à l'essai
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    76
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 76
    Points : 20
    Points
    20
    Par défaut
    autre chose :

    je compile, j'execute : crc = AC9A
    je ré-execute : crc = AC9A
    je recompile (sans changer le code d'un pouce), j'execute : crc = 0EFF.

    normalement, si je recompile sans changer le code, j'ai le même CRC non ?

  19. #39
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    effectivement ,
    moi je ferais le test suivant:
    je compile j'execute je regarde le crc ,je mets le prg de cote
    je recompile j'execute je regarde le crc si <> je reteste avec le prog mis de cote .
    si le resultat est le même ça veut dire que le compilo ne produit toujours la même chose sinon bug
    tient moi au courant .

  20. #40
    Membre à l'essai
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    76
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 76
    Points : 20
    Points
    20
    Par défaut
    le plus simple est que je te file mon code :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    unsigned short int Ccitt16Table[ 256 ]; 
    void BuildTable16( ) 
    { 
        int i; 
        int j; 
        int k; 
        int crc; 
     
        for ( i = 0 ; i < 256 ; i++ ) { 
            k = i << 8; 
            crc = 0; 
            for ( j = 0 ; j < 8 ; j++ ) { 
                if ( ( crc ^ k ) & 0x8000 ) 
                    crc = ( crc << 1 ) ^ 0x1021; 
                else 
                    crc <<= 1; 
                k <<= 1; 
            } 
            Ccitt16Table[ i ] = crc; 
        } 
    } 
    #define  CalculateCharacterCRC16(crc,c) (unsigned short int) ( ( crc << 8 ) ^ Ccitt16Table[ (crc >> 8 ) ^ c ] ) 
     
     
     
     
     
     
     
     
       // utilisation   
     unsigned long CalculeCRC(){
    	 char system_path[1000]; 
    	 GetWindowsDirectory(system_path, 1000);
    	 char DllPlop[1000];
    	 sprintf(DllPlop, "%s\\DllPlop.dll",system_path);
    	 char Classe[1000];
    	 sprintf(Classe, "%s\\Classe.dll",system_path);
     
     
    	char *aszFileName[]={DllPlop,Classe, "MON_APPLI.exe"}; 
    	unsigned long original_crc=0; 
    	FILE*  stream; 
    	int k=0; 
     
       BuildTable16();// initialisation  
       for(k=0;k<sizeof(aszFileName)/sizeof(char *);k++) 
       { 
          stream = fopen(aszFileName[k],"rb"); 
          fseek( stream, 0L, SEEK_SET);       
          while(!feof( stream )) 
          { 
             original_crc=CalculateCharacterCRC16(original_crc,fgetc( stream ));           
          } 
          fclose(stream); 
       }             
       //original_crc^=CRC_MASK; 
       return original_crc;
    }

+ Répondre à la discussion
Cette discussion est résolue.
Page 2 sur 3 PremièrePremière 123 DernièreDernière

Discussions similaires

  1. Générer un nombre aléatoire entre 0 et 1 (INCLUS !!!)
    Par haypo dans le forum Algorithmes et structures de données
    Réponses: 3
    Dernier message: 22/08/2002, 16h30
  2. [CR][VB] comment générer un état ?
    Par ndi dans le forum SDK
    Réponses: 3
    Dernier message: 22/08/2002, 13h13
  3. Cherche l'algo crc 16 bits
    Par icepower dans le forum Algorithmes et structures de données
    Réponses: 2
    Dernier message: 21/08/2002, 13h27
  4. codes crc
    Par patturbo dans le forum C++Builder
    Réponses: 7
    Dernier message: 24/07/2002, 09h28
  5. Réponses: 5
    Dernier message: 08/07/2002, 16h22

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo