Created
October 29, 2011 13:35
-
-
Save dizzi/1324466 to your computer and use it in GitHub Desktop.
bin2jpg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.io.FileType | |
targetDirectory = System.getProperty("user.dir") | |
println("Working directory: "+targetDirectory) | |
targetDirectory = "d:/test" | |
def param | |
if(args.size() != 0) | |
param = args[0] | |
else | |
param = "" | |
if(param == "criple"){ | |
println("Cripling only...") | |
} | |
def workDir = new File(targetDirectory) | |
workDir.traverse( | |
type:FileType.FILES, | |
nameFilter:~/.*\.jpg/ | |
){ | |
print(it) | |
// def file = new File(it) | |
def fn = it.getBytes() | |
if(fn[0]==(Byte)0xFF && fn[1]==(Byte)0xD8){ | |
println(" File has JPEG header") | |
if(param=="criple"){ | |
fn[0]=(Byte)0x30 | |
fn[1]=(Byte)0x30 | |
it.setBytes(fn) | |
} | |
} else if(fn[0]==(Byte)0x30 && fn[1]==(Byte)0x30){ | |
println(" File has cripled header, restoring") | |
fn[0]=(Byte)0xFF | |
fn[1]=(Byte)0xD8 | |
it.setBytes(fn) | |
} else { | |
println(" Undefined") | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment