简体   繁体   English

操纵装配说明

[英]Manipulate Assembly Instructions

I would like to "test" a function in C++ by manipulating its assembly instructions. 我想通过操作其汇编指令来“测试”C ++中的函数。 What's the best way to do something like this? 做这样的事情最好的方法是什么?

I guess one way is to have it compiled or an executable and then to start that .exe by another program which then tries to manipulate it. 我想一种方法是将它编译或执行,然后由另一个程序启动该.exe然后尝试操作它。 If that function-under-test has a point where its still running but waits for something (ie user input) then the simulator (program that starts the function-under-test) does not even need to put some kind of break-point into it. 如果被测功能有一个点仍然在运行但是等待某些东西(即用户输入)那么模拟器(启动被测功能的程序)甚至不需要设置某种断点。它。

How can I start a program and manipulate its assembly instructions? 如何启动程序并操作其汇编指令?

More clearly: Is it actually possible to write a simple simulator that (sets a break-point or for the first step without a break-point) and then access the memory of the running function-under-test to manipulate its assembly instructions? 更清楚的实际上是否可以编写一个简单的模拟器(设置断点或没有断点的第一步),然后访问正在运行的测试函数的内存来操作其汇编指令? It would be a very small and simple version of the big gdb. 这将是一个非常小而简单的大gdb版本。

  • write (and test) C++ program foo.cpp 编写(和测试)C ++程序foo.cpp

  • compile to asembly source ( g++ -Wall -S foo.cpp - output will be foo.s) 编译到asembly源代码( g++ -Wall -S foo.cpp - 输出将是foo.s)

  • REPEAT 重复

    • modify foo.s 修改foo.s

    • assemble foo.s ( gcc foo.s ) 汇编foo.s( gcc foo.s

    • test resulting executable ( ./a.out or gdb ./a.out ) 测试生成的可执行文件( ./a.outgdb ./a.out

  • UNTIL done 直到完成

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM