in pseudocode #usr/bin/perl -w sub inline my @asm; #the ASM cmds buffer do { getinput(); push(@asm,input); if(isloop(input)) { dealwithloop(); } else { dealwithregularcommand(); } } #### our pseudocode for the loop now looks like this sub inline my @asm; #the ASM cmds buffer do { getinput(); push(@asm,input); if(isloop(input)) { do { if(isjmp(input)) { $continue=testjmp(); } elsif(isloop(input())#loops and jumps are handled differently { $continue=testloop(); } else { dothing(input); } }until($continue==0) } else { dealwithregularcommand(); } } #### Something like this sub jump # this is basically all psuedocode the real sub is more complicated but this is the gist { if($condition == TRUE) { $jmptaken = 1; } else { $jmptaken = 0; } } sub loopstuff { do { &DoAllTheThing!!(); #since the loop/jmp is pushed to the array anyway, it will be run in the &doallthethings }until($jmptaken == 0) } #### the real code: sub interactive { my $current = 0; my %interactives; my @tmpASM; my $placeholder = 0; my $linesplit = ''; my $iLINE= ''; my $tmpstr = ''; my $first = 0; &tellme("\e[31mInteractive mode is enabled.",1,0); &tellme("\e[31mType your commands as you were were putting them into a file.",1,0); &tellme("\e[31mType ;status to check status, and int 0x80 to save a frame.",1,0); &tellme("\e[31mType -v or +v at any time to raise or lower the verbosity level.",1,0); &tellme("\e[31mType current or cmd at any time to print out the current cmds stored in the main array.",1,0); &tellme("\e[31mType q or quit to leave.",2,0); &tellme("\e[31mType anything to continue.",2,0); &getinput; print "\n"; &status; do { push(@tmpASM,$iLINE); #add it to our main parsing array $interactives{$iLINE} = $placeholder; &tellme("\e[34m".$iLINE."\e[33m pushed into main array. There have been \e[31m".$placeholder." \e[33m commands entered.",1,3) if$ first > 0; $placeholder++; &parsecmd($iLINE); system 'clear' if $first > 0; &status if $first > 0; print "\e[37mPhant0m>"; $first++; $tmpstr = &getinput; $tmpstr =~ m/(^[^;]*)/; # split at comments $iLINE = &trim($1) if (defined($1) and $1 ne '' and substr(&trim($1),0,1) ne ';'); # if we got something... $iLINE =~ m/(\w+)[ \t]+(\w+)[ \t]*,?[ \t]*(([^;]*))/i; #split that sucker up my $quickloop = &trim(uc($1)); my $quicklabel = &trim($2) if ($iLINE ne 'CDQ' and defined($2)); if (uc($iLINE) eq '+V') { $verbose++ ; &tellme("\e[31mVerbosity increased.",2,0); $iLINE = ''; } elsif (uc($iLINE) eq '-V') { $verbose-- ; $verbose =0 if $verbose == -1; &tellme("\e[31mVerbosity decreased.",2,0); $iLINE = ''; } elsif (uc($iLINE) eq 'CURRENT' or uc($iLINE) eq "CMD") { $iLINE = ''; &tellme("Main Parsing Array",2,0); &tellme("------------------------------------",1,0); foreach (@tmpASM) { &tellme($_,2,0); } } elsif ($quickloop eq 'JNE' or $quickloop eq 'JNS' or $quickloop eq 'JS' or $quickloop eq 'JE' or $quickloop eq 'JNE' or $quickloop eq 'JZ' or $quickloop eq 'JNZ' or $quickloop eq 'LOOP') { my $isjmptaken = 0; $current = $interactives{$quicklabel.":"}; my $loopnumber = $current; do { $tmpASM[$current] =~ m/(\w+)[ \t]+(\w+)[ \t]*,?[ \t]*(([^;]*))/i; #split that sucker up yet again... $quickloop = &trim(uc($1)); $quicklabel = &trim($2) if ($iLINE ne 'CDQ' and defined($2)); if (uc($quickloop) eq 'LOOP') { $isjmptaken = &LOOP($quickloop, $quicklabel); } elsif($quickloop eq 'JNE' or $quickloop eq 'JNS' or $quickloop eq 'JS' or $quickloop eq 'JE' or $quickloop eq 'JNE' or $quickloop eq 'JZ' or $quickloop eq 'JNZ') { $isjmptaken = &JMP($quickloop, $quicklabel); } else { &parsecmd($tmpASM[$current]); } $current++; if (not defined $tmpASM[$current]) { $current = $loopnumber; } } while ($isjmptaken == 1); push(@tmpASM,$quickloop." ".$quicklabel); #add it to our main loop $iLINE = ''; #clear it out so the loop isnt run again at the top of our code :) } } until (uc($iLINE) eq 'QUIT' or uc($iLINE) eq 'Q' or uc($iLINE) eq 'E' or uc($iLINE) eq 'EXIT'); }