Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for running Qiling inside of IDAPython interpreter. #1482

Merged
merged 2 commits into from
Jul 25, 2024

Conversation

xorhex
Copy link

@xorhex xorhex commented Jul 10, 2024

Fix for #1426 / #1417 / #1362. Hopefully this fix works for more than just me 🤞

Checklist

Which kind of PR do you create?

  • This PR only contains minor fixes.
  • This PR contains major feature update.
  • This PR introduces a new function/api for Qiling Framework.

Coding convention?

  • The new code conforms to Qiling Framework naming convention.
  • The imports are arranged properly.
  • Essential comments are added.
  • The reference of the new code is pointed out.

Extra tests?

  • No extra tests are needed for this PR.
  • I have added enough tests for this PR.
  • Tests will be added after some discussion and review.

Changelog?

  • This PR doesn't need to update Changelog.
  • Changelog will be updated after some proper review.
  • Changelog has been updated in my PR.

Target branch?

  • The target branch is dev branch.

One last thing


@elicn
Copy link
Member

elicn commented Jul 16, 2024

Code looks a bit cumbersome to be. Why not just use the following instead?

try:
    # ...
    sys.stdin.fileno()
    sys.stdout.fileno()
    sys.stderr.fileno()
except UnsupportedOperation:
    ...

Attempting to access the methods will raise the UnsupportedOperation exceotion without explicitly checking and raising. This is actually how the original code works.

@xorhex
Copy link
Author

xorhex commented Jul 16, 2024

Added error catching for AttributeError as UnsupportedOperation does not catch this error.

Without AttributeError being handled:

  File "/home/user/.local/lib/python3.10/site-packages/qiling/os/os.py", line 65, in __init__
    sys.stdout.fileno()
  File "/home/user/.local/lib/python3.10/site-packages/colorama/ansitowin32.py", line 29, in __getattr__
    return getattr(self.__wrapped, name)
AttributeError: 'IDAPythonStdOut' object has no attribute 'fileno'

Tested locally and this fix also works for my instance of IDA.

@elicn
Copy link
Member

elicn commented Jul 16, 2024

Thanks for the update.
Can you also test that in a regular Python interpreter? (e.g. IDLE)

@xorhex
Copy link
Author

xorhex commented Jul 18, 2024

Sorry for the delay - testing in Linux terminal window:

❯ python3 emu.py 
[=] 	Initiate stack address at 0xfffdd000 
[=] 	Loading /home/user/rootfs/x86_windows/test.exe to 0x400000
[=] 	PE entry point at 0x45e990
[=] 	TEB is at 0x6000
[=] 	PEB is at 0x61b0
[=] 	LDR is at 0x6630
[=] 	Loading ntdll.dll ...
[=] 	Done loading ntdll.dll
[=] 	Loading kernel32.dll ...
[=] 	Loading kernelbase.dll ...
[=] 	Done loading kernelbase.dll
[=] 	Done loading kernel32.dll
[=] 	Loading mscoree.dll ...
[=] 	Calling mscoree.dll DllMain at 0x10200a30
[=] 	GetSystemTimeAsFileTime(lpSystemTimeAsFileTime = 0xffffcfd8)
[=] 	GetCurrentProcessId() = 0x7cc
[=] 	GetCurrentThreadId() = 0x0
[=] 	GetTickCount() = 0x30d40
[=] 	QueryPerformanceCounter(lpPerformanceCount = 0xffffcfd0) = 0x0
[=] 	GetVersionExA(lpVersionInformation = "\x94") = 0x1
[=] 	HeapCreate(flOptions = 0, dwInitialSize = 0x1000, dwMaximumSize = 0) = 0x50006d0
[=] 	GetModuleHandleW(lpModuleName = "KERNELBASE.DLL") = 0x10000000
[=] 	GetProcAddress(hModule = 0x10000000, lpProcName = "FlsAlloc") = 0x100fbea0
[=] 	GetProcAddress(hModule = 0x10000000, lpProcName = "FlsGetValue") = 0x100e70c0

Seems to print to the console just fine.

@xorhex
Copy link
Author

xorhex commented Jul 24, 2024

Anything else needed from me? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants