IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++Builder Discussion :

Affichage des objets WMI


Sujet :

C++Builder

  1. #21
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Salut cedni
    J'utilise BCB6 Window7 64Bits
    J'ai trouve sur le net comment afficher une temperature
    le code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
     
    //---------------------------------------------------------------------------
    #include <vcl.h>
    #pragma hdrstop
    #include "Unit1.h"
    #include <comdef.h>
    #include <wbemidl.h>
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
         : TForm(Owner)
    {
    // lien <a href="http://www.stackprinter.com/export?service=stackoverflow&question=5327203&printer=false&linktohome=true" target="_blank">http://www.stackprinter.com/export?s...inktohome=true</a>
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    long pTemperature;
    if (pTemperature == NULL)
    pTemperature = -1;
    HRESULT ci = CoInitialize(NULL); // needs comdef.h
    HRESULT hr = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);
    if (SUCCEEDED(hr))
    {
    IWbemLocator *pLocator; // needs Wbemidl.h & Wbemuuid.lib
    hr = CoCreateInstance(CLSID_WbemAdministrativeLocator, NULL,
                        CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&pLocator);
    if (SUCCEEDED(hr))
    {
    IWbemServices *pServices;
    BSTR ns = SysAllocString(L"root\\WMI");
    hr = pLocator->ConnectServer(ns, NULL, NULL, NULL, 0, NULL, NULL, &pServices);
    pLocator->Release();
    SysFreeString(ns);
                if (SUCCEEDED(hr))
                {
                    BSTR query = SysAllocString(L"SELECT * FROM MSAcpi_ThermalZoneTemperature");
                    BSTR wql = SysAllocString(L"WQL");
                    IEnumWbemClassObject *pEnum;
                    hr = pServices->ExecQuery(wql, query, WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY, NULL, &pEnum);
                    SysFreeString(wql);
                    SysFreeString(query);
                    pServices->Release();
                    if (SUCCEEDED(hr))
                    {
                        IWbemClassObject *pObject;
                        ULONG returned;
                        hr = pEnum->Next(WBEM_INFINITE, 1, &pObject, &returned);
                        pEnum->Release();
                        if (SUCCEEDED(hr))
                        {
                            BSTR temp = SysAllocString(L"CurrentTemperature");
                            VARIANT v;
                            VariantInit(&v);
                            hr = pObject->Get(temp, 0, &v, NULL, NULL);
                            pObject->Release();
                            SysFreeString(temp);
                            if (SUCCEEDED(hr))
                            {
                            pTemperature = V_I4(&v);
                            }
                            VariantClear(&v);
                        }
                    }
                }
                if (ci == S_OK)
                {
                CoUninitialize();
                }
            }
        }
        ListBox1->Items->Add("hr =  " + (String)hr);
        ListBox1->Items->Add("temperature Celsius =  " + (String)(pTemperature / 10 - 273.15));
    }
    Par contre cela n'affiche qu'une seule temperature et le processeur possede quatre corps
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  2. #22
    Membre éclairé
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    573
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 573
    Points : 713
    Points
    713
    Par défaut
    Oui je connais cette classe

    Mais ne marche pas chez moi pourtant j ai du matos normal

    Pour le gpu j ai reussi , j utilise la dll de nvidia pour obtenir la temperature et l occupation , il me reste à finir la partie concernant l utilisation de la ram de la carte graphique.

    Pour le cpu , l occupation , c est bon ,mais je bloque toujours sur la temperature , je vais peut etre voir du coté de la dll d open hardware monitor .

  3. #23
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Bizarre je viens d'essayer sur un autre ordi que je viens juste de reinstaller suis a un crash avec Window7 64Bits et cela fonctionne
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  4. #24
    Membre éclairé
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    573
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 573
    Points : 713
    Points
    713
    Par défaut
    j obtiens celà

    hr = -2147217396
    temperature Celsius = 471585,85

    je veux bien que c est l été mais là ...

  5. #25
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    hr doit etre egal a 0 sinon tu ne passe pas sur une partie du code
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  6. #26
    Membre éclairé
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    573
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 573
    Points : 713
    Points
    713
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
     
    //---------------------------------------------------------------------------
    #include <vcl.h>
    #pragma hdrstop
    #include "Unit1.h"
    #include <comdef.h>
    #include <wbemidl.h>
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
         : TForm(Owner)
    {
    // lien <a href="http://www.stackprinter.com/export?service=stackoverflow&question=5327203&printer=false&linktohome=true" target="_blank">http://www.stackprinter.com/export?s...inktohome=true</a>
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    long pTemperature;
    if (pTemperature == NULL)
    pTemperature = -1;
    HRESULT ci = CoInitialize(NULL); // needs comdef.h
    HRESULT hr = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);
    if (SUCCEEDED(hr))     //1
    {
    IWbemLocator *pLocator; // needs Wbemidl.h & Wbemuuid.lib
    hr = CoCreateInstance(CLSID_WbemAdministrativeLocator, NULL,
                        CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&pLocator);
    if (SUCCEEDED(hr))     //2
    {
    IWbemServices *pServices;
    BSTR ns = SysAllocString(L"root\\WMI");
    hr = pLocator->ConnectServer(ns, NULL, NULL, NULL, 0, NULL, NULL, &pServices);
    pLocator->Release();
    SysFreeString(ns);
                if (SUCCEEDED(hr))    //3
                {
                    BSTR query = SysAllocString(L"SELECT * FROM MSAcpi_ThermalZoneTemperature");
                    BSTR wql = SysAllocString(L"WQL");
                    IEnumWbemClassObject *pEnum;
                    hr = pServices->ExecQuery(wql, query, WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY, NULL, &pEnum);
                    SysFreeString(wql);
                    SysFreeString(query);
                    pServices->Release();
                    if (SUCCEEDED(hr))     //4
                    {
                        IWbemClassObject *pObject;
                        ULONG returned;
                        hr = pEnum->Next(WBEM_INFINITE, 1, &pObject, &returned);
                        pEnum->Release();
                        if (SUCCEEDED(hr))      //5
                        {
                            BSTR temp = SysAllocString(L"CurrentTemperature");
                            VARIANT v;
                            VariantInit(&v);
                            hr = pObject->Get(temp, 0, &v, NULL, NULL);
                            pObject->Release();
                            SysFreeString(temp);
                            if (SUCCEEDED(hr))   //6
                            {
                            pTemperature = V_I4(&v);
                            }  else {Memo1->Lines->Add("6");}
                            VariantClear(&v);
                        } else {Memo1->Lines->Add("5");}
                    }else {Memo1->Lines->Add("4");}
                } else {Memo1->Lines->Add("3");}
                if (ci == S_OK)
                {
                CoUninitialize();
                }
            }  else {Memo1->Lines->Add("2");}
        }  else {Memo1->Lines->Add("1");}
        Memo1->Lines->Add("hr =  " + (String)hr);
        Memo1->Lines->Add("temperature Celsius =  " + (String)(pTemperature / 10 - 273.15));
    }
    J ai modifié légèrement le code ,: un memo et des else

    Il me renvoye un 5

  7. #27
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    j'ai fais un copie/colle du code inclus " wbemuuid.lib " et chez moi ca marche je recupere
    hr = 0
    temperature Celsius = 30.85

    en mode pas a pas tu dois verifier les hr ils doivent etre tous a zero si il y a une valeur differente c'est qu'il y a une erreur
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  8. #28
    Membre éclairé
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    573
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 573
    Points : 713
    Points
    713
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
                    if (SUCCEEDED(hr))     //4
                    {
                        IWbemClassObject *pObject;
                        ULONG returned;
                        hr = pEnum->Next(WBEM_INFINITE, 1, &pObject, &returned);
                        pEnum->Release();
    çà plante ici , la classe ne semble pas accessible ce qui , ma foi , concorde avec l erreur de WMICodeCreator

  9. #29
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Quelle version de BCB utilise tu, si ce n'est pas BCB6 pense a l'unicode
    tu peut essayer ceci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    BSTR query = SysAllocString((WideString)L"SELECT * FROM MSAcpi_ThermalZoneTemperature");
    BSTR wql = SysAllocString((WideString)L"WQL");
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  10. #30
    Membre éclairé
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    573
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 573
    Points : 713
    Points
    713
    Par défaut
    http://msdn.microsoft.com/en-us/libr...ROT.10%29.aspx

    d apres cette page qui décrit les codes d erreurs :

    WBEM_E_NOT_SUPPORTED = 0x8004100c

    bcb6 avec 7 64

  11. #31
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Je suis dans la meme configuration que toi, pour utiliser BCB je suis en mode compatible XP Pack2 et en mode administrateur pour tous les utilisateurs, il y a une chose aussi que j'ai remarque les messages d'erreurs sont parfois fantaisiste
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  12. #32
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Apres avoir trouve sur le site les sources en Delphi de "LadyWasky" voir le lien fourni plus haut j'ai fais des recherches, il est apparemment possible de lire la memoire, je n'y suis pas encore parvenu mais je pense que je ne suis plus tres loin de la solution, voici le code le plus simple en c trouve sur le Net.
    le .cpp
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
     
    //---------------------------------------------------------------------------
    #include <vcl.h>
    #pragma hdrstop
    #include "Unit1.h"
    //#include "SysUtils.hpp"
    //#include "windows.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    typedef LONG NTSTATUS;   
    #define NT_SUCCESS(status)  ((NTSTATUS)(status)>=0)     
    typedef struct _UNICODE_STRING   
    {    
        USHORT Length;
        USHORT MaximumLength;   
        PWSTR Buffer;   
    }UNICODE_STRING, *PUNICODE_STRING;
     
    typedef enum _SECTION_INHERIT{   
        ViewShare = 1,
        ViewUnmap = 2   
    }SECTION_INHERIT, *PSECTION_INHERIT;   
    //Valid values for the Attributes field    
    #define OBJ_INHERIT   0X00000002L    
    #define OBJ_CASE_INSENSITIVE   0X00000040L
    #define OBJ_KERNEL_HANDLE   0X00000200L    
     
    typedef struct _OBJECT_ATTRIBUTES
    {    
        ULONG Length;   
        HANDLE RootDirectory;
        PUNICODE_STRING ObjectName;   
        ULONG Attributes;   
        PVOID SecurityDescriptor;// Points to type SECURITY_DESCRIPTOR
        PVOID SecurityQualityOfService;// Points to type SECURITY_QUALITY_OF_SERVICE    
    }OBJECT_ATTRIBUTES, *POBJECT_ATTRIBUTES;   
    static VOID InitializeObjectAttributes   
                ( OUT POBJECT_ATTRIBUTES InitializedAttributes,   
                  IN PUNICODE_STRING ObjectName,
                  IN ULONG Attributes,   
                  IN HANDLE RootDirectory,   
                  IN PSECURITY_DESCRIPTOR SecurityDescriptor     )
        {   
        InitializedAttributes->Length               = sizeof( OBJECT_ATTRIBUTES );   
        InitializedAttributes->RootDirectory        = RootDirectory;
        InitializedAttributes->Attributes           = Attributes;
        InitializedAttributes->ObjectName           = ObjectName;
        InitializedAttributes->SecurityDescriptor   = SecurityDescriptor;
        InitializedAttributes->SecurityQualityOfService = NULL;
        return;   
    }  /* end of InitializeObjectAttributes */
     
     
     // Interesting functions in NTDLL
    typedef NTSTATUS (WINAPI *ZwOpenSectionProc)
    (  PHANDLE SectionHandle,
       DWORD DesiredAccess,
       /*
        #define SECTION_QUERY       0x0001  
        #define SECTION_MAP_WRITE   0x0002
        #define SECTION_MAP_READ    0x0004  
        #define SECTION_MAP_EXECUTE 0x0008  
        #define SECTION_EXTEND_SIZE 0x0010
        #define SECTION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SECTION_QUERY|\  
                                SECTION_MAP_WRITE |      \  
                                SECTION_MAP_READ |       \
                                SECTION_MAP_EXECUTE |    \  
                                SECTION_EXTEND_SIZE)*/   
       POBJECT_ATTRIBUTES ObjectAttributes   
     
    );
     
    typedef NTSTATUS (WINAPI *ZwMapViewOfSectionProc)   
    (
     HANDLE SectionHandle,   
     HANDLE ProcessHandle,    
     PVOID *BaseAddress,
     ULONG ZeroBits,   
     ULONG CommitSize,   
     PLARGE_INTEGER SectionOffset,
     PULONG ViewSize,   
     SECTION_INHERIT InheritDisposition,   
     ULONG AllocationType,
     ULONG Protect   
     );   
    typedef NTSTATUS (WINAPI *ZwUnmapViewOfSectionProc)   
    (       
     HANDLE ProcessHandle,
     PVOID BaseAddress   
     );   
    typedef VOID (WINAPI *RtlInitUnicodeStringProc)   
    (       
     IN OUT PUNICODE_STRING DestinationString,
     IN PCWSTR SourceString   
     );    
    // Global variables
     
    static HMODULE hModule = NULL;
    static HANDLE hPhysicalMemory = NULL;
    static ZwOpenSectionProc ZwOpenSection;   
    static ZwMapViewOfSectionProc ZwMapViewOfSection;   
    static ZwUnmapViewOfSectionProc ZwUnmapViewOfSection;
    static RtlInitUnicodeStringProc RtlInitUnicodeString;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
         : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    UCHAR buf[4096]={0};
    InitPhysicalMemory();
    ReadPhysicalMemory(buf, 0x000fe000, 4096);
    ExitPhysicalMemory();
    //return 0;
    }
    //---------------------------------------------------------------------------
    BOOL TForm1::InitPhysicalMemory()
    {
    // initialize
    hModule = LoadLibrary("ntdll.dll");
         if(hModule == NULL)
         {
         ListBox1->Items->Add("Erreur ntdll.dll");
         return FALSE;
         }
    ZwOpenSection = (ZwOpenSectionProc)GetProcAddress(hModule, "ZwOpenSection");
         if(ZwOpenSection == NULL)
         {
         ListBox1->Items->Add("Erreur ZwOpenSection");
         return FALSE;
         }
    ZwMapViewOfSection = (ZwMapViewOfSectionProc)GetProcAddress(hModule, "ZwMapViewOfSection");
         if(ZwMapViewOfSection == NULL)
         {
         ListBox1->Items->Add("Erreur ZwMapViewOfSection");
         return FALSE;
         }
    ZwUnmapViewOfSection = (ZwUnmapViewOfSectionProc)GetProcAddress(hModule, "ZwUnmapViewOfSection");
         if(ZwUnmapViewOfSection == NULL)
         {
         ListBox1->Items->Add("Erreur ZwUnmapViewOfSection");
         return FALSE;
         }
    RtlInitUnicodeString = (RtlInitUnicodeStringProc)GetProcAddress(hModule, "RtlInitUnicodeString");
         if(RtlInitUnicodeString == NULL)
         {
         ListBox1->Items->Add("Erreur RtlInitUnicodeString");
         return FALSE;
         }
    //
    WCHAR PhysicalMemoryName[] = L"<a href="file://\\Device\\PhysicalMemory" target="_blank">\\Device\\PhysicalMemory</a>";
    UNICODE_STRING PhysicalMemoryString;
    OBJECT_ATTRIBUTES attributes;
    RtlInitUnicodeString(&PhysicalMemoryString, PhysicalMemoryName);
    InitializeObjectAttributes(&attributes, &PhysicalMemoryString, OBJ_CASE_INSENSITIVE, NULL, NULL);
    //
    NTSTATUS status = ZwOpenSection(&hPhysicalMemory, SECTION_MAP_READ, &attributes );
    // &hPhysicalMemory = NULL
    // &attributes -> Length:24, RootDirectory:NULL, ObjectName::0018E478,
    // Attributes:64, SecurityDescriptor:NULL, SecurityQualityOfService:NULL
         if(!NT_SUCCESS(status))
         {
    // erreur NTSTATUS
    // -1073741790
    // 0xC0000005
    // STATUS_ACCESS_VIOLATION
    // The instruction at 0x%08lx referenced memory at 0x%08lx. The memory could not be %s.
         ListBox1->Items->Add("Erreur status:  " + (String)status);
         return FALSE;
         }
    return TRUE;
    }
    // terminate -- free     
    //---------------------------------------------------------------------------
    void TForm1::ExitPhysicalMemory()
     {   
        if (hPhysicalMemory != NULL)
        {        CloseHandle(hPhysicalMemory);    }    
        if (hModule != NULL)      
        {        FreeLibrary(hModule);    }
    }    
    //---------------------------------------------------------------------------
    BOOL TForm1::ReadPhysicalMemory(PVOID buffer, DWORD address, DWORD length)
    {       
        DWORD outlen;         //
        PVOID vaddress;
        NTSTATUS status;        
        LARGE_INTEGER base; //
        unsigned char buftest[4096];
     
        vaddress = 0;
        outlen = length;
        base.QuadPart = (ULONGLONG)(address);   
        //
        status = ZwMapViewOfSection(
                   hPhysicalMemory,   
                   (HANDLE) -1, //0xffffffff
                   (PVOID *) &vaddress,//
                   0,
                   length,   
                   &base,
                   &outlen,    
                   ViewShare,   
                   0,//
                   PAGE_READONLY   
                   );
        if (status  /*0*/)
        {        return FALSE;    }      
    //
        memmove(buffer, vaddress, length);
        memcpy(buftest, buffer, length);   
     
        for (int j=0; j<4096; j++)
        {
    ListBox1->Items->Add("c: " + *(buftest+j));
    //        printf("%c",*(buftest+j));
        }
    ListBox1->Items->Add("-");
    //    printf("\n");
        //
        status = ZwUnmapViewOfSection((HANDLE)-1, (PVOID)vaddress);
        return (status >= 0);
    }
    //---------------------------------------------------------------------------
    le .h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
     
    //---------------------------------------------------------------------------
    #ifndef Unit1H
    #define Unit1H
    //---------------------------------------------------------------------------
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <Forms.hpp>
    //---------------------------------------------------------------------------
    class TForm1 : public TForm
    {
    __published: // IDE-managed Components
         TButton *Button1;
         TListBox *ListBox1;
         void __fastcall Button1Click(TObject *Sender);
    private: // User declarations
    public:  // User declarations
         __fastcall TForm1(TComponent* Owner);
         BOOL InitPhysicalMemory();
         BOOL ReadPhysicalMemory(PVOID buffer, DWORD address, DWORD length);
         void ExitPhysicalMemory();
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm1 *Form1;
    //---------------------------------------------------------------------------
    #endif
    il y a une erreur sur la ligne et je n'arrive pas a la solutionner
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    NTSTATUS status = ZwOpenSection(&hPhysicalMemory, SECTION_MAP_READ, &attributes );
    voici la valeur de &hPhysicalMemory = NULL

    voici les valeurs &attributes
    Length:24, RootDirectory:NULL, ObjectName::0018E478, Attributes:64, SecurityDescriptor:NULL, SecurityQualityOfService:NULL

    voici l'erreur renvoyee par status apres consultation de MSND NTSTATUS erreurs
    erreur NTSTATUS status
    -1073741790 qui donne en hexa 0xC0000005 STATUS_ACCESS_VIOLATION
    The instruction at 0x%08lx referenced memory at 0x%08lx. The memory could not be %s.
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  13. #33
    Membre chevronné
    Avatar de DjmSoftware
    Homme Profil pro
    Responsable de compte
    Inscrit en
    Mars 2002
    Messages
    1 044
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Responsable de compte
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 044
    Points : 2 187
    Points
    2 187
    Billets dans le blog
    1
    Par défaut
    Hello
    Malheureusement ce code n'est pas compatible avec seven 64 bits
    cdlt
    vous trouverez mes tutoriels à l'adresse suivante: http://djmsoftware.developpez.com/
    je vous en souhaite une excellente lecture ...

    A lire : Les règles du forum

  14. #34
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Merci pour ta reponse DjmSoftware

    Est ce qu'une partie du code est compatible apparemment "LadyWasky" a un code Delphi assez similaire et semblait dire que cela fonctionnait avec Window7.

    Sinon a ton avis vers quoi doit on chercher
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  15. #35
    Membre chevronné
    Avatar de DjmSoftware
    Homme Profil pro
    Responsable de compte
    Inscrit en
    Mars 2002
    Messages
    1 044
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Responsable de compte
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 044
    Points : 2 187
    Points
    2 187
    Billets dans le blog
    1
    Par défaut
    Salut
    il serait intéressant de tester sous Seven 32 bits
    ci-joint l'application compilée sous XP avec mon vieux c++ builder 6
    cdlt
    Fichiers attachés Fichiers attachés
    vous trouverez mes tutoriels à l'adresse suivante: http://djmsoftware.developpez.com/
    je vous en souhaite une excellente lecture ...

    A lire : Les règles du forum

  16. #36
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    J'ai teste et cela renvoie une errreur, la meme que chez moi
    Erreur status -1073741790
    Normalement window7 64 bits peut utiliser une application 32 bits et mon vieux BCB6 compile en 32 bits, si je ne me trompe pas

    NTdll et present dans System32 et devrait fonctionner dans le code poste plus haut, ou on doit utiliser autre chose qui donne les privileges pour lire la memoire
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  17. #37
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Apres recherches j'ai teste le code suivant qui semble modifier les pivileges sans succes je ne suis pas sur qu'il n'y est pas une erreur dans le code.
    la modif .cpp
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
     
    BOOL TForm1::InitPhysicalMemory()
    {
    // initialize
    hModule = LoadLibrary("ntdll.dll");
         if(hModule == NULL)
         {
         ListBox1->Items->Add("Erreur ntdll.dll");
         return FALSE;
         }
    ZwOpenSection = (ZwOpenSectionProc)GetProcAddress(hModule, "ZwOpenSection");
         if(ZwOpenSection == NULL)
         {
         ListBox1->Items->Add("Erreur ZwOpenSection");
         return FALSE;
         }
    ZwMapViewOfSection = (ZwMapViewOfSectionProc)GetProcAddress(hModule, "ZwMapViewOfSection");
         if(ZwMapViewOfSection == NULL)
         {
         ListBox1->Items->Add("Erreur ZwMapViewOfSection");
         return FALSE;
         }
    ZwUnmapViewOfSection = (ZwUnmapViewOfSectionProc)GetProcAddress(hModule, "ZwUnmapViewOfSection");
         if(ZwUnmapViewOfSection == NULL)
         {
         ListBox1->Items->Add("Erreur ZwUnmapViewOfSection");
         return FALSE;
         }
    RtlInitUnicodeString = (RtlInitUnicodeStringProc)GetProcAddress(hModule, "RtlInitUnicodeString");
         if(RtlInitUnicodeString == NULL)
         {
         ListBox1->Items->Add("Erreur RtlInitUnicodeString");
         return FALSE;
         }
    HANDLE hToken;
    HANDLE hCurrentProcess;
    DWORD err;
    TOKEN_PRIVILEGES tkprivs;
    hCurrentProcess = GetCurrentProcess();
    if(OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
    {
    LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkprivs.Privileges[0].Luid);
    tkprivs.PrivilegeCount = 1;
    tkprivs.Privileges[0].Attributes = 1 ? SE_PRIVILEGE_ENABLED : 0;
    AdjustTokenPrivileges(hToken, FALSE, &tkprivs, 0, (PTOKEN_PRIVILEGES)NULL, NULL);
    }
    err = GetLastError();
    //return err == ERROR_SUCESS;
    //
    WCHAR PhysicalMemoryName[] = L"<a href="file://\\Device\\PhysicalMemory" target="_blank">\\Device\\PhysicalMemory</a>";
    UNICODE_STRING PhysicalMemoryString;
    OBJECT_ATTRIBUTES attributes;
    RtlInitUnicodeString(&PhysicalMemoryString, PhysicalMemoryName);
    InitializeObjectAttributes(&attributes, &PhysicalMemoryString, OBJ_CASE_INSENSITIVE, NULL, NULL);
    //
    NTSTATUS status = ZwOpenSection(&hPhysicalMemory, SECTION_MAP_READ, &attributes );
    if(!NT_SUCCESS(status))
         {
         status = ZwOpenSection(&hPhysicalMemory, READ_CONTROL|WRITE_DAC, &attributes);
         PACL pDacl = NULL;
         PSECURITY_DESCRIPTOR pSD = NULL;
         PACL pNewDacl = NULL;
         DWORD dwRes = GetSecurityInfo(hPhysicalMemory, SE_KERNEL_OBJECT, DACL_SECURITY_INFORMATION, NULL,
                             NULL, &pDacl, NULL, &pSD);
    if(ERROR_SUCCESS != dwRes)
         {
    if(pSD)
         LocalFree(pSD);
    if(pNewDacl)
         LocalFree(pNewDacl);
         }
    EXPLICIT_ACCESS ea;
    RtlZeroMemory(&ea, sizeof(EXPLICIT_ACCESS));
    ea.grfAccessPermissions = SECTION_MAP_WRITE;
    ea.grfAccessMode = GRANT_ACCESS;
    ea.grfInheritance= NO_INHERITANCE;
    ea.Trustee.TrusteeForm = TRUSTEE_IS_NAME;
    ea.Trustee.TrusteeType = TRUSTEE_IS_USER;
    ea.Trustee.ptstrName = "CURRENT_USER";
    dwRes = SetEntriesInAcl(1,&ea,pDacl,&pNewDacl);
     
    if(ERROR_SUCCESS != dwRes)
         {
    if(pSD)
         LocalFree(pSD);
    if(pNewDacl)
         LocalFree(pNewDacl);
         }
         dwRes = SetSecurityInfo(hPhysicalMemory,SE_KERNEL_OBJECT,
                   DACL_SECURITY_INFORMATION,NULL,NULL,pNewDacl,NULL);
    if(ERROR_SUCCESS != dwRes)
         {
    if(pSD)
         LocalFree(pSD);
    if(pNewDacl)
         LocalFree(pNewDacl);
         }
         CloseHandle(hPhysicalMemory);
         status = ZwOpenSection(&hPhysicalMemory, SECTION_MAP_READ, &attributes);
    //return ( NT_SUCCESS(status) ? hPhysicalMemory : NULL );
         ListBox1->Items->Add("Erreur status:  " + (String)status);
         return FALSE;
         }
    return TRUE;
    }
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  18. #38
    Membre chevronné
    Avatar de DjmSoftware
    Homme Profil pro
    Responsable de compte
    Inscrit en
    Mars 2002
    Messages
    1 044
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Responsable de compte
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 044
    Points : 2 187
    Points
    2 187
    Billets dans le blog
    1
    Par défaut
    Salut Blondelle
    Essaye a nouveau le code que j'ai posté en désactivant l'UAC
    si c'est concluant alors c'est un problème de privilège dans le cas contraire d'autres pistes sont à explorer
    cdlt
    vous trouverez mes tutoriels à l'adresse suivante: http://djmsoftware.developpez.com/
    je vous en souhaite une excellente lecture ...

    A lire : Les règles du forum

  19. #39
    Membre chevronné
    Avatar de DjmSoftware
    Homme Profil pro
    Responsable de compte
    Inscrit en
    Mars 2002
    Messages
    1 044
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Responsable de compte
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 044
    Points : 2 187
    Points
    2 187
    Billets dans le blog
    1
    Par défaut
    Salut Blondelle
    il semblerait qu'il y a un problème de driver sous seven 64 bits
    regarde le lien suivant
    http://www.codeproject.com/Articles/...-Configuration
    cdlt
    vous trouverez mes tutoriels à l'adresse suivante: http://djmsoftware.developpez.com/
    je vous en souhaite une excellente lecture ...

    A lire : Les règles du forum

  20. #40
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Salut DjmSoftware
    J'ai refais un essai du code en mode administrateur sans securite, j'ai modifie les proprietes du programme " compatibilite xp pack2 " et " executer en temps qu'administrateur ", j'ai toujours la meme erreur
    Erreur status -1073741790
    J'ai regarde le lien apparemment une fonction est obsolete, j'essaie de traduire le texte je pense qu'ils donnent les autres fonctions a utiliser mon anglais est tres mauvais ca va etre sport
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

Discussions similaires

  1. Différence d'affichage des objets null dans une JSP
    Par marinew dans le forum Servlets/JSP
    Réponses: 6
    Dernier message: 26/08/2008, 09h03
  2. Affichage des objets par un iterator
    Par yazen dans le forum Struts 1
    Réponses: 6
    Dernier message: 20/02/2008, 20h41
  3. Gestion de la position à l'affichage des objet Figure
    Par titoph03 dans le forum MATLAB
    Réponses: 9
    Dernier message: 27/09/2007, 13h44
  4. Comment modifier l'affichage des objets cachés de Windows ?
    Par maximdus dans le forum API, COM et SDKs
    Réponses: 23
    Dernier message: 23/07/2005, 11h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo