360手机助手 v3.3.0版本的 MD5 值为:127c345ad16bbebee6e347381328afd0
以下内容为反编译后的 k.java 源代码,内容仅作参考
package a.a.a;
import com.qihoo.speedometer.Config;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PushbackInputStream;
import java.io.RandomAccessFile;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.StringTokenizer;
public class k implements l {
final a f15a;
private final r f16b;
private final OutputStream c;
private PushbackInputStream d;
private int e;
private int f;
private String g;
private m h;
private Map i;
private Map j;
private f k;
private String l;
public k(a aVar, r rVar, InputStream inputStream, OutputStream outputStream, InetAddress inetAddress) {
this.f15a = aVar;
this.f16b = rVar;
this.d = new PushbackInputStream(inputStream, 8192);
this.c = outputStream;
String str = (inetAddress.isLoopbackAddress() || inetAddress.isAnyLocalAddress()) ? "127.0.0.1" : inetAddress.getHostAddress().toString();
this.j = new HashMap();
this.j.put("remote-addr", str);
this.j.put("http-client-ip", str);
}
private int a(ByteBuffer byteBuffer, int i) {
while (i < byteBuffer.limit()) {
if (byteBuffer.get(i) == 13) {
i++;
if (byteBuffer.get(i) == 10) {
i++;
if (byteBuffer.get(i) == 13) {
i++;
if (byteBuffer.get(i) == 10) {
break;
}
} else {
continue;
}
} else {
continue;
}
}
i++;
}
return i + 1;
}
private int a(byte[] bArr, int i) {
for (int i2 = 0; i2 + 3 < i; i2++) {
if (bArr[i2] == 13 && bArr[i2 + 1] == 10 && bArr[i2 + 2] == 13 && bArr[i2 + 3] == 10) {
return i2 + 4;
}
}
return 0;
}
private String a(ByteBuffer byteBuffer, int i, int i2) {
FileOutputStream fileOutputStream;
String str = Config.INVALID_IP;
if (i2 > 0) {
try {
q a2 = this.f16b.a();
ByteBuffer duplicate = byteBuffer.duplicate();
fileOutputStream = new FileOutputStream(a2.b());
try {
try {
FileChannel channel = fileOutputStream.getChannel();
duplicate.position(i).limit(i + i2);
channel.write(duplicate.slice());
str = a2.b();
a.b(fileOutputStream);
} catch (Exception e) {
e = e;
System.err.println("Error: " + e.getMessage());
a.b(fileOutputStream);
return str;
}
} catch (Throwable th) {
th = th;
a.b(fileOutputStream);
throw th;
}
} catch (Exception e2) {
e = e2;
fileOutputStream = null;
} catch (Throwable th2) {
th = th2;
fileOutputStream = null;
a.b(fileOutputStream);
throw th;
}
}
return str;
}
private void a(BufferedReader bufferedReader, Map map, Map map2, Map map3) {
String a2;
try {
String readLine = bufferedReader.readLine();
if (readLine == null) {
return;
}
StringTokenizer stringTokenizer = new StringTokenizer(readLine);
if (!stringTokenizer.hasMoreTokens()) {
throw new p(o.BAD_REQUEST, "BAD REQUEST: Syntax error. Usage: GET /example/file.html");
}
map.put("method", stringTokenizer.nextToken());
if (!stringTokenizer.hasMoreTokens()) {
throw new p(o.BAD_REQUEST, "BAD REQUEST: Missing URI. Usage: GET /example/file.html");
}
String nextToken = stringTokenizer.nextToken();
int indexOf = nextToken.indexOf(63);
if (indexOf >= 0) {
a(nextToken.substring(indexOf + 1), map2);
a2 = this.f15a.a(nextToken.substring(0, indexOf));
} else {
a2 = this.f15a.a(nextToken);
}
if (stringTokenizer.hasMoreTokens()) {
String readLine2 = bufferedReader.readLine();
while (readLine2 != null && readLine2.trim().length() > 0) {
int indexOf2 = readLine2.indexOf(58);
if (indexOf2 >= 0) {
map3.put(readLine2.substring(0, indexOf2).trim().toLowerCase(Locale.US), readLine2.substring(indexOf2 + 1).trim());
}
readLine2 = bufferedReader.readLine();
}
}
map.put("uri", a2);
} catch (IOException e) {
throw new p(o.INTERNAL_ERROR, "SERVER INTERNAL ERROR: IOException: " + e.getMessage(), e);
}
}
private void a(String str, ByteBuffer byteBuffer, BufferedReader bufferedReader, Map map, Map map2) {
try {
int[] a2 = a(byteBuffer, str.getBytes());
int i = 1;
String readLine = bufferedReader.readLine();
while (readLine != null) {
if (!readLine.contains(str)) {
throw new p(o.BAD_REQUEST, "BAD REQUEST: Content type is multipart/form-data but next chunk does not start with boundary. Usage: GET /example/file.html");
}
int i2 = i + 1;
HashMap hashMap = new HashMap();
readLine = bufferedReader.readLine();
while (readLine != null && readLine.trim().length() > 0) {
int indexOf = readLine.indexOf(58);
if (indexOf != -1) {
hashMap.put(readLine.substring(0, indexOf).trim().toLowerCase(Locale.US), readLine.substring(indexOf + 1).trim());
}
readLine = bufferedReader.readLine();
}
if (readLine != null) {
String str2 = (String) hashMap.get("content-disposition");
if (str2 == null) {
throw new p(o.BAD_REQUEST, "BAD REQUEST: Content type is multipart/form-data but no content-disposition info found. Usage: GET /example/file.html");
}
StringTokenizer stringTokenizer = new StringTokenizer(str2, "; ");
HashMap hashMap2 = new HashMap();
while (stringTokenizer.hasMoreTokens()) {
String nextToken = stringTokenizer.nextToken();
int indexOf2 = nextToken.indexOf(61);
if (indexOf2 != -1) {
hashMap2.put(nextToken.substring(0, indexOf2).trim().toLowerCase(Locale.US), nextToken.substring(indexOf2 + 1).trim());
}
}
String substring = ((String) hashMap2.get("name")).substring(1, r0.length() - 1);
String str3 = Config.INVALID_IP;
if (hashMap.get("content-type") != null) {
if (i2 <= a2.length) {
map2.put(substring, a(byteBuffer, a(byteBuffer, a2[i2 - 2]), (a2[i2 - 1] - r0) - 4));
str3 = ((String) hashMap2.get("filename")).substring(1, r0.length() - 1);
do {
readLine = bufferedReader.readLine();
if (readLine == null) {
break;
}
} while (!readLine.contains(str));
} else {
throw new p(o.INTERNAL_ERROR, "Error processing request");
}
} else {
while (readLine != null && !readLine.contains(str)) {
readLine = bufferedReader.readLine();
if (readLine != null) {
int indexOf3 = readLine.indexOf(str);
str3 = indexOf3 == -1 ? String.valueOf(str3) + readLine : String.valueOf(str3) + readLine.substring(0, indexOf3 - 2);
}
}
}
map.put(substring, str3);
}
i = i2;
}
} catch (IOException e) {
throw new p(o.INTERNAL_ERROR, "SERVER INTERNAL ERROR: IOException: " + e.getMessage(), e);
}
}
private void a(String str, Map map) {
if (str == null) {
this.l = Config.INVALID_IP;
return;
}
this.l = str;
StringTokenizer stringTokenizer = new StringTokenizer(str, "&");
while (stringTokenizer.hasMoreTokens()) {
String nextToken = stringTokenizer.nextToken();
int indexOf = nextToken.indexOf(61);
if (indexOf >= 0) {
map.put(this.f15a.a(nextToken.substring(0, indexOf)).trim(), this.f15a.a(nextToken.substring(indexOf + 1)));
} else {
map.put(this.f15a.a(nextToken).trim(), Config.INVALID_IP);
}
}
}
private int[] a(ByteBuffer byteBuffer, byte[] bArr) {
ArrayList arrayList = new ArrayList();
int i = 0;
int i2 = -1;
int i3 = 0;
while (i < byteBuffer.limit()) {
if (byteBuffer.get(i) == bArr[i3]) {
if (i3 == 0) {
i2 = i;
}
i3++;
if (i3 == bArr.length) {
arrayList.add(Integer.valueOf(i2));
i2 = -1;
i3 = 0;
}
} else {
i -= i3;
i2 = -1;
i3 = 0;
}
i++;
}
int[] iArr = new int[arrayList.size()];
for (int i4 = 0; i4 < iArr.length; i4++) {
iArr[i4] = ((Integer) arrayList.get(i4)).intValue();
}
return iArr;
}
private RandomAccessFile g() {
try {
return new RandomAccessFile(this.f16b.a().b(), "rw");
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
return null;
}
}
public void a() {
try {
try {
try {
byte[] bArr = new byte[8192];
this.e = 0;
this.f = 0;
try {
int read = this.d.read(bArr, 0, 8192);
if (read == -1) {
a.b(this.d);
a.b(this.c);
throw new SocketException("NanoHttpd Shutdown");
}
while (read > 0) {
this.f = read + this.f;
this.e = a(bArr, this.f);
if (this.e > 0) {
break;
} else {
read = this.d.read(bArr, this.f, 8192 - this.f);
}
}
if (this.e < this.f) {
this.d.unread(bArr, this.e, this.f - this.e);
}
this.i = new HashMap();
if (this.j == null) {
this.j = new HashMap();
}
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(bArr, 0, this.f)));
HashMap hashMap = new HashMap();
a(bufferedReader, hashMap, this.i, this.j);
this.h = m.a((String) hashMap.get("method"));
if (this.h == null) {
throw new p(o.BAD_REQUEST, "BAD REQUEST: Syntax error.");
}
this.g = (String) hashMap.get("uri");
this.k = new f(this.f15a, this.j);
n a2 = this.f15a.a(this);
if (a2 == null) {
throw new p(o.INTERNAL_ERROR, "SERVER INTERNAL ERROR: Serve() returned a null response.");
}
this.k.a(a2);
a2.a(this.h);
a2.a(this.c);
this.f16b.b();
} catch (Exception e) {
a.b(this.d);
a.b(this.c);
throw new SocketException("NanoHttpd Shutdown");
}
} catch (Throwable th) {
this.f16b.b();
throw th;
}
} catch (SocketException e2) {
throw e2;
} catch (IOException e3) {
new n(o.INTERNAL_ERROR, "text/plain", "SERVER INTERNAL ERROR: IOException: " + e3.getMessage()).a(this.c);
a.b(this.c);
this.f16b.b();
}
} catch (p e4) {
new n(e4.a(), "text/plain", e4.getMessage()).a(this.c);
a.b(this.c);
this.f16b.b();
} catch (SocketTimeoutException e5) {
throw e5;
}
}
@Override
public void a(Map map) {
BufferedReader bufferedReader;
RandomAccessFile randomAccessFile = null;
StringTokenizer stringTokenizer = null;
try {
RandomAccessFile g = g();
try {
long parseInt = this.j.containsKey("content-length") ? Integer.parseInt((String) this.j.get("content-length")) : this.e < this.f ? this.f - this.e : 0L;
byte[] bArr = new byte[512];
while (this.f >= 0 && parseInt > 0) {
this.f = this.d.read(bArr, 0, (int) Math.min(parseInt, 512L));
parseInt -= this.f;
if (this.f > 0) {
g.write(bArr, 0, this.f);
}
}
MappedByteBuffer map2 = g.getChannel().map(FileChannel.MapMode.READ_ONLY, 0L, g.length());
g.seek(0L);
bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(g.getFD())));
try {
if (m.POST.equals(this.h)) {
String str = Config.INVALID_IP;
String str2 = (String) this.j.get("content-type");
if (str2 != null) {
stringTokenizer = new StringTokenizer(str2, ",; ");
if (stringTokenizer.hasMoreTokens()) {
str = stringTokenizer.nextToken();
}
}
if (!"multipart/form-data".equalsIgnoreCase(str)) {
String str3 = Config.INVALID_IP;
StringBuilder sb = new StringBuilder();
char[] cArr = new char[512];
for (int read = bufferedReader.read(cArr); read >= 0 && !str3.endsWith("\r\n"); read = bufferedReader.read(cArr)) {
str3 = String.valueOf(cArr, 0, read);
sb.append(str3);
}
a(sb.toString().trim(), this.i);
} else {
if (!stringTokenizer.hasMoreTokens()) {
throw new p(o.BAD_REQUEST, "BAD REQUEST: Content type is multipart/form-data but boundary missing. Usage: GET /example/file.html");
}
String substring = str2.substring("boundary=".length() + str2.indexOf("boundary="), str2.length());
if (substring.startsWith("\"") && substring.endsWith("\"")) {
substring = substring.substring(1, substring.length() - 1);
}
a(substring, map2, bufferedReader, this.i, map);
}
} else if (m.PUT.equals(this.h)) {
map.put("content", a(map2, 0, map2.limit()));
}
a.b(g);
a.b(bufferedReader);
} catch (Throwable th) {
th = th;
randomAccessFile = g;
a.b(randomAccessFile);
a.b(bufferedReader);
throw th;
}
} catch (Throwable th2) {
th = th2;
bufferedReader = null;
randomAccessFile = g;
}
} catch (Throwable th3) {
th = th3;
bufferedReader = null;
}
}
@Override
public final Map b() {
return this.i;
}
@Override
public String c() {
return this.l;
}
@Override
public final Map d() {
return this.j;
}
@Override
public final String e() {
return this.g;
}
@Override
public final m f() {
return this.h;
}
}