Création de l'éditeur JaCarta

«Je ne peux dire qu'une chose au sujet du Royaume des Ombres: il y a la réalité et il y a son Ombre; c'est l'essence de tout. Dans le monde réel, il n'y a qu'Ambre, la vraie ville sur la vraie Terre, dans laquelle tout est collecté. Et le Royaume des Ombres n'est que l'infinité de l'irréalité. Ici, vous pouvez également tout trouver - mais ce seront des ombres, un reflet déformé de la réalité. Le royaume des ombres entoure l'ambre de tous les côtés. Et au-delà, le chaos règne. Tout est possible sur le chemin de l'ambre au royaume du chaos. »
Roger Zhelyazny. Les neuf princes d'ambre


Tout a commencé avec la nécessité de travailler avec la même clé sur etoken à partir de postes de travail différents et sensiblement distants (USB sur IP sera un peu cher pour quelques jetons) et mon grand désir d'ouvrir ce monde fermé. Je suis tombé sur l' oeuvre habr.com/post/276057 pour laquelle son auteur a beaucoup de respect, dans mon projet une partie importante des fonctions qu'il a inversées a été utilisée (le code est ouvert). Certes, il s'est avéré que tout ce qui fonctionne avec etsdk.dll ne fonctionne qu'avec du poisson bleu. Par conséquent, pour JaCarta, de nouvelles fonctions ont dû être réécrites et certaines d'entre elles ont dû être modifiées.

À la suite de longues recherches, l'éditeur JaCarta est apparu - un programme qui montre et vous permet de modifier des entités (c'est ainsi que les objets du système de fichiers de jetons sont appelés dans la documentation officielle, faisant apparemment allusion à leur éphéméralité et irréalité) sur les jetons d'Aladdin, y compris les plus modernes.

Une application similaire pour Rutoken est accessible au public dans le cadre du Rutoken SDK (Rutoken Editor), mais pour Aladdin, au moins, elle n'est pas dans le domaine public, bien qu'il y a environ 15 ans, à en juger par la documentation trouvée sur Internet, elle l'était (ETEditor).

Le programme est écrit en Autoit, testé avec EToken PRO Java 72 K, JaCarta LT, JaCarta Pro, JaCarta GOST-2.

Le programme ne fonctionnera pas si les pilotes Rutoken sont installés sur l'ordinateur (il est nécessaire que EToken ou Ja Carta aient un numéro de lecteur 0).

Pour la même raison, un seul jeton doit être connecté pour un fonctionnement correct.

Le script utilise des appels système Window $ et n'a été testé qu'avec cette famille de systèmes d'exploitation.

Pour fonctionner, vous devez installer le «Client unique JaCarta» (téléchargement gratuit sur le site Web du fabricant), lorsque vous l'installez, la version sensiblement plus récente de etsdk.dll et jcFS.dll contenant les fonctions du système de fichiers JaCarta (très similaire à ceux dans etsdk.dll, mais dans jcFS il y a beaucoup plus de fonctions sans lesquelles travailler avec certains jakarts modernes, comme GOST-2, sera impossible). Avec le client unifié installé, il n'est naturellement pas nécessaire de rechercher et de placer cette DLL dans le dossier avec le programme, sinon, avec le pilote installé pour un type spécifique de jeton, cette DLL doit être dans le dossier du programme.

Toutes les fonctions jcFS sont décrites en détail sur le site Web du fabricant, mais néanmoins, certains paramètres de ces fonctions ont dû être sélectionnés expérimentalement.

Pour accéder au répertoire racine du jeton, vous devez appeler la fonction ETRootDirOpen ou JCRootDirOpen (qui est la même, car la première de la DLL appelle la seconde, cela est vrai pour presque toutes les fonctions, mais il y a quelques exceptions) avec l'identifiant du fournisseur égal à 0 (les constantes comme 0xF007 permettront voir uniquement les répertoires individuels de la plupart des anciens eToken qui stockent les clés bancaires générées à l'aide d'utilitaires tels que PKIAdmin et MessagePRO).

La prochaine caractéristique importante de jakarta moderne est la nécessité de connaître l'id de l'applet qui est installée sur le jeton, la fonction JCSelectApplet en est responsable.

Les jetons plus anciens ont généralement une applet par défaut et l'appel de cette fonction n'est pas spécifiquement requis, mais pour les jakarts nouveaux et relativement nouveaux sans connaître l'ID de l'applet, un travail supplémentaire devient impossible. L'appel de toutes les fonctions recevant des informations du jeton dans ce cas renvoie False. Dans mon projet, dans ce cas, une force brute en deux étapes est implémentée (le jeton répond toujours à deux identifiants, mais un seul fonctionne) id et fonctionne ensuite avec la valeur souhaitée.

Toutes les informations sont affichées dans la fenêtre de sortie située sous l'arborescence de répertoires.
Le code PIN a été saisi, des informations sur les tentatives restantes de saisie sont également affichées.
Le contenu des répertoires et de brèves informations sur les fichiers sont affichés: le nom, si le fichier est privé, les informations sont un code PIN privé - la lettre p: (le fichier est public après lui, l'unité est privée) et la taille du fichier en octets après «s:». Le fichier est ouvert en double-cliquant.

Vous pouvez afficher et, si nécessaire, copier le contenu des fichiers de jeton dans le tampon au format hexadécimal ou l'enregistrer sous forme binaire sur un ordinateur.

Vous pouvez également modifier le contenu du fichier et sélectionner «Enregistrer les modifications» dans le menu (le code PIN doit être saisi en premier, s'il n'a pas été saisi, un message approprié s'affiche, auquel cas les données modifiées peuvent être sélectionnées et copiées dans le presse-papiers).

Pour supprimer un fichier, sélectionnez-le et cliquez sur "Supprimer", après quoi une fenêtre de confirmation apparaîtra.

JaCarta File System a une fonctionnalité intéressante, qui est présente sur tous les jetons que j'ai testés. Si vous créez un répertoire ou plusieurs répertoires sans fichiers sur le jeton, lors de la prochaine session de travail avec le jeton, ils disparaîtront, apparemment de cette façon, le système de fichiers se charge de sauvegarder la mémoire du jeton et nettoie toutes les ordures.

Par conséquent, lorsque vous cliquez sur le bouton Créer dans le programme, une chaîne est créée immédiatement à partir d'un répertoire ou de deux répertoires et d'un fichier. La profondeur d'imbrication des répertoires dans le programme est de deux, sans compter la racine. Dans le répertoire racine, vous ne pouvez créer que des répertoires, mais pas des fichiers.
Avant de créer, de modifier ou de supprimer des entités, vous devez saisir un code PIN.

Une note très importante sur les noms de répertoire!

Sur les jetons dont le contenu est créé par le fabricant, vous ne verrez jamais les répertoires du même nom, où qu'ils se trouvent. Cela est dû aux fonctionnalités du système de fichiers.

Supposons que nous ayons l'entité suivante sur le jeton: // 0001 / A001 / 0008 (c'est-à-dire que le dossier 0001 est dans le répertoire racine, le dossier A001 est dedans et le fichier 0008 est dedans) et nous créons une nouvelle entité sur le jeton: // CC00 / 0001/1010 . Lors de l'accès au fichier 1010, la recherche du répertoire 0001 commencera, qui se trouve à la racine et sera trouvée en premier, mais il n'y a pas un tel fichier dedans. Par conséquent, la fonction renvoie False et l'entité est perdue; vous ne pouvez pas non plus y accéder ni la supprimer. Seule l'initialisation du jeton sera utile.

À noter en particulier EToken PRO et JA Carta Pro, qui ne diffèrent que par leur apparence, ils ont des fichiers système dans le répertoire racine (ils sont affichés à l'écran), dans l'un desquels le hachage du code PIN est stocké, en changeant ces fichiers. au fait que l'autorisation devient impossible (le code PIN devient incorrect) et après cela, seule l'initialisation sera utile.

En ce qui concerne les clés privées, il a été possible d'établir ce qui suit: si un conteneur créé par un fournisseur de cryptographie tiers, tel que CryptoPro, est stocké sur le jeton, alors tout son contenu, y compris les clés privées, sera disponible, il s'agit simplement d'un lecteur flash avec un code PIN (comme indiqué dans l'image). Si la paire de clés a été générée à bord du jeton à l'aide de PKCS11, seuls le certificat et la clé publique seront disponibles.

Comme il s'agit d'un programme expérimental, je ne recommande pas de l'utiliser avec des jetons contenant des clés EDS valides, toutes les opérations sont effectuées à la peur et au risque de l'expérimentateur. Cela est particulièrement vrai pour la création de nouvelles entités, dans certains cas, le résultat est difficile à prévoir.

Toutes les informations pour la création du programme ont été obtenues à partir de sources ouvertes, le but de sa création est purement de recherche.

Le script lui-même

JACartaEditor.au3
#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <TreeViewConstants.au3> #include <GuiTreeView.au3> #include <GuiMenu.au3> #include <MsgBoxConstants.au3> #include <StaticConstants.au3> #include <GuiButton.au3> #NoTrayIcon ;  jcFS.dll Dim $ETSdkDll=DllOpen('jcFS.dll') Func ETTokenLock($BindId) Local $CallRes=DllCall($ETSdkDll,'WORD','ETTokenLock', _ 'DWORD',$BindId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func ETTokenUnLock($BindId) Local $CallRes=DllCall($ETSdkDll,'WORD','ETTokenUnLock', _ 'DWORD',$BindId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func ETReadersEnumOpen() Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','ETReadersEnumOpen', _ 'PTR',DllStructGetPtr($Out) _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func ETReadersEnumNext($EnumId) Local $Reader=DllStructCreate('CHAR name[260]; BYTE etoken;') Local $CallRes=DllCall($ETSdkDll,'WORD','ETReadersEnumNext', _ 'DWORD',$EnumId, _ 'PTR',DllStructGetPtr($Reader) _ ) Local $Result[2]=[ DllStructGetData($reader,'name'), _ DllStructGetData($reader,'etoken')] Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :$Result EndFunc Func ETReadersEnumClose($EnumId) Local $CallRes=DllCall($ETSdkDll,'WORD','ETReadersEnumClose', _ 'DWORD',$EnumId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func ETTokenBind($ReaderName) Local $In=DllStructCreate('BYTE['&(StringLen($ReaderName)+1)&']') Local $Out=DllStructCreate('DWORD') DllStructSetData($In,1,$ReaderName) Local $CallRes=DllCall($ETSdkDll,'WORD','ETTokenBind', _ 'PTR',DllStructGetPtr($Out), _ 'PTR',DllStructGetPtr($In) _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func ETTokenRebind($BindId) Local $CallRes=DllCall($ETSdkDll,'WORD','ETTokenRebind', _ 'DWORD',$BindId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func ETTokenUnbind($BindId) Local $CallRes=DllCall($ETSdkDll,'WORD','ETTokenUnbind', _ 'DWORD',$BindId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func ETTokenLogin($BindId,$Pin='') Local $In=DllStructCreate('BYTE['&(StringLen($Pin)+1)&']') DllStructSetData($In,1,$Pin) Local $CallRes=DllCall($ETSdkDll,'WORD','ETTokenLogin', _ 'DWORD',$BindId, _ 'PTR',DllStructGetPtr($In) _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func ETTokenPinChange($BindId,$Pin) Local $In=DllStructCreate('CHAR['&(StringLen($Pin)+1)&']') DllStructSetData($In,1,$Pin) Local $CallRes=DllCall($ETSdkDll,'WORD','ETTokenPinChange', _ 'DWORD',$BindId, _ 'PTR',DllStructGetPtr($In) _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func ETTokenLogout($BindId) Local $CallRes=DllCall($ETSdkDll,'WORD','ETTokenLogout', _ 'DWORD',$BindId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func ETRootDirOpen($BindId,$Dir=0xF007) Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','ETRootDirOpen', _ 'PTR',DllStructGetPtr($Out), _ 'DWORD',$BindId, _ 'DWORD',$Dir _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func ETDirOpen($Dir,$DirId) Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','ETDirOpen', _ 'PTR',DllStructGetPtr($Out), _ 'DWORD',$Dir, _ 'DWORD',$DirId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func ETDirCreate($Dir,$DirId) Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','ETDirCreate', _ 'PTR',DllStructGetPtr($Out), _ 'DWORD',$Dir, _ 'DWORD',$DirId, _ 'DWORD',0 _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func ETDirGetInfo($DirId) Local $Out=DllStructCreate('WORD wDirName; WORD wSize') Local $CallRes=DllCall($ETSdkDll,'WORD','ETDirGetInfo', _ 'DWORD',$DirId, _ 'PTR',DllStructGetPtr($Out) _ ) Local $Result[2]=[ DllStructGetData($Out,'wDirName'), _ DllStructGetData($Out,'wSize')] Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :$Result EndFunc Func ETDirClose($DirId) Local $CallRes=DllCall($ETSdkDll,'WORD','ETDirClose', _ 'DWORD',$DirId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func ETDirDelete($DirId) Local $CallRes=DllCall($ETSdkDll,'WORD','ETDirDelete', _ 'DWORD',$DirId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func ETDirEnumOpen($DirId) Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','ETDirEnumOpen', _ 'PTR',DllStructGetPtr($Out), _ 'DWORD',$DirId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func ETDirEnumNext($EnumId) Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','ETDirEnumNext', _ 'DWORD',$EnumId, _ 'PTR',DllStructGetPtr($Out) _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func ETDirEnumClose($EnumId) Local $CallRes=DllCall($ETSdkDll,'WORD','ETDirEnumClose', _ 'DWORD',$EnumId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func ETFileOpen($File,$DirId) Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','ETFileOpen', _ 'PTR',DllStructGetPtr($Out), _ 'DWORD',$DirId, _ 'DWORD',$File _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func ETFileCreate($File,$DirId,$Size,$Private=0) Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','ETFileCreate', _ 'PTR',DllStructGetPtr($Out), _ 'DWORD',$DirId, _ 'DWORD',$File, _ 'DWORD',$Size, _ 'DWORD',$Private _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func ETFileGetInfo($FileId) Local $Out=DllStructCreate('WORD name;WORD private;WORD;WORD size') Local $CallRes=DllCall($ETSdkDll,'WORD','ETFileGetInfo', _ 'DWORD',$FileId, _ 'PTR',DllStructGetPtr($Out) _ ) Local $Result[3]=[ DllStructGetData($Out,'name'), _ DllStructGetData($Out,'private'), _ DllStructGetData($Out,'size')] Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :$Result EndFunc Func ETFileRead($FileId) Local $FileInfo=ETFileGetInfo($FileId) If @error Then Return SetError(@error,0,False) Local $Out=DllStructCreate('BYTE ['&$FileInfo[2]&']') Local $CallRes=DllCall($ETSdkDll,'WORD','ETFileRead', _ 'DWORD',$FileId, _ 'DWORD',0, _ 'DWORD',0xFFFF, _ 'PTR',DllStructGetPtr($Out), _ 'DWORD',$FileInfo[2] _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func ETFileWrite($FileId,$Data,$Pos=0) $Data=Binary($Data) Local $DataSize=BinaryLen($Data) Local $In=DllStructCreate('BYTE['&$DataSize&']') DllStructSetData($In,1,$Data) Local $CallRes=DllCall($ETSdkDll,'WORD','ETFileWrite', _ 'DWORD',$FileId, _ 'DWORD',$Pos, _ 'PTR',DllStructGetPtr($In), _ 'DWORD',$DataSize _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func ETFileClose($FileId) Local $CallRes=DllCall($ETSdkDll,'WORD','ETFileClose', _ 'DWORD',$FileId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func ETFileDelete($FileId) Local $CallRes=DllCall($ETSdkDll,'WORD','ETFileDelete', _ 'DWORD',$FileId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func ETFilesEnumOpen($DirId) Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','ETFilesEnumOpen', _ 'PTR',DllStructGetPtr($Out), _ 'DWORD',$DirId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func ETFilesEnumNext($EnumId) Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','ETFilesEnumNext', _ 'DWORD',$EnumId, _ 'PTR',DllStructGetPtr($Out) _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func ETFilesEnumClose($EnumId) Local $CallRes=DllCall($ETSdkDll,'WORD','ETFilesEnumClose', _ 'DWORD',$EnumId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func ETTokenLabelGet($BindId) Local $Out1=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','ETTokenLabelGet', _ 'DWORD',$BindId, _ 'PTR',0, _ 'PTR',DllStructGetPtr($Out1) _ ) If $CallRes[0] Then Return SetError($CallRes[0],0,False) Local $Out2=DllStructCreate('CHAR['&DllStructGetData($Out1,1)&']') $CallRes=DllCall($ETSdkDll,'WORD','ETTokenLabelGet', _ 'DWORD',$BindId, _ 'PTR',DllStructGetPtr($Out2), _ 'PTR',DllStructGetPtr($Out1) _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out2,1) EndFunc Func ETTokenIDGet($BindId) Local $Out1=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','ETTokenIDGet', _ 'DWORD',$BindId, _ 'PTR',0, _ 'PTR',DllStructGetPtr($Out1) _ ) If $CallRes[0] Then Return SetError($CallRes[0],0,False) Local $Out2=DllStructCreate('CHAR['&DllStructGetData($Out1,1)&']') $CallRes=DllCall($ETSdkDll,'WORD','ETTokenIDGet', _ 'DWORD',$BindId, _ 'PTR',DllStructGetPtr($Out2), _ 'PTR',DllStructGetPtr($Out1) _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out2,1) EndFunc Func ETTokenMaxPinGet($BindId) Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','ETTokenMaxPinGet', _ 'DWORD',$BindId, _ 'PTR',DllStructGetPtr($Out) _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func ETTokenMinPinGet($BindId) Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','ETTokenMinPinGet', _ 'DWORD',$BindId, _ 'PTR',DllStructGetPtr($Out) _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func ETSelectApplet($BindId, $Applet) Local $In=DllStructCreate('DWORD') DllStructSetData($In,1,$Applet) Local $CallRes=DllCall($ETSdkDll,'WORD','ETSelectApplet', _ 'DWORD',$BindId, _ 'PTR',DllStructGetPtr($Applet) _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func JCSelectApplet($BindId, $Applet) Local $In=DllStructCreate('WORD') DllStructSetData($In,1,$Applet) Local $CallRes=DllCall($ETSdkDll,'WORD','JCSelectApplet', _ 'DWORD',$BindId, _ 'WORD',$Applet _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func JCReadersEnumOpen() Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','JCReadersEnumOpen', _ 'PTR',DllStructGetPtr($Out) _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func JCReadersEnumNext($EnumId) Local $Reader=DllStructCreate('CHAR name[260]; BYTE etoken;') Local $CallRes=DllCall($ETSdkDll,'WORD','JCReadersEnumNext', _ 'DWORD',$EnumId, _ 'PTR',DllStructGetPtr($Reader) _ ) Local $Result[2]=[ DllStructGetData($reader,'name'), _ DllStructGetData($reader,'etoken')] Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :$Result EndFunc Func JCReadersEnumClose($EnumId) Local $CallRes=DllCall($ETSdkDll,'WORD','JCReadersEnumClose', _ 'DWORD',$EnumId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func JCTokenBind($ReaderName) Local $In=DllStructCreate('CHAR['&(StringLen($ReaderName)+1)&']') Local $Out=DllStructCreate('DWORD') DllStructSetData($In,1,$ReaderName) Local $CallRes=DllCall($ETSdkDll,'WORD','JCTokenBind', _ 'PTR',DllStructGetPtr($Out), _ 'PTR',DllStructGetPtr($In) _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func JCTokenRebind($BindId) Local $CallRes=DllCall($ETSdkDll,'WORD','JCTokenRebind', _ 'DWORD',$BindId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func JCTokenUnbind($BindId) Local $CallRes=DllCall($ETSdkDll,'WORD','JCTokenUnbind', _ 'DWORD',$BindId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func JCTokenLogin($BindId,$Pin) Local $In=DllStructCreate('CHAR['&(StringLen($Pin)+1)&']') DllStructSetData($In,1,$Pin) Local $CallRes=DllCall($ETSdkDll,'WORD','JCTokenLogin', _ 'DWORD',$BindId, _ 'PTR',DllStructGetPtr($In) _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func JCTokenPinChange($BindId,$Pin) Local $In=DllStructCreate('CHAR['&(StringLen($Pin)+1)&']') DllStructSetData($In,1,$Pin) Local $CallRes=DllCall($ETSdkDll,'WORD','JCTokenPinChange', _ 'DWORD',$BindId, _ 'PTR',DllStructGetPtr($In) _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func JCTokenLogout($BindId) Local $CallRes=DllCall($ETSdkDll,'WORD','JCTokenLogout', _ 'DWORD',$BindId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func JCRootDirOpen($BindId,$Dir=0) Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','JCRootDirOpen', _ 'PTR',DllStructGetPtr($Out), _ 'DWORD',$BindId, _ 'WORD',$Dir _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func JCDirOpen($Dir,$DirId) Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','JCDirOpen', _ 'PTR',DllStructGetPtr($Out), _ 'DWORD',$Dir, _ 'DWORD',$DirId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func JCDirCreate($Dir,$DirId) Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','JCDirCreate', _ 'PTR',DllStructGetPtr($Out), _ 'DWORD',$Dir, _ 'DWORD',$DirId, _ 'DWORD',0 _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func JCDirGetInfo($DirId) Local $Out=DllStructCreate('BYTE[8]') Local $CallRes=DllCall($ETSdkDll,'WORD','JCDirGetInfo', _ 'DWORD',$DirId, _ 'PTR',DllStructGetPtr($Out) _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func JCDirClose($DirId) Local $CallRes=DllCall($ETSdkDll,'WORD','JCDirClose', _ 'DWORD',$DirId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func JCDirDelete($DirId) Local $CallRes=DllCall($ETSdkDll,'WORD','JCDirDelete', _ 'DWORD',$DirId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func JCDirEnumOpen($DirId) Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','JCDirEnumOpen', _ 'PTR',DllStructGetPtr($Out), _ 'DWORD',$DirId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func JCDirEnumNext($EnumId) Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','JCDirEnumNext', _ 'DWORD',$EnumId, _ 'PTR',DllStructGetPtr($Out) _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func JCDirEnumClose($EnumId) Local $CallRes=DllCall($ETSdkDll,'WORD','JCDirEnumClose', _ 'DWORD',$EnumId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func JCFileOpen($File,$DirId) Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','JCFileOpen', _ 'PTR',DllStructGetPtr($Out), _ 'DWORD',$DirId, _ 'DWORD',$File _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func JCFileCreate($File,$DirId,$Size,$Private=0) Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','JCFileCreate', _ 'PTR',DllStructGetPtr($Out), _ 'DWORD',$DirId, _ 'DWORD',$File, _ 'DWORD',$Size, _ 'DWORD',$Private _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func JCFileGetInfo($FileId) Local $Out=DllStructCreate('WORD name;WORD private;WORD;WORD size') Local $CallRes=DllCall($ETSdkDll,'WORD','JCFileGetInfo', _ 'DWORD',$FileId, _ 'PTR',DllStructGetPtr($Out) _ ) Local $Result[3]=[ DllStructGetData($Out,'name'), _ DllStructGetData($Out,'private'), _ DllStructGetData($Out,'size')] Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :$Result EndFunc Func JCFileRead($FileId) Local $FileInfo=JCFileGetInfo($FileId) If @error Then Return SetError(@error,0,False) Local $Out=DllStructCreate('BYTE ['&$FileInfo[2]&']') Local $CallRes=DllCall($ETSdkDll,'WORD','JCFileRead', _ 'DWORD',$FileId, _ 'DWORD',0, _ 'DWORD',0xFFFF, _ 'PTR',DllStructGetPtr($Out), _ 'DWORD',$FileInfo[2] _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func JCFileWrite($FileId,$Data,$Pos=0) $Data=Binary($Data) Local $DataSize=BinaryLen($Data) Local $In=DllStructCreate('BYTE['&$DataSize&']') DllStructSetData($In,1,$Data) Local $CallRes=DllCall($ETSdkDll,'WORD','JCFileWrite', _ 'DWORD',$FileId, _ 'DWORD',$Pos, _ 'PTR',DllStructGetPtr($In), _ 'DWORD',$DataSize _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func JCFileClose($FileId) Local $CallRes=DllCall($ETSdkDll,'WORD','JCFileClose', _ 'DWORD',$FileId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func JCFileDelete($FileId) Local $CallRes=DllCall($ETSdkDll,'WORD','JCFileDelete', _ 'DWORD',$FileId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func JCFilesEnumOpen($DirId) Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','JCFilesEnumOpen', _ 'PTR',DllStructGetPtr($Out), _ 'DWORD',$DirId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func JCFilesEnumNext($EnumId) Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','JCFilesEnumNext', _ 'DWORD',$EnumId, _ 'PTR',DllStructGetPtr($Out) _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func JCFilesEnumClose($EnumId) Local $CallRes=DllCall($ETSdkDll,'WORD','JCFilesEnumClose', _ 'DWORD',$EnumId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func JCTokenLabelGet($BindId) Local $Out1=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','JCTokenLabelGet', _ 'DWORD',$BindId, _ 'PTR',0, _ 'PTR',DllStructGetPtr($Out1) _ ) If $CallRes[0] Then Return SetError($CallRes[0],0,False) Local $Out2=DllStructCreate('CHAR['&DllStructGetData($Out1,1)&']') $CallRes=DllCall($ETSdkDll,'WORD','JCTokenLabelGet', _ 'DWORD',$BindId, _ 'PTR',DllStructGetPtr($Out2), _ 'PTR',DllStructGetPtr($Out1) _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out2,1) EndFunc Func JCTokenIDGet($BindId) Local $Out1=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','JCTokenIDGet', _ 'DWORD',$BindId, _ 'PTR',0, _ 'PTR',DllStructGetPtr($Out1) _ ) If $CallRes[0] Then Return SetError($CallRes[0],0,False) Local $Out2=DllStructCreate('CHAR['&DllStructGetData($Out1,1)&']') $CallRes=DllCall($ETSdkDll,'WORD','JCTokenIDGet', _ 'DWORD',$BindId, _ 'PTR',DllStructGetPtr($Out2), _ 'PTR',DllStructGetPtr($Out1) _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out2,1) EndFunc Func JCTokenMaxPinGet($BindId) Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','JCTokenMaxPinGet', _ 'DWORD',$BindId, _ 'PTR',DllStructGetPtr($Out) _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func JCTokenMinPinGet($BindId) Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','JCTokenMinPinGet', _ 'DWORD',$BindId, _ 'PTR',DllStructGetPtr($Out) _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc Func JCTokenUnLock($BindId) Local $CallRes=DllCall($ETSdkDll,'WORD','JCTokenUnLock', _ 'DWORD',$BindId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func JCTokenLock($BindId) Local $CallRes=DllCall($ETSdkDll,'WORD','JCTokenLock', _ 'DWORD',$BindId _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :True EndFunc Func JCTokenPinAttemptsGet($BindId) Local $Out=DllStructCreate('DWORD') Local $CallRes=DllCall($ETSdkDll,'WORD','JCTokenPinAttemptsGet', _ 'DWORD',$BindId, _ 'PTR',DllStructGetPtr($Out) _ ) Return $CallRes[0] _ ?SetError($CallRes[0],0,False) _ :DllStructGetData($Out,1) EndFunc ;  Opt("GUIOnEventMode", 1) Dim $BindId, $filelog, $Result, $DirIdRoot=False, $Edit, $msg, $Fileinfo, $treeview, $generalitem, $displayitem, $diritem, $Edit, $SrcSubId, $Output, $pinbutton, $hPinWin, $PinEdit, $pinokbutton, $pincancelbutton, $Pin, $Edit1, $Reader, $Applet, $AppletID, $text, $CreateDirWin Global $Dir1, $Dir2 Dim $hParentWin, $hChildWin, $sItemText, $folderbutton, $filebutton, $deletebutton, $CreateFileWin, $FileEdit, $fileokbutton, $filecancelbutton, $publicbutton, $privatebutton, $sizefile Dim $hFile, $hMain Global Enum $idSave= 1000, $Save Dim $Appname = 'JaCarta Editor' ;  applet ID  Func Applet() GUICtrlSetData($Output, '  applet ID... '&@CRLF,1) Local $Result, $AppletTemp= 0 For $Applet = 0 To 65535 Step 1 $Result = 0 $Result=JCSelectApplet($BindId,$Applet) ; 0x2001 PROJAVA  E-token, 0x1002 PRO, 0x1001 R2, 0x2202 GOST, 0x2205 DATASTORE, 0x2206 -2, 0x2201, 0x2204 ( JaCarta) If $Result = True Then $AppletTemp=$Applet $AppletID=$Applet ExitLoop EndIf Next Local $Id=ETTokenLabelGet($BindId) if $Id= False Then For $Applet=$AppletTemp+1 To 65535 Step 1 $Result=0 $Result=JCSelectApplet($BindId,$Applet) If $Result = True Then ExitLoop EndIf Next EndIf JCSelectApplet($BindId,$Applet) GUICtrlSetData($Output, 'Select applet 0x'&hex($Applet,4)&@CRLF,1) $AppletID=$Applet EndFunc ;      Func PrintDir($Id,$Prefix) Local $EnumId=ETDirEnumOpen($Id) While 1 Local $dir=ETDirEnumNext($EnumId) If @error Then ExitLoop Local $DirId=ETDirOpen($dir,$Id) Local $Dirinfo $Dirinfo=ETDirGetInfo($DirId) Local $Dirtext='(dir)'&hex($dir,4) $diritem = _GUICtrlTreeView_AddChild($treeview,$Prefix, $Dirtext) PrintDir($DirId,$diritem) ETDirClose($DirId) WEnd ETDirEnumClose($EnumId) $EnumId=ETFilesEnumOpen($Id) While 1 Local $file=ETFilesEnumNext($EnumId) If @error Then ExitLoop Local $FileId=ETFileOpen($file,$Id) $Fileinfo=ETFileGetInfo($FileId) Local $filetext='(file)'&hex($file,5)&' '&'p: '&$Fileinfo[1]&' s: '&$Fileinfo[2]&@CRLF _GUICtrlTreeView_AddChild($treeview,$Prefix,$filetext) WEnd ETFilesEnumClose($EnumId) EndFunc ;         Func List() GUICtrlSetData($Output, '') Local $text Local $EnumId=ETReadersEnumOpen() GUICtrlSetData($Output, '   :'&@CRLF,1) While 1 $Reader=ETReadersEnumNext($EnumId) If @error Then ExitLoop GUICtrlSetData($Output, $Reader[0]&@CRLF,1) WEnd ETReadersEnumClose($EnumId) Local $EnumId=ETReadersEnumOpen() $Reader=ETReadersEnumNext($EnumId) $BindId=ETTokenBind($Reader[0]) $Result=JCTokenLock($BindId) GUICtrlSetData($Output, '  '&$Reader[0]&@CRLF,1) ;    ID ,    AppletID $Result=ETTokenIDGet($BindId) if $Result= False Then if $AppletID<>0 Then JCSelectApplet($BindId,$AppletID) Else Applet() EndIf EndIf $Result=ETTokenIDGet($BindId) $text=$Reader[0]&' ID '&$Result $generalitem = _GUICtrlTreeView_AddChild($treeview,0,$text) $Result=ETTokenLabelGet($BindId) GUICtrlSetData($Output, 'Label: '&$Result&@CRLF,1) $DirIdRoot=ETRootDirOpen($BindId,0) ;0xF007   0x0001    $Result=JCTokenPinAttemptsGet($BindId) ;       If $Pin <> 0 Then $Result=JCTokenLogin($BindId,$Pin) If $Result=False Then $Result=JCTokenPinAttemptsGet($BindId) MsgBox(0x10,$Appname,' PIN '&@CRLF&'   PIN : '&$Result ) Else GUICtrlSetData($Output, 'Login OK'&@CRLF,1) EndIf EndIf $Result=JCTokenPinAttemptsGet($BindId) GUICtrlSetData($Output, '   PIN : '&$Result&@CRLF,1) PrintDir($DirIdRoot,0) ETTokenUnbind($BindId) ETReadersEnumClose($EnumId) EndFunc ;     Func onClose() GUISetState(@SW_HIDE, $hPinWin) GUISetState(@SW_HIDE, $hChildWin) GUISetState(@SW_HIDE, $CreateFileWin) if @GUI_WinHandle=$hParentWin Then Exit EndIf EndFunc ;     Func onPin() GUISetState(@SW_SHOW, $hPinWin ) EndFunc ;       Func onPinOK() $Pin=GUICtrlRead($PinEdit) GUISetState(@SW_HIDE, $hPinWin) _GUICtrlTreeView_DeleteAll ($treeview) List() EndFunc ;    Func onPinCancel() GUISetState(@SW_HIDE, $hPinWin) EndFunc ;  Func Delete() If $Pin=0 Then MsgBox(0x10,$Appname,'      ' ) Else Local $hItem = _GUICtrlTreeView_GetSelection($treeview) Local $Del = _GUICtrlTreeView_GetText($treeview, $hItem) if _GUICtrlTreeView_GetChildren($treeview, $hItem)=False Then $Del=StringTrimLeft ( $Del, 6 ) Local $p=0 $p=StringInStr ($Del,"p:") $Del=StringMid ( $Del, 1, $p-2 ) if MsgBox(4 + 32, $Appname, ' '& $Del &' ?') = 6 Then Local $DirID=_GUICtrlTreeView_GetParentHandle($treeview, $hItem) Local $Dir= _GUICtrlTreeView_GetText($treeview, $DirID) $Dir=StringTrimLeft ( $Dir, 5 ) $BindId=ETTokenBind($Reader[0]) $Result=JCTokenLock($BindId) if $AppletID<>0 Then JCSelectApplet($BindId,$AppletID) EndIf If $Pin <> 0 Then $Result=JCTokenLogin($BindId,$Pin) If $Result=False Then $Result=JCTokenPinAttemptsGet($BindId) MsgBox(0x10,$Appname,' PIN '&@CRLF&'   PIN : '&$Result) EndIf EndIf Local $HDir=GetDir(ETRootDirOpen($BindId,0), $Dir) Local $DELFile =JCFileOpen(Dec ($Del), $HDir) JCFileDelete($DELFile ) ETDirClose($HDir) ETTokenUnbind($BindId) _GUICtrlTreeView_DeleteAll ($treeview) List() EndIf Else MsgBox(0x10,$Appname,'           ' ) EndIf EndIf EndFunc ;     Func onFileCreate() If $Pin=0 Then MsgBox(0x10,$Appname,'      ' ) Else Local $hItem = _GUICtrlTreeView_GetSelection($treeview) Local $FileText = 0, $Dir1=0, $Dir2=0 $FileText = _GUICtrlTreeView_GetText($treeview, $hItem) ;      if StringLen($FileText) >20 Then GUICtrlSetData($FileEdit, '') GUICtrlSetData($FileEdit, '//',0) Else $Dir1=StringTrimLeft ( $FileText, 5 ) Local $ParentID=_GUICtrlTreeView_GetParentHandle($treeview, $hItem) Local $ParentDir= _GUICtrlTreeView_GetText($treeview, $ParentID) if StringInStr ($ParentDir,"Dir")=0 Then $ParentDir='' GUICtrlSetData($FileEdit, '') GUICtrlSetData($FileEdit, '//'&$Dir1&'/',0) Else $Dir2=StringTrimLeft ( $ParentDir, 5 ) $Dir2='/'&$Dir2 GUICtrlSetData($FileEdit, '') GUICtrlSetData($FileEdit, '/'&$Dir2&'/'&$Dir1&'/',0) EndIf EndIf GUISetState(@SW_SHOW, $CreateFileWin) EndIf EndFunc ;   Func onFileCancel() GUISetState(@SW_HIDE, $CreateFileWin) EndFunc ;   Func onFileOK() Local $filename=GUICtrlRead($FileEdit) Local $isPrivate=_GUICtrlButton_GetCheck($privatebutton) Local $fileSize=GUICtrlRead($sizefile) $BindId=ETTokenBind($Reader[0]) $Result=JCTokenLock($BindId) if $AppletID<>0 Then JCSelectApplet($BindId,$AppletID) EndIf If $Pin <> 0 Then $Result=JCTokenLogin($BindId,$Pin) If $Result=False Then $Result=JCTokenPinAttemptsGet($BindId) MsgBox(0x10,$Appname,' PIN '&@CRLF&'   PIN : '&$Result ) EndIf EndIf Local $rootdir=ETRootDirOpen($BindId,0) Local $text=StringTrimLeft ( $filename, 2 ) Local $text1=StringLeft($text, 4) $dir1=JCDirOpen(Dec ($text1), $rootdir) if $dir1=false Then $dir1= ETDirCreate(Dec ($text1), $rootdir) EndIf if StringLen($text) >12 Then $text=StringTrimLeft ( $text, 5 ) $text1=StringLeft($text, 4) $dir2=JCDirOpen(Dec ($text1), $dir1) if $dir2=false Then $dir2= ETDirCreate(Dec ($text1), $dir1) EndIf $text=StringTrimLeft ( $text, 5 ) Local $DstFile=JCFileCreate(Dec ($text),$Dir2,$fileSize,$isPrivate) JCFileClose($DstFile) Else $text=StringTrimLeft ( $text, 5 ) Local $DstFile=JCFileCreate(Dec ($text),$Dir1,$fileSize,$isPrivate) JCFileClose($DstFile) EndIf ETTokenUnbind($BindId) GUISetState(@SW_HIDE, $CreateFileWin) GUISetState(@SW_SHOW, $hParentWin) _GUICtrlTreeView_DeleteAll ($treeview) List() EndFunc ;     Func SaveFile() If $Pin=0 Then MsgBox(0x10,$Appname,'      ' ) Else Local $filebody=GUICtrlRead($Edit1) Local $hItem = _GUICtrlTreeView_GetSelection($treeview) Local $FileEd = _GUICtrlTreeView_GetText($treeview, $hItem) $FileEd=StringTrimLeft ( $FileEd, 6 ) Local $p=0 $p=StringInStr ($FileEd,"p:") $FileEd=StringMid ( $FileEd, 1, $p-2 ) Local $DirID=_GUICtrlTreeView_GetParentHandle($treeview, $hItem) Local $Dir= _GUICtrlTreeView_GetText($treeview, $DirID) $Dir=StringTrimLeft ( $Dir, 5 ) $BindId=ETTokenBind($Reader[0]) $Result=JCTokenLock($BindId) if $AppletID<>0 Then JCSelectApplet($BindId,$AppletID) EndIf If $Pin <> 0 Then $Result=JCTokenLogin($BindId,$Pin) If $Result=False Then $Result=JCTokenPinAttemptsGet($BindId) MsgBox(0x10,$Appname,' PIN '&@CRLF&'   PIN : '&$Result) EndIf EndIf Local $HDir=GetDir(ETRootDirOpen($BindId,0), $Dir) Local $File=JCFileOpen(Dec ($FileEd),$HDir) Local $Data =Binary('0x' & $filebody) JCFileWrite($File, $Data) JCFileClose($File) ETDirClose($HDir) ETTokenUnbind($BindId) GUISetState(@SW_HIDE, $hChildWin) _GUICtrlTreeView_DeleteAll ($treeview) List() EndIf EndFunc ;       Func SaveFileAs() Local $varFile = 0 $varFile = FileSaveDialog( " ", @MyDocumentsDir & "\", "  (*.bin)", 16,'',$hParentWin) If StringLen($varFile) > 3 Then Local $filedest $filedest = FileOpen($varFile, 17) ; Check if file open If $filedest = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWrite($filedest, $text) FileClose($filedest) EndIf EndFunc ;        Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $lParam Switch $wParam Case $Save SaveFile() Case $idSave SaveFileAs() EndSwitch EndFunc ;==>WM_COMMAND ;   Func GUIInit() $hParentWin= GUICreate($Appname, 560, 400) GUISetOnEvent($GUI_EVENT_CLOSE,'onClose') ;   $treeview = GUICtrlCreateTreeView(6, 6, 400, 300, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) $Output = GUICtrlCreateEdit("" , 6, 320, 400, 70, $ES_AUTOVSCROLL + $WS_VSCROLL + $ES_NOHIDESEL + $ES_WANTRETURN) $pinbutton = GUICtrlCreateButton("& PIN ", 430, 20, 100, 50) $filebutton = GUICtrlCreateButton("&", 430, 80, 100, 50) $deletebutton = GUICtrlCreateButton("&", 430, 140, 100, 50) ;     $hPinWin = GUICreate(' PIN ', 200, 200, -1, -1, $WS_SYSMENU, -1, $hParentWin) $PinEdit = GUICtrlCreateInput ("" , 50, 40, 100, 25, $ES_PASSWORD + $ES_NOHIDESEL + $ES_WANTRETURN) $pinokbutton = GUICtrlCreateButton("&OK", 20, 100, 60, 40) $pincancelbutton = GUICtrlCreateButton("&", 110, 100, 60, 40) ;   $CreateFileWin = GUICreate('   ', 340, 350, -1, -1, $WS_SYSMENU, -1, $hParentWin) $FileEdit = GUICtrlCreateInput ("" , 50, 70, 230, 25) $fileokbutton= GUICtrlCreateButton("&OK", 70, 240, 60, 40) $filecancelbutton = GUICtrlCreateButton("&", 210, 240, 60, 40) $publicbutton= _GUICtrlButton_Create($CreateFileWin, "Public", 100, 120, 50, 30, $BS_AUTORADIOBUTTON, 0) $privatebutton=_GUICtrlButton_Create($CreateFileWin, "Private", 160, 120, 50, 30, $BS_AUTORADIOBUTTON, 0) _GUICtrlButton_SetCheck($publicbutton, $BST_CHECKED) Local $label=GUICtrlCreateLabel('      hex  1001 ', 70, 20, 170, 40, $SS_CENTER) $sizefile = GUICtrlCreateInput ("10" , 220, 175, 50, 20) Local $label1=GUICtrlCreateLabel('    ', 20, 180, 200, 60, $SS_CENTER) ;   $hChildWin = GUICreate($sItemText, 300, 230, -1, -1, $WS_SYSMENU, -1, $hParentWin) $Edit1 = GUICtrlCreateEdit("", 10, 10, 240, 160, $ES_AUTOVSCROLL + $WS_VSCROLL + $ES_NOHIDESEL + $ES_WANTRETURN) ;   ""     $hFile = _GUICtrlMenu_CreateMenu () _GUICtrlMenu_InsertMenuItem ($hFile, 0, ' ...', $idSave) _GUICtrlMenu_InsertMenuItem ($hFile, 1, ' ', $Save) $hMain = _GUICtrlMenu_CreateMenu () _GUICtrlMenu_InsertMenuItem ($hMain, 0, '', 0, $hFile) _GUICtrlMenu_SetMenu ($hChildWin, $hMain) ;  GUICtrlSetOnEvent($filebutton,'onFileCreate') GUICtrlSetOnEvent($deletebutton,'Delete') GUICtrlSetOnEvent($pinbutton,'onPin') GUICtrlSetOnEvent($pinokbutton,'onPinOK') GUICtrlSetOnEvent($pincancelbutton,'onPinCancel') GUICtrlSetOnEvent($fileokbutton,'onFileOK') GUICtrlSetOnEvent($filecancelbutton,'onFileCancel') GUISetOnEvent($GUI_EVENT_CLOSE,'onClose') GUISetState(@SW_SHOW, $hParentWin) GUIRegisterMsg(0x0111, "WM_COMMAND") EndFunc ;    GUIInit() List() ;          GUIRegisterMsg($WM_NOTIFY, "MY_WM_NOTIFY") Global $iDoubleClick = 0 Func MY_WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $tagNMHDR, $vEvent Switch $wParam Case $treeview $tagNMHDR = DllStructCreate("int;int;int", $lParam) If @error Then Return $vEvent = DllStructGetData($tagNMHDR, 3) If $vEvent = $NM_DBLCLK Then $iDoubleClick = 1 EndIf EndSwitch $tagNMHDR = 0 EndFunc ;==>MY_WM_NOTIFY ;  ,      Func GetDir( $Id,$Dir_Id) Local $DirId=0 Local $DirResult=0 Local $EnumId=ETDirEnumOpen($Id) While 1 Local $dir=ETDirEnumNext($EnumId) If @error Then ExitLoop $DirId=ETDirOpen($dir,$Id) if hex($dir,4)=$Dir_Id Then $DirResult=$DirId ExitLoop EndIf $DirResult=GetDir( $DirId, $Dir_Id) ETDirClose($DirId) WEnd ETDirEnumClose($EnumId) Return $DirResult EndFunc ;            Func ListFile($file, $Dir_Id) $BindId=ETTokenBind($Reader[0]) $Result=JCTokenLock($BindId) if $AppletID<>0 Then JCSelectApplet($BindId,$AppletID) EndIf If $Pin <> 0 Then $Result=JCTokenLogin($BindId,$Pin) If $Result=False Then $Result=JCTokenPinAttemptsGet($BindId) MsgBox(0x10,$Appname,' PIN '&@CRLF&'   PIN : '&$Result ) EndIf EndIf if StringLen($Dir_Id)>10 Then $HDir=ETRootDirOpen($BindId,0) Else Local $HDir=GetDir(ETRootDirOpen($BindId,0), $Dir_Id) EndIf $SrcSubId=JCFileOpen(Dec ($file), $HDir) $text=JCFileRead($SrcSubId) GUICtrlSetData($Edit1, hex($text)) JCFileClose($SrcSubId) ETDirClose($HDir) ETTokenUnbind($BindId) EndFunc ;          While 1 if $iDoubleClick Then Local $hItem = _GUICtrlTreeView_GetSelection($treeview) if _GUICtrlTreeView_GetChildren($treeview, $hItem)=False Then Local $hItem = _GUICtrlTreeView_GetSelection($treeview) $sItemText = _GUICtrlTreeView_GetText($treeview, $hItem) if StringInStr ($sItemText,"Dir")=0 Then Local $text1=0 $text1=StringTrimLeft ( $sItemText, 6 ) Local $p=0 $p=StringInStr ($text1,"p:") $sItemText=0 $sItemText=StringMid ( $text1, 1, $p-2 ) GUISetState(@SW_SHOW, $hChildWin) GUISetOnEvent($GUI_EVENT_CLOSE,'onClose') Local $DirID=_GUICtrlTreeView_GetParentHandle($treeview, $hItem) Local $Dir= _GUICtrlTreeView_GetText($treeview, $DirID) $text1=StringTrimLeft ( $Dir, 5 ) $Dir=$text1 ListFile($sItemText, $Dir) EndIf EndIf $iDoubleClick = 0 EndIf WEnd 


Sources d'information

Guide du développeur eToken version 3.50 (décembre 2003)

Source: https://habr.com/ru/post/fr441476/


All Articles