a „oeïã@sŒddlZddlZddlZddlZddlZddlZddlZdd„Zddd„Zdd„Z dd „Z d d „Z d d „Z dd„Z dd„ZedkrˆeƒdS)éNcCsfzt tjdtj¡}Wntjy6tdƒYdS0t  |d¡\}}tdt |ƒfƒ|  ¡dS)Nz(Software\Python\PythonCore\%s\PythonPathz:The remote device does not appear to have Python installedrzThe remote PythonPath is '%s'é) Ú wincerapiÚCeRegOpenKeyExÚwin32conÚHKEY_LOCAL_MACHINEÚsysÚwinverÚwin32apiÚerrorÚprintZCeRegQueryValueExÚstrÚClose)ÚhÚpathÚtyp©rú3C:\Program Files\Certbot\pkgs\win32\Demos\cerapi.pyÚDumpPythonRegistrysþrc CsØt tjd¡}d|}d}zt ||¡\}}}WntjyHYqnYn0td||tt |ƒƒfƒ|d}qd}zt  ||¡\}}WntjyžYqÔYn0td||fƒt ||¡} t | |dƒ|d}qrdS)Nú rz%s%s=%srz%s%s\) rrrrZCeRegEnumValuer r r Úreprr ZCeRegEnumKeyExÚ DumpRegistry) ÚrootÚlevelrZ level_prefixÚindexÚnameÚdatarÚklassZsubkeyrrrrs$    rc Cs~t dtjddtjdd¡}t |d¡| ¡t dtjddtjdd¡}t  |d¡dkr`t dƒ| ¡t  d¡t dƒdS)NZ TestPythonrzHello from Pythonédz&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 Cs€z>t ddddddddd¡ \}}}}| ¡| ¡tdƒWn<tjyz}z"|j\}}}td|ƒWYd}~n d}~00dS)NzWindows\Python.exeÚrz'Python is running on the remote device!z Couldnt execute remote process -)rZCeCreateProcessr r r r Úargs)ZhpZhtZpidÚtidZxxx_todo_changeme1ÚhrÚfnÚmsgrrrÚDemoCreateProcessKsÿ   r%c Csìt ¡\ }}}}}}}}}|r$d}nd}|dkr6d} n|} td| |fƒt ¡\} } } } }}}td| ƒtddƒtdd | | fƒtdd ||fƒtdd | |fƒt ¡\}}tdd ||fƒtd t ¡ƒtdt ¡ƒdS)NZACZbatteryéÿÚunknownz?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 storeSizeZfreeSizerrrÚDumpRemoteMachineStatus[sP öÿÿ ø   r(c Cs^ttj ¡ƒD]b\}}|dd…dkrz"tt |¡ƒ}td||fƒWqtjyn}z WYd}~qd}~00qtdƒztt tj ¡ƒ}Wn4tjyÂ}ztd|ƒd}WYd}~n d}~00|�rZt  t j   |d¡¡D]z}|d}t j   |t|ƒ¡}zt |¡}Wn<tj�yF} z | j\} } } d| }WYd} ~ n d} ~ 00td ||fƒqÞdS) NéZCSIDL_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 CeFindFilesÚosrÚjoinZCeSHGetShortcutTargetr ) rÚvalÚlocZdetailsZ startMenuZfileAttrZfileNameZfullPathZresolvedZxxx_todo_changemeÚrcr#r$rrrÚDumpRemoteFolders‹s.  r4cCs<tdƒtdƒtdƒtdƒtdƒtdƒtdƒdS)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 rrrrÚusage¬sr5c Csäd}}}}d}zt tjdd…d¡\}}Wn8tjyj}ztd|ƒtƒWYd}~dSd}~00|D]h\}} |dkr”d}}}}} |dkr d}|dkr¬d}|dkr¸d}|d krÄd}|d krptd ƒd}qp|�rt ¡\} } t  | d ¡} | tj k�r �qqìtd ƒqìnt  ¡tdƒz¦t  ¡} td| d| d| dfƒ|�rbtdƒt ƒ|�rztdƒttjƒ|�rŽtdƒtƒtƒ|�rºtdƒtƒ�r²tƒntdƒWt ¡tdƒnt ¡tdƒ0dS)NrrZaprzInvalid usage:z-az-pz-rz-sz-fz-yz"Doing asynch init of CE connectioniôzCWaiting for Initialize to complete (picture a Cancel button here :)zConnected to remote CE device.z3The device is running windows CE version %d.%d - %sézDumping remote machine statuszDumping remote registry...z!Dumping remote folder informationzStarting remote Python processz1Not trying to start Python, as it's not installedZ Disconnected)ÚgetoptrÚargvr r r5rZ CeRapiInitExÚ win32eventZWaitForSingleObjectZ WAIT_OBJECT_0Z CeRapiInitZCeGetVersionExr(rrrr4rrr%Z CeRapiUninit)Z async_initZ bStartPythonZ bDumpRegistryZ bDumpFoldersZ bDumpStatusZoptsr ÚwhyÚoÚvZ asynch_initZeventr3ZverinforrrÚmain¶st     ÿÿÿ   ÿr=Ú__main__)r)r7r/rr rr9rrrrr%r(r4r5r=Ú__name__rrrrÚs  0! G