Je souhaite énumérer les modules d'une application. Je suis sous Windows 64 bits, je compile les applications en 64 bits. Donc tout est en 64 bits. Dependency Walker me le confirme.

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
#define PSAPI_VERSION 1
#define _WIN32_WINNT 0x0601
#include <stdio.h>

#include <windows.h>
#include <psapi.h>

#define CREATE_THREAD_ACCESS (PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_SUSPEND_RESUME | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ)

int main(int argc, char *argv[])
{
  STARTUPINFO         si;
  PROCESS_INFORMATION pi;
  char *file;
  HANDLE process;
  HMODULE modules[100];
  DWORD s;
  DWORD needed;
  BOOL res;

  if (argc < 2)
    return 1;

  file = argv[1];
  printf("%s\n", file);

  ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
  ZeroMemory(&si, sizeof(STARTUPINFO));
  si.cb = sizeof(STARTUPINFO);

  if (!CreateProcess(NULL, file, NULL, NULL, TRUE,
                     CREATE_SUSPENDED, NULL, NULL, &si, &pi))
    {
      printf("CreateProcess failed \n");
      return 1;
    }

  if (!WaitForInputIdle(pi.hProcess, INFINITE))
    {
      printf("WaitForInputIdle failed \n");
      return 1;
    }

  process = OpenProcess(QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pi.dwProcessId);
  if (!process)
    {
      printf("OpenProcess failed \n");
      return 1;
    }

  s = 100;
  res = EnumProcessModulesEx(process, modules, sizeof(modules), &needed, LIST_MODULES_ALL);
  if (!res)
    {
      printf("failed %ld\n", GetLastError());
    }

  printf("size : %lu, %Iu\n", needed, needed / sizeof(HMODULE));

  return 0;
}
EnumProcessModulesEx() retourne l'erreur 299 (ERROR_PARTIAL_COPY : "Only part of a ReadProcessMemory or WriteProcessMemory request was completed.")

Cette erreur est renvoyée en général quand il y a un processus 32 bits, mais l'application que je passe en argument est une application 64 bits, ainsi que l'application dont le code est ci-dessus.

Quelqu'un verrait-il le problème ?

merci