commit f92798f4aedcc4a06901a491e30daf3bfec9e04c Author: Mysaa Date: Mon May 24 12:48:25 2021 +0200 Premier commit - Inclusion dans le système git diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e108870 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.classpath +.project +.settings +bin/ diff --git a/src/com/bernard/exfatdemerde/ExfatChecksumCalculator.java b/src/com/bernard/exfatdemerde/ExfatChecksumCalculator.java new file mode 100644 index 0000000..b70a8cb --- /dev/null +++ b/src/com/bernard/exfatdemerde/ExfatChecksumCalculator.java @@ -0,0 +1,47 @@ +package com.bernard.exfatdemerde; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Scanner; + +public class ExfatChecksumCalculator { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("Chemin du fichier ?"); + File f = new File(sc.nextLine()); + if(!f.exists()) { + System.err.println("ERREUR: le fichier spécifié est introuvable");sc.close();return; + } + System.out.println("Nombre de bytes par secteur ?"); + int byteCount = 11*sc.nextInt(); + System.out.println("Lecture de "+byteCount+" octets"); + + try (FileInputStream fis = new FileInputStream(f)){ + byte[] data = new byte[byteCount]; + fis.read(data); + int checksum = exfatBootChecksum(data, byteCount); + System.out.println("Voila la checksum que j'ai calculée :"); + System.out.println(Integer.toString(checksum)); + System.out.println("0x"+Integer.toHexString(checksum)); + }catch(IOException e) { + e.printStackTrace(); + } + + System.out.println("\n\nTadaaaaaaaaaa"); + sc.close(); + } + + public static final int exfatBootChecksum(byte[] data, long bytes){ + int checksum = 0; + for (int i = 0 ; i < bytes ; i++){ + if (i == 106 || i == 107 || i == 112) + continue; + checksum = ((byte)((checksum&0xFF) << 31)) | (((byte)((checksum&0xFF) >> 1)) + ((byte)(data[i]&0xFF))); + //System.out.println("Checksum :"+Integer.toHexString(checksum)); + } + return checksum; + } + +}