I want to retrieve a GUI Object so that I can read and modify they Object.
Right now the only way I can think of to do this is via injection (where the injection does a lot of the retrieving of the data and sends back what I want). My problem with injection is that I cannot easily debug it and it takes a long time to figure out what to do.
I can find the handle of the GUI object so is there a way i can use ReadProcessMemory() or something like this so that I can read the memory in another process and from this build it up into the GUI object that I want?
Assuming you have the proper permissions and have some way to obtain the window handle (HWND) of a specific GUI object (see FindWindow()), you can call regular Win32 API functions such as SetWindowText() to modify the contents of those GUI objects.
However, doing this can break the other process' logic! If the process that owns the GUI object has cached some information and you modify the source behind its back, you might not get the desired effect.
Related
I have a c++ exe program I do not own the source and I want to access some data which is in the ListView. Is there any way to do this?
(My best guess is using memory address but how to know the format of ListView)
Image of the program
You can access ListView data by sending LVM_ messages to it if it owns data.
Or if ListView is virtual, data is provided by LVN_ notifications by its parent window. Either way, you need to be in exe's address space, so you would have to inject own code (which can be achived by making that exe load your DLL, can be done by windows hooks or by CreateRemoteThread).
So, generally it is possible, but cumbersome.
I have a Windows service written in C++ that needs to access the clipboard and read data from/paste data to it. I'm considering only textual data.
From MSDN's documentation, I can use OpenClipboard, EmptyClipboard and SetClipboardData to achieve what I want to.
I would have to pass NULL to OpenClipboard since I don't have any UI and hence no window handles. However, this would mean -
If an application calls OpenClipboard with hwnd set to NULL, EmptyClipboard sets the clipboard owner to NULL; this causes SetClipboardData to fail.
which would mean I can't set data on the clipboard.
What would be the correct way to get around this problem? Is it possible without using any windows?
You definitely CAN access the clipboard from a non-GUI application. Windows even included a command-line app (clip.exe) to do it.
However, before you spend too much time working on this......
The clipboard isn't shared among users on the same system. Suppose you have two users logged in. You can't copy data from one session, switch users (from the lock screen) and paste that same data.
So presumably, your service would act like another user session, and your app would only be able to see data that was copied earlier within that same instance of the service.
I have some native code and want to update the progressbar from the native code. There isn't no return value because it is a long duration task.
I found a small example http://developer.android.com/reference/android/widget/ProgressBar.html but when I move the update part in a extra method I get a NullPointerException.
It seems that this part must be in the thread of the progressbar.
I tried another way by using the AsyncTask as nested class, but I haven't access on the method publishProgress from anywhere outside the class itself.
Is there any possibility to get it working?
If it is possible to break your long task into multiple incremental calls then I'd recommend doing that. Then you can make those calls from a loop inside AsyncTask.doInBackground(), just like in the SDK examples.
If that's not possible, you'll need a progress variable in your native code that can safely be accessed from multiple threads: Write to it from your worker code and read it from a new "getProgress()" JNI function, with the appropriate synchronisation done in native code. You would then be able to call your getProgress() function from AsyncTask.doInBackground(), or whatever UI scheme you choose to use.
Is there a way (in C++ & windows XP) to detect if one process spawns any other processes?
for example,
write.exe in system32 spawns wordpad.exe then disappears, is there a function that tells me if the process is about to do this?
for those interested i solved the problem using this section of msdn:
http://msdn.microsoft.com/en-us/library/aa390425(v=VS.85).aspx
Nothing in the Win32 API for this. However, it is supported through WMI with the Win32_ProcessStartTrace query. You'll find some C# code that demonstrates the query in my answer in this thread. Writing WMI code in C++ is fairly painful, you'll find a link to boilerplate code you have to write in the MSDN Library article.
Do beware that this isn't particularly fast. It isn't clear to me how much help the WMI provider gets from the kernel to generate the notification but given the speed it quacks like polling. In other words, the process is likely to be well on its way by the time you get the notification. This is otherwise par for the course on a multitasking operating system.
You can enumerate over the process tree, which identifies running processes and their parents. This is the inverse of what you want (you want to identify child processes, not parent processes). But of course by keeping track of parent process IDs while enumerating, you can identify which sub-processes a given process has spawned.
To do this, call CreateToolhelp32Snapshot and then use Process32First and Process32Next to enumerate the processes. The enumeration will fill in a PROCESSENTRY32 struct that contains a th32ParentProcessID member.
This is a polling method; there may be another way of actually hooking the CreateProcess function, but I don’t have any information about that.
I think you would need to make a global hook DLL that attaches itself to every running process. DLL then finds a place where a function call to CreateProcess is mapped to actual CreateProcess from kernel32, and change a table entry to redirect the call to it's own code to "detect" the call to CreateProcess. All this assuming that some user firewall will not prevent your global hook from executing.
What's the approved way to handle second, third, etc launches of application in Windows (C++) application? I need the running (first) instance to take some special action (pop up a dialog) in this case, but for the secondary instances to terminate.
On Mac, AppleEvents sends you a 're-open' message in this scenario. Mozilla on Windows uses DDE to check for an existing instance and pass the command line through. It feels like a pretty nasty solution, all the same.
The windows way is to open a named mutex and, if you can acquire it, it means you're the first instance, if not, there is another one. At this point you can register a windows message (the function is literally RegisterWindowsMessage) which gives you a WM_ msg you can send to all windows and only your app would know to catch it, which allows you to tell your initial copy to open a dialog box or w/e.
How to limit 32-bit applications to one instance in Visual C++
"The method that is used in this article is the one that is described in MSDN under the WinMain topic. It uses the CreateMutex function to create a named mutex that can be checked across processes. Instead of duplicating the same code for every application that you will use as a single instance, the code that you must have is in a C++ wrapper class that you can reuse across each application."
SendMessage Function
"Sends the specified message to a window or windows. The SendMessage function calls the window procedure for the specified window and does not return until the window procedure has processed the message."
"Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a unique message for inter-application communication."
RegisterWindowMessage
"The RegisterWindowMessage function defines a new window message that is guaranteed to be unique throughout the system. The message value can be used when sending or posting messages."
On windows there is not really solution for that at least not out of the box.
You can use mutex to do such things, basically the app check for the mutex at startup create it if it doesn't exist.
There is one issue with CreateMutex method that you might need to consider - the named mutex might have been created by a third party. Now, most of the time, this won't be an issue, there would be no reason for someone else to block your application. However, if you're making a program that does something important, it may be an issue. Consider, if your program was a virus scanner, a virus could disable it by creating the mutex.
Usually, CreateMutex should do the job, but you should be aware of the limits of this method.