Guest User

Untitled

a guest
Mar 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.22 KB | None | 0 0
  1. static int GetPid()
  2. {
  3. Process iPokerProcess = null;
  4.  
  5. foreach (var proc in Process.GetProcesses())
  6. {
  7. if (proc.ProcessName == "pokerclient")
  8. {
  9. iPokerProcess = proc;
  10. break;
  11. }
  12. }
  13. if (iPokerProcess == null)
  14. {
  15. MessageBox.Show("Poker client not detected. Please check that the client is running", "Oops! Something has gone wrong", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  16. return -1;
  17. }
  18.  
  19. return iPokerProcess.Id;
  20. }
  21.  
  22. private void startHook_CheckedChanged(object sender, EventArgs e)
  23. {
  24. var checkbox = sender as CheckBox;
  25. var exitProg = true;
  26.  
  27. if (checkbox.Checked)
  28. {
  29. Int32 TargetPID = GetPid();
  30. Console.WriteLine("WTF");
  31.  
  32. if (TargetPID == -1)
  33. {
  34. infoBox.AppendText("Poker Client not detectedn");
  35. checkbox.Checked = false;
  36. }
  37.  
  38. else
  39. {
  40. try
  41. {
  42. try
  43. {
  44. Config.Register(
  45. "IPoker BB Modification",
  46. "IPokerBBMod.exe",
  47. "LunaInject.dll");
  48. }
  49. catch (ApplicationException)
  50. {
  51. MessageBox.Show("This is an administrative task!", "Permission denied...", MessageBoxButtons.OK);
  52.  
  53. System.Diagnostics.Process.GetCurrentProcess().Kill();
  54. }
  55.  
  56. RemoteHooking.IpcCreateServer<IPokerModInterface>(ref ChannelName, WellKnownObjectMode.SingleCall);
  57.  
  58. RemoteHooking.Inject(
  59. TargetPID,
  60. "LunaInject.dll",
  61. "LunaInject.dll",
  62. ChannelName);
  63.  
  64. clientName = Regex.Match(Process.GetProcessById(TargetPID).MainModule.FileName, @".+(?=\PokerClient.exe)").Value;
  65. clientName = clientName.Substring(0, clientName.LastIndexOf('\'));
  66. clientName = clientName.Substring(clientName.LastIndexOf('\'));
  67. clientName = clientName.Replace("\", "");
  68.  
  69. infoBox.AppendText(string.Format("Attached to Poker Client: {0}n", clientName));
  70.  
  71.  
  72. }
  73. catch (Exception ExtInfo)
  74. {
  75. Console.WriteLine("There was an error while connecting to target:rn{0}", ExtInfo.ToString());
  76. }
  77.  
  78. checkbox.Text = "Exit";
  79. checkbox.ForeColor = Color.Red;
  80.  
  81. }
  82. }
  83.  
  84. // Intercept function that is called whenever the ipoker client draws text to its graphical area.
  85. // IPoker draws text in a convuluted way, and it is extremely difficult to tell which window a piece of text is being drawn on hence the messy workaround
  86. static int DrawText_Hooked(IntPtr hdc, [In, Out, MarshalAs(UnmanagedType.LPTStr)] string lpString, int cchText, [In, Out, MarshalAs(UnmanagedType.Struct)] ref RECT lprc, uint dwDTFormat, [In, Out, MarshalAs(UnmanagedType.Struct)] ref DRAWTEXTPARAMS dparams)
  87. {
  88. double bigBlindAmount;
  89. double m;
  90.  
  91. // If detect a call to DrawTextEx with a new hdc and dwDTFormat 0x0800, check to see if the text being draw matches a limit regex (ie: it is a table title)
  92. // If so find the value of the big blind and add it to our dictionary of hdc/big blind pair values.
  93. if (dwDTFormat == 0x0800 && !hdcList.ContainsKey(hdc))
  94. {
  95. Match tableTitle = limit.Match(lpString);
  96. if (tableTitle.Success)
  97. {
  98. double.TryParse(bigBlind.Match(tableTitle.Value).Value.Substring(2), out bigBlindAmount);
  99.  
  100. hdcList.Add(hdc, Convert.ToDouble(bigBlindAmount));
  101. InvalidateRect((IntPtr)null, (IntPtr)null, true);
  102. }
  103. }
  104.  
  105.  
  106. // Match the string being drawn to a money regex, if it matches the client is trying to write text that is money values
  107. else if (money.IsMatch(lpString) && Double.TryParse(lpString.Substring(1), out m))
  108. {
  109. // Get the big blind value for the money value and convert to big blinds
  110. if (dwDTFormat == 0x0800 && hdcList.ContainsKey(hdc))
  111. {
  112. bigBlindAmount = hdcList[hdc];
  113. m = m / bigBlindAmount;
  114.  
  115. string stringOut = m.ToString("N");
  116.  
  117. //if (colorStacks)
  118. //{
  119. // SetTextColor(hdc, ColorTranslator.ToWin32(Color.Gold));
  120. //}
  121.  
  122. // Pass this new value to the underlying Win32 system function to draw to the screen
  123. return DrawTextExW(hdc, stringOut, -1, ref lprc, dwDTFormat, ref dparams);
  124. }
  125.  
  126. // Work around to align text properly
  127. else
  128. {
  129. return DrawTextExW(hdc, "999.99", 6, ref lprc, dwDTFormat, ref dparams);
  130. }
  131. }
  132.  
  133. // Otherwise just call the system DrawTextExW function with the original parameters without modification
  134. return DrawTextExW(hdc, lpString, cchText, ref lprc, dwDTFormat, ref dparams);
  135. }
Add Comment
Please, Sign In to add comment