Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package replaceHeader;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.RandomAccessFile;
- public class replaceHeader {
- static String hexString = ""; // A hex string that you want to use as replacement for the first 512 bits. 512 bits in hex is 1024 characters
- static byte[] headerBits = hexStringToByteArray(hexString);
- static File fil;
- static String path = "/path/to/folder/containing/files"; // EDIT THIS!!
- public static void main(String[] args) throws IOException{
- File folder = new File(path);
- File[] listOfFiles = folder.listFiles();
- for(int i = 0; i < listOfFiles.length; i++){
- fil = new File(listOfFiles[i]+"");
- replaceBytes();
- }
- }
- public static byte[] hexStringToByteArray(String s) {
- int len = s.length();
- byte[] data = new byte[len / 2];
- for (int i = 0; i < len; i += 2) {
- data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
- + Character.digit(s.charAt(i+1), 16));
- }
- return data;
- }
- public static void replaceBytes() throws IOException{
- RandomAccessFile raf = new RandomAccessFile(fil, "rw");
- try {
- raf.seek(0);
- raf.write(headerBits, 0, hexString.length()/2);
- } finally {
- raf.close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement