Skip to content
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

Entry Changes #364

Merged
merged 14 commits into from
Jul 8, 2021
Merged
164 changes: 63 additions & 101 deletions enigma-server/docs/protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,15 @@ struct Packet {
The IDs for client-to-server packets are as follows:
- 0: `Login`
- 1: `ConfirmChange`
- 2: `Rename`
- 3: `RemoveMapping`
- 4: `ChangeDocs`
- 5: `MarkDeobfuscated`
- 6: `Message`
- 7: `EntryChange`

The IDs for server-to-client packets are as follows:
- 0: `Kick`
- 1: `SyncMappings`
- 2: `Rename`
- 3: `RemoveMapping`
- 4: `ChangeDocs`
- 5: `MarkDeobfuscated`
- 6: `Message`
- 7: `UserList`
- 8: `EntryChange`

### The utf struct
```c
Expand Down Expand Up @@ -196,6 +190,45 @@ struct Message {
- `entry`: The entry that was modified.
- `new_name`: The new name for the entry.

### The entry_change struct
```c
typedef enum tristate_change {
TRISTATE_CHANGE_UNCHANGED = 0,
TRISTATE_CHANGE_RESET = 1,
TRISTATE_CHANGE_SET = 2
} tristate_change_t;

typedef enum access_modifier {
ACCESS_MODIFIER_UNCHANGED = 0,
ACCESS_MODIFIER_PUBLIC = 1,
ACCESS_MODIFIER_PROTECTED = 2,
ACCESS_MODIFIER_PRIVATE = 3
} access_modifier_t;

// Contains 4 packed values:
// bitmask type
// 00000011 tristate_change_t deobf_name_change;
// 00001100 tristate_change_t access_change;
// 00110000 tristate_change_t javadoc_change;
// 11000000 access_modifier_t access_modifiers;
typedef uint8_t entry_change_flags;

struct entry_change {
Entry entry;
entry_change_flags flags;
if <deobf_name_change == TRISTATE_CHANGE_SET> {
utf deobf_name;
}
if <javadoc_change == TRISTATE_CHANGE_SET> {
utf javadoc;
}
}
```
- `entry`: The entry this change gets applied to.
- `flags`: See definition of `entry_change_flags`.
- `deobf_name`: The new deobfuscated name, if deobf_name_change == TRISTATE_CHANGE_SET
- `javadoc`: The new javadoc, if javadoc_change == TRISTATE_CHANGE_SET
- `access_modifiers`: The new access modifier, if access_change == TRISTATE_CHANGE_SET (otherwise 0)

### Login (client-to-server)
```c
Expand Down Expand Up @@ -223,44 +256,6 @@ struct ConfirmChangeC2SPacket {
```
- `sync_id`: the sync ID to confirm.

### Rename (client-to-server)
```c
struct RenameC2SPacket {
Entry obf_entry;
utf new_name;
boolean refresh_class_tree;
}
```
- `obf_entry`: the obfuscated name and descriptor of the entry to rename.
- `new_name`: what to rename the entry to.
- `refresh_class_tree`: whether the class tree on the sidebar of Enigma needs refreshing as a result of this change.

### RemoveMapping (client-to-server)
```c
struct RemoveMappingC2SPacket {
Entry obf_entry;
}
```
- `obf_entry`: the obfuscated name and descriptor of the entry to remove the mapping for.

### ChangeDocs (client-to-server)
```c
struct ChangeDocsC2SPacket {
Entry obf_entry;
utf new_docs;
}
```
- `obf_entry`: the obfuscated name and descriptor of the entry to change the documentation for.
- `new_docs`: the new documentation for this entry, or an empty string to remove the documentation.

### MarkDeobfuscated (client-to-server)
```c
struct MarkDeobfuscatedC2SPacket {
Entry obf_entry;
}
```
- `obf_entry`: the obfuscated name and descriptor of the entry to mark as deobfuscated.

### Message (client-to-server)
```c
struct MessageC2SPacket {
Expand All @@ -269,6 +264,14 @@ struct MessageC2SPacket {
```
- `message`: The text message the user sent.

### EntryChange (client-to-server)
```c
struct EntryChangeC2SPacket {
entry_change change;
}
```
- `change`: The change to apply.

### Kick (server-to-client)
```c
struct KickS2CPacket {
Expand All @@ -286,70 +289,19 @@ struct SyncMappingsS2CPacket {
struct MappingNode {
NoParentEntry obf_entry;
boolean is_named;
if<is_named> {
utf name;
boolean has_javadoc;
if<has_javadoc> {
utf javadoc;
}
}
utf name;
utf javadoc;
unsigned short children_count;
MappingNode children[children_count];
}
typedef { Entry but without the has_parent or parent fields } NoParentEntry;
```
- `roots`: The root mapping nodes, containing all the entries without parents.
- `obf_entry`: The value of a node, containing the obfuscated name and descriptor of the entry.
- `name`: The deobfuscated name of the entry, if it has a mapping.
- `javadoc`: The documentation for the entry, if it is named and has documentation.
- `name`: The deobfuscated name of the entry, if it exists, otherwise the empty string.
- `javadoc`: The documentation for the entry, if it exists, otherwise the empty string.
- `children`: The children of this node

### Rename (server-to-client)
```c
struct RenameS2CPacket {
unsigned short sync_id;
Entry obf_entry;
utf new_name;
boolean refresh_class_tree;
}
```
- `sync_id`: the sync ID of the change for locking purposes.
- `obf_entry`: the obfuscated name and descriptor of the entry to rename.
- `new_name`: what to rename the entry to.
- `refresh_class_tree`: whether the class tree on the sidebar of Enigma needs refreshing as a result of this change.

### RemoveMapping (server-to-client)
```c
struct RemoveMappingS2CPacket {
unsigned short sync_id;
Entry obf_entry;
}
```
- `sync_id`: the sync ID of the change for locking purposes.
- `obf_entry`: the obfuscated name and descriptor of the entry to remove the mapping for.

### ChangeDocs (server-to-client)
```c
struct ChangeDocsS2CPacket {
unsigned short sync_id;
Entry obf_entry;
utf new_docs;
}
```
- `sync_id`: the sync ID of the change for locking purposes.
- `obf_entry`: the obfuscated name and descriptor of the entry to change the documentation for.
- `new_docs`: the new documentation for this entry, or an empty string to remove the documentation.

### MarkDeobfuscated (server-to-client)
```c
struct MarkDeobfuscatedS2CPacket {
unsigned short sync_id;
Entry obf_entry;
}
```
- `sync_id`: the sync ID of the change for locking purposes.
- `obf_entry`: the obfuscated name and descriptor of the entry to mark as deobfuscated.

### Message (server-to-client)
```c
struct MessageS2CPacket {
Expand All @@ -364,3 +316,13 @@ struct UserListS2CPacket {
utf user[len];
}
```

### EntryChange (server-to-client)
```c
struct EntryChangeS2CPacket {
uint16_t sync_id;
entry_change change;
}
```
- `sync_id`: The sync ID of the change for locking purposes.
- `change`: The change to apply.
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
package cuchaz.enigma.network;

import cuchaz.enigma.analysis.EntryReference;
import cuchaz.enigma.translation.mapping.EntryChange;
import cuchaz.enigma.translation.mapping.EntryMapping;
import cuchaz.enigma.translation.mapping.tree.EntryTree;
import cuchaz.enigma.network.packet.Packet;
import cuchaz.enigma.translation.representation.entry.Entry;
import cuchaz.enigma.utils.validation.ValidationContext;

import java.util.List;

public interface ClientPacketHandler {
void openMappings(EntryTree<EntryMapping> mappings);

void rename(ValidationContext vc, EntryReference<Entry<?>, Entry<?>> reference, String newName, boolean refreshClassTree);

void removeMapping(ValidationContext vc, EntryReference<Entry<?>, Entry<?>> reference);

void changeDocs(ValidationContext vc, EntryReference<Entry<?>, Entry<?>> reference, String updatedDocs);

void markAsDeobfuscated(ValidationContext vc, EntryReference<Entry<?>, Entry<?>> reference);
boolean applyChangeFromServer(EntryChange<?> change);

void disconnectIfConnected(String reason);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.concurrent.CopyOnWriteArrayList;

import cuchaz.enigma.network.packet.*;
import cuchaz.enigma.translation.mapping.EntryChange;
import cuchaz.enigma.translation.mapping.EntryMapping;
import cuchaz.enigma.translation.mapping.EntryRemapper;
import cuchaz.enigma.translation.representation.entry.Entry;
Expand All @@ -16,7 +17,7 @@ public abstract class EnigmaServer {

// https://discordapp.com/channels/507304429255393322/566418023372816394/700292322918793347
public static final int DEFAULT_PORT = 34712;
public static final int PROTOCOL_VERSION = 0;
public static final int PROTOCOL_VERSION = 1;
public static final int CHECKSUM_SIZE = 20;
public static final int MAX_PASSWORD_LENGTH = 255; // length is written as a byte in the login packet

Expand Down Expand Up @@ -234,11 +235,11 @@ public void confirmChange(Socket client, int syncId) {

public void sendCorrectMapping(Socket client, Entry<?> entry, boolean refreshClassTree) {
EntryMapping oldMapping = mappings.getDeobfMapping(entry);
String oldName = oldMapping == null ? null : oldMapping.getTargetName();
String oldName = oldMapping.targetName();
if (oldName == null) {
sendPacket(client, new RemoveMappingS2CPacket(DUMMY_SYNC_ID, entry));
sendPacket(client, new EntryChangeS2CPacket(DUMMY_SYNC_ID, EntryChange.modify(entry).clearDeobfName()));
} else {
sendPacket(client, new RenameS2CPacket(0, entry, oldName, refreshClassTree));
sendPacket(client, new EntryChangeS2CPacket(0, EntryChange.modify(entry).withDeobfName(oldName)));
}
}

Expand Down

This file was deleted.

This file was deleted.

Loading