summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/MTP/beastpatcher/Makefile11
-rw-r--r--utils/MTP/beastpatcher/README4
-rw-r--r--utils/MTP/beastpatcher/beastpatcher.c2
-rw-r--r--utils/MTP/beastpatcher/mtp_common.h3
-rw-r--r--utils/MTP/beastpatcher/mtp_libmtp.c2
-rw-r--r--utils/MTP/beastpatcher/mtp_win32.c174
6 files changed, 183 insertions, 13 deletions
diff --git a/utils/MTP/beastpatcher/Makefile b/utils/MTP/beastpatcher/Makefile
index edd08b1248..c0c82df53b 100644
--- a/utils/MTP/beastpatcher/Makefile
+++ b/utils/MTP/beastpatcher/Makefile
@@ -3,20 +3,17 @@ CFLAGS=-Wall -W
3ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN) 3ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN)
4OUTPUT=beastpatcher.exe 4OUTPUT=beastpatcher.exe
5CROSS= 5CROSS=
6CFLAGS+=-mno-cygwin
6else 7else
7OUTPUT=beastpatcher 8OUTPUT=beastpatcher
8CROSS=i586-mingw32msvc- 9CROSS=i586-mingw32msvc-
9endif 10endif
10 11
11ifeq ($(OUTPUT),beastpatcher)
12LIBS = /usr/lib/libmtp.a /usr/lib/libusb.a 12LIBS = /usr/lib/libmtp.a /usr/lib/libusb.a
13CFLAGS += $(shell printf \ 13CFLAGS += $(shell printf \
14 '\#include <libmtp.h>\nlibmtp version: LIBMTP_VERSION\n' | \ 14 '\#include <libmtp.h>\nlibmtp version: LIBMTP_VERSION\n' | \
15 gcc -E -P - -o - | grep -q '^libmtp version: 0\.2' && echo '-DOLDMTP') 15 gcc -E -P - -o - | grep -q '^libmtp version: 0\.2' && echo '-DOLDMTP')
16else 16WINLIBS = ../MTP_DLL.dll
17CFLAGS+=-mno-cygwin
18LIBS = ../MTP_DLL.dll
19endif
20 17
21NATIVECC = gcc 18NATIVECC = gcc
22CC = $(CROSS)gcc 19CC = $(CROSS)gcc
@@ -27,8 +24,8 @@ beastpatcher: beastpatcher.c bootimg.c mtp_common.h mtp_libmtp.c
27 gcc $(CFLAGS) -o beastpatcher beastpatcher.c bootimg.c mtp_libmtp.c $(LIBS) 24 gcc $(CFLAGS) -o beastpatcher beastpatcher.c bootimg.c mtp_libmtp.c $(LIBS)
28 strip beastpatcher 25 strip beastpatcher
29 26
30beastpatcher.exe: beastpatcher.c bootimg.c mtp_common.h mtp_win32.c $(LIBS) 27beastpatcher.exe: beastpatcher.c bootimg.c mtp_common.h mtp_win32.c $(WINLIBS)
31 $(CROSS)$(CC) $(CFLAGS) $(LIBS) -o beastpatcher.exe beastpatcher.c bootimg.c 28 $(CC) $(CFLAGS) -o beastpatcher.exe beastpatcher.c bootimg.c mtp_win32.c $(WINLIBS)
32 $(CROSS)strip beastpatcher.exe 29 $(CROSS)strip beastpatcher.exe
33 30
34beastpatcher-mac: beastpatcher-i386 beastpatcher-ppc 31beastpatcher-mac: beastpatcher-i386 beastpatcher-ppc
diff --git a/utils/MTP/beastpatcher/README b/utils/MTP/beastpatcher/README
index 85a039268a..42968b0022 100644
--- a/utils/MTP/beastpatcher/README
+++ b/utils/MTP/beastpatcher/README
@@ -50,8 +50,6 @@ The OS X build is a universal binary statically linked with libusb and libmtp.
50Windows 50Windows
51------- 51-------
52 52
53[Not yet implemented]
54
55The MTP_DLL.dll requires VC2005 to compile - see instructions in 53The MTP_DLL.dll requires VC2005 to compile - see instructions in
56MTP_DLL/README 54MTP_DLL/README
57 55
@@ -59,3 +57,5 @@ To compile beastpatcher itself, you can either cross-compile from
59Linux using the mingw32 package, or compile in Cygwin. Just type 57Linux using the mingw32 package, or compile in Cygwin. Just type
60"make beastpatcher.exe" (in Linux) or "make" (in Cygwin). 58"make beastpatcher.exe" (in Linux) or "make" (in Cygwin).
61 59
60To run beastpatcher.exe, you need MTP_DLL.dll in the same directory
61(or the Windows DLL path).
diff --git a/utils/MTP/beastpatcher/beastpatcher.c b/utils/MTP/beastpatcher/beastpatcher.c
index 8043ebadc2..0ba324883a 100644
--- a/utils/MTP/beastpatcher/beastpatcher.c
+++ b/utils/MTP/beastpatcher/beastpatcher.c
@@ -6,7 +6,7 @@
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * 8 *
9 * $Id:$ 9 * $Id$
10 * 10 *
11 * Copyright (c) 2009, Dave Chapman 11 * Copyright (c) 2009, Dave Chapman
12 * All rights reserved. 12 * All rights reserved.
diff --git a/utils/MTP/beastpatcher/mtp_common.h b/utils/MTP/beastpatcher/mtp_common.h
index 2fb52a9e81..5f7de3983b 100644
--- a/utils/MTP/beastpatcher/mtp_common.h
+++ b/utils/MTP/beastpatcher/mtp_common.h
@@ -6,7 +6,7 @@
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * 8 *
9 * $Id:$ 9 * $Id$
10 * 10 *
11 * Copyright (c) 2009, Dave Chapman 11 * Copyright (c) 2009, Dave Chapman
12 * All rights reserved. 12 * All rights reserved.
@@ -41,7 +41,6 @@
41#define _MTP_COMMON_H 41#define _MTP_COMMON_H
42 42
43#ifdef __WIN32__ 43#ifdef __WIN32__
44#error Windows support not yet implemented
45#else 44#else
46#include "libmtp.h" 45#include "libmtp.h"
47#endif 46#endif
diff --git a/utils/MTP/beastpatcher/mtp_libmtp.c b/utils/MTP/beastpatcher/mtp_libmtp.c
index 7e8579ac99..9ada7bfeea 100644
--- a/utils/MTP/beastpatcher/mtp_libmtp.c
+++ b/utils/MTP/beastpatcher/mtp_libmtp.c
@@ -6,7 +6,7 @@
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * 8 *
9 * $Id:$ 9 * $Id$
10 * 10 *
11 * Copyright (c) 2009, Dave Chapman 11 * Copyright (c) 2009, Dave Chapman
12 * All rights reserved. 12 * All rights reserved.
diff --git a/utils/MTP/beastpatcher/mtp_win32.c b/utils/MTP/beastpatcher/mtp_win32.c
new file mode 100644
index 0000000000..f68faddbc2
--- /dev/null
+++ b/utils/MTP/beastpatcher/mtp_win32.c
@@ -0,0 +1,174 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * $Id$
10 *
11 * Copyright (c) 2009, Dave Chapman
12 * All rights reserved.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met:
17 *
18 * * Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 *
21 * * Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials provided
24 * with the distribution.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 *
38 *
39 ****************************************************************************/
40
41#include <stdio.h>
42#include <string.h>
43#include <stddef.h>
44#include <stdlib.h>
45#include <wchar.h>
46#include <stdbool.h>
47#include <windows.h>
48#include <tchar.h>
49
50#include "mtp_common.h"
51
52
53extern __declspec(dllimport) bool send_fw(LPWSTR file, int filesize,
54 void (*callback)(unsigned int progress, unsigned int max));
55
56int mtp_init(struct mtp_info_t* mtp_info)
57{
58 /* Fill the info struct with zeros - mainly for the strings */
59 memset(mtp_info, 0, sizeof(struct mtp_info_t));
60
61 return 0;
62
63}
64
65int mtp_finished(struct mtp_info_t* mtp_info)
66{
67 (void)mtp_info;
68
69 return 0;
70}
71
72int mtp_scan(struct mtp_info_t* mtp_info)
73{
74 strcpy(mtp_info->manufacturer,"<unknown>");
75 strcpy(mtp_info->modelname,"<unknown>");
76 strcpy(mtp_info->version,"<unknown>");
77
78 return 0;
79
80}
81
82static void callback(unsigned int progress, unsigned int max)
83{
84 int percent = (progress * 100) / max;
85
86 printf("Progress: %u of %u (%d%%)\r", progress, max, percent);
87 fflush(stdout);
88}
89
90
91int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
92 int fwsize)
93{
94 HANDLE hTempFile;
95 DWORD dwRetVal;
96 DWORD dwBytesWritten;
97 UINT uRetVal;
98 TCHAR szTempName[1024];
99 TCHAR lpPathBuffer[1024];
100 BOOL fSuccess;
101 wchar_t *tmp;
102 int ret;
103
104 (void)mtp_info;
105
106 /* Get the path for temporary files */
107 dwRetVal = GetTempPath(sizeof(lpPathBuffer), lpPathBuffer);
108 if (dwRetVal > sizeof(lpPathBuffer) || (dwRetVal == 0))
109 {
110 fprintf(stderr, "[ERR] GetTempPath failed (%d)\n", (int)GetLastError());
111 return -1;
112 }
113
114 /* Create the temporary file */
115 uRetVal = GetTempFileName(lpPathBuffer, TEXT("NKBIN"), 0, szTempName);
116 if (uRetVal == 0)
117 {
118 fprintf(stderr, "[ERR] GetTempFileName failed (%d)\n", (int)GetLastError());
119 return -1;
120 }
121
122 /* Now create the file */
123 hTempFile = CreateFile((LPTSTR) szTempName, // file name
124 GENERIC_READ | GENERIC_WRITE, // open r-w
125 0, // do not share
126 NULL, // default security
127 CREATE_ALWAYS, // overwrite existing
128 FILE_ATTRIBUTE_NORMAL,// normal file
129 NULL); // no template
130 if (hTempFile == INVALID_HANDLE_VALUE)
131 {
132 fprintf(stderr, "[ERR] Could not create %s\n", szTempName);
133 return -1;
134 }
135
136 fSuccess = WriteFile(hTempFile, fwbuf, fwsize, &dwBytesWritten, NULL);
137 if (!fSuccess)
138 {
139 fprintf(stderr, "[ERR] WriteFile failed (%d)\n", (int)GetLastError());
140 return -1;
141 }
142
143 fSuccess = CloseHandle (hTempFile);
144 if (!fSuccess)
145 {
146 fprintf(stderr, "[ERR] CloseHandle failed (%d)\n", (int)GetLastError());
147 return -1;
148 }
149
150 tmp = (LPWSTR)malloc(strlen(szTempName)*2+1);
151 mbstowcs(tmp, szTempName, strlen(szTempName)*2+1);
152
153 fprintf(stderr, "[INFO] Sending firmware...\n");
154 if (send_fw(tmp, fwsize, &callback))
155 {
156 fprintf(stderr, "[INFO] Firmware sent successfully\n");
157 ret = 0;
158 }
159 else
160 {
161 fprintf(stderr, "[ERR] Error occured during sending.\n");
162 ret = -1;
163 }
164
165 /* Keep the progress line onscreen */
166 printf("\n");
167
168 free(tmp);
169
170 if (!DeleteFile(szTempName))
171 fprintf(stderr,"[WARN] Could not remove temporary file %s\n",szTempName);
172
173 return ret;
174}