summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2009-06-08 18:04:10 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2009-06-08 18:04:10 +0000
commiteebde2a3676f7dd11011fabd7c4d74f0cb6532d5 (patch)
treec8568e4f398f5a1e2fcfc1c937dbbbc18d0f1aeb
parent5575f425d64b555ad2399ef6e4ae3d1efcb6627d (diff)
downloadrockbox-eebde2a3676f7dd11011fabd7c4d74f0cb6532d5.tar.gz
rockbox-eebde2a3676f7dd11011fabd7c4d74f0cb6532d5.zip
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
-rwxr-xr-xutils/MTP/MTP_DLL.dllbin90112 -> 90112 bytes
-rw-r--r--utils/MTP/MTP_DLL/MTP_DLL.h13
-rw-r--r--utils/MTP/MTP_DLL/MTP_DLL.vcproj29
-rw-r--r--utils/MTP/MTP_DLL/mtp_wrapper.cpp284
-rw-r--r--utils/MTP/MTP_DLL/progresshelper.cpp104
-rw-r--r--utils/MTP/MTP_DLL/progresshelper.h52
-rw-r--r--utils/MTP/MTP_DLL/sendfirm_win.cpp260
-rw-r--r--utils/MTP/beastpatcher/README.pstdint7
-rw-r--r--utils/MTP/beastpatcher/beastpatcher.c16
-rw-r--r--utils/MTP/beastpatcher/mtp_common.h4
-rw-r--r--utils/MTP/beastpatcher/mtp_win32.c27
-rw-r--r--utils/MTP/beastpatcher/pstdint.h799
-rw-r--r--utils/MTP/beastpatcher/vs2005/beastpatcher.vcproj223
-rw-r--r--utils/MTP/sendfirm_win.c6
14 files changed, 1524 insertions, 300 deletions
diff --git a/utils/MTP/MTP_DLL.dll b/utils/MTP/MTP_DLL.dll
index 448dff430a..e39c4db754 100755
--- a/utils/MTP/MTP_DLL.dll
+++ b/utils/MTP/MTP_DLL.dll
Binary files differ
diff --git a/utils/MTP/MTP_DLL/MTP_DLL.h b/utils/MTP/MTP_DLL/MTP_DLL.h
index eeee72a87b..2793c936e1 100644
--- a/utils/MTP/MTP_DLL/MTP_DLL.h
+++ b/utils/MTP/MTP_DLL/MTP_DLL.h
@@ -1,10 +1,21 @@
1
2#ifndef MTP_DLL_H
3#define MTP_DLL_H
4
1#ifdef MTP_DLL_EXPORTS 5#ifdef MTP_DLL_EXPORTS
2#define MTP_DLL_API __declspec(dllexport) 6#define MTP_DLL_API __declspec(dllexport)
3#else 7#else
4#define MTP_DLL_API __declspec(dllimport) 8#define MTP_DLL_API __declspec(dllimport)
5#endif 9#endif
6 10
11#ifdef __cplusplus
7extern "C" 12extern "C"
8{ 13{
9 __declspec(dllexport) bool send_fw(LPWSTR file, int filesize, void (*callback)(unsigned int progress, unsigned int max)); 14#endif
15MTP_DLL_API int mtp_sendnk(LPWSTR file, int filesize, void (*callback)(unsigned int progress, unsigned int max));
16MTP_DLL_API int mtp_description(wchar_t* name, wchar_t* manufacturer, DWORD* version);
17#ifdef __cplusplus
10} 18}
19#endif
20
21#endif
diff --git a/utils/MTP/MTP_DLL/MTP_DLL.vcproj b/utils/MTP/MTP_DLL/MTP_DLL.vcproj
index 3d7fa43475..644e2e445e 100644
--- a/utils/MTP/MTP_DLL/MTP_DLL.vcproj
+++ b/utils/MTP/MTP_DLL/MTP_DLL.vcproj
@@ -1,7 +1,7 @@
1<?xml version="1.0" encoding="Windows-1252"?> 1<?xml version="1.0" encoding="Windows-1252"?>
2<VisualStudioProject 2<VisualStudioProject
3 ProjectType="Visual C++" 3 ProjectType="Visual C++"
4 Version="8,00" 4 Version="8.00"
5 Name="MTP_DLL" 5 Name="MTP_DLL"
6 ProjectGUID="{C7A39A2D-2ADF-40A3-A9A5-0DF4509B761B}" 6 ProjectGUID="{C7A39A2D-2ADF-40A3-A9A5-0DF4509B761B}"
7 RootNamespace="MTP_DLL" 7 RootNamespace="MTP_DLL"
@@ -170,6 +170,7 @@
170 /> 170 />
171 <Tool 171 <Tool
172 Name="VCPostBuildEventTool" 172 Name="VCPostBuildEventTool"
173 CommandLine="echo Copying $(TargetName) dll / lib to ..&#x0D;&#x0A;copy /Y &quot;$(InputDir)$(ConfigurationName)\$(TargetFileName)&quot; &quot;$(InputDir)..\&quot;&#x0D;&#x0A;copy /Y &quot;$(InputDir)$(ConfigurationName)\$(TargetName).lib&quot; &quot;$(InputDir)..\&quot;"
173 /> 174 />
174 </Configuration> 175 </Configuration>
175 </Configurations> 176 </Configurations>
@@ -186,24 +187,12 @@
186 > 187 >
187 </File> 188 </File>
188 <File 189 <File
189 RelativePath=".\sendfirm_win.cpp" 190 RelativePath=".\mtp_wrapper.cpp"
191 >
192 </File>
193 <File
194 RelativePath=".\progresshelper.cpp"
190 > 195 >
191 <FileConfiguration
192 Name="Debug|Win32"
193 >
194 <Tool
195 Name="VCCLCompilerTool"
196 UsePrecompiledHeader="0"
197 />
198 </FileConfiguration>
199 <FileConfiguration
200 Name="Release|Win32"
201 >
202 <Tool
203 Name="VCCLCompilerTool"
204 UsePrecompiledHeader="0"
205 />
206 </FileConfiguration>
207 </File> 196 </File>
208 <File 197 <File
209 RelativePath=".\stdafx.cpp" 198 RelativePath=".\stdafx.cpp"
@@ -236,6 +225,10 @@
236 > 225 >
237 </File> 226 </File>
238 <File 227 <File
228 RelativePath=".\progresshelper.h"
229 >
230 </File>
231 <File
239 RelativePath=".\stdafx.h" 232 RelativePath=".\stdafx.h"
240 > 233 >
241 </File> 234 </File>
diff --git a/utils/MTP/MTP_DLL/mtp_wrapper.cpp b/utils/MTP/MTP_DLL/mtp_wrapper.cpp
new file mode 100644
index 0000000000..f444a59631
--- /dev/null
+++ b/utils/MTP/MTP_DLL/mtp_wrapper.cpp
@@ -0,0 +1,284 @@
1/*
2 * Windows MTP Firmware Uploading Implementation
3 *
4 * Based on http://opensource.creative.com/mtp_xfer.html
5 * Edited by Maurus Cuelenaere for Rockbox
6 *
7 * Copyright (c) 2009, Maurus Cuelenaere
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * * Neither the name of the <organization> nor the
18 * names of its contributors may be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY MAURUS CUELENAERE ''AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL MAURUS CUELENAERE BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33
34#include "stdafx.h"
35
36#include <windows.h>
37#include "mswmdm_i.c"
38#include "mswmdm.h"
39#include "sac.h"
40#include "scclient.h"
41
42#include "progresshelper.h"
43#include "MTP_DLL.h"
44
45/*
46 * Compilation requirements:
47 *
48 * Download the Windows Media Format 9.5 SDK
49 * Add "c:\wmsdk\wmfsdk95\include,c:\wmsdk\wmfsdk95\wmdm\inc" to your inclusion path
50 * Add "c:\wmsdk\wmfsdk95\lib,c:\wmsdk\wmfsdk95\wmdm\lib" to your library inclusion path
51 * Link to "mssachlp.lib"
52 *
53 */
54
55struct mtp_if {
56 IComponentAuthenticate* pICompAuth;
57 CSecureChannelClient *pSacClient;
58 IWMDeviceManager3* pIdvMgr;
59 bool initialized;
60};
61
62
63extern "C" {
64static int mtp_init(struct mtp_if* mtp)
65{
66 HRESULT hr;
67 mtp->pSacClient = new CSecureChannelClient;
68 mtp->pIdvMgr = NULL;
69 mtp->initialized = false;
70
71 /* these are generic keys */
72 BYTE abPVK[] = {0x00};
73 BYTE abCert[] = {0x00};
74
75 CoInitialize(NULL);
76
77 /* get an authentication interface */
78 hr = CoCreateInstance(CLSID_MediaDevMgr, NULL, CLSCTX_ALL,
79 IID_IComponentAuthenticate, (void **)&mtp->pICompAuth);
80 if SUCCEEDED(hr)
81 {
82 /* create a secure channel client certificate */
83 hr = mtp->pSacClient->SetCertificate(SAC_CERT_V1, (BYTE*) abCert,
84 sizeof(abCert), (BYTE*) abPVK, sizeof(abPVK));
85 if SUCCEEDED(hr)
86 {
87 /* bind the authentication interface to the secure channel client */
88 mtp->pSacClient->SetInterface(mtp->pICompAuth);
89
90 /* trigger communication */
91 hr = mtp->pSacClient->Authenticate(SAC_PROTOCOL_V1);
92 if SUCCEEDED(hr)
93 {
94 /* get main interface to media device manager */
95 hr = mtp->pICompAuth->QueryInterface(IID_IWMDeviceManager2,
96 (void**)&mtp->pIdvMgr);
97 if SUCCEEDED(hr)
98 {
99 mtp->initialized = true;
100 }
101 }
102 }
103 }
104 else {
105 CoUninitialize();
106 }
107 return mtp->initialized;
108}
109
110
111static int mtp_close(struct mtp_if* mtp)
112{
113 if(mtp->initialized)
114 {
115 mtp->pIdvMgr->Release();
116 mtp->pICompAuth->Release();
117 CoUninitialize();
118 mtp->initialized = false;
119 }
120 return 0;
121}
122
123__declspec(dllexport) int mtp_description(wchar_t* name, wchar_t* manufacturer, DWORD* version)
124{
125 HRESULT hr;
126 int num = 0;
127 struct mtp_if mtp;
128 /* zero mtp structure */
129 memset(&mtp, 0, sizeof(struct mtp_if));
130
131 /* initialize interface */
132 mtp_init(&mtp);
133 if(mtp.initialized == false) {
134 return -1;
135 }
136
137 /* we now have a media device manager interface... */
138 /* enumerate devices... */
139 IWMDMEnumDevice *pIEnumDev;
140 wchar_t pwsString[256];
141 hr = mtp.pIdvMgr->EnumDevices2(&pIEnumDev);
142 if SUCCEEDED(hr) {
143 hr = pIEnumDev->Reset(); /* Next will now return the first device */
144 if SUCCEEDED(hr) {
145 IWMDMDevice3* pIDevice;
146 unsigned long ulNumFetched;
147 hr = pIEnumDev->Next(1, (IWMDMDevice **)&pIDevice, &ulNumFetched);
148 while (SUCCEEDED(hr) && (hr != S_FALSE)) {
149 /* output device name */
150 hr = pIDevice->GetName(pwsString, 256);
151 if SUCCEEDED(hr) {
152 wcsncpy_s(name, 256, pwsString, _TRUNCATE);
153 num++;
154 }
155 /* device manufacturer */
156 hr = pIDevice->GetManufacturer(pwsString, 256);
157 if SUCCEEDED(hr) {
158 wcsncpy_s(manufacturer, 256, pwsString, _TRUNCATE);
159 }
160 /* device version -- optional interface so might fail. */
161 DWORD ver;
162 hr = pIDevice->GetVersion(&ver);
163 if SUCCEEDED(hr) {
164 *version = ver;
165 }
166 else {
167 *version = 0;
168 }
169
170 /* move to next device */
171 hr = pIEnumDev->Next(1, (IWMDMDevice **)&pIDevice, &ulNumFetched);
172 }
173 pIEnumDev->Release();
174 }
175 mtp_close(&mtp);
176 }
177 return (num > 0) ? num : -1;
178}
179
180__declspec(dllexport) int mtp_sendnk(LPWSTR file, int filesize, void (*callback)(unsigned int progress, unsigned int max))
181{
182 HRESULT hr;
183 bool return_value = false;
184 struct mtp_if mtp;
185 /* zero mtp structure */
186 memset(&mtp, 0, sizeof(struct mtp_if));
187
188 /* initialize interface */
189 mtp_init(&mtp);
190 if(mtp.initialized == false) {
191 return false;
192 }
193 /* enumerate devices... */
194 IWMDMEnumDevice *pIEnumDev;
195 hr = mtp.pIdvMgr->EnumDevices2(&pIEnumDev);
196 if SUCCEEDED(hr)
197 {
198 hr = pIEnumDev->Reset(); /* Next will now return the first device */
199 if SUCCEEDED(hr)
200 {
201 IWMDMDevice3* pIDevice;
202 unsigned long ulNumFetched;
203 hr = pIEnumDev->Next(1, (IWMDMDevice **)&pIDevice, &ulNumFetched);
204 while (SUCCEEDED(hr) && (hr != S_FALSE))
205 {
206 /* get storage info */
207 DWORD tempDW;
208 pIDevice->GetType(&tempDW);
209 if (tempDW & WMDM_DEVICE_TYPE_STORAGE)
210 {
211 IWMDMEnumStorage *pIEnumStorage = NULL;
212 IWMDMStorage *pIStorage = NULL;
213 IWMDMStorage3 *pIFileStorage = NULL;
214 hr = pIDevice->EnumStorage(&pIEnumStorage);
215 if SUCCEEDED(hr)
216 {
217 pIEnumStorage->Reset();
218 hr = pIEnumStorage->Next(1, (IWMDMStorage **)&pIStorage, &ulNumFetched);
219 while (SUCCEEDED(hr) && (hr != S_FALSE))
220 {
221 IWMDMStorage3 *pNewStorage;
222 hr = pIStorage->QueryInterface(IID_IWMDMStorage3, (void **)&pNewStorage);
223 if SUCCEEDED(hr)
224 {
225 IWMDMStorageControl3 *pIWMDMStorageControl;
226 hr = pNewStorage->QueryInterface(IID_IWMDMStorageControl3,
227 (void**)&pIWMDMStorageControl);
228 if SUCCEEDED(hr)
229 {
230 IWMDMMetaData *pIWMDMMetaData = NULL;
231 hr = pNewStorage->CreateEmptyMetadataObject(&pIWMDMMetaData);
232 if (SUCCEEDED(hr))
233 {
234 DWORD dw = WMDM_FORMATCODE_UNDEFINEDFIRMWARE;
235 hr = pIWMDMMetaData->AddItem(WMDM_TYPE_DWORD, g_wszWMDMFormatCode, (BYTE *)&dw, sizeof(dw));
236 hr = pIWMDMMetaData->AddItem(WMDM_TYPE_STRING, g_wszWMDMFileName, (BYTE *)L"nk.bin", 32);
237 DWORD ow[2];
238 ow[0] = filesize;
239 ow[1] = 0;
240 hr = pIWMDMMetaData->AddItem(WMDM_TYPE_QWORD, g_wszWMDMFileSize, (BYTE *)ow, 2 * sizeof(dw));
241 if (SUCCEEDED(hr))
242 {
243 IWMDMStorage *pNewObject = NULL;
244 CProgressHelper *progress = new CProgressHelper(callback);
245
246 hr = pIWMDMStorageControl->Insert3(
247 WMDM_MODE_BLOCK | WMDM_CONTENT_FILE | WMDM_MODE_PROGRESS,
248 0,
249 file,
250 NULL,
251 NULL,
252 (callback == NULL ? NULL : (IWMDMProgress*)progress),
253 pIWMDMMetaData,
254 NULL,
255 (IWMDMStorage **)&pNewObject);
256
257 if(SUCCEEDED(hr)
258 || hr == WMDM_S_NOT_ALL_PROPERTIES_APPLIED
259 || hr == WMDM_S_NOT_ALL_PROPERTIES_RETRIEVED)
260 {
261 return_value = true;
262 hr = S_FALSE;
263 }
264 }
265 }
266 }
267 }
268 }
269 }
270 pIEnumStorage->Release();
271 }
272
273 /* move to next device */
274 if(!return_value)
275 hr = pIEnumDev->Next(1, (IWMDMDevice **)&pIDevice, &ulNumFetched);
276 }
277 pIEnumDev->Release();
278 }
279 mtp_close(&mtp);
280 }
281 return return_value ? 1 : 0;
282}
283
284} \ No newline at end of file
diff --git a/utils/MTP/MTP_DLL/progresshelper.cpp b/utils/MTP/MTP_DLL/progresshelper.cpp
new file mode 100644
index 0000000000..a8aac365c5
--- /dev/null
+++ b/utils/MTP/MTP_DLL/progresshelper.cpp
@@ -0,0 +1,104 @@
1/*
2 * Windows MTP Firmware Uploading Implementation
3 *
4 * Based on http://opensource.creative.com/mtp_xfer.html
5 * Edited by Maurus Cuelenaere for Rockbox
6 *
7 * Copyright (c) 2009, Maurus Cuelenaere
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * * Neither the name of the <organization> nor the
18 * names of its contributors may be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY MAURUS CUELENAERE ''AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL MAURUS CUELENAERE BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include "stdafx.h"
34
35#include <windows.h>
36#include "mswmdm_i.c"
37#include "mswmdm.h"
38#include "sac.h"
39#include "scclient.h"
40
41#include "progresshelper.h"
42
43
44
45
46CProgressHelper::CProgressHelper( void (*callback)(unsigned int progress, unsigned int max) )
47{
48 m_cur_ticks = 0;
49 m_max_ticks = 0;
50 m_counter = 0;
51
52 m_callback = callback;
53}
54
55CProgressHelper::~CProgressHelper()
56{
57}
58
59HRESULT CProgressHelper::Begin( DWORD dwEstimatedTicks )
60{
61 m_max_ticks = dwEstimatedTicks;
62
63 return S_OK;
64}
65
66HRESULT CProgressHelper::Progress( DWORD dwTranspiredTicks )
67{
68 m_cur_ticks = dwTranspiredTicks;
69
70 if(m_callback != NULL)
71 m_callback(m_cur_ticks, max(m_max_ticks, m_cur_ticks));
72
73 return S_OK;
74}
75
76HRESULT CProgressHelper::End()
77{
78 m_cur_ticks = m_max_ticks;
79
80 return S_OK;
81}
82
83HRESULT CProgressHelper::QueryInterface( REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject )
84{
85 if(riid == IID_IWMDMProgress || riid == IID_IUnknown)
86 {
87 *ppvObject = this;
88 return S_OK;
89 }
90 else
91 {
92 *ppvObject = NULL;
93 return E_NOINTERFACE;
94 }
95}
96
97ULONG CProgressHelper::AddRef()
98{
99 return m_counter++;
100}
101ULONG CProgressHelper::Release()
102{
103 return m_counter--;
104}
diff --git a/utils/MTP/MTP_DLL/progresshelper.h b/utils/MTP/MTP_DLL/progresshelper.h
new file mode 100644
index 0000000000..ac54095520
--- /dev/null
+++ b/utils/MTP/MTP_DLL/progresshelper.h
@@ -0,0 +1,52 @@
1/*
2 * Windows MTP Firmware Uploading Implementation
3 *
4 * Based on http://opensource.creative.com/mtp_xfer.html
5 * Edited by Maurus Cuelenaere for Rockbox
6 *
7 * Copyright (c) 2009, Maurus Cuelenaere
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * * Neither the name of the <organization> nor the
18 * names of its contributors may be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY MAURUS CUELENAERE ''AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL MAURUS CUELENAERE BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33class CProgressHelper :
34 public IWMDMProgress
35{
36 void (*m_callback)(unsigned int progress, unsigned int max);
37 DWORD m_max_ticks;
38 DWORD m_cur_ticks;
39 DWORD m_counter;
40
41public:
42 CProgressHelper( void (*callback)(unsigned int progress, unsigned int max) );
43 ~CProgressHelper();
44 STDMETHOD(Begin)( DWORD dwEstimatedTicks );
45 STDMETHOD(Progress)( DWORD dwTranspiredTicks );
46 STDMETHOD(End)();
47
48 STDMETHOD(QueryInterface) ( REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject );
49 STDMETHOD_(ULONG, AddRef)( void );
50 STDMETHOD_(ULONG, Release)( void );
51};
52
diff --git a/utils/MTP/MTP_DLL/sendfirm_win.cpp b/utils/MTP/MTP_DLL/sendfirm_win.cpp
deleted file mode 100644
index 6f9cf24e93..0000000000
--- a/utils/MTP/MTP_DLL/sendfirm_win.cpp
+++ /dev/null
@@ -1,260 +0,0 @@
1/*
2 * Windows MTP Firmware Uploading Implementation
3 *
4 * Based on http://opensource.creative.com/mtp_xfer.html
5 * Edited by Maurus Cuelenaere for Rockbox
6 *
7 * Copyright (c) 2009, Maurus Cuelenaere
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * * Neither the name of the <organization> nor the
18 * names of its contributors may be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY MAURUS CUELENAERE ''AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL MAURUS CUELENAERE BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include <windows.h>
34#include "mswmdm_i.c"
35#include "mswmdm.h"
36#include "sac.h"
37#include "scclient.h"
38
39class CProgressHelper :
40 public IWMDMProgress
41{
42 void (*m_callback)(unsigned int progress, unsigned int max);
43 DWORD m_max_ticks;
44 DWORD m_cur_ticks;
45 DWORD m_counter;
46
47public:
48 CProgressHelper( void (*callback)(unsigned int progress, unsigned int max) );
49 ~CProgressHelper();
50 STDMETHOD(Begin)( DWORD dwEstimatedTicks );
51 STDMETHOD(Progress)( DWORD dwTranspiredTicks );
52 STDMETHOD(End)();
53
54 STDMETHOD(QueryInterface) ( REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject );
55 STDMETHOD_(ULONG, AddRef)( void );
56 STDMETHOD_(ULONG, Release)( void );
57};
58
59/*
60 * Compilation requirements:
61 *
62 * Download the Windows Media Format 9.5 SDK
63 * Add "c:\wmsdk\wmfsdk95\include,c:\wmsdk\wmfsdk95\wmdm\inc" to your inclusion path
64 * Add "c:\wmsdk\wmfsdk95\lib,c:\wmsdk\wmfsdk95\wmdm\lib" to your library inclusion path
65 * Link to "mssachlp.lib"
66 *
67 */
68extern "C" {
69__declspec(dllexport) bool send_fw(LPWSTR file, int filesize, void (*callback)(unsigned int progress, unsigned int max))
70{
71 bool return_value = false;
72 HRESULT hr;
73 IComponentAuthenticate* pICompAuth;
74 CSecureChannelClient *m_pSacClient = new CSecureChannelClient;
75 IWMDeviceManager3* m_pIdvMgr = NULL;
76
77 /* these are generic keys */
78 BYTE abPVK[] = {0x00};
79 BYTE abCert[] = {0x00};
80
81 CoInitialize(NULL);
82
83 /* get an authentication interface */
84 hr = CoCreateInstance(CLSID_MediaDevMgr, NULL, CLSCTX_ALL ,IID_IComponentAuthenticate, (void **)&pICompAuth);
85 if SUCCEEDED(hr)
86 {
87 /* create a secure channel client certificate */
88 hr = m_pSacClient->SetCertificate(SAC_CERT_V1, (BYTE*) abCert, sizeof(abCert), (BYTE*) abPVK, sizeof(abPVK));
89 if SUCCEEDED(hr)
90 {
91 /* bind the authentication interface to the secure channel client */
92 m_pSacClient->SetInterface(pICompAuth);
93
94 /* trigger communication */
95 hr = m_pSacClient->Authenticate(SAC_PROTOCOL_V1);
96 if SUCCEEDED(hr)
97 {
98 /* get main interface to media device manager */
99 hr = pICompAuth->QueryInterface(IID_IWMDeviceManager2, (void**)&m_pIdvMgr);
100 if SUCCEEDED(hr)
101 {
102 /* enumerate devices... */
103 IWMDMEnumDevice *pIEnumDev;
104 hr = m_pIdvMgr->EnumDevices2(&pIEnumDev);
105 if SUCCEEDED(hr)
106 {
107 hr = pIEnumDev->Reset(); /* Next will now return the first device */
108 if SUCCEEDED(hr)
109 {
110 IWMDMDevice3* pIDevice;
111 unsigned long ulNumFetched;
112 hr = pIEnumDev->Next(1, (IWMDMDevice **)&pIDevice, &ulNumFetched);
113 while (SUCCEEDED(hr) && (hr != S_FALSE))
114 {
115 /* get storage info */
116 DWORD tempDW;
117 pIDevice->GetType(&tempDW);
118 if (tempDW & WMDM_DEVICE_TYPE_STORAGE)
119 {
120 IWMDMEnumStorage *pIEnumStorage = NULL;
121 IWMDMStorage *pIStorage = NULL;
122 IWMDMStorage3 *pIFileStorage = NULL;
123 hr = pIDevice->EnumStorage(&pIEnumStorage);
124 if SUCCEEDED(hr)
125 {
126 pIEnumStorage->Reset();
127 hr = pIEnumStorage->Next(1, (IWMDMStorage **)&pIStorage, &ulNumFetched);
128 while (SUCCEEDED(hr) && (hr != S_FALSE))
129 {
130 IWMDMStorage3 *pNewStorage;
131 hr = pIStorage->QueryInterface(IID_IWMDMStorage3, (void **)&pNewStorage);
132 if SUCCEEDED(hr)
133 {
134 IWMDMStorageControl3 *pIWMDMStorageControl;
135 hr = pNewStorage->QueryInterface(IID_IWMDMStorageControl3,
136 (void**)&pIWMDMStorageControl);
137 if SUCCEEDED(hr)
138 {
139 IWMDMMetaData *pIWMDMMetaData = NULL;
140 hr = pNewStorage->CreateEmptyMetadataObject(&pIWMDMMetaData);
141 if (SUCCEEDED(hr))
142 {
143 DWORD dw = WMDM_FORMATCODE_UNDEFINEDFIRMWARE;
144 hr = pIWMDMMetaData->AddItem(WMDM_TYPE_DWORD, g_wszWMDMFormatCode, (BYTE *)&dw, sizeof(dw));
145 hr = pIWMDMMetaData->AddItem(WMDM_TYPE_STRING, g_wszWMDMFileName, (BYTE *)L"nk.bin", 32);
146 DWORD ow[2];
147 ow[0] = filesize;
148 ow[1] = 0;
149 hr = pIWMDMMetaData->AddItem(WMDM_TYPE_QWORD, g_wszWMDMFileSize, (BYTE *)ow, 2 * sizeof(dw));
150 if (SUCCEEDED(hr))
151 {
152 IWMDMStorage *pNewObject = NULL;
153 CProgressHelper *progress = new CProgressHelper(callback);
154
155 hr = pIWMDMStorageControl->Insert3(
156 WMDM_MODE_BLOCK | WMDM_CONTENT_FILE | WMDM_MODE_PROGRESS,
157 0,
158 file,
159 NULL,
160 NULL,
161 (callback == NULL ? NULL : (IWMDMProgress*)progress),
162 pIWMDMMetaData,
163 NULL,
164 (IWMDMStorage **)&pNewObject);
165
166 if(SUCCEEDED(hr) || hr == WMDM_S_NOT_ALL_PROPERTIES_APPLIED
167 || hr == WMDM_S_NOT_ALL_PROPERTIES_RETRIEVED)
168 {
169 return_value = true;
170 hr = S_FALSE;
171 }
172 }
173 }
174 }
175 }
176 }
177 }
178 pIEnumStorage->Release();
179 }
180
181 /* move to next device */
182 if(!return_value)
183 hr = pIEnumDev->Next(1, (IWMDMDevice **)&pIDevice, &ulNumFetched);
184 }
185 pIEnumDev->Release();
186 }
187 m_pIdvMgr->Release();
188 }
189 pICompAuth->Release();
190 }
191 }
192 }
193 }
194
195 CoUninitialize();
196
197 return return_value;
198}
199}
200
201
202CProgressHelper::CProgressHelper( void (*callback)(unsigned int progress, unsigned int max) )
203{
204 m_cur_ticks = 0;
205 m_max_ticks = 0;
206 m_counter = 0;
207
208 m_callback = callback;
209}
210
211CProgressHelper::~CProgressHelper()
212{
213}
214
215HRESULT CProgressHelper::Begin( DWORD dwEstimatedTicks )
216{
217 m_max_ticks = dwEstimatedTicks;
218
219 return S_OK;
220}
221
222HRESULT CProgressHelper::Progress( DWORD dwTranspiredTicks )
223{
224 m_cur_ticks = dwTranspiredTicks;
225
226 if(m_callback != NULL)
227 m_callback(m_cur_ticks, max(m_max_ticks, m_cur_ticks));
228
229 return S_OK;
230}
231
232HRESULT CProgressHelper::End()
233{
234 m_cur_ticks = m_max_ticks;
235
236 return S_OK;
237}
238
239HRESULT CProgressHelper::QueryInterface( REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject )
240{
241 if(riid == IID_IWMDMProgress || riid == IID_IUnknown)
242 {
243 *ppvObject = this;
244 return S_OK;
245 }
246 else
247 {
248 *ppvObject = NULL;
249 return E_NOINTERFACE;
250 }
251}
252
253ULONG CProgressHelper::AddRef()
254{
255 return m_counter++;
256}
257ULONG CProgressHelper::Release()
258{
259 return m_counter--;
260}
diff --git a/utils/MTP/beastpatcher/README.pstdint b/utils/MTP/beastpatcher/README.pstdint
new file mode 100644
index 0000000000..8dacc44fe2
--- /dev/null
+++ b/utils/MTP/beastpatcher/README.pstdint
@@ -0,0 +1,7 @@
1pstdint.h: A portable stdint.h
2
3This file is taken from http://www.azillionmonkeys.com/qed/pstdint.h
4
5Copyright (c) 2005-2007 Paul Hsieh
6Licensed under the BSD License. See file header for details.
7
diff --git a/utils/MTP/beastpatcher/beastpatcher.c b/utils/MTP/beastpatcher/beastpatcher.c
index 0ba324883a..783b11f202 100644
--- a/utils/MTP/beastpatcher/beastpatcher.c
+++ b/utils/MTP/beastpatcher/beastpatcher.c
@@ -38,11 +38,17 @@
38 ****************************************************************************/ 38 ****************************************************************************/
39 39
40#include <stdio.h> 40#include <stdio.h>
41#if !defined(_MSC_VER)
41#include <unistd.h> 42#include <unistd.h>
42#include <fcntl.h> 43#include <fcntl.h>
44#endif
43#include <string.h> 45#include <string.h>
44#include <stdlib.h> 46#include <stdlib.h>
47#if !defined(_MSC_VER)
45#include <inttypes.h> 48#include <inttypes.h>
49#else
50#include "pstdint.h"
51#endif
46#include <sys/types.h> 52#include <sys/types.h>
47#include <sys/stat.h> 53#include <sys/stat.h>
48 54
@@ -70,10 +76,10 @@ void print_usage(void)
70 76
71static void put_uint32le(uint32_t x, unsigned char* p) 77static void put_uint32le(uint32_t x, unsigned char* p)
72{ 78{
73 p[0] = x & 0xff; 79 p[0] = (unsigned char)(x & 0xff);
74 p[1] = (x >> 8) & 0xff; 80 p[1] = (unsigned char)((x >> 8) & 0xff);
75 p[2] = (x >> 16) & 0xff; 81 p[2] = (unsigned char)((x >> 16) & 0xff);
76 p[3] = (x >> 24) & 0xff; 82 p[3] = (unsigned char)((x >> 24) & 0xff);
77} 83}
78 84
79static uint32_t calc_csum(const unsigned char* pb, int cb) 85static uint32_t calc_csum(const unsigned char* pb, int cb)
@@ -94,7 +100,7 @@ static void create_single_boot(unsigned char* boot, int bootlen,
94 *fwsize = 15 + 16 + 12 + bootlen + 12; 100 *fwsize = 15 + 16 + 12 + bootlen + 12;
95 *fwbuf = malloc(*fwsize); 101 *fwbuf = malloc(*fwsize);
96 102
97 if(buf == NULL) { 103 if(fwbuf == NULL) {
98 fprintf(stderr, "[ERR] Cannot allocate memory.\n" ); 104 fprintf(stderr, "[ERR] Cannot allocate memory.\n" );
99 *fwbuf = NULL; 105 *fwbuf = NULL;
100 *fwsize = 0; 106 *fwsize = 0;
diff --git a/utils/MTP/beastpatcher/mtp_common.h b/utils/MTP/beastpatcher/mtp_common.h
index 5f7de3983b..4b60fa08da 100644
--- a/utils/MTP/beastpatcher/mtp_common.h
+++ b/utils/MTP/beastpatcher/mtp_common.h
@@ -40,7 +40,7 @@
40#ifndef _MTP_COMMON_H 40#ifndef _MTP_COMMON_H
41#define _MTP_COMMON_H 41#define _MTP_COMMON_H
42 42
43#ifdef __WIN32__ 43#if defined(__WIN32__) || defined(_WIN32)
44#else 44#else
45#include "libmtp.h" 45#include "libmtp.h"
46#endif 46#endif
@@ -53,7 +53,7 @@ struct mtp_info_t
53 char version[200]; 53 char version[200];
54 54
55 /* OS-Specific data */ 55 /* OS-Specific data */
56#ifdef __WIN32__ 56#if defined(__WIN32__) || defined(_WIN32)
57#else 57#else
58 LIBMTP_mtpdevice_t *device; 58 LIBMTP_mtpdevice_t *device;
59#endif 59#endif
diff --git a/utils/MTP/beastpatcher/mtp_win32.c b/utils/MTP/beastpatcher/mtp_win32.c
index f68faddbc2..ced930ab80 100644
--- a/utils/MTP/beastpatcher/mtp_win32.c
+++ b/utils/MTP/beastpatcher/mtp_win32.c
@@ -43,15 +43,12 @@
43#include <stddef.h> 43#include <stddef.h>
44#include <stdlib.h> 44#include <stdlib.h>
45#include <wchar.h> 45#include <wchar.h>
46#include <stdbool.h>
47#include <windows.h> 46#include <windows.h>
48#include <tchar.h> 47#include <tchar.h>
49 48
50#include "mtp_common.h" 49#include "mtp_common.h"
51 50
52 51#include "../MTP_DLL/MTP_DLL.h"
53extern __declspec(dllimport) bool send_fw(LPWSTR file, int filesize,
54 void (*callback)(unsigned int progress, unsigned int max));
55 52
56int mtp_init(struct mtp_info_t* mtp_info) 53int mtp_init(struct mtp_info_t* mtp_info)
57{ 54{
@@ -71,11 +68,18 @@ int mtp_finished(struct mtp_info_t* mtp_info)
71 68
72int mtp_scan(struct mtp_info_t* mtp_info) 69int mtp_scan(struct mtp_info_t* mtp_info)
73{ 70{
74 strcpy(mtp_info->manufacturer,"<unknown>"); 71 wchar_t name[256];
75 strcpy(mtp_info->modelname,"<unknown>"); 72 wchar_t manufacturer[256];
76 strcpy(mtp_info->version,"<unknown>"); 73 DWORD version;
74 int num = 0;
77 75
78 return 0; 76 num = mtp_description(name, manufacturer, &version);
77
78 wcstombs(mtp_info->manufacturer, manufacturer, 200);
79 wcstombs(mtp_info->modelname, name, 200);
80
81 sprintf(mtp_info->version, "%x", (unsigned int)version);
82 return (num > 0) ? num : -1;
79 83
80} 84}
81 85
@@ -147,11 +151,11 @@ int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
147 return -1; 151 return -1;
148 } 152 }
149 153
150 tmp = (LPWSTR)malloc(strlen(szTempName)*2+1); 154 tmp = (LPWSTR)malloc(_tcslen(szTempName)*2+1);
151 mbstowcs(tmp, szTempName, strlen(szTempName)*2+1); 155 mbstowcs(tmp, (char*)szTempName, _tcslen(szTempName)*2+1);
152 156
153 fprintf(stderr, "[INFO] Sending firmware...\n"); 157 fprintf(stderr, "[INFO] Sending firmware...\n");
154 if (send_fw(tmp, fwsize, &callback)) 158 if (mtp_sendnk(tmp, fwsize, &callback))
155 { 159 {
156 fprintf(stderr, "[INFO] Firmware sent successfully\n"); 160 fprintf(stderr, "[INFO] Firmware sent successfully\n");
157 ret = 0; 161 ret = 0;
@@ -172,3 +176,4 @@ int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
172 176
173 return ret; 177 return ret;
174} 178}
179
diff --git a/utils/MTP/beastpatcher/pstdint.h b/utils/MTP/beastpatcher/pstdint.h
new file mode 100644
index 0000000000..12c108a2e9
--- /dev/null
+++ b/utils/MTP/beastpatcher/pstdint.h
@@ -0,0 +1,799 @@
1/* A portable stdint.h
2 ****************************************************************************
3 * BSD License:
4 ****************************************************************************
5 *
6 * Copyright (c) 2005-2007 Paul Hsieh
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 ****************************************************************************
33 *
34 * Version 0.1.11
35 *
36 * The ANSI C standard committee, for the C99 standard, specified the
37 * inclusion of a new standard include file called stdint.h. This is
38 * a very useful and long desired include file which contains several
39 * very precise definitions for integer scalar types that is
40 * critically important for making portable several classes of
41 * applications including cryptography, hashing, variable length
42 * integer libraries and so on. But for most developers its likely
43 * useful just for programming sanity.
44 *
45 * The problem is that most compiler vendors have decided not to
46 * implement the C99 standard, and the next C++ language standard
47 * (which has a lot more mindshare these days) will be a long time in
48 * coming and its unknown whether or not it will include stdint.h or
49 * how much adoption it will have. Either way, it will be a long time
50 * before all compilers come with a stdint.h and it also does nothing
51 * for the extremely large number of compilers available today which
52 * do not include this file, or anything comparable to it.
53 *
54 * So that's what this file is all about. Its an attempt to build a
55 * single universal include file that works on as many platforms as
56 * possible to deliver what stdint.h is supposed to. A few things
57 * that should be noted about this file:
58 *
59 * 1) It is not guaranteed to be portable and/or present an identical
60 * interface on all platforms. The extreme variability of the
61 * ANSI C standard makes this an impossibility right from the
62 * very get go. Its really only meant to be useful for the vast
63 * majority of platforms that possess the capability of
64 * implementing usefully and precisely defined, standard sized
65 * integer scalars. Systems which are not intrinsically 2s
66 * complement may produce invalid constants.
67 *
68 * 2) There is an unavoidable use of non-reserved symbols.
69 *
70 * 3) Other standard include files are invoked.
71 *
72 * 4) This file may come in conflict with future platforms that do
73 * include stdint.h. The hope is that one or the other can be
74 * used with no real difference.
75 *
76 * 5) In the current verison, if your platform can't represent
77 * int32_t, int16_t and int8_t, it just dumps out with a compiler
78 * error.
79 *
80 * 6) 64 bit integers may or may not be defined. Test for their
81 * presence with the test: #ifdef INT64_MAX or #ifdef UINT64_MAX.
82 * Note that this is different from the C99 specification which
83 * requires the existence of 64 bit support in the compiler. If
84 * this is not defined for your platform, yet it is capable of
85 * dealing with 64 bits then it is because this file has not yet
86 * been extended to cover all of your system's capabilities.
87 *
88 * 7) (u)intptr_t may or may not be defined. Test for its presence
89 * with the test: #ifdef PTRDIFF_MAX. If this is not defined
90 * for your platform, then it is because this file has not yet
91 * been extended to cover all of your system's capabilities, not
92 * because its optional.
93 *
94 * 8) The following might not been defined even if your platform is
95 * capable of defining it:
96 *
97 * WCHAR_MIN
98 * WCHAR_MAX
99 * (u)int64_t
100 * PTRDIFF_MIN
101 * PTRDIFF_MAX
102 * (u)intptr_t
103 *
104 * 9) The following have not been defined:
105 *
106 * WINT_MIN
107 * WINT_MAX
108 *
109 * 10) The criteria for defining (u)int_least(*)_t isn't clear,
110 * except for systems which don't have a type that precisely
111 * defined 8, 16, or 32 bit types (which this include file does
112 * not support anyways). Default definitions have been given.
113 *
114 * 11) The criteria for defining (u)int_fast(*)_t isn't something I
115 * would trust to any particular compiler vendor or the ANSI C
116 * committee. It is well known that "compatible systems" are
117 * commonly created that have very different performance
118 * characteristics from the systems they are compatible with,
119 * especially those whose vendors make both the compiler and the
120 * system. Default definitions have been given, but its strongly
121 * recommended that users never use these definitions for any
122 * reason (they do *NOT* deliver any serious guarantee of
123 * improved performance -- not in this file, nor any vendor's
124 * stdint.h).
125 *
126 * 12) The following macros:
127 *
128 * PRINTF_INTMAX_MODIFIER
129 * PRINTF_INT64_MODIFIER
130 * PRINTF_INT32_MODIFIER
131 * PRINTF_INT16_MODIFIER
132 * PRINTF_LEAST64_MODIFIER
133 * PRINTF_LEAST32_MODIFIER
134 * PRINTF_LEAST16_MODIFIER
135 * PRINTF_INTPTR_MODIFIER
136 *
137 * are strings which have been defined as the modifiers required
138 * for the "d", "u" and "x" printf formats to correctly output
139 * (u)intmax_t, (u)int64_t, (u)int32_t, (u)int16_t, (u)least64_t,
140 * (u)least32_t, (u)least16_t and (u)intptr_t types respectively.
141 * PRINTF_INTPTR_MODIFIER is not defined for some systems which
142 * provide their own stdint.h. PRINTF_INT64_MODIFIER is not
143 * defined if INT64_MAX is not defined. These are an extension
144 * beyond what C99 specifies must be in stdint.h.
145 *
146 * In addition, the following macros are defined:
147 *
148 * PRINTF_INTMAX_HEX_WIDTH
149 * PRINTF_INT64_HEX_WIDTH
150 * PRINTF_INT32_HEX_WIDTH
151 * PRINTF_INT16_HEX_WIDTH
152 * PRINTF_INT8_HEX_WIDTH
153 * PRINTF_INTMAX_DEC_WIDTH
154 * PRINTF_INT64_DEC_WIDTH
155 * PRINTF_INT32_DEC_WIDTH
156 * PRINTF_INT16_DEC_WIDTH
157 * PRINTF_INT8_DEC_WIDTH
158 *
159 * Which specifies the maximum number of characters required to
160 * print the number of that type in either hexadecimal or decimal.
161 * These are an extension beyond what C99 specifies must be in
162 * stdint.h.
163 *
164 * Compilers tested (all with 0 warnings at their highest respective
165 * settings): Borland Turbo C 2.0, WATCOM C/C++ 11.0 (16 bits and 32
166 * bits), Microsoft Visual C++ 6.0 (32 bit), Microsoft Visual Studio
167 * .net (VC7), Intel C++ 4.0, GNU gcc v3.3.3
168 *
169 * This file should be considered a work in progress. Suggestions for
170 * improvements, especially those which increase coverage are strongly
171 * encouraged.
172 *
173 * Acknowledgements
174 *
175 * The following people have made significant contributions to the
176 * development and testing of this file:
177 *
178 * Chris Howie
179 * John Steele Scott
180 * Dave Thorup
181 *
182 */
183
184#include <stddef.h>
185#include <limits.h>
186#include <signal.h>
187
188/*
189 * For gcc with _STDINT_H, fill in the PRINTF_INT*_MODIFIER macros, and
190 * do nothing else. On the Mac OS X version of gcc this is _STDINT_H_.
191 */
192
193#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)
194#include <stdint.h>
195#define _PSTDINT_H_INCLUDED
196# ifndef PRINTF_INT64_MODIFIER
197# define PRINTF_INT64_MODIFIER "ll"
198# endif
199# ifndef PRINTF_INT32_MODIFIER
200# define PRINTF_INT32_MODIFIER "l"
201# endif
202# ifndef PRINTF_INT16_MODIFIER
203# define PRINTF_INT16_MODIFIER "h"
204# endif
205# ifndef PRINTF_INTMAX_MODIFIER
206# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
207# endif
208# ifndef PRINTF_INT64_HEX_WIDTH
209# define PRINTF_INT64_HEX_WIDTH "16"
210# endif
211# ifndef PRINTF_INT32_HEX_WIDTH
212# define PRINTF_INT32_HEX_WIDTH "8"
213# endif
214# ifndef PRINTF_INT16_HEX_WIDTH
215# define PRINTF_INT16_HEX_WIDTH "4"
216# endif
217# ifndef PRINTF_INT8_HEX_WIDTH
218# define PRINTF_INT8_HEX_WIDTH "2"
219# endif
220# ifndef PRINTF_INT64_DEC_WIDTH
221# define PRINTF_INT64_DEC_WIDTH "20"
222# endif
223# ifndef PRINTF_INT32_DEC_WIDTH
224# define PRINTF_INT32_DEC_WIDTH "10"
225# endif
226# ifndef PRINTF_INT16_DEC_WIDTH
227# define PRINTF_INT16_DEC_WIDTH "5"
228# endif
229# ifndef PRINTF_INT8_DEC_WIDTH
230# define PRINTF_INT8_DEC_WIDTH "3"
231# endif
232# ifndef PRINTF_INTMAX_HEX_WIDTH
233# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
234# endif
235# ifndef PRINTF_INTMAX_DEC_WIDTH
236# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
237# endif
238
239/*
240 * Something really weird is going on with Open Watcom. Just pull some of
241 * these duplicated definitions from Open Watcom's stdint.h file for now.
242 */
243
244# if defined (__WATCOMC__) && __WATCOMC__ >= 1250
245# if !defined (INT64_C)
246# define INT64_C(x) (x + (INT64_MAX - INT64_MAX))
247# endif
248# if !defined (UINT64_C)
249# define UINT64_C(x) (x + (UINT64_MAX - UINT64_MAX))
250# endif
251# if !defined (INT32_C)
252# define INT32_C(x) (x + (INT32_MAX - INT32_MAX))
253# endif
254# if !defined (UINT32_C)
255# define UINT32_C(x) (x + (UINT32_MAX - UINT32_MAX))
256# endif
257# if !defined (INT16_C)
258# define INT16_C(x) (x)
259# endif
260# if !defined (UINT16_C)
261# define UINT16_C(x) (x)
262# endif
263# if !defined (INT8_C)
264# define INT8_C(x) (x)
265# endif
266# if !defined (UINT8_C)
267# define UINT8_C(x) (x)
268# endif
269# if !defined (UINT64_MAX)
270# define UINT64_MAX 18446744073709551615ULL
271# endif
272# if !defined (INT64_MAX)
273# define INT64_MAX 9223372036854775807LL
274# endif
275# if !defined (UINT32_MAX)
276# define UINT32_MAX 4294967295UL
277# endif
278# if !defined (INT32_MAX)
279# define INT32_MAX 2147483647L
280# endif
281# if !defined (INTMAX_MAX)
282# define INTMAX_MAX INT64_MAX
283# endif
284# if !defined (INTMAX_MIN)
285# define INTMAX_MIN INT64_MIN
286# endif
287# endif
288#endif
289
290#ifndef _PSTDINT_H_INCLUDED
291#define _PSTDINT_H_INCLUDED
292
293#ifndef SIZE_MAX
294# define SIZE_MAX (~(size_t)0)
295#endif
296
297/*
298 * Deduce the type assignments from limits.h under the assumption that
299 * integer sizes in bits are powers of 2, and follow the ANSI
300 * definitions.
301 */
302
303#ifndef UINT8_MAX
304# define UINT8_MAX 0xff
305#endif
306#ifndef uint8_t
307# if (UCHAR_MAX == UINT8_MAX) || defined (S_SPLINT_S)
308 typedef unsigned char uint8_t;
309# define UINT8_C(v) ((uint8_t) v)
310# else
311# error "Platform not supported"
312# endif
313#endif
314
315#ifndef INT8_MAX
316# define INT8_MAX 0x7f
317#endif
318#ifndef INT8_MIN
319# define INT8_MIN INT8_C(0x80)
320#endif
321#ifndef int8_t
322# if (SCHAR_MAX == INT8_MAX) || defined (S_SPLINT_S)
323 typedef signed char int8_t;
324# define INT8_C(v) ((int8_t) v)
325# else
326# error "Platform not supported"
327# endif
328#endif
329
330#ifndef UINT16_MAX
331# define UINT16_MAX 0xffff
332#endif
333#ifndef uint16_t
334#if (UINT_MAX == UINT16_MAX) || defined (S_SPLINT_S)
335 typedef unsigned int uint16_t;
336# ifndef PRINTF_INT16_MODIFIER
337# define PRINTF_INT16_MODIFIER ""
338# endif
339# define UINT16_C(v) ((uint16_t) (v))
340#elif (USHRT_MAX == UINT16_MAX)
341 typedef unsigned short uint16_t;
342# define UINT16_C(v) ((uint16_t) (v))
343# ifndef PRINTF_INT16_MODIFIER
344# define PRINTF_INT16_MODIFIER "h"
345# endif
346#else
347#error "Platform not supported"
348#endif
349#endif
350
351#ifndef INT16_MAX
352# define INT16_MAX 0x7fff
353#endif
354#ifndef INT16_MIN
355# define INT16_MIN INT16_C(0x8000)
356#endif
357#ifndef int16_t
358#if (INT_MAX == INT16_MAX) || defined (S_SPLINT_S)
359 typedef signed int int16_t;
360# define INT16_C(v) ((int16_t) (v))
361# ifndef PRINTF_INT16_MODIFIER
362# define PRINTF_INT16_MODIFIER ""
363# endif
364#elif (SHRT_MAX == INT16_MAX)
365 typedef signed short int16_t;
366# define INT16_C(v) ((int16_t) (v))
367# ifndef PRINTF_INT16_MODIFIER
368# define PRINTF_INT16_MODIFIER "h"
369# endif
370#else
371#error "Platform not supported"
372#endif
373#endif
374
375#ifndef UINT32_MAX
376# define UINT32_MAX (0xffffffffUL)
377#endif
378#ifndef uint32_t
379#if (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S)
380 typedef unsigned long uint32_t;
381# define UINT32_C(v) v ## UL
382# ifndef PRINTF_INT32_MODIFIER
383# define PRINTF_INT32_MODIFIER "l"
384# endif
385#elif (UINT_MAX == UINT32_MAX)
386 typedef unsigned int uint32_t;
387# ifndef PRINTF_INT32_MODIFIER
388# define PRINTF_INT32_MODIFIER ""
389# endif
390# define UINT32_C(v) v ## U
391#elif (USHRT_MAX == UINT32_MAX)
392 typedef unsigned short uint32_t;
393# define UINT32_C(v) ((unsigned short) (v))
394# ifndef PRINTF_INT32_MODIFIER
395# define PRINTF_INT32_MODIFIER ""
396# endif
397#else
398#error "Platform not supported"
399#endif
400#endif
401
402#ifndef INT32_MAX
403# define INT32_MAX (0x7fffffffL)
404#endif
405#ifndef INT32_MIN
406# define INT32_MIN INT32_C(0x80000000)
407#endif
408#ifndef int32_t
409#if (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S)
410 typedef signed long int32_t;
411# define INT32_C(v) v ## L
412# ifndef PRINTF_INT32_MODIFIER
413# define PRINTF_INT32_MODIFIER "l"
414# endif
415#elif (INT_MAX == INT32_MAX)
416 typedef signed int int32_t;
417# define INT32_C(v) v
418# ifndef PRINTF_INT32_MODIFIER
419# define PRINTF_INT32_MODIFIER ""
420# endif
421#elif (SHRT_MAX == INT32_MAX)
422 typedef signed short int32_t;
423# define INT32_C(v) ((short) (v))
424# ifndef PRINTF_INT32_MODIFIER
425# define PRINTF_INT32_MODIFIER ""
426# endif
427#else
428#error "Platform not supported"
429#endif
430#endif
431
432/*
433 * The macro stdint_int64_defined is temporarily used to record
434 * whether or not 64 integer support is available. It must be
435 * defined for any 64 integer extensions for new platforms that are
436 * added.
437 */
438
439#undef stdint_int64_defined
440#if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined (S_SPLINT_S)
441# if (__STDC__ && __STDC_VERSION >= 199901L) || defined (S_SPLINT_S)
442# define stdint_int64_defined
443 typedef long long int64_t;
444 typedef unsigned long long uint64_t;
445# define UINT64_C(v) v ## ULL
446# define INT64_C(v) v ## LL
447# ifndef PRINTF_INT64_MODIFIER
448# define PRINTF_INT64_MODIFIER "ll"
449# endif
450# endif
451#endif
452
453#if !defined (stdint_int64_defined)
454# if defined(__GNUC__)
455# define stdint_int64_defined
456 __extension__ typedef long long int64_t;
457 __extension__ typedef unsigned long long uint64_t;
458# define UINT64_C(v) v ## ULL
459# define INT64_C(v) v ## LL
460# ifndef PRINTF_INT64_MODIFIER
461# define PRINTF_INT64_MODIFIER "ll"
462# endif
463# elif defined(__MWERKS__) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || defined (__APPLE_CC__) || defined (_LONG_LONG) || defined (_CRAYC) || defined (S_SPLINT_S)
464# define stdint_int64_defined
465 typedef long long int64_t;
466 typedef unsigned long long uint64_t;
467# define UINT64_C(v) v ## ULL
468# define INT64_C(v) v ## LL
469# ifndef PRINTF_INT64_MODIFIER
470# define PRINTF_INT64_MODIFIER "ll"
471# endif
472# elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined (__BORLANDC__) && __BORLANDC__ > 0x460) || defined (__alpha) || defined (__DECC)
473# define stdint_int64_defined
474 typedef __int64 int64_t;
475 typedef unsigned __int64 uint64_t;
476# define UINT64_C(v) v ## UI64
477# define INT64_C(v) v ## I64
478# ifndef PRINTF_INT64_MODIFIER
479# define PRINTF_INT64_MODIFIER "I64"
480# endif
481# endif
482#endif
483
484#if !defined (LONG_LONG_MAX) && defined (INT64_C)
485# define LONG_LONG_MAX INT64_C (9223372036854775807)
486#endif
487#ifndef ULONG_LONG_MAX
488# define ULONG_LONG_MAX UINT64_C (18446744073709551615)
489#endif
490
491#if !defined (INT64_MAX) && defined (INT64_C)
492# define INT64_MAX INT64_C (9223372036854775807)
493#endif
494#if !defined (INT64_MIN) && defined (INT64_C)
495# define INT64_MIN INT64_C (-9223372036854775808)
496#endif
497#if !defined (UINT64_MAX) && defined (INT64_C)
498# define UINT64_MAX UINT64_C (18446744073709551615)
499#endif
500
501/*
502 * Width of hexadecimal for number field.
503 */
504
505#ifndef PRINTF_INT64_HEX_WIDTH
506# define PRINTF_INT64_HEX_WIDTH "16"
507#endif
508#ifndef PRINTF_INT32_HEX_WIDTH
509# define PRINTF_INT32_HEX_WIDTH "8"
510#endif
511#ifndef PRINTF_INT16_HEX_WIDTH
512# define PRINTF_INT16_HEX_WIDTH "4"
513#endif
514#ifndef PRINTF_INT8_HEX_WIDTH
515# define PRINTF_INT8_HEX_WIDTH "2"
516#endif
517
518#ifndef PRINTF_INT64_DEC_WIDTH
519# define PRINTF_INT64_DEC_WIDTH "20"
520#endif
521#ifndef PRINTF_INT32_DEC_WIDTH
522# define PRINTF_INT32_DEC_WIDTH "10"
523#endif
524#ifndef PRINTF_INT16_DEC_WIDTH
525# define PRINTF_INT16_DEC_WIDTH "5"
526#endif
527#ifndef PRINTF_INT8_DEC_WIDTH
528# define PRINTF_INT8_DEC_WIDTH "3"
529#endif
530
531/*
532 * Ok, lets not worry about 128 bit integers for now. Moore's law says
533 * we don't need to worry about that until about 2040 at which point
534 * we'll have bigger things to worry about.
535 */
536
537#ifdef stdint_int64_defined
538 typedef int64_t intmax_t;
539 typedef uint64_t uintmax_t;
540# define INTMAX_MAX INT64_MAX
541# define INTMAX_MIN INT64_MIN
542# define UINTMAX_MAX UINT64_MAX
543# define UINTMAX_C(v) UINT64_C(v)
544# define INTMAX_C(v) INT64_C(v)
545# ifndef PRINTF_INTMAX_MODIFIER
546# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
547# endif
548# ifndef PRINTF_INTMAX_HEX_WIDTH
549# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
550# endif
551# ifndef PRINTF_INTMAX_DEC_WIDTH
552# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
553# endif
554#else
555 typedef int32_t intmax_t;
556 typedef uint32_t uintmax_t;
557# define INTMAX_MAX INT32_MAX
558# define UINTMAX_MAX UINT32_MAX
559# define UINTMAX_C(v) UINT32_C(v)
560# define INTMAX_C(v) INT32_C(v)
561# ifndef PRINTF_INTMAX_MODIFIER
562# define PRINTF_INTMAX_MODIFIER PRINTF_INT32_MODIFIER
563# endif
564# ifndef PRINTF_INTMAX_HEX_WIDTH
565# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT32_HEX_WIDTH
566# endif
567# ifndef PRINTF_INTMAX_DEC_WIDTH
568# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT32_DEC_WIDTH
569# endif
570#endif
571
572/*
573 * Because this file currently only supports platforms which have
574 * precise powers of 2 as bit sizes for the default integers, the
575 * least definitions are all trivial. Its possible that a future
576 * version of this file could have different definitions.
577 */
578
579#ifndef stdint_least_defined
580 typedef int8_t int_least8_t;
581 typedef uint8_t uint_least8_t;
582 typedef int16_t int_least16_t;
583 typedef uint16_t uint_least16_t;
584 typedef int32_t int_least32_t;
585 typedef uint32_t uint_least32_t;
586# define PRINTF_LEAST32_MODIFIER PRINTF_INT32_MODIFIER
587# define PRINTF_LEAST16_MODIFIER PRINTF_INT16_MODIFIER
588# define UINT_LEAST8_MAX UINT8_MAX
589# define INT_LEAST8_MAX INT8_MAX
590# define UINT_LEAST16_MAX UINT16_MAX
591# define INT_LEAST16_MAX INT16_MAX
592# define UINT_LEAST32_MAX UINT32_MAX
593# define INT_LEAST32_MAX INT32_MAX
594# define INT_LEAST8_MIN INT8_MIN
595# define INT_LEAST16_MIN INT16_MIN
596# define INT_LEAST32_MIN INT32_MIN
597# ifdef stdint_int64_defined
598 typedef int64_t int_least64_t;
599 typedef uint64_t uint_least64_t;
600# define PRINTF_LEAST64_MODIFIER PRINTF_INT64_MODIFIER
601# define UINT_LEAST64_MAX UINT64_MAX
602# define INT_LEAST64_MAX INT64_MAX
603# define INT_LEAST64_MIN INT64_MIN
604# endif
605#endif
606#undef stdint_least_defined
607
608/*
609 * The ANSI C committee pretending to know or specify anything about
610 * performance is the epitome of misguided arrogance. The mandate of
611 * this file is to *ONLY* ever support that absolute minimum
612 * definition of the fast integer types, for compatibility purposes.
613 * No extensions, and no attempt to suggest what may or may not be a
614 * faster integer type will ever be made in this file. Developers are
615 * warned to stay away from these types when using this or any other
616 * stdint.h.
617 */
618
619typedef int_least8_t int_fast8_t;
620typedef uint_least8_t uint_fast8_t;
621typedef int_least16_t int_fast16_t;
622typedef uint_least16_t uint_fast16_t;
623typedef int_least32_t int_fast32_t;
624typedef uint_least32_t uint_fast32_t;
625#define UINT_FAST8_MAX UINT_LEAST8_MAX
626#define INT_FAST8_MAX INT_LEAST8_MAX
627#define UINT_FAST16_MAX UINT_LEAST16_MAX
628#define INT_FAST16_MAX INT_LEAST16_MAX
629#define UINT_FAST32_MAX UINT_LEAST32_MAX
630#define INT_FAST32_MAX INT_LEAST32_MAX
631#define INT_FAST8_MIN INT_LEAST8_MIN
632#define INT_FAST16_MIN INT_LEAST16_MIN
633#define INT_FAST32_MIN INT_LEAST32_MIN
634#ifdef stdint_int64_defined
635 typedef int_least64_t int_fast64_t;
636 typedef uint_least64_t uint_fast64_t;
637# define UINT_FAST64_MAX UINT_LEAST64_MAX
638# define INT_FAST64_MAX INT_LEAST64_MAX
639# define INT_FAST64_MIN INT_LEAST64_MIN
640#endif
641
642#undef stdint_int64_defined
643
644/*
645 * Whatever piecemeal, per compiler thing we can do about the wchar_t
646 * type limits.
647 */
648
649#if defined(__WATCOMC__) || defined(_MSC_VER) || defined (__GNUC__)
650# include <wchar.h>
651# ifndef WCHAR_MIN
652# define WCHAR_MIN 0
653# endif
654# ifndef WCHAR_MAX
655# define WCHAR_MAX ((wchar_t)-1)
656# endif
657#endif
658
659/*
660 * Whatever piecemeal, per compiler/platform thing we can do about the
661 * (u)intptr_t types and limits.
662 */
663
664#if defined (_MSC_VER) && defined (_UINTPTR_T_DEFINED)
665# define STDINT_H_UINTPTR_T_DEFINED
666#endif
667
668#ifndef STDINT_H_UINTPTR_T_DEFINED
669# if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) || defined (_WIN64)
670# define stdint_intptr_bits 64
671# elif defined (__WATCOMC__) || defined (__TURBOC__)
672# if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
673# define stdint_intptr_bits 16
674# else
675# define stdint_intptr_bits 32
676# endif
677# elif defined (__i386__) || defined (_WIN32) || defined (WIN32)
678# define stdint_intptr_bits 32
679# elif defined (__INTEL_COMPILER)
680/* TODO -- what will Intel do about x86-64? */
681# endif
682
683# ifdef stdint_intptr_bits
684# define stdint_intptr_glue3_i(a,b,c) a##b##c
685# define stdint_intptr_glue3(a,b,c) stdint_intptr_glue3_i(a,b,c)
686# ifndef PRINTF_INTPTR_MODIFIER
687# define PRINTF_INTPTR_MODIFIER stdint_intptr_glue3(PRINTF_INT,stdint_intptr_bits,_MODIFIER)
688# endif
689# ifndef PTRDIFF_MAX
690# define PTRDIFF_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
691# endif
692# ifndef PTRDIFF_MIN
693# define PTRDIFF_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
694# endif
695# ifndef UINTPTR_MAX
696# define UINTPTR_MAX stdint_intptr_glue3(UINT,stdint_intptr_bits,_MAX)
697# endif
698# ifndef INTPTR_MAX
699# define INTPTR_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
700# endif
701# ifndef INTPTR_MIN
702# define INTPTR_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
703# endif
704# ifndef INTPTR_C
705# define INTPTR_C(x) stdint_intptr_glue3(INT,stdint_intptr_bits,_C)(x)
706# endif
707# ifndef UINTPTR_C
708# define UINTPTR_C(x) stdint_intptr_glue3(UINT,stdint_intptr_bits,_C)(x)
709# endif
710 typedef stdint_intptr_glue3(uint,stdint_intptr_bits,_t) uintptr_t;
711 typedef stdint_intptr_glue3( int,stdint_intptr_bits,_t) intptr_t;
712# else
713/* TODO -- This following is likely wrong for some platforms, and does
714 nothing for the definition of uintptr_t. */
715 typedef ptrdiff_t intptr_t;
716# endif
717# define STDINT_H_UINTPTR_T_DEFINED
718#endif
719
720/*
721 * Assumes sig_atomic_t is signed and we have a 2s complement machine.
722 */
723
724#ifndef SIG_ATOMIC_MAX
725# define SIG_ATOMIC_MAX ((((sig_atomic_t) 1) << (sizeof (sig_atomic_t)*CHAR_BIT-1)) - 1)
726#endif
727
728#endif
729
730#if defined (__TEST_PSTDINT_FOR_CORRECTNESS)
731
732/*
733 * Please compile with the maximum warning settings to make sure macros are not
734 * defined more than once.
735 */
736
737#include <stdlib.h>
738#include <stdio.h>
739#include <string.h>
740
741#define glue3_aux(x,y,z) x ## y ## z
742#define glue3(x,y,z) glue3_aux(x,y,z)
743
744#define DECLU(bits) glue3(uint,bits,_t) glue3(u,bits,=) glue3(UINT,bits,_C) (0);
745#define DECLI(bits) glue3(int,bits,_t) glue3(i,bits,=) glue3(INT,bits,_C) (0);
746
747#define DECL(us,bits) glue3(DECL,us,) (bits)
748
749#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)
750
751int main () {
752 DECL(I,8)
753 DECL(U,8)
754 DECL(I,16)
755 DECL(U,16)
756 DECL(I,32)
757 DECL(U,32)
758#ifdef INT64_MAX
759 DECL(I,64)
760 DECL(U,64)
761#endif
762 intmax_t imax = INTMAX_C(0);
763 uintmax_t umax = UINTMAX_C(0);
764 char str0[256], str1[256];
765
766 sprintf (str0, "%d %x\n", 0, ~0);
767
768 sprintf (str1, "%d %x\n", i8, ~0);
769 if (0 != strcmp (str0, str1)) printf ("Something wrong with i8 : %s\n", str1);
770 sprintf (str1, "%u %x\n", u8, ~0);
771 if (0 != strcmp (str0, str1)) printf ("Something wrong with u8 : %s\n", str1);
772 sprintf (str1, "%d %x\n", i16, ~0);
773 if (0 != strcmp (str0, str1)) printf ("Something wrong with i16 : %s\n", str1);
774 sprintf (str1, "%u %x\n", u16, ~0);
775 if (0 != strcmp (str0, str1)) printf ("Something wrong with u16 : %s\n", str1);
776 sprintf (str1, "%" PRINTF_INT32_MODIFIER "d %x\n", i32, ~0);
777 if (0 != strcmp (str0, str1)) printf ("Something wrong with i32 : %s\n", str1);
778 sprintf (str1, "%" PRINTF_INT32_MODIFIER "u %x\n", u32, ~0);
779 if (0 != strcmp (str0, str1)) printf ("Something wrong with u32 : %s\n", str1);
780#ifdef INT64_MAX
781 sprintf (str1, "%" PRINTF_INT64_MODIFIER "d %x\n", i64, ~0);
782 if (0 != strcmp (str0, str1)) printf ("Something wrong with i64 : %s\n", str1);
783#endif
784 sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "d %x\n", imax, ~0);
785 if (0 != strcmp (str0, str1)) printf ("Something wrong with imax : %s\n", str1);
786 sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "u %x\n", umax, ~0);
787 if (0 != strcmp (str0, str1)) printf ("Something wrong with umax : %s\n", str1);
788
789 TESTUMAX(8);
790 TESTUMAX(16);
791 TESTUMAX(32);
792#ifdef INT64_MAX
793 TESTUMAX(64);
794#endif
795
796 return EXIT_SUCCESS;
797}
798
799#endif
diff --git a/utils/MTP/beastpatcher/vs2005/beastpatcher.vcproj b/utils/MTP/beastpatcher/vs2005/beastpatcher.vcproj
new file mode 100644
index 0000000000..e0473e240a
--- /dev/null
+++ b/utils/MTP/beastpatcher/vs2005/beastpatcher.vcproj
@@ -0,0 +1,223 @@
1<?xml version="1.0" encoding="Windows-1252"?>
2<VisualStudioProject
3 ProjectType="Visual C++"
4 Version="8.00"
5 Name="beastpatcher"
6 ProjectGUID="{AF17AD8F-DE5E-4A2D-ABF9-721736F6FA72}"
7 RootNamespace="beastpatcher"
8 Keyword="Win32Proj"
9 >
10 <Platforms>
11 <Platform
12 Name="Win32"
13 />
14 </Platforms>
15 <ToolFiles>
16 </ToolFiles>
17 <Configurations>
18 <Configuration
19 Name="Debug|Win32"
20 OutputDirectory="$(SolutionDir)$(ConfigurationName)"
21 IntermediateDirectory="$(ConfigurationName)"
22 ConfigurationType="1"
23 CharacterSet="2"
24 >
25 <Tool
26 Name="VCPreBuildEventTool"
27 CommandLine=""
28 />
29 <Tool
30 Name="VCCustomBuildTool"
31 />
32 <Tool
33 Name="VCXMLDataGeneratorTool"
34 />
35 <Tool
36 Name="VCWebServiceProxyGeneratorTool"
37 />
38 <Tool
39 Name="VCMIDLTool"
40 />
41 <Tool
42 Name="VCCLCompilerTool"
43 Optimization="0"
44 AdditionalIncludeDirectories=""
45 PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE"
46 MinimalRebuild="true"
47 BasicRuntimeChecks="3"
48 RuntimeLibrary="0"
49 UsePrecompiledHeader="0"
50 WarningLevel="3"
51 Detect64BitPortabilityProblems="true"
52 DebugInformationFormat="4"
53 />
54 <Tool
55 Name="VCManagedResourceCompilerTool"
56 />
57 <Tool
58 Name="VCResourceCompilerTool"
59 />
60 <Tool
61 Name="VCPreLinkEventTool"
62 />
63 <Tool
64 Name="VCLinkerTool"
65 AdditionalDependencies="..\MTP_DLL.lib"
66 LinkIncremental="2"
67 GenerateDebugInformation="true"
68 SubSystem="1"
69 TargetMachine="1"
70 />
71 <Tool
72 Name="VCALinkTool"
73 />
74 <Tool
75 Name="VCManifestTool"
76 />
77 <Tool
78 Name="VCXDCMakeTool"
79 />
80 <Tool
81 Name="VCBscMakeTool"
82 />
83 <Tool
84 Name="VCFxCopTool"
85 />
86 <Tool
87 Name="VCAppVerifierTool"
88 />
89 <Tool
90 Name="VCWebDeploymentTool"
91 />
92 <Tool
93 Name="VCPostBuildEventTool"
94 CommandLine=""
95 />
96 </Configuration>
97 <Configuration
98 Name="Release|Win32"
99 OutputDirectory="$(SolutionDir)$(ConfigurationName)"
100 IntermediateDirectory="$(ConfigurationName)"
101 ConfigurationType="1"
102 CharacterSet="1"
103 WholeProgramOptimization="1"
104 >
105 <Tool
106 Name="VCPreBuildEventTool"
107 />
108 <Tool
109 Name="VCCustomBuildTool"
110 />
111 <Tool
112 Name="VCXMLDataGeneratorTool"
113 />
114 <Tool
115 Name="VCWebServiceProxyGeneratorTool"
116 />
117 <Tool
118 Name="VCMIDLTool"
119 />
120 <Tool
121 Name="VCCLCompilerTool"
122 AdditionalIncludeDirectories="&quot;$(InputDir)\..&quot;"
123 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE"
124 RuntimeLibrary="2"
125 UsePrecompiledHeader="0"
126 WarningLevel="3"
127 Detect64BitPortabilityProblems="true"
128 DebugInformationFormat="3"
129 />
130 <Tool
131 Name="VCManagedResourceCompilerTool"
132 />
133 <Tool
134 Name="VCResourceCompilerTool"
135 />
136 <Tool
137 Name="VCPreLinkEventTool"
138 />
139 <Tool
140 Name="VCLinkerTool"
141 AdditionalDependencies="..\MTP_DLL.lib"
142 LinkIncremental="1"
143 GenerateDebugInformation="true"
144 SubSystem="1"
145 OptimizeReferences="2"
146 EnableCOMDATFolding="2"
147 TargetMachine="1"
148 />
149 <Tool
150 Name="VCALinkTool"
151 />
152 <Tool
153 Name="VCManifestTool"
154 />
155 <Tool
156 Name="VCXDCMakeTool"
157 />
158 <Tool
159 Name="VCBscMakeTool"
160 />
161 <Tool
162 Name="VCFxCopTool"
163 />
164 <Tool
165 Name="VCAppVerifierTool"
166 />
167 <Tool
168 Name="VCWebDeploymentTool"
169 />
170 <Tool
171 Name="VCPostBuildEventTool"
172 />
173 </Configuration>
174 </Configurations>
175 <References>
176 </References>
177 <Files>
178 <Filter
179 Name="Source Files"
180 Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
181 UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
182 >
183 <File
184 RelativePath="..\beastpatcher.c"
185 >
186 </File>
187 <File
188 RelativePath="..\bootimg.c"
189 >
190 </File>
191 <File
192 RelativePath="..\mtp_win32.c"
193 >
194 </File>
195 </Filter>
196 <Filter
197 Name="Header Files"
198 Filter="h;hpp;hxx;hm;inl;inc;xsd"
199 UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
200 >
201 <File
202 RelativePath="..\bootimg.h"
203 >
204 </File>
205 <File
206 RelativePath="..\mtp_common.h"
207 >
208 </File>
209 <File
210 RelativePath="..\pstdint.h"
211 >
212 </File>
213 </Filter>
214 <Filter
215 Name="Resource Files"
216 Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
217 UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
218 >
219 </Filter>
220 </Files>
221 <Globals>
222 </Globals>
223</VisualStudioProject>
diff --git a/utils/MTP/sendfirm_win.c b/utils/MTP/sendfirm_win.c
index c16a7ab68b..3c45aa6ae7 100644
--- a/utils/MTP/sendfirm_win.c
+++ b/utils/MTP/sendfirm_win.c
@@ -19,7 +19,6 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21 21
22#define LPWSTR wchar_t*
23 22
24#include <stdio.h> 23#include <stdio.h>
25#include <string.h> 24#include <string.h>
@@ -27,8 +26,9 @@
27#include <stdlib.h> 26#include <stdlib.h>
28#include <wchar.h> 27#include <wchar.h>
29#include <stdbool.h> 28#include <stdbool.h>
29#include <windows.h>
30 30
31extern __declspec(dllimport) bool send_fw(LPWSTR file, int filesize, void (*callback)(unsigned int progress, unsigned int max)); 31#include "MTP_DLL/MTP_DLL.h"
32 32
33void usage(void) 33void usage(void)
34{ 34{
@@ -76,7 +76,7 @@ int main(int argc, char **argv)
76 76
77 fprintf(stdout, "Sending firmware...\n"); 77 fprintf(stdout, "Sending firmware...\n");
78 78
79 if(send_fw(tmp, filesize(argv[1]), &callback)) 79 if(mtp_sendnk(tmp, filesize(argv[1]), &callback))
80 fprintf(stdout, "Firmware sent successfully!\n"); 80 fprintf(stdout, "Firmware sent successfully!\n");
81 else 81 else
82 fprintf(stdout, "Error occured during sending!\n"); 82 fprintf(stdout, "Error occured during sending!\n");