Charles Sheehe
Charles Sheehe

Reputation: 11

Is there a way to close a .py file directly after running the script instead of after detaching when using pykd in windbg?

Sorry for all the questions but I think I have narrowed down my issue. In the below code, I call the following script via pykd in windbg. For the most part, it behaves as intended. However, after I call the script a few hundred times (504 times), the script stops executing until I detach and re-attach. In an attempt to find out the problem, I set up Process Monitor and watched Windbg. After I detached windbg from the process, Process Monitor showed that 504 files were closed and they were all the python script. I believe pykd might not be closing the process after finishing the script. Would anyone have any information in windbg or pykd to close the python file as soon as it completes instead of keeping it open?

Any information you could provide would be appreciated!

Process Monitor Screenshot


import sys
import pykd
from re import findall # pattern matches strings


bp_dict = {
'BaseGameStops':' 9 477 77 18 14 ',
'MysteryRandomReplacementBGWildStateReplacement_weightReels_Main':' 170428 ',
'ThemeGame_Credit_Wild_Spin_0_Reel_2_StripNdx_18_Cascade_-1':' 0 ',
'ThemeGame_Credit_Wild_Spin_0_Reel_1_StripNdx_17_Cascade_-1':' 702 ',
'MysteryRandomReplacementBGWAP_MysteryReplacement_3_weightReels_Main':' 196874 ',
'ThemeFSMoolahWildCreditAward_Credit_Wild_Spin_508_Reel_1_StripNdx_15_Cascade_-1':' 10646 ',
'ThemeFSMoolahWildCreditAward_Credit_Wild_Spin_508_Reel_1_StripNdx_16_Cascade_-1':' 10490 ',
'ThemeFSMoolahWildCreditAward_Credit_Wild_Spin_508_Reel_1_StripNdx_17_Cascade_-1':' 10629 ',
'ThemeFSMoolahWildCreditAward_Credit_Wild_Spin_508_Reel_1_StripNdx_18_Cascade_-1':' 10676 ',
'ThemeFSMoolahWildCreditAward_Credit_Wild_Spin_508_Reel_1_StripNdx_19_Cascade_-1':' 10667 ',
'MysteryPay':' 2268637 ',  }

pykd.dbgCommand("r @$t4=${t7_alias}")
pykd.dbgCommand("as /mu ${/v:stringInstanceName} poi(@$t2+@$t4)+0x10;")
breakpoint = pykd.dbgCommand(".echo stringInstanceName").strip()

try:
    print(pykd.dbgCommand(f'$$>a< c:\emulations\ProcessRNGsToSet.txt{bp_dict[breakpoint]}'))
except KeyError:
    potential_breakpoints = [identifier for identifier in bp_dict if any(symbol in identifier for symbol in ['*', '?']) and findall(identifier.replace('*', '\S*').replace('?', '\S'), breakpoint)]
    if len(potential_breakpoints) == 0:
        print(f'Missed Breakpoint: {breakpoint}')
        # save to missed breakpoints file
    elif len(potential_breakpoints) == 1:
        print(pykd.dbgCommand(f'$$>a< c:\emulations\ProcessRNGsToSet.txt{bp_dict[potential_breakpoints[0]]}'))
    else:
        print(f'Multiple given wildcard breakpoints match the current breakpoint: {breakpoint}')
except Exception as e:
    print(f'Unexpected error: {e}')

sys.exit()

The version number of my pykd.pyd is 0.3.4.15

Upvotes: 1

Views: 115

Answers (0)

Related Questions