I am trying to search for an identification tag in a binary using a conditional (if) statement for each iteration of the search, in which if the search has completed successfully it will echo a message and the location of the identified hexadecimal tag.
When I execute the code in CMD, it returns no response except for: echo "test 1"; echo "test 2";
My Code:
<?php
// Author: Labrador
// Date: 19-07-2020
// Purpose: To modify the contents of a binary
checkBin();
// This function checks the input file to see if it is compatible with the program
function checkBin() {
//Open file in current directory
$file = file_get_contents(dirname(__FILE__). './file.bin');
echo "test 1";
//Convert file to hexadecimal
$ori = strtoupper(bin2hex($file));
$ori_hex = str_split($ori, 2);
$ori_hex_length = count($ori_hex);
$string_loc = 0;
echo "test 2";
// Search for identification tag
for ($i = 0; $i < ($ori_hex_length - 1); $i++) {
if (hexdec($ori_hex[$i]) == hexdec("36")) {
if (hexdec($ori_hex[$i + 1]) == hexdec("30")) {
if (hexdec($ori_hex[$i + 2]) == hexdec("36")) {
if (hexdec($ori_hex[$i + 3]) == hexdec("59")) {
if (hexdec($ori_hex[$i + 4]) == hexdec("30")) {
{
$string_loc = 0x00000000 + $i;
echo "Binary Identified as compatible Software <strong>0x".$string_loc."</strong> \n";
}
}
}
}
}
}
}
// Return false if not found
if ($string_loc==0)
{
return false;
echo "Not Found!";
}
echo "test 3";
}
?>
User contributions licensed under CC BY-SA 3.0