a oe@sddlZddlZddlZddlZddlZddlZddlZddZdddZddZ dd Z d d Z d d Z ddZ ddZedkredS)NcCsfzttjdtj}Wntjy6tdYdS0t |d\}}tdt |f| dS)Nz(Software\Python\PythonCore\%s\PythonPathz:The remote device does not appear to have Python installedrzThe remote PythonPath is '%s') wincerapiCeRegOpenKeyExwin32conHKEY_LOCAL_MACHINEsyswinverwin32apierrorprintZCeRegQueryValueExstrClose)hpathtypr3C:\Program Files\Certbot\pkgs\win32\Demos\cerapi.pyDumpPythonRegistrysrc Csttjd}d|}d}zt||\}}}WntjyHYqnYn0td||tt |f|d}qd}zt ||\}}WntjyYqYn0td||ft||} t | |d|d}qrdS)N rz%s%s=%srz%s%s\) rrrrZCeRegEnumValuer r r reprr ZCeRegEnumKeyEx DumpRegistry) rootlevelrZ level_prefixindexnamedatarklassZsubkeyrrrrs$    rc Cs~tdtjddtjdd}t|d|tdtjddtjdd}t |ddkr`t d|t dt ddS)NZ TestPythonrzHello from Pythondz&Couldnt read the data from the device!z5Created, wrote to, read from and deleted a test file!) rZ CeCreateFilerZ GENERIC_WRITEZ OPEN_ALWAYSZ CeWriteFiler Z GENERIC_READZ OPEN_EXISTINGZ CeReadFiler Z CeDeleteFile)Zcefilerrr DemoCopyFile8s  rc Csz>tddddddddd \}}}}||tdWn<tjyz}z"|j\}}}td|WYd}~n d}~00dS)NzWindows\Python.exerz'Python is running on the remote device!z Couldnt execute remote process -)rZCeCreateProcessr r r r args)ZhpZhtZpidtidZxxx_todo_changeme1hrfnmsgrrrDemoCreateProcessKs   r%c Cst\ }}}}}}}}}|r$d}nd}|dkr6d} n|} td| |ft\} } } } }}}td| tddtdd | | ftdd ||ftdd | |ft\}}tdd ||ftd ttdtdS)NZACZbatteryunknownz?The batteries are at %s%%, and is currently being powered by %szThe memory is %d%% utilized.z%-20s%-10s%-10s)rZTotalZAvailzPhysical MemoryzVirtual Memoryz Paging filez File storezThe CE temp path isz!The system info for the device is)rZCeGetSystemPowerStatusExr ZCeGlobalMemoryStatusZCeGetStoreInformationZ CeGetTempPathZCeGetSystemInfo)Z ACLineStatusZ BatteryFlagZBatteryLifePercentZBatteryLifeTimeZBatteryFullLifeTimeZBackupBatteryFlagZBackupBatteryLifePercentZBackupBatteryLifeTimeZpowerZbatPercZmemLoadZ totalPhysZ availPhysZ totalPageZ availPageZ totalVirtZ availVirtZ storeSizeZfreeSizerrrDumpRemoteMachineStatus[sP     r(c Cs^ttjD]b\}}|dddkrz"tt|}td||fWqtjyn}z WYd}~qd}~00qtdztttj }Wn4tjy}ztd|d}WYd}~n d}~00|rZt t j |dD]z}|d}t j |t|}zt|}Wn<tjyF} z | j\} } } d| }WYd} ~ n d} ~ 00td ||fqdS) NZCSIDL_zFolder %s is at %szDumping start menu shortcuts...zThis device has no start menu!*z #Error - %sz%s->%s)listr__dict__itemsr ZCeGetSpecialFolderPathr r r ZCSIDL_STARTMENUZ CeFindFilesosrjoinZCeSHGetShortcutTargetr ) rvallocZdetailsZ startMenuZfileAttrZfileNameZfullPathZresolvedZxxx_todo_changemercr#r$rrrDumpRemoteFolderss.  r4cCs<tdtdtdtdtdtdtddS)NzOptions:z-a - Execute all demosz,-p - Execute Python process on remote devicez-r - Dump the remote registryz--f - Dump all remote special folder locationsz-s - Dont dump machine statusz)-y - Perform asynch init of CE connection)r rrrrusagesr5c Csd}}}}d}zttjddd\}}Wn8tjyj}ztd|tWYd}~dSd}~00|D]h\}} |dkrd}}}}} |dkrd}|dkrd}|dkrd}|d krd}|d krptd d}qp|rt\} } t | d } | tj kr qqtd qnt tdzt } td| d| d| df|rbtdt |rztdttj|rtdtt|rtdtrtntdWttdnttd0dS)NrrZaprzInvalid usage:z-az-pz-rz-sz-fz-yz"Doing asynch init of CE connectionizCWaiting for Initialize to complete (picture a Cancel button here :)zConnected to remote CE device.z3The device is running windows CE version %d.%d - %szDumping remote machine statuszDumping remote registry...z!Dumping remote folder informationzStarting remote Python processz1Not trying to start Python, as it's not installedZ Disconnected)getoptrargvr r r5rZ CeRapiInitEx win32eventZWaitForSingleObjectZ WAIT_OBJECT_0Z CeRapiInitZCeGetVersionExr(rrrr4rrr%Z CeRapiUninit)Z async_initZ bStartPythonZ bDumpRegistryZ bDumpFoldersZ bDumpStatusZoptsr whyovZ asynch_initZeventr3Zverinforrrmainst        r=__main__)r)r7r/rr rr9rrrrr%r(r4r5r=__name__rrrrs  0! G