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

i think it would be better to create your buffer first and then just copy it all in 1 chunk, it will be faster and you will have less problems.

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt
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

how can i achieve that in the event_while function. in this stage you did not have a pointer

to the code buffer so that you can navigate until you found '}'.

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

Colin admin
Posts
928
Threads
49
Location
Bulgaria

you would not do it on the event but when you do the strOffset('.while', ... etc

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

ok , i am using this to calculate the max buffer size of the while body , need to know your opinion please.

    // part of FileEntry code that computes max buf  
    buflen = 0; // global variable 
    eax = strOffset(strCode, '_WHILE');
    while (char[eax] <> 0) {
           edx = 0;
           while(char[eax] != "{")
            {
               eax++;
            }
           while(char[eax] != "}")
            {
               edx++;
               eax++;
            } 
           if(edx >  buflen)
            {
              buflen = edx;
            }
           eax = strOffset(eax, '_WHILE');
    } 

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

Colin admin
Posts
928
Threads
49
Location
Bulgaria

i don't think that will work because of nested while loops

maybe something like:

	buflen = 0; // global variable 

	push edi //nest counter
	edi = xor;
	eax = strOffset(strCode, '_WHILE');
	while (char[eax] <> 0) {
		edx = xor;
		
		while(char[eax] != "{") {
			eax++;
		}
		edi++;
		
		while(edi <> 0) {
			edx++;
			eax++;
			
			if (char[eax] == "{") {
				edi++;
			} elseif (char[eax] == "}") {
				edi--;
			}
		} 
		
		if(edx >  buflen) {
			buflen = edx;
		}
		eax = strOffset(eax, '_WHILE');
	} 
	pop edi

note that i have not tested this.

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

i have access violation in masm.dll , so that i putted this for debug

  buflen = 0; // global variable 
  push edi //nest counter
  edi = xor;
  eax = strOffset(strCode, '_WHILE');
  while (char[eax] <> 0) {
    edx = xor;
    while(char[eax] != "{") {
      eax++;
    }
    edi++;
    while(edi <> 0) {
      edx++;
      eax++;
      if (char[eax] == "{") {
        edi++;
      } elseif (char[eax] == "}") {
        edi--;
      }
    } 
    if(edx >  buflen) {
      buflen = edx;
    }
    eax = strOffset(eax, '_WHILE');
  } 
  pop edi
    // debug 
    char tmp[1024];
    IntToStr(buflen, @tmp);
    Ziron_ShowMessage(@tmp);    

so i got that

PlugSys: Basic plugin has loaded! PlugSys: Emit plugin has loaded! PlugSys: Masm plugin version 0.01 has loaded! PlugSys: Sleep seconds plugin has loaded PlugSys: 14 PlugSys: 0 PlugSys: 0 PlugSys: 0 PlugSys: 0 PlugSys: 0 PlugSys: 0 PlugSys: 0 PlugSys: 0 -------------------------------------------- Access violation at address 01493394 in module 'masm.dll'. Read of address 00000000

from that i have found out that buflen is 0 when FileEntry finished but why?

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

Colin admin
Posts
928
Threads
49
Location
Bulgaria

not all files contain _while's... check the plugin documentation search for the function to display the filename from handle, then print out the filename along with the size, to check.

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

ok , i got strange results from Ziron_GetFileName

here is my code of FileEntry

procedure FileEntry(DWord handle; char* strCode) {
  
     uses edi;
       
     Ziron_ShowMessage(Ziron_GetFileName(handle));
} 
     

i got that

PlugSys: Basic plugin has loaded! PlugSys: Emit plugin has loaded! PlugSys: Masm plugin version 0.01 has loaded! PlugSys: Sleep seconds plugin has loaded PlugSys: PlugSys: PlugSys: macro return PlugSys: macro return PlugSys: macro return PlugSys: macro return PlugSys: macro return PlugSys: macro return PlugSys: macro return -------------------------------------------- Access violation at address 0023334A in module 'masm.dll'. Read of address 00000000

forget the access violation now , i will check it later , but i think there is a problem with Ziron_GetFileName , am i wright ?

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