Register | Login
Forum Index > Plugins > Ziron_SetFileBuffer function
Author Message
Pages: 1 2 3
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[282] Ziron_SetFileBuffer function - posted: 2011-11-03 19:02:57
well , could you please provide some example that uses the new function Ziron_SetFileBuffer.

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

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[283] - posted: 2011-11-03 19:10:52
i have not tested this but a quick example is:

Code:
function FileEntry(DWord handle; char* strCode) {
  const maxLen = 512;
  
  //create a buffer
  char myBuffer[maxLen];
  
  if (handle == 0) {
    strlcpy(@myBuffer, 'program WIN32CUI \'test\'; #include \'console.zir\'; print(\'hello world!\r\n\'); wait_key(nil); ExitProcess(0);', 104);
  
    //set the buffer
    Ziron_SetFileBuffer(handle, @myBuffer, 104);
  }  
}


you would then export this function

Code:
exports InitPlugin, FileEntry;


now basically when this plugin is loaded, it will replace the main file with the above code, basically forcing the application to only compile a small hello world sample.

of course since this is static replacement you can just do:

Code:
function FileEntry(DWord handle; char* strCode) {
  if (handle == 0) {
    //set the buffer
    Ziron_SetFileBuffer(handle, 'program WIN32CUI \'test\'; #include \'console.zir\'; print(\'hello world!\r\n\'); wait_key(nil); ExitProcess(0);', 104);
  }  
}


so the idea behind these functions is you are able to preprocess the file, change things (then set the new file buffer) and then ziron will compile/assemble the file as if it is the original smile

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
[284] - posted: 2011-11-03 19:41:00

very good , thanks.

is the second argument of FileEntry is the address of original file buffer ?

and is the first argument is not zero , who can we make use of it ?


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

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[285] - posted: 2011-11-03 19:44:58
the first argument is a ziron handle to the file that is being entered, so for example

most likely the first included file will be id 1, and so on.. so for each included file you would preprocess the file and pass it back with the handle that was passed, i just checked for 0 as example of replacing the main file..

the second argument yes is the char pointer to the actually internal buffer and should not be changed directly, you would scan through this code and place your changed version into your own buffer, then pass it via Ziron_SetFileBuffer.

hope you understand smile

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
[290] - posted: 2011-11-03 20:40:52

is that mean , Ziron will call FileEntry function many times ( per included file),
and we have to check that by first param?

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

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[291] - posted: 2011-11-03 21:00:29
it will call it only when a new file is opened and a new internal buffer is being created for the file...

so...

Code:
program WIN32CUI 'temp';

#include 'kernel32.zir';

ExitProcess(0);


in this situation, FileEntry will be called a twice, the first is the actual project file (the code above) and the second will be the entrance to the inclued file 'kernel32.zir'

of course if you include 'console.zir' it also has its own included files, so it will also be called when they are entered

Code:
program WIN32CUI 'temp';

#include 'kernel32.zir';
#include 'kernel32.zir';

ExitProcess(0);


this above would still be twice, because the second include is ignored.

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
[299] - posted: 2011-11-03 22:45:34

ok, the next code gives this error
List index out of bounds (2)
Code:
function GetNextLine(char* strbuf; pointer dest)
{ 
  global int32 incr;

  uses esi edi;
  eax = xor;
  
  ecx = incr;
  esi = strbuf;  
  add esi, ecx
  edi = dest;
  
  while(char[esi] != 0)
   {
      if (word[esi] == "\r\n")
       {
         eax += 2; 
         break;
       }
      bl = char[Esi]; 
      char[edi] = bl; 
      eax++; 
      esi++;
      edi++;
   }
  char[edi] = 0; 
  
  add ecx, eax
  incr = ecx;
}

function FileEntry(DWord handle; char* strCode)
{
  const maxLen = 512;
  
  //create a buffer
  char myBuffer[maxLen];
  
  //preprocess the main file
  if (handle == 0)
   {    
     push edi
     edi = GetNextLine(strCode,@myBuffer);
     while(edi > 0) 
      {
         Ziron_ShowMessage(@myBuffer);
         edi = GetNextLine(strCode,@myBuffer);
      } 
     pop edi
   }   
}




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

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[301] - posted: 2011-11-03 23:11:04
i do not see any problems in this code, the problem must lie in another part of the code

EDIT: i see the problem, i will fix this and re-update package shortly - else i tested and have your code compiled and works fine.

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Pages: 1 2 3
create new reply


Quick reply:

Message:



Currently Active Users:
There are currently 2 user(s) online. 0 member(s) and 2 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