Closed OevreFlataeker closed 4 years ago
I believe IDA sets __name__
to its own custom thing. Can you let us know what __name__
contains?
Hm, if I am not mistaken... name gives "builtins" in the VS Code Terminal when breaking on that line...
Interesting! Well, it's not really an issue specific to IDACode so a possible fix would be to just not deal with if __name__ == ...
source lines or the other would be to override the global to __main__
. Not sure which "fix" would suit best in this scenario.
idaapi.IDAPython_ExecScript called python's execfile, which just load all code into current context, so __builtin__
is returned instead of __main__
, detail information is listed here: https://stackoverflow.com/questions/711066/calling-execfile-in-custom-namespace-executes-code-in-builtin-namespace
And it means it is something that would need a change in IDA or how IDA calls the script, correct? Like the last post said: Use import() instead of execfile()
I would assume that setting __name__
when passing the globals into execute_sync
should fix the issue, I will give that a shot.
I can confirm this does indeed work and doesn't cause any unexpected issues.
I introduced __name__
as __main__
in the following commit: https://github.com/ioncodes/idacode/commit/6c01131296e0ca2c20224d2978750b077a3b007c. A new version will be published in the next hour.
That's awesome! Thanks!
If the python script to debug contains something like
the script will not run correctly. To fix, remove the "if" line and just directly call main().