Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / Plugins

PlugIn Example in C

A community discussion post from the original code:zIRON forum.

Replies

Colin admin
Posts
928
Threads
49
Location
Bulgaria

seems there is some other problem also, i will see if i can find why is there access violation before i upload, will let you know shortly.

Colin admin
Posts
928
Threads
49
Location
Bulgaria

OK, this should be all corrected now, the new MOV handler had a few small issues.

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

ok, i am trying to change this code

edx=10;
.WHILE( edx > 5)
{ 
  edx--;
}
print('edx = ', Edx); 

to this , so that ziron will understand it

@__While__1:
if( edx > 5)  {
 edx--;
 goto @__While__1; 
}

but got that error

[1,21]: Unexpected character "}". in [plugin buffer] Code: goto @__While__1; }

and here is the while event function ,part of masm plugin

function event_While() {
  uses edi esi ecx ebx;
  boolean Flg = true;  
  char condBuf[1024];
  char label[1024];
  char tmp[1024];
  global Dword incr; 
    
  if(Flg) {    
        //get the condition from while
        condBuf=0;
        eax = Ziron_GetNextToken();
        if (eax == zirParenOpen)
         {
            eax = Ziron_GetNextToken();
            while( eax != zirParenClose)
             {
               H_strjoin(@condBuf , ' ' ,Ziron_GetStrValue());
               eax = Ziron_GetNextToken(); 
             }      
         } 
        else
         {
             eax = Ziron_IsNextLineBreak();
             while(!eax)
              {
                H_strjoin(@condBuf , ' ' ,Ziron_GetStrValue());
                Ziron_GetNextToken(); 
                eax = Ziron_IsNextLineBreak();
              }
             H_strjoin(@condBuf , ' ' ,Ziron_GetStrValue()); 
         }             
       incr++; 
       // always start with  '{' 
       eax = Ziron_ExpectNextToken(zirBraceOpen);    
       if (eax == -1) {
            Ziron_FatalError('Expected { symbol');
            return true;
        }
       // put the label here
       label=0;
       IntToStr(incr, @tmp);
       H_strjoin(@label , '@__While__' , @tmp, ':'); 
       Ziron_Exec(@label);  
       Ziron_ShowMessage(@label);
       // local lable without ':' at the end
       label=0;
       H_strjoin(@label , '@__While__' , @tmp);        
       tmp=0;
       H_strjoin(@tmp , 'if(' , @condBuf , ')  {');
       Ziron_Exec(@tmp); 
       Ziron_ShowMessage(@tmp); 
             
       repeat {
          // found '}' so let's finished
          eax = Ziron_PeekNextToken(); 
          if (eax == zirBraceClose) {
              tmp=0;
              H_strjoin(@tmp , ' goto ' , @label, '; }');
              Ziron_ShowMessage(@tmp); 
              Ziron_Exec(@tmp); 
              Ziron_GetNextToken();
              break;
           } 
          // update to next line
          // get the entire line and execute it  
          Ziron_GetNextToken();    
          Ziron_ExtractLine(@tmp, 2048);  
          GotoLineEnd();
          Ziron_ShowMessage(@tmp); 
          Ziron_Exec(@tmp);  
       };        
        return true;   // let Ziron handle the next line   
  } else {     
        return false;  // let Ziron handle the line  
  }  
}

http://www.freewebs.com/ogremagic/index.htm

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

also when remove '}' from this line

H_strjoin(@tmp , ' goto ' , @label, '; }');

so that it is look like that

H_strjoin(@tmp , ' goto ' , @label, ';');

it compiles ok but did not work correctly e.g it does not print edx = 5

http://www.freewebs.com/ogremagic/index.htm

Colin admin
Posts
928
Threads
49
Location
Bulgaria

this is because ziron is an assembler not a compiler, you can not pass fragmented code to be assembled, if you need to do this you would need to use raw assembly code...

instead of if you will need to write an if processor...

e.g.

if (eax == 1) {

to

cmp eax, 1
jne @myendif;

the options are if you are writing a masm compiler plugin then you would need to build a full buffer and then execute it... you could copy the whole contents of the if statement and execute it inside the buffer..

executing:

if (....) {
  //rest of buffer that was inside the while
}
Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt
you would need to build a full buffer and then execute it... you could copy the whole contents of the if statement and execute it inside the buffer

i think that it is good solution , but what is the recommended buffer size that will hold the

entire while body?

http://www.freewebs.com/ogremagic/index.htm

Colin admin
Posts
928
Threads
49
Location
Bulgaria

you would need to calculate this in real time and create a dynamic buffer...

so you would keep track of your pointer offset... then use another or variable to find the offset of the matching } and then create your buffer to match the size of

size=offset2-offset1

then do a strCopy from offset 1 to size

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

or the better thing is using growable buffer , and i think the best implementation is using

a class , so what do you think.

http://www.freewebs.com/ogremagic/index.htm