diff options
Diffstat (limited to 'heimdall/source')
54 files changed, 375 insertions, 465 deletions
diff --git a/heimdall/source/Arguments.cpp b/heimdall/source/Arguments.cpp index a37572d..feae2e1 100644 --- a/heimdall/source/Arguments.cpp +++ b/heimdall/source/Arguments.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/Arguments.h b/heimdall/source/Arguments.h index 72aa036..83cf128 100644 --- a/heimdall/source/Arguments.h +++ b/heimdall/source/Arguments.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/BeginDumpPacket.h b/heimdall/source/BeginDumpPacket.h index 9561aa3..d664674 100644 --- a/heimdall/source/BeginDumpPacket.h +++ b/heimdall/source/BeginDumpPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna
+/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/heimdall/source/BeginSessionPacket.h b/heimdall/source/BeginSessionPacket.h index c688504..27d982e 100644 --- a/heimdall/source/BeginSessionPacket.h +++ b/heimdall/source/BeginSessionPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/BridgeManager.cpp b/heimdall/source/BridgeManager.cpp index 8d4a9b6..d9e6f06 100644 --- a/heimdall/source/BridgeManager.cpp +++ b/heimdall/source/BridgeManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -19,7 +19,7 @@ THE SOFTWARE.*/ // C Standard Library -#include <stdio.h> +#include <cstdio> // libusb #include <libusb.h> @@ -53,7 +53,9 @@ #include "SessionSetupResponse.h" // Future versions of libusb will use usb_interface instead of interface. +#ifndef usb_interface #define usb_interface interface +#endif #define USB_CLASS_CDC_DATA 0x0A @@ -68,27 +70,11 @@ const DeviceIdentifier BridgeManager::supportedDevices[BridgeManager::kSupported enum { - kDumpBufferSize = 4096, -}; - -enum -{ kFileTransferSequenceMaxLengthDefault = 800, kFileTransferPacketSizeDefault = 131072, kFileTransferSequenceTimeoutDefault = 30000 // 30 seconds }; -enum -{ - kHandshakeMaxAttempts = 5, - kReceivePacketMaxAttempts = 5 -}; - -enum -{ - kPitSizeMultiplicand = 4096 -}; - int BridgeManager::FindDeviceInterface(void) { Interface::Print("Detecting device...\n"); @@ -232,7 +218,7 @@ int BridgeManager::FindDeviceInterface(void) libusb_free_config_descriptor(configDescriptor); - if (result != LIBUSB_SUCCESS) + if (interfaceIndex < 0) { Interface::PrintError("Failed to find correct interface configuration\n"); return (BridgeManager::kInitialiseFailed); @@ -313,138 +299,51 @@ bool BridgeManager::InitialiseProtocol(void) unsigned char dataBuffer[7]; - int result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, 0x22, 0x3, 0, nullptr, 0, 1000); - - if (result < 0 && verbose) - Interface::PrintWarning("Control transfer #1 failed. Result: %d\n", result); - - memset(dataBuffer, 0, 7); - dataBuffer[1] = 0xC2; - dataBuffer[2] = 0x01; - dataBuffer[6] = 0x07; - - result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, 0x20, 0x0, 0, dataBuffer, 7, 1000); - - if (result < 0 && verbose) - Interface::PrintWarning("Control transfer #2 failed. Result: %d\n", result); - - result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, 0x22, 0x3, 0, nullptr, 0, 1000); - - if (result < 0 && verbose) - Interface::PrintWarning("Control transfer #3 failed. Result: %d\n", result); + // Send "ODIN" + memcpy(dataBuffer, "ODIN", 4); + memset(dataBuffer + 4, 0, 1); - result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, 0x22, 0x2, 0, nullptr, 0, 1000); - - if (result < 0 && verbose) - Interface::PrintWarning("Control transfer #4 failed. Result: %d\n", result); + if (!SendBulkTransfer(dataBuffer, 4, 1000)) + { + Interface::PrintError("Failed to send handshake!"); + } + // Expect "LOKE" memset(dataBuffer, 0, 7); - dataBuffer[1] = 0xC2; - dataBuffer[2] = 0x01; - dataBuffer[6] = 0x08; - - result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, 0x20, 0x0, 0, dataBuffer, 7, 1000); - - if (result < 0 && verbose) - Interface::PrintWarning("Control transfer #5 failed. Result: %d\n", result); - result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, 0x22, 0x2, 0, nullptr, 0, 1000); + int dataTransferred = 0; - if (result < 0 && verbose) - Interface::PrintWarning("Control transfer #6 failed. Result: %d\n", result); + int result = libusb_bulk_transfer(deviceHandle, inEndpoint, dataBuffer, 7, &dataTransferred, 1000); - unsigned int attempt = 0; - - // max(250, communicationDelay) - int retryDelay = (communicationDelay > 250) ? communicationDelay : 250; - - for (; attempt < kHandshakeMaxAttempts; attempt++) + if (result != LIBUSB_SUCCESS) { - if (attempt > 0) - { - if (verbose) - Interface::PrintErrorSameLine(" Retrying...\n"); - - // Wait longer each retry - Sleep(retryDelay * (attempt + 1)); - } - - int dataTransferred = 0; - - // Send "ODIN" - memcpy(dataBuffer, "ODIN", 4); - memset(dataBuffer + 4, 0, 1); - - result = libusb_bulk_transfer(deviceHandle, outEndpoint, dataBuffer, 4, &dataTransferred, 1000); - if (result < 0) - { - if (verbose) - Interface::PrintError("Failed to send data: \"%s\"\n", dataBuffer); - else - Interface::PrintError("Failed to send data!"); - - return (false); - } - - if (dataTransferred != 4) - { - if (verbose) - Interface::PrintError("Failed to complete sending of data: \"%s\"\n", dataBuffer); - else - Interface::PrintError("Failed to complete sending of data!"); - - return (false); - } - - // Expect "LOKE" - memset(dataBuffer, 0, 7); - - int retry = 0; - dataTransferred = 0; - - result = libusb_bulk_transfer(deviceHandle, inEndpoint, dataBuffer, 7, &dataTransferred, 1000); - - if (result < 0) + if (verbose) + Interface::PrintError("Failed to receive handshake response. Result: %d\n", result); + } + else + { + if (dataTransferred == 4 && memcmp(dataBuffer, "LOKE", 4) == 0) { - if (verbose) - Interface::PrintError("Failed to receive handshake response."); + // Successfully received "LOKE" + Interface::Print("Protocol initialisation successful.\n\n"); + return (true); } else { - if (dataTransferred == 4 && memcmp(dataBuffer, "LOKE", 4) == 0) - { - // Successfully received "LOKE" - break; - } - else - { - if (verbose) - Interface::PrintError("Expected: \"%s\"\nReceived: \"%s\"\n", "LOKE", dataBuffer); + if (verbose) + Interface::PrintError("Expected: \"LOKE\"\nReceived: \"%s\"\n", dataBuffer); - Interface::PrintError("Unexpected handshake response!"); - } + Interface::PrintError("Unexpected handshake response!\n"); } } - if (attempt == kHandshakeMaxAttempts) - { - if (verbose) - Interface::PrintErrorSameLine("\n"); - - Interface::PrintError("Protocol initialisation failed!\n\n"); - return (false); - } - else - { - Interface::Print("Protocol initialisation successful.\n\n"); - return (true); - } + Interface::PrintError("Protocol initialisation failed!\n\n"); + return (false); } -BridgeManager::BridgeManager(bool verbose, int communicationDelay) +BridgeManager::BridgeManager(bool verbose) { this->verbose = verbose; - this->communicationDelay = communicationDelay; libusbContext = nullptr; deviceHandle = nullptr; @@ -676,46 +575,6 @@ bool BridgeManager::BeginSession(void) } } - // -------------------- KIES DOESN'T DO THIS -------------------- - - /*DeviceTypePacket deviceTypePacket; - - if (!SendPacket(&deviceTypePacket)) - { - Interface::PrintError("Failed to request device type!\n"); - return (false); - } - - SessionSetupResponse deviceTypeResponse; - - if (!ReceivePacket(&deviceTypeResponse)) - return (false); - - unsigned int deviceType = deviceTypeResponse.GetResult(); - - switch (deviceType) - { - // NOTE: If you add a new device type don't forget to update the error message below! - - case 0: // Galaxy S etc. - case 3: // Galaxy Tab - case 30: // Galaxy S 2 Skyrocket - case 180: // Galaxy S etc. - case 190: // M110S Galaxy S - - if (verbose) - Interface::Print("Session begun with device of type: %d.\n\n", deviceType); - else - Interface::Print("Session begun.\n\n"); - - return (true); - - default: - - Interface::PrintError("Unexpected device info response!\nExpected: 0, 3, 30, 180 or 190\nReceived:%d\n", deviceType); - return (false); - }*/ - Interface::Print("Session begun.\n\n"); return (true); } @@ -776,21 +635,17 @@ bool BridgeManager::EndSession(bool reboot) const return (true); } -bool BridgeManager::SendPacket(OutboundPacket *packet, int timeout, bool retry) const +bool BridgeManager::SendBulkTransfer(unsigned char *data, int length, int timeout, bool retry) const { - packet->Pack(); - int dataTransferred; - int result = libusb_bulk_transfer(deviceHandle, outEndpoint, packet->GetData(), packet->GetSize(), - &dataTransferred, timeout); + int result = libusb_bulk_transfer(deviceHandle, outEndpoint, data, length, &dataTransferred, timeout); - if (result < 0 && retry) + if (result != LIBUSB_SUCCESS && retry) { - // max(250, communicationDelay) - int retryDelay = (communicationDelay > 250) ? communicationDelay : 250; + static const int retryDelay = 250; if (verbose) - Interface::PrintError("libusb error %d whilst sending packet.", result); + Interface::PrintError("libusb error %d whilst sending bulk transfer.", result); // Retry for (int i = 0; i < 5; i++) @@ -801,95 +656,134 @@ bool BridgeManager::SendPacket(OutboundPacket *packet, int timeout, bool retry) // Wait longer each retry Sleep(retryDelay * (i + 1)); - result = libusb_bulk_transfer(deviceHandle, outEndpoint, packet->GetData(), packet->GetSize(), - &dataTransferred, timeout); + result = libusb_bulk_transfer(deviceHandle, outEndpoint, data, length, &dataTransferred, timeout); - if (result >= 0) + if (result == LIBUSB_SUCCESS) break; if (verbose) - Interface::PrintError("libusb error %d whilst sending packet.", result); + Interface::PrintError("libusb error %d whilst sending bulk transfer.", result); } if (verbose) Interface::PrintErrorSameLine("\n"); } - if (communicationDelay != 0) - Sleep(communicationDelay); - - if (result < 0 || dataTransferred != packet->GetSize()) - return (false); - - return (true); + return (result == LIBUSB_SUCCESS && dataTransferred == length); } -bool BridgeManager::ReceivePacket(InboundPacket *packet, int timeout, bool retry, unsigned char *buffer, unsigned int bufferSize) const +int BridgeManager::ReceiveBulkTransfer(unsigned char *data, int length, int timeout, bool retry) const { - bool bufferProvided = buffer != nullptr && bufferSize >= packet->GetSize(); - - if (!bufferProvided) + if (data == nullptr) { - buffer = packet->GetData(); - bufferSize = packet->GetSize(); + // HACK: It seems WinUSB ignores us when we try to read with length zero. + static unsigned char dummyData; + data = &dummyData; + length = 1; } int dataTransferred; - int result; + int result = libusb_bulk_transfer(deviceHandle, inEndpoint, data, length, &dataTransferred, timeout); - unsigned int attempt = 0; - unsigned int maxAttempts = (retry) ? kReceivePacketMaxAttempts : 1; - - // max(250, communicationDelay) - int retryDelay = (communicationDelay > 250) ? communicationDelay : 250; - - for (; attempt < maxAttempts; attempt++) + if (result != LIBUSB_SUCCESS && retry) { - if (attempt > 0) + static const int retryDelay = 250; + + if (verbose) + Interface::PrintError("libusb error %d whilst receiving bulk transfer.", result); + + // Retry + for (int i = 0; i < 5; i++) { if (verbose) Interface::PrintErrorSameLine(" Retrying...\n"); - + // Wait longer each retry - Sleep(retryDelay * (attempt + 1)); - } + Sleep(retryDelay * (i + 1)); - result = libusb_bulk_transfer(deviceHandle, inEndpoint, buffer, bufferSize, &dataTransferred, timeout); + result = libusb_bulk_transfer(deviceHandle, inEndpoint, data, length, &dataTransferred, timeout); - if (result >= 0) - break; + if (result == LIBUSB_SUCCESS) + break; + + if (verbose) + Interface::PrintError("libusb error %d whilst receiving bulk transfer.", result); + } if (verbose) - Interface::PrintError("libusb error %d whilst receiving packet.", result); + Interface::PrintErrorSameLine("\n"); } - if (verbose && attempt > 0) - Interface::PrintErrorSameLine("\n"); + if (result != LIBUSB_SUCCESS) + return (result); + + return (dataTransferred); +} + +bool BridgeManager::SendPacket(OutboundPacket *packet, int timeout, int emptyTransferFlags) const +{ + packet->Pack(); + + if (emptyTransferFlags & kEmptyTransferBefore) + { + if (!SendBulkTransfer(nullptr, 0, kDefaultTimeoutEmptyTransfer, false) && verbose) + { + Interface::PrintWarning("Empty bulk transfer before sending packet failed. Continuing anyway...\n"); + } + } - if (attempt == maxAttempts) + if (!SendBulkTransfer(packet->GetData(), packet->GetSize(), timeout)) return (false); - if (communicationDelay != 0) - Sleep(communicationDelay); + if (emptyTransferFlags & kEmptyTransferAfter) + { + if (!SendBulkTransfer(nullptr, 0, kDefaultTimeoutEmptyTransfer, false) && verbose) + { + Interface::PrintWarning("Empty bulk transfer after sending packet failed. Continuing anyway...\n"); + } + } + + return (true); +} + +bool BridgeManager::ReceivePacket(InboundPacket *packet, int timeout, int emptyTransferFlags) const +{ + if (emptyTransferFlags & kEmptyTransferBefore) + { + if (ReceiveBulkTransfer(nullptr, 0, kDefaultTimeoutEmptyTransfer, false) < 0 && verbose) + { + Interface::PrintWarning("Empty bulk transfer before receiving packet failed. Continuing anyway...\n"); + } + } + + int receivedSize = ReceiveBulkTransfer(packet->GetData(), packet->GetSize(), timeout); + + if (receivedSize < 0) + return (false); - if (dataTransferred != packet->GetSize() && !packet->IsSizeVariable()) + if (receivedSize != packet->GetSize() && !packet->IsSizeVariable()) { if (verbose) - Interface::PrintError("Incorrect packet size received - expected size = %d, received size = %d.\n", packet->GetSize(), dataTransferred); + Interface::PrintError("Incorrect packet size received - expected size = %d, received size = %d.\n", packet->GetSize(), receivedSize); return (false); } - if (bufferProvided) - memcpy(packet->GetData(), buffer, dataTransferred); - - packet->SetReceivedSize(dataTransferred); + packet->SetReceivedSize(receivedSize); bool unpacked = packet->Unpack(); if (!unpacked && verbose) Interface::PrintError("Failed to unpack received packet.\n"); + if (emptyTransferFlags & kEmptyTransferAfter) + { + if (ReceiveBulkTransfer(nullptr, 0, kDefaultTimeoutEmptyTransfer, false) < 0 && verbose) + { + Interface::PrintWarning("Empty bulk transfer after receiving packet failed. Continuing anyway...\n"); + } + } + return (unpacked); } @@ -1053,7 +947,6 @@ int BridgeManager::ReceivePitFile(unsigned char **pitBuffer) const unsigned char *buffer = new unsigned char[fileSize]; int offset = 0; - // NOTE: The PIT file appears to always be padded out to exactly 4 kilobytes. for (unsigned int i = 0; i < transferCount; i++) { DumpPartPitFilePacket *requestPacket = new DumpPartPitFilePacket(i); @@ -1066,10 +959,12 @@ int BridgeManager::ReceivePitFile(unsigned char **pitBuffer) const delete [] buffer; return (0); } + + int receiveEmptyTransferFlags = (i == transferCount - 1) ? kEmptyTransferAfter : kEmptyTransferNone; ReceiveFilePartPacket *receiveFilePartPacket = new ReceiveFilePartPacket(); - success = ReceivePacket(receiveFilePartPacket); - + success = ReceivePacket(receiveFilePartPacket, kDefaultTimeoutReceive, receiveEmptyTransferFlags); + if (!success) { Interface::PrintError("Failed to receive PIT file part #%d!\n", i); @@ -1152,9 +1047,9 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int return (false); } - fseek(file, 0, SEEK_END); - long fileSize = ftell(file); - rewind(file); + FileSeek(file, 0, SEEK_END); + unsigned int fileSize = (unsigned int)FileTell(file); + FileRewind(file); ResponsePacket *fileTransferResponse = new ResponsePacket(ResponsePacket::kResponseTypeFileTransfer); success = ReceivePacket(fileTransferResponse); @@ -1174,14 +1069,14 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int { sequenceCount++; - int lastSequenceBytes = fileSize % (fileTransferSequenceMaxLength * fileTransferPacketSize); + unsigned int lastSequenceBytes = fileSize % (fileTransferSequenceMaxLength * fileTransferPacketSize); lastSequenceSize = lastSequenceBytes / fileTransferPacketSize; if (partialPacketByteCount != 0) lastSequenceSize++; } - long bytesTransferred = 0; + unsigned int bytesTransferred = 0; unsigned int currentPercent; unsigned int previousPercent = 0; Interface::Print("0%%"); @@ -1190,14 +1085,9 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int { bool isLastSequence = (sequenceIndex == sequenceCount - 1); unsigned int sequenceSize = (isLastSequence) ? lastSequenceSize : fileTransferSequenceMaxLength; - unsigned int sequenceByteCount; + unsigned int sequenceTotalByteCount = sequenceSize * fileTransferPacketSize; - if (isLastSequence) - sequenceByteCount = ((partialPacketByteCount) ? lastSequenceSize - 1 : lastSequenceSize) * fileTransferPacketSize + partialPacketByteCount; - else - sequenceByteCount = fileTransferSequenceMaxLength * fileTransferPacketSize; - - FlashPartFileTransferPacket *beginFileTransferPacket = new FlashPartFileTransferPacket(sequenceByteCount); + FlashPartFileTransferPacket *beginFileTransferPacket = new FlashPartFileTransferPacket(sequenceTotalByteCount); success = SendPacket(beginFileTransferPacket); delete beginFileTransferPacket; @@ -1219,14 +1109,14 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int return (false); } - SendFilePartPacket *sendFilePartPacket; - SendFilePartResponse *sendFilePartResponse; - for (unsigned int filePartIndex = 0; filePartIndex < sequenceSize; filePartIndex++) { + // NOTE: This empty transfer thing is entirely ridiculous, but sadly it seems to be required. + int sendEmptyTransferFlags = (filePartIndex == 0) ? kEmptyTransferNone : kEmptyTransferBefore; + // Send - sendFilePartPacket = new SendFilePartPacket(file, fileTransferPacketSize); - success = SendPacket(sendFilePartPacket); + SendFilePartPacket *sendFilePartPacket = new SendFilePartPacket(file, fileTransferPacketSize); + success = SendPacket(sendFilePartPacket, kDefaultTimeoutSend, sendEmptyTransferFlags); delete sendFilePartPacket; if (!success) @@ -1237,7 +1127,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int } // Response - sendFilePartResponse = new SendFilePartResponse(); + SendFilePartResponse *sendFilePartResponse = new SendFilePartResponse(); success = ReceivePacket(sendFilePartResponse); int receivedPartIndex = sendFilePartResponse->GetPartIndex(); @@ -1255,7 +1145,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int // Send sendFilePartPacket = new SendFilePartPacket(file, fileTransferPacketSize); - success = SendPacket(sendFilePartPacket); + success = SendPacket(sendFilePartPacket, kDefaultTimeoutSend, sendEmptyTransferFlags); delete sendFilePartPacket; if (!success) @@ -1299,7 +1189,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int if (bytesTransferred > fileSize) bytesTransferred = fileSize; - currentPercent = (int)(100.0f * ((float)bytesTransferred / (float)fileSize)); + currentPercent = (unsigned int)(100.0 * ((double)bytesTransferred / (double)fileSize)); if (currentPercent != previousPercent) { @@ -1319,11 +1209,14 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int previousPercent = currentPercent; } + unsigned int sequenceEffectiveByteCount = (isLastSequence && partialPacketByteCount != 0) ? + fileTransferPacketSize * (lastSequenceSize - 1) + partialPacketByteCount : sequenceTotalByteCount; + if (destination == EndFileTransferPacket::kDestinationPhone) { - EndPhoneFileTransferPacket *endPhoneFileTransferPacket = new EndPhoneFileTransferPacket(sequenceByteCount, 0, deviceType, fileIdentifier, isLastSequence); + EndPhoneFileTransferPacket *endPhoneFileTransferPacket = new EndPhoneFileTransferPacket(sequenceEffectiveByteCount, 0, deviceType, fileIdentifier, isLastSequence); - success = SendPacket(endPhoneFileTransferPacket, 3000); + success = SendPacket(endPhoneFileTransferPacket, kDefaultTimeoutSend, kEmptyTransferBeforeAndAfter); delete endPhoneFileTransferPacket; if (!success) @@ -1335,9 +1228,9 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int } else // destination == EndFileTransferPacket::kDestinationModem { - EndModemFileTransferPacket *endModemFileTransferPacket = new EndModemFileTransferPacket(sequenceByteCount, 0, deviceType, isLastSequence); + EndModemFileTransferPacket *endModemFileTransferPacket = new EndModemFileTransferPacket(sequenceEffectiveByteCount, 0, deviceType, isLastSequence); - success = SendPacket(endModemFileTransferPacket, 3000); + success = SendPacket(endModemFileTransferPacket, kDefaultTimeoutSend, kEmptyTransferBeforeAndAfter); delete endModemFileTransferPacket; if (!success) diff --git a/heimdall/source/BridgeManager.h b/heimdall/source/BridgeManager.h index 063b273..867bfa3 100644 --- a/heimdall/source/BridgeManager.h +++ b/heimdall/source/BridgeManager.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna
+/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -61,11 +61,6 @@ namespace Heimdall enum
{
- kCommunicationDelayDefault = 0
- };
-
- enum
- {
kInitialiseSucceeded = 0,
kInitialiseFailed,
kInitialiseDeviceNotDetected
@@ -78,9 +73,16 @@ namespace Heimdall enum
{
- kPidGalaxyS = 0x6601,
- kPidGalaxyS2 = 0x685D,
- kPidDroidCharge = 0x68C3
+ kPidGalaxyS = 0x6601,
+ kPidGalaxyS2 = 0x685D,
+ kPidDroidCharge = 0x68C3
+ };
+
+ enum
+ {
+ kDefaultTimeoutSend = 3000,
+ kDefaultTimeoutReceive = 3000,
+ kDefaultTimeoutEmptyTransfer = 100
};
enum UsbLogLevel
@@ -94,12 +96,19 @@ namespace Heimdall Default = Error
};
+ enum
+ {
+ kEmptyTransferNone = 0,
+ kEmptyTransferBefore = 1,
+ kEmptyTransferAfter = 1 << 1,
+ kEmptyTransferBeforeAndAfter = kEmptyTransferBefore | kEmptyTransferAfter
+ };
+
private:
static const DeviceIdentifier supportedDevices[kSupportedDeviceCount];
bool verbose;
- int communicationDelay;
libusb_context *libusbContext;
libusb_device_handle *deviceHandle;
@@ -131,9 +140,12 @@ namespace Heimdall bool InitialiseProtocol(void);
+ bool SendBulkTransfer(unsigned char *data, int length, int timeout, bool retry = true) const;
+ int ReceiveBulkTransfer(unsigned char *data, int length, int timeout, bool retry = true) const;
+
public:
- BridgeManager(bool verbose, int communicationDelay = BridgeManager::kCommunicationDelayDefault);
+ BridgeManager(bool verbose);
~BridgeManager();
bool DetectDevice(void);
@@ -142,8 +154,8 @@ namespace Heimdall bool BeginSession(void);
bool EndSession(bool reboot) const;
- bool SendPacket(OutboundPacket *packet, int timeout = 3000, bool retry = true) const;
- bool ReceivePacket(InboundPacket *packet, int timeout = 3000, bool retry = true, unsigned char *buffer = nullptr, unsigned int bufferSize = -1) const;
+ bool SendPacket(OutboundPacket *packet, int timeout = kDefaultTimeoutSend, int emptyTransferFlags = kEmptyTransferAfter) const;
+ bool ReceivePacket(InboundPacket *packet, int timeout = kDefaultTimeoutReceive, int emptyTransferFlags = kEmptyTransferNone) const;
bool RequestDeviceType(unsigned int request, int *result) const;
diff --git a/heimdall/source/ClosePcScreenAction.cpp b/heimdall/source/ClosePcScreenAction.cpp index 2f6435e..a38f68c 100644 --- a/heimdall/source/ClosePcScreenAction.cpp +++ b/heimdall/source/ClosePcScreenAction.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -29,9 +29,12 @@ using namespace std; using namespace Heimdall; const char *ClosePcScreenAction::usage = "Action: close-pc-screen\n\ -Arguments: [--verbose] [--no-reboot] [--stdout-errors] [--delay <ms>]\n\ +Arguments: [--verbose] [--no-reboot] [--resume] [--stdout-errors]\n\ [--usb-log-level <none/error/warning/debug>]\n\ -Description: Attempts to get rid off the \"connect phone to PC\" screen.\n"; +Description: Attempts to get rid off the \"connect phone to PC\" screen.\n\ +Note: --no-reboot causes the device to remain in download mode after the action\n\ + is completed. If you wish to perform another action whilst remaining in\n\ + download mode, then the following action must specify the --resume flag.\n"; int ClosePcScreenAction::Execute(int argc, char **argv) { @@ -40,7 +43,6 @@ int ClosePcScreenAction::Execute(int argc, char **argv) map<string, ArgumentType> argumentTypes; argumentTypes["no-reboot"] = kArgumentTypeFlag; argumentTypes["resume"] = kArgumentTypeFlag; - argumentTypes["delay"] = kArgumentTypeUnsignedInteger; argumentTypes["verbose"] = kArgumentTypeFlag; argumentTypes["stdout-errors"] = kArgumentTypeFlag; argumentTypes["usb-log-level"] = kArgumentTypeString; @@ -53,10 +55,8 @@ int ClosePcScreenAction::Execute(int argc, char **argv) return (0); } - const UnsignedIntegerArgument *communicationDelayArgument = static_cast<const UnsignedIntegerArgument *>(arguments.GetArgument("delay")); const StringArgument *usbLogLevelArgument = static_cast<const StringArgument *>(arguments.GetArgument("usb-log-level")); - - int usbLogLevel = BridgeManager::Default; + BridgeManager::UsbLogLevel usbLogLevel = BridgeManager::UsbLogLevel::Default; if (usbLogLevelArgument) { @@ -104,12 +104,7 @@ int ClosePcScreenAction::Execute(int argc, char **argv) // Download PIT file from device. - int communicationDelay = BridgeManager::kCommunicationDelayDefault; - - if (communicationDelayArgument) - communicationDelay = communicationDelayArgument->GetValue(); - - BridgeManager *bridgeManager = new BridgeManager(verbose, communicationDelay); + BridgeManager *bridgeManager = new BridgeManager(verbose); bridgeManager->SetUsbLogLevel(usbLogLevel); if (bridgeManager->Initialise(resume) != BridgeManager::kInitialiseSucceeded || !bridgeManager->BeginSession()) diff --git a/heimdall/source/ClosePcScreenAction.h b/heimdall/source/ClosePcScreenAction.h index 6f167ca..58cbdee 100644 --- a/heimdall/source/ClosePcScreenAction.h +++ b/heimdall/source/ClosePcScreenAction.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -28,7 +28,7 @@ namespace Heimdall extern const char *usage; int Execute(int argc, char **argv); - }; + } } #endif diff --git a/heimdall/source/ControlPacket.h b/heimdall/source/ControlPacket.h index 99169b7..78785f8 100644 --- a/heimdall/source/ControlPacket.h +++ b/heimdall/source/ControlPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna
+/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/heimdall/source/DetectAction.cpp b/heimdall/source/DetectAction.cpp index f137e88..a0b9e6e 100644 --- a/heimdall/source/DetectAction.cpp +++ b/heimdall/source/DetectAction.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/DetectAction.h b/heimdall/source/DetectAction.h index d71d396..b4bcd59 100644 --- a/heimdall/source/DetectAction.h +++ b/heimdall/source/DetectAction.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -28,7 +28,7 @@ namespace Heimdall extern const char *usage; int Execute(int argc, char **argv); - }; + } } #endif diff --git a/heimdall/source/DeviceTypePacket.h b/heimdall/source/DeviceTypePacket.h index 6721bc6..4c2dc2a 100644 --- a/heimdall/source/DeviceTypePacket.h +++ b/heimdall/source/DeviceTypePacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/DownloadPitAction.cpp b/heimdall/source/DownloadPitAction.cpp index 20c8fb0..7c58b91 100644 --- a/heimdall/source/DownloadPitAction.cpp +++ b/heimdall/source/DownloadPitAction.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -33,9 +33,12 @@ using namespace Heimdall; const char *DownloadPitAction::usage = "Action: download-pit\n\ Arguments: --output <filename> [--verbose] [--no-reboot] [--stdout-errors]\n\ - [--delay <ms>] [--usb-log-level <none/error/warning/debug>]\n\ + [--usb-log-level <none/error/warning/debug>]\n\ Description: Downloads the connected device's PIT file to the specified\n\ - output file.\n"; + output file.\n\ +Note: --no-reboot causes the device to remain in download mode after the action\n\ + is completed. If you wish to perform another action whilst remaining in\n\ + download mode, then the following action must specify the --resume flag.\n"; int DownloadPitAction::Execute(int argc, char **argv) { @@ -45,7 +48,6 @@ int DownloadPitAction::Execute(int argc, char **argv) argumentTypes["output"] = kArgumentTypeString; argumentTypes["no-reboot"] = kArgumentTypeFlag; argumentTypes["resume"] = kArgumentTypeFlag; - argumentTypes["delay"] = kArgumentTypeUnsignedInteger; argumentTypes["verbose"] = kArgumentTypeFlag; argumentTypes["stdout-errors"] = kArgumentTypeFlag; argumentTypes["usb-log-level"] = kArgumentTypeString; @@ -67,8 +69,6 @@ int DownloadPitAction::Execute(int argc, char **argv) return (0); } - const UnsignedIntegerArgument *communicationDelayArgument = static_cast<const UnsignedIntegerArgument *>(arguments.GetArgument("delay")); - bool reboot = arguments.GetArgument("no-reboot") == nullptr; bool resume = arguments.GetArgument("resume") != nullptr; bool verbose = arguments.GetArgument("verbose") != nullptr; @@ -120,7 +120,7 @@ int DownloadPitAction::Execute(int argc, char **argv) // Open output file const char *outputFilename = outputArgument->GetValue().c_str(); - FILE *outputPitFile = fopen(outputFilename, "wb"); + FILE *outputPitFile = FileOpen(outputFilename, "wb"); if (!outputPitFile) { @@ -130,17 +130,12 @@ int DownloadPitAction::Execute(int argc, char **argv) // Download PIT file from device. - int communicationDelay = BridgeManager::kCommunicationDelayDefault; - - if (communicationDelayArgument) - communicationDelay = communicationDelayArgument->GetValue(); - - BridgeManager *bridgeManager = new BridgeManager(verbose, communicationDelay); + BridgeManager *bridgeManager = new BridgeManager(verbose); bridgeManager->SetUsbLogLevel(usbLogLevel); if (bridgeManager->Initialise(resume) != BridgeManager::kInitialiseSucceeded || !bridgeManager->BeginSession()) { - fclose(outputPitFile); + FileClose(outputPitFile); delete bridgeManager; return (1); @@ -169,7 +164,7 @@ int DownloadPitAction::Execute(int argc, char **argv) delete bridgeManager; - fclose(outputPitFile); + FileClose(outputPitFile); delete [] pitBuffer; return (success ? 0 : 1); diff --git a/heimdall/source/DownloadPitAction.h b/heimdall/source/DownloadPitAction.h index b9bfd2d..e93dcb5 100644 --- a/heimdall/source/DownloadPitAction.h +++ b/heimdall/source/DownloadPitAction.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -28,7 +28,7 @@ namespace Heimdall extern const char *usage; int Execute(int argc, char **argv); - }; + } } #endif diff --git a/heimdall/source/DumpPartFileTransferPacket.h b/heimdall/source/DumpPartFileTransferPacket.h index 229927d..3c0a922 100644 --- a/heimdall/source/DumpPartFileTransferPacket.h +++ b/heimdall/source/DumpPartFileTransferPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna
+/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/heimdall/source/DumpPartPitFilePacket.h b/heimdall/source/DumpPartPitFilePacket.h index 343c339..1190a06 100644 --- a/heimdall/source/DumpPartPitFilePacket.h +++ b/heimdall/source/DumpPartPitFilePacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna
+/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/heimdall/source/DumpResponse.h b/heimdall/source/DumpResponse.h index 060dfc3..6777ce1 100644 --- a/heimdall/source/DumpResponse.h +++ b/heimdall/source/DumpResponse.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna
+/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/heimdall/source/EndFileTransferPacket.h b/heimdall/source/EndFileTransferPacket.h index 7e78899..bb312da 100644 --- a/heimdall/source/EndFileTransferPacket.h +++ b/heimdall/source/EndFileTransferPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna
+/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -34,7 +34,7 @@ namespace Heimdall {
kDestinationPhone = 0x00,
kDestinationModem = 0x01
- };
+ };
protected:
@@ -47,18 +47,18 @@ namespace Heimdall unsigned int destination; // PDA / Modem
unsigned int sequenceByteCount;
- unsigned int unknown1;
- unsigned int chipIdentifier;
+ unsigned int unknown1; // EFS?
+ unsigned int deviceType;
protected:
- EndFileTransferPacket(unsigned int destination, unsigned int sequenceByteCount, unsigned int unknown1, unsigned int chipIdentifier)
+ EndFileTransferPacket(unsigned int destination, unsigned int sequenceByteCount, unsigned int unknown1, unsigned int deviceType)
: FileTransferPacket(FileTransferPacket::kRequestEnd)
{
this->destination = destination;
this->sequenceByteCount = sequenceByteCount;
this->unknown1 = unknown1;
- this->chipIdentifier = chipIdentifier;
+ this->deviceType = deviceType;
}
public:
@@ -78,9 +78,9 @@ namespace Heimdall return (unknown1);
}
- unsigned int GetChipIdentifier(void) const
+ unsigned int GetDeviceType(void) const
{
- return (chipIdentifier);
+ return (deviceType);
}
virtual void Pack(void)
@@ -90,7 +90,7 @@ namespace Heimdall PackInteger(FileTransferPacket::kDataSize, destination);
PackInteger(FileTransferPacket::kDataSize + 4, sequenceByteCount);
PackInteger(FileTransferPacket::kDataSize + 8, unknown1);
- PackInteger(FileTransferPacket::kDataSize + 12, chipIdentifier);
+ PackInteger(FileTransferPacket::kDataSize + 12, deviceType);
}
};
}
diff --git a/heimdall/source/EndModemFileTransferPacket.h b/heimdall/source/EndModemFileTransferPacket.h index 2a42880..f0489a5 100644 --- a/heimdall/source/EndModemFileTransferPacket.h +++ b/heimdall/source/EndModemFileTransferPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna
+/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/heimdall/source/EndPhoneFileTransferPacket.h b/heimdall/source/EndPhoneFileTransferPacket.h index 803ce73..5ab21b4 100644 --- a/heimdall/source/EndPhoneFileTransferPacket.h +++ b/heimdall/source/EndPhoneFileTransferPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna
+/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/heimdall/source/EndPitFileTransferPacket.h b/heimdall/source/EndPitFileTransferPacket.h index 9dddcb0..378ab00 100644 --- a/heimdall/source/EndPitFileTransferPacket.h +++ b/heimdall/source/EndPitFileTransferPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/EndSessionPacket.h b/heimdall/source/EndSessionPacket.h index 5ac2c5a..52cea50 100644 --- a/heimdall/source/EndSessionPacket.h +++ b/heimdall/source/EndSessionPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/FilePartSizePacket.h b/heimdall/source/FilePartSizePacket.h index 42b9525..c346fad 100644 --- a/heimdall/source/FilePartSizePacket.h +++ b/heimdall/source/FilePartSizePacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/FileTransferPacket.h b/heimdall/source/FileTransferPacket.h index c7a2f6b..3dd18a2 100644 --- a/heimdall/source/FileTransferPacket.h +++ b/heimdall/source/FileTransferPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna
+/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/heimdall/source/FlashAction.cpp b/heimdall/source/FlashAction.cpp index 0bea8a6..66588da 100644 --- a/heimdall/source/FlashAction.cpp +++ b/heimdall/source/FlashAction.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -39,17 +39,19 @@ using namespace Heimdall; const char *FlashAction::usage = "Action: flash\n\ Arguments:\n\ - --repartition --pit <filename>\n\ - --<partition name>|--<partition identifier> <filename> [...]\n\ - [--verbose] [--no-reboot] [--stdout-errors] [--delay <ms>]\n\ + [--<partition name> <filename> ...]\n\ + [--<partition identifier> <filename> ...]\n\ + [--pit <filename>] [--verbose] [--no-reboot] [--resume] [--stdout-errors]\n\ [--usb-log-level <none/error/warning/debug>]\n\ or:\n\ - --<partition name>|--<partition identifier> <filename> [...]\n\ - [--pit <filename>]\n\ - [--verbose] [--no-reboot] [--stdout-errors] [--delay <ms>]\n\ - [--usb-log-level <none/error/warning/debug>]\n\ + --repartition --pit <filename> [--<partition name> <filename> ...]\n\ + [--<partition identifier> <filename> ...] [--verbose] [--no-reboot]\n\ + [--resume] [--stdout-errors] [--usb-log-level <none/error/warning/debug>]\n\ Description: Flashes one or more firmware files to your phone. Partition names\n\ (or identifiers) can be obtained by executing the print-pit action.\n\ +Note: --no-reboot causes the device to remain in download mode after the action\n\ + is completed. If you wish to perform another action whilst remaining in\n\ + download mode, then the following action must specify the --resume flag.\n\ WARNING: If you're repartitioning it's strongly recommended you specify\n\ all files at your disposal.\n"; @@ -85,7 +87,7 @@ static bool openFiles(Arguments& arguments, vector<PartitionFile>& partitionFile if (pitArgument) { - pitFile = fopen(pitArgument->GetValue().c_str(), "rb"); + pitFile = FileOpen(pitArgument->GetValue().c_str(), "rb"); if (!pitFile) { @@ -98,7 +100,6 @@ static bool openFiles(Arguments& arguments, vector<PartitionFile>& partitionFile for (vector<const Argument *>::const_iterator it = arguments.GetArguments().begin(); it != arguments.GetArguments().end(); it++) { - bool isPartitionArgument = false; const string& argumentName = (*it)->GetName(); // The only way an argument could exist without being in the argument types map is if it's a wild-card. @@ -108,7 +109,7 @@ static bool openFiles(Arguments& arguments, vector<PartitionFile>& partitionFile if (arguments.GetArgumentTypes().find(argumentName) == arguments.GetArgumentTypes().end()) { const StringArgument *stringArgument = static_cast<const StringArgument *>(*it); - FILE *file = fopen(stringArgument->GetValue().c_str(), "rb"); + FILE *file = FileOpen(stringArgument->GetValue().c_str(), "rb"); if (!file) { @@ -129,34 +130,34 @@ static void closeFiles(vector<PartitionFile>& partitionFiles, FILE *& pitFile) if (pitFile) { - fclose(pitFile); + FileClose(pitFile); pitFile = nullptr; } // Close partition files for (vector<PartitionFile>::const_iterator it = partitionFiles.begin(); it != partitionFiles.end(); it++) - fclose(it->file); + FileClose(it->file); partitionFiles.clear(); } static bool sendTotalTransferSize(BridgeManager *bridgeManager, const vector<PartitionFile>& partitionFiles, FILE *pitFile, bool repartition) { - int totalBytes = 0; + unsigned int totalBytes = 0; for (vector<PartitionFile>::const_iterator it = partitionFiles.begin(); it != partitionFiles.end(); it++) { - fseek(it->file, 0, SEEK_END); - totalBytes += ftell(it->file); - rewind(it->file); + FileSeek(it->file, 0, SEEK_END); + totalBytes += (unsigned int)FileTell(it->file); + FileRewind(it->file); } if (repartition) { - fseek(pitFile, 0, SEEK_END); - totalBytes += ftell(pitFile); - rewind(pitFile); + FileSeek(pitFile, 0, SEEK_END); + totalBytes += (unsigned int)FileTell(pitFile); + FileRewind(pitFile); } bool success; @@ -167,7 +168,7 @@ static bool sendTotalTransferSize(BridgeManager *bridgeManager, const vector<Par if (!success) { - Interface::PrintError("Failed to send total bytes device info packet!\n"); + Interface::PrintError("Failed to send total bytes packet!\n"); return (false); } @@ -178,13 +179,13 @@ static bool sendTotalTransferSize(BridgeManager *bridgeManager, const vector<Par if (!success) { - Interface::PrintError("Failed to receive device info response!\n"); + Interface::PrintError("Failed to receive session total bytes response!\n"); return (false); } if (totalBytesResult != 0) { - Interface::PrintError("Unexpected device info response!\nExpected: 0\nReceived:%d\n", totalBytesResponse); + Interface::PrintError("Unexpected session total bytes response!\nExpected: 0\nReceived:%d\n", totalBytesResult); return (false); } @@ -251,7 +252,7 @@ static bool flashFile(BridgeManager *bridgeManager, const PartitionFlashInfo& pa Interface::Print("Uploading %s\n", partitionFlashInfo.pitEntry->GetPartitionName()); if (bridgeManager->SendFile(partitionFlashInfo.file, EndModemFileTransferPacket::kDestinationModem, - partitionFlashInfo.pitEntry->GetDeviceType())) // <-- Odin method + partitionFlashInfo.pitEntry->GetDeviceType())) { Interface::Print("%s upload successful\n\n", partitionFlashInfo.pitEntry->GetPartitionName()); return (true); @@ -315,9 +316,9 @@ static PitData *getPitData(BridgeManager *bridgeManager, FILE *pitFile, bool rep { // Load the local pit file into memory. - fseek(pitFile, 0, SEEK_END); - long localPitFileSize = ftell(pitFile); - rewind(pitFile); + FileSeek(pitFile, 0, SEEK_END); + unsigned int localPitFileSize = (unsigned int)FileTell(pitFile); + FileRewind(pitFile); unsigned char *pitFileBuffer = new unsigned char[localPitFileSize]; memset(pitFileBuffer, 0, localPitFileSize); @@ -326,7 +327,7 @@ static PitData *getPitData(BridgeManager *bridgeManager, FILE *pitFile, bool rep if (dataRead > 0) { - rewind(pitFile); + FileRewind(pitFile); localPitData = new PitData(); localPitData->Unpack(pitFileBuffer); @@ -389,7 +390,6 @@ int FlashAction::Execute(int argc, char **argv) argumentTypes["no-reboot"] = kArgumentTypeFlag; argumentTypes["resume"] = kArgumentTypeFlag; - argumentTypes["delay"] = kArgumentTypeUnsignedInteger; argumentTypes["verbose"] = kArgumentTypeFlag; argumentTypes["stdout-errors"] = kArgumentTypeFlag; argumentTypes["usb-log-level"] = kArgumentTypeString; @@ -417,8 +417,6 @@ int FlashAction::Execute(int argc, char **argv) return (0); } - const UnsignedIntegerArgument *communicationDelayArgument = static_cast<const UnsignedIntegerArgument *>(arguments.GetArgument("delay")); - bool reboot = arguments.GetArgument("no-reboot") == nullptr; bool resume = arguments.GetArgument("resume") != nullptr; bool verbose = arguments.GetArgument("verbose") != nullptr; @@ -497,12 +495,7 @@ int FlashAction::Execute(int argc, char **argv) // Perform flash - int communicationDelay = BridgeManager::kCommunicationDelayDefault; - - if (communicationDelayArgument) - communicationDelay = communicationDelayArgument->GetValue(); - - BridgeManager *bridgeManager = new BridgeManager(verbose, communicationDelay); + BridgeManager *bridgeManager = new BridgeManager(verbose); bridgeManager->SetUsbLogLevel(usbLogLevel); if (bridgeManager->Initialise(resume) != BridgeManager::kInitialiseSucceeded || !bridgeManager->BeginSession()) diff --git a/heimdall/source/FlashAction.h b/heimdall/source/FlashAction.h index 7c41136..dcc969e 100644 --- a/heimdall/source/FlashAction.h +++ b/heimdall/source/FlashAction.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -28,7 +28,7 @@ namespace Heimdall extern const char *usage; int Execute(int argc, char **argv); - }; + } } #endif diff --git a/heimdall/source/FlashPartFileTransferPacket.h b/heimdall/source/FlashPartFileTransferPacket.h index 1824467..861a2f9 100644 --- a/heimdall/source/FlashPartFileTransferPacket.h +++ b/heimdall/source/FlashPartFileTransferPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna
+/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/heimdall/source/FlashPartPitFilePacket.h b/heimdall/source/FlashPartPitFilePacket.h index c6ea41a..b893c92 100644 --- a/heimdall/source/FlashPartPitFilePacket.h +++ b/heimdall/source/FlashPartPitFilePacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna
+/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/heimdall/source/Heimdall.h b/heimdall/source/Heimdall.h index d0194a5..205f01d 100644 --- a/heimdall/source/Heimdall.h +++ b/heimdall/source/Heimdall.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna
+/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -21,21 +21,36 @@ #ifndef HEIMDALL_H
#define HEIMDALL_H
-#include "../config.h"
-
-#ifdef OS_WINDOWS
+#ifdef _MSC_VER // Microsoft Visual C Standard Library
#include <Windows.h>
#undef GetBinaryType
-#else
+#ifndef va_copy
+#define va_copy(d, s) ((d) = (s))
+#endif
+
+#define FileOpen(FILE, MODE) fopen(FILE, MODE)
+#define FileClose(FILE) fclose(FILE)
+#define FileSeek(FILE, OFFSET, ORIGIN) _fseeki64(FILE, OFFSET, ORIGIN)
+#define FileTell(FILE) _ftelli64(FILE)
+#define FileRewind(FILE) rewind(FILE)
+
+#else // POSIX Standard Library
+
+#ifdef AUTOCONF
+#include "../config.h"
+#endif
-#if defined(OS_DARWIN) || defined(OS_LINUX)
#include <unistd.h>
+
#define Sleep(t) usleep(1000*t)
-#else
-#error operating system not supported
-#endif
+
+#define FileOpen(FILE, MODE) fopen(FILE, MODE)
+#define FileClose(FILE) fclose(FILE)
+#define FileSeek(FILE, OFFSET, ORIGIN) fseeko(FILE, OFFSET, ORIGIN)
+#define FileTell(FILE) ftello(FILE)
+#define FileRewind(FILE) rewind(FILE)
#endif
diff --git a/heimdall/source/HelpAction.cpp b/heimdall/source/HelpAction.cpp index e2f9bdb..a95dd18 100644 --- a/heimdall/source/HelpAction.cpp +++ b/heimdall/source/HelpAction.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/HelpAction.h b/heimdall/source/HelpAction.h index 83e1d37..ce06ac4 100644 --- a/heimdall/source/HelpAction.h +++ b/heimdall/source/HelpAction.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -28,7 +28,7 @@ namespace Heimdall extern const char *usage; int Execute(int argc, char **argv); - }; + } } #endif diff --git a/heimdall/source/InboundPacket.h b/heimdall/source/InboundPacket.h index f929297..d42a6bc 100644 --- a/heimdall/source/InboundPacket.h +++ b/heimdall/source/InboundPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna
+/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/heimdall/source/InfoAction.cpp b/heimdall/source/InfoAction.cpp index e60758a..dc1a1af 100644 --- a/heimdall/source/InfoAction.cpp +++ b/heimdall/source/InfoAction.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/InfoAction.h b/heimdall/source/InfoAction.h index ae5d445..89fec36 100644 --- a/heimdall/source/InfoAction.h +++ b/heimdall/source/InfoAction.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -28,7 +28,7 @@ namespace Heimdall extern const char *usage; int Execute(int argc, char **argv); - }; + } } #endif diff --git a/heimdall/source/Interface.cpp b/heimdall/source/Interface.cpp index dbf8431..fd989fa 100644 --- a/heimdall/source/Interface.cpp +++ b/heimdall/source/Interface.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -42,11 +42,11 @@ using namespace Heimdall; map<string, Interface::ActionInfo> actionMap; bool stdoutErrors = false; -const char *version = "v1.4.0"; +const char *version = "v1.4.1"; const char *actionUsage = "Usage: heimdall <action> <action arguments>\n"; const char *releaseInfo = "Heimdall %s\n\n\ -Copyright (c) 2010-2013, Benjamin Dobell, Glass Echidna\n\ +Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna\n\ http://www.glassechidna.com.au/\n\n\ This software is provided free of charge. Copying and redistribution is\nencouraged.\n\n\ If you appreciate this software and you would like to support future\ndevelopment please consider donating:\n\ @@ -92,74 +92,86 @@ void Interface::Print(const char *format, ...) void Interface::PrintWarning(const char *format, ...) { - va_list args; - va_start(args, format); - - fprintf(stderr, "WARNING: "); - vfprintf(stderr, format, args); - fflush(stderr); + va_list stderrArgs; + va_start(stderrArgs, format); if (stdoutErrors) { + va_list stdoutArgs; + va_copy(stdoutArgs, stderrArgs); fprintf(stdout, "WARNING: "); - vfprintf(stdout, format, args); + vfprintf(stdout, format, stdoutArgs); fflush(stdout); + va_end(stdoutArgs); } - va_end(args); + fprintf(stderr, "WARNING: "); + vfprintf(stderr, format, stderrArgs); + fflush(stderr); + + va_end(stderrArgs); } void Interface::PrintWarningSameLine(const char *format, ...) { - va_list args; - va_start(args, format); - - vfprintf(stderr, format, args); - fflush(stderr); + va_list stderrArgs; + va_start(stderrArgs, format); if (stdoutErrors) { - vfprintf(stdout, format, args); + va_list stdoutArgs; + va_copy(stdoutArgs, stderrArgs); + vfprintf(stdout, format, stdoutArgs); fflush(stdout); + va_end(stdoutArgs); } - va_end(args); + vfprintf(stderr, format, stderrArgs); + fflush(stderr); + + va_end(stderrArgs); } void Interface::PrintError(const char *format, ...) { - va_list args; - va_start(args, format); - - fprintf(stderr, "ERROR: "); - vfprintf(stderr, format, args); - fflush(stderr); + va_list stderrArgs; + va_start(stderrArgs, format); if (stdoutErrors) { + va_list stdoutArgs; + va_copy(stdoutArgs, stderrArgs); fprintf(stdout, "ERROR: "); - vfprintf(stdout, format, args); + vfprintf(stdout, format, stdoutArgs); fflush(stdout); + va_end(stdoutArgs); } - va_end(args); + fprintf(stderr, "ERROR: "); + vfprintf(stderr, format, stderrArgs); + fflush(stderr); + + va_end(stderrArgs); } void Interface::PrintErrorSameLine(const char *format, ...) { - va_list args; - va_start(args, format); - - vfprintf(stderr, format, args); - fflush(stderr); + va_list stderrArgs; + va_start(stderrArgs, format); if (stdoutErrors) { - vfprintf(stdout, format, args); + va_list stdoutArgs; + va_copy(stdoutArgs, stderrArgs); + vfprintf(stdout, format, stdoutArgs); fflush(stdout); + va_end(stdoutArgs); } - va_end(args); + vfprintf(stderr, format, stderrArgs); + fflush(stderr); + + va_end(stderrArgs); } void Interface::PrintVersion(void) @@ -264,6 +276,9 @@ void Interface::PrintPit(const PitData *pitData) if (entry->GetAttributes() & PitEntry::kAttributeSTL) Interface::Print("STL "); + /*if (entry->GetAttributes() & PitEntry::kAttributeBML) + Interface::Print("BML ");*/ + if (entry->GetAttributes() & PitEntry::kAttributeWrite) Interface::Print("Read/Write"); else diff --git a/heimdall/source/Interface.h b/heimdall/source/Interface.h index 27d08c8..a3fb1d7 100644 --- a/heimdall/source/Interface.h +++ b/heimdall/source/Interface.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -74,7 +74,7 @@ namespace Heimdall void PrintPit(const libpit::PitData *pitData); void SetStdoutErrors(bool enabled); - }; + } } #endif diff --git a/heimdall/source/OutboundPacket.h b/heimdall/source/OutboundPacket.h index 50fb9d3..77f562e 100644 --- a/heimdall/source/OutboundPacket.h +++ b/heimdall/source/OutboundPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna
+/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/heimdall/source/Packet.h b/heimdall/source/Packet.h index b571ae4..43007d9 100644 --- a/heimdall/source/Packet.h +++ b/heimdall/source/Packet.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna
+/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/heimdall/source/PitFilePacket.h b/heimdall/source/PitFilePacket.h index 7bc32fb..f2f27db 100644 --- a/heimdall/source/PitFilePacket.h +++ b/heimdall/source/PitFilePacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna
+/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/heimdall/source/PitFileResponse.h b/heimdall/source/PitFileResponse.h index 68fd7ed..b993b2f 100644 --- a/heimdall/source/PitFileResponse.h +++ b/heimdall/source/PitFileResponse.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna
+/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/heimdall/source/PrintPitAction.cpp b/heimdall/source/PrintPitAction.cpp index 20144a7..8e33126 100644 --- a/heimdall/source/PrintPitAction.cpp +++ b/heimdall/source/PrintPitAction.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -34,10 +34,13 @@ using namespace Heimdall; const char *PrintPitAction::usage = "Action: print-pit\n\ Arguments: [--file <filename>] [--verbose] [--no-reboot] [--stdout-errors]\n\ - [--delay <ms>] [--usb-log-level <none/error/warning/debug>]\n\ + [--usb-log-level <none/error/warning/debug>]\n\ Description: Prints the contents of a PIT file in a human readable format. If\n\ a filename is not provided then Heimdall retrieves the PIT file from the \n\ - connected device.\n"; + connected device.\n\ +Note: --no-reboot causes the device to remain in download mode after the action\n\ + is completed. If you wish to perform another action whilst remaining in\n\ + download mode, then the following action must specify the --resume flag.\n"; int PrintPitAction::Execute(int argc, char **argv) { @@ -47,7 +50,6 @@ int PrintPitAction::Execute(int argc, char **argv) argumentTypes["file"] = kArgumentTypeString; argumentTypes["no-reboot"] = kArgumentTypeFlag; argumentTypes["resume"] = kArgumentTypeFlag; - argumentTypes["delay"] = kArgumentTypeUnsignedInteger; argumentTypes["verbose"] = kArgumentTypeFlag; argumentTypes["stdout-errors"] = kArgumentTypeFlag; argumentTypes["usb-log-level"] = kArgumentTypeString; @@ -61,7 +63,6 @@ int PrintPitAction::Execute(int argc, char **argv) } const StringArgument *fileArgument = static_cast<const StringArgument *>(arguments.GetArgument("file")); - const UnsignedIntegerArgument *communicationDelayArgument = static_cast<const UnsignedIntegerArgument *>(arguments.GetArgument("delay")); bool reboot = arguments.GetArgument("no-reboot") == nullptr; bool resume = arguments.GetArgument("resume") != nullptr; @@ -114,7 +115,7 @@ int PrintPitAction::Execute(int argc, char **argv) { const char *filename = fileArgument->GetValue().c_str(); - localPitFile = fopen(filename, "rb"); + localPitFile = FileOpen(filename, "rb"); if (!localPitFile) { @@ -132,14 +133,14 @@ int PrintPitAction::Execute(int argc, char **argv) { // Print PIT from file; there's no need for a BridgeManager. - fseek(localPitFile, 0, SEEK_END); - long localPitFileSize = ftell(localPitFile); - rewind(localPitFile); + FileSeek(localPitFile, 0, SEEK_END); + unsigned int localPitFileSize = (unsigned int)FileTell(localPitFile); + FileRewind(localPitFile); // Load the local pit file into memory. unsigned char *pitFileBuffer = new unsigned char[localPitFileSize]; - size_t dataRead = fread(pitFileBuffer, 1, localPitFileSize, localPitFile); // dataRead is discarded, it's here to remove warnings. - fclose(localPitFile); + (void)fread(pitFileBuffer, 1, localPitFileSize, localPitFile); + FileClose(localPitFile); PitData *pitData = new PitData(); pitData->Unpack(pitFileBuffer); @@ -155,12 +156,7 @@ int PrintPitAction::Execute(int argc, char **argv) { // Print PIT from a device. - int communicationDelay = BridgeManager::kCommunicationDelayDefault; - - if (communicationDelayArgument) - communicationDelay = communicationDelayArgument->GetValue(); - - BridgeManager *bridgeManager = new BridgeManager(verbose, communicationDelay); + BridgeManager *bridgeManager = new BridgeManager(verbose); bridgeManager->SetUsbLogLevel(usbLogLevel); if (bridgeManager->Initialise(resume) != BridgeManager::kInitialiseSucceeded || !bridgeManager->BeginSession()) diff --git a/heimdall/source/PrintPitAction.h b/heimdall/source/PrintPitAction.h index f672375..ff2831b 100644 --- a/heimdall/source/PrintPitAction.h +++ b/heimdall/source/PrintPitAction.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -28,7 +28,7 @@ namespace Heimdall extern const char *usage; int Execute(int argc, char **argv); - }; + } } #endif diff --git a/heimdall/source/ReceiveFilePartPacket.h b/heimdall/source/ReceiveFilePartPacket.h index a07549b..8dc8321 100644 --- a/heimdall/source/ReceiveFilePartPacket.h +++ b/heimdall/source/ReceiveFilePartPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna
+/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/heimdall/source/ResponsePacket.h b/heimdall/source/ResponsePacket.h index 9883852..d0769af 100644 --- a/heimdall/source/ResponsePacket.h +++ b/heimdall/source/ResponsePacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna
+/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -64,8 +64,6 @@ namespace Heimdall virtual bool Unpack(void)
{
- const unsigned char *data = GetData();
-
unsigned int receivedResponseType = UnpackInteger(0);
if (receivedResponseType != responseType)
{
diff --git a/heimdall/source/SendFilePartPacket.h b/heimdall/source/SendFilePartPacket.h index a553a65..561bf58 100644 --- a/heimdall/source/SendFilePartPacket.h +++ b/heimdall/source/SendFilePartPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna
+/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -34,24 +34,22 @@ namespace Heimdall {
public:
- SendFilePartPacket(FILE *file, int size) : OutboundPacket(size)
+ SendFilePartPacket(FILE *file, unsigned int size) : OutboundPacket(size)
{
memset(data, 0, size);
- long position = ftell(file);
+ unsigned int position = (unsigned int)FileTell(file);
- fseek(file, 0, SEEK_END);
- long fileSize = ftell(file);
- fseek(file, position, SEEK_SET);
+ FileSeek(file, 0, SEEK_END);
+ unsigned int fileSize = (unsigned int)FileTell(file);
+ FileSeek(file, position, SEEK_SET);
// min(fileSize, size)
- int bytesToRead = (fileSize < size) ? fileSize - position : size;
-
- // bytesRead is discarded (it's just there to stop GCC warnings)
- int bytesRead = fread(data, 1, bytesToRead, file);
+ unsigned int bytesToRead = (fileSize < size) ? fileSize - position : size;
+ (void)fread(data, 1, bytesToRead, file);
}
- SendFilePartPacket(unsigned char *buffer, int size) : OutboundPacket(size)
+ SendFilePartPacket(unsigned char *buffer, unsigned int size) : OutboundPacket(size)
{
memcpy(data, buffer, size);
}
diff --git a/heimdall/source/SendFilePartResponse.h b/heimdall/source/SendFilePartResponse.h index 3cfc91c..763d2d2 100644 --- a/heimdall/source/SendFilePartResponse.h +++ b/heimdall/source/SendFilePartResponse.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna
+/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/heimdall/source/SessionSetupPacket.h b/heimdall/source/SessionSetupPacket.h index b8353bd..055e701 100644 --- a/heimdall/source/SessionSetupPacket.h +++ b/heimdall/source/SessionSetupPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/SessionSetupResponse.h b/heimdall/source/SessionSetupResponse.h index 9647219..0fb2de5 100644 --- a/heimdall/source/SessionSetupResponse.h +++ b/heimdall/source/SessionSetupResponse.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/TotalBytesPacket.h b/heimdall/source/TotalBytesPacket.h index 79a02b5..a3b0d27 100644 --- a/heimdall/source/TotalBytesPacket.h +++ b/heimdall/source/TotalBytesPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -18,7 +18,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ -#ifndef TOTALBYTESSPACKET_H +#ifndef TOTALBYTESPACKET_H #define TOTALBYTESPACKET_H // Heimdall diff --git a/heimdall/source/Utility.cpp b/heimdall/source/Utility.cpp index d8947d2..2256cf5 100644 --- a/heimdall/source/Utility.cpp +++ b/heimdall/source/Utility.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/Utility.h b/heimdall/source/Utility.h index 195ecf0..0008319 100644 --- a/heimdall/source/Utility.h +++ b/heimdall/source/Utility.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/VersionAction.cpp b/heimdall/source/VersionAction.cpp index 6121cad..36edd4e 100644 --- a/heimdall/source/VersionAction.cpp +++ b/heimdall/source/VersionAction.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/VersionAction.h b/heimdall/source/VersionAction.h index 20457b5..9dee26f 100644 --- a/heimdall/source/VersionAction.h +++ b/heimdall/source/VersionAction.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -28,7 +28,7 @@ namespace Heimdall extern const char *usage; int Execute(int argc, char **argv); - }; + } } #endif diff --git a/heimdall/source/main.cpp b/heimdall/source/main.cpp index b7ae47b..b5d44d0 100644 --- a/heimdall/source/main.cpp +++ b/heimdall/source/main.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal |