Process Hacker
procicon.c
Go to the documentation of this file.
1 /*
2  * Process Hacker Extended Tools -
3  * process icon duplication
4  *
5  * Copyright (C) 2011 wj32
6  *
7  * This file is part of Process Hacker.
8  *
9  * Process Hacker is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * Process Hacker is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include "exttools.h"
24 
26  _In_ HICON Icon
27  )
28 {
29  PET_PROCESS_ICON processIcon;
30 
31  processIcon = PhAllocate(sizeof(ET_PROCESS_ICON));
32  processIcon->RefCount = 1;
33  processIcon->Icon = DuplicateIcon(NULL, Icon);
34 
35  return processIcon;
36 }
37 
39  _Inout_ PET_PROCESS_ICON ProcessIcon
40  )
41 {
42  _InterlockedIncrement(&ProcessIcon->RefCount);
43 }
44 
46  _Inout_ PET_PROCESS_ICON ProcessIcon
47  )
48 {
49  if (_InterlockedDecrement(&ProcessIcon->RefCount) == 0)
50  {
51  DestroyIcon(ProcessIcon->Icon);
52  PhFree(ProcessIcon);
53  }
54 }
55 
57  _Inout_ PET_PROCESS_BLOCK Block
58  )
59 {
60  PET_PROCESS_ICON smallProcessIcon;
61 
62  smallProcessIcon = Block->SmallProcessIcon;
63 
64  if (!smallProcessIcon && PhTestEvent(&Block->ProcessItem->Stage1Event))
65  {
66  smallProcessIcon = EtProcIconCreateProcessIcon(Block->ProcessItem->SmallIcon);
67 
69  &Block->SmallProcessIcon,
70  smallProcessIcon,
71  NULL
72  ) != NULL)
73  {
74  EtProcIconDereferenceProcessIcon(smallProcessIcon);
75  smallProcessIcon = Block->SmallProcessIcon;
76  }
77  }
78 
79  if (smallProcessIcon)
80  {
81  EtProcIconReferenceProcessIcon(smallProcessIcon);
82  }
83 
84  return smallProcessIcon;
85 }
86 
88  _Inout_ PET_PROCESS_BLOCK Block
89  )
90 {
91  if (Block->SmallProcessIcon)
92  {
93  EtProcIconDereferenceProcessIcon(Block->SmallProcessIcon);
94  }
95 }