Skip to content

Instantly share code, notes, and snippets.

@azcdev
Created October 12, 2013 03:36
Show Gist options
  • Save azcdev/6945508 to your computer and use it in GitHub Desktop.
Save azcdev/6945508 to your computer and use it in GitHub Desktop.
Script en PHP para extraer imagenes de cadenas de texto
<?php
function extraerImagen($cadenaDeTexto, $encabezado, $pieDeArchivo){
$ini = strpos($cadenaDeTexto, $encabezado);
if ($ini == 0) return false;
$lon = strpos($cadenaDeTexto,$pieDeArchivo, $ini);
return substr($cadenaDeTexto,$ini,$lon);
}
$archivo = 'fileCarvingTest.docx';
$buffer = fread(fopen($archivo, "r"), filesize($archivo));
$imagen = extraerImagen(bin2hex($buffer), "ffd8", "ffd9");
if($imagen) {
file_put_contents('imagenExtraida.jpg',hex2bin($imagen));
} else {
echo "Imagen no encontrada";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment