Process Hacker
fixlib.c
Go to the documentation of this file.
1 #include <ph.h>
2 
3 #define ARG_OUTFILE 1
4 
7 
8 BOOLEAN NTAPI CommandLineCallback(
9  _In_opt_ PPH_COMMAND_LINE_OPTION Option,
10  _In_opt_ PPH_STRING Value,
11  _In_opt_ PVOID Context
12  )
13 {
14  if (Option)
15  {
16  switch (Option->Id)
17  {
18  case ARG_OUTFILE:
19  {
20  PhSwapReference(&outFile, Value);
21  }
22  break;
23  }
24  }
25  else
26  {
27  PhSwapReference(&inFile, Value);
28  }
29 
30  return TRUE;
31 }
32 
33 int __cdecl main(int argc, char *argv[])
34 {
35  static PH_COMMAND_LINE_OPTION options[] =
36  {
38  };
39  NTSTATUS status;
40  PH_STRINGREF commandLine;
41  PH_MAPPED_ARCHIVE mappedArchive;
44 
46  return 1;
47 
48  PhUnicodeStringToStringRef(&NtCurrentPeb()->ProcessParameters->CommandLine, &commandLine);
49 
50  if (!PhParseCommandLine(
51  &commandLine,
52  options,
53  sizeof(options) / sizeof(PH_COMMAND_LINE_OPTION),
56  NULL
57  ) || !inFile)
58  {
59  wprintf(L"Usage: fixlib [-o outfile] infile\n");
60  return 1;
61  }
62 
63  if (!outFile)
64  outFile = inFile;
65 
66  CopyFile(inFile->Buffer, outFile->Buffer, FALSE);
67 
68  status = PhLoadMappedArchive(outFile->Buffer, NULL, FALSE, &mappedArchive);
69 
70  if (!NT_SUCCESS(status))
71  {
72  wprintf(L"Error: %s\n", PhGetStringOrDefault(PhGetNtMessage(status), L"unknown"));
73  return status;
74  }
75 
76  member = *(mappedArchive.LastStandardMember);
77 
78  while (NT_SUCCESS(PhGetNextMappedArchiveMember(&member, &member)))
79  {
80  if (NT_SUCCESS(PhGetMappedArchiveImportEntry(&member, &entry)))
81  {
82  IMPORT_OBJECT_HEADER *header;
83  PWSTR type = L"unknown";
84 
85  switch (entry.NameType)
86  {
87  case IMPORT_OBJECT_ORDINAL:
88  type = L"ordinal";
89  break;
90  case IMPORT_OBJECT_NAME:
91  type = L"name";
92  break;
93  case IMPORT_OBJECT_NAME_NO_PREFIX:
94  type = L"name-noprefix";
95  break;
96  case IMPORT_OBJECT_NAME_UNDECORATE:
97  type = L"name-undecorate";
98  break;
99  }
100 
101  wprintf(L"%S: %S (%s)\n", entry.DllName, entry.Name, type);
102 
103  header = (IMPORT_OBJECT_HEADER *)member.Data;
104 
105  // Changes
106 
107  header->NameType = IMPORT_OBJECT_NAME_UNDECORATE;
108  }
109  }
110 
111  PhUnloadMappedArchive(&mappedArchive);
112 }