Skip to content

Commit

Permalink
Print some more information and error logs
Browse files Browse the repository at this point in the history
  • Loading branch information
zokker13 committed Jan 13, 2018
1 parent 0a0788d commit cf04313
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 6 deletions.
2 changes: 1 addition & 1 deletion RatherWeird/RatherWeird/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
</StackPanel>
</Button.ToolTip>
</Button>
<Label x:Name="lblVersion" Content="Version: 0.5.0-pre.1" Margin="0,3,10,0" Grid.Row="2" Height="26" VerticalAlignment="Top" HorizontalAlignment="Right" Width="112" IsEnabled="False"/>
<Label x:Name="lblVersion" Content="Version: 0.5.0-pre.2" Margin="0,3,10,0" Grid.Row="2" Height="26" VerticalAlignment="Top" HorizontalAlignment="Right" Width="112" IsEnabled="False"/>
<Button x:Name="btnBrowse" ToolTipService.ShowDuration="10000" Content="..." HorizontalAlignment="Left" Margin="287,9,0,0" Grid.Row="1" VerticalAlignment="Top" Width="18" Height="23" Click="btnBrowse_Click">
<Button.ToolTip>
<StackPanel>
Expand Down
2 changes: 2 additions & 0 deletions RatherWeird/RatherWeird/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ private void chInvokeAltUp_Click(object sender, RoutedEventArgs e)
private void Window_Loaded(object sender, RoutedEventArgs e)
{
RemoveLog();
Utility.Utility.LogSystemInformation();

settings = Preferences.Load();

SetupControls();
Expand Down
12 changes: 12 additions & 0 deletions RatherWeird/RatherWeird/Utility/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,17 @@ public static void Fatal(string text)
Log(LogType.Fatal, text);
MessageBox.Show($"Fatal Error was thrown:\n{text}\nYou shouldn't see this.", "FATAL ERROR");
}

public static string Fillerline(string repeatingText, int amount)
{
StringBuilder sb = new StringBuilder(amount * repeatingText.Length);

for (int i = 0; i < amount; i++)
{
sb.Append(repeatingText);
}

return sb.ToString();
}
}
}
27 changes: 23 additions & 4 deletions RatherWeird/RatherWeird/Utility/MemoryManipulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public bool UnlockProcess(Process ra3Process, ProcessAccessFlags flags)
{
LockProcess();

Logger.Debug("attempt to unlock process (open process)");
Logger.Debug($"attempt to unlock process (open process). using pid {ra3Process.Id}");
Handle = OpenProcess(
flags
, false
Expand All @@ -75,7 +75,9 @@ public bool UnlockProcess(Process ra3Process, ProcessAccessFlags flags)
return true;
}

Logger.Debug("ER.. unlock process (open process)");
int errCode = Marshal.GetLastWin32Error();

Logger.Error($"ER.. unlock process (open process). code: {errCode}");
return false;
}

Expand All @@ -93,9 +95,13 @@ public bool LockProcess()
Logger.Debug("OK.. lock process (close handle)");
}
else
Logger.Debug("ER.. lock process (close handle)");
{
int errCode = Marshal.GetLastWin32Error();
Logger.Error($"ER.. lock process (close handle). code: {errCode}");
}
}

Logger.Debug("no process or handle found that could be closed");
return true;
}

Expand All @@ -106,9 +112,22 @@ public bool WriteByte(IntPtr address, byte value)
throw new InvalidHandle();
}

Logger.Debug($"attempt to write byte to {address.ToString("X8")}");

byte[] bytesToWrite = {value};

return WriteProcessMemory(Handle, address, bytesToWrite, 1, out _);
bool success = WriteProcessMemory(Handle, address, bytesToWrite, 1, out _);
if (success)
{
Logger.Debug("OK.. write byte");
}
else
{
int errCode = Marshal.GetLastWin32Error();
Logger.Error($"ER.. write byte. code: {errCode}");
}

return success;
}
}
}
28 changes: 27 additions & 1 deletion RatherWeird/RatherWeird/Utility/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,33 @@ namespace RatherWeird.Utility
{
public class Utility
{

public static Dictionary<string, string> SystemInformation()
{
Dictionary<string, string> systemInfo = new Dictionary<string, string>();


systemInfo.Add("osversion", Environment.OSVersion.ToString());
systemInfo.Add("clr_version", Environment.Version.ToString());
systemInfo.Add("is_64bit_process", Environment.Is64BitProcess.ToString());
systemInfo.Add("is_64bit_os", Environment.Is64BitOperatingSystem.ToString());
systemInfo.Add("current_directory", Environment.CurrentDirectory);

return systemInfo;
}

public static void LogSystemInformation()
{
var systemInfo = SystemInformation();

Logger.Info(Logger.Fillerline("=", 20));
Logger.Info("System Information");
Logger.Info(Logger.Fillerline("-", 20));
foreach (var element in systemInfo)
{
Logger.Info($"{element.Key}: {element.Value}");
}
Logger.Info(Logger.Fillerline("=", 20));
}

}
}

0 comments on commit cf04313

Please sign in to comment.