Exemplo n.º 1
0
/*
 * find any icat files on Flash and initiate transfer of these files to the iCAT ISFLash
 */
transferIcatFiles()
{
    char buffer[2048],filename[36];
    char *pCList,*pStr,*pType;
    int nfound,index,result;
    nfound = fffind("icat_top*.bit", buffer, sizeof(buffer));
    IPRINT2(-1,"\ntransferIcatFiles()  found: %d, names: '%s'\n", nfound,buffer);
    pCList = buffer;
    filename[0] = 0;

    for (pStr = (char *) strtok_r(buffer,",",&pCList);
	      pStr != NULL;
	      pStr = (char *) strtok_r(NULL,",",&pCList))
    {
       if (pStr != NULL)
          strncpy(filename,pStr,35);

       IPRINT1(1,"transferIcatFiles() filename: '%s'\n",filename);
       pType = (char*) strrchr(filename,'.') + 1;
       IPRINT2(1,"type: 0x%lx, '%s'\n",pType,pType);
       index = extractIndex(filename);
       IPRINT1(1,"index: %ld \n",index);
       result = transferFile2Icat( filename );
       filename[0] = 0;
    }
}
Exemplo n.º 2
0
/**
 * static func.
 *
 * Example: /foo/bar[10]/zod[3] would return:
 * ret: {"foo", "bar", "zod" }
 * index: { 0, 10, 3 }
 */
bool Shell::chopPath( const string& path, vector< string >& ret, 
	vector< unsigned int >& index )
{
	bool isAbsolute = chopString( path, ret, '/' );
	if ( isAbsolute ) {
		index.clear();
	} else {
		index.clear();
	}
	for ( unsigned int i = 0; i < ret.size(); ++i )
	{
		index.push_back( 0 );
		if ( ret[i] == "." )
			continue;
		if ( ret[i] == ".." ) {
			continue;
		}
		if ( !extractIndex( ret[i], index[i] ) ) {
			cout << "Error: Shell::chopPath: Failed to parse indices in path '" <<
				path << "'\n";
				ret.resize( 0 );
				index.resize( 0 );
				return isAbsolute;
		}
		unsigned int pos = ret[i].find_first_of( '[' );
		if ( pos != string::npos )
			ret[i] = ret[i].substr( 0, pos );
	}

	return isAbsolute;
}
Exemplo n.º 3
0
bool ScummDiskImage::generateIndex() {
	int bufsize;

	bufsize = extractIndex(0);

	free(_buf);
	_buf = (byte *)calloc(1, bufsize);

	Common::MemoryWriteStream out(_buf, bufsize);

	extractIndex(&out);

	delete _stream;
	_stream = new Common::MemoryReadStream(_buf, bufsize);

	return true;
}
Exemplo n.º 4
0
/*
 *breif:获取表的间接引用对象.
 *param[iref]:间接引用表.
*/
Object* IndirectRefTable::get(IndirectRef iref) const {
    IndirectRefKind kind = indirectRefKind(iref);
    if (kind != kind_) {
        if (iref == NULL) {
            ALOGW("Attempt to look up NULL %s reference", indirectRefKindToString(kind_));
            return kInvalidIndirectRefObject;
        }
        if (kind == kIndirectKindInvalid) {
            ALOGE("JNI ERROR (app bug): invalid %s reference %p",
                    indirectRefKindToString(kind_), iref);
            abortMaybe();
            return kInvalidIndirectRefObject;
        }
        // References of the requested kind cannot appear within this table.
        return kInvalidIndirectRefObject;
    }

    u4 topIndex = segmentState.parts.topIndex;
    u4 index = extractIndex(iref);
    if (index >= topIndex) {
        /* bad -- stale reference? */
        ALOGE("JNI ERROR (app bug): accessed stale %s reference %p (index %d in a table of size %d)",
                indirectRefKindToString(kind_), iref, index, topIndex);
        abortMaybe();
        return kInvalidIndirectRefObject;
    }

    Object* obj = table_[index].obj;
    if (obj == NULL) {
        ALOGI("JNI ERROR (app bug): accessed deleted %s reference %p",
                indirectRefKindToString(kind_), iref);
        abortMaybe();
        return kInvalidIndirectRefObject;
    }

    u4 serial = extractSerial(iref);
    if (serial != table_[index].serial) {
        ALOGE("JNI ERROR (app bug): attempt to use stale %s reference %p",
                indirectRefKindToString(kind_), iref);
        abortMaybe();
        return kInvalidIndirectRefObject;
    }

    return obj;
}
Exemplo n.º 5
0
bool ScummDiskImage::open(const Common::String &filename) {
	uint16 signature;

	// check signature
	openDisk(1);

	if (_game.platform == Common::kPlatformApple2GS) {
		File::seek(142080);
	} else {
		File::seek(0);
	}

	signature = fileReadUint16LE();
	if (signature != 0x0A31) {
		error("ScummDiskImage::open(): signature not found in disk 1");
		return false;
	}

	extractIndex(0); // Fill in resource arrays

	if (_game.features & GF_DEMO)
		return true;

	openDisk(2);

	if (_game.platform == Common::kPlatformApple2GS) {
		File::seek(143104);
		signature = fileReadUint16LE();
		if (signature != 0x0032)
			error("Error: signature not found in disk 2");
	} else {
		File::seek(0);
		signature = fileReadUint16LE();
		if (signature != 0x0132)
			error("Error: signature not found in disk 2");
	}


	return true;
}
Exemplo n.º 6
0
/*
 * Verify that the indirect table lookup is valid.
 *
 * Returns "false" if something looks bad.
 */
bool IndirectRefTable::getChecked(IndirectRef iref) const
{
    if (iref == NULL) {
        LOGW("Attempt to look up NULL %s reference", indirectRefKindToString(kind_));
        return false;
    }
    if (indirectRefKind(iref) == kIndirectKindInvalid) {
        LOGE("JNI ERROR (app bug): invalid %s reference %p",
                indirectRefKindToString(kind_), iref);
        abortMaybe();
        return false;
    }

    int topIndex = segmentState.parts.topIndex;
    int idx = extractIndex(iref);
    if (idx >= topIndex) {
        /* bad -- stale reference? */
        LOGE("JNI ERROR (app bug): accessed stale %s reference %p (index %d in a table of size %d)",
                indirectRefKindToString(kind_), iref, idx, topIndex);
        abortMaybe();
        return false;
    }

    if (table_[idx] == NULL) {
        LOGI("JNI ERROR (app bug): accessed deleted %s reference %p",
                indirectRefKindToString(kind_), iref);
        abortMaybe();
        return false;
    }

    if (!checkEntry("use", iref, idx)) {
        return false;
    }

    return true;
}
Exemplo n.º 7
0
/*
 * transfer an iCAT file from the controller's flash file system to the iCAT ISF
 * e.g. icat configuration files:  icat_config00.tbl, icat_config01.tbl, etc..
 *  GMB
 */
int transferFile2Icat( char *filename )
{
   char md5sig[32 + 1];
   char md5sig2[32 + 1];
   char name[36], md5[36];
   int result, ret, di;
   unsigned long size, nSize, sizeBytes, len;
   int tableIndex,dataOffset,status,OverWriteYes;;
   char *xferfileBuffer;
   char *pFileExtType;

   OverWriteYes = 1;

   size = getFFSize(filename);
   IPRINT2(-1,"transferFile2Icat: File: '%s', Bytes: %ld\n",filename,size);
   if (size < 1)   /* return file not present */
    return(0);

   // need this extra length (headersize) for the readback  verification step
   xferfileBuffer = (char*) malloc(size + getISFFileHeaderSize() + 4); 
   if ( (xferfileBuffer == NULL) )
   {
      errLogRet(LOGIT,debugInfo, " ****** System Memory Malloc failed\n");
      return(-1);
   }

   /* transfer FFS into buffer */
   result =  cpFF2Buf(filename,xferfileBuffer,&nSize);
   if (result < 0) 
   {
      errLogRet(LOGIT,debugInfo, " ****** Read from Flash FileSystem failed\n");
      free(xferfileBuffer);
      return(-1);
   }

   /* ---------------------------*/
   /* calc MD5 checksum signiture */
   calcMd5(xferfileBuffer, nSize, md5sig);

   IPRINT3(1,"transferFile2Icat: file: '%s', nSize: %ld, md5: '%s'\n",
               filename,nSize, md5sig);

   // determine if this file is a FPGA bitstream *.bit or configuration file *.tbl
   pFileExtType = (char*) strrchr(filename,'.') + 1;
   IPRINT1(1,"transferFile2Icat: File Ext Type: '%s'\n",pFileExtType);
   tableIndex = extractIndex(filename);
   IPRINT1(1,"transferFile2Icat: tableIndex; %ld\n", tableIndex);
   // =======================================================================
   // Configuration table transfers
   //
   if ( (strcmp("tbl",pFileExtType) == 0) )
   {
      // =======================================================================
      // read conf file header from iCAT flash
      // If the file already exists on icat ISFlash don't re-copy to ISFlash
      tableIndex = getConfigTableByName(filename);  // no longer use index encoded in name, just find it.
      IPRINT2(-11,"transferFile2Icat: filename: '%s', tableIndex: %d\n", filename, tableIndex);
      if (tableIndex != -1)  // -1 means didn't find this named file
      {
         result = readConfigTableHeader(tableIndex, name, md5, (int*) &sizeBytes);
         if (result != -1)   // -1 == invalid table index, no file present
         {
             IPRINT2(1,"transferFile2Icat: 2cp md5: '%s'\n\t\t\t\t\t\t vs present md5: '%s'\n",
                      md5sig,md5);      
             ret = strcmp(md5sig, md5);
             if (ret == 0) 
             {
                IPRINT(-1,"transferFile2Icat: File already Present on Icat ISFlash\n\n");
                free(xferfileBuffer);
                return(0);
             }
         }
      }
      // =======================================================================
      result = writeIsfFile(filename, md5sig, nSize, xferfileBuffer, OverWriteYes);
      memset(xferfileBuffer,0,nSize);

      // now read it back and confirm proper writing to iCAT ISF
      len = nSize;
      // relocate file, there is no guarentee that same index was used.
      tableIndex = getConfigTableByName(filename);  // no longer use index encoded in name, just find it.
      IPRINT2(-11,"transferFile2Icat: filename: '%s', tableIndex: %d\n", filename, tableIndex);
      result = readConfigTable(tableIndex, name, md5, (UINT32*) &len, xferfileBuffer, (int*) &dataOffset);
      IPRINT4(-12,"transferFile2Icat() name: '%s', md5: '%s', len: %ld, dataOffset: %ld\n",name,md5,len,dataOffset);
   
   }
   // =======================================================================
   // iCAT FPAG file transfers
   //
   else if ( (strcmp("bit",pFileExtType) == 0) && ((tableIndex >= -1) && (tableIndex <= 1)) )
   {
      IPRINT3(1,"transferFile2Icat() bitstream: '%s', md5: '%s', len: %ld \n",
              filename,md5sig,nSize);
      // =======================================================================
      // read conf file header from iCAT flash
      // If file already exist on icat ISFlash don't re-copy to ISFlash
      if (tableIndex == -1)
         tableIndex = 0;
      result = readIcatFPGAHeader(tableIndex,name, md5, (int*)  &sizeBytes);
      if (result != -1)   // -1 == invalid table index, no file present
      {
          IPRINT2(1,"transferFile2Icat: 2cp md5: '%s'\n\t\t\t\t\t\t vs preset md5: '%s'\n",
                md5sig,md5);      
          ret = strcmp(md5sig, md5);
          if (ret == 0) 
          {
             IPRINT(-1,"transferFile2Icat: File already Present on Icat ISFlash\n\n");
	     free(xferfileBuffer);
             return(0);
          }
      }
      // =======================================================================
      // transfer FPGA bit-stream

      result = writeIcatFPGA(tableIndex, filename, md5sig, nSize, xferfileBuffer);
      memset(xferfileBuffer,0,nSize);
      // now read it back confirm proper writing to iCAT ISF
      len = nSize;
      result = readIcatFPGA(tableIndex, name, md5, (UINT32*) &len, xferfileBuffer);
      dataOffset = 0;   
   }
   /* calc MD5 checksum signiture */
   calcMd5((xferfileBuffer + dataOffset), len, md5sig2);
   IPRINT3(1,"transferFile2Icat: file: '%s', written/read md5: '%s'\n\t\t\t\t\t\t\t vs '%s'\n",
          filename, md5sig, md5sig2);

   ret = strcmp(md5sig, md5sig2);
   if (ret != 0) 
   {
      char errmsg[256];
      // failure on Primary or Seconadary iCAT FPGA image, must mark failure via a small file
      if ( (strcmp("bit",pFileExtType) == 0)  )
      {
          // do not alter format of string prior to '\n'
          sprintf(errmsg,"iCAT_DNA: 0x%llx \nImage failed to copy.",iCAT_DNA);
          if ( (tableIndex >= -1) && (tableIndex <= 0) ) 
          {
             createFailFile("pri_imagecp.fail",  errmsg);
             // deleting primary image is probably un-necessary , it's just not going to boot anymore
          }
          else
          {
             createFailFile("sec_imagecp.fail",  errmsg);
             isffpgadel(); // deleted secondary image
          }
          errLogRet(LOGIT,debugInfo, "transferFile2Icat(): '%s' iCAT FPGA image copy, failed.\n",filename);
      }
      else if ( (strcmp("tbl",pFileExtType) == 0) && ((tableIndex >= 0) && (tableIndex < 6)) )
      {  // maybe moot since we don't copy tables any more to the ISF flash
         isftbldel(tableIndex);	// delete table that failed to copy
      }

      errLogRet(LOGIT,debugInfo, "transferFile2Icat():  ****** ERROR: MD5 Checksum do NOT match\n");
      errLogRet(LOGIT,debugInfo, "transferFile2Icat():  True MD5 - '%s'\n",md5sig);
      errLogRet(LOGIT,debugInfo, "transferFile2Icat():  Calc MD5 - '%s'\n",md5sig2);
      free(xferfileBuffer);
      return(-1);
   }
   IPRINT(-1,"Transfer Succesful\n\n");
   free(xferfileBuffer);
   return 0;
}
Exemplo n.º 8
0
/*
 *breif:从"pRef"删除 "obj".
*/
bool IndirectRefTable::remove(u4 cookie, IndirectRef iref)
{
    IRTSegmentState prevState;
    prevState.all = cookie;
    u4 topIndex = segmentState.parts.topIndex;
    u4 bottomIndex = prevState.parts.topIndex;

    assert(table_ != NULL);
    assert(alloc_entries_ <= max_entries_);
    assert(segmentState.parts.numHoles >= prevState.parts.numHoles);

    IndirectRefKind kind = indirectRefKind(iref);
    u4 index;
    if (kind == kind_) {
        index = extractIndex(iref);
        if (index < bottomIndex) {
            /* wrong segment */
            ALOGV("Attempt to remove index outside index area (%ud vs %ud-%ud)",
                    index, bottomIndex, topIndex);
            return false;
        }
        if (index >= topIndex) {
            /* bad -- stale reference? */
            ALOGD("Attempt to remove invalid index %ud (bottom=%ud top=%ud)",
                    index, bottomIndex, topIndex);
            return false;
        }
        if (table_[index].obj == NULL) {
            ALOGD("Attempt to remove cleared %s reference %p",
                    indirectRefKindToString(kind_), iref);
            return false;
        }
        u4 serial = extractSerial(iref);
        if (table_[index].serial != serial) {
            ALOGD("Attempt to remove stale %s reference %p",
                    indirectRefKindToString(kind_), iref);
            return false;
        }
    } else if (kind == kIndirectKindInvalid && gDvmJni.workAroundAppJniBugs) {
        // reference looks like a pointer, scan the table to find the index
        int i = findObject(reinterpret_cast<Object*>(iref), bottomIndex, topIndex, table_);
        if (i < 0) {
            ALOGW("trying to work around app JNI bugs, but didn't find %p in table!", iref);
            return false;
        }
        index = i;
    } else {
        // References of the requested kind cannot appear within this table.
        return false;
    }

    if (index == topIndex - 1) {
        // Top-most entry.  Scan up and consume holes.
        int numHoles = segmentState.parts.numHoles - prevState.parts.numHoles;
        if (numHoles != 0) {
            while (--topIndex > bottomIndex && numHoles != 0) {
                ALOGV("+++ checking for hole at %d (cookie=0x%08x) val=%p",
                    topIndex-1, cookie, table_[topIndex-1].obj);
                if (table_[topIndex-1].obj != NULL) {
                    break;
                }
                ALOGV("+++ ate hole at %d", topIndex-1);
                numHoles--;
            }
            segmentState.parts.numHoles = numHoles + prevState.parts.numHoles;
            segmentState.parts.topIndex = topIndex;
        } else {
            segmentState.parts.topIndex = topIndex-1;
            ALOGV("+++ ate last entry %d", topIndex-1);
        }
    } else {
        /*
         * Not the top-most entry.  This creates a hole.  We NULL out the
         * entry to prevent somebody from deleting it twice and screwing up
         * the hole count.
         */
        table_[index].obj = NULL;
        segmentState.parts.numHoles++;
        ALOGV("+++ left hole at %d, holes=%d", index, segmentState.parts.numHoles);
    }

    return true;
}
Exemplo n.º 9
0
/*
 * Remove "obj" from "pRef".  We extract the table offset bits from "iref"
 * and zap the corresponding entry, leaving a hole if it's not at the top.
 *
 * If the entry is not between the current top index and the bottom index
 * specified by the cookie, we don't remove anything.  This is the behavior
 * required by JNI's DeleteLocalRef function.
 *
 * Note this is NOT called when a local frame is popped.  This is only used
 * for explicit single removals.
 *
 * Returns "false" if nothing was removed.
 */
bool IndirectRefTable::remove(u4 cookie, IndirectRef iref)
{
    IRTSegmentState prevState;
    prevState.all = cookie;
    int topIndex = segmentState.parts.topIndex;
    int bottomIndex = prevState.parts.topIndex;

    assert(table_ != NULL);
    assert(alloc_entries_ <= max_entries_);
    assert(segmentState.parts.numHoles >= prevState.parts.numHoles);

    int idx = extractIndex(iref);
    bool workAroundAppJniBugs = false;

    if (indirectRefKind(iref) == kIndirectKindInvalid && gDvmJni.workAroundAppJniBugs) {
        idx = linearScan(iref, bottomIndex, topIndex, table_);
        workAroundAppJniBugs = true;
        if (idx == -1) {
            LOGW("trying to work around app JNI bugs, but didn't find %p in table!", iref);
            return false;
        }
    }

    if (idx < bottomIndex) {
        /* wrong segment */
        LOGV("Attempt to remove index outside index area (%d vs %d-%d)",
            idx, bottomIndex, topIndex);
        return false;
    }
    if (idx >= topIndex) {
        /* bad -- stale reference? */
        LOGD("Attempt to remove invalid index %d (bottom=%d top=%d)",
            idx, bottomIndex, topIndex);
        return false;
    }

    if (idx == topIndex-1) {
        // Top-most entry.  Scan up and consume holes.

        if (workAroundAppJniBugs == false && !checkEntry("remove", iref, idx)) {
            return false;
        }

        table_[idx] = NULL;
        int numHoles = segmentState.parts.numHoles - prevState.parts.numHoles;
        if (numHoles != 0) {
            while (--topIndex > bottomIndex && numHoles != 0) {
                LOGV("+++ checking for hole at %d (cookie=0x%08x) val=%p",
                    topIndex-1, cookie, table_[topIndex-1]);
                if (table_[topIndex-1] != NULL) {
                    break;
                }
                LOGV("+++ ate hole at %d", topIndex-1);
                numHoles--;
            }
            segmentState.parts.numHoles = numHoles + prevState.parts.numHoles;
            segmentState.parts.topIndex = topIndex;
        } else {
            segmentState.parts.topIndex = topIndex-1;
            LOGV("+++ ate last entry %d", topIndex-1);
        }
    } else {
        /*
         * Not the top-most entry.  This creates a hole.  We NULL out the
         * entry to prevent somebody from deleting it twice and screwing up
         * the hole count.
         */
        if (table_[idx] == NULL) {
            LOGV("--- WEIRD: removing null entry %d", idx);
            return false;
        }
        if (workAroundAppJniBugs == false && !checkEntry("remove", iref, idx)) {
            return false;
        }

        table_[idx] = NULL;
        segmentState.parts.numHoles++;
        LOGV("+++ left hole at %d, holes=%d", idx, segmentState.parts.numHoles);
    }

    return true;
}