-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial proxy implementation #1
base: main
Are you sure you want to change the base?
Changes from all commits
352222e
db999a7
28d2adf
4bce5e1
f278197
0d1de19
7ff6fce
1a3768d
42353be
f5415c3
e172f67
5f7aa02
658dc83
39d9164
b5c46ff
84fa584
5a5a8cb
14c326e
5512bc1
2779048
04f02eb
da5d110
4884b2f
6c33921
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/proxy/out/ | ||
/proxy/.idea | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.trimlighthacking; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider com.knottysoftware.trimlight.proxy? You should generally own the domain you use for your package name. |
||
|
||
import java.util.Arrays; | ||
|
||
public class BuiltInPatternSetRequest extends Request { | ||
private final int fixedUnknown1; | ||
private final int fixedUnknown2; | ||
|
||
public BuiltInPatternSetRequest(byte[] buffer) { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whitespace? |
||
|
||
this.fixedUnknown1 = buffer[2] & 0xFF; | ||
this.fixedUnknown2 = buffer[3] & 0xFF; | ||
|
||
this.PatternIndex = buffer[4] & 0xFF; | ||
this.Speed = buffer[5] & 0xFF; | ||
this.Brightness = buffer[6] & 0xFF; | ||
// Reduce to interesting slice | ||
this.rawBytes = Arrays.copyOfRange(buffer, 2, buffer.length - 1); | ||
} | ||
|
||
int PatternIndex; // TODO: Enumerate names | ||
int Speed; | ||
int Brightness; | ||
|
||
public String toString() { | ||
return String.format("%s <Built-In Pattern Set Request> Index: %s Speed: %d Brightness: %d Unknowns: (Fixed: %02X %02X)", this.LogPrefix, PatternIndex, Speed, Brightness, fixedUnknown1, fixedUnknown2); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.trimlighthacking; | ||
|
||
public class ByteArrayFormatter { | ||
public static String format(byte[] bytes, int count) { | ||
StringBuilder out = new StringBuilder(bytes.length * 3); | ||
out.append("\n "); | ||
if(count > bytes.length) { | ||
throw new IllegalArgumentException(String.format("Count %d is greater than buffer length %d", count, bytes.length)); | ||
} | ||
for(int i = 0; i < count; i++) { | ||
byte b = bytes[i]; | ||
if((b & 0xFF) < 32) { | ||
out.append(String.format("^%s ", (char)((b & 0xFF) + 64))); | ||
} else if((b & 0xFF) < 128) { | ||
out.append(String.format(" %s ", (char)(b))); | ||
} | ||
else { | ||
out.append(" "); | ||
} | ||
|
||
} | ||
out.append("\n "); | ||
for(int i = 0; i < count; i++) { | ||
out.append(String.format("%02X ", bytes[i])); | ||
} | ||
return out.toString(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.trimlighthacking; | ||
|
||
import java.util.Arrays; | ||
import java.util.Calendar; | ||
import java.util.GregorianCalendar; | ||
|
||
public class ConnectionRequest extends Request { | ||
private final int fixedUnknown1; | ||
private final int fixedUnknown2; | ||
private final int varUnknown1; | ||
private final int varUnknown2; | ||
private final int varUnknown3; | ||
|
||
public ConnectionRequest(byte[] buffer) { | ||
// We don't know what indices 2-6 are used for yet. | ||
int year = buffer[7] & 0xff; | ||
int month = buffer[8] & 0xff; | ||
int day = buffer[9] & 0xff; | ||
int hour = buffer[11] & 0xff; | ||
int minute = buffer[12] & 0xff; | ||
int second = buffer[13] & 0xff; | ||
|
||
this.fixedUnknown1 = buffer[2] & 0xff; | ||
this.fixedUnknown2 = buffer[3] & 0xff; | ||
this.varUnknown1 = buffer[4] & 0xff; | ||
this.varUnknown2 = buffer[5] & 0xff; | ||
this.varUnknown3 = buffer[6] & 0xff; | ||
|
||
Calendar calendar = new GregorianCalendar(); | ||
|
||
calendar.set(Calendar.YEAR, year); | ||
calendar.set(Calendar.MONTH, month - 1); | ||
calendar.set(Calendar.DAY_OF_MONTH, day); | ||
calendar.set(Calendar.HOUR, hour); | ||
calendar.set(Calendar.MINUTE, minute); | ||
calendar.set(Calendar.SECOND, second); | ||
this.ConnectionStartDate = calendar; | ||
|
||
// Reduce to interesting slice | ||
this.rawBytes = Arrays.copyOfRange(buffer, 2, buffer.length - 1); | ||
} | ||
|
||
public final Calendar ConnectionStartDate; | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("%s <Connection Request> Connection Started: %s Unknowns: (Fixed: %02X %02X Var: %02X %02X %02X)", this.LogPrefix, this.ConnectionStartDate.getTime().toString(), fixedUnknown1, fixedUnknown2, varUnknown1, varUnknown2, varUnknown3); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.trimlighthacking; | ||
|
||
import java.util.Arrays; | ||
|
||
public class ConnectionResponse extends Response { | ||
|
||
private final int varUnknown1; | ||
private final int fixedUnknown1; | ||
private final int fixedUnknown2; | ||
private final int fixedUnknown3; | ||
private final int fixedUnknown4; | ||
private final int fixedUnknown5; | ||
|
||
public ConnectionResponse(byte[] buffer) { | ||
|
||
this.varUnknown1 = buffer[1] & 0xff; | ||
this.fixedUnknown1 = buffer[2] & 0xff; | ||
int hostnameLength = buffer[3] & 0xff; | ||
int hostnameEnd = 4 + hostnameLength; | ||
byte[] hostname = Arrays.copyOfRange(buffer, 4, hostnameEnd); | ||
this.HostName = new String(hostname); | ||
this.fixedUnknown2 = buffer[hostnameEnd] & 0xff; | ||
this.fixedUnknown3 = buffer[hostnameEnd + 1] & 0xff; | ||
this.PixelCount = (((buffer[hostnameEnd + 2] & 0xff) << 8) + (buffer[hostnameEnd + 3] & 0xff)); | ||
this.fixedUnknown4 = buffer[hostnameEnd + 4] & 0xff; | ||
this.fixedUnknown5 = buffer[hostnameEnd + 5] & 0xff; | ||
// Reduce to interesting slice | ||
this.rawBytes = Arrays.copyOfRange(buffer, 2, buffer.length - 1); | ||
} | ||
|
||
public String HostName; | ||
public int PixelCount; | ||
@Override | ||
public String toString() { | ||
return String.format("%s <Connection Response> HostName: %s PixelCount: %d Unknowns: (Fixed: %02X %02X %02X %02X %02X Var: %02X)", this.LogPrefix, this.HostName, this.PixelCount, fixedUnknown1, fixedUnknown2, fixedUnknown3, fixedUnknown4, fixedUnknown5, varUnknown1); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.trimlighthacking; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStreamWriter; | ||
import java.io.PrintWriter; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
System.out.println("TrimLight Proxy v0.000001"); | ||
|
||
Server s = new Server(System.out, 12); // log stream, max connections | ||
try { | ||
s.addService(new TrimlightProxyServer("192.168.254.50", 8189), 8189); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.trimlighthacking; | ||
|
||
public class MalformedBufferException extends RuntimeException { | ||
public MalformedBufferException(String message, byte[] buffer) { | ||
super(message); | ||
this.buffer = buffer; | ||
} | ||
|
||
public MalformedBufferException(String message, Throwable cause, byte[] buffer) { | ||
super(message, cause); | ||
this.buffer = buffer; | ||
} | ||
|
||
public MalformedBufferException(Throwable cause, byte[] buffer) { | ||
super(cause); | ||
this.buffer = buffer; | ||
} | ||
|
||
public final byte[] buffer; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.trimlighthacking; | ||
|
||
import java.util.Arrays; | ||
|
||
public class PatternEntryRequest extends Request { | ||
private final int fixedUnknown1; | ||
private final int fixedUnknown2; | ||
|
||
public PatternEntryRequest(byte[] buffer) { | ||
this.fixedUnknown1 = buffer[2] & 0xFF; | ||
this.fixedUnknown2 = buffer[3] & 0xFF; | ||
|
||
this.PatternIndex = buffer[4] & 0xFF; | ||
// Reduce to interesting slice | ||
this.rawBytes = Arrays.copyOfRange(buffer, 2, buffer.length - 1); | ||
} | ||
|
||
public int PatternIndex; | ||
|
||
public String toString() { | ||
return String.format("%s <Pattern Entry Request> Index: %d Unknowns: (Fixed: %02X %02X)", this.LogPrefix, this.PatternIndex, fixedUnknown1, fixedUnknown2); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.trimlighthacking; | ||
|
||
import sun.plugin2.util.ColorUtil; | ||
|
||
import java.awt.*; | ||
import java.util.Arrays; | ||
|
||
public class PatternEntryResponse extends Response { | ||
public PatternEntryResponse(byte[] buffer) { | ||
this.PatternIndex = buffer[1] & 0xFF; | ||
byte[] patternNameBytes = Arrays.copyOfRange(buffer, 2, 27); | ||
this.PatternName = new String(patternNameBytes); | ||
for(int i = 0; i < 7; i++) { | ||
Lengths[i] = buffer[31 + i] & 0xFF; | ||
} | ||
|
||
for(int i = 0; i < 7; i++) { | ||
int tripletStart = i * 3 + 38; | ||
int r = buffer[tripletStart + 0] & 0xFF; | ||
int g = buffer[tripletStart + 1] & 0xFF; | ||
int b = buffer[tripletStart + 2] & 0xFF; | ||
Colors[i] = new Color(r,g,b); | ||
} | ||
// Reduce to interesting slice | ||
this.rawBytes = Arrays.copyOfRange(buffer, 2, buffer.length - 1); | ||
} | ||
|
||
public int PatternIndex; | ||
public String PatternName; | ||
public int[] Lengths = new int[7]; | ||
public Color[] Colors = new Color[7]; | ||
|
||
public String toString() { | ||
String formattedByteArray = ByteArrayFormatter.format(this.rawBytes, this.rawBytes.length); | ||
StringBuilder sb = new StringBuilder(); | ||
for(int i = 0; i < 7; i++) { | ||
sb.append(Colors[i].toString().replace("java.awt.Color", "")); | ||
sb.append(" x "); | ||
sb.append(Lengths[i]); | ||
sb.append(" "); | ||
} | ||
return String.format("%s <Pattern Entry Response> #%d \"%s\" %s", this.LogPrefix, this.PatternIndex, this.PatternName, sb.toString()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.trimlighthacking; | ||
|
||
import java.util.Arrays; | ||
|
||
public class PatternLibraryQueryRequest extends Request { | ||
|
||
private final int fixedUnknown1; | ||
private final int fixedUnknown2; | ||
|
||
public PatternLibraryQueryRequest(byte[] buffer) { | ||
|
||
this.fixedUnknown1 = buffer[1] & 0xFF; | ||
this.fixedUnknown2 = buffer[2] & 0xFF; | ||
// Reduce to interesting slice | ||
this.rawBytes = Arrays.copyOfRange(buffer, 2, buffer.length - 1); | ||
} | ||
|
||
public String toString() { | ||
return String.format("%s <Pattern Library Query Request> Unknowns: (Fixed: %02X %02X)", this.LogPrefix, fixedUnknown1, fixedUnknown2); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.trimlighthacking; | ||
|
||
import java.util.Arrays; | ||
|
||
public class PatternLibraryQueryResponse extends Response { | ||
|
||
public PatternLibraryQueryResponse(byte[] buffer) { | ||
|
||
/*this.PatternIndex = buffer[1] & 0xFF; | ||
byte[] patternNameBytes = Arrays.copyOfRange(buffer, 2, 27); | ||
this.PatternName = new String(patternNameBytes);*/ | ||
// Reduce to interesting slice | ||
this.rawBytes = Arrays.copyOfRange(buffer, 2, buffer.length - 1); | ||
} | ||
|
||
public int PatternIndex; | ||
public String PatternName; | ||
|
||
public String toString() { | ||
String formattedByteArray = ByteArrayFormatter.format(this.rawBytes, this.rawBytes.length); | ||
return String.format("%s <Pattern Library Query Response> %s", this.LogPrefix, formattedByteArray); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this .gitignore working? I see .idea in the PR.