void qtDLGHeapView::MenuCallback(QAction* pAction) { if(QString().compare(pAction->text(),"Send Offset To HexView") == 0) { qtDLGHexView *newView = new qtDLGHexView(this,Qt::Window,tblHeapBlocks->item(m_selectedRow,0)->text().toULongLong(0,16), tblHeapBlocks->item(m_selectedRow,2)->text().toULongLong(0,16), tblHeapBlocks->item(m_selectedRow,3)->text().toULongLong(0,16)); newView->show(); } else if(QString().compare(pAction->text(),"Dump Memory To File") == 0) { HANDLE hProc = clsDebugger::GetProcessHandleByPID(tblHeapBlocks->item(m_selectedRow,0)->text().toULongLong(0,16)); clsMemDump memDump(hProc, L"Heap", tblHeapBlocks->item(m_selectedRow,2)->text().toULongLong(0,16), tblHeapBlocks->item(m_selectedRow,3)->text().toULongLong(0,16)); } else if(QString().compare(pAction->text(),"Line") == 0) { QClipboard* clipboard = QApplication::clipboard(); clipboard->setText(QString("%1:%2:%3:%4:%5:%6") .arg(tblHeapBlocks->item(m_selectedRow,0)->text()) .arg(tblHeapBlocks->item(m_selectedRow,1)->text()) .arg(tblHeapBlocks->item(m_selectedRow,2)->text()) .arg(tblHeapBlocks->item(m_selectedRow,3)->text()) .arg(tblHeapBlocks->item(m_selectedRow,4)->text()) .arg(tblHeapBlocks->item(m_selectedRow,5)->text())); } else if(QString().compare(pAction->text(),"HeapID") == 0) { QClipboard* clipboard = QApplication::clipboard(); clipboard->setText(tblHeapBlocks->item(m_selectedRow,1)->text()); } else if(QString().compare(pAction->text(),"Address") == 0) { QClipboard* clipboard = QApplication::clipboard(); clipboard->setText(tblHeapBlocks->item(m_selectedRow,2)->text()); } else if(QString().compare(pAction->text(),"Block Size") == 0) { QClipboard* clipboard = QApplication::clipboard(); clipboard->setText(tblHeapBlocks->item(m_selectedRow,3)->text()); } else if(QString().compare(pAction->text(),"Block Count") == 0) { QClipboard* clipboard = QApplication::clipboard(); clipboard->setText(tblHeapBlocks->item(m_selectedRow,4)->text()); } else if(QString().compare(pAction->text(),"Flags") == 0) { QClipboard* clipboard = QApplication::clipboard(); clipboard->setText(tblHeapBlocks->item(m_selectedRow,5)->text()); } }
// Dump a portion of physical memory to file static void memPhysDump(uint32 paddr, uint32 size) { while (size) { uint8 *vaddr = memPhysMap(paddr); uint32 bytes = PHYS_CACHE_SIZE - (PHYS_CACHE_MASK & (uint32)vaddr); if (bytes > size) bytes = size; memDump(vaddr, bytes, paddr); size -= bytes; paddr += bytes; } }
static void cmd_memaccess(const char *tok, const char *args) { bool virt = toupper(tok[0]) == 'V'; uint32 addr, size; if (!get_expression(&args, &addr) || !get_expression(&args, &size)) { ScriptError("Expected <addr> <size>"); return; } alignMemAddr(&addr); if (virt) memDump((uint8 *)addr, size); else memPhysDump(addr, size); }
/************************************************************************* * FUNCTION * swNic_send * * DESCRIPTION * This function writes one packet to tx descriptors, and waits until * the packet is successfully sent. * * INPUTS * None * * OUTPUTS * None *************************************************************************/ __MIPS16 __IRAM_FWD inline int32 _swNic_send(void *skb, void * output, uint32 len,rtl_nicTx_info *nicTx) { struct rtl_pktHdr * pPkthdr; int next_index, ret; if ((currTxPkthdrDescIndex[nicTx->txIdx]+1)==txPkthdrRingCnt[nicTx->txIdx]) next_index = 0; else next_index = currTxPkthdrDescIndex[nicTx->txIdx]+1; if (next_index == txPktDoneDescIndex[nicTx->txIdx]) { /* TX ring full */ return -1; } #if defined(CONFIG_RTL_ENHANCE_RELIABILITY) && defined(CONFIG_RTL_8198C) pPkthdr = (struct rtl_pktHdr *) ((int32) txPkthdrRing_base[nicTx->txIdx] + (sizeof(struct rtl_pktHdr) * currTxPkthdrDescIndex[nicTx->txIdx])); #else /* Fetch packet header from Tx ring */ pPkthdr = (struct rtl_pktHdr *) ((int32) txPkthdrRing[nicTx->txIdx][currTxPkthdrDescIndex[nicTx->txIdx]] & ~(DESC_OWNED_BIT | DESC_WRAP)); #endif /* Pad small packets and add CRC */ if ( len < 60 ) len = 64; else len += 4; pPkthdr->ph_mbuf->m_len = len; pPkthdr->ph_mbuf->m_extsize = len; pPkthdr->ph_mbuf->skb = skb; pPkthdr->ph_len = len; pPkthdr->ph_vlanId = nicTx->vid; #if defined(CONFIG_8198_PORT5_GMII) || defined(CONFIG_8198_PORT5_RGMII) || defined(CONFIG_RTL_8198C_8367RB) pPkthdr->ph_portlist = nicTx->portlist&0x3f; #else pPkthdr->ph_portlist = nicTx->portlist&0x1f; #endif pPkthdr->ph_srcExtPortNum = nicTx->srcExtPort; pPkthdr->ph_flags = nicTx->flags; #if defined(CONFIG_RTL_HW_QOS_SUPPORT) || defined(CONFIG_RTK_VOIP_QOS) pPkthdr->ph_txPriority = nicTx->priority; #endif #ifdef CONFIG_RTK_VLAN_WAN_TAG_SUPPORT if (*((unsigned short *)((unsigned char*)output+ETH_ALEN*2)) != __constant_htons(ETH_P_8021Q)) pPkthdr->ph_txCVlanTagAutoAdd = nicTx->tagport; else pPkthdr->ph_txCVlanTagAutoAdd = 0; #endif #if defined(CONFIG_RTL_VLAN_8021Q) || defined(CONFIG_SWCONFIG) if (*((unsigned short *)((unsigned char*)output+ETH_ALEN*2)) != __constant_htons(ETH_P_8021Q)) { pPkthdr->ph_txCVlanTagAutoAdd = (0x3f) & rtk_get_vlan_tagmask(pPkthdr->ph_vlanId); } else pPkthdr->ph_txCVlanTagAutoAdd = 0; #if 0 panic_printk("%s %d pPkthdr->ph_txCVlanTagAutoAdd=0x%x pPkthdr->ph_portlist=0x%x pPkthdr->ph_vlanId=%d\n", __FUNCTION__, __LINE__, pPkthdr->ph_txCVlanTagAutoAdd, pPkthdr->ph_portlist, pPkthdr->ph_vlanId); #endif #elif defined(CONFIG_RTL_HW_VLAN_SUPPORT) if (*((unsigned short *)((unsigned char*)output+ETH_ALEN*2)) != __constant_htons(ETH_P_8021Q)) pPkthdr->ph_txCVlanTagAutoAdd = auto_set_tag_portmask; else pPkthdr->ph_txCVlanTagAutoAdd = 0; #endif /* Set cluster pointer to buffer */ pPkthdr->ph_mbuf->m_data = (output); pPkthdr->ph_mbuf->m_extbuf = (output); #if defined(CONFIG_RTL_819XD) || defined(CONFIG_RTL_8196E) || defined(CONFIG_RTL_8198C) pPkthdr->ph_ptpPkt = 0; #endif #ifdef _PKTHDR_CACHEABLE #if defined(CONFIG_RTL_8198C) _dma_cache_wback((unsigned long)pPkthdr, sizeof(struct rtl_pktHdr)); _dma_cache_wback((unsigned long)(pPkthdr->ph_mbuf), sizeof(struct rtl_mBuf)); #else _dma_cache_wback_inv((unsigned long)pPkthdr, sizeof(struct rtl_pktHdr)); _dma_cache_wback_inv((unsigned long)(pPkthdr->ph_mbuf), sizeof(struct rtl_mBuf)); #endif #endif ret = currTxPkthdrDescIndex[nicTx->txIdx]; currTxPkthdrDescIndex[nicTx->txIdx] = next_index; /* Give descriptor to switch core */ txPkthdrRing[nicTx->txIdx][ret] |= DESC_SWCORE_OWNED; #if defined(CONFIG_RTL_ENHANCE_RELIABILITY) && !defined(CONFIG_RTL_8198C) { uint32 pkthdr2 = (uint32)txPkthdrRing[nicTx->txIdx][ret]; if ((pkthdr2 & DESC_OWNED_BIT) == 0) #ifndef CONFIG_OPENWRT_SDK panic_printk("_swNic_send: idx= %d, read back pkthdr= 0x%x.\n", ret, pkthdr2); #else printk("_swNic_send: idx= %d, read back pkthdr= 0x%x.\n", ret, pkthdr2); #endif } #endif #if 0 memDump((void*)output, 64, "TX"); printk("index %d address 0x%p, 0x%x 0x%p.\n", ret, &txPkthdrRing[nicTx->txIdx][ret], (*(volatile uint32 *)&txPkthdrRing[nicTx->txIdx][ret]), pPkthdr); printk("Flags 0x%x proto 0x%x portlist 0x%x vid %d extPort %d srcExtPort %d len %d.\n", pPkthdr->ph_flags, pPkthdr->ph_proto, pPkthdr->ph_portlist, pPkthdr->ph_vlanId, pPkthdr->ph_extPortList, pPkthdr->ph_srcExtPortNum, pPkthdr->ph_len); #endif /* Set TXFD bit to start send */ REG32(CPUICR) |= TXFD; return ret; }
/** Main menu **/ void menu() { int instrReturn; char choice; int bytesRead; unsigned offset, length; // initialize memory, declared in myMenu.h char memory[MEMSIZE]; // initialize registers and reset, declared in myMenu.h struct Registers myRegisters; reset(&myRegisters); while (1) { // display menu fprintf(stdout, "\n\n---------------------------------------------------"); fprintf(stdout, "\nSheranga Balasuriya: Welcome to my Virtual CPU\nPlease select one of the following"); fprintf(stdout, "\nd\tdump memory"); fprintf(stdout, "\ng\tgo"); fprintf(stdout, "\nl\tload a file into memory"); fprintf(stdout, "\nm\tmemory modify"); fprintf(stdout, "\nq\tquit"); fprintf(stdout, "\nr\tdisplay registers"); fprintf(stdout, "\nt\ttrace"); fprintf(stdout, "\nw\twrite file"); fprintf(stdout, "\nz\treset registers"); fprintf(stdout, "\nb\tenable/disable debugging"); fprintf(stdout, "\n? , h\tdisplay help\n"); fscanf(stdin, " %1c", &choice); flush(); // check choice taken switch (choice) { case 'd': case 'D': // get offset from user fprintf(stdout, "\nPleae enter the offset in hex: "); fscanf(stdin, "%x", &offset); flush(); // get length from user fprintf(stdout, "\nPlease enter the length in hex: "); fscanf(stdin, "%x", &length); flush(); memDump(memory, offset, length); break; case 'g': case 'G': go(&myRegisters,memory); break; case 'l': case 'L': bytesRead = loadFile(memory, MEMSIZE); if (bytesRead > 0) fprintf(stdout, "\n%d(0x%X) bytes read into memory", bytesRead, bytesRead); break; case 'm': case 'M': modify(memory); break; case 'q': case 'Q': return; break; case 'r': case 'R': showRegisters(&myRegisters); break; case 't': case 'T': instrReturn = instructionCycle(&myRegisters, memory); showRegisters(&myRegisters); break; case 'w': case 'W': writeFile(memory); break; case 'z': case 'Z': reset(&myRegisters); break; case 'b': case 'B': debug(&myRegisters); break; case '?': case 'h': case 'H': help(); break; default: fprintf(stdout, "\nIncorrect entry, try again"); } } }
void qtDLGMemoryView::MenuCallback(QAction* pAction) { if(QString().compare(pAction->text(),"Send to HexView") == 0) { qtDLGHexView *newView = new qtDLGHexView(this,Qt::Window,tblMemoryView->item(m_selectedRow,0)->text().toULongLong(0,16), tblMemoryView->item(m_selectedRow,1)->text().toULongLong(0,16), tblMemoryView->item(m_selectedRow,2)->text().toULongLong(0,16)); newView->show(); } else if(QString().compare(pAction->text(),"Dump to File") == 0) { HANDLE hProc = clsDebugger::GetProcessHandleByPID(tblMemoryView->item(m_selectedRow,0)->text().toULongLong(0,16)); clsMemDump memDump(hProc, (PTCHAR)tblMemoryView->item(m_selectedRow,3)->text().utf16(), tblMemoryView->item(m_selectedRow,1)->text().toULongLong(0,16), tblMemoryView->item(m_selectedRow,2)->text().toULongLong(0,16)); } else if(QString().compare(pAction->text(),"Line") == 0) { QClipboard* clipboard = QApplication::clipboard(); clipboard->setText(QString("%1:%2:%3:%4:%5") .arg(tblMemoryView->item(m_selectedRow,0)->text()) .arg(tblMemoryView->item(m_selectedRow,1)->text()) .arg(tblMemoryView->item(m_selectedRow,2)->text()) .arg(tblMemoryView->item(m_selectedRow,3)->text()) .arg(tblMemoryView->item(m_selectedRow,4)->text())); } else if(QString().compare(pAction->text(),"Base Address") == 0) { QClipboard* clipboard = QApplication::clipboard(); clipboard->setText(tblMemoryView->item(m_selectedRow,1)->text()); } else if(QString().compare(pAction->text(),"Size") == 0) { QClipboard* clipboard = QApplication::clipboard(); clipboard->setText(tblMemoryView->item(m_selectedRow,2)->text()); } else if(QString().compare(pAction->text(),"Module") == 0) { QClipboard* clipboard = QApplication::clipboard(); clipboard->setText(tblMemoryView->item(m_selectedRow,3)->text()); } else if(QString().compare(pAction->text(),"Type") == 0) { QClipboard* clipboard = QApplication::clipboard(); clipboard->setText(tblMemoryView->item(m_selectedRow,4)->text()); } else if(QString().compare(pAction->text(),"Access") == 0) { QClipboard* clipboard = QApplication::clipboard(); clipboard->setText(tblMemoryView->item(m_selectedRow,5)->text()); } else if(QString().compare(pAction->text(),"PAGE_EXECUTE") == 0) SetPageProctection(PAGE_EXECUTE); else if(QString().compare(pAction->text(),"PAGE_EXECUTE_READ") == 0) SetPageProctection(PAGE_EXECUTE_READ); else if(QString().compare(pAction->text(),"PAGE_EXECUTE_READWRITE") == 0) SetPageProctection(PAGE_EXECUTE_READWRITE); else if(QString().compare(pAction->text(),"PAGE_EXECUTE_WRITECOPY") == 0) SetPageProctection(PAGE_EXECUTE_WRITECOPY); else if(QString().compare(pAction->text(),"PAGE_NOACCESS") == 0) SetPageProctection(PAGE_NOACCESS); else if(QString().compare(pAction->text(),"PAGE_READONLY") == 0) SetPageProctection(PAGE_READONLY); else if(QString().compare(pAction->text(),"PAGE_WRITECOPY") == 0) SetPageProctection(PAGE_WRITECOPY); else if(QString().compare(pAction->text(),"PAGE_READWRITE") == 0) SetPageProctection(PAGE_READWRITE); }
BOOL execute(UCHAR* _buffer) { if ( !validate(_buffer) ) { #if defined _DEBUG printf("\n--- execute: '%s' is invalid\n", _buffer); #endif return false; } #if defined _DEBUG printf("\n+++ execute: (@ 0x%X) '%s'\n", _buffer, _buffer); #endif int sz=strlen(_buffer); int repeat=0; UCHAR* repeat_start=0; UCHAR* repeat_stop=0; // TODO: crashes here /* with this sc @ +3 [> +10 <-]> -3 .@ < +6 [> +10 <-]> +4 .@ < +6 (crashes here) [> -- -- -- - <-]> .@ < +6 [> +10 <-]> ..@ < +9 [> -9 <-]> - .@ < +6 [> +10 <-]> +4 .@ < +6 [> -7 <-]> - .@ + < +6 [> +10 <-]> ..@ */ UCHAR* repeat_buffer; repeat_buffer=(UCHAR*)calloc(BUFFER_SIZE, sizeof(char)); if ( !repeat_buffer ) { #if defined _DEBUG printf("--- execute: repeat_buffer=NULL\n"); #else printf("error: can't allocate memory\n"); #endif return false; } BOOL repeat_done=false; UCHAR* tmp_buffer; // copy here body of loop cycle if any UCHAR* bf_sp=_buffer; // if ( bfo & BFO_QUICK ) // { // free(repeat_buffer); // printf("not implemented qbf yet\n"); // return false; // } while ( bf_sp<_buffer+sz ) { repeat_done=false; // #if defined _DEBUG // printf("+++ execute: parse '%c'@ 0x%X\n", *bf_sp, bf_sp); // #endif if ( *bf_sp=='@' ) { #if defined _DEBUG printf("\n+++ executeq: breakpoint reached\n"); memDump(); printSource(_buffer, bf_sp); getchar(); #else if ( bfo & BFO_DEBUG ) { printf("\nstop on breakpoint\n"); memDump(); printSource(_buffer, bf_sp); getchar(); } #endif } if ( *bf_sp=='+' ) { #if defined _DEBUG printf("+++ execute: +\n"); #endif if ( (bfo & BFO_QUICK) && bf_sp<_buffer+sz+1 ) { if ( *(bf_sp+1)>=48 && *(bf_sp+1)<=57 ) { repeat_start= ++bf_sp; while ( bf_sp<_buffer+sz+1 && *(bf_sp+1)>=48 && *(bf_sp+1)<=57 ) { bf_sp++; } repeat_stop=bf_sp+1; memcpy(repeat_buffer, repeat_start, abs(repeat_start-repeat_stop)); #if defined _DEBUG printf("+++ executeq: repeat %s(%d) times\n", repeat_buffer, atoi(repeat_buffer)); #endif (*bf_mp)+=atoi(repeat_buffer); repeat_done=true; memset(repeat_buffer, 0, BUFFER_SIZE); } else { #if defined _DEBUG printf("--- executeq: '%c' NAN\n", *(bf_sp+1)); #endif } } if ( !repeat_done ) { #if defined _DEBUG printf("%d (0x%0X) @ 0x%X -> ", *bf_mp, *bf_mp, bf_mp); (*bf_mp)++; printf("%d (0x%0X) @ 0x%X\n", *bf_mp, *bf_mp, bf_mp); #else (*bf_mp)++; #endif } if ( used_memory<bf_mp ) { used_memory=bf_mp; } } if ( *bf_sp=='-' ) { #if defined _DEBUG printf("+++ execute: -\n"); #endif if ( (bfo & BFO_QUICK) && bf_sp<_buffer+sz+1 ) { if ( *(bf_sp+1)>=48 && *(bf_sp+1)<=57 ) { repeat_start= ++bf_sp; while ( bf_sp<_buffer+sz+1 && *(bf_sp+1)>=48 && *(bf_sp+1)<=57 ) { bf_sp++; } repeat_stop=bf_sp+1; memcpy(repeat_buffer, repeat_start, abs(repeat_start-repeat_stop)); #if defined _DEBUG printf("+++ executeq: repeat %s(%d) times\n", repeat_buffer, atoi(repeat_buffer)); #endif (*bf_mp)-=atoi(repeat_buffer); repeat_done=true; memset(repeat_buffer, 0, BUFFER_SIZE); } else { #if defined _DEBUG printf("--- executeq: '%c' NAN\n", *(bf_sp+1)); #endif } } if ( !repeat_done ) { #if defined _DEBUG printf("%d (0x%0X) @ 0x%X -> ", *bf_mp, *bf_mp, bf_mp); (*bf_mp)--; printf("%d (0x%0X) @ 0x%X\n", *bf_mp, *bf_mp, bf_mp); #else (*bf_mp)--; #endif } if ( used_memory<bf_mp ) { used_memory=bf_mp; } } if ( *bf_sp=='>' ) { #if defined _DEBUG printf("+++ execute: >\n"); #endif repeat=1; if ( (bfo & BFO_QUICK) && bf_sp<_buffer+sz+1 ) { if ( *(bf_sp+1)>=48 && *(bf_sp+1)<=57 ) { repeat_start= ++bf_sp; while ( bf_sp<_buffer+sz+1 && *(bf_sp+1)>=48 && *(bf_sp+1)<=57 ) { bf_sp++; } repeat_stop=bf_sp+1; memcpy(repeat_buffer, repeat_start, abs(repeat_start-repeat_stop)); #if defined _DEBUG printf("+++ executeq: repeat %s(%d) times\n", repeat_buffer, atoi(repeat_buffer)); #endif repeat=atoi(repeat_buffer); memset(repeat_buffer, 0, BUFFER_SIZE); } else { #if defined _DEBUG printf("--- executeq: '%c' NAN\n", *(bf_sp+1)); #endif } } if ( bf_mp+repeat<=bf_mem+BF_MEMORY_SIZE) { #if defined _DEBUG printf("0x%X -> ", bf_mp); bf_mp+=repeat; printf("0x%X\n", bf_mp); #else bf_mp+=repeat; #endif } else { #if defined _DEBUG printf("--- execute>: out of memory bounds\n"); #else printf("warning: out of memory bounds\n"); #endif if ( bfo & BFO_QUICK ) { bf_mp=bf_mem+BF_MEMORY_SIZE; } } if ( used_memory<bf_mp ) { used_memory=bf_mp; } } if ( *bf_sp=='<' ) { #if defined _DEBUG printf("+++ execute: <\n"); #endif repeat=1; if ( (bfo & BFO_QUICK) && bf_sp<_buffer+sz+1 ) { if ( *(bf_sp+1)>=48 && *(bf_sp+1)<=57 ) { repeat_start= ++bf_sp; while ( bf_sp<_buffer+sz+1 && *(bf_sp+1)>=48 && *(bf_sp+1)<=57 ) { bf_sp++; } repeat_stop=bf_sp+1; memcpy(repeat_buffer, repeat_start, abs(repeat_start-repeat_stop)); #if defined _DEBUG printf("+++ executeq: repeat %s(%d) times\n", repeat_buffer, atoi(repeat_buffer)); #endif repeat=atoi(repeat_buffer); memset(repeat_buffer, 0, BUFFER_SIZE); } else { #if defined _DEBUG printf("--- executeq: '%c' NAN\n", *(bf_sp+1)); #endif } } if ( bf_mp-repeat>=bf_mem ) { #if defined _DEBUG printf("0x%X -> ", bf_mp); bf_mp-=repeat; printf("0x%X\n", bf_mp); #else bf_mp-=repeat; #endif } else { #if defined _DEBUG printf("--- execute<: out of memory bounds\n"); #else printf("warning: out of memory bounds\n"); #endif if ( bfo & BFO_QUICK ) { bf_mp=bf_mem; } } } if ( *bf_sp=='.' ) { #if defined _DEBUG printf("+++ execute: .\n"); #endif #if defined _DEBUG memDump(); #else putchar(*bf_mp); #endif if ( used_memory<bf_mp ) { used_memory=bf_mp; } } if ( *bf_sp==',' ) { #if defined _DEBUG printf("+++ execute: ,\n"); #endif if ( (bfo & BFO_QUICK) && bf_sp<_buffer+sz+1 ) { if ( *(bf_sp+1)>=48 && *(bf_sp+1)<=57 ) { repeat_start= ++bf_sp; while ( bf_sp<_buffer+sz+1 && *(bf_sp+1)>=48 && *(bf_sp+1)<=57 ) { bf_sp++; } repeat_stop=bf_sp+1; memcpy(repeat_buffer, repeat_start, abs(repeat_start-repeat_stop)); #if defined _DEBUG printf("+++ executeq: repeat %s(%d) times\n", repeat_buffer, atoi(repeat_buffer)); #endif repeat=atoi(repeat_buffer); memset(repeat_buffer, 0, BUFFER_SIZE); } else { #if defined _DEBUG printf("--- executeq: '%c' NAN\n", *(bf_sp+1)); #endif repeat=1; } } while ( repeat ) { *bf_mp=(UCHAR)getchar(); #if defined _DEBUG printf("+++ execute,: 0x%x\n", *bf_mp); #endif if ( bf_mp<bf_mem+BF_MEMORY_SIZE) { bf_mp++; } else { #if defined _DEBUG printf("--- executeq: out of memory bounds. input into last cell (%d left)\n", repeat); #else printf("warning: out of memory bounds. input into last cell\n"); #endif } repeat--; } if ( used_memory<bf_mp ) { used_memory=bf_mp; } } if ( *bf_sp=='[' ) { #if defined _DEBUG printf("+++ execute[: '[' found @ 0x%X\n", bf_sp); #endif UCHAR* tmp_bf_sp=index(bf_sp, ']')+1; int tmp_sz=abs(bf_sp-tmp_bf_sp); tmp_buffer=(UCHAR*)calloc(tmp_sz, sizeof(char)); if ( tmp_buffer ) { memcpy(tmp_buffer, bf_sp, tmp_sz); tmp_buffer[tmp_sz]=0; } else { #if defined _DEBUG printf("--- execute[: tmp_buffer=NULL\n"); #else printf("error: can't allocate memory\n"); #endif return false; } while ( tmp_buffer && !validate(tmp_buffer) ) { #if defined _DEBUG printf("+++ execute[::searchEndOfCycle: '%s'(%d) is invalid : ++\n", tmp_buffer, tmp_sz); #endif tmp_bf_sp=index(tmp_bf_sp, ']')+1; tmp_sz=abs(bf_sp-tmp_bf_sp); tmp_buffer=(UCHAR*)realloc(tmp_buffer, tmp_sz); memset(tmp_buffer, 0, tmp_sz); if ( tmp_buffer ) { memcpy(tmp_buffer, bf_sp, tmp_sz); tmp_buffer[tmp_sz]=0; } else { #if defined _DEBUG printf("--- execute[: tmp_buffer=NULL\n"); #else printf("error: can't allocate memory\n"); #endif return false; } } if ( tmp_buffer ) { int sz=strlen(tmp_buffer); tmp_buffer[sz-1]=0; while ( *bf_mp ) { #if defined _DEBUG printf("\n+++ execute: recursive calls left: %d\n", *bf_mp); #endif if ( !execute(tmp_buffer+1) ) { #if defined _DEBUG printf("--- execute: error execute while recursive calls\n"); memDump(); #endif return false; } } #if defined _DEBUG printf("+++ execute: exit from recursive call\n\n"); #endif free(tmp_buffer); bf_sp=tmp_bf_sp-1; } } bf_sp++; } free(repeat_buffer); return true; }