import clrThe RunMeCallBack function starts the tested application the same way as we showed in the previous part. We create an independent thread and run this function in it so it does not block the console. The thread finishes its work when the tested application terminates (the main form of the application is closed) or when the console is closed.
from System import *
from System.Reflection import *
from System.Threading import *
from System.Windows.Forms import Application
from time import sleep
asm = Assembly.LoadFrom('GUIAT_PoC.exe')
asm_type = asm.GetType('GUIAT_PoC.frmGUIAT')
App = Activator.CreateInstance(asm_type)
App = None
while not App:
The important part is line
App = Activator.CreateInstance(asm_type)Here we remember the instance of the main form in the variable App. We have access to the whole application thanks to the App variable! The while cycle at the end ensures waiting until the App variable is not None. Which only happens when our tested application is up and running.
The App variable is our Holy Grail. Let's explore what is inside:
>>> AppBasically, we have access to all public properties and methods. Try dir(App) and you'll see. With a trick, we can even access private properties and methods (using the power of reflection).
<GUIAT_PoC.frmGUIAT object at 0x000000000000002B
[GUIAT_PoC.frmGUIAT, Text: GUIAT - Proof of Concept]>
'GUIAT - Proof of Concept'
To find what components are on the main form, iterate through the Controls collection:
>>> for c in App.Controls:To find out what text is in the text box, try the following:
... print c.Name, c.GetType()
>>> App.Controls.TextNow, write something directly into the text box in the tested application and call the statement again:
>>> App.Controls.TextCool, isn't it? ;-)
Next time, I show you how to simulate user interaction programatically - how to send a text or click to the tested application.