Skip to content

Commit

Permalink
Fixed empty spaces in code and write protection removal
Browse files Browse the repository at this point in the history
  • Loading branch information
erfg12 committed Oct 26, 2020
1 parent c084992 commit 0bddf5c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Memory/memory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,8 @@ public string ReadPString(UIntPtr address, string code, string file = "")
///<param name="write">value to write to address.</param>
///<param name="file">path and name of .ini file (OPTIONAL)</param>
///<param name="stringEncoding">System.Text.Encoding.UTF8 (DEFAULT). Other options: ascii, unicode, utf32, utf7</param>
public bool WriteMemory(string code, string type, string write, string file = "", System.Text.Encoding stringEncoding = null)
///<param name="RemoveWriteProtection">If building a trainer on an emulator (Ex: RPCS3) you'll want to set this to false</param>
public bool WriteMemory(string code, string type, string write, string file = "", System.Text.Encoding stringEncoding = null, bool RemoveWriteProtection = true)
{
byte[] memory = new byte[4];
int size = 4;
Expand Down Expand Up @@ -1122,12 +1123,13 @@ public bool WriteMemory(string code, string type, string write, string file = ""
}

//Debug.Write("DEBUG: Writing bytes [TYPE:" + type + " ADDR:" + theCode + "] " + String.Join(",", memory) + Environment.NewLine);
bool WriteProcMem = false;
MemoryProtection OldMemProt = 0x00;

ChangeProtection(code, MemoryProtection.ExecuteReadWrite, out OldMemProt); // change protection
bool WriteProcMem = false;
if (RemoveWirteProtection)
ChangeProtection(code, MemoryProtection.ExecuteReadWrite, out OldMemProt); // change protection
WriteProcMem = WriteProcessMemory(pHandle, theCode, memory, (UIntPtr)size, IntPtr.Zero);
ChangeProtection(code, OldMemProt, out _); // restore
if (RemoveWirteProtection)
ChangeProtection(code, OldMemProt, out _); // restore
return WriteProcMem;
}

Expand Down Expand Up @@ -1272,7 +1274,7 @@ public UIntPtr GetCode(string name, string path = "", int size = 8)

// remove spaces
if (theCode.Contains(" "))
theCode.Replace(" ", String.Empty);
theCode = theCode.Replace(" ", String.Empty);

if (!theCode.Contains("+") && !theCode.Contains(",")) return new UIntPtr(Convert.ToUInt32(theCode, 16));

Expand Down
File renamed without changes.

0 comments on commit 0bddf5c

Please sign in to comment.