}
#ifdef USE_WIN32STREAMEXTRACTION
+
+void int64_LE2BE(int64_t* pBE, const int64_t v)
+{
+ /* convert little endian to big endian */
+ if (htonl(1) != 1L) { /* no work if on little endian machine */
+ memcpy(pBE, &v, sizeof(int64_t));
+ } else {
+ int i;
+ uint8_t rv[sizeof(int64_t)];
+ uint8_t *pv = (uint8_t *) &v;
+
+ for (i = 0; i < 8; i++) {
+ rv[i] = pv[7 - i];
+ }
+ memcpy(pBE, &rv, sizeof(int64_t));
+ }
+}
+
+
+void int32_LE2BE(int32_t* pBE, const int32_t v)
+{
+ /* convert little endian to big endian */
+ if (htonl(1) != 1L) { /* no work if on little endian machine */
+ memcpy(pBE, &v, sizeof(int32_t));
+ } else {
+ int i;
+ uint8_t rv[sizeof(int32_t)];
+ uint8_t *pv = (uint8_t *) &v;
+
+ for (i = 0; i < 4; i++) {
+ rv[i] = pv[3 - i];
+ }
+ memcpy(pBE, &rv, sizeof(int32_t));
+ }
+}
+
+
BOOL processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, size_t dwSize)
{
/* pByte contains the buffer
*/
PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT* pContext = &(bfd->win32DecompContext);
- BOOL bContinue = FALSE;
- LONGLONG dwDataOffset = 0;
- LONGLONG dwDataLen;
+ bool bContinue = FALSE;
+ int64_t dwDataOffset = 0;
+ int64_t dwDataLen;
/* Win32 Stream Header size without name of stream.
* = sizeof (WIN32_STREAM_ID)- sizeof(WCHAR*);
*/
- DWORD dwSizeHeader = 20;
+ int32_t dwSizeHeader = 20;
do {
if (pContext->liNextHeader >= dwSize) {
}
if (pContext->liNextHeader < dwSize) {/* is a header in this block ? */
- DWORD dwOffsetTarget;
- DWORD dwOffsetSource;
+ int32_t dwOffsetTarget;
+ int32_t dwOffsetSource;
if (pContext->liNextHeader < 0) {
/* start of header was before this block, so we
dwOffsetSource = pContext->liNextHeader;
}
- DWORD dwHeaderPartLen = dwSizeHeader-dwOffsetTarget;
- BOOL bHeaderIsComplete;
+ int32_t dwHeaderPartLen = dwSizeHeader-dwOffsetTarget;
+ bool bHeaderIsComplete;
if (dwHeaderPartLen <= dwSize-dwOffsetSource)
/* header (or rest of header) is completely available
/* recalculate position of next header */
if (bHeaderIsComplete) {
- dwDataOffset = pContext->liNextHeader+dwSizeHeader+pContext->header_stream.dwStreamNameSize;
- pContext->liNextHeader = dwDataOffset+pContext->header_stream.Size.QuadPart;
+ /* convert stream name size (32 bit little endian) to machine type */
+ int32_t dwNameSize;
+ int32_LE2BE (&dwNameSize, pContext->header_stream.dwStreamNameSize);
+ dwDataOffset = dwNameSize+pContext->liNextHeader+dwSizeHeader;
+
+ /* convert stream size (64 bit little endian) to machine type */
+ int64_LE2BE (&(pContext->liNextHeader), pContext->header_stream.Size);
+ pContext->liNextHeader += dwDataOffset;
+
pContext->bIsInData = pContext->header_stream.dwStreamId == BACKUP_DATA;
if (dwDataOffset == dwSize)
bContinue = FALSE;
*/
bool is_stream_supported(int stream)
{
- /* No Win32 backup on this machine */
+ /* With Win32 backup on this machine */
switch (stream) {
case STREAM_WIN32_DATA:
#ifdef HAVE_ZLIB
#endif
#ifdef USE_WIN32STREAMEXTRACTION
+
+/* this should physically correspond to WIN32_STREAM_ID
+ * from winbase.h on Win32. We didn't inlcude cStreamName
+ * as we don't use it and don't need it for a correct struct size.
+ */
+
+typedef struct _BWIN32_STREAM_ID {
+ int32_t dwStreamId;
+ int32_t dwStreamAttributes;
+ int64_t Size;
+ int32_t dwStreamNameSize;
+} BWIN32_STREAM_ID, *LPBWIN32_STREAM_ID ;
+
+
typedef struct _PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT {
- LONGLONG liNextHeader;
- BOOL bIsInData;
- WIN32_STREAM_ID header_stream;
+ int64_t liNextHeader;
+ bool bIsInData;
+ BWIN32_STREAM_ID header_stream;
} PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT;
#endif