Skip to content

Commit

Permalink
fix ObjectDisposedException
Browse files Browse the repository at this point in the history
add logging in AADCoreInjector
v4.0.0.1
  • Loading branch information
wwh1004 committed Mar 13, 2022
1 parent 84644be commit 3fe3240
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 96 deletions.
2 changes: 1 addition & 1 deletion ExtremeDumper.Common.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<Title>ExtremeDumper</Title>
<Version>4.0.0.0</Version>
<Version>4.0.0.1</Version>
<Copyright>Copyright © 2018-2022 Wwh</Copyright>
</PropertyGroup>
<PropertyGroup>
Expand Down
4 changes: 4 additions & 0 deletions ExtremeDumper/AntiAntiDump/AADCoreInjector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using dnlib.DotNet;
using ExtremeDumper.Injecting;
using ExtremeDumper.Logging;

namespace ExtremeDumper.AntiAntiDump;

Expand All @@ -22,6 +23,7 @@ public static string GetAADCorePath() {
var data = GetAADCore(true, out var name);
dllPath = Path.Combine(Path.GetTempPath(), name);
File.WriteAllBytes(dllPath, data);
Logger.Info($"ExtremeDumper.AntiAntiDump.dll has been released to '{dllPath}'");
return dllPath;
}

Expand Down Expand Up @@ -51,10 +53,12 @@ public static AADClient Inject(uint processId, InjectionClrVersion clrVersion, s
bool b = Injector.InjectManaged(processId, GetAADCorePath(), "ExtremeDumper.AntiAntiDump.Injection", "Main", pipeName, clrVersion);
if (!b)
throw new InvalidOperationException("Can't inject ExtremeDumper.AntiAntiDump.dll to target process.");
Logger.Info($"ExtremeDumper.AntiAntiDump.dll has been injected into process {processId} and clr version is {clrVersion}");

var client = AADClient.Create(pipeName);
if (client is null)
throw new InvalidOperationException($"Can't create {nameof(AADClient)}.");
Logger.Info($"Create {nameof(AADClient)} of process {processId} successfully and clr version is {clrVersion}");

return client;
}
Expand Down
20 changes: 1 addition & 19 deletions ExtremeDumper/Forms/FunctionsForm.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Windows.Forms;
using ExtremeDumper.Logging;
using NativeSharp;

namespace ExtremeDumper.Forms;
Expand All @@ -9,7 +8,7 @@ unsafe partial class FunctionsForm : Form {
readonly NativeProcess process;
readonly NativeModule module;

FunctionsForm(uint processId, nuint moduleHandle) {
public FunctionsForm(uint processId, nuint moduleHandle) {
InitializeComponent();
Utils.ScaleByDpi(this);
process = NativeProcess.Open(processId);
Expand All @@ -22,23 +21,6 @@ unsafe partial class FunctionsForm : Form {
RefreshFunctionList();
}

public static FunctionsForm? Create(uint processId, nuint moduleHandle) {
if (processId == 0)
throw new ArgumentNullException(nameof(processId));
if (moduleHandle == 0)
throw new ArgumentNullException(nameof(moduleHandle));

try {
var form = new FunctionsForm(processId, moduleHandle);
form.FormClosed += (_, _) => form.Dispose();
return form;
}
catch (Exception ex) {
Logger.Exception(ex);
return null;
}
}

#region Events
void lvwFunctions_Resize(object sender, EventArgs e) {
lvwFunctions.AutoResizeColumns(true);
Expand Down
15 changes: 0 additions & 15 deletions ExtremeDumper/Forms/InjectingForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,6 @@ public InjectingForm(ProcessInfo process) {
cmbCLRVersion.SelectedIndex = 0;
}

public static InjectingForm? Create(ProcessInfo process) {
if (process is null)
throw new ArgumentNullException(nameof(process));

try {
var form = new InjectingForm(process);
form.FormClosed += (_, _) => form.Dispose();
return form;
}
catch (Exception ex) {
Logger.Exception(ex);
return null;
}
}

#region Events
void InjectingForm_DragEnter(object sender, DragEventArgs e) {
e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None;
Expand Down
25 changes: 2 additions & 23 deletions ExtremeDumper/Forms/ModulesForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ partial class ModulesForm : Form {
readonly TitleComposer title;
readonly List<ModuleInfo> modules = new();

ModulesForm(ProcessInfo process, StrongBox<DumperType> dumperType) {
public ModulesForm(ProcessInfo process, StrongBox<DumperType> dumperType) {
InitializeComponent();
Utils.ScaleByDpi(this);
this.process = process;
Expand All @@ -40,23 +40,6 @@ partial class ModulesForm : Form {
RefreshModuleList();
}

public static ModulesForm? Create(ProcessInfo process, StrongBox<DumperType> dumperType) {
if (process is null)
throw new ArgumentNullException(nameof(process));
if (dumperType is null)
throw new ArgumentNullException(nameof(dumperType));

try {
var form = new ModulesForm(process, dumperType);
form.FormClosed += (_, _) => form.Dispose();
return form;
}
catch (Exception ex) {
Logger.Exception(ex);
return null;
}
}

#region Events
void lvwModules_Resize(object sender, EventArgs e) {
lvwModules.AutoResizeColumns(true);
Expand Down Expand Up @@ -122,11 +105,7 @@ void mnuViewFunctions_Click(object sender, EventArgs e) {
if (!TryGetSelectedModule(out var module))
return;

var form = FunctionsForm.Create(process.Id, module.ImageBase);
if (form is not null)
form.Show();
else
Logger.Error($"Can't create {nameof(FunctionsForm)}");
new FunctionsForm(process.Id, module.ImageBase).Show();
}

void mnuOnlyDotNetModule_Click(object sender, EventArgs e) {
Expand Down
15 changes: 3 additions & 12 deletions ExtremeDumper/Forms/ProcessesForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
namespace ExtremeDumper.Forms;

partial class ProcessesForm : Form {
static readonly LoaderHookForm loaderHookForm = new();
static readonly bool IsAdministrator = new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
static bool hasSeDebugPrivilege;

Expand Down Expand Up @@ -71,7 +70,7 @@ void mnuDebugPrivilege_Click(object sender, EventArgs e) {
}

void mnuOpenLoaderHook_Click(object sender, EventArgs e) {
loaderHookForm.Show();
new LoaderHookForm().Show();
}

void lvwProcesses_Resize(object sender, EventArgs e) {
Expand Down Expand Up @@ -117,11 +116,7 @@ void mnuViewModules_Click(object sender, EventArgs e) {
return;
}

var form = ModulesForm.Create(process, dumperType);
if (form is not null)
form.Show();
else
Logger.Error($"Can't create {nameof(ModulesForm)}");
new ModulesForm(process, dumperType).Show();
}

void mnuRefreshProcessList_Click(object sender, EventArgs e) {
Expand All @@ -144,11 +139,7 @@ void mnuInjectDll_Click(object sender, EventArgs e) {
if (!TryGetSelectedProcess(out var process))
return;

var form = InjectingForm.Create(process);
if (form is not null)
form.Show();
else
Logger.Error($"Can't create {nameof(InjectingForm)}");
new InjectingForm(process).Show();
}

void mnuGotoLocation_Click(object sender, EventArgs e) {
Expand Down
28 changes: 2 additions & 26 deletions ExtremeDumper/GlobalExceptionCatcher.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using ExtremeDumper.Logging;

Expand All @@ -17,31 +15,9 @@ static class GlobalExceptionCatcher {
/// </summary>
public static void Catch() {
if (!isStarted) {
Application.ThreadException += (sender, e) => ShowDetailException(e.Exception);
AppDomain.CurrentDomain.UnhandledException += (sender, e) => ShowDetailException((Exception)e.ExceptionObject);
Application.ThreadException += (sender, e) => Logger.Exception(e.Exception);
AppDomain.CurrentDomain.UnhandledException += (sender, e) => Logger.Exception(e.ExceptionObject as Exception);
isStarted = true;
}
}

static void ShowDetailException(Exception exception) {
var sb = new StringBuilder();
DumpException(exception, sb);
Logger.Error(sb.ToString());
}

static void DumpException(Exception exception, StringBuilder sb) {
exception ??= new ArgumentNullException(nameof(exception), "<No exception object>");
sb.AppendLine($"Type: {Environment.NewLine}{exception.GetType().FullName}");
sb.AppendLine($"Message: {Environment.NewLine}{exception.Message}");
sb.AppendLine($"Source: {Environment.NewLine}{exception.Source}");
sb.AppendLine($"StackTrace: {Environment.NewLine}{exception.StackTrace}");
sb.AppendLine($"TargetSite: {Environment.NewLine}{exception.TargetSite}");
sb.AppendLine("----------------------------------------");
if (exception.InnerException is not null)
DumpException(exception.InnerException, sb);
if (exception is ReflectionTypeLoadException reflectionTypeLoadException) {
foreach (var loaderException in reflectionTypeLoadException.LoaderExceptions)
DumpException(loaderException, sb);
}
}
}

0 comments on commit 3fe3240

Please sign in to comment.