ItsMods

Full Version: NOP in C#
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys im here to bring to you an easy way to make a NOP in C#.

N.O.P. = No Operation (computer processor instruction)

CSHARP Code
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Diagnostics;
  10. using System.Runtime.InteropServices;
  11. using System.Threading;
  12.  
  13. namespace mw3_t
  14. {
  15. public partial class Form1 : Form
  16. {
  17. private static int ProcessID = -1;
  18. private static IntPtr ProcessHandle = IntPtr.Zero;
  19.  
  20. [DllImport("kernel32.dll", EntryPoint = "WriteProcessMemory")]
  21. private static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, [Out] int lpNumberOfBytesWritten);
  22.  
  23.  
  24. [DllImport("kernel32.dll", EntryPoint = "ReadProcessMemory")]
  25. private static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer, int dwSize, [Out] int lpNumberOfBytesRead);
  26.  
  27. [DllImport("kernel32.dll", EntryPoint = "OpenProcess")]
  28. private static extern IntPtr OpenProcess(uint dwDesiredAccess, bool bInheritHandle, int dwProcessId);
  29.  
  30. public Form1()
  31. {
  32. InitializeComponent();
  33. }
  34.  
  35. private void Form1_Load(object sender, EventArgs e)
  36. {
  37. System.Diagnostics.Process[] myprocesses = System.Diagnostics.Process.GetProcessesByName("iw5sp");
  38. if (myprocesses.Length != 0)
  39. {
  40. Process[] processes = Process.GetProcessesByName("iw5sp"); // in the "iw5sp" is the name of the process
  41. ProcessID = processes[0].Id;
  42. ProcessHandle = OpenProcess(0x001F0FFF/*PROCESS_ALL_ACCESS*/, false, ProcessID);
  43. byte[] nop = { 0x90, 0x90, 0x90, 0x90, 0x90 };// 5 bytes
  44. WriteProcessMemory(ProcessHandle, (IntPtr)0x004ECF46, nop, 5/*amount of bytes written(5)*/, 0);
  45. }
  46. }
  47. }
  48. }


I think this might help someone, anyway...

Credits: itsmods.com for some help Fuck yea!

Thanks Barata...

cool, but what does a NOP do?
(01-31-2012, 17:10)iAegle Wrote: [ -> ]cool, but what does a NOP do?

For example, nukems ammo plugin uses it. It makes it so that the function that checks if ammo needs to be decreased stops working.
(01-31-2012, 17:11)Pozzuh Wrote: [ -> ]
(01-31-2012, 17:10)iAegle Wrote: [ -> ]cool, but what does a NOP do?

For example, nukems ammo plugin uses it. It makes it so that the function that checks if ammo needs to be decreased stops working.

So basicly it disables the thing that changes the value to default?
No. For example, the code could be like

Code:
DecreaseAmmo()
{
    ammo--;
}

and after the NOPs
the function will be
Code:
DecreaseAmmo()
{
}
It does nothing anymore
(01-31-2012, 17:16)iAegle Wrote: [ -> ]
(01-31-2012, 17:11)Pozzuh Wrote: [ -> ]
(01-31-2012, 17:10)iAegle Wrote: [ -> ]cool, but what does a NOP do?

For example, nukems ammo plugin uses it. It makes it so that the function that checks if ammo needs to be decreased stops working.

So basicly it disables the thing that changes the value to default?

Basicaly, yes...

NOP = no operation...

Thanks Barata...

"an int is 5 bytes in size"

Good.
I didnt know you can NOP in real-time
(02-01-2012, 01:17)kokole Wrote: [ -> ]I didnt know you can NOP in real-time

Indeed you can...

Thanks Barata...