Skip to content

Commit 79f96bb

Browse files
committed
code optimization & obfuscation
1 parent dba833c commit 79f96bb

14 files changed

Lines changed: 93 additions & 80 deletions

.github/workflows/auto-build.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ jobs:
2727
- name: Build
2828
run: msbuild winMemoryOptimizer.sln -p:Configuration=Release -m
2929

30-
- name: Publish build
31-
uses: actions/upload-artifact@v4
32-
with:
33-
name: winMemoryOptimizer
34-
path: |
35-
winMemoryOptimizer/bin
30+
# - name: Publish build
31+
# uses: actions/upload-artifact@v4
32+
# with:
33+
# name: winMemoryOptimizer
34+
# path: |
35+
# winMemoryOptimizer/bin

winMemoryOptimizer/Engine/ComputerService.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
using Microsoft.Win32.SafeHandles;
1111

1212
namespace winMemoryOptimizer {
13-
13+
1414
internal class ComputerService {
1515

16-
public static bool HasCombinedPageList => OperatingSystemHelper.IsWindows8OrGreater;
17-
public static bool HasModifiedPageList => OperatingSystemHelper.IsWindowsVistaOrGreater;
18-
public static bool HasProcessesWorkingSet => OperatingSystemHelper.IsWindowsXpOrGreater;
19-
public static bool HasStandbyList => OperatingSystemHelper.IsWindowsVistaOrGreater;
20-
public static bool HasSystemWorkingSet => OperatingSystemHelper.IsWindowsXpOrGreater;
21-
public static bool HasModifiedFileCache => OperatingSystemHelper.IsWindowsXpOrGreater;
22-
public static bool HasSystemFileCache => OperatingSystemHelper.IsWindowsXpOrGreater;
23-
public static bool HasRegistryCache => OperatingSystemHelper.IsWindows81OrGreater;
16+
public static bool HasCombinedPageList => OSHelper.IsWindows8OrGreater;
17+
public static bool HasModifiedPageList => OSHelper.IsWindowsVistaOrGreater;
18+
public static bool HasProcessesWorkingSet => OSHelper.IsWindowsXpOrGreater;
19+
public static bool HasStandbyList => OSHelper.IsWindowsVistaOrGreater;
20+
public static bool HasSystemWorkingSet => OSHelper.IsWindowsXpOrGreater;
21+
public static bool HasModifiedFileCache => OSHelper.IsWindowsXpOrGreater;
22+
public static bool HasSystemFileCache => OSHelper.IsWindowsXpOrGreater;
23+
public static bool HasRegistryCache => OSHelper.IsWindows81OrGreater;
2424

2525
private WindowsStructs.MemoryStatusEx memoryStatusEx;
2626

@@ -45,7 +45,7 @@ public bool UpdateMemoryState() {
4545
}
4646
return false;
4747
}
48-
48+
4949
public event Action<byte, string> OnOptimizeProgressUpdate;
5050

5151
private static bool SetIncreasePrivilege(string privilegeName) {
@@ -199,11 +199,11 @@ public void Optimize(Enums.MemoryAreas areas, Enums.OptimizationReason reason) {
199199
value++;
200200
OnOptimizeProgressUpdate(value, "Modified File Cache");
201201
}
202-
202+
203203
stopwatch.Restart();
204-
204+
205205
OptimizeModifiedFileCache();
206-
206+
207207
runtime = runtime.Add(stopwatch.Elapsed);
208208

209209
infoLog.AppendLine(string.Format(infoLogFormat, "Modified file cache", "Optimized",
@@ -329,7 +329,7 @@ private static void OptimizeModifiedFileCache() {
329329
if (handle == null || handle.IsInvalid)
330330
continue;
331331

332-
if (OperatingSystemHelper.IsWindows7OrGreater) {
332+
if (OSHelper.IsWindows7OrGreater) {
333333
try {
334334
var buffer = Marshal.AllocHGlobal(1);
335335
try {
@@ -345,9 +345,9 @@ private static void OptimizeModifiedFileCache() {
345345
// ignored
346346
}
347347

348-
if (OperatingSystemHelper.IsWindows8OrGreater) {
348+
if (OSHelper.IsWindows8OrGreater) {
349349
try {
350-
if (!NativeMethods.DeviceIoControl(handle, Constants.Windows.Drive.FsctlDiscardVolumeCache,
350+
if (!NativeMethods.DeviceIoControl(handle, Constants.Windows.Drive.FsctlDiscardVolumeCache,
351351
IntPtr.Zero, 0, IntPtr.Zero, 0, out _, IntPtr.Zero))
352352
throw new Win32Exception(Marshal.GetLastWin32Error());
353353
}
@@ -462,7 +462,7 @@ private static void OptimizeSystemWorkingSet() {
462462
var handle = GCHandle.Alloc(0);
463463
try {
464464
object systemCacheInformation;
465-
if (OperatingSystemHelper.Is64Bit)
465+
if (OSHelper.Is64Bit)
466466
systemCacheInformation = new WindowsStructs.SystemCacheInformation64
467467
{MinimumWorkingSet = -1L, MaximumWorkingSet = -1L};
468468
else
@@ -501,7 +501,7 @@ private static void OptimizeSystemFileCache() {
501501
try {
502502
object systemFileCacheInformation;
503503

504-
if (OperatingSystemHelper.Is64Bit)
504+
if (OSHelper.Is64Bit)
505505
systemFileCacheInformation = new WindowsStructs.SystemFileCacheInformation64
506506
{MinimumWorkingSet = -1L, MaximumWorkingSet = -1L};
507507
else
@@ -552,4 +552,4 @@ private static SafeFileHandle OpenVolumeHandle(string driveLetter) {
552552
);
553553
}
554554
}
555-
}
555+
}

winMemoryOptimizer/Engine/Constants.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace winMemoryOptimizer {
2-
2+
33
internal static class Constants {
4-
4+
55
public static class Windows {
66
public static class Privilege {
77
public const string SeDebugName = "SeDebugPrivilege"; // Required to debug and adjust the memory of a process owned by another account. User Right: Debug programs.
@@ -43,4 +43,4 @@ public static class File {
4343
}
4444
}
4545
}
46-
}
46+
}

winMemoryOptimizer/Engine/Enums.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
namespace winMemoryOptimizer {
44

55
internal static class Enums {
6-
6+
77
[Flags]
88
public enum LogLevels {
99
Debug = 1,
1010
Information = 2,
1111
Warning = 4,
1212
Error = 8
1313
}
14-
14+
1515
[Flags]
1616
public enum MemoryAreas {
1717
None = 0,
@@ -25,7 +25,7 @@ public enum MemoryAreas {
2525
SystemFileCache = 128,
2626
RegistryCache = 256,
2727
}
28-
28+
2929
public enum MemoryUnit {
3030
B,
3131
KB,
@@ -67,4 +67,4 @@ public enum Priority {
6767
High
6868
}
6969
}
70-
}
70+
}

winMemoryOptimizer/Engine/Logger.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
using sergiye.Common;
55

66
namespace winMemoryOptimizer {
7-
7+
88
internal static class Logger {
9-
9+
1010
private static readonly Enums.LogLevels level = Enums.LogLevels.Debug | Enums.LogLevels.Information |
1111
Enums.LogLevels.Warning | Enums.LogLevels.Error;
1212

winMemoryOptimizer/Engine/Memory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace winMemoryOptimizer {
2-
2+
33
internal class Memory {
4-
4+
55
public void Update(WindowsStructs.MemoryStatusEx memoryStatusEx) {
66

77
Physical.Update(memoryStatusEx.AvailPhys, memoryStatusEx.TotalPhys, memoryStatusEx.MemoryLoad);
@@ -13,4 +13,4 @@ public void Update(WindowsStructs.MemoryStatusEx memoryStatusEx) {
1313

1414
public override string ToString() => $"Physical: {Physical.Used} / {Physical.Free}\nVirtual: {Virtual.Used} / {Virtual.Free}";
1515
}
16-
}
16+
}

winMemoryOptimizer/Engine/MemorySize.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace winMemoryOptimizer {
22

33
internal class MemorySize {
4-
4+
55
public void Update(ulong bytes) {
66
Bytes = bytes;
77
var memory = bytes.ToMemoryUnit();
@@ -15,4 +15,4 @@ public void Update(ulong bytes) {
1515
public double Value { get; private set; }
1616
public override string ToString() => $"{Value:0.00} {Unit} ({Percentage}%)";
1717
}
18-
}
18+
}

winMemoryOptimizer/Engine/MemoryStats.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace winMemoryOptimizer {
22

33
internal class MemoryStats {
4-
4+
55
public void Update(ulong free, ulong total, uint? used = null) {
66
Free.Update(free);
77
Total.Update(total);
@@ -16,4 +16,4 @@ public void Update(ulong free, ulong total, uint? used = null) {
1616
public MemorySize Used { get; } = new MemorySize();
1717
public override string ToString() => $"({Total.Value:0.#} {Total.Unit}) Used | {Used} - Free | {Free}";
1818
}
19-
}
19+
}

winMemoryOptimizer/Engine/NativeMethods.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
using Microsoft.Win32.SafeHandles;
66

77
namespace winMemoryOptimizer {
8-
8+
99
internal static class NativeMethods {
10-
10+
1111
[DllImport("advapi32.dll", SetLastError = true)]
1212
[return: MarshalAs(UnmanagedType.Bool)]
1313
internal static extern bool AdjustTokenPrivileges(IntPtr tokenHandle,
@@ -33,19 +33,19 @@ internal static extern bool AdjustTokenPrivileges(IntPtr tokenHandle,
3333
[return: MarshalAs(UnmanagedType.Bool)]
3434
internal static extern bool SetSystemFileCacheSize(IntPtr minimumFileCacheSize, IntPtr maximumFileCacheSize,
3535
int flags);
36-
36+
3737
[SuppressUnmanagedCodeSecurity]
3838
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
3939
internal static extern SafeFileHandle CreateFile([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, FileAccess dwDesiredAccess, FileShare dwShareMode, IntPtr lpSecurityAttributes, FileMode dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile);
40-
40+
4141
[SuppressUnmanagedCodeSecurity]
4242
[DllImport("kernel32.dll", SetLastError = true)]
4343
[return: MarshalAs(UnmanagedType.Bool)]
4444
internal static extern bool DeviceIoControl(SafeFileHandle hDevice, int dwIoControlCode, IntPtr lpInBuffer, int nInBufferSize, IntPtr lpOutBuffer, int nOutBufferSize, out int lpBytesReturned, IntPtr lpOverlapped);
45-
45+
4646
[SuppressUnmanagedCodeSecurity]
4747
[DllImport("kernel32.dll", SetLastError = true)]
4848
[return: MarshalAs(UnmanagedType.Bool)]
4949
internal static extern bool FlushFileBuffers(SafeFileHandle hFile);
5050
}
51-
}
51+
}

0 commit comments

Comments
 (0)