Register | Login
Forum Index > Source Help > masm plugin help
Author Message
Pages: 1
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[721] masm plugin help - posted: 2011-11-17 18:02:12

i am stuck , and i think i will give up . i spent 3 days trying to make to work . but..............
it's hard to program in language that did not have arithmetic expression.

anyway
i am trying to use 'char right[5100];' as an array of string by calculation the address that
i will write to it or read from it by using this formula
Code:
          eax = indx
          imul eax, 255
          edx = @right
          eax += edx;
          edx = @val
          H_strcpy(eax , edx );


but it did not work ,
here is my entire code
Code:
//******************************************************//
//                                                      //
//                                                      //
//                 Masm plugin                          //
//               By  Emil Halim                         //
//                 11/11/2011                           //
//                                                      //
//******************************************************//

plugins off;
plugins emit; 

program WIN32DLL 'Masm PLUGIN';

#include 'zirplug/framework.zir';
#include 'zirutils.zir';

//////////////////////////////

const strLoaded = 'Masm plugin has loaded!';

function  H_strcpy(Dword dst,src)
{ 
  Eax = dst; 
  Edx = src; 
  push Eax;
  BL =  [Edx]; 
  while ( BL != 0)  
   { 
      [Eax] = BL; 
      Eax++; Edx++; 
      BL =  [Edx]; 
   }  
  [Eax] = 0;
  pop Eax;
} 

function H_strcat(Dword dst,src) 
{ 
  Eax = dst; 
  Edx = src;
  push Eax;
  while (byte [Eax] != 0) { Eax++; } 
  while (byte [Edx] != 0)  
   { 
      BL =  [Edx]; 
      [Eax] = BL;  
      Edx++; Eax++; 
   } 
  [Eax] = 0;
  pop Eax;
} 

inline procedure  H_strjoin(;)
{
  $temp = 1;
  $to = $argc - 1;  
  $repeat $to:  
     H_strcat($arg[0],$arg[$temp]);  
  $temp++;
  $end
}

//////////////////////////////


function event_Data() {
  uses edi;
  char buf[2048];
  char val[255];
  char var[255];
  char right[5100];
  char tmp[255];
  dword indx;
  boolean Flg = true;  
  
  if(Flg)
   {
       // always start with  '{' 
      eax = Ziron_ExpectNextToken(zirBraceOpen);    
      if (eax == -1) {
          Ziron_FatalError('Expected { symbol');
          return true;
       }
              
       repeat {
              // found '}' so let's finished
             eax = Ziron_PeekNextToken(); 
             if (eax == zirBraceClose)
              {
                 Ziron_GetNextToken(); 
                 //Ziron_ShowMessage(Ziron_GetStringValue());
                 break;
              } 
              
              buf=0;
              right=0;
              indx = 0;
              // get the variable name and hold it in Var  
              eax = Ziron_ExpectNextToken(zirIdent);
              if (eax == -1) {
                  Ziron_FatalError('Expected Variable Name');
                  return true;
               }
              H_strcpy(@var,Ziron_GetStringValue());     
              
              
              // get DB or DW or DD or DQ
              eax = Ziron_ExpectNextToken(zirIdent);
              if (eax == -1) {
                  Ziron_FatalError('Expected Variable Name');
                  return true;
               }
               
              
              strCmp('db',strLower(Ziron_GetStringValue()));
              // found DB 
              if(eax)
               { 
                 @digit:
                   // get whatever after DB 
                   eax = Ziron_GetNextToken();
                   if(eax == zirQuestionSym)
                    {
                      H_strjoin(@buf, 'byte ' , @var, ' = ' , '0;' ); 
                      Ziron_Exec(@buf);
                      continue;
                    }
                   case (eax) {
                          state zirHEXADECIMAL:
                              H_strcpy(@val,'0x');
                              H_strcat(@val,Ziron_GetStringValue());
                              break;
                    state zirNUMBER:
                        H_strcpy(@val,Ziron_GetStringValue());                 
                              break;      
                          default:
                              Ziron_FatalError('Expected number');
                              return true;
                    } //end case 
                   //pointer  addr = @right + indx * 255;
                   eax = indx
                   imul eax, 255
                   edx = @right
                   eax += edx;
                   edx = @val
                   H_strcpy(eax , edx );
                                           
                   
                   // check for ','
                   eax = Ziron_PeekNextToken();
                   if (eax == zirCOMMA) {
                         Ziron_GetNextToken(); // remove ','
                         indx++;        
                         goto @digit
                   } 
                   if(indx == 0)
                    { 
                       buf = 0;
                       H_strjoin(@buf, 'byte ' , @var, ' = ' , @val , ';' ); 
                       Ziron_ShowMessage(@buf);
                       Ziron_Exec(@buf); 
                    }
                   else
                    {
                       H_strcat(@buf, 'byte ' );
                       ecx = 0;
                       while(ecx < indx)
                        { 
                           push ecx;
                           IntToStr(ecx,@tmp); 
                           eax = ecx; imul  eax,255; edx = @right;  eax += Edx; 
                           pointer pt = eax;
                           H_strjoin(@buf, @var, '[' , @tmp ,']=' , pt  , '; ' ); 
                           pop ecx ; ecx++; 
                        }   
                    } 
                   Ziron_ShowMessage(@buf);
                   Ziron_Exec(@buf);  
               }  
       };            
      return true;
   }
  else
   {   
      return false;                           // let Ziron handle the line  
   }  
}

procedure FileEntry(DWord handle; char* strCode) {
  
     eax = strOffset(strCode, '.DATA');
     while (char[eax] <> 0) {
            char[eax] = "_";
            eax = strOffset(eax, '.DATA');
     }
     
     eax = strOffset(strCode, '.CODE');
     while (char[eax] <> 0) {
            char[eax] = "_";
            eax = strOffset(eax, '.CODE');
     }
     
}

function InitPlugin(pointer pGetF) {
  Ziron_LoadAll(pGetF); //use framework utility function to load all

  //register our keyword
  Ziron_RegisterKeyword('_Data', @event_Data);
  
  return strLoaded;
}

entry function DLLMain(DWord iDLL; DWord iReason; Pointer iResult) {
  if (iReason == DLL_PROCESS_ATTACH) {
    return true;
  }

  return false;
}

exports InitPlugin, FileEntry;


http://www.freewebs.com/ogremagic/index.htm
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[722] - posted: 2011-11-17 18:04:49
and here is the test program
Code:
{

//var      DB 0x00 
//vv       Db 1 
//ar1      DB ?  
//ar2      DB 0 

ml       db 0 , 1 , 100

/*
                   ; Declare a byte, referred to as location var, containing the value 64.
var2     DB ?      ; Declare an uninitialized byte, referred to as location var2.
         DB 10     ; Declare a byte with no label, containing the value 10. Its location is var2 + 1.
X        DW ?      ; Declare a 2-byte uninitialized value, referred to as location X.
Y        DD 30000  ; Declare a 4-byte value, referred to as location Y, initialized to 30000.

Z        DD 1, 2, 3     ; Declare three 4-byte values, initialized to 1, 2, and 3. The value of location Z + 8 will be 3.
bytes    DB 10 DUP(?)   ; Declare 10 uninitialized bytes starting at location bytes.
arr      DD 100 DUP(0)  ; Declare 100 4-byte words starting at location arr, all initialized to 0
str1     DB 'hello',0   ; Declare 6 bytes starting at the address str, initialized to the ASCII character values for hello and the null (0) byte.
*/
}

wait_key(nil);
ExitProcess(0);


i think i will not code again until ziron will be more solid.

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

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[723] - posted: 2011-11-17 18:24:59
it is a shame to hear that... i will look into this error anyways, as for expressions of course this is planned but i can not add/fix everything at once... btw why not write your plugins in another language which can still help Ziron improve, you could even code in masm or pascal or c or any language.

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[724] - posted: 2011-11-17 19:35:45
i am so sorry , but beleave me i liked Ziron very much , and liked to code in ziron ,which
make programing in asm is very simple and more effectives. in one word i am enjoying coding
with ziron.

but i am stuck to make that expression to work ,..........

any way i will continue supporting Ziron , i will start to code plugin in c code and of course let you know.

please , can you add plugin section in forum that written in other language.

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

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[725] - posted: 2011-11-17 20:26:47
OK i've used your code and found 2 bugs in Ziron.. 1 was with imul.. it worked for eax but others was a slight bug

Code:
imul edx, 255


was actually producing

Code:
imul edx, eax, 255


and the other was with while statements, anyways i have updated the beta package and here is your working code:

Code:
plugins off;
plugins emit; 

program WIN32DLL 'Masm PLUGIN';

#include 'zirplug/framework.zir';
#include 'zirutils.zir';

//////////////////////////////

const strLoaded = 'Masm plugin has loaded!';

function  H_strcpy(Dword dst,src)
{ 
  uses edx ebx;
  
  Eax = dst; 
  Edx = src; 
  push Eax;
  BL =  [Edx]; 
  while ( BL != 0)  
   { 
      [Eax] = BL; 
      Eax++; Edx++; 
      BL =  [Edx]; 
   }  
  [Eax] = 0;
  pop Eax;
} 

function H_strcat(Dword dst,src) 
{ 
  uses edx ebx;

  Eax = dst; 
  Edx = src;
  push Eax;
  while (byte [Eax] != 0) { Eax++; } 
  while (byte [Edx] != 0)  
   { 
      BL =  [Edx]; 
      [Eax] = BL;  
      Edx++; Eax++; 
   } 
  [Eax] = 0;
  pop Eax;
} 

inline procedure  H_strjoin(;)
{
  $temp = 1;
  $to = $argc - 1;  
  $repeat $to:  
     H_strcat($arg[0],$arg[$temp]);  
  $temp++;
  $end
}

//////////////////////////////


function event_Data() {
  uses edi;
  char buf[2048];
  char val[255];
  char var[255];
  char right[5100];
  char tmp[255];
  dword indx;
  boolean Flg = true;  
  
  if(Flg) {
    // always start with  '{' 
    eax = Ziron_ExpectNextToken(zirBraceOpen);    
    if (eax == -1) {
      Ziron_FatalError('Expected { symbol');
      return true;
    }
              
    repeat {
      // found '}' so let's finished
      eax = Ziron_PeekNextToken(); 
      if (eax == zirBraceClose) {
        Ziron_GetNextToken(); 
        break;
      } 
              
      buf=0;
      right=0;
      indx = 0;
      
      // get the variable name and hold it in Var  
      eax = Ziron_ExpectNextToken(zirIdent);
      if (eax == -1) {
        Ziron_FatalError('Expected Variable Name');
        return true;
      }
      H_strcpy(@var, Ziron_GetStringValue());     
              
      // get DB or DW or DD or DQ
      eax = Ziron_ExpectNextToken(zirIdent);
      if (eax == -1) {
        Ziron_FatalError('Expected Variable Name');
        return true;
      }
               
              
      eax = strCmp('db',strLower(Ziron_GetStringValue()));
      // found DB 
      if (eax) { 
         
        @digit:
        
        // get whatever after DB 
        eax = Ziron_GetNextToken();
        if (eax == zirQuestionSym) {
          H_strjoin(@buf, 'byte ' , @var, ' = ' , '0;' ); 
          Ziron_Exec(@buf);
          continue;
        }
          
        case (eax) {
          state zirHEXADECIMAL:
          state zirNUMBER:
            edx = indx;
            imul edx, 255
            eax = @right;
            edx += eax;            
          
            H_strcpy(edx,Ziron_GetStringValue());                 
            break;   
          default:
            Ziron_FatalError('Expected number');
            return true;
        }
        
        // check for ','
        eax = Ziron_PeekNextToken();
        if (eax == zirCOMMA) {
          Ziron_GetNextToken(); // remove ','
          indx++;        
          goto @digit;
        } 
          
        buf = 0;
        if (indx == 0) { 
          H_strjoin(@buf, 'byte ' , @var, ' = ' , @val , ';' ); 
          Ziron_ShowMessage(@buf);
          Ziron_Exec(@buf); 
        } else {
          H_strcat(@buf, 'byte ' );            

          edi = xor;        
          while (edi < indx) {       
            IntToStr(edi, @tmp);           
          
            edx = edi;
            imul edx, 255;
            eax = @right;
            edx += eax; 
            
            H_strjoin(@buf, @var, '[' , @tmp ,']=' , edx , '; ' ); 
            
            edi++; 
          }   
        } 
        Ziron_ShowMessage(@buf);
        Ziron_Exec(@buf);  
      }  
    };            
    return true;
  } else {   
    return false;                           // let Ziron handle the line  
  }  
}

procedure FileEntry(DWord handle; char* strCode) {
  
     eax = strOffset(strCode, '.DATA');
     while (char[eax] <> 0) {
            char[eax] = "_";
            eax = strOffset(eax, '.DATA');
     }
     
     eax = strOffset(strCode, '.CODE');
     while (char[eax] <> 0) {
            char[eax] = "_";
            eax = strOffset(eax, '.CODE');
     }
     
}

function InitPlugin(pointer pGetF) {
  Ziron_LoadAll(pGetF); //use framework utility function to load all

  //register our keyword
  Ziron_RegisterKeyword('_Data', @event_Data);
  
  return strLoaded;
}

entry function DLLMain(DWord iDLL; DWord iReason; Pointer iResult) {
  if (iReason == DLL_PROCESS_ATTACH) {
    return true;
  }

  return false;
}

exports InitPlugin, FileEntry;


as for plugin section - you can post any language inside that forum, as long as it is stated in thread which compiler / language the plugin is written. Note that since you have been developing plugins in Ziron it has helped fix many bugs, thanks.

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[726] - posted: 2011-11-17 21:53:49

ok , thanks for your hard work.

http://www.freewebs.com/ogremagic/index.htm
Pages: 1
create new reply


Quick reply:

Message:



Currently Active Users:
There are currently 6 user(s) online. 0 member(s) and 6 guest(s)
Most users ever online was 1046, January 28, 2022, 2:08 pm.


Statistics:
Threads: 225 | Posts: 1848 | Members: 51 | Active Members: 51
Welcome to our newest member, yecate
const Copyright = '2011-2024 © OverHertz Ltd. All rights reserved.';
Web development by OverHertz Ltd