예제 #1
0
파일: 7z.c 프로젝트: BSzili/aros-stuff
SRes SzFileSeekImp(void *object, Int64 *pos, ESzSeek method)
{
  CFileXadInStream *s = (CFileXadInStream *)object;
#ifdef __amigaos4__
	struct xadMasterIFace *IxadMaster = s->IxadMaster;
#else
	struct xadMasterBase *xadMasterBase = s->xadMasterBase;
#endif
	int res=0;
//	ULONG posn = *pos >> 32;

	switch(method)
	{
		case SZ_SEEK_SET:
  			res = xadHookAccess(XADAC_INPUTSEEK, (long)*pos-(s->ai->xai_InPos), 0, s->ai);
		break;

		case SZ_SEEK_CUR:
  			res = xadHookAccess(XADAC_INPUTSEEK, (long)*pos, 0, s->ai);
		break;

		case SZ_SEEK_END:
  			res = xadHookAccess(XADAC_INPUTSEEK, (s->ai->xai_InSize) - (long)*pos - (s->ai->xai_InPos), 0, s->ai);
		break;
	}

  if (res == 0)
	{
		s->posn = *pos;
		*pos = s->ai->xai_InPos;
    	return SZ_OK;
	}
  return SZ_ERROR_FAIL;
}
예제 #2
0
static xadINT32 PKDdecrBuf(xadSTRPTR *buf, xadUINT32 *i, struct xadArchiveInfo *ai,
struct xadMasterBase *xadMasterBase, xadUINT32 oldmode)
{
  xadINT32 err, size;
  if(!(err = xadHookAccess(XADM XADAC_READ, 4, &size, ai)))
  {
    if(!(err = xpkDecrunch(buf, i, ai, xadMasterBase)))
    {
      if(!oldmode)
        err = xadHookAccess(XADM XADAC_READ, 4, &size, ai);
    }
  }
  return err;
}
예제 #3
0
파일: 7z.c 프로젝트: BSzili/aros-stuff
SRes SzFileReadImp(void *object, void *buffer, size_t *size)
{
  CFileXadInStream *s = (CFileXadInStream *)object;
#ifdef __amigaos4__
	struct xadMasterIFace *IxadMaster = s->IxadMaster;
#else
	struct xadMasterBase *xadMasterBase = s->xadMasterBase;
#endif

	if(!g_buffer) g_buffer = AllocVec(kBufferSize, MEMF_PRIVATE);

  size_t processedSizeLoc =+ *size; // =+
	//s->posn = processedSizeLoc;

  if (*size > kBufferSize)
    *size = kBufferSize;

	if(xadHookAccess(XADAC_READ, *size, g_buffer, s->ai) != XADERR_OK)
		return SZ_ERROR_FAIL;

	memcpy(buffer, g_buffer, *size);

//	*buffer = g_buffer;
/*
  if (processedSize != 0)
    *processedSize = processedSizeLoc;
*/
  return SZ_OK;
}
예제 #4
0
파일: 7z.c 프로젝트: BSzili/aros-stuff
ASM(LONG) sz_UnArchive(REG(a0, struct xadArchiveInfo *ai),
REG(a6, struct xadMasterBase *xadMasterBase))
#endif
{
	struct xad7zprivate *xad7z = ai->xai_PrivateClient;
  struct xadFileInfo *fi = ai->xai_CurFile;
	long err=XADERR_OK;
  CFileXadInStream *archiveStream = &xad7z->archiveStream;
  CSzArEx *db = &xad7z->db;       /* 7z archive database structure */
  ISzAlloc allocImp;           /* memory functions for main pool */
  ISzAlloc allocTempImp;       /* memory functions for temporary pool */
	CLookToRead *lookStream = &xad7z->lookStream;

	UInt32 *blockIndex = &xad7z->blockIndex;
      Byte **outBuffer = &xad7z->outBuffer; /* it must be 0 before first call for each new archive. */
      size_t *outBufferSize = &xad7z->outBufferSize;  /* it can have any value before first call (if outBuffer = 0) */
        size_t offset = 0;
        size_t outSizeProcessed = 0;
	int res=0;

  allocImp.Alloc = SzAlloc;
  allocImp.Free = SzFree;
  allocTempImp.Alloc = SzAllocTemp;
  allocTempImp.Free = SzFreeTemp;

#ifdef __amigaos4__
	if(!newlibbase)
	{
    	IExec = (struct ExecIFace *)(*(struct ExecBase **)4)->MainInterface;
	    newlibbase = OpenLibrary("newlib.library", 52);
    	if(newlibbase)
        	INewlib = GetInterface(newlibbase, "main", 1, NULL);
	}
#elif defined(__AROS__)
	if(!aroscbase && !(aroscbase = OpenLibrary("arosc.library", 41)))
		return(XADERR_RESOURCE);
#else
 SysBase = *(struct ExecBase **)4;
#endif

  res = SzArEx_Extract(
    db,
    &lookStream->s, 
    (UInt32)fi->xfi_EntryNumber - 1,         /* index of file */
    blockIndex,       /* index of solid block */
    outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */
    outBufferSize,    /* buffer size for output buffer */
    &offset,           /* offset of stream for required file in *outBuffer */
    &outSizeProcessed, /* size of file in *outBuffer */
    &allocImp,
    &allocTempImp);

	if(res==SZ_OK)
	{
		/* test loopy stuff */
		UBYTE *tempmem = NULL;
		long bytes = 0,writebytes=0;

		tempmem = AllocVec(1024,MEMF_CLEAR);
		if(!tempmem) return XADERR_NOMEMORY;

		for(bytes = outSizeProcessed;bytes>0;bytes-=1024)
		{
			if(bytes>1024)
			{
				writebytes = 1024;
			}
			else
			{
				writebytes = bytes;
			}

			CopyMem((*outBuffer)+offset+(outSizeProcessed-bytes),tempmem,writebytes);
			err = xadHookAccess(XADAC_WRITE,writebytes,tempmem,ai);
			if(err != XADERR_OK) break;
//			xadHookAccess(XADAC_WRITE,outSizeProcessed,(*outBuffer)+offset, ai);

		}
		FreeVec(tempmem);
	}

	if(err==XADERR_OK) err=sztoxaderr(res);

	return err;
}