跳到主内容
@wquguru
精选88Hacker News Best(web_list)技巧与观点

用AI逆向工程硬件:从抓包到驱动开发的完整工作流

Using AI to reverse engineer hardware

原文
发到 X
推荐理由

提供了一套可复现的“AI+抓包”逆向工程硬件工作流,包含具体工具链设计与对比逻辑,对需要开发Linux驱动的开发者极具参考价值。

After my mother passed away I ended up with a big box full of old film negatives containing photos from childhood family trips and similar. So I decided to buy a negative photo scanner and found that the Plustek 8200i was supported under Linux so I bought that. Only to discover that the chipset in the scanner had changed to one that wasn’t supported under Linux anymore. So I had some success making Linux configuration tools for some of my hardware using Claude code, like my Dell Camera controller app so I thought, maybe Claude can help me get a working SANE driver. I basically got stuck and got nowhere for the longest time and even basically gave up on the project for a few Months.

母亲去世后,我留下一个装满旧胶片底片的大盒子,里面是童年家庭旅行等照片。于是我决定购买一台底片扫描仪,发现 Plustek 8200i 在 Linux 下受支持,便买了那款。结果却发现扫描仪的芯片组已更换为 Linux 不再支持的型号。此前我曾利用 Claude code 为部分硬件制作 Linux 配置工具(例如我的 Dell Camera 控制器应用),因此我想,也许 Claude 能帮我搞定一个可用的 SANE 驱动。我基本上卡住了,长时间毫无进展,甚至为此项目放弃了几个月。

Then I saw a post on X from Tom Crider aka Glorious Eggroll talking about how he had managed to fix a mouse driver using AI tooling. He basically described how he set it up so that the AI agent had full control of a Windows instance to capture data needed to fix the driver. So I pasted his tweet into Claude and asked it to help me set up a windows virtual machine to do the same things Tom as doing for my scanner. I think the combination of having the ability to run scans under windows and capture the USB data while doing so worked wonders, probably combined with improvements to Claude code made a huge difference. Within a few hours I had my first ever working scan under Linux, sure with some quality issues, but 100% recognizable as the image in the negative. Some days later I had a near perfect driver, including support for Infrared scanning ready to go, only to discover that in the time between me giving up and then trying again someone had committed code to SANE to support the scanner already…..it happens sometimes. I also used Claude to write an application for doing negative scanning, which I named Negative Vibes, thought that was a cute name.

然后我在 X(原 Twitter)上看到 Tom Crider(又名 Glorious Eggroll)的一篇帖子,讲述他如何利用 AI 工具修复鼠标驱动。他基本描述了如何设置让 AI 代理完全控制 Windows 实例,以捕获修复驱动所需的数据。于是我把他的推文粘贴到 Claude 中,请它帮我搭建一个 Windows 虚拟机,以便对我的扫描仪做同样的事情。我认为能够在 Windows 下运行扫描并在此过程中捕获 USB 数据的能力发挥了奇效,这可能与 Claude code 的改进相结合产生了巨大影响。几个小时内,我就在 Linux 下实现了首次成功扫描,虽然存在一些质量问题,但图像内容 100% 可识别。几天后,我得到了一个近乎完美的驱动,包括准备就绪的红外扫描支持,结果却发现在我放弃和重新尝试之间的这段时间里,有人已经向 SANE 提交了支持该扫描仪的代码……这种事偶尔会发生。我还使用 Claude 编写了一个用于底片扫描的应用程序,命名为 Negative Vibes,觉得这个名字挺可爱。

Anyway, with the success of my scanner effort I thought, I wonder if I can use this to finally fix the last issues with MIPI camera support on my laptop. So I told claude to re-use the harness I had created and try to fix the MIPI camera on my laptop by updating the kernel driver and libcamera as needed. I started the job in the morning and by the end of the day I had a much improved situation with patches for both the kernel and libcamera ready.

总之,鉴于扫描仪项目的成功,我想,不知道能否借此最终解决笔记本电脑上 MIPI 相机支持的遗留问题。于是我叫 Claude 复用我之前创建的框架,通过按需更新内核驱动和 libcamera 来修复笔记本上的 MIPI 相机。我在早上开始这项工作,到当天结束时,情况已大幅改善,内核和 libcamera 的补丁均已就绪。

So I thought that this might be worthwhile sharing with the world, and while anyone could start from scratch I did ask Claude to make the harness generic and document it to make the pathway for anyone else who wants to try this on their hardware a little easier. Writing a driver for undocumented hardware has always been tedious. You capture bus traffic, stare at hex dumps, and form hypotheses about what each register or control transfer does. You then test them one at a time, usually for weeks. None of it is conceptually hard, but it takes a lot of patience and skills.

所以我认为这可能值得与全世界分享,虽然任何人都可以从头开始,但我确实要求 Claude 使 harness 通用化并对其进行文档化,以便为其他想在他们的硬件上尝试此操作的人铺平道路。为未记录的硬件编写驱动程序一直都很繁琐。你捕获总线流量,盯着十六进制转储,并对每个寄存器或控制传输的作用形成假设。然后你一次测试一个,通常要花上几周时间。这在概念上都不难,但需要大量的耐心和技巧。

That kind of work suits an AI model well. It can read thousands of lines of USB capture, notice that a sequence repeats with one byte changing, and propose what that byte means. It can write the test to confirm it, and it doesn’t get bored. The human still decides what to build and checks that it works on real hardware, but the slog shrinks a lot.

这类工作非常适合 AI 模型。它可以阅读数千行 USB 捕获数据,注意到一个序列在其中一个字节发生变化时重复出现,并提出该字节的含义。它可以编写测试来确认这一点,而且它不会感到无聊。人类仍然决定构建什么并检查它在真实硬件上是否有效,但繁重的劳动大大减少了。

hw-harness

Be aware that I did not use hw-harness in this form for my projects as this was basically bespoke code at that time, so this project is an attempt to make the harness more generic and shareable from the scripts I was using while doing the work. What hw-harness is meant to help your Claude or Codex session with:

请注意,我并没有以这种形式在我的项目中使用 hw-harness,因为当时这基本上是定制代码,所以这个项目是试图从我工作时使用的脚本中使 harness 更加通用和可共享。hw-harness 旨在帮助你的 Claude 或 Codex 会话:

1. Record a reference session. Run the vendor’s Windows driver in a KVM virtual machine, with the real device passed through to the guest.

1. 记录参考会话。在 KVM 虚拟机中运行供应商的 Windows 驱动程序,并将真实设备直通到客户机中。

2. Capture from outside the VM. Record the traffic on the Linux host with usbmon. It sits below the passthrough layer, so the guest can’t see it.

2. 从 VM 外部捕获。使用 usbmon 在 Linux 主机上记录流量。它位于直通层之下,因此客户机无法看到它。

3. Repeat the same operation on Linux with your own driver, and capture that the same way.

3. 在你的驱动程序下在 Linux 上重复相同的操作,并以相同的方式捕获。

4. Diff the two traces. Both come from the same instrument, so they compare directly. The differences are your list of driver bugs.

4. 比较两个跟踪结果。两者都来自同一仪器,因此可以直接比较。差异就是你的驱动程序错误列表。

For devices with no bus to tap, such as an internal MIPI camera, the harness uses Windows-side inspection instead. That means INF files, registry data, ACPI tables and device properties.

对于没有总线可探测的设备,例如内部 MIPI 摄像头,harness 使用 Windows 端检查。这意味着 INF 文件、注册表数据、ACPI 表和设备属性。

The approach should be fine in the sense it doesn’t rely on copying any code instead it observes what the hardware does and only extract configuration data from the Windows drivers, so every constant in the new driver traces back to something recorded.

这种方法应该是可行的,因为它不依赖于复制任何代码,而是观察硬件做什么,并且只从 Windows 驱动程序中提取配置数据,因此新驱动程序中的每个常量都可以追溯到记录的内容。

So for those interested I have 3 short descriptions of the projects I did and what was needed.

所以对于感兴趣的人,我有 3 个简短的描述,介绍我所做的项目以及所需的内容。

Project 1: a SANE backend for the Plustek OpticFilm 8200i

项目 1:Plustek OpticFilm 8200i 的 SANE 后端

Comparing the driver output of two drivers available.

比较两个可用驱动程序的驱动程序输出

The first project is a SANE backend for the newer Plustek OpticFilm 8200i. It uses the Genesys GL128 controller (USB 07b3:1825) and had no Linux support. The older model with the same name uses a GL845 and is already handled by SANE.

第一个项目是为新款 Plustek OpticFilm 8200i 扫描仪开发的 SANE 后端。它使用 Genesys GL128 控制器(USB 07b3:1825),此前没有 Linux 支持。同名的旧款型号使用 GL845 控制器,目前已由 SANE 处理。

The backend supports:

该后端支持:

  • Color, gray, infrared and color+infrared modes
  • Resolutions from 300 to 7200 dpi, at 8 or 16 bits per channel
  • Dust and scratch removal from the infrared channel
  • An exposure multiplier for dense negatives
  • 彩色、灰度、红外以及彩色+红外模式
  • 分辨率从 300 到 7200 dpi,每通道 8 或 16 位
  • 通过红外通道去除灰尘和划痕
  • 针对高密度底片的曝光倍增器

It’s packaged as a Fedora RPM, built automatically on every push. I mostly tested it with my own Negative Vibes application as there are not that many options under Linux for negative scanning.

它以 Fedora RPM 包的形式发布,每次推送时自动构建。我主要使用自己的 Negative Vibes 应用程序对其进行测试,因为在 Linux 下用于底片扫描的选项并不多。

Upstream SANE’s genesys backend also gained support for this scanner in September 2026, so I compared the two. Both resolve the same fine detail at 3600 dpi. Mine is faster at full resolution (34.6 s against 54.4 s) and supports infrared dust removal. Upstream offers more resolution steps. The webpage has an interactive side-by-side comparison you can check out. These are single-unit, single-frame results, so treat them as one data point. Check out the interactive page I made showing the current state of the two drivers, hopefully the discoveries I made can be used by the SANE project to fix some smaller items in the upstream driver. Anyway, I put this project up more as a proof of concept due to that since I expect everyone including myself will use the upstream driver once it reaches parity with this one.

SANE 上游的 genesys 后端也在 2026 年 9 月增加了对该扫描仪的支持,因此我对两者进行了比较。在 3600 dpi 下,两者都能解析相同的精细细节。我的版本在全分辨率下速度更快(34.6 秒对比 54.4 秒),并支持红外除尘。上游版本提供了更多的分辨率步进。网页上有一个交互式并列对比供您查看。这些是单台设备、单帧的结果,因此请将其视为一个数据点。请查看我制作的展示两个驱动程序当前状态的交互页面,希望我所做的发现能被 SANE 项目用来修复上游驱动程序中的一些小问题。总之,由于我预计包括我在内的所有人都会在上游驱动达到与此驱动相当的水平后使用上游驱动,因此我将此项目更多地作为概念验证提出。

Project 2: Negative Vibes

项目 2:Negative Vibes

Full scan of negative completed including infrared cleaning of image.

底片完整扫描已完成,包括图像的红外清理。

A driver alone isn’t much use if scanning negatives is still painful, so I built Negative Vibes. It’s a GNOME app, written in Rust, for scanning colour and black-and-white negatives and slides on any film-capable SANE scanner.

如果扫描底片仍然痛苦,那么仅有驱动程序是没有多大用处的,因此我构建了 Negative Vibes。它是一个 GNOME 应用程序,用 Rust 编写,用于在任何支持底片的 SANE 扫描仪上扫描彩色和黑白底片及幻灯片。

The scan is kept exactly as the scanner delivered it: 16-bit, linear, with the infrared plane. Everything else is a stack of non-destructive settings on top, so you can change the look and export again. It includes:

扫描结果保持与扫描仪输出完全一致:16 位、线性,并包含红外平面。其他所有内容都是基于非破坏性设置的堆栈,因此您可以更改外观并重新导出。它包括:

  • Density-space negative inversion with film base and dye-crosstalk correction
  • Roll-wide settings with per-frame overrides
  • Infrared and software dust removal
  • IT8 calibration through ArgyllCMS
  • Export to TIFF, JPEG, PNG and DNG, with ICC profiles and metadata
  • 密度空间底片反转,带有胶片基底和染料串扰校正
  • 整卷设置及逐帧覆盖
  • 红外和软件除尘
  • 通过 ArgyllCMS 进行 IT8 校准
  • 导出为 TIFF、JPEG、PNG 和 DNG 格式,附带 ICC 配置文件和元数据

It ships as a Flatpak that includes the scanner backend. It’s tested on the 8200i so far. The goal is to support any film scanner SANE supports. For that, SANE needs a standard way to expose infrared channels, which it doesn’t have yet.

它以 Flatpak 形式发布,其中包含扫描仪后端。目前已在 8200i 上进行了测试。目标是支持 SANE 支持的任何底片扫描仪。为此,SANE 需要一种标准的暴露红外通道的方法,而目前它还没有。

Project 3: Fixing the MIPI camera on my ThinkPad

项目3:修复我的ThinkPad上的MIPI摄像头

Showing MIPI output before and after fixes. Colors are better than they look as I was sitting in a relatively dark room by the end of the session.

展示修复前后的MIPI输出。由于在会议结束时我坐在一个相对较暗的房间里,实际颜色比看起来更好。

The camera in my Lenovo ThinkPad X1 Carbon Gen 14 (Aura Edition) uses a Sony IMX471 sensor behind an Intel IPU7. On Linux it produced dark images with heavy vignetting and a strong yellow-green cast. mipi-fixes-x1-aura collects the fixes. It’s only relevant to this laptop, which is why it isn’t one of the bigger packaged projects, but I have already submitted the kernel patches to Kate Hsuan and the libcamera patches is being reviewed by Wim Taymans for submission to Libcamera.

我的Lenovo ThinkPad X1 Carbon Gen 14(Aura版)中的摄像头使用索尼IMX471传感器,位于Intel IPU7之后。在Linux系统下,它生成的图像昏暗、存在严重的暗角以及强烈的黄绿色偏色。mipi-fixes-x1-aura收集了相关的修复方案。该方案仅适用于这款笔记本电脑,因此它没有被打包成大型项目之一,但我已经向Kate Hsuan提交了内核补丁,并且libcamera补丁正在由Wim Taymans审核,以便提交给Libcamera。

Kernel (IMX471 driver):

内核(IMX471驱动):

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

关联信息,但可能不是同一事件