Page 1 of 4 123 ... LastLast
Results 1 to 15 of 57
  1. #1
    NextGen1's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Not sure really.
    Posts
    6,312
    Reputation
    382
    Thanks
    3,019
    My Mood
    Amazed

    C, C++ and VC++ Snippets

    Use this format for submitting snippets

    It may be used later to parse the snippets to a application (like the one in the VB Section)

    If you're going to post a snippet in this thread then you should be posting it in the following format:

    Snippet Name: ____________________
    Keywords: ____,____,____ ...
    Description(Optional): _______________________
    Code:
    Code:
    Your Code Here...
    This is to be used for any small bit of code you would like to share.




     


     


     



    The Most complete application MPGH will ever offer - 68%




  2. The Following 6 Users Say Thank You to NextGen1 For This Useful Post:

    'Bruno (09-29-2010),Lolland (09-28-2010),Rave_ (01-23-2011),therofl (10-01-2010),Void (09-28-2010),why06 (09-28-2010)

  3. #2
    Auxilium's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    深い碧の果てに
    Posts
    4,518
    Reputation
    445
    Thanks
    609
    My Mood
    Happy
    First to post snippet

    Name:Auto space presser can be used for Bunny Hopper (doesnt work on CA) dont know about other games.

    Keywords:Bunny ,hop, hopper, kallisti, is, cool

    description:Simulates space press to jump

    [highlight=cpp]
    //dont post on this thread telling me how
    //i couldve used something other than goto plox
    //ng gonna rageban you too
    start: //haters gonna hate
    while(true)
    {
    Sleep(200);
    if(GetAsyncKeyState(VK_F8))
    {
    while(true)
    {
    Sleep(600);
    keybd_event(VK_SPACE,0x20,KEYEVENTF_EXTENDEDKEY | 0,0);
    if(GetAsyncKeyState(VK_ESCAPE))
    {
    goto start; //start hating
    }

    if(GetAsyncKeyState(VK_F9))
    {
    MessageBox(NULL,L"Bye",L"",MB_ICONEXCLAMATION);
    return 0;
    }
    }
    }[/highlight]
    Last edited by NextGen1; 02-14-2011 at 10:27 AM.

  4. The Following 4 Users Say Thank You to Auxilium For This Useful Post:

    Lyoto Machida (05-15-2011),Morball (05-05-2020),NextGen1 (09-28-2010),therofl (10-01-2010)

  5. #3
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    First is the worst Patrick, second is the best. ftw.

    Snippet name: Low level keyboard hook.

    Keywords: Low,Level,Keyboard,Hook,SetWindowsHookEx,Hotkeys

    Description: Settings up a low level keyboard hook using SetWindowsHookEx for hotkey use.

    Code:
    [highlight=cpp]
    #include <windows.h>
    #include <iostream>

    using namespace std;

    HHOOK keybdhook;
    LRESULT CALLBACK KeyboardHook(int nCode,WPARAM wParam,LPARAM lParam); // declaration of the callback

    int main()
    {
    keybdhook = SetWindowsHookEx(WH_KEYBOARD_LL,KeyboardHook,GetMo duleHandle(0),0);
    if(keybdhook == 0)
    {
    cout <<"Fail to create hook"<<endl;
    }

    MSG msg;
    while(GetMessage(&msg,0,0,0))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }

    }

    LRESULT CALLBACK KeyboardHook(int nCode,WPARAM wParam,LPARAM lParam)
    {
    KBDLLHOOKSTRUCT* key;
    if(wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN)
    {
    key = (KBDLLHOOKSTRUCT*)lParam;

    //hotkey example
    if(key->vkCode == VkKeyScan('a'))
    {
    cout << "You pressed 'a'" << endl;
    }
    if(key->vkCode == VK_F1)
    {
    cout <<"You pressed the F1 key"<<endl;
    }
    }
    return CallNextHookEx(keybdhook,nCode,wParam,lParam);
    }
    [/highlight]

  6. The Following 6 Users Say Thank You to Void For This Useful Post:

    Hassan (09-28-2010),Melodia (10-04-2010),NextGen1 (09-29-2010),punisher54 (09-19-2014),therofl (10-01-2010),why06 (09-28-2010)

  7. #4
    Kallisti's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    深い碧の果てに
    Posts
    4,019
    Reputation
    52
    Thanks
    376
    My Mood
    In Love
    3rd is the one with the dang treasure chest.

    Name: Record mouse coordinates
    keywords: patty, patrick, patty c, is, a, badass
    description: title

    [highlight=cpp]while(true)
    {
    POINT mousePos;
    GetCursorPos(&mousePos);
    cout << "(" << mousePos.x << "," << mousePos.y << ")";
    Sleep(20);
    system("cls");
    }[/highlight]
    Last edited by NextGen1; 02-14-2011 at 10:29 AM.

    未来が見えなくて怖いから
    未来が見えてしまって悲しいから
    目を閉じて優しい思い出に浸ってしまう




  8. The Following 4 Users Say Thank You to Kallisti For This Useful Post:

    Lyoto Machida (05-15-2011),NextGen1 (09-29-2010),therofl (10-01-2010),why06 (09-29-2010)

  9. #5
    freedompeace's Avatar
    Join Date
    Jul 2010
    Gender
    female
    Posts
    3,033
    Reputation
    340
    Thanks
    2,792
    My Mood
    Sad
    Snippet Name: SMTP example.
    Keywords: email, POP, POP3, SMTP, emails, electronic, mail, messages, C++, C
    Description(Optional): Demonstration of how to use SMTP to send emails

    [highlight=cpp]
    #include<iostream>
    #include <syspes.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <netdb.h>
    #include <stdio.h>
    using namespace std;
    #define HELO "HELO 192.168.1.1\r\n"
    #define DATA "DATA\r\n"
    #define QUIT "QUIT\r\n"

    //#define h_addr h_addr_list[0]
    //FILE *fin;
    int sock;
    struct sockaddr_in server;
    struct hostent *hp, *gethostbyname();
    char buf[BUFSIZ+1];
    int len;
    char *host_id="192.168.1.10";
    char *from_id="username@Domain.com";
    char *to_id="username@Domain.com";
    char *sub="testmail\r\n";
    char wkstr[100]="hello how r u\r\n";

    /*=====Send a string to the socket=====*/

    void send_socket(char *s)
    {
    write(sock,s,strlen(s));
    write(1,s,strlen(s));
    //printf("Client:%s\n",s);
    }

    //=====Read a string from the socket=====*/

    void read_socket()
    {
    len = read(sock,buf,BUFSIZ);
    write(1,buf,len);
    //printf("Server:%s\n",buf);
    }

    /*=====MAIN=====*/
    int main(int argc, char* argv[])
    {

    /*=====Create Socket=====*/
    sock = socket(AF_INET, SOCK_STREAM, 0);
    if (sock==-1)
    {
    perror("opening stream socket");
    exit(1);
    }
    else
    cout << "socket created\n";
    /*=====Verify host=====*/
    server.sin_family = AF_INET;
    hp = gethostbyname(host_id);
    if (hp==(struct hostent *) 0)
    {
    fprintf(stderr, "%s: unknown host\n", host_id);
    exit(2);
    }

    /*=====Connect to port 25 on remote host=====*/
    memcpy((char *) &server.sin_addr, (char *) hp->h_addr, hp->h_length);
    server.sin_port=htons(25); /* SMTP PORT */
    if (connect(sock, (struct sockaddr *) &server, sizeof server)==-1)
    {
    perror("connecting stream socket");
    exit(1);
    }
    else
    cout << "Connected\n";
    /*=====Write some data then read some =====*/
    read_socket(); /* SMTP Server logon string */
    send_socket(HELO); /* introduce ourselves */
    read_socket(); /*Read reply */
    send_socket("MAIL FROM: ");
    send_socket(from_id);
    send_socket("\r\n");
    read_socket(); /* Sender OK */
    send_socket("VRFY ");
    send_socket(from_id);
    send_socket("\r\n");
    read_socket(); // Sender OK */
    send_socket("RCPT TO: "); /*Mail to*/
    send_socket(to_id);
    send_socket("\r\n");
    read_socket(); // Recipient OK*/
    send_socket(DATA);// body to follow*/
    send_socket("Subject: ");
    send_socket(sub);
    read_socket(); // Recipient OK*/
    send_socket(wkstr);
    send_socket(".\r\n");
    read_socket();
    send_socket(QUIT); /* quit */
    read_socket(); // log off */

    //=====Close socket and finish=====*/
    close(sock);
    exit(0);
    [/highlight]
    Last edited by NextGen1; 02-14-2011 at 10:30 AM.

  10. The Following 6 Users Say Thank You to freedompeace For This Useful Post:

    flameswor10 (12-24-2010),Melodia (10-04-2010),nxkun (11-28-2011),punisher54 (09-19-2014),SpongeBox (11-13-2010),therofl (10-01-2010)

  11. #6
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by Kallisti View Post
    Don't get this too offtopic.
    Okay here's a snippet (don't even know if it works in C++, I hope it does.)

    [highlight=cpp]
    int main()
    {
    while(true)
    {
    for(int i=0; i<256; i++)
    {
    if(GetAsyncKeyState(i)&1)
    {
    cout<<"I don't know how to convert from keyvalue to string, yay!";
    }
    }
    }

    }
    [/highlight]
    Last edited by NextGen1; 02-14-2011 at 10:30 AM.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  12. The Following 2 Users Say Thank You to Jason For This Useful Post:

    therofl (10-01-2010),Vagner_Donizete (11-03-2015)

  13. #7
    Kallisti's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    深い碧の果てに
    Posts
    4,019
    Reputation
    52
    Thanks
    376
    My Mood
    In Love
    Auto Refresher
    Kallisti is cool
    Auto refreshes
    [highlight=cpp]
    #include <windows.h>
    #include <iostream>
    using namespace std;
    DWORD timesPressed = 0;


    int main()
    {

    while(true)
    {
    startLoop:
    Sleep(100);
    if(GetAsyncKeyState(VK_NUMPAD0))
    {
    while(true)
    {
    if(GetAsyncKeyState(VK_END))
    {
    cout << "Stopped. Press 'Numpad 0' to start again.\n";
    goto startLoop;
    }
    Sleep(12500);
    timesPressed++;
    keybd_event(VK_F5,0x74,KEYEVENTF_EXTENDEDKEY | 0,0);
    cout << "Times pressed: " << timesPressed << '\n';
    }
    }
    }
    }
    [/highlight]
    Last edited by NextGen1; 02-14-2011 at 10:31 AM.

    未来が見えなくて怖いから
    未来が見えてしまって悲しいから
    目を閉じて優しい思い出に浸ってしまう




  14. The Following User Says Thank You to Kallisti For This Useful Post:

    therofl (10-01-2010)

  15. #8
    .::SCHiM::.'s Avatar
    Join Date
    Sep 2010
    Gender
    male
    Posts
    733
    Reputation
    180
    Thanks
    880
    My Mood
    Twisted
    Snippet Name: Convert strings to integers
    Keywords: String, Integer, Loops
    Description(Optional): A messy bit of code used by me to convert strings to integers


    Code:
    #include <math.h>
    #include <string.h>
    Code:
    unsigned long StrToInt(std::string str){
    unsigned long rint = NULL;
    unsigned long size = str.size();
    unsigned long fi[sizeof(str)];
    unsigned long mul;
    
    for( int i = 0; i != size; i++){
            if( str.at(i) == '0' ) fi[i] = 0;
    	if( str.at(i) == '1' ) fi[i] = 1;
    	if( str.at(i) == '2' ) fi[i] = 2;
    	if( str.at(i) == '3' ) fi[i] = 3;
    	if( str.at(i) == '4' ) fi[i] = 4;
    	if( str.at(i) == '5' ) fi[i] = 5;
    	if( str.at(i) == '6' ) fi[i] = 6;
    	if( str.at(i) == '7' ) fi[i] = 7;
    	if( str.at(i) == '8' ) fi[i] = 8;
    	if( str.at(i) == '9' ) fi[i] = 9;
    }
    
    for(int i = 0; i != str.size() ; i++){
    	mul = (1 * pow(10, (double)size-1));
    	size--;
    	rint += ( mul * fi[i]);
    }
    return rint;
    }
    Use

    Code:
    int i = (int) StrToInt("5192491");
    i wil now hold 5192491, as an integer variable

    -SCHiM


    Hell: Or you just use atoi(str.c_str());
    Last edited by Hell_Demon; 10-26-2010 at 07:02 AM.

    I'm SCHiM

    Morals derive from the instinct to survive. Moral behavior is survival behavior above the individual level.

    Polymorphic engine
    Interprocess callback class
    SIN
    Infinite-precision arithmetic
    Hooking dynamic linkage
    (sloppy)Kernel mode Disassembler!!!

    Semi debugger




  16. The Following 4 Users Say Thank You to .::SCHiM::. For This Useful Post:

    cmc5414 (04-10-2014),NextGen1 (10-22-2010),NTvalk (07-07-2013),qwerty01 (02-23-2011)

  17. #9
    fateinabox's Avatar
    Join Date
    Feb 2010
    Gender
    male
    Posts
    17
    Reputation
    10
    Thanks
    1
    Your code to convert alpha to numeric is a little larger than it needs to be..Atoi isn't always a reliable routine to use so a smaller alternative could be to use

    Snippet: Smaller Alpha To Numeric ( atoi )
    Keywords: String, Numeric, Alpha, ATOI, ITOA

    [php]
    #define isnumeric(a) ( ( a >='0' && a <='9' ) )
    #define isalpha(a) !isnumeric(a)
    #define tonum(a) ( ( a - '0' ) )

    long strtonum( char *buffer )
    {
    long tmpNum;
    tmpNum = 0;

    if ( !isnumeric(*buffer) ) return -1;

    while ( isnumeric(*buffer) )
    {
    tmpNum = ( tmpNum * 10 ) + tonum( *buffer );
    (buffer)++;
    }
    return tmpNum;
    }
    [/php]

    Usage: retval = strtonum( "1234" )
    retval=1234
    Last edited by fateinabox; 11-19-2010 at 11:25 AM.

  18. The Following User Says Thank You to fateinabox For This Useful Post:

    Void (11-19-2010)

  19. #10
    Rave_'s Avatar
    Join Date
    Aug 2010
    Gender
    male
    Posts
    98
    Reputation
    16
    Thanks
    288
    My Mood
    Tired
    Snippet Name: Calculator ASCII
    Description(Optional): This was a project of mine and it's been a while. It will act like a calculator but in ascii.

    Code:
    Code:
    #include "stdafx.h"
    #include "windows.h"
    #include <iostream>
    #include <cmath>
    
    using namespace std;
    
    struct Define
    {
    	int option;
    	char operators;
    	long basica;
    	long basicb;
    	float adva;
    	long answerbasic;
    	float answeradv;
    };
    
    Define df;
    
    namespace Calculator
    {
    	int MainLobby( )
    	{
    		printf( " \nWelcome to Calculator(ASCII)!\n");
    		printf( " Enter: ");
    		printf( " '1' for Basic. ");
    		printf( " '2' for Advanced : ");
    		cin >> df.option;
    		return 0;
    	}
    
    	int BasicLobby( )
    	{
    		cout << " Enter operator ( +, -, *, / ): ";
    		cin >> df.operators;
    		cout << " Enter a number: ";
    		cin >> df.basica;
    		cout << " Enter another number: ";
    		cin >> df.basicb;
    
    		if ( df.operators == ('+') )
    		{
    			df.answerbasic = df.basica + df.basicb;
    			cout << df.basica << " " << df.operators << " " << df.basicb << " = " << df.answerbasic;
    		}
    		
    		if ( df.operators == ('-') )
    		{
    			df.answerbasic = df.basica - df.basicb;
    			cout << df.basica << " " << df.operators << " " << df.basicb << " = " << df.answerbasic;
    		}
    
    		if ( df.operators == ('*') )
    		{
    			df.answerbasic = df.basica * df.basicb;
    			cout << df.basica << " " << df.operators << " " << df.basicb << " = " << df.answerbasic;
    		}
    
    		if ( df.operators == ('/') )
    		{
    			df.answerbasic = df.basica / df.basicb;
    			cout << df.basica << " " << df.operators << " " << df.basicb << " = " << df.answerbasic;
    		}
    
    		cout << "\n\n";
    
    		return 0;
    	}
    
    	int AdvancedLobby( )
    	{
    		cout << "Enter operators 's' for square root: ";
    		cin >> df.operators;
    		cout << "Enter a number: ";
    		cin >> df.adva;
    
    		if ( df.operators == ('s') )
    		{
    			df.answeradv = sqrt(df.adva);
    			cout << " square root " << df.adva << " = " << df.answeradv;
    		}
    
    		cout << "\n\n";
    
    		return 0;
    
    	}
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	while( 1 )
    	{
    Restart:
    		Calculator::MainLobby( );
    		switch(df.option)
    		{
    		case (1): Calculator::BasicLobby( ); break;
    		case (2): Calculator::AdvancedLobby( ); break;
    		default: cout << "\nPlease enter 1 or 2."; break;
    		}
    		goto Restart;
    	}
    
    	return 0;
    }
    Support me for being a WarRock Official Coder.
    [Here]

  20. The Following User Says Thank You to Rave_ For This Useful Post:

    punisher54 (09-19-2014)

  21. #11
    master131's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    Melbourne, Australia
    Posts
    8,858
    Reputation
    3438
    Thanks
    101,662
    My Mood
    Breezy
    Snippet Name: Simple Keylogger/GAKS Tool
    Keywords: keylogger, GetAsyncKeyState, keyboard, master131.

    Code:
    //GAKS.cpp written by master131
    
    #include <Windows.h>
    #include <iostream>
    
    int main()
    {
    	using namespace std;
    	char* keys[] = {"{LEFTMOUSE}", "{RIGHTMOUSE}", "{CANCEL}", 
    		"{MIDDLEMOUSE}", "{XBUTTON1}", "{XBUTTON2}", "", "{BACKSPACE}", "{TAB}",
    		"","","{CLEAR}", "{ENTER}", "", "", "{SHIFT}", "{CTRL}", "{ALT}", "{PAUSE}", "{CAPSLOCK}" };
    	char* otherkeys[] = {"{SPACE}", "{PGUP}", "{PGDOWN}", "{END}", "{HOME}", "{LEFT ARROW}", "{UP ARROW}", 
    		"{RIGHT ARROW}", "{DOWN ARROW}", "{SELECT}", "{PRINT}", "{EXECUTE}", "{PRNTSCREEN}", "{INS}",
    		"{DEL}", "{HELP}"};
    	char* standardkeys[] = {":", "+", ",", "-", ".", "/", "`"};
    	char* misckeys[] = {"[", "\\", "]", "'"};
    	char* numpadkeys[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "+", "", "-", ".", "/"};
    
    	while(1)
    	{
    		for(int i = 0; i < 255; i++)
    			if(GetAsyncKeyState(i))
    			{
    				while(GetAsyncKeyState(i)) { };
    				if(i >= 1 && i <= 19) //Special Keys
    					cout << keys[i-1];
    				if(i >= 32 && i <= 47) //Other keys
    					cout << otherkeys[i-32];
    				if(i >= 48 && i <= 90) //Literal Keys
    					cout << (char)tolower(i);
    				if(i >= 96 && i <= 111) //Numpad keys
    					cout << numpadkeys[i-96];
    				if(i >= 112 && i <= 135) //F keys
    					cout << "{F" << i - 111 << "}";
    				if(i >= 186 && i <= 192) //Punctuation Keys
    					cout << standardkeys[i-186];
    				if(i >= 219 && i <= 222) //Misc keys
    					cout << misckeys[i-219];
    			}
    		Sleep(1);
    	}
    	return 0;
    }

    Hell: Or use a WH_KEYBOARD hook =3
    Last edited by Hell_Demon; 03-23-2011 at 04:22 AM.
    Donate:
    BTC: 1GEny3y5tsYfw8E8A45upK6PKVAEcUDNv9


    Handy Tools/Hacks:
    Extreme Injector v3.7.3
    A powerful and advanced injector in a simple GUI.
    Can scramble DLLs on injection making them harder to detect and even make detected hacks work again!

    Minion Since: 13th January 2011
    Moderator Since: 6th May 2011
    Global Moderator Since: 29th April 2012
    Super User/Unknown Since: 23rd July 2013
    'Game Hacking' Team Since: 30th July 2013

    --My Art--
    [Roxas - Pixel Art, WIP]
    [Natsu - Drawn]
    [Natsu - Coloured]


    All drawings are coloured using Photoshop.

    --Gifts--
    [Kyle]

  22. The Following 3 Users Say Thank You to master131 For This Useful Post:

    An0y (01-26-2015),cmc5414 (04-10-2014),unspeakable (10-06-2012)

  23. #12
    whit's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Posts
    7,159
    Reputation
    490
    Thanks
    2,253

    PC NAME & Draw Battery Life

    I Orginally Posted these in a Thread but Threads Die So Here Ya Go

    Draw PC NAME:
    Code:
    char  pcName [MAX_COMPUTERNAME_LENGTH + 1];
    DWORD dwPcName = sizeof ( pcName );   
    
    if ( GetComputerName (pcName,&dwPcName)) cFont->DrawText(300,300,Green,pcName,D3DFONT_SHADOW);
    Draw Battery Life:
    Code:
    void Drawbatterylife( int x, int y )
    {
       SYSTEM_POWER_STATUS status;
       GetSystemPowerStatus( &status );
    
       int life = status.BatteryLifePercent;
       char szLife[256];
    
       sprintf(szLife,"%i",life);
       DrawString(x, y, White, m_font, szLife);
    
       switch (status.BatteryFlag) {
                  case 1: 
    		 DrawString( x, y + 17, White, m_font, "High");
    		 break;
    
    	      case 2: 
    	          DrawString( x, y + 17, White, m_font, "Low");
    	          break;
    
                   case 4: 
    	          DrawString( x, y + 17, White, m_font, "Criticial");
                      break;
    
    	       case 128: 
    		  DrawString( x, y + 17, White, m_font, "No system battery");
    		  break;
    
                   case 256: 
                      DrawString( x, y + 17, White, m_font, "Unknown status");
                      break;
    
    	}
    }

  24. #13
    Clarkie's Avatar
    Join Date
    May 2011
    Gender
    male
    Posts
    28
    Reputation
    20
    Thanks
    14
    My Mood
    Shocked
    Snippet Name: Clarkie's Detours
    Keywords: Detour, Hook, Hack, Source
    Description(Optional): Thank Topblast ^^
    Code:
    [highlight=c++]#pragma pack(push)
    #pragma pack(1)

    typedef struct {
    unsigned char bNop;
    unsigned char bPush;
    unsigned long dwAddress;
    unsigned char bRet;
    } TestJmp;


    typedef struct {
    TestJmp bOPS;
    unsigned char bNop;
    unsigned char bJmp;
    unsigned long dwAddress;
    } Tjmp;
    #pragma pack(pop)

    bool Hook(PBYTE pTargetAddr, PBYTE pNewAddr, VOID** pCallOrigAddress)
    {
    TestJmp recJump;
    Tjmp RetJump;
    DWORD dwProtect;
    *pCallOrigAddress = VirtualAlloc(0, sizeof(Tjmp), (MEM_COMMIT | MEM_RESERVE), PAGE_EXECUTE_READWRITE);
    if( pCallOrigAddress != NULL)
    {
    WriteNOP(&RetJump, sizeof(Tjmp));

    memcpy(&RetJump.bOPS, pTargetAddr, sizeof(TestJmp));
    RetJump.bNop = 0x90;
    RetJump.bJmp = 0xE9;
    RetJump.dwAddress = (DWORD(pTargetAddr) + (sizeof(TestJmp)+1))-DWORD(*pCallOrigAddress)-(((sizeof(TestJmp)*2)));
    memcpy(*pCallOrigAddress, &RetJump, sizeof(Tjmp));

    if( WriteNOP(pTargetAddr, (sizeof(TestJmp))) == true &&
    VirtualProtect(pTargetAddr, sizeof(TestJmp), PAGE_EXECUTE_READWRITE, &dwProtect) == TRUE)
    {
    WriteNOP(&recJump, sizeof(TestJmp));
    recJump.bNop = 0x90;
    recJump.bPush = 0x68;
    recJump.dwAddress = DWORD(pNewAddr);
    recJump.bRet = 0xC3;
    memcpy(pTargetAddr, &recJump, sizeof(TestJmp));
    VirtualProtect(pTargetAddr, sizeof(TestJmp), dwProtect, &dwProtect);
    return true;
    }
    }
    return false;
    }
    [/highlight]
    New Coder here to Rock your world.

    Email : Mr_clarkie@live.com


  25. #14
    Cyberdyne's Avatar
    Join Date
    Sep 2011
    Gender
    male
    Posts
    244
    Reputation
    -15
    Thanks
    33
    My Mood
    Inspired
    Okay, I'm bored. and I was reading a VC++ book

    Snippet Name: Calculate Gas Mileage
    Keywords: Arrays

    Code:

    Code:
    // Calculating gas mileage
    #include <iostream>
    #include <iomanip>
    
    using std::cin;
    using std::cout;
    using std::endl;
    using std::setw;
    using namespace std;
    
    int main()
    {
       const int MAX(20);                      // Maximum number of values
       double gas[ MAX ];                      // Gas quantity in gallons
       long miles[ MAX ];                      // Odometer readings
       int count(0);                           // Loop counter
       char indicator('y');                    // Input indicator
    
       while( ('y' == indicator || 'Y' == indicator) && count < MAX )
       {
          cout << endl << "Enter gas quantity: ";
          cin >> gas[count];                   // Read gas quantity
          cout << "Enter odometer reading: ";
          cin >> miles[count];                 // Read odometer value
    
          ++count;
          cout << "Do you want to enter another(y or n)? ";
          cin >> indicator;
       }
    
       if(count <= 1)                     // count = 1 after 1 entry completed
       {                                  // ... we need at least 2
          cout << endl << "Sorry - at least two readings are necessary.";
          cin.get();
          return 0;
       }
    
       // Output results from 2nd entry to last entry
       for(int i = 1; i < count; i++)
       {
         cout << endl
              << setw(2) << i << "."             // Output sequence number
              << "Gas purchased = " << gas[i] << " gallons" // Output gas
              << " resulted in "                 // Output miles per gallon
              << (miles[i] - miles[i - 1])/gas[i] << " miles per gallon.";
       }
    
       cout << endl;
       system("PAUSE");
       return 0;
    }




  26. The Following User Says Thank You to Cyberdyne For This Useful Post:

    punisher54 (09-19-2014)

  27. #15
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,132
    My Mood
    Dead
    Snippet Name: File Handling
    Keywords: Fuck,Assignments

    Code:
    #include <stdio.h>
    #include <iostream>
    #include <string>
    #include <fstream>
    #include <conio.h>
    using namespace std;
    void ReRun();
    bool CopyF(char *SourceFile,char *DestinationFile);
    void main()
    {
    	system("cls");
    	cout << "Enter 'r' to read contents of an existing file." << endl;
    	cout << "Enter 'w' to write contents to a new file." << endl;
    	cout << "Enter 'a' to append contents of an existing file." << endl;
    	cout << "Enter 'c' to copy a file to another place." << endl;
    	cout << "Enter 'm' to move a file to another place." << endl;
    	cout << "Enter 'd' to delete an existing file." << endl << endl;
    	cout << "Enter your choice: ";
    	char choice;
    	cin >> choice;
    	switch(choice)
    	{
    	case 'r':
    	case 'R':
    		{
    			cin.ignore();
    			char FileName[FILENAME_MAX];
    			cout << endl << "Enter the directory appended by the filename you want to read data from: ";
    			cin.getline(FileName,FILENAME_MAX);
    			fstream ReadonlyFile;
    			ReadonlyFile.open(FileName,ios::in);
    			if(ReadonlyFile.is_open())
    			{
    				while(!ReadonlyFile.eof())
    				{
    					string CurrentLine;
    					cout << endl;
    					while(getline(ReadonlyFile,CurrentLine))
    					{
    						cout << CurrentLine << endl;
    					}
    				}
    				cout << endl << "Finished reading data from " << FileName << ".";
    				ReRun();
    			}
    			else
    			{
    				if(!ReadonlyFile)
    				{
    					cout << "File '" << FileName << "' does not exists.";
    					ReRun();
    				}
    				else
    				{
    					cout << "There is a problem reading file '" << FileName << "'.";
    					ReRun();
    				}
    			}
    		}
    		break;
    	case 'w':
    	case 'W':
    		{
    			cin.ignore();
    			char FileName[FILENAME_MAX];
    			cout << endl << "Enter the directory appended by the name of the new file you want to create: ";
    			cin.getline(FileName,FILENAME_MAX);
    			fstream WriteonlyFile;
    			WriteonlyFile.open(FileName,ios::out);
    			if(WriteonlyFile.is_open())
    			{
    				cout << endl << "Enter the data you want to enter to the file. Write '[Close]' on a new line to end writing to the file: " << endl << endl;
    				string NewData;
    				while( (getline(cin,NewData)))
    				{
    					if(NewData=="[Close]")
    					{
    						WriteonlyFile.close();
    						ReRun();
    					}
    					WriteonlyFile << NewData << endl;
    				}
    				WriteonlyFile.close();
    			}
    			else
    			{
    				cout << "Unable to create a new file '" << FileName << "'.";
    				ReRun();
    			}
    		}
    		break;
    	case 'a':
    	case 'A':
    		{
    			cin.ignore();
    			char FileName[FILENAME_MAX];
    			cout << endl << "Enter the directory appended by the name of the new file you want to append contents to: ";
    			cin.getline(FileName,FILENAME_MAX);
    			fstream AppendToFile;
    			AppendToFile.open(FileName,ios::out | ios::app);
    			if(AppendToFile.is_open())
    			{
    				cout << endl << "Enter the data you want to append to the file. Write '[Close]' on a new line to end writing to the file: " << endl << endl;
    				string NewData;
    				while( (getline(cin,NewData)))
    				{
    					if(NewData=="[Close]")
    					{
    						AppendToFile.close();
    						ReRun();
    					}
    					AppendToFile << endl << NewData;
    				}
    				AppendToFile.close();
    			}
    			else
    			{
    				cout << "Unable to open file '" << FileName << "' for appending.";
    				ReRun();
    			}
    		}
    		break;
    	case 'c':
    	case 'C':
    		{
    cin.ignore();
    		char SourceFileName[FILENAME_MAX];
    		cout << endl << "Enter the directory appended by the name of the file you want to copy: ";
    		cin.getline(SourceFileName,FILENAME_MAX);
    		char DestinationFileName[FILENAME_MAX];
    		cout << endl << "Enter the directory appended by the name of the file you want the file to be copied: ";
    		cin.getline(DestinationFileName,FILENAME_MAX);
    		cout << endl << endl << "Copying " << SourceFileName << ". Please wait...";
    
    		if(CopyF(SourceFileName,DestinationFileName))
    		{
    			cout << endl <<  endl << "File " << SourceFileName << " successfully copied to " << DestinationFileName << ".";
    		}
    		ReRun();
    		}
    		
    		break;
    	case 'm':
    	case 'M':
    		{
    			cin.ignore();
    			char SourceFileName[FILENAME_MAX];
    			cout << endl << "Enter the directory appended by the name of the file you want to move: ";
    			cin.getline(SourceFileName,FILENAME_MAX);
    			char DestinationFileName[FILENAME_MAX];
    			cout << endl << "Enter the directory appended by the name of the file you want the file to be moved: ";
    			cin.getline(DestinationFileName,FILENAME_MAX);
    			cout << endl << endl << "Moving " << SourceFileName << ". Please wait...";
    
    			if(CopyF(SourceFileName,DestinationFileName))
    			{
    				remove(SourceFileName);
    				cout << endl << endl <<  "File " << SourceFileName << " successfully moved to " << DestinationFileName << ".";
    			}
    			ReRun();
    		}
    		break;
    	case 'd':
    	case 'D':
    		{
    			cin.ignore();
    			char FileToDelete[FILENAME_MAX];
    			cout << endl << "Enter the directory appended by the name of the file you want to delete: ";
    			cin.getline(FileToDelete,FILENAME_MAX);
    			cout << "Deleting File: " << FileToDelete << ". Please wait...";
    			if(remove(FileToDelete))
    			{
    				cout << endl << endl << "File " << FileToDelete << " successfully deleted.";
    			}
    			ReRun();
    		}
    		break;
    	default:
    		{
    			cout << endl << "You have not entered a valid choice. " << endl << "Do you want to show the choices again ?";
    			cout << endl << endl << "Press 'y' if you want the choices to be showed again. Press any other key and press enter to exit the program:";
    			cout << endl ;
    			char choice;
    			cin >> choice;
    			if( choice =='y' || choice == 'Y')
    				main();
    			else
    				exit(0);
    		}
    	}
    }
    bool CopyF(char *SourceFileName,char *DestinationFileName)
    {
    	fstream SourceFile;
    	fstream DestinationFile;
    	char *Buffer;
    	long SizeofFile;
    	SourceFile.open(SourceFileName,ios::in | ios::binary );
    	DestinationFile.open(DestinationFileName,ios::out | ios::binary );
    	SourceFile.seekg(0,ios::end);
    	SizeofFile = SourceFile.tellg();
    	SourceFile.seekg(0);
    	Buffer = new char[SizeofFile];
    	SourceFile.read(Buffer,SizeofFile);
    	DestinationFile.write(Buffer,SizeofFile);
    	delete[] Buffer;
    	DestinationFile.close();
    	SourceFile.close();
    	return true;
    }
    	void ReRun()
    {
    	cout << endl <<endl << "Do you wish to perform another operation ?" << endl;
    	cout << "Press 'y' to perform another operation or any other key to exit the program." << endl << endl;
    	cout << "Enter your choice: ";
    	char choice;
    	cin >> choice;
    	if(choice=='y' || choice == 'Y')
    		main();
    	else
    		exit(0);
    }
    My assignment. Sharing as it can be useful for others.
    Last edited by Hassan; 11-20-2011 at 06:39 AM.

Page 1 of 4 123 ... LastLast

Similar Threads

  1. [Snippet] ButtonHandler - A cleaner and easier way to add button clicking
    By Shakugan no Shana in forum Runescape Private Servers
    Replies: 0
    Last Post: 10-10-2011, 08:47 PM
  2. [Snippet]Controlable speed and gravity
    By apandhi in forum Combat Arms Hack Coding / Programming / Source Code
    Replies: 8
    Last Post: 02-21-2010, 05:40 PM
  3. [Tutorial/Snippet][VB6] Reading and writing INI Files
    By That0n3Guy in forum Visual Basic Programming
    Replies: 6
    Last Post: 10-26-2009, 05:31 PM
  4. Lineag2 and Ragnarok
    By suppaman in forum General Gaming
    Replies: 12
    Last Post: 01-01-2006, 04:07 PM
  5. i need short icq number pls and hack to wr..
    By BoneXDBreaker in forum WarRock - International Hacks
    Replies: 1
    Last Post: 12-26-2005, 05:08 PM

Tags for this Thread