PDA

View Full Version : [DEBUG] Debug or reverse engineering a QListView or QListBox



flaab
29th September 2010, 14:51
Hello :-)

I'll be straighforward: A third party application for Mac OS X is programmed with carbon + qt3, and it uses a QListBox -maybe a QListView I don't know for sure, "nm" shows both of them- to display text information in rows.

PROBLEM
---------
I want to log every row added to the QListView or QListBox in a file. For that, I have three options:


OPTIONS
-----------
1) Use any QT debug tool that might help me to do achieve this. Is there any?

2) Inject C++ code into te application, using class interposing or method swizzling with DYLD dynamic linking.

I have already achieve this, being able to intercept standard C++ functions that helped me to get a clear picture of the workarounds of the application, like open(), close(), malloc() and string related functions.

My question is, what should I interpose?

- Is there any simple C++ function QString uses to build itself? This would be the best solution because it's low level and no class-interposing is needed. Maybe concatenation functions would be effective as well: the messages I want to intercept are built with concatenation for sure because all of them have the same structure: "Dealer: <message>" ;)

Regarding QString, I am ready to incercept any function that does not belong to any class. I am browsing QString.h and it uses many functions that are declared outside of the class, like real_detach() and operatorPlusEqHelper(), inserhelper(), etc. Any ideas on this path oriented towards seeing all processed strings would be welcomed. The base for QString is http://doc.qt.nokia.com/qtopia1.6/html/qcstring-h.html and standard C++ string.h functions are used. That seems a good place to start.

- I am browsing QListView documentation and can't find any addRow or insertRow methods. I do find it in QListBox: if this were the case, I should override QListBox::inserItem(). If not, QListViewItem would be the center of my attention. Which one do you think is it?

3) Another option would be to recompile completely the QT bundle the application uses from source code, adding my own changes. This is huge and effective but if they added their own touch, it won't work.


REASONS
---------
I have built a Poker Engine and I want it to retrieve information from the board to guide my playing: the future of it would be creating a bot. The application I want to debug is the following:

5251

The chat window in the lower-left displays ALL the information my poker bot needs to work. And it's a QListview or QListBox. The players and actions, folds, bets, my cards, the flop, everything I need is displayed there. I want to log all that activity to a file and make my application parse it to get a clear picture of the game.

Would you think it is a QListBox or QListView?

Thanks in advace for your answers!

tbscope
29th September 2010, 16:43
You naughty boy!
You want to cheat in poker rooms :-)
And get some quick cash :-)

Learn about application hooks. You'll have to do some disassembly to get the correct address of a statement or function, but once you get that, you can just hook into it. A lot of debuggers use a similar technique.

Or... on MacOs you have this wonderfull toy called DTrace. Learn about it. It can do magic beyond your wildest dreams.

Now, on to reporting you to FTP.

flaab
29th September 2010, 16:52
Thank you for answering. I am more from linux and use strace. Dtrace would do. Any nice man to point me to? I am exploring QString inheritance and that seems extremely doable :P

tbscope
29th September 2010, 16:55
Well, on linux use Systemtap.
It has a very high learning curve but it can do magic at almost no speed loss. Just run your program and in the background trace it though systemtap. Write a little script to send new list items, via a local tcp socket to your own program. You still need a hook into the event queue to actual control the program.

Edit: I think these are enough tips.

flaab
30th September 2010, 10:31
It's going to be easier than I thought. QString uses memcpy for almost all concatenation processes, insert and append. I have averriden memcpy with my patch and applying a suitable regex to find out only the strings I want I have it solved :P