shanept/assembly-simulator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

shanept/assembly-simulator

Composer 安装命令:

composer require shanept/assembly-simulator

包简介

Allows stepping through compiled assembly code. Provides access to registers and the stack for easy querying of values.

README 文档

README

The AssemblySimulator project provides a means to step through compiled assembly code, operation by operation, and provides access to registers and the stack for easy querying of values. The implementation is quite simplistic, we only implement a few basic instructions. However the architecture allows for easy extensibility of the instruction set, to satisfy your project's needs.

The Simulator

The simulator may be manually instantiated, or instantiated by the SimulatorFactory. Note that using the SimulatorFactory does not restrict you from registering further instructions after the simulator is created. The following are equivalent:

<?php
// METHOD 1: Using the factory.
$simulator = SimulatorFactory::createSimulator(Simulator::PROTECTED_MODE);

// METHOD 2: Manually creating the simulator.
$simulator = new Simulator(Simulator::PROTECTED_MODE);

// Instantiate default instruction set manually.
$xor = new ExclusiveOr();
$lea = new LoadEffectiveAddress();
$mov = new Move();
$pop = new Pop();
$push = new Push();

// Link instruction set to simulator.
$xor->setSimulator($simulator);
$lea->setSimulator($simulator);
$mov->setSimulator($simulator);
$pop->setSimulator($simulator);
$push->setSimulator($simulator);

Modes

The simulator supports operating in real, protected and long mode. In order to specify the mode under which the simulator should operate, provide one of the mode constants to either the constructor or the setMode function:

  • Simulator::REAL_MODE
  • Simulator::PROTECTED_MODE
  • Simulator::LONG_MODE

Note: If you set the simulator mode with $simulator->setMode() function, you must perform a reset before performing any simulations, with a call to $simulator->reset(). See the Simulator Reset section.

Resetting the Simulator

There are some circumstances where you will need to reset the simulator - think of it like hitting the reset switch on your computer. The reset function is used to restore the simulator to a better known state. This includes clearing registers and the stack.

Registering Custom Instructions

In order to use the simulator, it must be instantiated with the instruction set you wish to use. An example is provided here with the default instruction set. Please note, if you wish to use the simulator with the default instruction set, you can simply use the SimulatorFactory.

For more information, see the custom instruction example.

<?php
$simulator = new Simulator(Simulator::PROTECTED_MODE);

// Instantiate our instruction set.
$exclusiveOr = new ExclusiveOr;
$lea = new LoadEffectiveAddress;
$mov = new Move;
$pop = new Pop;
$push = new Push;

// Link our instruction set with the simulator.
$exclusiveOr->setSimulator($simulator);
$lea->setSimulator($simulator);
$mov->setSimulator($simulator);
$pop->setSimulator($simulator);
$push->setSimulator($simulator);

The Code Buffer

Prior to simulation, the simulator must be provided a code buffer off which to operate. This must be provided as a binary string.

<?php
$simulator = new Simulator(Simulator::PROTECTED_MODE);

// Taken from PHP v8.3.7 Thread-Safe Windows "php8ts.dll" binary.
$assemblyCode =
    "\x56" .                                        // push esi
    "\x68\x18\xA7\x60\x10" .                        // push 0x1060A718
    "\x6A\x0B" .                                    // push 0xB
    "\x68\x98\x4D\x61\x10";                         // push 0x10614D98

$simulator->setCodeBuffer($assemblyCode);

// OR: Reads the same string from the php8ts.dll file.
$fp = fopen("php8ts.dll", "rb");
fseek($fp, 4782677);
$assemblyCode = fread($fp, 13);
fclose($fp);

$simulator->setCodeBuffer($assemblyCode);

// The simulator can now run.
$simulator->simulate();

Examples

For more information, see the examples under the example directory.

  • examples/getCdeclFunctionCallParameters.php - For a basic example of how to use the simulator.
  • examples/registeringCustomInstruction.php - For an example of how to build and use a custom instruction.
  • examples/registeringCustomInstructionWithFactory.php - As above, uses the SimulatorFactory.
  • examples/myCustomInstruction.php - For an example of how a custom instruction is implemented.

shanept/assembly-simulator 适用场景与选型建议

shanept/assembly-simulator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 05 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 shanept/assembly-simulator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 shanept/assembly-simulator 我们能提供哪些服务?
定制开发 / 二次开发

基于 shanept/assembly-simulator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 26
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 17
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-05-22