简体   繁体   中英

Manipulate Assembly Instructions

I would like to "test" a function in C++ by manipulating its assembly instructions. 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. 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.

  • write (and test) C++ program foo.cpp

  • compile to asembly source ( g++ -Wall -S foo.cpp - output will be foo.s)

  • REPEAT

    • modify foo.s

    • assemble foo.s ( gcc foo.s )

    • test resulting executable ( ./a.out or gdb ./a.out )

  • UNTIL done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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