SKIP to LINE 117

#include <iostream>
#include <windows.h>
#include <fstream.h>
#include <stdio.h>
#include <stdlib.h>


using namespace std;

char n , p , m , L , F , E;
int v , x , y , O , z , q , R;

int main()
{
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
    cout<<"This Program will help downgrade the iphone 3Gs provided you have an \n\n";
    cout<<"ECID/SHSH stored in cydia (open cydia & check). If not you are Out Of LUCK\n";
    cout<<"Check the top of cydia to see if you have one. Its written in green) \n\n";
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
    cout<<"Please Answer the Following Questions: \n \n";
    cout<<"Have you edited the hosts file yet?    1 = Yes ... 2 = N \n";
    cin>> x;
    cin.ignore();
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
    cout<<"Are you using a Mac or a PC?    1 = Mac ... 2 = PC \n";
    cin>> y;
    
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
    if (x == 2 && y == 2)
    {
         fstream hosts;
         hosts.open("C:/Windows/System32/drivers/etc/hosts", fstream::out | fstream::app);
         hosts<<"\n74.208.10.249		gs.apple.com";
         hosts.close();
         SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
         cout<<"Hosts file edited\n";
         cout<<"Are you Running Windows Vista/7?   1 = Yes ... 2 = No \n";
         cin>> z;
         if (z == 1)
         {
               cout<<"Is you Operating system 64x(x86) or 32 bit?\n\n";
               cout<<"1 = 64bit(x86)  ...   2 = 32 bit.. Enter your option now.\n";
               cin>> q;
         }
         SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
               if (q == 1)
               {
                     cout<<"Now Running Itunes 64-bit(x86)\n";
                     system("start iTunes.exe");
               }
               else if (q == 2)
               {
                   cout<<"Now Running Itunes 32-bit\n";
                   system ("start iTunes.exe");
               }
               else
               {
                   cout<<"Now running iTunes for Windows XP\n";
                   system ("start iTunes.exe");
               }
         
    }
    else if ( (x == 2) && (y == 1) )
    {
         fstream hosts;
         hosts.open("/etc/hosts", fstream::out | fstream::app);
         hosts<<"\n74.208.10.249		gs.apple.com";
         hosts.close();
         cout<<"Hosts file edited\n";
         cout<<"Opening iTunes for Mac to do the restore";
         system ("start iTunes.dmg");
    }
    else if ( (x == 1) && (y == 2))
    {
         cout<<"Are you Running Windows Vista/7?   1 = Yes ... 2 = No \n";
         cin>> v;
         if (v == 1)
         {
               cout<<"Is you Operating system 64x(x86) or 32 bit?\n\n";
               cout<<"1 = 64bit(x86)  ...   2 = 32 bit.. Enter your option now.\n";
               cin>> O;
         }
               if (O == 1)
               {
                     cout<<"Now Running Itunes 64-bit(x86)\n";
                     system("start iTunes.exe");
               }
               else if (O == 2)
               {
                   cout<<"Now Running Itunes 32-bit\n";
                   system ("start iTunes.exe");
               }
               else
               {
                   cout<<"Now running iTunes for Windows XP\n";
                   system ("start iTunes.exe");
               }
    }    
    else if ( (x == 1) && (y == 1))
    {
         cout<<"Opening iTunes for Mac to do the restore";
         system ("start iTunes.dmg");
    }
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
    
    Sleep(4000);
    cout<<"Opening Itunes for restore =)\n";
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
    cout<<"Press L when Itunes has finished loading(opening)... Followed by {Enter}\n";
    std::cin >> L;
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
    
    
    
//create two structures to hold our Main Window handle
//and the Button's handle
HWND WindowHandle;
HWND ButtonHandle;

//this window's caption is "iTunes", so we search for it's handle using the FindWindow API
WindowHandle = FindWindow(NULL, "iTunes");

//the Button's Caption is "Restore" and it is a "Button". SPYXX.exe that comes with Microsoft Visual Studio will reveal this information to you
ButtonHandle = FindWindowEx(WindowHandle, 0, "Button", "&Restore");

//send a message to the button that you are "clicking" it. 
SendMessage (ButtonHandle, BM_CLICK, 0 , 0);


   
    
    
    
    
    
    cout<<"Hold the Shift/Option buttons on the keyboard! and click restore\n";
    cout<<"Wait for Itunes to Restore the phone...\n\n";
    Sleep(3000);
    
    
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
    cout<<"You may get an error such as 1015... No problem! \n";
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
    cout<<"ERROR 1015? - Just restore again... You WILL get the error a second time!\n";
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
    cout<<"If you get 16XX while in DFU, Put the device in Recovery-mode and restore\n";
    cout<<"Or try IREB by Ih8Sn0w\n\n";
    Sleep(4000);
    
    
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
    cout<<"When finished restoring press the F button... Followed by {Enter}\n";
    std::cin >> F;
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
    cout<<"Run quickpwn 2.2 OR Blackra1n OR Redsn0w 0.94 to boot the iphone\n\n";
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
    cout<<"This will get the iphone out of recovery mode and boot it to springboard\n\n";
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
    cout<<"If you get *Iphone not ellegible for this build* YOU DONT HAVE AN ECID/SHSH\n\n";
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
    cout<<"Finished restoring? Want to return the hosts file back to the way it was?\n";
    cout<<"1 = Yes ......   2 = No\n";
    cin>> R;
    cout<<"Any Problems then join irc.xsellize.com, channel: #xsellize \n";
    
    
    cout<<"Created by Headspin AKA Iphone_d\n\n";
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
    cout<<"Press Any-Key to exit\n";
    std::cin >> E;
    Sleep(1500);
return 0;
}

My problem is I cannot get the restore button in itunes to click.... Im trying to get the program to click the iphone in the listbox to the left and then click the restore button but it wont click...

Ive used spy++ to grab the button caption and class: button and i tried finding control id to click it but cant make use of anything... it just wont click! ={ Point of it is to click the restore button in itunes...

Recommended Answers

All 4 Replies

Can someone please tell me how to click a button using its handle?! Im confused... I have a button caption, i know its a button and i have its handle...

I have a button caption, i know its a button and i have its handle...

Are you sure about that? FindWindowxx() may very well return NULL. So, first thing to do, would be to add code that checks that you actually receive handles to those windows. Upon failure, you may get some insight by calling GetLastError() to see what the error code is.

it finds the window and everything ive used spy++ to make sure i got the right window and stuff it just wont click the button.... is there a way to click the button using its handle? cuz there is the restore button as well which is actually the maximize button and then there is another button called restore but its actually to restore the phone itself...

so i wanted to know how to click a button using its handle.

Well, there definitely is. First lets explain how a child window (like a button) reacts when pressed in the window properly. We know it is run through the WndProc function and uses 4 variables, HWND, MSG, WPARAM, LPARAM. Knowing what the button sends when pressed, you can send a message manually as if it was pressed. msg should always be the WM_COMMAND since it is a child window and WPARAM should be its ID. the HWND will be the parent windows.

Also a better way would be to sniff the window messages when you press the button and see what exactly is send. There are window message sniffers out there that can do this for you, you just have to go through the other messages sent to find the one you want. Shouldn't be too hard, you can ignore all messages that are not WM_COMMAND. This will help you to send a manual SendMessage that will enable you to press the button virtually.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.