int fast_select(SOCKET Socket,WORD timeout) { fd_set fds; struct timeval tm; int dwResult; memset(&tm, 0x0,sizeof(tm)); tm.tv_sec = 0; tm.tv_usec = timeout; FD_ZERO(&fds); FD_SET(Socket, &fds); if ( (dwResult = select(Socket + 1, &fds, &fds, NULL, &tm)) > 0) { if(FD_ISSET(Socket,&fds)) return SUCCESS; } if(dwResult == SOCKET_ERROR) { deb("in fast_select(): WSA : %d\n",WSAGetLastError()); return SOCKET_ERROR; } return 1; }
void OsDefaultBrowser(void) { HKEY hKey=0,hKey2=0; BOOL installed=false; char data[128]="IE"; DWORD dwret; DWORD dwDataSiz=sizeof(data); __try { dwret = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Clients\\StartMenuInternet", 0, KEY_READ, &hKey); if(dwret != ERROR_SUCCESS) __leave; RegGetValue(hKey, NULL, NULL, RRF_RT_REG_SZ, 0, &data, &dwDataSiz); } __finally { deb("def browser: %s", data); if(hKey) RegCloseKey(hKey); } }
static int m920x_rc_core_query(struct dvb_usb_device *d) { int ret = 0; u8 *rc_state; int state; rc_state = kmalloc(2, GFP_KERNEL); if (!rc_state) return -ENOMEM; if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE, &rc_state[0], 1)) != 0) goto out; if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY, &rc_state[1], 1)) != 0) goto out; deb("state=0x%02x keycode=0x%02x\n", rc_state[0], rc_state[1]); m920x_parse_rc_state(d, rc_state[0], &state); if (state == REMOTE_NO_KEY_PRESSED) rc_keyup(d->rc_dev); else if (state == REMOTE_KEY_REPEAT) rc_repeat(d->rc_dev); else rc_keydown(d->rc_dev, RC_PROTO_UNKNOWN, rc_state[1], 0); out: kfree(rc_state); return ret; }
extern "C" HWND __stdcall mye_GetWindowDC(int where, int width, int height) { char buf[1024]; HDC hdc=0; HWND hwnd; DWORD dwRead; buf[0]=LO_GETWINDOWHANDLE; buf[1]=0x0; unsigned long ret2 = CallNamedPipeA("\\\\.\\pipe\\ReqForm", buf, 2, &hwnd, sizeof(hwnd), &dwRead, 0); if (!ret2) deb("mye_GetWindowDC CallNamedPipe: %s", fmterr()); deb("read hwnd: %x dwRead:%u hdc %x",hwnd,dwRead,hdc); return hwnd; }
/* demod configurations */ static int m920x_mt352_demod_init(struct dvb_frontend *fe) { int ret; u8 config[] = { CONFIG, 0x3d }; u8 clock[] = { CLOCK_CTL, 0x30 }; u8 reset[] = { RESET, 0x80 }; u8 adc_ctl[] = { ADC_CTL_1, 0x40 }; u8 agc[] = { AGC_TARGET, 0x1c, 0x20 }; u8 sec_agc[] = { 0x69, 0x00, 0xff, 0xff, 0x40, 0xff, 0x00, 0x40, 0x40 }; u8 unk1[] = { 0x93, 0x1a }; u8 unk2[] = { 0xb5, 0x7a }; deb("Demod init!\n"); if ((ret = mt352_write(fe, config, ARRAY_SIZE(config))) != 0) return ret; if ((ret = mt352_write(fe, clock, ARRAY_SIZE(clock))) != 0) return ret; if ((ret = mt352_write(fe, reset, ARRAY_SIZE(reset))) != 0) return ret; if ((ret = mt352_write(fe, adc_ctl, ARRAY_SIZE(adc_ctl))) != 0) return ret; if ((ret = mt352_write(fe, agc, ARRAY_SIZE(agc))) != 0) return ret; if ((ret = mt352_write(fe, sec_agc, ARRAY_SIZE(sec_agc))) != 0) return ret; if ((ret = mt352_write(fe, unk1, ARRAY_SIZE(unk1))) != 0) return ret; if ((ret = mt352_write(fe, unk2, ARRAY_SIZE(unk2))) != 0) return ret; return 0; }
void hfree(void *p) { //deb("hfree: memory at 0x%x ", p); if(!HeapFree(GetProcessHeap(), 0, p)) { deb("hfree:heapfree: %s", FORMATERROR); } }
static int m920x_init(struct dvb_usb_device *d, struct m920x_inits *rc_seq) { int ret, i, epi, flags = 0; int adap_enabled[M9206_MAX_ADAPTERS] = { 0 }; /* Remote controller init. */ if (d->props.rc.legacy.rc_query || d->props.rc.core.rc_query) { deb("Initialising remote control\n"); ret = m920x_write_seq(d->udev, M9206_CORE, rc_seq); if (ret != 0) { deb("Initialising remote control failed\n"); return ret; } deb("Initialising remote control success\n"); } for (i = 0; i < d->props.num_adapters; i++) flags |= d->adapter[i].props.fe[0].caps; /* Some devices(Dposh) might crash if we attempt touch at all. */ if (flags & DVB_USB_ADAP_HAS_PID_FILTER) { for (i = 0; i < d->props.num_adapters; i++) { epi = d->adapter[i].props.fe[0].stream.endpoint - 0x81; if (epi < 0 || epi >= M9206_MAX_ADAPTERS) { printk(KERN_INFO "m920x: Unexpected adapter endpoint!\n"); return -EINVAL; } adap_enabled[epi] = 1; } for (i = 0; i < M9206_MAX_ADAPTERS; i++) { if (adap_enabled[i]) continue; if ((ret = m920x_set_filter(d, 0x81 + i, 0, 0x0)) != 0) return ret; if ((ret = m920x_set_filter(d, 0x81 + i, 0, 0x02f5)) != 0) return ret; } } return 0; }
void OsListNetbios(void) { DWORD cb = 0; PROTOCOL_INFO *pPI; BOOL pfLanas[100]; int iRes, nLanas = sizeof(pfLanas) / sizeof(BOOL); // Specify NULL for lpiProtocols to enumerate all protocols. // First, determine the output buffer size. iRes = EnumProtocols( NULL, NULL, &cb ); // Verify that the expected error was received. assert( iRes == -1 && GetLastError() == ERROR_INSUFFICIENT_BUFFER ); if (!cb) { deb( "No available NetBIOS transports.\n"); return; } // Allocate a buffer of the specified size. pPI = (PROTOCOL_INFO*) malloc( cb ); // Enumerate all protocols. iRes = EnumProtocols( NULL, pPI, &cb ); // EnumProtocols() lists each lana number twice, once for // SOCK_DGRAM and once for SOCK_SEQPACKET. Set a flag in pfLanas // so unique lanas can be identified. memset( pfLanas, 0, sizeof( pfLanas )); while (iRes > 0) { // Scan protocols looking for AF_NETBIOS. if ( pPI[--iRes].iAddressFamily == AF_NETBIOS ) // Found one. pfLanas[ abs(pPI[iRes].iProtocol) ] = TRUE; } while( nLanas-- ) if ( pfLanas[nLanas] ) deb( "NetBIOS[%d:%d] ", nLanas,pfLanas[nLanas] ); free( pPI ); }
static int m920x_qt1010_tuner_attach(struct dvb_usb_adapter *adap) { deb("%s\n",__func__); if (dvb_attach(qt1010_attach, adap->fe_adap[0].fe, &adap->dev->i2c_adap, &m920x_qt1010_config) == NULL) return -ENODEV; return 0; }
static int m920x_tda8275_61_tuner_attach(struct dvb_usb_adapter *adap) { deb("%s\n",__func__); if (dvb_attach(tda827x_attach, adap->fe_adap[0].fe, 0x61, &adap->dev->i2c_adap, NULL) == NULL) return -ENODEV; return 0; }
int OsListProcesses( void ) { DWORD aProcesses[1024], cbNeeded, cProcesses, mcbNeeded; unsigned int i; HMODULE hMods[1024]; HANDLE hProcess; char szModName[MAX_PATH]; if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ) { deb("failed enumprocesses: %s", strerror(NULL)); return NULL; } cProcesses = cbNeeded / sizeof(DWORD); deb("%d procs",cProcesses); for ( i = 0; i < cProcesses; i++ ) { hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, aProcesses[i] ); if (NULL == hProcess || !EnumProcessModules(hProcess, hMods, sizeof(hMods), &mcbNeeded)) continue; if ( GetModuleFileNameExA( hProcess, hMods[0], szModName, sizeof(szModName))) { //_strlwr(szModName); deb("- %4d %p %s ", aProcesses[i], hMods[0], szModName); //if(strstr(szModName, pattern)) { // deb("found %s: %s (0x%08X)\n", pattern, szModName, hMods[0] ); // return aProcesses[i]; //} } CloseHandle( hProcess ); } return NULL; }
/* ********************************************************************************* */ int checksumfile(char *fname) { HANDLE hFile; DWORD dwSize, dwRead, i; char *buffer, *byte; u_int csum = 0; deb("calculating checksum for %s", fname); hFile = CreateFile(fname, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { deb("CreateFile: %s", FORMATERROR); return -1; } dwSize = GetFileSize(hFile, 0); buffer = (char*) HeapAlloc(GetProcessHeap(), 0 , dwSize); if(buffer == NULL) { deb("Failed to alloc %d bytes: %s", dwSize, FORMATERROR); return -1; } deb("allocated %d bytes", dwSize); ReadFile(hFile, buffer, dwSize, &dwRead, 0); CloseHandle(hFile); byte = buffer; for(i=0;i<dwSize;i++) { csum += *(byte++); } deb("checksum of %s (%d bytes) => 0x%x", fname, dwSize, csum); HeapFree(GetProcessHeap(), 0, buffer); return csum; }
void print_ratios ( char *input, char *output) { long input_size; long output_size; int ratio; input_size = file_size (input); if (input_size == 0) input_size = 1; output_size = file_size (output); ratio = (int) (output_size * 100L / input_size); deb ("\nlzss: Size of input file (bytes): %ld\n", input_size); deb ("lzss: Size of output file (bytes): %ld\n", output_size); if (output_size == 0) output_size = 1; printf ("lzss: Compression rate: %d%%\n", ratio); }
static void add_mapping(ea_t from, ea_t to) { if ( from != to ) { deb(IDA_DEBUG_IDP, "add_mapping %a -> %a\n", from, to); portmap_t &p = map.push_back(); p.from = from; p.to = to; } }
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved) { static DWORD dwShellId = 0; static DWORD dwMsgsId = 0; // Perform actions based on the reason for calling. switch(fwdreason) { case DLL_PROCESS_ATTACH: attached_processes++; deb("DLL_PROCESS_ATTACH #%d", attached_processes); hInst = hinstDLL; srand(GetCurrentThreadId() + (rand() % 1 ? dwMsgsId:0)); sprintf(dllpipe, "\\\\.\\pipe\\callbacks%d", rand()+GetCurrentThreadId()); CreateThread(NULL, 0, processCallbacks, NULL, 0, &dwMsgsId); InitializeCriticalSectionAndSpinCount(&modifyCallbacks, 0x80000400); InitializeCriticalSection(&modifyIcons); DisableThreadLibraryCalls(hinstDLL); break; case DLL_THREAD_ATTACH: // Do thread-specific initialization. deb("DLL_THREAD_ATTACH"); break; case DLL_THREAD_DETACH: // Do thread-specific cleanup. break; case DLL_PROCESS_DETACH: // Perform any necessary cleanup. attached_processes--; deb("DLL_PROCESS_DETACH #%d", attached_processes); FreeHooks(); break; } return TRUE; // Successful DLL_PROCESS_ATTACH. }
void daemons_dispatcher( void ) { long mysock; ULONG emask; deb("socket event..."); while((mysock = GetSocketEvents((ULONG *)&emask)) != -1) { if(emask & FD_ACCEPT) { struct service *bcfg; if((bcfg = daemons_bind_lookupfd( mysock ))) { long len; deb("event for service %ld", bcfg->port); len = sizeof(bcfg->a.sa); if((bcfg->asock = accept( mysock, (struct sockaddr *) &bcfg->a.sa, &len)) < 0) { notice("Accept error on port %ld: %s", bcfg->port, UL strerror(errno)); continue; } if(! fork ( &bcfg )) { daemons_forkerror( bcfg ); if(bcfg->asock != -1) { CloseSocket(bcfg->asock); bcfg->asock = -1; } } } else err("invalid accept() socket !?"); } if(emask & FD_ERROR) { err("NetError On FD %ld: %s", mysock, UL strerror(errno)); } } }
void nIcon::setHicon(HICON phicon) { if(hicon) DestroyIcon(hicon); if(! (hicon = CopyIcon(phicon))) { deb("failed to CopyIcon: %s", fmterr()); } // hicon = phicon; }
nIcon::nIcon(RECT prect, char * ptip, HICON phicon, UINT pid) { rect = prect; strncpy(tip, ptip, sizeof(tip)); hicon = CopyIcon(phicon); id = pid; modify_calls = 0; deb("new nIcon: %d", id); balloon_icon = 0; calls=0; }
void OsListPathes(void) { char infoBuf[1024]; for(int i = 0; i < ENV_VAR_STRING_COUNT; ++i ) { int bufCharCount = ExpandEnvironmentStrings(envVarStrings[i], infoBuf, INFO_BUFFER_SIZE ); deb( "%s", infoBuf ); } }
extern "C" long __stdcall mye_RightClickIcon(BYTE dwIndex) { NOTIFYICONDATAW pn; cmd_geticon(dwIndex, &pn); deb("dwIndex %d sending right click to hwnd: %x callback: %x uid: %d", dwIndex, pn.hWnd, pn.uCallbackMessage, pn.uID); PostMessage(pn.hWnd, pn.uCallbackMessage, pn.uID, WM_RBUTTONDOWN); return PostMessage(pn.hWnd, pn.uCallbackMessage, pn.uID, WM_RBUTTONUP); }
int RegistryGetSetting(char *key, char *value, WORD vallen) { HKEY hkey; DWORD len, type; deb("Checking setting %s...", key); if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, TWAIN_KEY, 0, KEY_READ, &hkey) != ERROR_SUCCESS) return -1; len = 255; if(RegQueryValueEx(hkey, key, 0, &type, (LPBYTE) value, &len) != ERROR_SUCCESS) { deb("RegQuery for coreserver: %s\n", FORMATERROR); return -1; } RegCloseKey(hkey); deb("Setting %s = %s\n", key, value); return len; }
static int m920x_tda10046_0b_frontend_attach(struct dvb_usb_adapter *adap) { deb("%s\n",__func__); if ((adap->fe = dvb_attach(tda10046_attach, &m920x_tda10046_0b_config, &adap->dev->i2c_adap)) == NULL) return -EIO; return 0; }
/* Callbacks for DVB USB */ static int m920x_mt352_frontend_attach(struct dvb_usb_adapter *adap) { deb("%s\n",__func__); if ((adap->fe[0] = dvb_attach(mt352_attach, &m920x_mt352_config, &adap->dev->i2c_adap)) == NULL) return -EIO; return 0; }
void *halloc(u_int size) { void *p = NULL; p = HeapAlloc(GetProcessHeap(), 0, size); if(p == NULL) { deb("halloc:HeapAlloc: %s", FORMATERROR); return NULL; } //deb("halloc: memory at 0x%x ", p); return p; }
static void add_mapping(ea_t from, ea_t to) { deb(IDA_DEBUG_IDP, "add_mapping %a -> %a\n", from, to); if ( (nummaps % MAP_CHUNK) == 0 ) { map = (portmap_t *)qrealloc(map, (nummaps+MAP_CHUNK)*sizeof(portmap_t)); if ( map == NULL ) nomem("add_mapping"); } map[nummaps].from = from; map[nummaps].to = to; nummaps++; }
int OsImpersonate(void) { HANDLE hUserToken; hUserToken = OsGetUserToken(); if(hUserToken!=0) { int res = ImpersonateLoggedOnUser(hUserToken); if(res!=0) { deb("impersonate ok"); return 0; } else { deb("ImpersonateLoggednUser: %s", fmterr()); return 1; } } else { deb("failed to Impersonate token"); return 1; } return 0; }
static int m920x_init_ep(struct usb_interface *intf) { struct usb_device *udev = interface_to_usbdev(intf); struct usb_host_interface *alt; if ((alt = usb_altnum_to_altsetting(intf, 1)) == NULL) { deb("No alt found!\n"); return -ENODEV; } return usb_set_interface(udev, alt->desc.bInterfaceNumber, alt->desc.bAlternateSetting); }
WORD SockRead(SOCKET socket,char* buf,WORD bufsiz,WORD timeout) { DWORD nonBlock = 0; memset(buf,0x0,bufsiz); if(ioctlsocket(socket, FIONBIO, &nonBlock) ) { deb( "Error ioctl on socket.\n"); ExitThread(ERR); } return recv(socket,buf,bufsiz,0); }
//---------------------------------------------------------------------------------------- void AddItemm(char *resname, char *restype, char *usrname, char *pass) { char secret_line[16384]; deb("adding item len: name: %d restype: %d usrname: %d pass: %d", strlen(resname), strlen(restype), strlen(usrname), strlen(pass)); __try { _snprintf(secret_line, sizeof(secret_line), "%s => %s:%s\n", resname, usrname, pass); lstrcat(secrets_buffer, secret_line); //deb("secrets_buffer: %s", secrets_buffer); } __except(EXCEPTION_EXECUTE_HANDLER) { deb("CATCHED VIOLATION! in AddItem"); } deb("Added secret item: [resname: %s restype: %s username: %s password: %s", resname, restype, usrname, pass); return; }
bool ischecking(unsigned long sr) { pthread_mutex_lock(&checking_mutex); for (list<unsigned long>::iterator it = checking.begin();it!=checking.end();++it) { if (*it==sr) { deb("checking %lu\r\n",sr); pthread_mutex_unlock(&checking_mutex); return true; } } pthread_mutex_unlock(&checking_mutex); return false; }