1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Asm ---> c++ (help)

Discussion in 'Programming' started by Elite Crew, Aug 15, 2010.

  1. Elite Crew

    Elite Crew Active Member

    How I can make ASM to C++ that uses triple or double bytes example:

     
  2. Siobhan

    Siobhan New Member

    Or use something like this.

    hack.h
    Code (Text):
    1.  
    2. #include <Windows.h>
    3.  
    4. #ifndef JMP
    5. #define JMP(frm,to) (((int)to - (int)frm)-5)
    6. #endif
    7.  
    8. class Hack
    9. {
    10.  
    11. private:
    12.     enum { UNINITIALIZED, BINARY, HOOK, HOOKCALL };
    13.     int hacktype;
    14.     int binLen;
    15.     BOOL bInjected;
    16.     DWORD hackPtr;
    17.     DWORD injPtr;
    18.     BYTE *orig;
    19.  
    20. public:
    21.     Hack();
    22.     Hack(BYTE *source, DWORD target, int len); // Make a binpatch
    23.     ~Hack();
    24.  
    25.     BOOL injected();
    26.     void set_hook(DWORD source, DWORD target, int padding);
    27.     void set_hookcall(DWORD source, DWORD target, int padding);
    28.     void set_binpatch(BYTE *source, DWORD target, int len);
    29.     void inject();
    30.     void restore();
    31. };
    32.  

    hack.cpp
    Code (Text):
    1.  
    2. #include <Windows.h>
    3. #include "Hack.h"
    4.  
    5. Hack::Hack() { hacktype = UNINITIALIZED; }
    6.    
    7. Hack::Hack(BYTE *source, DWORD target, int len) {
    8.     set_binpatch(source, target, len);
    9. }
    10.  
    11. Hack::~Hack() {
    12.     if(hacktype != UNINITIALIZED) {
    13.         restore();
    14.         delete orig;
    15.     }
    16. }
    17.  
    18. BOOL Hack::injected() {
    19.     return bInjected;
    20. }
    21.  
    22. void Hack::set_hook(DWORD source, DWORD target, int padding) {
    23.     hacktype = HOOK;
    24.     hackPtr = source;
    25.     injPtr = target;
    26.     binLen = 5+padding; // JMP + Long Ptr
    27.     orig = new BYTE(binLen);
    28. };
    29.  
    30. void Hack::set_hookcall(DWORD source, DWORD target, int padding) {
    31.     hacktype = HOOKCALL;
    32.     hackPtr = source;
    33.     injPtr = target;
    34.     binLen = 5+padding; // CALL + Long Ptr
    35.     orig = new BYTE(binLen);
    36. };
    37.  
    38. void Hack::set_binpatch(BYTE *source, DWORD target, int len) {
    39.     hacktype = BINARY;
    40.     hackPtr = (DWORD)source;
    41.     injPtr = target;
    42.     binLen = len;
    43.     orig = new BYTE(binLen);
    44. };
    45.  
    46. void Hack::inject() {
    47.  
    48.     DWORD oldp;
    49.        
    50.     if(bInjected) return;
    51.  
    52.     bInjected = TRUE;
    53.  
    54.     VirtualProtect((void*)injPtr, binLen, PAGE_EXECUTE_READWRITE, &oldp);
    55.  
    56.     memcpy(orig,(BYTE *)injPtr,binLen);
    57.     memset((void *)injPtr,0x90,binLen);
    58.  
    59.     if(hacktype == HOOKCALL) {
    60.         *(BYTE*)injPtr = (BYTE)0xE8; //CALL
    61.         *(ULONG32*)(injPtr+1) = JMP(injPtr,(DWORD)hackPtr);
    62.     }
    63.  
    64.     if(hacktype == HOOK) {
    65.         *(BYTE*)injPtr = (BYTE)0xE9; //JMP
    66.         *(ULONG32*)(injPtr+1) = JMP(injPtr,(DWORD)hackPtr);
    67.     }
    68.  
    69.     if(hacktype == BINARY) {
    70.         memcpy((void *)injPtr, (void *)hackPtr, binLen);
    71.     }
    72.  
    73.     VirtualProtect((void*)injPtr, binLen, oldp, &oldp);
    74.  
    75. }
    76.    
    77. void Hack::restore() {
    78.     DWORD oldp;
    79.        
    80.     if(!bInjected) return;
    81.     bInjected = FALSE;
    82.  
    83.     VirtualProtect((void*)injPtr, binLen, PAGE_EXECUTE_READWRITE, &oldp);
    84.     memcpy((BYTE *)injPtr,(BYTE *)orig,binLen);
    85.     VirtualProtect((void*)injPtr, binLen, oldp, &oldp);
    86. }
    87.  

    And use it somewhat like this!

    Code (Text):
    1.  
    2. BYTE MobSpeedDat[] = {0x8D, 0x4E, 0x0C};
    3.  
    4. void main() {
    5.   Hack HackMobSpeedup(MobSpeedDat,0x0091618F, 3);
    6.   HackItemFilter.set_hook((DWORD)ItemFilter,0x004F7338,1);
    7.  
    8.   HackMobSpeedup.inject();
    9.   HackItemFilter.restore();
    10. }
    11.  
     
  3. Elite Crew

    Elite Crew Active Member

    Thank you very much. :)
     

Share This Page