
import clr
import sys
import os
import System
from System import AppDomain

def inspect_dll(dll_path):
    filename = os.path.basename(dll_path)
    print(f"Inspecting: {filename}")
    
    if not os.path.exists(dll_path):
        print("  File not found.")
        return

    try:
        # Load the assembly
        try:
            ref = clr.AddReference(dll_path)
            print(f"  Loaded Assembly: {ref.FullName}")
        except Exception as e:
            print(f"  Failed to AddReference: {e}")
            return
        
        assembly = None
        for a in AppDomain.CurrentDomain.GetAssemblies():
             if a.FullName == ref.FullName:
                 assembly = a
                 break
        
        if not assembly:
            # Try finding by name match if FullName doesn't match exactly
            for a in AppDomain.CurrentDomain.GetAssemblies():
                if filename.replace(".dll", "") in a.FullName:
                    assembly = a
                    print(f"  Found assembly by partial name: {a.FullName}")
                    break
        
        if not assembly:
            print("  Could not find assembly in AppDomain.")
            return

        print("  Scanning types...")
        target_keywords = ["Engine", "Client", "Connection", "Session", "Plugin", "Rithmic", "Omne", "RApi", "Login", "Connect"]
        
        found_count = 0
        for t in assembly.GetTypes():
            if not t.IsPublic:
                continue
                
            name_match = False
            for kw in target_keywords:
                if kw.lower() in t.Name.lower():
                    name_match = True
                    break
            
            if name_match:
                print(f"    [Type] {t.FullName}")
                found_count += 1
                
                # Check for Login/Connect methods
                try:
                    methods = t.GetMethods()
                    for m in methods:
                        if m.Name in ["Login", "Connect", "Initialize", "Start"]:
                            params = [p.ParameterType.Name for p in m.GetParameters()]
                            print(f"      -> Method: {m.Name}({', '.join(params)})")
                except:
                    pass
        
        if found_count == 0:
            print("  No interesting types found.")

    except Exception as e:
        print(f"  Error inspecting DLL: {e}")
    
    print("-" * 30)

if __name__ == "__main__":
    # Rithmic DLL Directory
    dll_dir = r"C:\Program Files (x86)\Rithmic\Rithmic Trader Pro"
    sys.path.append(dll_dir)
    
    # List of likely DLLs
    targets = [
        "RithmicPlugin.dll", 
        "OmneStreamEngine.dll", 
        "OmneChannel.dll", 
        "OmneVerse.dll",
        "OmneBook.dll"
    ]
    
    for t in targets:
        inspect_dll(os.path.join(dll_dir, t))
