php - 使用 PHP 在二进制中搜索十六进制标记
问题描述
我正在尝试使用条件(if)语句在搜索的每次迭代中搜索二进制文件中的标识标签,如果搜索成功完成,它将回显一条消息和已识别的十六进制标签的位置。
当我在 CMD 中执行代码时,它没有返回任何响应,除了: echo "test 1"; 回声“测试2”;
我的代码:
<?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";
}
?>
解决方案
推荐阅读
- join - 如何使用 ffmpeg 连接所有“mkv”文件?
- amazon-web-services - 具有 OpenAPI 招摇资源定义的 terraform 中的 AWS API Gateway
- angular - Github Pages 无法将源更改为 docs 文件夹
- reactjs - 如何在 React 的无状态函数组件中初始化类实例?
- java - 在 Java 中包含 python 文件和库
- sockets - 如何在特定网站上找到 websocket 和 websocket url?
- python - 在python中屏蔽图像
- python - 处理非结构化数据——Python panda
- xamarin - 在 Xamarin.Android 中,需要通过使用 DependencyService 从 Xamarin.Forms 调用来使用 Activity
- android - Xamarin - 仅发布中的“资源”文件夹中未加载或丢失的项目