Guest User

Untitled

a guest
Jun 19th, 2017
22
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Decompiled with JetBrains decompiler
  2. // Type: Keyboard_Core.KeyboardControl
  3. // Assembly: Keyboard_Core, Version=1.0.6131.2377, Culture=neutral, PublicKeyToken=null
  4. // MVID: 149D34D9-1EDF-455C-AB79-AE28152A6A4D
  5. // Assembly location: C:\Users\All Users\Lenovo\ImController\Plugins\ThinkKeyboardPlugin\x86\Keyboard_Core.dll
  6.  
  7. using <CppImplementationDetails>;
  8. using Lenovo.Modern.Contracts.Keyboard;
  9. using System;
  10. using System.Threading;
  11. using ThinkPad;
  12.  
  13. namespace Keyboard_Core
  14. {
  15.   public class KeyboardControl
  16.   {
  17.     public unsafe uint GetKeyboardBackLightLevel(out int level)
  18.     {
  19.       ErrorCodeType errorCodeType = ErrorCodeType.Success;
  20.       CKeyboardLight* ckeyboardLightPtr1 = (CKeyboardLight*) <Module>.@new(4U);
  21.       CKeyboardLight* ckeyboardLightPtr2;
  22.       // ISSUE: fault handler
  23.       try
  24.       {
  25.         ckeyboardLightPtr2 = (IntPtr) ckeyboardLightPtr1 == IntPtr.Zero ? (CKeyboardLight*) 0 : <Module>.ThinkPad.CKeyboardLight.{ctor}(ckeyboardLightPtr1);
  26.       }
  27.       __fault
  28.       {
  29.         <Module>.delete((void*) ckeyboardLightPtr1);
  30.       }
  31.       KBDLIGHT_LEVEL kbdlightLevel;
  32.       if (<Module>.ThinkPad.CKeyboardLight.GetLevel(ckeyboardLightPtr2, &kbdlightLevel) != 0)
  33.       {
  34.         level = (int) kbdlightLevel;
  35.         if (kbdlightLevel == (KBDLIGHT_LEVEL) 0)
  36.           errorCodeType = ErrorCodeType.NoCapability;
  37.       }
  38.       else
  39.         errorCodeType = ErrorCodeType.Unknown;
  40.       if ((IntPtr) ckeyboardLightPtr2 != IntPtr.Zero)
  41.       {
  42.         CKeyboardLight* ckeyboardLightPtr3 = ckeyboardLightPtr2;
  43.         int num = 1;
  44.         // ISSUE: cast to a function pointer type
  45.         // ISSUE: function pointer call
  46.         void* voidPtr = __calli((__FnPtr<void* (IntPtr, uint)>) *(int*) *(int*) ckeyboardLightPtr2)((uint) ckeyboardLightPtr3, (IntPtr) num);
  47.       }
  48.       return (uint) errorCodeType;
  49.     }
  50.  
  51.     public unsafe uint GetKeyboardBackLightStatus(out int nStatus)
  52.     {
  53.       ErrorCodeType errorCodeType = ErrorCodeType.Success;
  54.       CKeyboardLight* ckeyboardLightPtr1 = (CKeyboardLight*) <Module>.@new(4U);
  55.       CKeyboardLight* ckeyboardLightPtr2;
  56.       // ISSUE: fault handler
  57.       try
  58.       {
  59.         ckeyboardLightPtr2 = (IntPtr) ckeyboardLightPtr1 == IntPtr.Zero ? (CKeyboardLight*) 0 : <Module>.ThinkPad.CKeyboardLight.{ctor}(ckeyboardLightPtr1);
  60.       }
  61.       __fault
  62.       {
  63.         <Module>.delete((void*) ckeyboardLightPtr1);
  64.       }
  65.       KBDLIGHT_STATUS kbdlightStatus;
  66.       if (<Module>.ThinkPad.CKeyboardLight.GetStatus(ckeyboardLightPtr2, &kbdlightStatus) != 0)
  67.         nStatus = (int) kbdlightStatus;
  68.       else
  69.         errorCodeType = ErrorCodeType.Unknown;
  70.       if ((IntPtr) ckeyboardLightPtr2 != IntPtr.Zero)
  71.       {
  72.         CKeyboardLight* ckeyboardLightPtr3 = ckeyboardLightPtr2;
  73.         int num = 1;
  74.         // ISSUE: cast to a function pointer type
  75.         // ISSUE: function pointer call
  76.         void* voidPtr = __calli((__FnPtr<void* (IntPtr, uint)>) *(int*) *(int*) ckeyboardLightPtr2)((uint) ckeyboardLightPtr3, (IntPtr) num);
  77.       }
  78.       return (uint) errorCodeType;
  79.     }
  80.  
  81.     public unsafe uint SetKeyboardBackLightStatus(int nStatus)
  82.     {
  83.       CKeyboardLight* ckeyboardLightPtr1 = (CKeyboardLight*) <Module>.@new(4U);
  84.       CKeyboardLight* ckeyboardLightPtr2;
  85.       // ISSUE: fault handler
  86.       try
  87.       {
  88.         ckeyboardLightPtr2 = (IntPtr) ckeyboardLightPtr1 == IntPtr.Zero ? (CKeyboardLight*) 0 : <Module>.ThinkPad.CKeyboardLight.{ctor}(ckeyboardLightPtr1);
  89.       }
  90.       __fault
  91.       {
  92.         <Module>.delete((void*) ckeyboardLightPtr1);
  93.       }
  94.       <Module>.ThinkPad.CKeyboardLight.SetStatus(ckeyboardLightPtr2, (KBDLIGHT_STATUS) nStatus);
  95.       if ((IntPtr) ckeyboardLightPtr2 != IntPtr.Zero)
  96.       {
  97.         CKeyboardLight* ckeyboardLightPtr3 = ckeyboardLightPtr2;
  98.         int num = 1;
  99.         // ISSUE: cast to a function pointer type
  100.         // ISSUE: function pointer call
  101.         void* voidPtr = __calli((__FnPtr<void* (IntPtr, uint)>) *(int*) *(int*) ckeyboardLightPtr2)((uint) ckeyboardLightPtr3, (IntPtr) num);
  102.       }
  103.       return 0;
  104.     }
  105.  
  106.     public void StartBackgroundMonitor()
  107.     {
  108.       new Thread(new ThreadStart(KeyboardControl.MonitorThread)).Start();
  109.     }
  110.  
  111.     public unsafe void StopBackgroundMonitor()
  112.     {
  113.       void* voidPtr1 = <Module>.OpenEventW(2031619U, 0, (char*) &<Module>.??_C@_1DE@LNFKCALF@?$AAL?$AAn?$AAv?$AA_?$AAS?$AAt?$AAo?$AAp?$AAB?$AAa?$AAc?$AAk?$AAg?$AAr?$AAo?$AAu?$AAn?$AAd?$AAM?$AAo?$AAn?$AAi?$AAt?$AAo?$AAr?$AA?$AA@);
  114.       if ((IntPtr) voidPtr1 != IntPtr.Zero)
  115.         <Module>.SetEvent(voidPtr1);
  116.       void* voidPtr2 = <Module>.OpenEventW(2031619U, 0, (char*) &<Module>.??_C@_1DK@HIDMJOCE@?$AAL?$AAn?$AAv?$AA_?$AAB?$AAa?$AAc?$AAk?$AAg?$AAr?$AAo?$AAu?$AAn?$AAd?$AAM?$AAo?$AAn?$AAi?$AAt?$AAo?$AAr?$AAS?$AAt?$AAo?$AAp?$AAp?$AAe?$AAd?$AA?$AA@);
  117.       if ((IntPtr) voidPtr2 == IntPtr.Zero)
  118.         return;
  119.       int num = (int) <Module>.WaitForSingleObject(voidPtr2, uint.MaxValue);
  120.       <Module>.CloseHandle(voidPtr2);
  121.     }
  122.  
  123.     private static unsafe void MonitorThread()
  124.     {
  125.       void* eventW = <Module>.CreateEventW((_SECURITY_ATTRIBUTES*) 0, 0, 0, (char*) &<Module>.??_C@_1DK@HIDMJOCE@?$AAL?$AAn?$AAv?$AA_?$AAB?$AAa?$AAc?$AAk?$AAg?$AAr?$AAo?$AAu?$AAn?$AAd?$AAM?$AAo?$AAn?$AAi?$AAt?$AAo?$AAr?$AAS?$AAt?$AAo?$AAp?$AAp?$AAe?$AAd?$AA?$AA@);
  126.       CPMServiceEvent cpmServiceEvent;
  127.       <Module>.ThinkPad.CPMServiceEvent.{ctor}(&cpmServiceEvent);
  128.       // ISSUE: fault handler
  129.       try
  130.       {
  131.         $ArrayType$$$BY01PAX arrayTypeBy01Pax;
  132.         // ISSUE: explicit reference operation
  133.         // ISSUE: cast to a reference type
  134.         // ISSUE: explicit reference operation
  135.         ^(int&) @arrayTypeBy01Pax = (int) <Module>.CreateEventW((_SECURITY_ATTRIBUTES*) 0, 0, 0, (char*) &<Module>.??_C@_1DE@LNFKCALF@?$AAL?$AAn?$AAv?$AA_?$AAS?$AAt?$AAo?$AAp?$AAB?$AAa?$AAc?$AAk?$AAg?$AAr?$AAo?$AAu?$AAn?$AAd?$AAM?$AAo?$AAn?$AAi?$AAt?$AAo?$AAr?$AA?$AA@);
  136.         // ISSUE: cast to a reference type
  137.         // ISSUE: explicit reference operation
  138.         ^(int&) ((IntPtr) &arrayTypeBy01Pax + 4) = (int) <Module>.ThinkPad.CPMServiceEvent.GetHandleForMonitoringType(&cpmServiceEvent);
  139.         while (true)
  140.         {
  141.           void* voidPtr;
  142.           do
  143.           {
  144.             _PMSVC_TYPE1 pmsvcTypE1;
  145.             int num1;
  146.             // ISSUE: cast to a reference type
  147.             // ISSUE: explicit reference operation
  148.             // ISSUE: cast to a reference type
  149.             // ISSUE: explicit reference operation
  150.             do
  151.             {
  152.               int num2;
  153.               do
  154.               {
  155.                 num2 = (int) <Module>.WaitForMultipleObjects(2U, (void**) &arrayTypeBy01Pax, 0, 30000U);
  156.                 if (num2 == 0)
  157.                   goto label_7;
  158.               }
  159.               while (num2 != 1);
  160.               // ISSUE: explicit reference operation
  161.               // ISSUE: cast to a reference type
  162.               // ISSUE: explicit reference operation
  163.               ^(int&) @pmsvcTypE1 = 0;
  164.               // ISSUE: cast to a reference type
  165.               // ISSUE: initblk instruction
  166.               __memset((_PMSVC_TYPE1&) ((IntPtr) &pmsvcTypE1 + 4), 0, 12);
  167.               _PMSVC_TYPE2 pmsvcTypE2;
  168.               // ISSUE: explicit reference operation
  169.               // ISSUE: cast to a reference type
  170.               // ISSUE: explicit reference operation
  171.               ^(int&) @pmsvcTypE2 = 0;
  172.               // ISSUE: cast to a reference type
  173.               // ISSUE: initblk instruction
  174.               __memset((_PMSVC_TYPE2&) ((IntPtr) &pmsvcTypE2 + 4), 0, 40);
  175.               num1 = 0;
  176.               <Module>.ThinkPad.CPMServiceEvent.GetTypeNotification(&cpmServiceEvent, &pmsvcTypE1, &pmsvcTypE2, &num1);
  177.             }
  178.             while (^(int&) ((IntPtr) &pmsvcTypE1 + 8) == 0 && ^(int&) ((IntPtr) &pmsvcTypE1 + 12) == 0 && num1 == 0);
  179.             voidPtr = <Module>.OpenEventW(2031619U, 0, (char*) &<Module>.??_C@_1DI@LMBNLIJN@?$AAL?$AAn?$AAv?$AA_?$AAB?$AAa?$AAc?$AAk?$AAl?$AAi?$AAg?$AAh?$AAt?$AA_?$AAS?$AAt?$AAa?$AAt?$AAu?$AAs?$AAC?$AAh?$AAa?$AAn?$AAg?$AAe?$AAd?$AA?$AA@);
  180.           }
  181.           while ((IntPtr) voidPtr == IntPtr.Zero);
  182.           <Module>.SetEvent(voidPtr);
  183.         }
  184. label_7:
  185.         // ISSUE: explicit reference operation
  186.         // ISSUE: cast to a reference type
  187.         // ISSUE: explicit reference operation
  188.         <Module>.CloseHandle((void*) ^(int&) @arrayTypeBy01Pax);
  189.         if ((IntPtr) eventW != IntPtr.Zero)
  190.           <Module>.SetEvent(eventW);
  191.       }
  192.       __fault
  193.       {
  194.         // ISSUE: method pointer
  195.         // ISSUE: cast to a function pointer type
  196.         <Module>.___CxxCallUnwindDtor((__FnPtr<void (void*)>) __methodptr(ThinkPad.CPMServiceEvent.{dtor}), (void*) &cpmServiceEvent);
  197.       }
  198.       <Module>.ThinkPad.CPMServiceEvent.{dtor}(&cpmServiceEvent);
  199.     }
  200.   }
  201. }
RAW Paste Data