Skip to content

Commit 22f6a46

Browse files
Support for Microsoft Update
1 parent db3df1b commit 22f6a46

File tree

9 files changed

+36
-8
lines changed

9 files changed

+36
-8
lines changed

src/io/github/explodingbottle/jmagicproxy/implementation/WUProxy.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public WUProxy() {
4343

4444
private static final String DLREP1_REPLACEMENT = "/v9/windowsupdate/a/selfupdate/";
4545
private static final String DLREP2_REPLACEMENT = "/v11/3/windowsupdate/selfupdate/";
46+
private static final String MU_DLREP1_REPLACEMENT = "/v9/microsoftupdate/a/selfupdate/";
47+
private static final String MU_DLREP2_REPLACEMENT = "/v9/1/microsoftupdate/b/selfupdate/";
4648

4749
@Override
4850
public ConnectionDirective onReceiveProxyRequest(HttpRequestHeader request) {
@@ -70,6 +72,21 @@ public ConnectionDirective onReceiveProxyRequest(HttpRequestHeader request) {
7072
}
7173
}
7274

75+
if (ProxyMain.getPropertiesProvider().getAsBoolean(PropertyKey.WUPROXY_REDIRECT_WUCLIENT)) {
76+
if (request.getHost().toLowerCase().contains(MU_DLREP2_REPLACEMENT)) {
77+
computed.setHost("download.windowsupdate.com");
78+
computed.setPort(80);
79+
String preHost = computed.getOutcomingRequest().getHost();
80+
computed.getOutcomingRequest()
81+
.setHost(preHost.toLowerCase().replace(MU_DLREP2_REPLACEMENT, MU_DLREP1_REPLACEMENT));
82+
if (computed.getOutcomingRequest() != null) {
83+
computed.getOutcomingRequest().getHeaders().put("Host", "download.windowsupdate.com");
84+
}
85+
logger.log(LoggingLevel.INFO,
86+
"Replaced " + preHost + " by " + computed.getOutcomingRequest().getHost() + ".");
87+
}
88+
}
89+
7390
if (request.getHost().toLowerCase().contains("/windowsupdate/v6/shared/js/redirect.js")
7491
|| request.getHost().toLowerCase().contains("/microsoftupdate/v6/shared/js/redirect.js")) {
7592
logger.log(LoggingLevel.INFO, "Found a redirect.js request.");

src/io/github/explodingbottle/jmagicproxy/proxy/ConnectionDirectiveHandler.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@
2222
import java.io.InputStream;
2323
import java.io.OutputStream;
2424
import java.net.Socket;
25+
import java.text.SimpleDateFormat;
2526
import java.util.ArrayList;
2627
import java.util.Collections;
28+
import java.util.Date;
2729
import java.util.List;
30+
import java.util.Locale;
31+
import java.util.TimeZone;
2832

2933
import io.github.explodingbottle.jmagicproxy.ProxyMain;
3034
import io.github.explodingbottle.jmagicproxy.api.ConnectionDirective;
@@ -228,13 +232,6 @@ public void openSocket() {
228232
try {
229233

230234
openingTool.run();
231-
/*
232-
* referenceSocket = new Socket(InetAddress.getByName(directive.getHost()),
233-
* directive.getPort()); inputStream = referenceSocket.getInputStream();
234-
* outputStream = referenceSocket.getOutputStream(); rewriteDirectiveLine();
235-
* pipeThread = new SimpleInputOutputPipeThread(inputStream,
236-
* handlerThread.getOutputStream(), this); pipeThread.start();
237-
*/
238235
} catch (Exception e) {
239236
logger.log(LoggingLevel.WARN, "Failed to open the outgoing socket.", e);
240237
closeSocket();
@@ -246,6 +243,12 @@ public void openSocket() {
246243
inputStream = new FileInputStream(directive.getFileInput());
247244
handlerThread.getOutputStream().write(new String("HTTP/1.1 200 OK\r\n").getBytes());
248245
handlerThread.getOutputStream().write(new String("Connection: Keep-Alive\r\n").getBytes());
246+
SimpleDateFormat f = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
247+
f.setTimeZone(TimeZone.getTimeZone("GMT"));
248+
String lM = f.format(new Date(directive.getFileInput().lastModified()));
249+
handlerThread.getOutputStream().write(new String("Last-Modified: " + lM + "\r\n").getBytes());
250+
handlerThread.getOutputStream()
251+
.write(new String("Content-Type: application/octet-stream\r\n").getBytes());
249252
handlerThread.getOutputStream().write(
250253
new String("Content-Length: " + directive.getFileInput().length() + "\r\n\r\n").getBytes());
251254
pipeThread = new SimpleInputOutputPipeThread(inputStream, handlerThread.getOutputStream(), this);

src/io/github/explodingbottle/jmagicproxy/proxy/ssl/SSLCommunicationServer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ public void run() {
240240
int read = heartInput.read(buffer, 0, buffer.length);
241241
while (!interrupted() && read != -1) {
242242
Integer offset = handleLineRead(read);
243-
;
244243
if (offset != null) {
245244
if (outgoingHandler != null)
246245
outgoingHandler.feedOutput(buffer, offset, read - offset);

src/io/github/explodingbottle/jmagicproxy/proxy/ssl/SSLDirectiveHandler.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@
2222
import java.io.InputStream;
2323
import java.io.OutputStream;
2424
import java.net.Socket;
25+
import java.text.SimpleDateFormat;
2526
import java.util.ArrayList;
2627
import java.util.Collections;
28+
import java.util.Date;
2729
import java.util.List;
30+
import java.util.Locale;
31+
import java.util.TimeZone;
2832

2933
import javax.net.ssl.SSLSocket;
3034

@@ -117,6 +121,11 @@ public void openSocket() {
117121
inputStream = new FileInputStream(directive.getFileInput());
118122
parent.getHeartOutput().write(new String("HTTP/1.1 200 OK\r\n").getBytes());
119123
parent.getHeartOutput().write(new String("Connection: Keep-Alive\r\n").getBytes());
124+
SimpleDateFormat f = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
125+
f.setTimeZone(TimeZone.getTimeZone("GMT"));
126+
String lM = f.format(new Date(directive.getFileInput().lastModified()));
127+
parent.getHeartOutput().write(new String("Last-Modified: " + lM + "\r\n").getBytes());
128+
parent.getHeartOutput().write(new String("Content-Type: application/octet-stream\r\n").getBytes());
120129
parent.getHeartOutput().write(
121130
new String("Content-Length: " + directive.getFileInput().length() + "\r\n\r\n").getBytes());
122131
ioPipe = new SSLInputOutputPipeThread(inputStream, parent.getHeartOutput(), this);

wiki_images/mu/cscript.png

737 KB
Loading

wiki_images/mu/detectnow.png

755 KB
Loading

wiki_images/mu/mu_ui.png

707 KB
Loading

wiki_images/mu/mu_web.png

101 KB
Loading

wiki_images/mu/winupd_options.png

691 KB
Loading

0 commit comments

Comments
 (0)