Currently I'm doing the following for analysing a memory leak:
- I open both dumps, using Windbg.
- I launch heap_stat script, a Python-based script for making a summary of the objects, used in the heap.
- I copy the results of both heap_stat scripts, and paste them in an Excel sheet, where the results are analysed.
I'd like to automate this, starting from the final Excel sheet, using VBA, as follows:
- Start two instances of an external program (
Windbg.exe
) and open both dumps with them. - In those
Windbg
instances, launch the necessary commands (.load pykd.pykd
, followed by.py heap_stat.py -stat
). - Wait for the
heap_stat.py
script to finish, and copy the result to the Excel sheet. - Add some necessary
Match()
worksheet functions and Excel formulas for completing the analysis.
In order to do this, I need to be able to:
- Launch an external program from VBA. This can be done, using the
Shell
command. - Within that external program, launch two other commands. (Launching one command is easy, as explained here, but what about two?) In case this is not possible:
Windbg
allows concatenating commands, using a semi-colon, so that can be skipped. In order to perform this, I'm thinking about the trick, explained in mentioned URL. - Wait for everything to be finished. This can be done using this link.
- Read the output.
My issue is : is it possible to read the output? I know it is possible to wait for a command to finish, to verify if the result is ok or if there is an error, but I don't find a way to read the actual output, thrown by the command.
Does anybody know if this is (easily) feasible?
If you want to use pykd for fully automatic tasks, why you need to run it inside windbg? You can make a standalone python script.
I've found following solution to my problem:
- I'll adapt my heap_stat script, at the end it'll create an empty (flag) file.
I'll windbg from Excel VBA as follows:
Shell "windbg -z ""C:\Directory\Dumpfile.dmp"" -c "".load pykd.pyd;.logopen C:\Directory\output.txt;!py heap_stat.py -stat""", vbMaximizedFocus
The meaning of the Windbg commands is the following:
.load pykd.pyd // load PYKD library .logopen ... // open a logfile, for all Windbg output (thanks, Zac and Tate, for the idea) !py heap_stat.py -stat // launch the heap_stat script
- I'll write a
while
-loop, verifying for the presence of the flag file. - The output file's content will be copied to the Excel file, which will do the analysis.
来源:https://stackoverflow.com/questions/54292846/starting-from-excel-vba-launch-an-external-interactive-program-and-in-there