mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 02:27:39 -04:00
Major W32 beastpatcher rework (FS#10220).
Update beastpatcher to scan for the device separately, rework MTP_DLL and modify to allow building with VS2005. - include pstdint.h when building with VS2005 as VS doesn't have inttypes.h - don't use bool in the DLL as VS doesn't support type bool in C. - rearrange DLL files to avoid filename ambiguities with sendfirm. - include MTP_DLL.h instead of duplicating prototypes. Adjust header for easy inclusion. - make MTP_DLL project file also copy the resulting dll to MTP folder for convenience. - extend MTP_DLL API for separate device scanning. Note that this (intentionally) breaks compatibility of the dll. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21221 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
5575f425d6
commit
eebde2a367
14 changed files with 1524 additions and 300 deletions
Binary file not shown.
|
@ -1,10 +1,21 @@
|
|||
|
||||
#ifndef MTP_DLL_H
|
||||
#define MTP_DLL_H
|
||||
|
||||
#ifdef MTP_DLL_EXPORTS
|
||||
#define MTP_DLL_API __declspec(dllexport)
|
||||
#else
|
||||
#define MTP_DLL_API __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
__declspec(dllexport) bool send_fw(LPWSTR file, int filesize, void (*callback)(unsigned int progress, unsigned int max));
|
||||
#endif
|
||||
MTP_DLL_API int mtp_sendnk(LPWSTR file, int filesize, void (*callback)(unsigned int progress, unsigned int max));
|
||||
MTP_DLL_API int mtp_description(wchar_t* name, wchar_t* manufacturer, DWORD* version);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8,00"
|
||||
Version="8.00"
|
||||
Name="MTP_DLL"
|
||||
ProjectGUID="{C7A39A2D-2ADF-40A3-A9A5-0DF4509B761B}"
|
||||
RootNamespace="MTP_DLL"
|
||||
|
@ -170,6 +170,7 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
CommandLine="echo Copying $(TargetName) dll / lib to ..
copy /Y "$(InputDir)$(ConfigurationName)\$(TargetFileName)" "$(InputDir)..\"
copy /Y "$(InputDir)$(ConfigurationName)\$(TargetName).lib" "$(InputDir)..\""
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
|
@ -186,24 +187,12 @@
|
|||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\sendfirm_win.cpp"
|
||||
RelativePath=".\mtp_wrapper.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\progresshelper.cpp"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.cpp"
|
||||
|
@ -235,6 +224,10 @@
|
|||
RelativePath=".\MTP_DLL.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\progresshelper.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.h"
|
||||
>
|
||||
|
|
284
utils/MTP/MTP_DLL/mtp_wrapper.cpp
Normal file
284
utils/MTP/MTP_DLL/mtp_wrapper.cpp
Normal file
|
@ -0,0 +1,284 @@
|
|||
/*
|
||||
* Windows MTP Firmware Uploading Implementation
|
||||
*
|
||||
* Based on http://opensource.creative.com/mtp_xfer.html
|
||||
* Edited by Maurus Cuelenaere for Rockbox
|
||||
*
|
||||
* Copyright (c) 2009, Maurus Cuelenaere
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the <organization> nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY MAURUS CUELENAERE ''AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL MAURUS CUELENAERE BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include "mswmdm_i.c"
|
||||
#include "mswmdm.h"
|
||||
#include "sac.h"
|
||||
#include "scclient.h"
|
||||
|
||||
#include "progresshelper.h"
|
||||
#include "MTP_DLL.h"
|
||||
|
||||
/*
|
||||
* Compilation requirements:
|
||||
*
|
||||
* Download the Windows Media Format 9.5 SDK
|
||||
* Add "c:\wmsdk\wmfsdk95\include,c:\wmsdk\wmfsdk95\wmdm\inc" to your inclusion path
|
||||
* Add "c:\wmsdk\wmfsdk95\lib,c:\wmsdk\wmfsdk95\wmdm\lib" to your library inclusion path
|
||||
* Link to "mssachlp.lib"
|
||||
*
|
||||
*/
|
||||
|
||||
struct mtp_if {
|
||||
IComponentAuthenticate* pICompAuth;
|
||||
CSecureChannelClient *pSacClient;
|
||||
IWMDeviceManager3* pIdvMgr;
|
||||
bool initialized;
|
||||
};
|
||||
|
||||
|
||||
extern "C" {
|
||||
static int mtp_init(struct mtp_if* mtp)
|
||||
{
|
||||
HRESULT hr;
|
||||
mtp->pSacClient = new CSecureChannelClient;
|
||||
mtp->pIdvMgr = NULL;
|
||||
mtp->initialized = false;
|
||||
|
||||
/* these are generic keys */
|
||||
BYTE abPVK[] = {0x00};
|
||||
BYTE abCert[] = {0x00};
|
||||
|
||||
CoInitialize(NULL);
|
||||
|
||||
/* get an authentication interface */
|
||||
hr = CoCreateInstance(CLSID_MediaDevMgr, NULL, CLSCTX_ALL,
|
||||
IID_IComponentAuthenticate, (void **)&mtp->pICompAuth);
|
||||
if SUCCEEDED(hr)
|
||||
{
|
||||
/* create a secure channel client certificate */
|
||||
hr = mtp->pSacClient->SetCertificate(SAC_CERT_V1, (BYTE*) abCert,
|
||||
sizeof(abCert), (BYTE*) abPVK, sizeof(abPVK));
|
||||
if SUCCEEDED(hr)
|
||||
{
|
||||
/* bind the authentication interface to the secure channel client */
|
||||
mtp->pSacClient->SetInterface(mtp->pICompAuth);
|
||||
|
||||
/* trigger communication */
|
||||
hr = mtp->pSacClient->Authenticate(SAC_PROTOCOL_V1);
|
||||
if SUCCEEDED(hr)
|
||||
{
|
||||
/* get main interface to media device manager */
|
||||
hr = mtp->pICompAuth->QueryInterface(IID_IWMDeviceManager2,
|
||||
(void**)&mtp->pIdvMgr);
|
||||
if SUCCEEDED(hr)
|
||||
{
|
||||
mtp->initialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
CoUninitialize();
|
||||
}
|
||||
return mtp->initialized;
|
||||
}
|
||||
|
||||
|
||||
static int mtp_close(struct mtp_if* mtp)
|
||||
{
|
||||
if(mtp->initialized)
|
||||
{
|
||||
mtp->pIdvMgr->Release();
|
||||
mtp->pICompAuth->Release();
|
||||
CoUninitialize();
|
||||
mtp->initialized = false;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
__declspec(dllexport) int mtp_description(wchar_t* name, wchar_t* manufacturer, DWORD* version)
|
||||
{
|
||||
HRESULT hr;
|
||||
int num = 0;
|
||||
struct mtp_if mtp;
|
||||
/* zero mtp structure */
|
||||
memset(&mtp, 0, sizeof(struct mtp_if));
|
||||
|
||||
/* initialize interface */
|
||||
mtp_init(&mtp);
|
||||
if(mtp.initialized == false) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* we now have a media device manager interface... */
|
||||
/* enumerate devices... */
|
||||
IWMDMEnumDevice *pIEnumDev;
|
||||
wchar_t pwsString[256];
|
||||
hr = mtp.pIdvMgr->EnumDevices2(&pIEnumDev);
|
||||
if SUCCEEDED(hr) {
|
||||
hr = pIEnumDev->Reset(); /* Next will now return the first device */
|
||||
if SUCCEEDED(hr) {
|
||||
IWMDMDevice3* pIDevice;
|
||||
unsigned long ulNumFetched;
|
||||
hr = pIEnumDev->Next(1, (IWMDMDevice **)&pIDevice, &ulNumFetched);
|
||||
while (SUCCEEDED(hr) && (hr != S_FALSE)) {
|
||||
/* output device name */
|
||||
hr = pIDevice->GetName(pwsString, 256);
|
||||
if SUCCEEDED(hr) {
|
||||
wcsncpy_s(name, 256, pwsString, _TRUNCATE);
|
||||
num++;
|
||||
}
|
||||
/* device manufacturer */
|
||||
hr = pIDevice->GetManufacturer(pwsString, 256);
|
||||
if SUCCEEDED(hr) {
|
||||
wcsncpy_s(manufacturer, 256, pwsString, _TRUNCATE);
|
||||
}
|
||||
/* device version -- optional interface so might fail. */
|
||||
DWORD ver;
|
||||
hr = pIDevice->GetVersion(&ver);
|
||||
if SUCCEEDED(hr) {
|
||||
*version = ver;
|
||||
}
|
||||
else {
|
||||
*version = 0;
|
||||
}
|
||||
|
||||
/* move to next device */
|
||||
hr = pIEnumDev->Next(1, (IWMDMDevice **)&pIDevice, &ulNumFetched);
|
||||
}
|
||||
pIEnumDev->Release();
|
||||
}
|
||||
mtp_close(&mtp);
|
||||
}
|
||||
return (num > 0) ? num : -1;
|
||||
}
|
||||
|
||||
__declspec(dllexport) int mtp_sendnk(LPWSTR file, int filesize, void (*callback)(unsigned int progress, unsigned int max))
|
||||
{
|
||||
HRESULT hr;
|
||||
bool return_value = false;
|
||||
struct mtp_if mtp;
|
||||
/* zero mtp structure */
|
||||
memset(&mtp, 0, sizeof(struct mtp_if));
|
||||
|
||||
/* initialize interface */
|
||||
mtp_init(&mtp);
|
||||
if(mtp.initialized == false) {
|
||||
return false;
|
||||
}
|
||||
/* enumerate devices... */
|
||||
IWMDMEnumDevice *pIEnumDev;
|
||||
hr = mtp.pIdvMgr->EnumDevices2(&pIEnumDev);
|
||||
if SUCCEEDED(hr)
|
||||
{
|
||||
hr = pIEnumDev->Reset(); /* Next will now return the first device */
|
||||
if SUCCEEDED(hr)
|
||||
{
|
||||
IWMDMDevice3* pIDevice;
|
||||
unsigned long ulNumFetched;
|
||||
hr = pIEnumDev->Next(1, (IWMDMDevice **)&pIDevice, &ulNumFetched);
|
||||
while (SUCCEEDED(hr) && (hr != S_FALSE))
|
||||
{
|
||||
/* get storage info */
|
||||
DWORD tempDW;
|
||||
pIDevice->GetType(&tempDW);
|
||||
if (tempDW & WMDM_DEVICE_TYPE_STORAGE)
|
||||
{
|
||||
IWMDMEnumStorage *pIEnumStorage = NULL;
|
||||
IWMDMStorage *pIStorage = NULL;
|
||||
IWMDMStorage3 *pIFileStorage = NULL;
|
||||
hr = pIDevice->EnumStorage(&pIEnumStorage);
|
||||
if SUCCEEDED(hr)
|
||||
{
|
||||
pIEnumStorage->Reset();
|
||||
hr = pIEnumStorage->Next(1, (IWMDMStorage **)&pIStorage, &ulNumFetched);
|
||||
while (SUCCEEDED(hr) && (hr != S_FALSE))
|
||||
{
|
||||
IWMDMStorage3 *pNewStorage;
|
||||
hr = pIStorage->QueryInterface(IID_IWMDMStorage3, (void **)&pNewStorage);
|
||||
if SUCCEEDED(hr)
|
||||
{
|
||||
IWMDMStorageControl3 *pIWMDMStorageControl;
|
||||
hr = pNewStorage->QueryInterface(IID_IWMDMStorageControl3,
|
||||
(void**)&pIWMDMStorageControl);
|
||||
if SUCCEEDED(hr)
|
||||
{
|
||||
IWMDMMetaData *pIWMDMMetaData = NULL;
|
||||
hr = pNewStorage->CreateEmptyMetadataObject(&pIWMDMMetaData);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
DWORD dw = WMDM_FORMATCODE_UNDEFINEDFIRMWARE;
|
||||
hr = pIWMDMMetaData->AddItem(WMDM_TYPE_DWORD, g_wszWMDMFormatCode, (BYTE *)&dw, sizeof(dw));
|
||||
hr = pIWMDMMetaData->AddItem(WMDM_TYPE_STRING, g_wszWMDMFileName, (BYTE *)L"nk.bin", 32);
|
||||
DWORD ow[2];
|
||||
ow[0] = filesize;
|
||||
ow[1] = 0;
|
||||
hr = pIWMDMMetaData->AddItem(WMDM_TYPE_QWORD, g_wszWMDMFileSize, (BYTE *)ow, 2 * sizeof(dw));
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
IWMDMStorage *pNewObject = NULL;
|
||||
CProgressHelper *progress = new CProgressHelper(callback);
|
||||
|
||||
hr = pIWMDMStorageControl->Insert3(
|
||||
WMDM_MODE_BLOCK | WMDM_CONTENT_FILE | WMDM_MODE_PROGRESS,
|
||||
0,
|
||||
file,
|
||||
NULL,
|
||||
NULL,
|
||||
(callback == NULL ? NULL : (IWMDMProgress*)progress),
|
||||
pIWMDMMetaData,
|
||||
NULL,
|
||||
(IWMDMStorage **)&pNewObject);
|
||||
|
||||
if(SUCCEEDED(hr)
|
||||
|| hr == WMDM_S_NOT_ALL_PROPERTIES_APPLIED
|
||||
|| hr == WMDM_S_NOT_ALL_PROPERTIES_RETRIEVED)
|
||||
{
|
||||
return_value = true;
|
||||
hr = S_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pIEnumStorage->Release();
|
||||
}
|
||||
|
||||
/* move to next device */
|
||||
if(!return_value)
|
||||
hr = pIEnumDev->Next(1, (IWMDMDevice **)&pIDevice, &ulNumFetched);
|
||||
}
|
||||
pIEnumDev->Release();
|
||||
}
|
||||
mtp_close(&mtp);
|
||||
}
|
||||
return return_value ? 1 : 0;
|
||||
}
|
||||
|
||||
}
|
104
utils/MTP/MTP_DLL/progresshelper.cpp
Normal file
104
utils/MTP/MTP_DLL/progresshelper.cpp
Normal file
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Windows MTP Firmware Uploading Implementation
|
||||
*
|
||||
* Based on http://opensource.creative.com/mtp_xfer.html
|
||||
* Edited by Maurus Cuelenaere for Rockbox
|
||||
*
|
||||
* Copyright (c) 2009, Maurus Cuelenaere
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the <organization> nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY MAURUS CUELENAERE ''AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL MAURUS CUELENAERE BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include "mswmdm_i.c"
|
||||
#include "mswmdm.h"
|
||||
#include "sac.h"
|
||||
#include "scclient.h"
|
||||
|
||||
#include "progresshelper.h"
|
||||
|
||||
|
||||
|
||||
|
||||
CProgressHelper::CProgressHelper( void (*callback)(unsigned int progress, unsigned int max) )
|
||||
{
|
||||
m_cur_ticks = 0;
|
||||
m_max_ticks = 0;
|
||||
m_counter = 0;
|
||||
|
||||
m_callback = callback;
|
||||
}
|
||||
|
||||
CProgressHelper::~CProgressHelper()
|
||||
{
|
||||
}
|
||||
|
||||
HRESULT CProgressHelper::Begin( DWORD dwEstimatedTicks )
|
||||
{
|
||||
m_max_ticks = dwEstimatedTicks;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CProgressHelper::Progress( DWORD dwTranspiredTicks )
|
||||
{
|
||||
m_cur_ticks = dwTranspiredTicks;
|
||||
|
||||
if(m_callback != NULL)
|
||||
m_callback(m_cur_ticks, max(m_max_ticks, m_cur_ticks));
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CProgressHelper::End()
|
||||
{
|
||||
m_cur_ticks = m_max_ticks;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CProgressHelper::QueryInterface( REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject )
|
||||
{
|
||||
if(riid == IID_IWMDMProgress || riid == IID_IUnknown)
|
||||
{
|
||||
*ppvObject = this;
|
||||
return S_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
*ppvObject = NULL;
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
}
|
||||
|
||||
ULONG CProgressHelper::AddRef()
|
||||
{
|
||||
return m_counter++;
|
||||
}
|
||||
ULONG CProgressHelper::Release()
|
||||
{
|
||||
return m_counter--;
|
||||
}
|
52
utils/MTP/MTP_DLL/progresshelper.h
Normal file
52
utils/MTP/MTP_DLL/progresshelper.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Windows MTP Firmware Uploading Implementation
|
||||
*
|
||||
* Based on http://opensource.creative.com/mtp_xfer.html
|
||||
* Edited by Maurus Cuelenaere for Rockbox
|
||||
*
|
||||
* Copyright (c) 2009, Maurus Cuelenaere
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the <organization> nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY MAURUS CUELENAERE ''AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL MAURUS CUELENAERE BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
class CProgressHelper :
|
||||
public IWMDMProgress
|
||||
{
|
||||
void (*m_callback)(unsigned int progress, unsigned int max);
|
||||
DWORD m_max_ticks;
|
||||
DWORD m_cur_ticks;
|
||||
DWORD m_counter;
|
||||
|
||||
public:
|
||||
CProgressHelper( void (*callback)(unsigned int progress, unsigned int max) );
|
||||
~CProgressHelper();
|
||||
STDMETHOD(Begin)( DWORD dwEstimatedTicks );
|
||||
STDMETHOD(Progress)( DWORD dwTranspiredTicks );
|
||||
STDMETHOD(End)();
|
||||
|
||||
STDMETHOD(QueryInterface) ( REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject );
|
||||
STDMETHOD_(ULONG, AddRef)( void );
|
||||
STDMETHOD_(ULONG, Release)( void );
|
||||
};
|
||||
|
|
@ -1,260 +0,0 @@
|
|||
/*
|
||||
* Windows MTP Firmware Uploading Implementation
|
||||
*
|
||||
* Based on http://opensource.creative.com/mtp_xfer.html
|
||||
* Edited by Maurus Cuelenaere for Rockbox
|
||||
*
|
||||
* Copyright (c) 2009, Maurus Cuelenaere
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the <organization> nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY MAURUS CUELENAERE ''AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL MAURUS CUELENAERE BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include "mswmdm_i.c"
|
||||
#include "mswmdm.h"
|
||||
#include "sac.h"
|
||||
#include "scclient.h"
|
||||
|
||||
class CProgressHelper :
|
||||
public IWMDMProgress
|
||||
{
|
||||
void (*m_callback)(unsigned int progress, unsigned int max);
|
||||
DWORD m_max_ticks;
|
||||
DWORD m_cur_ticks;
|
||||
DWORD m_counter;
|
||||
|
||||
public:
|
||||
CProgressHelper( void (*callback)(unsigned int progress, unsigned int max) );
|
||||
~CProgressHelper();
|
||||
STDMETHOD(Begin)( DWORD dwEstimatedTicks );
|
||||
STDMETHOD(Progress)( DWORD dwTranspiredTicks );
|
||||
STDMETHOD(End)();
|
||||
|
||||
STDMETHOD(QueryInterface) ( REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject );
|
||||
STDMETHOD_(ULONG, AddRef)( void );
|
||||
STDMETHOD_(ULONG, Release)( void );
|
||||
};
|
||||
|
||||
/*
|
||||
* Compilation requirements:
|
||||
*
|
||||
* Download the Windows Media Format 9.5 SDK
|
||||
* Add "c:\wmsdk\wmfsdk95\include,c:\wmsdk\wmfsdk95\wmdm\inc" to your inclusion path
|
||||
* Add "c:\wmsdk\wmfsdk95\lib,c:\wmsdk\wmfsdk95\wmdm\lib" to your library inclusion path
|
||||
* Link to "mssachlp.lib"
|
||||
*
|
||||
*/
|
||||
extern "C" {
|
||||
__declspec(dllexport) bool send_fw(LPWSTR file, int filesize, void (*callback)(unsigned int progress, unsigned int max))
|
||||
{
|
||||
bool return_value = false;
|
||||
HRESULT hr;
|
||||
IComponentAuthenticate* pICompAuth;
|
||||
CSecureChannelClient *m_pSacClient = new CSecureChannelClient;
|
||||
IWMDeviceManager3* m_pIdvMgr = NULL;
|
||||
|
||||
/* these are generic keys */
|
||||
BYTE abPVK[] = {0x00};
|
||||
BYTE abCert[] = {0x00};
|
||||
|
||||
CoInitialize(NULL);
|
||||
|
||||
/* get an authentication interface */
|
||||
hr = CoCreateInstance(CLSID_MediaDevMgr, NULL, CLSCTX_ALL ,IID_IComponentAuthenticate, (void **)&pICompAuth);
|
||||
if SUCCEEDED(hr)
|
||||
{
|
||||
/* create a secure channel client certificate */
|
||||
hr = m_pSacClient->SetCertificate(SAC_CERT_V1, (BYTE*) abCert, sizeof(abCert), (BYTE*) abPVK, sizeof(abPVK));
|
||||
if SUCCEEDED(hr)
|
||||
{
|
||||
/* bind the authentication interface to the secure channel client */
|
||||
m_pSacClient->SetInterface(pICompAuth);
|
||||
|
||||
/* trigger communication */
|
||||
hr = m_pSacClient->Authenticate(SAC_PROTOCOL_V1);
|
||||
if SUCCEEDED(hr)
|
||||
{
|
||||
/* get main interface to media device manager */
|
||||
hr = pICompAuth->QueryInterface(IID_IWMDeviceManager2, (void**)&m_pIdvMgr);
|
||||
if SUCCEEDED(hr)
|
||||
{
|
||||
/* enumerate devices... */
|
||||
IWMDMEnumDevice *pIEnumDev;
|
||||
hr = m_pIdvMgr->EnumDevices2(&pIEnumDev);
|
||||
if SUCCEEDED(hr)
|
||||
{
|
||||
hr = pIEnumDev->Reset(); /* Next will now return the first device */
|
||||
if SUCCEEDED(hr)
|
||||
{
|
||||
IWMDMDevice3* pIDevice;
|
||||
unsigned long ulNumFetched;
|
||||
hr = pIEnumDev->Next(1, (IWMDMDevice **)&pIDevice, &ulNumFetched);
|
||||
while (SUCCEEDED(hr) && (hr != S_FALSE))
|
||||
{
|
||||
/* get storage info */
|
||||
DWORD tempDW;
|
||||
pIDevice->GetType(&tempDW);
|
||||
if (tempDW & WMDM_DEVICE_TYPE_STORAGE)
|
||||
{
|
||||
IWMDMEnumStorage *pIEnumStorage = NULL;
|
||||
IWMDMStorage *pIStorage = NULL;
|
||||
IWMDMStorage3 *pIFileStorage = NULL;
|
||||
hr = pIDevice->EnumStorage(&pIEnumStorage);
|
||||
if SUCCEEDED(hr)
|
||||
{
|
||||
pIEnumStorage->Reset();
|
||||
hr = pIEnumStorage->Next(1, (IWMDMStorage **)&pIStorage, &ulNumFetched);
|
||||
while (SUCCEEDED(hr) && (hr != S_FALSE))
|
||||
{
|
||||
IWMDMStorage3 *pNewStorage;
|
||||
hr = pIStorage->QueryInterface(IID_IWMDMStorage3, (void **)&pNewStorage);
|
||||
if SUCCEEDED(hr)
|
||||
{
|
||||
IWMDMStorageControl3 *pIWMDMStorageControl;
|
||||
hr = pNewStorage->QueryInterface(IID_IWMDMStorageControl3,
|
||||
(void**)&pIWMDMStorageControl);
|
||||
if SUCCEEDED(hr)
|
||||
{
|
||||
IWMDMMetaData *pIWMDMMetaData = NULL;
|
||||
hr = pNewStorage->CreateEmptyMetadataObject(&pIWMDMMetaData);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
DWORD dw = WMDM_FORMATCODE_UNDEFINEDFIRMWARE;
|
||||
hr = pIWMDMMetaData->AddItem(WMDM_TYPE_DWORD, g_wszWMDMFormatCode, (BYTE *)&dw, sizeof(dw));
|
||||
hr = pIWMDMMetaData->AddItem(WMDM_TYPE_STRING, g_wszWMDMFileName, (BYTE *)L"nk.bin", 32);
|
||||
DWORD ow[2];
|
||||
ow[0] = filesize;
|
||||
ow[1] = 0;
|
||||
hr = pIWMDMMetaData->AddItem(WMDM_TYPE_QWORD, g_wszWMDMFileSize, (BYTE *)ow, 2 * sizeof(dw));
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
IWMDMStorage *pNewObject = NULL;
|
||||
CProgressHelper *progress = new CProgressHelper(callback);
|
||||
|
||||
hr = pIWMDMStorageControl->Insert3(
|
||||
WMDM_MODE_BLOCK | WMDM_CONTENT_FILE | WMDM_MODE_PROGRESS,
|
||||
0,
|
||||
file,
|
||||
NULL,
|
||||
NULL,
|
||||
(callback == NULL ? NULL : (IWMDMProgress*)progress),
|
||||
pIWMDMMetaData,
|
||||
NULL,
|
||||
(IWMDMStorage **)&pNewObject);
|
||||
|
||||
if(SUCCEEDED(hr) || hr == WMDM_S_NOT_ALL_PROPERTIES_APPLIED
|
||||
|| hr == WMDM_S_NOT_ALL_PROPERTIES_RETRIEVED)
|
||||
{
|
||||
return_value = true;
|
||||
hr = S_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pIEnumStorage->Release();
|
||||
}
|
||||
|
||||
/* move to next device */
|
||||
if(!return_value)
|
||||
hr = pIEnumDev->Next(1, (IWMDMDevice **)&pIDevice, &ulNumFetched);
|
||||
}
|
||||
pIEnumDev->Release();
|
||||
}
|
||||
m_pIdvMgr->Release();
|
||||
}
|
||||
pICompAuth->Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CoUninitialize();
|
||||
|
||||
return return_value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CProgressHelper::CProgressHelper( void (*callback)(unsigned int progress, unsigned int max) )
|
||||
{
|
||||
m_cur_ticks = 0;
|
||||
m_max_ticks = 0;
|
||||
m_counter = 0;
|
||||
|
||||
m_callback = callback;
|
||||
}
|
||||
|
||||
CProgressHelper::~CProgressHelper()
|
||||
{
|
||||
}
|
||||
|
||||
HRESULT CProgressHelper::Begin( DWORD dwEstimatedTicks )
|
||||
{
|
||||
m_max_ticks = dwEstimatedTicks;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CProgressHelper::Progress( DWORD dwTranspiredTicks )
|
||||
{
|
||||
m_cur_ticks = dwTranspiredTicks;
|
||||
|
||||
if(m_callback != NULL)
|
||||
m_callback(m_cur_ticks, max(m_max_ticks, m_cur_ticks));
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CProgressHelper::End()
|
||||
{
|
||||
m_cur_ticks = m_max_ticks;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CProgressHelper::QueryInterface( REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject )
|
||||
{
|
||||
if(riid == IID_IWMDMProgress || riid == IID_IUnknown)
|
||||
{
|
||||
*ppvObject = this;
|
||||
return S_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
*ppvObject = NULL;
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
}
|
||||
|
||||
ULONG CProgressHelper::AddRef()
|
||||
{
|
||||
return m_counter++;
|
||||
}
|
||||
ULONG CProgressHelper::Release()
|
||||
{
|
||||
return m_counter--;
|
||||
}
|
7
utils/MTP/beastpatcher/README.pstdint
Normal file
7
utils/MTP/beastpatcher/README.pstdint
Normal file
|
@ -0,0 +1,7 @@
|
|||
pstdint.h: A portable stdint.h
|
||||
|
||||
This file is taken from http://www.azillionmonkeys.com/qed/pstdint.h
|
||||
|
||||
Copyright (c) 2005-2007 Paul Hsieh
|
||||
Licensed under the BSD License. See file header for details.
|
||||
|
|
@ -38,11 +38,17 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#if !defined(_MSC_VER)
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#if !defined(_MSC_VER)
|
||||
#include <inttypes.h>
|
||||
#else
|
||||
#include "pstdint.h"
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
@ -70,10 +76,10 @@ void print_usage(void)
|
|||
|
||||
static void put_uint32le(uint32_t x, unsigned char* p)
|
||||
{
|
||||
p[0] = x & 0xff;
|
||||
p[1] = (x >> 8) & 0xff;
|
||||
p[2] = (x >> 16) & 0xff;
|
||||
p[3] = (x >> 24) & 0xff;
|
||||
p[0] = (unsigned char)(x & 0xff);
|
||||
p[1] = (unsigned char)((x >> 8) & 0xff);
|
||||
p[2] = (unsigned char)((x >> 16) & 0xff);
|
||||
p[3] = (unsigned char)((x >> 24) & 0xff);
|
||||
}
|
||||
|
||||
static uint32_t calc_csum(const unsigned char* pb, int cb)
|
||||
|
@ -94,7 +100,7 @@ static void create_single_boot(unsigned char* boot, int bootlen,
|
|||
*fwsize = 15 + 16 + 12 + bootlen + 12;
|
||||
*fwbuf = malloc(*fwsize);
|
||||
|
||||
if(buf == NULL) {
|
||||
if(fwbuf == NULL) {
|
||||
fprintf(stderr, "[ERR] Cannot allocate memory.\n" );
|
||||
*fwbuf = NULL;
|
||||
*fwsize = 0;
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
#ifndef _MTP_COMMON_H
|
||||
#define _MTP_COMMON_H
|
||||
|
||||
#ifdef __WIN32__
|
||||
#if defined(__WIN32__) || defined(_WIN32)
|
||||
#else
|
||||
#include "libmtp.h"
|
||||
#endif
|
||||
|
@ -53,7 +53,7 @@ struct mtp_info_t
|
|||
char version[200];
|
||||
|
||||
/* OS-Specific data */
|
||||
#ifdef __WIN32__
|
||||
#if defined(__WIN32__) || defined(_WIN32)
|
||||
#else
|
||||
LIBMTP_mtpdevice_t *device;
|
||||
#endif
|
||||
|
|
|
@ -43,15 +43,12 @@
|
|||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
#include <stdbool.h>
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
|
||||
#include "mtp_common.h"
|
||||
|
||||
|
||||
extern __declspec(dllimport) bool send_fw(LPWSTR file, int filesize,
|
||||
void (*callback)(unsigned int progress, unsigned int max));
|
||||
#include "../MTP_DLL/MTP_DLL.h"
|
||||
|
||||
int mtp_init(struct mtp_info_t* mtp_info)
|
||||
{
|
||||
|
@ -71,11 +68,18 @@ int mtp_finished(struct mtp_info_t* mtp_info)
|
|||
|
||||
int mtp_scan(struct mtp_info_t* mtp_info)
|
||||
{
|
||||
strcpy(mtp_info->manufacturer,"<unknown>");
|
||||
strcpy(mtp_info->modelname,"<unknown>");
|
||||
strcpy(mtp_info->version,"<unknown>");
|
||||
wchar_t name[256];
|
||||
wchar_t manufacturer[256];
|
||||
DWORD version;
|
||||
int num = 0;
|
||||
|
||||
return 0;
|
||||
num = mtp_description(name, manufacturer, &version);
|
||||
|
||||
wcstombs(mtp_info->manufacturer, manufacturer, 200);
|
||||
wcstombs(mtp_info->modelname, name, 200);
|
||||
|
||||
sprintf(mtp_info->version, "%x", (unsigned int)version);
|
||||
return (num > 0) ? num : -1;
|
||||
|
||||
}
|
||||
|
||||
|
@ -147,11 +151,11 @@ int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
|
|||
return -1;
|
||||
}
|
||||
|
||||
tmp = (LPWSTR)malloc(strlen(szTempName)*2+1);
|
||||
mbstowcs(tmp, szTempName, strlen(szTempName)*2+1);
|
||||
tmp = (LPWSTR)malloc(_tcslen(szTempName)*2+1);
|
||||
mbstowcs(tmp, (char*)szTempName, _tcslen(szTempName)*2+1);
|
||||
|
||||
fprintf(stderr, "[INFO] Sending firmware...\n");
|
||||
if (send_fw(tmp, fwsize, &callback))
|
||||
if (mtp_sendnk(tmp, fwsize, &callback))
|
||||
{
|
||||
fprintf(stderr, "[INFO] Firmware sent successfully\n");
|
||||
ret = 0;
|
||||
|
@ -172,3 +176,4 @@ int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
799
utils/MTP/beastpatcher/pstdint.h
Normal file
799
utils/MTP/beastpatcher/pstdint.h
Normal file
|
@ -0,0 +1,799 @@
|
|||
/* A portable stdint.h
|
||||
****************************************************************************
|
||||
* BSD License:
|
||||
****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2005-2007 Paul Hsieh
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************
|
||||
*
|
||||
* Version 0.1.11
|
||||
*
|
||||
* The ANSI C standard committee, for the C99 standard, specified the
|
||||
* inclusion of a new standard include file called stdint.h. This is
|
||||
* a very useful and long desired include file which contains several
|
||||
* very precise definitions for integer scalar types that is
|
||||
* critically important for making portable several classes of
|
||||
* applications including cryptography, hashing, variable length
|
||||
* integer libraries and so on. But for most developers its likely
|
||||
* useful just for programming sanity.
|
||||
*
|
||||
* The problem is that most compiler vendors have decided not to
|
||||
* implement the C99 standard, and the next C++ language standard
|
||||
* (which has a lot more mindshare these days) will be a long time in
|
||||
* coming and its unknown whether or not it will include stdint.h or
|
||||
* how much adoption it will have. Either way, it will be a long time
|
||||
* before all compilers come with a stdint.h and it also does nothing
|
||||
* for the extremely large number of compilers available today which
|
||||
* do not include this file, or anything comparable to it.
|
||||
*
|
||||
* So that's what this file is all about. Its an attempt to build a
|
||||
* single universal include file that works on as many platforms as
|
||||
* possible to deliver what stdint.h is supposed to. A few things
|
||||
* that should be noted about this file:
|
||||
*
|
||||
* 1) It is not guaranteed to be portable and/or present an identical
|
||||
* interface on all platforms. The extreme variability of the
|
||||
* ANSI C standard makes this an impossibility right from the
|
||||
* very get go. Its really only meant to be useful for the vast
|
||||
* majority of platforms that possess the capability of
|
||||
* implementing usefully and precisely defined, standard sized
|
||||
* integer scalars. Systems which are not intrinsically 2s
|
||||
* complement may produce invalid constants.
|
||||
*
|
||||
* 2) There is an unavoidable use of non-reserved symbols.
|
||||
*
|
||||
* 3) Other standard include files are invoked.
|
||||
*
|
||||
* 4) This file may come in conflict with future platforms that do
|
||||
* include stdint.h. The hope is that one or the other can be
|
||||
* used with no real difference.
|
||||
*
|
||||
* 5) In the current verison, if your platform can't represent
|
||||
* int32_t, int16_t and int8_t, it just dumps out with a compiler
|
||||
* error.
|
||||
*
|
||||
* 6) 64 bit integers may or may not be defined. Test for their
|
||||
* presence with the test: #ifdef INT64_MAX or #ifdef UINT64_MAX.
|
||||
* Note that this is different from the C99 specification which
|
||||
* requires the existence of 64 bit support in the compiler. If
|
||||
* this is not defined for your platform, yet it is capable of
|
||||
* dealing with 64 bits then it is because this file has not yet
|
||||
* been extended to cover all of your system's capabilities.
|
||||
*
|
||||
* 7) (u)intptr_t may or may not be defined. Test for its presence
|
||||
* with the test: #ifdef PTRDIFF_MAX. If this is not defined
|
||||
* for your platform, then it is because this file has not yet
|
||||
* been extended to cover all of your system's capabilities, not
|
||||
* because its optional.
|
||||
*
|
||||
* 8) The following might not been defined even if your platform is
|
||||
* capable of defining it:
|
||||
*
|
||||
* WCHAR_MIN
|
||||
* WCHAR_MAX
|
||||
* (u)int64_t
|
||||
* PTRDIFF_MIN
|
||||
* PTRDIFF_MAX
|
||||
* (u)intptr_t
|
||||
*
|
||||
* 9) The following have not been defined:
|
||||
*
|
||||
* WINT_MIN
|
||||
* WINT_MAX
|
||||
*
|
||||
* 10) The criteria for defining (u)int_least(*)_t isn't clear,
|
||||
* except for systems which don't have a type that precisely
|
||||
* defined 8, 16, or 32 bit types (which this include file does
|
||||
* not support anyways). Default definitions have been given.
|
||||
*
|
||||
* 11) The criteria for defining (u)int_fast(*)_t isn't something I
|
||||
* would trust to any particular compiler vendor or the ANSI C
|
||||
* committee. It is well known that "compatible systems" are
|
||||
* commonly created that have very different performance
|
||||
* characteristics from the systems they are compatible with,
|
||||
* especially those whose vendors make both the compiler and the
|
||||
* system. Default definitions have been given, but its strongly
|
||||
* recommended that users never use these definitions for any
|
||||
* reason (they do *NOT* deliver any serious guarantee of
|
||||
* improved performance -- not in this file, nor any vendor's
|
||||
* stdint.h).
|
||||
*
|
||||
* 12) The following macros:
|
||||
*
|
||||
* PRINTF_INTMAX_MODIFIER
|
||||
* PRINTF_INT64_MODIFIER
|
||||
* PRINTF_INT32_MODIFIER
|
||||
* PRINTF_INT16_MODIFIER
|
||||
* PRINTF_LEAST64_MODIFIER
|
||||
* PRINTF_LEAST32_MODIFIER
|
||||
* PRINTF_LEAST16_MODIFIER
|
||||
* PRINTF_INTPTR_MODIFIER
|
||||
*
|
||||
* are strings which have been defined as the modifiers required
|
||||
* for the "d", "u" and "x" printf formats to correctly output
|
||||
* (u)intmax_t, (u)int64_t, (u)int32_t, (u)int16_t, (u)least64_t,
|
||||
* (u)least32_t, (u)least16_t and (u)intptr_t types respectively.
|
||||
* PRINTF_INTPTR_MODIFIER is not defined for some systems which
|
||||
* provide their own stdint.h. PRINTF_INT64_MODIFIER is not
|
||||
* defined if INT64_MAX is not defined. These are an extension
|
||||
* beyond what C99 specifies must be in stdint.h.
|
||||
*
|
||||
* In addition, the following macros are defined:
|
||||
*
|
||||
* PRINTF_INTMAX_HEX_WIDTH
|
||||
* PRINTF_INT64_HEX_WIDTH
|
||||
* PRINTF_INT32_HEX_WIDTH
|
||||
* PRINTF_INT16_HEX_WIDTH
|
||||
* PRINTF_INT8_HEX_WIDTH
|
||||
* PRINTF_INTMAX_DEC_WIDTH
|
||||
* PRINTF_INT64_DEC_WIDTH
|
||||
* PRINTF_INT32_DEC_WIDTH
|
||||
* PRINTF_INT16_DEC_WIDTH
|
||||
* PRINTF_INT8_DEC_WIDTH
|
||||
*
|
||||
* Which specifies the maximum number of characters required to
|
||||
* print the number of that type in either hexadecimal or decimal.
|
||||
* These are an extension beyond what C99 specifies must be in
|
||||
* stdint.h.
|
||||
*
|
||||
* Compilers tested (all with 0 warnings at their highest respective
|
||||
* settings): Borland Turbo C 2.0, WATCOM C/C++ 11.0 (16 bits and 32
|
||||
* bits), Microsoft Visual C++ 6.0 (32 bit), Microsoft Visual Studio
|
||||
* .net (VC7), Intel C++ 4.0, GNU gcc v3.3.3
|
||||
*
|
||||
* This file should be considered a work in progress. Suggestions for
|
||||
* improvements, especially those which increase coverage are strongly
|
||||
* encouraged.
|
||||
*
|
||||
* Acknowledgements
|
||||
*
|
||||
* The following people have made significant contributions to the
|
||||
* development and testing of this file:
|
||||
*
|
||||
* Chris Howie
|
||||
* John Steele Scott
|
||||
* Dave Thorup
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
|
||||
/*
|
||||
* For gcc with _STDINT_H, fill in the PRINTF_INT*_MODIFIER macros, and
|
||||
* do nothing else. On the Mac OS X version of gcc this is _STDINT_H_.
|
||||
*/
|
||||
|
||||
#if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined (__WATCOMC__) && (defined (_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_)) )) && !defined (_PSTDINT_H_INCLUDED)
|
||||
#include <stdint.h>
|
||||
#define _PSTDINT_H_INCLUDED
|
||||
# ifndef PRINTF_INT64_MODIFIER
|
||||
# define PRINTF_INT64_MODIFIER "ll"
|
||||
# endif
|
||||
# ifndef PRINTF_INT32_MODIFIER
|
||||
# define PRINTF_INT32_MODIFIER "l"
|
||||
# endif
|
||||
# ifndef PRINTF_INT16_MODIFIER
|
||||
# define PRINTF_INT16_MODIFIER "h"
|
||||
# endif
|
||||
# ifndef PRINTF_INTMAX_MODIFIER
|
||||
# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
|
||||
# endif
|
||||
# ifndef PRINTF_INT64_HEX_WIDTH
|
||||
# define PRINTF_INT64_HEX_WIDTH "16"
|
||||
# endif
|
||||
# ifndef PRINTF_INT32_HEX_WIDTH
|
||||
# define PRINTF_INT32_HEX_WIDTH "8"
|
||||
# endif
|
||||
# ifndef PRINTF_INT16_HEX_WIDTH
|
||||
# define PRINTF_INT16_HEX_WIDTH "4"
|
||||
# endif
|
||||
# ifndef PRINTF_INT8_HEX_WIDTH
|
||||
# define PRINTF_INT8_HEX_WIDTH "2"
|
||||
# endif
|
||||
# ifndef PRINTF_INT64_DEC_WIDTH
|
||||
# define PRINTF_INT64_DEC_WIDTH "20"
|
||||
# endif
|
||||
# ifndef PRINTF_INT32_DEC_WIDTH
|
||||
# define PRINTF_INT32_DEC_WIDTH "10"
|
||||
# endif
|
||||
# ifndef PRINTF_INT16_DEC_WIDTH
|
||||
# define PRINTF_INT16_DEC_WIDTH "5"
|
||||
# endif
|
||||
# ifndef PRINTF_INT8_DEC_WIDTH
|
||||
# define PRINTF_INT8_DEC_WIDTH "3"
|
||||
# endif
|
||||
# ifndef PRINTF_INTMAX_HEX_WIDTH
|
||||
# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
|
||||
# endif
|
||||
# ifndef PRINTF_INTMAX_DEC_WIDTH
|
||||
# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
|
||||
# endif
|
||||
|
||||
/*
|
||||
* Something really weird is going on with Open Watcom. Just pull some of
|
||||
* these duplicated definitions from Open Watcom's stdint.h file for now.
|
||||
*/
|
||||
|
||||
# if defined (__WATCOMC__) && __WATCOMC__ >= 1250
|
||||
# if !defined (INT64_C)
|
||||
# define INT64_C(x) (x + (INT64_MAX - INT64_MAX))
|
||||
# endif
|
||||
# if !defined (UINT64_C)
|
||||
# define UINT64_C(x) (x + (UINT64_MAX - UINT64_MAX))
|
||||
# endif
|
||||
# if !defined (INT32_C)
|
||||
# define INT32_C(x) (x + (INT32_MAX - INT32_MAX))
|
||||
# endif
|
||||
# if !defined (UINT32_C)
|
||||
# define UINT32_C(x) (x + (UINT32_MAX - UINT32_MAX))
|
||||
# endif
|
||||
# if !defined (INT16_C)
|
||||
# define INT16_C(x) (x)
|
||||
# endif
|
||||
# if !defined (UINT16_C)
|
||||
# define UINT16_C(x) (x)
|
||||
# endif
|
||||
# if !defined (INT8_C)
|
||||
# define INT8_C(x) (x)
|
||||
# endif
|
||||
# if !defined (UINT8_C)
|
||||
# define UINT8_C(x) (x)
|
||||
# endif
|
||||
# if !defined (UINT64_MAX)
|
||||
# define UINT64_MAX 18446744073709551615ULL
|
||||
# endif
|
||||
# if !defined (INT64_MAX)
|
||||
# define INT64_MAX 9223372036854775807LL
|
||||
# endif
|
||||
# if !defined (UINT32_MAX)
|
||||
# define UINT32_MAX 4294967295UL
|
||||
# endif
|
||||
# if !defined (INT32_MAX)
|
||||
# define INT32_MAX 2147483647L
|
||||
# endif
|
||||
# if !defined (INTMAX_MAX)
|
||||
# define INTMAX_MAX INT64_MAX
|
||||
# endif
|
||||
# if !defined (INTMAX_MIN)
|
||||
# define INTMAX_MIN INT64_MIN
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef _PSTDINT_H_INCLUDED
|
||||
#define _PSTDINT_H_INCLUDED
|
||||
|
||||
#ifndef SIZE_MAX
|
||||
# define SIZE_MAX (~(size_t)0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Deduce the type assignments from limits.h under the assumption that
|
||||
* integer sizes in bits are powers of 2, and follow the ANSI
|
||||
* definitions.
|
||||
*/
|
||||
|
||||
#ifndef UINT8_MAX
|
||||
# define UINT8_MAX 0xff
|
||||
#endif
|
||||
#ifndef uint8_t
|
||||
# if (UCHAR_MAX == UINT8_MAX) || defined (S_SPLINT_S)
|
||||
typedef unsigned char uint8_t;
|
||||
# define UINT8_C(v) ((uint8_t) v)
|
||||
# else
|
||||
# error "Platform not supported"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef INT8_MAX
|
||||
# define INT8_MAX 0x7f
|
||||
#endif
|
||||
#ifndef INT8_MIN
|
||||
# define INT8_MIN INT8_C(0x80)
|
||||
#endif
|
||||
#ifndef int8_t
|
||||
# if (SCHAR_MAX == INT8_MAX) || defined (S_SPLINT_S)
|
||||
typedef signed char int8_t;
|
||||
# define INT8_C(v) ((int8_t) v)
|
||||
# else
|
||||
# error "Platform not supported"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef UINT16_MAX
|
||||
# define UINT16_MAX 0xffff
|
||||
#endif
|
||||
#ifndef uint16_t
|
||||
#if (UINT_MAX == UINT16_MAX) || defined (S_SPLINT_S)
|
||||
typedef unsigned int uint16_t;
|
||||
# ifndef PRINTF_INT16_MODIFIER
|
||||
# define PRINTF_INT16_MODIFIER ""
|
||||
# endif
|
||||
# define UINT16_C(v) ((uint16_t) (v))
|
||||
#elif (USHRT_MAX == UINT16_MAX)
|
||||
typedef unsigned short uint16_t;
|
||||
# define UINT16_C(v) ((uint16_t) (v))
|
||||
# ifndef PRINTF_INT16_MODIFIER
|
||||
# define PRINTF_INT16_MODIFIER "h"
|
||||
# endif
|
||||
#else
|
||||
#error "Platform not supported"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef INT16_MAX
|
||||
# define INT16_MAX 0x7fff
|
||||
#endif
|
||||
#ifndef INT16_MIN
|
||||
# define INT16_MIN INT16_C(0x8000)
|
||||
#endif
|
||||
#ifndef int16_t
|
||||
#if (INT_MAX == INT16_MAX) || defined (S_SPLINT_S)
|
||||
typedef signed int int16_t;
|
||||
# define INT16_C(v) ((int16_t) (v))
|
||||
# ifndef PRINTF_INT16_MODIFIER
|
||||
# define PRINTF_INT16_MODIFIER ""
|
||||
# endif
|
||||
#elif (SHRT_MAX == INT16_MAX)
|
||||
typedef signed short int16_t;
|
||||
# define INT16_C(v) ((int16_t) (v))
|
||||
# ifndef PRINTF_INT16_MODIFIER
|
||||
# define PRINTF_INT16_MODIFIER "h"
|
||||
# endif
|
||||
#else
|
||||
#error "Platform not supported"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef UINT32_MAX
|
||||
# define UINT32_MAX (0xffffffffUL)
|
||||
#endif
|
||||
#ifndef uint32_t
|
||||
#if (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S)
|
||||
typedef unsigned long uint32_t;
|
||||
# define UINT32_C(v) v ## UL
|
||||
# ifndef PRINTF_INT32_MODIFIER
|
||||
# define PRINTF_INT32_MODIFIER "l"
|
||||
# endif
|
||||
#elif (UINT_MAX == UINT32_MAX)
|
||||
typedef unsigned int uint32_t;
|
||||
# ifndef PRINTF_INT32_MODIFIER
|
||||
# define PRINTF_INT32_MODIFIER ""
|
||||
# endif
|
||||
# define UINT32_C(v) v ## U
|
||||
#elif (USHRT_MAX == UINT32_MAX)
|
||||
typedef unsigned short uint32_t;
|
||||
# define UINT32_C(v) ((unsigned short) (v))
|
||||
# ifndef PRINTF_INT32_MODIFIER
|
||||
# define PRINTF_INT32_MODIFIER ""
|
||||
# endif
|
||||
#else
|
||||
#error "Platform not supported"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef INT32_MAX
|
||||
# define INT32_MAX (0x7fffffffL)
|
||||
#endif
|
||||
#ifndef INT32_MIN
|
||||
# define INT32_MIN INT32_C(0x80000000)
|
||||
#endif
|
||||
#ifndef int32_t
|
||||
#if (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S)
|
||||
typedef signed long int32_t;
|
||||
# define INT32_C(v) v ## L
|
||||
# ifndef PRINTF_INT32_MODIFIER
|
||||
# define PRINTF_INT32_MODIFIER "l"
|
||||
# endif
|
||||
#elif (INT_MAX == INT32_MAX)
|
||||
typedef signed int int32_t;
|
||||
# define INT32_C(v) v
|
||||
# ifndef PRINTF_INT32_MODIFIER
|
||||
# define PRINTF_INT32_MODIFIER ""
|
||||
# endif
|
||||
#elif (SHRT_MAX == INT32_MAX)
|
||||
typedef signed short int32_t;
|
||||
# define INT32_C(v) ((short) (v))
|
||||
# ifndef PRINTF_INT32_MODIFIER
|
||||
# define PRINTF_INT32_MODIFIER ""
|
||||
# endif
|
||||
#else
|
||||
#error "Platform not supported"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The macro stdint_int64_defined is temporarily used to record
|
||||
* whether or not 64 integer support is available. It must be
|
||||
* defined for any 64 integer extensions for new platforms that are
|
||||
* added.
|
||||
*/
|
||||
|
||||
#undef stdint_int64_defined
|
||||
#if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined (S_SPLINT_S)
|
||||
# if (__STDC__ && __STDC_VERSION >= 199901L) || defined (S_SPLINT_S)
|
||||
# define stdint_int64_defined
|
||||
typedef long long int64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
# define UINT64_C(v) v ## ULL
|
||||
# define INT64_C(v) v ## LL
|
||||
# ifndef PRINTF_INT64_MODIFIER
|
||||
# define PRINTF_INT64_MODIFIER "ll"
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined (stdint_int64_defined)
|
||||
# if defined(__GNUC__)
|
||||
# define stdint_int64_defined
|
||||
__extension__ typedef long long int64_t;
|
||||
__extension__ typedef unsigned long long uint64_t;
|
||||
# define UINT64_C(v) v ## ULL
|
||||
# define INT64_C(v) v ## LL
|
||||
# ifndef PRINTF_INT64_MODIFIER
|
||||
# define PRINTF_INT64_MODIFIER "ll"
|
||||
# endif
|
||||
# elif defined(__MWERKS__) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || defined (__APPLE_CC__) || defined (_LONG_LONG) || defined (_CRAYC) || defined (S_SPLINT_S)
|
||||
# define stdint_int64_defined
|
||||
typedef long long int64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
# define UINT64_C(v) v ## ULL
|
||||
# define INT64_C(v) v ## LL
|
||||
# ifndef PRINTF_INT64_MODIFIER
|
||||
# define PRINTF_INT64_MODIFIER "ll"
|
||||
# endif
|
||||
# elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined (__BORLANDC__) && __BORLANDC__ > 0x460) || defined (__alpha) || defined (__DECC)
|
||||
# define stdint_int64_defined
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
# define UINT64_C(v) v ## UI64
|
||||
# define INT64_C(v) v ## I64
|
||||
# ifndef PRINTF_INT64_MODIFIER
|
||||
# define PRINTF_INT64_MODIFIER "I64"
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined (LONG_LONG_MAX) && defined (INT64_C)
|
||||
# define LONG_LONG_MAX INT64_C (9223372036854775807)
|
||||
#endif
|
||||
#ifndef ULONG_LONG_MAX
|
||||
# define ULONG_LONG_MAX UINT64_C (18446744073709551615)
|
||||
#endif
|
||||
|
||||
#if !defined (INT64_MAX) && defined (INT64_C)
|
||||
# define INT64_MAX INT64_C (9223372036854775807)
|
||||
#endif
|
||||
#if !defined (INT64_MIN) && defined (INT64_C)
|
||||
# define INT64_MIN INT64_C (-9223372036854775808)
|
||||
#endif
|
||||
#if !defined (UINT64_MAX) && defined (INT64_C)
|
||||
# define UINT64_MAX UINT64_C (18446744073709551615)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Width of hexadecimal for number field.
|
||||
*/
|
||||
|
||||
#ifndef PRINTF_INT64_HEX_WIDTH
|
||||
# define PRINTF_INT64_HEX_WIDTH "16"
|
||||
#endif
|
||||
#ifndef PRINTF_INT32_HEX_WIDTH
|
||||
# define PRINTF_INT32_HEX_WIDTH "8"
|
||||
#endif
|
||||
#ifndef PRINTF_INT16_HEX_WIDTH
|
||||
# define PRINTF_INT16_HEX_WIDTH "4"
|
||||
#endif
|
||||
#ifndef PRINTF_INT8_HEX_WIDTH
|
||||
# define PRINTF_INT8_HEX_WIDTH "2"
|
||||
#endif
|
||||
|
||||
#ifndef PRINTF_INT64_DEC_WIDTH
|
||||
# define PRINTF_INT64_DEC_WIDTH "20"
|
||||
#endif
|
||||
#ifndef PRINTF_INT32_DEC_WIDTH
|
||||
# define PRINTF_INT32_DEC_WIDTH "10"
|
||||
#endif
|
||||
#ifndef PRINTF_INT16_DEC_WIDTH
|
||||
# define PRINTF_INT16_DEC_WIDTH "5"
|
||||
#endif
|
||||
#ifndef PRINTF_INT8_DEC_WIDTH
|
||||
# define PRINTF_INT8_DEC_WIDTH "3"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Ok, lets not worry about 128 bit integers for now. Moore's law says
|
||||
* we don't need to worry about that until about 2040 at which point
|
||||
* we'll have bigger things to worry about.
|
||||
*/
|
||||
|
||||
#ifdef stdint_int64_defined
|
||||
typedef int64_t intmax_t;
|
||||
typedef uint64_t uintmax_t;
|
||||
# define INTMAX_MAX INT64_MAX
|
||||
# define INTMAX_MIN INT64_MIN
|
||||
# define UINTMAX_MAX UINT64_MAX
|
||||
# define UINTMAX_C(v) UINT64_C(v)
|
||||
# define INTMAX_C(v) INT64_C(v)
|
||||
# ifndef PRINTF_INTMAX_MODIFIER
|
||||
# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
|
||||
# endif
|
||||
# ifndef PRINTF_INTMAX_HEX_WIDTH
|
||||
# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
|
||||
# endif
|
||||
# ifndef PRINTF_INTMAX_DEC_WIDTH
|
||||
# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
|
||||
# endif
|
||||
#else
|
||||
typedef int32_t intmax_t;
|
||||
typedef uint32_t uintmax_t;
|
||||
# define INTMAX_MAX INT32_MAX
|
||||
# define UINTMAX_MAX UINT32_MAX
|
||||
# define UINTMAX_C(v) UINT32_C(v)
|
||||
# define INTMAX_C(v) INT32_C(v)
|
||||
# ifndef PRINTF_INTMAX_MODIFIER
|
||||
# define PRINTF_INTMAX_MODIFIER PRINTF_INT32_MODIFIER
|
||||
# endif
|
||||
# ifndef PRINTF_INTMAX_HEX_WIDTH
|
||||
# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT32_HEX_WIDTH
|
||||
# endif
|
||||
# ifndef PRINTF_INTMAX_DEC_WIDTH
|
||||
# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT32_DEC_WIDTH
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Because this file currently only supports platforms which have
|
||||
* precise powers of 2 as bit sizes for the default integers, the
|
||||
* least definitions are all trivial. Its possible that a future
|
||||
* version of this file could have different definitions.
|
||||
*/
|
||||
|
||||
#ifndef stdint_least_defined
|
||||
typedef int8_t int_least8_t;
|
||||
typedef uint8_t uint_least8_t;
|
||||
typedef int16_t int_least16_t;
|
||||
typedef uint16_t uint_least16_t;
|
||||
typedef int32_t int_least32_t;
|
||||
typedef uint32_t uint_least32_t;
|
||||
# define PRINTF_LEAST32_MODIFIER PRINTF_INT32_MODIFIER
|
||||
# define PRINTF_LEAST16_MODIFIER PRINTF_INT16_MODIFIER
|
||||
# define UINT_LEAST8_MAX UINT8_MAX
|
||||
# define INT_LEAST8_MAX INT8_MAX
|
||||
# define UINT_LEAST16_MAX UINT16_MAX
|
||||
# define INT_LEAST16_MAX INT16_MAX
|
||||
# define UINT_LEAST32_MAX UINT32_MAX
|
||||
# define INT_LEAST32_MAX INT32_MAX
|
||||
# define INT_LEAST8_MIN INT8_MIN
|
||||
# define INT_LEAST16_MIN INT16_MIN
|
||||
# define INT_LEAST32_MIN INT32_MIN
|
||||
# ifdef stdint_int64_defined
|
||||
typedef int64_t int_least64_t;
|
||||
typedef uint64_t uint_least64_t;
|
||||
# define PRINTF_LEAST64_MODIFIER PRINTF_INT64_MODIFIER
|
||||
# define UINT_LEAST64_MAX UINT64_MAX
|
||||
# define INT_LEAST64_MAX INT64_MAX
|
||||
# define INT_LEAST64_MIN INT64_MIN
|
||||
# endif
|
||||
#endif
|
||||
#undef stdint_least_defined
|
||||
|
||||
/*
|
||||
* The ANSI C committee pretending to know or specify anything about
|
||||
* performance is the epitome of misguided arrogance. The mandate of
|
||||
* this file is to *ONLY* ever support that absolute minimum
|
||||
* definition of the fast integer types, for compatibility purposes.
|
||||
* No extensions, and no attempt to suggest what may or may not be a
|
||||
* faster integer type will ever be made in this file. Developers are
|
||||
* warned to stay away from these types when using this or any other
|
||||
* stdint.h.
|
||||
*/
|
||||
|
||||
typedef int_least8_t int_fast8_t;
|
||||
typedef uint_least8_t uint_fast8_t;
|
||||
typedef int_least16_t int_fast16_t;
|
||||
typedef uint_least16_t uint_fast16_t;
|
||||
typedef int_least32_t int_fast32_t;
|
||||
typedef uint_least32_t uint_fast32_t;
|
||||
#define UINT_FAST8_MAX UINT_LEAST8_MAX
|
||||
#define INT_FAST8_MAX INT_LEAST8_MAX
|
||||
#define UINT_FAST16_MAX UINT_LEAST16_MAX
|
||||
#define INT_FAST16_MAX INT_LEAST16_MAX
|
||||
#define UINT_FAST32_MAX UINT_LEAST32_MAX
|
||||
#define INT_FAST32_MAX INT_LEAST32_MAX
|
||||
#define INT_FAST8_MIN INT_LEAST8_MIN
|
||||
#define INT_FAST16_MIN INT_LEAST16_MIN
|
||||
#define INT_FAST32_MIN INT_LEAST32_MIN
|
||||
#ifdef stdint_int64_defined
|
||||
typedef int_least64_t int_fast64_t;
|
||||
typedef uint_least64_t uint_fast64_t;
|
||||
# define UINT_FAST64_MAX UINT_LEAST64_MAX
|
||||
# define INT_FAST64_MAX INT_LEAST64_MAX
|
||||
# define INT_FAST64_MIN INT_LEAST64_MIN
|
||||
#endif
|
||||
|
||||
#undef stdint_int64_defined
|
||||
|
||||
/*
|
||||
* Whatever piecemeal, per compiler thing we can do about the wchar_t
|
||||
* type limits.
|
||||
*/
|
||||
|
||||
#if defined(__WATCOMC__) || defined(_MSC_VER) || defined (__GNUC__)
|
||||
# include <wchar.h>
|
||||
# ifndef WCHAR_MIN
|
||||
# define WCHAR_MIN 0
|
||||
# endif
|
||||
# ifndef WCHAR_MAX
|
||||
# define WCHAR_MAX ((wchar_t)-1)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Whatever piecemeal, per compiler/platform thing we can do about the
|
||||
* (u)intptr_t types and limits.
|
||||
*/
|
||||
|
||||
#if defined (_MSC_VER) && defined (_UINTPTR_T_DEFINED)
|
||||
# define STDINT_H_UINTPTR_T_DEFINED
|
||||
#endif
|
||||
|
||||
#ifndef STDINT_H_UINTPTR_T_DEFINED
|
||||
# if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) || defined (_WIN64)
|
||||
# define stdint_intptr_bits 64
|
||||
# elif defined (__WATCOMC__) || defined (__TURBOC__)
|
||||
# if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
|
||||
# define stdint_intptr_bits 16
|
||||
# else
|
||||
# define stdint_intptr_bits 32
|
||||
# endif
|
||||
# elif defined (__i386__) || defined (_WIN32) || defined (WIN32)
|
||||
# define stdint_intptr_bits 32
|
||||
# elif defined (__INTEL_COMPILER)
|
||||
/* TODO -- what will Intel do about x86-64? */
|
||||
# endif
|
||||
|
||||
# ifdef stdint_intptr_bits
|
||||
# define stdint_intptr_glue3_i(a,b,c) a##b##c
|
||||
# define stdint_intptr_glue3(a,b,c) stdint_intptr_glue3_i(a,b,c)
|
||||
# ifndef PRINTF_INTPTR_MODIFIER
|
||||
# define PRINTF_INTPTR_MODIFIER stdint_intptr_glue3(PRINTF_INT,stdint_intptr_bits,_MODIFIER)
|
||||
# endif
|
||||
# ifndef PTRDIFF_MAX
|
||||
# define PTRDIFF_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
|
||||
# endif
|
||||
# ifndef PTRDIFF_MIN
|
||||
# define PTRDIFF_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
|
||||
# endif
|
||||
# ifndef UINTPTR_MAX
|
||||
# define UINTPTR_MAX stdint_intptr_glue3(UINT,stdint_intptr_bits,_MAX)
|
||||
# endif
|
||||
# ifndef INTPTR_MAX
|
||||
# define INTPTR_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
|
||||
# endif
|
||||
# ifndef INTPTR_MIN
|
||||
# define INTPTR_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
|
||||
# endif
|
||||
# ifndef INTPTR_C
|
||||
# define INTPTR_C(x) stdint_intptr_glue3(INT,stdint_intptr_bits,_C)(x)
|
||||
# endif
|
||||
# ifndef UINTPTR_C
|
||||
# define UINTPTR_C(x) stdint_intptr_glue3(UINT,stdint_intptr_bits,_C)(x)
|
||||
# endif
|
||||
typedef stdint_intptr_glue3(uint,stdint_intptr_bits,_t) uintptr_t;
|
||||
typedef stdint_intptr_glue3( int,stdint_intptr_bits,_t) intptr_t;
|
||||
# else
|
||||
/* TODO -- This following is likely wrong for some platforms, and does
|
||||
nothing for the definition of uintptr_t. */
|
||||
typedef ptrdiff_t intptr_t;
|
||||
# endif
|
||||
# define STDINT_H_UINTPTR_T_DEFINED
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Assumes sig_atomic_t is signed and we have a 2s complement machine.
|
||||
*/
|
||||
|
||||
#ifndef SIG_ATOMIC_MAX
|
||||
# define SIG_ATOMIC_MAX ((((sig_atomic_t) 1) << (sizeof (sig_atomic_t)*CHAR_BIT-1)) - 1)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined (__TEST_PSTDINT_FOR_CORRECTNESS)
|
||||
|
||||
/*
|
||||
* Please compile with the maximum warning settings to make sure macros are not
|
||||
* defined more than once.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define glue3_aux(x,y,z) x ## y ## z
|
||||
#define glue3(x,y,z) glue3_aux(x,y,z)
|
||||
|
||||
#define DECLU(bits) glue3(uint,bits,_t) glue3(u,bits,=) glue3(UINT,bits,_C) (0);
|
||||
#define DECLI(bits) glue3(int,bits,_t) glue3(i,bits,=) glue3(INT,bits,_C) (0);
|
||||
|
||||
#define DECL(us,bits) glue3(DECL,us,) (bits)
|
||||
|
||||
#define TESTUMAX(bits) glue3(u,bits,=) glue3(~,u,bits); if (glue3(UINT,bits,_MAX) glue3(!=,u,bits)) printf ("Something wrong with UINT%d_MAX\n", bits)
|
||||
|
||||
int main () {
|
||||
DECL(I,8)
|
||||
DECL(U,8)
|
||||
DECL(I,16)
|
||||
DECL(U,16)
|
||||
DECL(I,32)
|
||||
DECL(U,32)
|
||||
#ifdef INT64_MAX
|
||||
DECL(I,64)
|
||||
DECL(U,64)
|
||||
#endif
|
||||
intmax_t imax = INTMAX_C(0);
|
||||
uintmax_t umax = UINTMAX_C(0);
|
||||
char str0[256], str1[256];
|
||||
|
||||
sprintf (str0, "%d %x\n", 0, ~0);
|
||||
|
||||
sprintf (str1, "%d %x\n", i8, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with i8 : %s\n", str1);
|
||||
sprintf (str1, "%u %x\n", u8, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with u8 : %s\n", str1);
|
||||
sprintf (str1, "%d %x\n", i16, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with i16 : %s\n", str1);
|
||||
sprintf (str1, "%u %x\n", u16, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with u16 : %s\n", str1);
|
||||
sprintf (str1, "%" PRINTF_INT32_MODIFIER "d %x\n", i32, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with i32 : %s\n", str1);
|
||||
sprintf (str1, "%" PRINTF_INT32_MODIFIER "u %x\n", u32, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with u32 : %s\n", str1);
|
||||
#ifdef INT64_MAX
|
||||
sprintf (str1, "%" PRINTF_INT64_MODIFIER "d %x\n", i64, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with i64 : %s\n", str1);
|
||||
#endif
|
||||
sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "d %x\n", imax, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with imax : %s\n", str1);
|
||||
sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "u %x\n", umax, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with umax : %s\n", str1);
|
||||
|
||||
TESTUMAX(8);
|
||||
TESTUMAX(16);
|
||||
TESTUMAX(32);
|
||||
#ifdef INT64_MAX
|
||||
TESTUMAX(64);
|
||||
#endif
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
#endif
|
223
utils/MTP/beastpatcher/vs2005/beastpatcher.vcproj
Normal file
223
utils/MTP/beastpatcher/vs2005/beastpatcher.vcproj
Normal file
|
@ -0,0 +1,223 @@
|
|||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="beastpatcher"
|
||||
ProjectGUID="{AF17AD8F-DE5E-4A2D-ABF9-721736F6FA72}"
|
||||
RootNamespace="beastpatcher"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
CommandLine=""
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="0"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="..\MTP_DLL.lib"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
CommandLine=""
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""$(InputDir)\..""
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="..\MTP_DLL.lib"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\beastpatcher.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\bootimg.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\mtp_win32.c"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\bootimg.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\mtp_common.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\pstdint.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
|
@ -19,7 +19,6 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define LPWSTR wchar_t*
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -27,8 +26,9 @@
|
|||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
#include <stdbool.h>
|
||||
#include <windows.h>
|
||||
|
||||
extern __declspec(dllimport) bool send_fw(LPWSTR file, int filesize, void (*callback)(unsigned int progress, unsigned int max));
|
||||
#include "MTP_DLL/MTP_DLL.h"
|
||||
|
||||
void usage(void)
|
||||
{
|
||||
|
@ -76,7 +76,7 @@ int main(int argc, char **argv)
|
|||
|
||||
fprintf(stdout, "Sending firmware...\n");
|
||||
|
||||
if(send_fw(tmp, filesize(argv[1]), &callback))
|
||||
if(mtp_sendnk(tmp, filesize(argv[1]), &callback))
|
||||
fprintf(stdout, "Firmware sent successfully!\n");
|
||||
else
|
||||
fprintf(stdout, "Error occured during sending!\n");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue