Beispiel #1
0
pubyte copymacros( pubyte dest, pubyte src )
{
    while ( *src )
    {
        if ( !mem_cmpign( src, "%GNAME%", 7 ))
        {
            dest += mem_copyuntilzero( dest, gname ) - 1;
            src += 7;
        }
        else if ( !mem_cmpign( src, "%GPATH%", 7 ))
        {
            dest += mem_copyuntilzero( dest, gpath ) - 1;
            src += 7;
        }
        else if ( !mem_cmpign( src, "%EXEPATH%", 9 ))
        {
            dest += mem_copyuntilzero( dest, exepath ) - 1;
            src += 9;
        }
        else
            *dest++ = *src++;
    }
    *dest++ = 0;
    return dest;
}
Beispiel #2
0
pstr  STDCALL getmodulepath( pstr name, pstr additional )
{
   str  temp;

   str_init( &temp );

#ifdef LINUX
   //Only for linux ???
   uint len = readlink( "/proc/self/exe", additional, 512 ) - 1;
   //uint sep1 = str_find(additionaļ,0,'\304',1);
   uint   separ = str_find( additional, 0, SLASH, 1 );
   //pCopyStr=strrchr(additionaļ,SLASH);
   //while ( len && (additional[ len ] != '/') ) len--;
   //if ( str_findch(filename,SLASH) != 0 )
   mem_copyuntilzero((pubyte) (additional + separ + 1), name );
   //strcpy(str_ptr(name),pCopyStr);
   //mem_copyuntilzero( additional + len + 1, name );
#else
   getmodulename( name );
   str_getdirfile( name, &temp, NULL );
   str_dirfile( &temp, additional, name );
#endif
   str_delete( &temp );
   return name;
}
Beispiel #3
0
pubyte getpath( pubyte filename )
{
    uint i = 0, last = 0, dot = 0;

    while ( filename[i] )
    {
        if ( filename[i] == '\\' )
            last = i;
        if ( filename[i] == '.' )
            dot = i;
        i++;
    }
    if ( !last )
    {
        ubyte  temp[512];

        GetFullPathName( filename, 512, temp, NULL );
        mem_copyuntilzero( filename, temp );
        return getpath( filename );
    }
    filename[dot] = 0;
    filename[last] = 0;

    return filename + last + 1;
}
Beispiel #4
0
pubyte   STDCALL os_getexepath( pubyte dir, pubyte name )
{
   uint len;
   //ubyte ptr_Test[512];
  pstr sDir,sName;


#ifdef LINUX
   //Only for linux
//   dir[0] = 0;
//   name[0] = 0;
   len = readlink( "/proc/self/exe", dir, 512 )- 1 ;
   while ( len && dir[ len ] != '/' ) {
        //dir[ len ] = ' ' ;
        len--;
   }
   mem_copyuntilzero( dir + len + 1, name );
#else
   len = GetModuleFileName( 0, dir, 512 ) - 1;
   while ( len && dir[ len ] != '\\' ) len--;
   mem_copyuntilzero( dir + len + 1, name );
#endif
   return dir;
}
Beispiel #5
0
/*
pubyte  STDCALL os_getexename( pubyte buf, uint size )
{
   uint len,lich=0;
   ubyte linkname[64];
   ubyte link_name[512];
   pid_t pid;
   int ret;
   pid= getpid();

   if(snprintf(linkname,sizeof(linkname),"/proc/%i/exe",pid) , 0)
   {
       abort();
   }
   ret = readlink(linkname,link_name,size);
   if (ret == -1) return NULL;
   while ( ret && link_name[ ret ] != '/' ) {
        //dir[ len ] = ' ' ;
        lich++;
   }
   mem_copyuntilzero( buf, link_name+ret-lich );
   //mem_copy(buf,link_name,+(ret-lich));
   return buf;
}
*/
pubyte   STDCALL os_getexename( pubyte dir)
{
   uint len,lich=0;
   ubyte dir2[512];
   //ubyte ptr_Test[512];

   len = readlink( "/proc/self/exe", dir2, 512 )- 1 ;
   while ( len && dir2[ len ] != '/' ) {
        //dir[ len ] = ' ' ;
        lich++;
        len--;
   }
   mem_copyuntilzero( dir, dir2 + len + 1 - lich);
   //print( "dir =%s\n", dir );
   return dir;
}
Beispiel #6
0
pubyte getprofile( pubyte key, puint pflag, uint flagval )
{
    pubyte      ret = ( pubyte )pflag;
    ubyte       val[512];

    if ( flagval < 0xFFF0 )
    {
        GetPrivateProfileString( profile, key, *pflag & flagval ? "1" : "0",
                                 val, 512, inifile );
        if ( val[0] == '1' )
            *pflag |= flagval;
        else
            *pflag &= ~flagval;
    }
    if ( flagval == 0xFFF0 )
    {
        GetPrivateProfileString( profile, key, ( pubyte )pflag,
                                 val, 512, inifile );
        copymacros( ( pubyte )pflag, val );
    }
    if ( flagval == 0xFFF1 )
    {
        ubyte keyi[64];
        uint  i = 0;

        mem_copyuntilzero( keyi, key );
        while ( 1 )
        {
            GetPrivateProfileString( profile, keyi, "", val, 512, inifile );
            if ( !val[0] )
                break;

            ( pubyte )pflag = copymacros( ( pubyte )pflag, val );
            sprintf( keyi, "%s%i", key, ++i );
        }
        ret = ( pubyte )pflag;
    }
    return ret;
}
Beispiel #7
0
pubyte  STDCALL load_common( pubyte input, pubyte* out, uint structsize )
{
   pvmobj  obj;
   ubyte   type = *input++;
   uint    flag = *( puint )input & 0x20FFFFFF; // ??? GHRT_ to zero
                             //  except GHRT_PRIVATE
   uint    len;

   input += sizeof( uint );

   _vm.ipack = flag & GHCOM_PACK ? 1 : 0;

   _vm.isize = load_bwd( &input );
/*   if ( type == OVM_GLOBAL )
   {
      _vm.isize += 50000;
//      print("Load = %s isize = %i\n", obj->name, _vm.isize );
   }*/
   obj = ( pvmobj )vmmng_begin( ( _vm.ipack ? 2 : 1 ) * _vm.isize );
   mem_zero( obj, structsize );

   obj->type = type;
   obj->flag = flag;
   *out = ( pubyte )obj + structsize;

   if ( flag & GHCOM_NAME )   
   {
      // считываем опционально имя
      len = mem_copyuntilzero( *out, input );
      obj->name = *out;

      input += len;
      *out += len;
   }

   return input;
}
Beispiel #8
0
pvartype  STDCALL load_var( pubyte* input, pubyte* output, uint count, 
                            puint size, uint align )
{
   pvartype   psub;
   povmtype   newtype;
   pubyte     out = *output;
   pubyte     ptr = *input;
   pvartype   ret;
   uint       i, off = 0, flag, len, k;
   
   ret = psub = ( pvartype )out;
         
   out += count * sizeof( vartype );
//   print("Count=%i ---------\n", count );
   for ( i = 0; i < count; i++ )
   {
      mem_zero( psub, sizeof( vartype ));
      psub->type = load_convert( &ptr );   
      psub->off = align ? ( off >> 2 ) : off;
      flag = *ptr++;
      psub->flag = ( ubyte )flag;
      if ( flag & VAR_NAME )
      {
         len = mem_copyuntilzero( out, ptr ); 
         psub->name = out;
         ptr += len;
//         print("    Field %i %s\n", i, psub->name );
         out += len;
      }
      newtype = ( povmtype )PCMD( psub->type );
      off += flag & VAR_PARAM ? ( newtype->stsize << 2 ) : newtype->size;

      if ( flag & VAR_OFTYPE )
         psub->oftype = load_convert( &ptr );

      psub->ptr = ( puint )out;

      if ( flag & VAR_DIM )
      {
         len = 1;
         psub->dim = *ptr++;
         
         for ( k = 0; k < psub->dim; k++ )      
         {
            *( puint )out = load_bwd( &ptr );
            len *= *( puint )out;
            out += sizeof( uint );
         }
         // Если reserved < 4 удаляем лишнее
         if ( psub->type == TReserved )
            off += len - 4;
      }
      if ( flag & VAR_DATA )
      {
         psub->data = 1;
//         print("Data=%s\n", psub->name );
         if ( newtype->vmo.flag & GHTY_STACK )
            len = newtype->size;
         else
         {
            if ( psub->type == TStr )
            {
               len = mem_len( ptr ) + 1;
//               print("Val=%s\n", ptr );
            }
            else
            {
               *( puint )out = load_bwd( &ptr );
               len = *( puint )out;
//               print("Load %i %x\n", len, *( puint )ptr );
               out += sizeof( uint );
            }
         }
         mem_copy( out, ptr, len );
         ptr += len;
         out += len;
      }
      // Alignment
      if ( align && ( off & 3 ))
         off += 4 - ( off & 0x3 );
//      print("off = %i \n", off );

      psub++;         
   }
   *size = off;

   *output = out;
   *input = ptr;
   return ret;
}