diff --git a/tools/corrupt/corrupt.php b/tools/corrupt/corrupt.php new file mode 100644 index 0000000..1a0be37 --- /dev/null +++ b/tools/corrupt/corrupt.php @@ -0,0 +1,83 @@ + (500 * 1024)) die("File is too big"); + + function jpegIsValid($filename) { + // load the file + $img = @imageCreateFromJPEG($filename); + + // return 0 if the image is invalid + if(!$img) return(0); + + // return 1 otherwise + return(1); + } + + function scramble($content, $size) { + $sStart = 10; + $sEnd = $size-1; + $nReplacements = rand(1, 30); + + for($i = 0; $i < $nReplacements; $i++) { + $PosA = rand($sStart, $sEnd); + $PosB = rand($sStart, $sEnd); + + $tmp = $content[$PosA]; + $content[$PosA] = $content[$PosB]; + $content[$PosB] = $tmp; + } + + return($content); + } + + // first check if 'upfile' is set + if(empty($upfile) or empty($upfile_name)) { + die("No file to corrupt, please go back and select a JPEG image to upload."); + } + + // then check if it is a JPEG file + if($upfile_type != "image/jpeg") { + die("The image does not seem to be JPEG but of type '$upfile_type', please go back and select a JPEG image to upload."); + } + + // load the file and get its size + $content = file_get_contents($upfile); + $size = $upfile_size; + + // now store the original one + $fd = fopen("images/$upfile_name", "w") or die("The first fopen went wrong, e-mail webmaster Ben."); + fwrite($fd, $content, $size) or die("The first fwrite went wrong, e-mail webmaster Ben."); + fclose($fd); + + // check the copied image + if(!imageCreateFromJPEG("images/$upfile_name")) { + die("This JPEG is not valid, please go back and try another one."); + } + + // create a folder to store the corrupted versions + @mkdir("images/$upfile_name-corrupted"); + + // corrupt it a few times + for($c = 0, $r = 0; $c < $nCorrupts && $r < $nRetries; $r++) { + // corrupt the file + $corrupted = scramble($content, $size); + + // save it to disc + $fd = fopen("images/$upfile_name-corrupted/$c.jpg", "w") or die("The fopen went wrong, e-mail webmaster Ben."); + fwrite($fd, $corrupted, $size) or die("The fwrite went wrong, e-mail webmaster Ben."); + fclose($fd); + + // count succeeded corrupts + if(jpegIsValid("images/$upfile_name-corrupted/$c.jpg")) $c++; + } + + // jippie! we're done! now go to the list of images... + Header("Location: index.php"); +?> diff --git a/tools/corrupt/index.html b/tools/corrupt/index.html new file mode 100644 index 0000000..5367a12 --- /dev/null +++ b/tools/corrupt/index.html @@ -0,0 +1,106 @@ + + + +
+
+
+
+ Corrupt™ - data corruption software 3.0 +
| |
![]() |
+
+ +Upload and Corrupt™ a JPEG file - Max 500kb + + + |
+
+
+
+
![]() |
+|
3 Latest uploaded image | Corrupted version | ");
+ echo(" | ");
+ echo("");
+ }
+?>
+
+
+
+
Corrupt™ - data corruption software 3.0
+
Corrupt by Corrupt by Recyclism is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Based on a work at www.recyclism.com.
+
Corrupt™ - data corruption software 3.0
+
Corrupt by Corrupt by Recyclism is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Based on a work at www.recyclism.com.
+