bool UpdateXferProgress( uint64_t iBytesCurrent, uint64_t iBytesTotal ) { bool bInterrupt = false; FOREACH_EnabledPlayer(pn) { bInterrupt |= INPUTMAPPER->IsButtonDown( MenuInput(pn, MENU_BUTTON_SELECT) ); bInterrupt |= INPUTMAPPER->IsButtonDown(MenuInput(pn, MENU_BUTTON_LEFT)) && INPUTMAPPER->IsButtonDown(MenuInput(pn, MENU_BUTTON_RIGHT)); } if ( bInterrupt ) { InputEventArray throwaway; INPUTFILTER->GetInputEvents( throwaway ); return false; } // Draw() is very expensive: only do it on occasion. if( DrawTimer.Ago() < DRAW_UPDATE_TIME ) return true; /* this truncates to int, but that's okay for our purposes */ float iTransferRate = iBytesCurrent / g_UpdateDuration.Ago(); float fPercent = iBytesCurrent / (iBytesTotal/100); const CString sRate = FormatByteValue( iTransferRate ) + "/sec"; CString sMessage = ssprintf( "\n\n%s\n%.2f%% %s\n\n%s", USER_PACK_WAIT_TEXT.GetValue().c_str(), fPercent, sRate.c_str(), USER_PACK_CANCEL_TEXT.GetValue().c_str() ); SCREENMAN->OverlayMessage( sMessage ); SCREENMAN->Draw(); DrawTimer.Touch(); return true; }
VOID ProcessPacket(SYSTEMTIME rTime, unsigned char *szBuffer, int size, BOOL bFilter) { struct ethernet_802_3 *eth; struct iphdr *ip; struct arppkt *arp; int size_iphdr, size_framehdr, index; RuleNode *alert_node, *log_node, *counter_node; BOOL bMatch = FALSE; char src[32], dst[32], type[64]; char info[64], str[128], msg[128], numbytes[12]; unsigned short ptype; if (size < 42) // probably a corrupt packet return; size_framehdr = 14; src[0] = '\0'; dst[0] = '\0'; info[0] = '\0'; msg[0] = '\0'; wsprintf(numbytes, "%d", size); wsprintf(type, "Unknown"); eth = (struct ethernet_802_3 *) szBuffer; if (ntohs(eth->length) > 0x05DC) // its an ethernet_II frame { ptype = eth->length; /* length actually is type since its an eth_II frame */ size_framehdr = 14; } else // its an 802.3 frame { ptype = eth->type; size_framehdr = 22; } ptype = ntohs(ptype); /* if rules are NOT to be used, show all captured packets */ if (bFilter == FALSE) { GetPacketInfo(ptype, szBuffer, size_framehdr, src, dst, type, info); AddToAlert(rTime, szBuffer, size, src, dst, numbytes, type, info, ""); return; } if (ptype == 0x0800) { ip = (struct iphdr *) &szBuffer[size_framehdr]; size_iphdr = (ip->verlen & 0x0f) * 4; switch (ip->prot) { case R_ICMP: alert_node = root.alert.IcmpList; log_node = root.log.IcmpList; counter_node = root.counter.IcmpList; break; case R_UDP: alert_node = root.alert.UdpList; log_node = root.log.UdpList; counter_node = root.counter.UdpList; break; case R_TCP: alert_node = root.alert.TcpList; log_node = root.log.TcpList; counter_node = root.counter.TcpList; break; default: return; } /* check for match in the alert chain */ while (alert_node != NULL) { debug("checking alert node\r\n"); bMatch = MatchIpFields(alert_node, &szBuffer[size_framehdr]); if (bMatch) debug("ip header matches\r\n"); if (bMatch && alert_node->content_set) bMatch = MatchContent(&szBuffer[size_iphdr], size-size_iphdr, alert_node->content, lstrlen(alert_node->content)); if (bMatch) { GetPacketInfo(ptype, szBuffer, size_framehdr, src, dst, type, info); AddToAlert(rTime, szBuffer, size, src, dst, numbytes, type, info, alert_node->msg); break; } alert_node = alert_node->next; } /* check for match in the log chain */ while (log_node != NULL) { bMatch = MatchIpFields(log_node, &szBuffer[size_framehdr]); if (bMatch && log_node->content_set) bMatch = MatchContent(&szBuffer[size_iphdr], size-size_iphdr, log_node->content, lstrlen(log_node->content)); if (bMatch) { AddToLog(rTime, szBuffer, size, log_node->msg); break; } log_node = log_node->next; } /* check for all matches in the counter chain */ while (counter_node != NULL) { bMatch = MatchIpFields(counter_node, &szBuffer[size_framehdr]); if (bMatch && counter_node->content_set) bMatch = MatchContent(&szBuffer[size_iphdr], size-size_iphdr, counter_node->content, lstrlen(counter_node->content)); if (bMatch && counter_node->counter_id_set) { index = counter_node->counter_id; counter[index].count += 1; counter[index].bytes += size; wsprintf(str, "%d", counter[index].count); ListView_SetItemText(hWndCounterList, index, 2, str); FormatByteValue(counter[index].bytes, str); ListView_SetItemText(hWndCounterList, index, 3, str); } counter_node = counter_node->next; } } /* SPECIAL HANDLING FOR ARP PACKETS */ else if (ptype == 0x0806) { alert_node = root.alert.ArpList; if (alert_node != NULL) { GetPacketInfo(ptype, szBuffer, size_framehdr, src, dst, type, info); AddToAlert(rTime, szBuffer, size, src, dst, numbytes, type, info, alert_node->msg); } log_node = root.log.ArpList; if (log_node != NULL) { AddToLog(rTime, szBuffer, size, log_node->msg); } /* increment counter while here */ alert_node = root.counter.ArpList; if ((alert_node != NULL) && alert_node->counter_id_set) { index = alert_node->counter_id; counter[index].count += 1; counter[index].bytes += size; wsprintf(str, "%d", counter[index].count); ListView_SetItemText(hWndCounterList, index, 2, str); FormatByteValue(counter[index].bytes, str); ListView_SetItemText(hWndCounterList, index, 3, str); } arp = (struct arppkt *) &szBuffer[size_framehdr]; wsprintf(dst, "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", arp->sender_ha[0], arp->sender_ha[1],arp->sender_ha[2],arp->sender_ha[3],arp->sender_ha[4],arp->sender_ha[5]); wsprintf(src, "%d.%d.%d.%d", arp->sender_ip[0], arp->sender_ip[1], arp->sender_ip[2], arp->sender_ip[3]); AddToARP(hWndARPList, src, dst); } }
CString DiagnosticsUtil::GetDiskSpaceTotal() { uint64_t iBytes = HOOKS->GetDiskSpaceTotal( USER_PACK_SAVE_PATH ); return FormatByteValue( iBytes ); }