Skip to content

Commit 7c012a7

Browse files
committed
add 3 byte format :)
1 parent 685eebe commit 7c012a7

File tree

5 files changed

+49
-15
lines changed

5 files changed

+49
-15
lines changed

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,14 @@
22

33
By. Whoopsunix
44

5-
抽离出 utf-8-overlong-encoding 的序列化逻辑,直接加密序列化数组, WIKI https://whoopsunix.com/docs/PPPYSO/advance/UTFMIX/
5+
抽离出 utf-8-overlong-encoding 的序列化逻辑,直接加密序列化数组, WIKI https://whoopsunix.com/docs/PPPYSO/advance/UTFMIX/
6+
7+
2、3 字节的加密都已实现,修改 com.ppp.UTF8BytesMix.type 属性值更改。
8+
9+
2 字节
10+
11+
![image-20240311100317285](attachments/image-20240311100317285.png)
12+
13+
3 字节
14+
15+
![image-20240311100348330](attachments/image-20240311100348330.png)
157 KB
Loading
136 KB
Loading

src/main/java/com/ppp/Run.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ public static void main(String[] args) throws Exception {
2626
print(UEBytes);
2727

2828

29-
3029
System.out.println("\n\n\n---mix---");
3130
byte[] mixBytes = new UTF8BytesMix(Serializer.serialize(gadget)).builder();
3231
print(mixBytes);
3332
Deserializer.deserialize(mixBytes);
3433
}
3534

3635

37-
public static void print(byte[] bytes ){
36+
public static void print(byte[] bytes) {
3837
ByteArrayOutputStream out = new ByteArrayOutputStream();
3938
for (byte b : bytes) {
4039
out.write(b);
4140
}
41+
System.out.println("byte length:" + bytes.length);
4242
System.out.println(out);
4343
}
4444
}

src/main/java/com/ppp/UTF8BytesMix.java

+36-12
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ public class UTF8BytesMix {
99

1010
public static byte[] resultBytes = new byte[0];
1111
public static byte[] originalBytes = new byte[0];
12+
13+
// 加密字节位数
14+
public static int type = 2; //3
15+
1216
// 原 byte[] 坐标
1317
public static int index = 0;
1418

@@ -55,6 +59,7 @@ public static byte[] builder() {
5559
}
5660
return resultBytes;
5761
}
62+
5863
public static void changeTC_PROXYCLASSDESC() {
5964
int interfaceCount = ((originalBytes[index + 1] & 0xFF) << 24) |
6065
((originalBytes[index + 2] & 0xFF) << 16) |
@@ -73,7 +78,7 @@ public static void changeTC_PROXYCLASSDESC() {
7378
System.arraycopy(originalBytes, index + 3, originalValue, 0, length);
7479
index += 3 + length;
7580

76-
encode(originalValue);
81+
encode(originalValue, type);
7782
index--;
7883
}
7984

@@ -133,7 +138,7 @@ public static boolean changeTC_CLASSDESC() {
133138
byte[] originalFieldName = new byte[fieldLength];
134139
System.arraycopy(originalBytes, index + 2, originalFieldName, 0, fieldLength);
135140
index += 2 + fieldLength;
136-
encode(originalFieldName);
141+
encode(originalFieldName, type);
137142
}
138143

139144
/**
@@ -156,7 +161,7 @@ public static boolean changeTC_CLASSDESC() {
156161
byte[] originalClassName = new byte[classLength];
157162
System.arraycopy(originalBytes, index + 2, originalClassName, 0, classLength);
158163
index += 2 + classLength;
159-
encode(originalClassName);
164+
encode(originalClassName, type);
160165
isFiledOver = true;
161166
} else if (originalBytes[index] == TC_REFERENCE) {
162167
/**
@@ -212,7 +217,7 @@ public static boolean changeTC_STRING() {
212217
}
213218

214219
index += 3 + length;
215-
encode(originalValue);
220+
encode(originalValue, type);
216221

217222
index--;
218223
return true;
@@ -251,17 +256,36 @@ public static boolean isField(byte[] checkBytes, int index) {
251256
*
252257
* @return
253258
*/
254-
public static void encode(byte[] originalValue) {
255-
int newLength = originalValue.length * 2;
259+
public static void encode(byte[] originalValue, int type) {
260+
if (type == 3) {
261+
// 3 byte format: 1110xxxx 10xxxxxx 10xxxxxx
262+
int newLength = originalValue.length * 3;
263+
264+
byteAdd((byte) ((newLength >> 8) & 0xFF));
265+
byteAdd((byte) (newLength & 0xFF));
266+
267+
for (int i = 0; i < originalValue.length; i++) {
268+
char c = (char) originalValue[i];
269+
byteAdd((byte) (0xE0 | ((c >> 12) & 0x0F)));
270+
byteAdd((byte) (0x80 | ((c >> 6) & 0x3F)));
271+
byteAdd((byte) (0x80 | ((c >> 0) & 0x3F)));
272+
}
256273

257-
byteAdd((byte) ((newLength >> 8) & 0xFF));
258-
byteAdd((byte) (newLength & 0xFF));
274+
} else {
275+
// 2 byte format: 110xxxxx 10xxxxxx
276+
int newLength = originalValue.length * 2;
259277

260-
for (int i = 0; i < originalValue.length; i++) {
261-
char c = (char) originalValue[i];
262-
byteAdd((byte) (0xC0 | ((c >> 6) & 0x1F)));
263-
byteAdd((byte) (0x80 | ((c >> 0) & 0x3F)));
278+
byteAdd((byte) ((newLength >> 8) & 0xFF));
279+
byteAdd((byte) (newLength & 0xFF));
280+
281+
for (int i = 0; i < originalValue.length; i++) {
282+
char c = (char) originalValue[i];
283+
byteAdd((byte) (0xC0 | ((c >> 6) & 0x1F)));
284+
byteAdd((byte) (0x80 | ((c >> 0) & 0x3F)));
285+
}
264286
}
287+
288+
265289
}
266290

267291
/**

0 commit comments

Comments
 (0)