Reverse Engineering an Apple Kext - Reconstructing the Class - c++

Greetings!
I am currently attempting to extend the functionality of the Magic Mouse. To do this, I am hoping to write a kext that intercepts events from the multitouch driver, AppleMultitouchDriver.kext, interprets them, and either dispatches new events or forwards the actual event. This approach is similar to the approach used by DoubleCommand.
I have already created a small test kext that intercepts the mouse events (click, motion, etc) as that will be needed also.
The problem I am having now is that I am unable to intercept the events from the AppleMultitouchDevice and/or AppleMultitouchHIDEventDriver objects because there is no class definition for them. I need to be able to reassign the pointer to the callback function as I do in the mouse interceptor and as is done in DoubleCommand. As far as I know, this means I need to reconstruct the AppleMultitouchDevice class. I already am able to get a reference to the instance of the AppleMultitouchDevice object, so I just need to be able to cast it and use it.
Now that you have the background, here are my direct questions:
What methods do I need to use in order to reverse engineer the kext or reconstruct the classes in question?
What programs are available that will assist me in this effort?
Are there any tutorials or e-books that focus on this particular topic that you know of?
Is it possible for me to reassign the callback pointer without actually reconstructing the entire class?
Anything else I may have missed as I am so very new to this.
Thanks in advance for any advice or assistance!!

Could this be of any help?
FingerMgMt

I've managed to find what I needed. Now all it will take is time and effort. :)

Related

Platformer game - Avoid collision with platform when getting down

I'm using BulletPhysics in C++.
I would like to know if there is a way to avoid collision for an object when I want?
I'm trying to create a platformer and I want my character to be able to pass through a platform (by holding down the down button). I've thought about using ray cast to manage its position but it doesn't seems for me to be a good way; it would be better if I could access the physics response and choose whether or not to apply it to my object, but I don't know if this is possible.
(If you have a solution without code it's ok for me, I'm just making some research, I haven't started development).
Thank you in advance.
I found a solution to my problem.
To be able to cross a platform (by holding down the down button), you have to know if the character is on a platform. To do this, you have to put a box (which listens to all object that collide with it) and if it collides with a platform, get a pointer of the platform and call the method void setIgnoreCollisionCheck btCollisionObject * co, bool ignoreCollisionCheck) on the character's btCollisionObject.

AFX/MFC Intercept ALL command messages

I'm attempting to use CMFCCmdUsageCounter to track command usage in my program. This class requires I call AddCmd(ID_COMMAND); every time the ID_COMMAND is handled/sent.
Since my program has thousands of ID_COMMAND's, which are handled throughout millions of lines of code...This seems unfeasible.
I'm hoping there is some simple way to intercept ALL commands sent within my program. Is it possible to override the SendMessage()/PostMessage() functions?(not even sure this would get all commands) Maybe there is some MFC function that passes every command through my virtual function, before passing it on like normal.
I'm sorry my understanding of MFC/AFX messages is limited. Any help in attempting to track ID_COMMAND usage is welcome.
Take a look at SetWidowsHookEx. In particular, I would start with the WH_GETMESSAGE type hook. A combination of hooks may give you what you need.

C++ Output: GUI or Console?

I am making an application in C++ that runs a simulation for a health club. The user simply enters the simulation data at the beginning (3 integer values) and presses run. After that there is no user input - so very simple.
After starting the simulation a lot of the logic is deep down in lower classes but a lot of them need to print simple output messages to the UI. Returning a message is not possible as objects need to print to the UI but keep working.
I was going to pass a reference to the UI object to all classes that need it but I end up passing it around quite a lot - there must be a better way.
What I really need is something that can make calling the UI's printOutput(string) function as easy (or not much more difficult) than cout << string;
The UI also has a displayConnectionStatus(bool[] connections) method.
Bear in mind the UI inherits an abstract 'UserInterface' class so simple console UIs and GUIs can be changed in and out easily.
How do you suggest I implement this link to the UI?
If I were to use a global function, how can I redirect it to call methods of the UserInterface implementation that I selected to use?
Don't be afraid of globals.
Global objects hurt encapsulation, but for a targeted solution with no concern for immediate reusability, globals are just fine.
Expose a global object that processes events from your simulation. You can then choose to print the events, send them by e-mail, render them with OpenGL or whatever you fancy. Make a uniform interface that catches what happens inside the simulation via report callbacks, and then you can subclass this global object to suit your needs.
If the object wasn't global, you'd be passing a pointer around all the codebase.
I would suggest to go for logging framework i.e. your own class LogMessages, which got functions which get data and log the data, it can be to a UI, file, over network or anything.
And each class which needs logging, can use your logging class.
This way you can avoid globals and a generic solution , also have a look at http://www.pantheios.org/ which is open source C/C++ Diagnostic Logging API library, you may use that also...

How to handle this situation (need to register functions with variable arguments)

I'm looking for suggestion on how to handle this situation as anything I've thought of thus far does not work.
I'm working on an RPG game and am currently developing the graphical system. My graphics system consists of a series of ScreenStacks which are arranged in a particular order and then drawn.
A ScreenStack is basically just a collection of related Screens, along with a unique id and a draw order.
i.e.
class ScreenStack
{
//Constructors, getters/setters etc.
private:
std::string StackName;
int DrawPriority;
int UID;
bool Valid;
bool DrawStack;
bool UpdateStack;
bool SendInputs;
bool DeleteStack;
std::vector<screen_ptr> OwnedScreens; //screen_ptr is a shared_ptr around a Screen object
};
A screen is a simple graphical layer responsible for visualizing some part of the game, for example there's a screen for showing the player inventory, party overview, party status in battle, enemy party, etc.
I have a screen manager that is responsible for storing the various functions for creating screen stacks (i.e. a function to create a battle stack will make a screen for the player party, the enemy party, the attack animation screen, the background, and the user interface). Each of the various screen stack creation functions needs a different set of paramters to construct it. What I'm doing now is manually adding in stack creation functions to the screen manager on an as needed basis. For instance, right now the screen manager has a function for creating the title screen stack, the start menu stack, the battle stack, the overworld stack, the tilemap stack etc.
This works, but is cumbersome and cluttered. What I'd like to be able to do is have files external from the screen manager be able to register stack creation functions with the screen manager and then I can just look up the screen creation function instead of having to add a new function to the screen manager for each stack I need to create.
I initially tried adding an unordered_map<std::string, StackCreationFunction> with StackCreationFunction being typedef'd as
boost::function<ScreenStack (Engine& engine, ScreenManager& manager, const std::string screenName, const int StackID, const std::vector<std::string>& TryToCopyScreens, ...)>
... was from cstdargs. The idea was that each ScreenStack would add it's own StackCreationFunction to this map. This doesn't work however as boost::function is invalid with ...
So essentially what I'm trying to do is allow external files/screens be able to register their own creation functions (that has variable arguments) with the screenmanager, and Ideally be able to do this at compile time/immediately after starting. This feels like it should be possible with the preprocessor, but I'm unsure how to do it. I'm pretty stuck here, and I really would like a better solution then adding many stack creator functions to the screen manager and cluttering it up.
Any suggestions/a better solution would be greatly appreciated, and I can provide more details if the above was not clear enough
Thanks
Each of the various screen stack creation functions needs a different set of paramters to construct it.
I think that's the problem here, and you need to think of an abstraction here to make your map work. After all, how are these extra arguments actually provided by the calling code? When the calling code knows which class is instantiated and can provide the arguments, you don't need the map. When not, the map is of no use, since you can't tell which arguments to provide to the stack creation function.
The most likely solution is to boost::bind away all arguments of your StackCreatorFunction that would normally go into the ... arguments and register this bound version of your function at the unordered map, which can be freed of the ....
I would suggest that rather than having something external register into your system think about having your system call the external entity. In this case your system would locate and load a series of plugins that have specific entry points. You will need to create your variable length argument list using some convential container; either an array or data structure.
I'm not sure if that answers your question, but if your concern is to call various functions of different signatures from an interpreter-like code, you could (under GNU/Linux at least) use the LibFFI (a library for foreign function interface) for that.

Complete example of wxwidgets custom event passing string data

I am receiving messages from the network on a non-GUI thread and need to use wxEvtHandler::AddPendingEvent to tell the GUI to update accordingly. I also need to pass data to my GUI code so that it can act apropriately.
I believe I have to create a custom event, but haven't found a straightforward implementation. This closest thing that I've found is The wxWiki on Creating a Custom Event, which is a partial example.
If you are receiving messages from a different thread, then you explicitily can not use AddPendingEvent. You must instead use wxEvtHandler::QueueEvent.
Second, there are a couple of good examples for creating custom event classes: the old way, the new way.
With the old way, you can also use the Connect method and leave off the event table, but it's not illustrated in that example. The new way has the much preferred Bind method... but as you can see in my question, I'm having my own problems with it.