Exemple #1
0
int WINAPI
WinMain(HINSTANCE inst, HINSTANCE inst2, LPSTR arg, int style)
{
  HRSRC nameres, shyres, setupres, dnlsiteres, dnlpathres;
  DWORD len = 0, rlen = 0, tid = 0;
  LPVOID data = NULL;
  TCHAR buf[BUFSIZE], path[BUFSIZE], cmd[BUFSIZE];
  HKEY hkey;
  BOOL shoes;
  DWORD plen;
  HANDLE payload, th;
  MSG msg;
  char *key = "SOFTWARE\\Hackety.org\\Shoes";
  //char *key = "Software\\Hackety.org\\Shoes";
 
  
  // Allow old String lookups first, then id# 
  nameres = FindResource(inst, "SHOES_FILENAME", RT_STRING);
  if (nameres == NULL) {
    nameres = FindResource(inst, MAKEINTRESOURCE(SHOES_APP_NAME), RT_STRING);
  }
  shyres = FindResource(inst, "SHOES_PAYLOAD", RT_RCDATA);
  if (shyres == NULL) {
    shyres = FindResource(inst, MAKEINTRESOURCE(SHOES_APP_CONTENT), RT_RCDATA);
  }
    
  if (nameres == NULL || shyres == NULL)
  {
	// Test - find a numbered resource

    if (nameres == NULL) {
	  MessageBox(NULL, "No Filename", "Magic Happens!!", MB_OK);
	  return 0;
    } else {
      // MessageBox(NULL, "This is an empty Shoes stub.", "shoes!! feel yeah!!", MB_OK);
      MessageBox(NULL, "Missing contents", "shoes!! feel yeah!!", MB_OK);
     return 0;
    }
  }

  setupres = FindResource(inst, "SHOES_SETUP", RT_RCDATA);  //msvc way
  if (setupres == NULL) {
    setupres = FindResource(inst, MAKEINTRESOURCE(SHOES_SYS_SETUP), RT_RCDATA);
  }
  plen = sizeof(path);
  if (!(shoes = reg_s((hkey=HKEY_LOCAL_MACHINE), key, "", (LPBYTE)&path, &plen)))
    shoes = reg_s((hkey=HKEY_CURRENT_USER), key, "", (LPBYTE)&path, &plen);

  if (shoes)
  {
    //sprintf(cmd, "%s\\shoes.exe", path);
    //printf("bfr: %s\n", cmd);
    //if (!file_exists(cmd)) shoes = FALSE;
    //memset(cmd, 0, BUFSIZE);
    if (!file_exists(path)) shoes = FALSE;
    memset(cmd, 0, BUFSIZE);
  }

  if (!shoes)
  {
	/*
	 * Need to download Shoes installer. Get the site and path
	 * from the resources and stuff in globals vars - wide strings
	*/
	LPVOID tmpptr;
	int tlen;
	dnlsiteres = FindResource(inst, MAKEINTRESOURCE(SHOES_DOWNLOAD_SITE), RT_STRING);
	tmpptr = LoadResource(inst, dnlsiteres);
    tlen = SizeofResource(inst, dnlsiteres);
    wcscpy(download_site, tmpptr+2); // cjc: I hate that +2 offset hack

	dnlpathres = FindResource(inst, MAKEINTRESOURCE(SHOES_DOWNLOAD_PATH), RT_STRING);
	tmpptr = LoadResource(inst, dnlpathres);
    tlen = SizeofResource(inst, dnlpathres);
    wcscpy(download_path, tmpptr+2); // more hack

    
    LPTHREAD_START_ROUTINE back_action = (LPTHREAD_START_ROUTINE)shoes_auto_setup;

    INITCOMMONCONTROLSEX InitCtrlEx;
    InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
    InitCtrlEx.dwICC = ICC_PROGRESS_CLASS;
    InitCommonControlsEx(&InitCtrlEx);

    dlg = CreateDialog(inst, MAKEINTRESOURCE(ASKDLG), NULL, stub_win32proc);
    ShowWindow(dlg, SW_SHOW);

    if (setupres == NULL)
      back_action = (LPTHREAD_START_ROUTINE)shoes_http_thread;

    if (!(th = CreateThread(0, 0, back_action, inst, 0, &tid)))
      return 0;

    while (WaitForSingleObject(th, 10) != WAIT_OBJECT_0)   
    {       
       //while (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))         
       while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))         
       {            
            TranslateMessage(&msg);           
            DispatchMessage(&msg);         
        }        
    }
    CloseHandle(th);

    if (!(shoes = reg_s((hkey=HKEY_LOCAL_MACHINE), key, "", (LPBYTE)&path, &plen)))
      shoes = reg_s((hkey=HKEY_CURRENT_USER), key, "", (LPBYTE)&path, &plen);
  }

  if (shoes)
  {
    GetTempPath(BUFSIZE, buf);
    char *str = shoes_str_load(inst, SHOES_APP_NAME);
    strcat(buf, (LPTSTR)str);
    //data = LoadResource(inst, nameres);
    //len = SizeofResource(inst, nameres);
    //strncat(buf, (LPTSTR)data+2, len);  // cjc hack

    payload = CreateFile(buf, GENERIC_READ | GENERIC_WRITE,
      FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
    len = SizeofResource(inst, shyres);
    if (GetFileSize(payload, NULL) != len)
    {
      HGLOBAL resdata = LoadResource(inst, shyres);
      data = LockResource(resdata);
      SetFilePointer(payload, 0, 0, FILE_BEGIN);
      SetEndOfFile(payload);
      WriteFile(payload, (LPBYTE)data, len, &rlen, NULL);
    }
    CloseHandle(payload);
#ifdef STUB_DEBUG    
    printf("payload %s, len: %d\n", buf, (int)len);
    printf("cmd: %s\n", path);
 #endif
    HINSTANCE retcode;
    retcode = ShellExecute(NULL, "open", path, buf, NULL, SW_SHOWNORMAL);
#ifdef STUB_DEBUG
    printf("Return: %i\n", (int)retcode);
#endif
  }

  return 0;
}
Exemple #2
0
int WINAPI
WinMain(HINSTANCE inst, HINSTANCE inst2, LPSTR arg, int style)
{
  HRSRC nameres, shyres, setupres;
  DWORD len = 0, rlen = 0, tid = 0;
  LPVOID data = NULL;
  TCHAR buf[BUFSIZE], path[BUFSIZE], cmd[BUFSIZE];
  HKEY hkey;
  BOOL shoes;
  DWORD plen;
  HANDLE payload, th;
  MSG msg;
  char *key = "SOFTWARE\\Hackety.org\\Shoes";

  nameres = FindResource(inst, "SHOES_FILENAME", RT_STRING);
  shyres = FindResource(inst, "SHOES_PAYLOAD", RT_RCDATA);
  if (nameres == NULL || shyres == NULL)
  {
    MessageBox(NULL, "This is an empty Shoes stub.", "shoes!! feel yeah!!", MB_OK);
    return 0;
  }

  setupres = FindResource(inst, "SHOES_SETUP", RT_RCDATA);
  plen = sizeof(path);
  if (!(shoes = reg_s((hkey=HKEY_LOCAL_MACHINE), key, "", (LPBYTE)&path, &plen)))
    shoes = reg_s((hkey=HKEY_CURRENT_USER), key, "", (LPBYTE)&path, &plen);

  if (shoes)
  {
    sprintf(cmd, "%s\\shoes.exe", path);
    if (!file_exists(cmd)) shoes = FALSE;
    memset(cmd, 0, BUFSIZE);
  }

  if (!shoes)
  {
    LPTHREAD_START_ROUTINE back_action = (LPTHREAD_START_ROUTINE)shoes_auto_setup;

    INITCOMMONCONTROLSEX InitCtrlEx;
    InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
    InitCtrlEx.dwICC = ICC_PROGRESS_CLASS;
    InitCommonControlsEx(&InitCtrlEx);

    dlg = CreateDialog(inst, MAKEINTRESOURCE(ASKDLG), NULL, stub_win32proc);
    ShowWindow(dlg, SW_SHOW);

    if (setupres == NULL)
      back_action = (LPTHREAD_START_ROUTINE)shoes_download_thread;

    if (!(th = CreateThread(0, 0, back_action, inst, 0, &tid)))
      return 0;

    while (WaitForSingleObject(th, 10) != WAIT_OBJECT_0)   
    {       
        while (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))         
        {            
            TranslateMessage(&msg);           
            DispatchMessage(&msg);         
        }        
    }
    CloseHandle(th);

    if (!(shoes = reg_s((hkey=HKEY_LOCAL_MACHINE), key, "", (LPBYTE)&path, &plen)))
      shoes = reg_s((hkey=HKEY_CURRENT_USER), key, "", (LPBYTE)&path, &plen);
  }

  if (shoes)
  {
    GetTempPath(BUFSIZE, buf);
    data = LoadResource(inst, nameres);
    len = SizeofResource(inst, nameres);
    strncat(buf, (LPTSTR)data, len);

    payload = CreateFile(buf, GENERIC_READ | GENERIC_WRITE,
      FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
    len = SizeofResource(inst, shyres);
    if (GetFileSize(payload, NULL) != len)
    {
      HGLOBAL resdata = LoadResource(inst, shyres);
      data = LockResource(resdata);
      SetFilePointer(payload, 0, 0, FILE_BEGIN);
      SetEndOfFile(payload);
      WriteFile(payload, (LPBYTE)data, len, &rlen, NULL);
    }
    CloseHandle(payload);

    sprintf(cmd, "%s\\..\\shoes.bat", path);
    ShellExecute(NULL, "open", cmd, buf, NULL, 0);
  }

  return 0;
}