static INT_PTR makeAvatar(WPARAM wParam, LPARAM) { debug("Searching for flash avatar...\n"); FLASHAVATAR* hFA = (FLASHAVATAR*)wParam; PROTO_AVATAR_INFORMATIONT AI = {0}; AI.cbSize = sizeof(AI); AI.hContact = hFA->hContact; AI.format = PA_FORMAT_UNKNOWN; flash_avatar_item key(hFA->hContact, *hFA, NULL); bool avatarOK = false; if(hFA->hContact) avatarOK = (int)CallProtoService(key.getProto(), PS_GETAVATARINFOT, 0, (LPARAM)&AI) == GAIR_SUCCESS; else { avatarOK = (int)CallProtoService(key.getProto(), PS_GETMYAVATART, (WPARAM)AI.filename, (LPARAM)255) == 0; if(avatarOK) { TCHAR* ext = _tcsrchr(AI.filename, _T('.')); if(ext && (_tcsicmp(ext, _T(".xml")) == 0)) AI.format = PA_FORMAT_XML; } } if (!avatarOK) return 0; debug("Avatar found...\n"); TCHAR url[MAX_PATH]; switch(AI.format) { case PA_FORMAT_SWF: _tcsncpy(url, AI.filename, SIZEOF(url)); break; case PA_FORMAT_XML: { int src = _topen(AI.filename, _O_BINARY | _O_RDONLY); if(src != -1) { char pBuf[2048]; char* urlBuf; _read(src, pBuf, sizeof(pBuf)); _close(src); urlBuf = strstr(pBuf, "<URL>"); if(urlBuf) _tcsncpy(url, _A2T(strtok(urlBuf + 5, "\r\n <")), SIZEOF(url)); else return 0; } else { return 0; } break; } default: destroyAvatar(wParam, 0); return 0; } Lock l(cs); flash_avatar_item *item = FlashList.find(&key); if (item) { debug("Flash already exists...\n"); hFA->hWindow = item->hFA.hWindow; ShowWindow(hFA->hWindow, SW_SHOW); if ( _tcsicmp(item->hFA.cUrl, url) != 0) { debug("Refreshing flash...\n"); IShockwaveFlash* flash = item->pFlash; mir_free(item->hFA.cUrl); FlashList.remove(item); delete item; prepareFlash(key.getProto(), url, *hFA, flash); } } else { debug("Creating new flash...\n"); RECT rc; GetWindowRect(hFA->hParentWindow, &rc); hFA->hWindow = CreateWindowEx(WS_EX_TOPMOST, _T("AtlAxWin"), _T(""), WS_VISIBLE | WS_CHILD, 0, 0, rc.right - rc.left, rc.bottom - rc.top, hFA->hParentWindow, (HMENU) 0, g_hInst, NULL); IShockwaveFlash* flash = NULL; debug("Creating flash instance...\n"); CoCreateInstance(__uuidof(ShockwaveFlash),0,CLSCTX_ALL, __uuidof(IShockwaveFlash), (void **)&flash); debug("Initialized.\n"); prepareFlash(key.getProto(), url, *hFA, flash); } return 0; }
int main(int argc, char **argv) { setLogLevel(LOGLEVEL_INFO); const char *device = DEFAULT_BASEBAND_DEVICE; unsigned int rate = 921600; char mode = '\0'; char *secpack = NULL; char *binfile = NULL; unsigned int start = 0; unsigned int length = 0; int ch; while ((ch = getopt(argc, argv, "D:B:b:n:s:r:xw:vh")) != -1) { switch (ch) { case 'v': setLogLevel(LOGLEVEL_TRACE); break; case 'x': mode = 'x'; break; case 'h': usage(); return 0; case 'D': device = optarg; break; case 'B': rate = (unsigned int) strtoul(optarg, NULL, 10); break; case 'b': start = (unsigned int) strtoul(optarg, NULL, 0); if (start < 0xa0000000 || start >= 0xb0000000) { start = (start & ~0xf0000000) | 0xa0000000; fprintf(stderr, "Start address is not in flash range, corrected to 0x%08x.\n", start); } break; case 'n': length = (unsigned int) strtoul(optarg, NULL, 0); break; case 's': secpack = optarg; break; case 'r': mode = 'r'; binfile = optarg; break; case 'w': mode = 'w'; binfile = optarg; break; default: usage(); return 1; } } resetBaseband(); int fd = openBaseband(device); if (fd == -1) { fprintf(stderr, "Can't open %s: %s", device, strerror(errno)); return 2; } setBaudRate(fd, rate); VersionPacket version = getBootVersion(fd); fprintf(stderr, "Got %d.%d, %s\n", version.major, version.minor, version.major <= 3 ? "GOOD." : "BAD. You need a secpack that is more recent than the installed firmware."); prepareFlash(fd); int err = 0; switch (mode) { case 'x': sendSecPack(fd, secpack); eraseBaseband(fd, start, start + length); endSecPack(fd); break; case 'r': err = readFlash(fd, binfile, start, length); break; case 'w': sendSecPack(fd, secpack); //eraseBaseband(fd, start, start + length); err = writeFlash(fd, binfile, start, length); endSecPack(fd); break; default: break; } close(fd); return err; }