0

im currently try to echo the raw bytes of a DLL File in hexa format, the unpack function overflow the variable memory limit ( not setable by my hosting service atm), is there any method to read it by parts into 3 or more variables, or other methods to output the bytes and echo these?

the file size is around 1,98MB ( 1.990.656 BYTES ) ( yes i know the buffer is much bigger in php).

Following error occured: Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 67108872 bytes)

Thanks for any help.

ini_set('memory_limit', '-1');
$fileName= "driver.dll"; 
$fsize = filesize($fileName); 

$hex = unpack("C*", file_get_contents($fileName));
$hexa_string= "";

foreach($hex as $v) 
{
    $hexa_string.= sprintf("%02X", $v);
}

echo $hexa_string;
rck
  • 33
  • 5
  • 1
    Possible duplicate of [Allowed memory size of 33554432 bytes exhausted (tried to allocate 43148176 bytes) in php](https://stackoverflow.com/questions/415801/allowed-memory-size-of-33554432-bytes-exhausted-tried-to-allocate-43148176-byte) – Darragh Enright Aug 17 '19 at 10:15
  • yea, but i cant set the memory limit as i said. – rck Aug 17 '19 at 10:18
  • 1
    Have you tried `bin2hex`? – odan Aug 17 '19 at 14:44

1 Answers1

0

You'd have to use the c wrappers for file manipulation: fseek

$size = 1024 * 1000;
$handle = fopen($file, 'r');
fseek($handle, -$size);
$limitedContent = fread($handle, $size);
Harshil Patel
  • 278
  • 2
  • 8
  • yea that gave me the wrong output: with stringToHex "4D5A90030004000FFFF" supposed: "4D5A90000300000004000000FFFF" seems cutted of, idk why – rck Aug 17 '19 at 11:11