Advertisement
Guest User

Untitled

a guest
Oct 1st, 2014
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.90 KB | None | 0 0
  1. private static bool ErrorCheckPatch(byte[] fileBuffer)
  2.         {
  3.             /* Patches the following check:
  4.             * GetLastError returns non-zero */
  5.  
  6.             byte[] oldClientSig = new byte[] { 0x85, 0xC0, 0x75, 0x2F, 0xBF };
  7.             byte[] newClientSig = new byte[] { 0x85, 0xC0, 0x5F, 0x5E, 0x75, 0x2F };
  8.             int offset;
  9.  
  10.             if (FindSignatureOffset(oldClientSig, fileBuffer, out offset)) //signature = target bytes, so no check necessary
  11.             {
  12.                 //XOR AX, AX
  13.                 fileBuffer[offset] = 0x66;
  14.                 fileBuffer[offset + 1] = 0x33;
  15.                 fileBuffer[offset + 2] = 0xC0;
  16.                 fileBuffer[offset + 3] = 0x90;
  17.                 return true;
  18.             }
  19.  
  20.             if (FindSignatureOffset(newClientSig, fileBuffer, out offset)) //signature = target bytes, so no check necessary
  21.             {
  22.                 fileBuffer[offset + 4] = 0x90;
  23.                 fileBuffer[offset + 5] = 0x90;
  24.                 return true;
  25.             }
  26.  
  27.             return false;
  28.         }
  29.  
  30.         private static bool SingleCheckPatch(byte[] fileBuffer)
  31.         {
  32.             /* Patches the following check:
  33.             * "Another copy of UO is already running!" */
  34.  
  35.             byte[] oldClientSig = new byte[] { 0xC7, 0x44, 0x24, 0x10, 0x11, 0x01, 0x00, 0x00 };
  36.             byte[] newClientSig = new byte[] { 0x83, 0xC4, 0x04, 0x33, 0xDB, 0x53, 0x50 };
  37.             int offset;
  38.  
  39.             if (FindSignatureOffset(oldClientSig, fileBuffer, out offset))
  40.             {
  41.                 if (fileBuffer[offset + 0x17] == 0x74)
  42.                 {
  43.                     fileBuffer[offset + 0x17] = 0xEB;
  44.                     return true;
  45.                 }
  46.                 else
  47.                 {
  48.                     // Single check signature found, but actual byte differs from expected.  Aborting.
  49.                     return false;
  50.                 }
  51.             }
  52.  
  53.             if (FindSignatureOffset(newClientSig, fileBuffer, out offset))
  54.             {
  55.                 if (fileBuffer[offset + 0x0F] == 0x74)
  56.                 {
  57.                     fileBuffer[offset + 0x0F] = 0xEB;
  58.                     return true;
  59.                 }
  60.                 else
  61.                 {
  62.                     // Single check signature found, but actual byte differs from expected.  Aborting.
  63.                     return false;
  64.                 }
  65.             }
  66.  
  67.             return false;
  68.         }
  69.  
  70.         private static bool TripleCheckPatch(byte[] fileBuffer)
  71.         {
  72.             /* Patches following checks:
  73.             * "Another instance of UO may already be running."
  74.             * "Another instance of UO is already running."
  75.             * "An instance of UO Patch is already running." */
  76.  
  77.             byte[] oldClientSig = new byte[] { 0xFF, 0xD6, 0x6A, 0x01, 0xFF, 0xD7, 0x68 };
  78.             byte[] newClientSig = new byte[] { 0x3B, 0xC3, 0x89, 0x44, 0x24, 0x08 };
  79.             int offset;
  80.  
  81.             if (FindSignatureOffset(oldClientSig, fileBuffer, out offset))
  82.             {
  83.                 if (fileBuffer[offset - 0x2D] == 0x75 && fileBuffer[offset - 0x0E] == 0x75 && fileBuffer[offset + 0x18] == 0x74)
  84.                 {
  85.                     fileBuffer[offset - 0x2D] = 0xEB;
  86.                     fileBuffer[offset - 0x0E] = 0xEB;
  87.                     fileBuffer[offset + 0x18] = 0xEB;
  88.                     return true;
  89.                 }
  90.                 else
  91.                 {
  92.                     // Triple check signature found, but actual bytes differ from expected.  Aborting.
  93.                     return false;
  94.                 }
  95.             }
  96.  
  97.             if (FindSignatureOffset(newClientSig, fileBuffer, out offset))
  98.             {
  99.                 if (fileBuffer[offset + 0x06] == 0x75 && fileBuffer[offset + 0x2D] == 0x75 && fileBuffer[offset + 0x5F] == 0x74)
  100.                 {
  101.                     fileBuffer[offset + 0x06] = 0xEB;
  102.                     fileBuffer[offset + 0x2D] = 0xEB;
  103.                     fileBuffer[offset + 0x5F] = 0xEB;
  104.                     return true;
  105.                 }
  106.                 else
  107.                 {
  108.                     // Triple check signature found, but actual bytes differ from expected.  Aborting.
  109.                     return false;
  110.                 }
  111.             }
  112.  
  113.             return false;
  114.         }
  115.  
  116.         private void MultiClientPatch()
  117.         {
  118.             if (!TripleCheckPatch(bytes))
  119.             {
  120.                 // Triple check signature not found. Aborting.
  121.                 return;
  122.             }
  123.             if (!SingleCheckPatch(bytes))
  124.             {
  125.                 // Single check signature not found. Aborting.
  126.                 return;
  127.             }
  128.             if (!ErrorCheckPatch(bytes))
  129.             {
  130.                 // Error check signature not found. Aborting.
  131.                 return;
  132.             }
  133.  
  134.             this.LAB_StatusIS.Text = "Multi Client Patching...Done";
  135.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement