HRESULT FromBase64(LPSTR pszString, BYTE **ppbBinary) { HRESULT hRes=S_OK; DWORD cbBinary; hRes = CryptStringToBinaryA(pszString, 0, CRYPT_STRING_BASE64, NULL, &cbBinary, NULL, NULL); if(FAILED(hRes)){ dbgout("[sync] failed at CryptStringToBinaryA: %d\n", GetLastError()); return E_FAIL; } *ppbBinary = (BYTE *) malloc(cbBinary+1); if (ppbBinary==NULL){ dbgout("[sync] failed at allocate buffer: %d\n", GetLastError()); return E_FAIL; } hRes = CryptStringToBinaryA(pszString, 0, CRYPT_STRING_BASE64, *ppbBinary, &cbBinary, NULL, NULL); if(FAILED(hRes)){ dbgout("[sync] send failed at CryptStringToBinaryA: %d\n", GetLastError()); return E_FAIL; } *((char *)((*ppbBinary)+cbBinary)) = 0; return hRes; }
void init_queue(){ dbgout("ATA: Initialising queue...\n"); queue=new ata_queue(); dbgpf("ATA: queue at: %p\n", queue); dbgout("ATA: Syncing...\n"); ata_sync(); }
void SmallImageTest() { CPUTracker *tracker = new CPUTracker(50,50, 16); GenerateTestImage(ImageData(tracker->srcImage, tracker->GetWidth(), tracker->GetHeight()), tracker->width/2,tracker->height/2, 9, 0.0f); FloatToJPEGFile("smallimg.jpg", tracker->srcImage, tracker->width, tracker->height); vector2f com = tracker->ComputeMeanAndCOM(0); dbgout(SPrintf("COM: %f,%f\n", com.x, com.y)); vector2f initial(25,25); bool boundaryHit = false; vector2f xcor = tracker->ComputeXCorInterpolated(initial, 2, 16, boundaryHit); dbgout(SPrintf("XCor: %f,%f\n", xcor.x, xcor.y)); //assert(fabsf(xcor.x-15.0f) < 1e-6 && fabsf(xcor.y-15.0f) < 1e-6); int I=4; vector2f pos = initial; for (int i=0;i<I;i++) { bool bhit; vector2f np = tracker->ComputeQI(pos, 1, 32, 4, 1, 1, 16, bhit); dbgprintf("qi[%d]. New=%.4f, %.4f;\tOld=%.4f, %.4f\n", i, np.x, np.y, pos.x, pos.y); } FloatToJPEGFile("debugimg.jpg", tracker->GetDebugImage(), tracker->width, tracker->height); delete tracker; }
uint8_t read_key() { REQUIRE(__readeflags() & rflag_mask_if); // Very crude translation of scan keys in Scan Code Set 1 for (;;) { auto sk = get_scan_key(); if (sk == 0xE0) { auto sk2 = get_scan_key(); dbgout() << "[ps2] ignoring scan key = 0xE0 0x" << as_hex(sk2) << "\n"; continue; } else if (sk == 0xE1) { auto sk2 = get_scan_key(); auto sk3 = get_scan_key(); dbgout() << "[ps2] ignoring scan key = 0xE1 0x" << as_hex(sk2) << " 0x" << as_hex(sk3) << "\n"; continue; } // Only act on key release as they are not repeated const bool released = (sk & 0x80) != 0; if (!released) continue; sk &= ~0x80; if (sk < scan_code_set_1_size) { const auto k = scan_code_set_1[sk]; if (k != sc_invalid) { return k; } } dbgout() << "[ps2] ignoring scan key = 0x" << as_hex(sk) << "\n"; } }
HRESULT TunnelClose() { HRESULT hRes=S_OK; int iResult; if(SUCCEEDED(TunnelIsUp())) { hRes=TunnelSend("[notice]{\"type\":\"dbg_quit\",\"msg\":\"dbg disconnected\"}\n"); if(FAILED(hRes)) return hRes; } if(!(g_Sock == INVALID_SOCKET)){ iResult = closesocket(g_Sock); g_Sock = INVALID_SOCKET; if (iResult == SOCKET_ERROR) dbgout("[sync] closesocket failed with error %d\n", WSAGetLastError()); } dbgout("[sync] sync is off\n"); g_Synchronized=FALSE; WSACleanup(); return hRes; }
void bo_snmp_main(char *ip[], int n) { int stop = 1; int exec = -1, sock = -1, i = 0; struct OPT_SWITCH *o_sw = NULL; bo_log("SNMP(monitor) START"); bo_snmp_lock_mut(); exec = bo_init_snmp(); bo_snmp_unlock_mut(); if(exec == -1) { bo_log("bo_snmp_main ERROR can't create data for run snmp"); goto exit; } bo_snmp_lock_mut(); exec = bo_crt_optSwitch(ip, n); bo_snmp_unlock_mut(); if(exec == -1) { bo_log("bo_snmp_main ERROR can't create data for OPT_SWITCH"); goto exit; } for(i = 0; i < n; i++) { o_sw = tab_sw + i; dbgout("bo_snmp_mng INFO SWITCH IP-%d[%s]\n", i, o_sw->ip); bo_log("bo_snmp_mng INFO SWITCH IP-%d[%s]", i, o_sw->ip); } sock = bo_udp_sock(); if(sock == 0) { bo_log("bo_snmp_main ERROR can't create socket for run snmp"); goto exit; } while(stop == 1) { sleep(10); dbgout("\n ==================== \n"); for(i = 0; i < n; i++) { o_sw = tab_sw + i; bo_snmp_lock_mut(); bo_checkSwitch(sock, o_sw); if(bo_snmp_isChange() == 1) { bo_snmp_get_tab(); bo_prt_switch(i); } bo_snmp_unlock_mut(); } dbgout("\n ==================== \n"); } exit: bo_snmp_lock_mut(); bo_del_snmp(); bo_del_tab_switch(); bo_snmp_unlock_mut(); bo_log("SNMP monitor END"); }
int main(int argc, char **argv) { mtrace(); dbgout("START -> %s\n", *argv); bo_log("TEST"); dbgout("END\n"); muntrace(); return 0; }
int main(int argc, char **argv) { /* mtrace(); */ dbgout("START master-> %s\n", *argv); bo_master_main(argc, argv); dbgout("END\n"); /* muntrace(); */ return 0; }
HRESULT TunnelReceive(int *lpNbBytesRecvd, LPSTR *lpBuffer) { HRESULT hRes=S_OK; int iResult; errno_t err; *lpNbBytesRecvd = 0; if(FAILED(hRes=TunnelIsUp())) { dbgout("[sync] TunnelReceive: tunnel is not available\n"); return hRes; } iResult = recv(g_Sock, RecvBuffer, MAX_SEND, 0); if ( iResult == SOCKET_ERROR ) { iResult = WSAGetLastError(); if (iResult == WSAEWOULDBLOCK) { return hRes; } else { dbgout("[sync] recv failed with error: %d, 0x%x\n", iResult, g_Sock); WsaErrMsg(iResult); goto error_close; } } else if ( iResult == 0 ) { dbgout("[sync] recv: connection closed\n"); goto error_close; } *lpBuffer = (LPSTR) calloc(iResult+1, sizeof(CHAR)); if (lpBuffer == NULL) { dbgout("[sync] failed at allocate buffer: %d\n", GetLastError()); return E_FAIL; } err = memcpy_s(*lpBuffer, iResult+1, RecvBuffer, iResult); if (err) { dbgout("[sync] memcpy_s failed to copy received buffer\n"); free(*lpBuffer); *lpBuffer = NULL; hRes = E_FAIL; } else { *lpNbBytesRecvd = iResult; } return hRes; error_close: g_Synchronized = FALSE; TunnelClose(); return E_FAIL; }
int main(void) { int i; uint64_t dmaPageTable[MAX_PAGE_TABLE_SIZE] = { 0 }; struct blabuffer* outBufferDescriptor; struct blabuffer* inBufferDescriptor; g.getPhysicalSegment = f; outBufferDescriptor = &g; inBufferDescriptor = &g; #if 0 for (int i = 0; i < 25; i++) { printf ("offset %i ", (i < 2) ? 0 : 8192 * (((i-2)/8)+1)); printf ("first %i step %i\n", (i < 2) ? 32 * i : 32 * ((i-2) % 8), (i < 2) ? 64 : 256); } #endif // AES In, stereo for (i = 0; i < NUM_AES_PAGES; i++) { dmaPageTable[i+MAX_PAGE_TABLE_SIZE/2] = inBufferDescriptor->getPhysicalSegment(i*HARDWARE_PAGE_SIZE, 0); dbgout(i+MAX_PAGE_TABLE_SIZE/2, inBufferDescriptor->getPhysicalSegment(i*HARDWARE_PAGE_SIZE, 0), "AES IN"); } // MADI In, 192 channels for (i = 0; i < NUM_MADI_PAGES; i++) { dmaPageTable[i+MAX_PAGE_TABLE_SIZE/2+NUM_DMA_CH_PAGES] = inBufferDescriptor->getPhysicalSegment((i+NUM_AES_PAGES)*HARDWARE_PAGE_SIZE, 0); dbgout(i+MAX_PAGE_TABLE_SIZE/2+NUM_DMA_CH_PAGES, inBufferDescriptor->getPhysicalSegment((i+NUM_AES_PAGES)*HARDWARE_PAGE_SIZE, 0), "MADI IN"); } // AES Out, stereo for (i = 0; i < NUM_AES_PAGES; i++) { dmaPageTable[i] = outBufferDescriptor->getPhysicalSegment(i*HARDWARE_PAGE_SIZE, 0); dbgout(i, outBufferDescriptor->getPhysicalSegment(i*HARDWARE_PAGE_SIZE, 0), "AES OUT"); } // Phones Out, stereo for (i = 0; i < NUM_AES_PAGES; i++) { dmaPageTable[i+1*NUM_DMA_CH_PAGES] = outBufferDescriptor->getPhysicalSegment((i+1*NUM_AES_PAGES)*HARDWARE_PAGE_SIZE, 0); dbgout(i+1*NUM_DMA_CH_PAGES, outBufferDescriptor->getPhysicalSegment((i+1*NUM_AES_PAGES)*HARDWARE_PAGE_SIZE, 0), "Phones OUT"); } // MADI Out, 192 channels for (i = 0; i < NUM_MADI_PAGES; i++) { dmaPageTable[i+2*NUM_DMA_CH_PAGES] = outBufferDescriptor->getPhysicalSegment((i+2*NUM_AES_PAGES)*HARDWARE_PAGE_SIZE, 0); dbgout(i+2*NUM_DMA_CH_PAGES, outBufferDescriptor->getPhysicalSegment((i+2*NUM_AES_PAGES)*HARDWARE_PAGE_SIZE, 0), "MADI OUT"); } printf ("Full pagetable:\n"); for (i = 0 ; i < MAX_PAGE_TABLE_SIZE; i++) { printf ("PT %i %i\n", i, dmaPageTable[i]); } return 0; }
static void bo_prt_switch(int n) { int i = 0; struct OPT_SWITCH *o_sw = (tab_sw + n); struct PortItem *port = NULL; for(; i < BO_OPT_SW_PORT_N; i++) { port = (o_sw->ports + i); dbgout("%d:ip[%d][%s] ", i, strlen(o_sw->ip), o_sw->ip ); dbgout("flg[%d] link[%d] speed[%d] descr[%s]\n", port->flg, port->link, port->speed, port->descr); } }
/* Become process lead and detach from tty Code lifted from fetchmail 5.0.0 */ void TRawServer::Daemonize( void ) { /* Ignore BSD terminal stop signals */ signal(SIGTTOU, SIG_IGN); signal(SIGTTIN, SIG_IGN); signal(SIGTSTP, SIG_IGN); /* Change to root dir so we don't hold any mount points open */ if( chdir( "/" ) != 0 ) { dbgout( "chdir failed (%s)", strerror(errno) ); } /* * In case we were not started in the background, fork and let the parent exit. * Guarantees that the child is not a process group leader */ pid_t childpid; if( (childpid = fork()) < 0 ) { dbgout( "fork failed (%s)", strerror(errno) ); return; } else if( childpid > 0 ) { exit( 0 ); /* parent */ } /* * Make ourselves the leader of a new process group with no controlling terminal * POSIX makes this soooo easy to do */ if( setsid() < 0 ) { dbgout( "setsid failed (%s)", strerror(errno) ); return; } /* lose controlling tty */ signal( SIGHUP, SIG_IGN ); if( (childpid = fork()) < 0 ) { dbgout( "fork failed (%s)", strerror(errno) ); return; } else if( childpid > 0 ) { exit( 0 ); /* parent */ } }
int main(int argc , char* argv[]) { int fd = -1; int ret = 0; int req; fd = open("/dev/nfc", O_RDWR); if (fd < 0) { perror("Open nfc fail:"); return -1; } ioc_write_arg.data = buffer; ioc_write_arg.size = 2048 - 0x14; /* About addr_l and addr_h: */ /* According to the manual, the low 16bits of addr_l are for inside page address,so, pay attention when giving values of both variables */ ioc_write_arg.addr_l = 0x10000; ioc_write_arg.addr_h = 0; req = NFC_IOC_WRITE; ret = ioctl( fd, req, &ioc_write_arg); dbgout("ioctl write size:0x%x ret:0x%x\n", ioc_write_arg.size, ret); #if 0 req = NFC_IOC_CMD_RESET; ioctl( fd, req, NULL ); dbgout("ioctl req:0x%x\n", req ); #endif #if 0 req = NFC_IOC_CMD_READID; ioctl( fd, req, &ret ); dbgout("ioctl req:0x%x ret:0x%x\n", req, ret); #endif #if 0 req = NFC_IOC_CMD_STATUS; ioctl( fd, req, &ret ); dbgout("ioctl req:0x%x ret:0x%x\n", req, ret); #endif close(fd); return 0; }
uint64_t shm_map(uint64_t id, void *addr, uint32_t offset, size_t pages, uint32_t flags){ hold_lock hl(shm_lock); dbgout("MM2: Creating SHM mapping.\n"); if(!spaces->has_key(id)) { dbgpf("MM2: No such SHM space %i\n", (int)id); return 0; } if((uint32_t)addr % MM2_Page_Size != 0){ dbgpf("MM2: Mapping address (%p) is not page-aligned!\n", addr); return 0; } if(offset % MM2_Page_Size != 0){ dbgpf("MM2: Offset (%i) is not a multiple of page size.\n", (int)offset); return 0; } uint64_t ret = ++mapping_id_counter; current_pagedir->free_pages(addr, pages); for(uint32_t i = (uint32_t)addr; i < (uint32_t)addr + (pages * MM2_Page_Size); i += MM2_Page_Size){ current_pagedir->guard_page_at((void*)i); } current_pagedir->add_region(addr, pages * MM2_Page_Size, &shm_pf_handler, ret); shm_mapping *mapping = new shm_mapping(); mapping->space = (*spaces)[id]; mapping->addr = addr; mapping->offset = offset; mapping->pages = pages; mapping->pid = proc_current_pid; (*mappings)[ret] = mapping; dbgpf("MM2: Mapped %i pages from SHM space %i offset %x to address %p as mapping ID: %i\n", (int)pages, (int)id, (unsigned)offset, addr, (int)ret); return ret; }
void TestBoundCheck() { CPUTracker *tracker = new CPUTracker(32,32, 16); bool boundaryHit; for (int i=0;i<10;i++) { float xp = tracker->GetWidth()/2+(rand_uniform<float>() - 0.5) * 20; float yp = tracker->GetHeight()/2+(rand_uniform<float>() - 0.5) * 20; GenerateTestImage(ImageData(tracker->srcImage, tracker->GetWidth(), tracker->GetHeight()), xp, yp, 1, 0.0f); vector2f com = tracker->ComputeMeanAndCOM(); dbgout(SPrintf("COM: %f,%f\n", com.x-xp, com.y-yp)); vector2f initial = com; boundaryHit=false; vector2f xcor = tracker->ComputeXCorInterpolated(initial, 3, 16, boundaryHit); dbgprintf("XCor: %f,%f. Err: %d\n", xcor.x-xp, xcor.y-yp, boundaryHit); boundaryHit=false; vector2f qi = tracker->ComputeQI(initial, 3, 64, 32, ANGSTEPF, 1, 10, boundaryHit); dbgprintf("QI: %f,%f. Err: %d\n", qi.x-xp, qi.y-yp, boundaryHit); } delete tracker; }
void *get10thr(void *arg) { unsigned char msg[21] = {0}; unsigned char buf[30] = {0}; int i = 0, exec = -1, j = 0; const int err = -1; while(i < 2000) { exec = bo_getFifoVal(buf, 30); if(exec != -1) { sprintf(msg, "%18d", i); // printf("[%d]get10thr[%d][%s]\n", i, exec, buf); if(exec != 18) { bo_log("get10thr() return length value from FIFO"); goto error; } for(j = 0; j < exec; j++) { if(buf[j]!= msg[j]) { bo_log("get10thr() return bad value from FIFO"); bo_log("value[%s] msg[%s]", buf, msg); goto error; } } i++; } else { // bo_log("get10thr fifo no data"); } } if(err == 1) { error: dbgout("!!! ERROR !!!"); bo_log(" ERROR "); } }
void TRawServer::Run( void ) { srand( time(&curTime) ); Logger::open("/var/log/crowdspider.log", 1); LOG(1)("crowdspider is now started.\n"); if( Init() ) { bool running = true; while( running ) { int rc = m_poller->poll(200); if( rc < 0 ) { dbgout("poll failed:error=%i (%s)",errno,strerror(errno)); break; } if( rc == 0 ) {} if( rc > 0 ) { TPollEvent * pevents = m_poller->getPollEvents(); handleEvent(pevents, rc); } } } Exit(); LOG(1)("crowdspider is now stoped.\n"); }
virtual void do_send_packet(const void* data, uint32_t length) override { REQUIRE(length <= 1500); if (!(ioreg(reg::STATUS) & STATUS_LU)) { dbgout() << "[i825x] Link not up. Dropping packet\n"; return; } // prepare descriptor auto& td = tx_desc_[tx_tail_]; tx_tail_ = (tx_tail_ + 1) % num_tx_descriptors; REQUIRE(td.upper.fields.status == 0); td.buffer_addr = virt_to_phys(data); td.lower.data = length | TXD_CMD_RS | TXD_CMD_EOP | TXD_CMD_IFCS; td.upper.data = 0; _mm_mfence(); ioreg(reg::TDT0, tx_tail_); //dbgout() << "Waiting for packet to be sent.\n"; for (uint32_t timeout = 100; !td.upper.fields.status; ) { __halt(); if (!timeout--) { #if 0 // Dump stats constexpr uint32_t nstats = 0x100 / 4; static uint32_t stats[nstats]; for (uint32_t i = 0; i < nstats; ++i) { stats[i] += ioreg(static_cast<reg>(0x4000 + i * 4)); dbgout() << as_hex(stats[i]); dbgout() << ((i % 8 == 7) ? '\n' : ' '); } #endif dbgout() << "Transfer NOT done. Timed out! STATUS = " << as_hex(ioreg(reg::STATUS)) << " TDH = " << ioreg(reg::TDH0) << " TDT " << ioreg(reg::TDT0) << "\n"; #if 0 for (uint32_t i = 0; i < num_tx_descriptors; ++i) { dbgout() << as_hex(tx_desc_[i].buffer_addr) << " "; dbgout() << as_hex(tx_desc_[i].lower.data) << " "; dbgout() << as_hex(tx_desc_[i].upper.data) << " "; dbgout() << ((i % 3 == 2) ? '\n' : ' '); } dbgout() << "\n"; #endif return; } } //dbgout() << "[i825x] TX Status = " << as_hex(td.upper.fields.status) << "\n"; REQUIRE(td.upper.fields.status == TXD_STAT_DD); td.upper.data = 0; // Mark ready for re-use REQUIRE(ioreg(reg::TDH0) == ioreg(reg::TDT0)); }
void OnePixelTest() { CPUTracker* tracker = new CPUTracker(32,32, 16); tracker->GetPixel(15,15) = 1; dbgout(SPrintf("Pixel at 15,15\n")); vector2f com = tracker->ComputeMeanAndCOM(); dbgout(SPrintf("COM: %f,%f\n", com.x, com.y)); vector2f initial(15,15); bool boundaryHit = false; vector2f xcor = tracker->ComputeXCorInterpolated(initial,2, 16, boundaryHit); dbgout(SPrintf("XCor: %f,%f\n", xcor.x, xcor.y)); assert(xcor.x == 15.0f && xcor.y == 15.0f); delete tracker; }
static int GetDataBlock(SDL_RWops *src, unsigned char *buf) { unsigned char count; if (!ReadOK(src, &count, 1)) { dbgout("error in getting DataBlock size\n"); return -1; } ZeroDataBlock = count == 0; if ((count != 0) && (!ReadOK(src, buf, count))) { dbgout("error in reading DataBlock\n"); return -1; } return count; }
int IMG_SavePNG(const char* filename, SDL_Surface* surf) { unsigned char** ss_rows = NULL; SDL_Surface* ss_surface = NULL; int i = 0; dbgout("Writing..\n"); int result = 0; if (!surf) { dbgout("Invalid SDL_Surface\n"); result = -1; } else { dbgout("Performing Lock\n"); /*Create a surface formatted just for PNG saving since it must be 24bit*/ ss_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, surf->w, surf->h, 24, RMASK, GMASK, BMASK, AMASK); if (!ss_surface) { dbgout("Failed to allocate PNG surface\n"); return -1; } dbgout("Making Rows\n"); ss_rows = (unsigned char**)malloc(sizeof(unsigned char*) * surf->h); dbgout("Blitting\n"); SDL_BlitSurface(surf, NULL, ss_surface, NULL); /* Render the pic onto the formatted surface */ dbgout("Lock and copy\n"); if (SDL_MUSTLOCK(surf)) SDL_LockSurface(surf); for (i = 0; i < surf->h; i++) { ss_rows[i] = ((unsigned char*)ss_surface->pixels) + i * ss_surface->pitch; } if (SDL_MUSTLOCK(surf)) SDL_UnlockSurface(surf); dbgout("Writing\n"); write_png(filename, ss_rows, surf->w, surf->h, PNG_COLOR_TYPE_RGB, 8); dbgout("Freeing\n"); free(ss_rows); SDL_FreeSurface(ss_surface); } dbgout("Done\n"); return result; }
void isr() { const auto icr = ioreg(reg::ICR); ioreg(reg::ICR, icr); // clear pending interrupts constexpr uint32_t ICR_INT_ASSERTED = 1U << 31; // Reported by bochs if (icr & ~(ICR_RXT0 | ICR_TXDW | ICR_INT_ASSERTED)) { // Only report interesting IRQs dbgout() << "[i825x] IRQ. ICR = " << as_hex(icr) << "\n"; } }
void isr() { const auto st = status(); REQUIRE(st & status_mask_output_full); if (!buffer_.full()) { buffer_.push(data()); } else { dbgout() << "[ps2] Keyboard buffer is full!!\n"; } }
HRESULT WsaErrMsg(int LastError) { HRESULT hRes=S_OK; switch(LastError){ case WSAECONNRESET: dbgout(" -> Connection reset by peer\n"); break; case WSAENOTCONN: dbgout(" -> Socket is not connected\n"); break; case WSAECONNABORTED: dbgout(" -> Software caused connection abort\n"); break; default: break; } return hRes; }
static void logOk(struct KA_log_param *p) { int exec = -1; unsigned char msg[] = " OK"; int i = 0; dbgout("len[%d]\nlog[", p->len); for(; i < p->len; i++) { dbgout("%c", *(p->buf + i) ); } dbgout("]\n"); exec = bo_sendAllData(p->sock, msg, 3); if(exec == -1) { bo_log("logOk() errno[%s]", strerror(errno)); p->len = -1; p->status = LOGERR; } else { p->status = LOGQUIT; } }
//------------------------------------------------ // 構築(new & constructor) //------------------------------------------------ PValRef* PValRef::New( int vflag ) { PValRef* self = (PValRef*)hspmalloc( sizeof(PValRef) ); if ( vflag > 0 ) PVal_init( &self->pval, vflag ); self->cntRefed = 0; PVALREF_DBGCODE( self->id = PValRef::stt_counter ++; // 参照カウンタ表示用にID値をつける dbgout( "[%d] new!", self->id ); ) return self;
static int DoExtension(GifFrame* frame, SDL_RWops *src, int label) { static unsigned char buf[256]; char *str; switch (label) { case 0x01: /* Plain Text Extension */ dbgout("Plain Text Extension\n"); break; case 0xff: /* Application Extension */ dbgout("Application Extension\n"); break; case 0xfe: /* Comment Extension */ dbgout("Comment Extension\n"); while (GetDataBlock(src, (unsigned char *) buf) != 0) ; return FALSE; case 0xf9: /* Graphic Control Extension */ dbgout("Graphic Control Extension\n"); (void) GetDataBlock(src, (unsigned char *) buf); frame->disposal = (buf[0] >> 2) & 0x7; frame->inputFlag = (buf[0] >> 1) & 0x1; frame->delayMs = LM_to_uint(buf[1], buf[2]); if ((buf[0] & 0x1) != 0) frame->transparent = buf[3]; while (GetDataBlock(src, (unsigned char *) buf) != 0) ; return FALSE; default: dbgout("Unknown Extension: %s (0x%02x)\n", (char*)buf, label); break; } while (GetDataBlock(src, (unsigned char *) buf) != 0) ; return FALSE; }
/* Supported color types shall include: PNG_COLOR_TYPE_GRAY (bit depths 1, 2, 4, 8, 16) PNG_COLOR_TYPE_GRAY_ALPHA (bit depths 8, 16) PNG_COLOR_TYPE_PALETTE (bit depths 1, 2, 4, 8) PNG_COLOR_TYPE_RGB (bit depths 8, 16) PNG_COLOR_TYPE_RGB_ALPHA (bit depths 8, 16) PNG_COLOR_MASK_PALETTE PNG_COLOR_MASK_COLOR PNG_COLOR_MASK_ALPHA */ int write_png(const char *file_name, png_bytep *rows, int w, int h, int colortype, int bitdepth) { /*if ( IMG_InitPNG() < 0 ) { return NULL; }*/ png_structp png_ptr = NULL; png_infop info_ptr = NULL; FILE* fp = NULL; const char *doing = "open for writing"; int error = 0; fp = fopen(file_name, "wb"); /* if (!fp) return 0; fprintf(fp, "Dicks\n"); fclose(fp); return 0;*/ if (!fp) goto fail; doing = "create png write struct"; if (!(png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL))) goto fail; doing = "create png info struct"; if (!(info_ptr = png_create_info_struct(png_ptr))) goto fail; if (setjmp(png_jmpbuf(png_ptr))) goto fail; /* png_set_write_fn(png_ptr, fp, png_write_data); Using standard C FILE*, don't need to modify*/ doing = "init IO"; png_init_io(png_ptr, fp); doing = "write header"; png_set_IHDR(png_ptr, info_ptr, w, h, bitdepth, colortype, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); doing = "write info"; png_write_info(png_ptr, info_ptr); doing = "write image"; png_write_image(png_ptr, rows); doing = "write end"; png_write_end(png_ptr, NULL); out: if (png_ptr) png_destroy_write_struct(&png_ptr, (png_infopp)NULL); if (fp) fclose(fp); return error; fail: dbgout("Write_png: could not %s\n", doing); error = -1; goto out; }
HRESULT TunnelSend(PCSTR Format, ...) { HRESULT hRes=S_OK; va_list Args; int iResult; size_t cbRemaining; if(FAILED(hRes=TunnelIsUp())) { dbgout("[sync] TunnelSend: tunnel is unavailable\n"); return hRes; } va_start(Args, Format); hRes = StringCbVPrintfExA(SendBuffer, MAX_SEND, NULL, &cbRemaining, STRSAFE_NULL_ON_FAILURE, Format, Args); va_end(Args); if (FAILED(hRes)) return hRes; #if VERBOSE >= 2 dbgout("[sync] send 0x%x bytes, %s\n", MAX_SEND-cbRemaining, SendBuffer); #endif iResult = send(g_Sock, (const char *)SendBuffer, MAX_SEND-((unsigned int)cbRemaining), 0); if(iResult == SOCKET_ERROR) { iResult = WSAGetLastError(); dbgout("[sync] send failed with error %d, 0x%x\n", iResult, g_Sock); WsaErrMsg(iResult); g_Synchronized=FALSE; TunnelClose(); hRes=E_FAIL; } return hRes; }
HRESULT ToBase64(const BYTE *pbBinary, DWORD cbBinary, LPSTR *pszString) { BOOL bRes=FALSE; HRESULT hRes=S_OK; DWORD cchString = 0; bRes = CryptBinaryToStringA(pbBinary, cbBinary, CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, NULL, &cchString); if (!bRes){ dbgout("[sync] send failed at CryptBinaryToString: %d\n", GetLastError()); return E_FAIL; } *pszString = (LPSTR) malloc(cchString); if (pszString==NULL){ dbgout("[sync] failed at allocate buffer: %d\n", GetLastError()); return E_FAIL; } bRes = CryptBinaryToStringA(pbBinary, cbBinary, CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, *pszString, &cchString); if (!bRes){ dbgout("[sync] send failed at CryptBinaryToString: %d\n", GetLastError()); return E_FAIL; } /* CRYPT_STRING_NOCRLF 0x40000000 Windows Server 2003 and Windows XP: This value is not supported */ #if _NT_TARGET_VERSION_WINXPOR2K3 trimcrlf(*pszString); #endif return hRes; }