Skip to content

Instantly share code, notes, and snippets.

@dizzi
Created October 29, 2011 13:35
Show Gist options
  • Save dizzi/1324466 to your computer and use it in GitHub Desktop.
Save dizzi/1324466 to your computer and use it in GitHub Desktop.
bin2jpg
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