Skip to content

Commit 0924b4f

Browse files
committed
Clean up, add font options.
1 parent 126e7ca commit 0924b4f

File tree

14 files changed

+96
-20
lines changed

14 files changed

+96
-20
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Trinity
22
Trinity is a powerful lightning-fast software reverse engineering suite for the Java bytecode architecture handling highly obfuscated binaries with ease.
33

4-
[![Download](https://img.shields.io/badge/Download%20Latest-green.svg)](https://github.com/firstfault/Trinity/releases)
5-
[![Apache License 2.0](https://img.shields.io/badge/License-Apache%20License%202.0-yellow.svg)](https://choosealicense.com/licenses/apache-2.0/)
4+
[![Download](https://img.shields.io/badge/Download-green.svg)](https://github.com/firstfault/Trinity/releases)
65

76
![Screenshot](screenshots/trinity.png)
87

src/main/java/me/f1nal/trinity/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import java.util.concurrent.TimeUnit;
2525

2626
public class Main {
27-
public static final String VERSION = "0.0.1-alpha0";
27+
public static final String VERSION = "0.0.1-alpha1";
2828

2929
/**
3030
* Manages the graphical user interface (GUI) elements and interactions.

src/main/java/me/f1nal/trinity/appdata/PreferencesFile.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import me.f1nal.trinity.Main;
44
import me.f1nal.trinity.appdata.keybindings.KeyBindingData;
5+
import me.f1nal.trinity.decompiler.output.DecompilerFontEnum;
56
import me.f1nal.trinity.decompiler.output.number.NumberDisplayTypeEnum;
67
import me.f1nal.trinity.events.EventRefreshDecompilerText;
78
import me.f1nal.trinity.gui.windows.impl.xref.SearchMaxDisplay;
@@ -15,6 +16,7 @@
1516
import java.util.Set;
1617

1718
public class PreferencesFile extends AppDataFile {
19+
private DecompilerFontEnum decompilerFontEnum = DecompilerFontEnum.JETBRAINS_MONO;
1820
private NumberDisplayTypeEnum defaultNumberDisplayType = NumberDisplayTypeEnum.DECIMAL;
1921
private SearchMaxDisplay searchMaxDisplay = SearchMaxDisplay.MAX_200;
2022
private boolean decompilerHideComments = false;
@@ -86,6 +88,14 @@ public SearchMaxDisplay getSearchMaxDisplay() {
8688
return searchMaxDisplay;
8789
}
8890

91+
public void setDecompilerFontEnum(DecompilerFontEnum decompilerFontEnum) {
92+
this.decompilerFontEnum = decompilerFontEnum;
93+
}
94+
95+
public DecompilerFontEnum getDecompilerFontEnum() {
96+
return decompilerFontEnum;
97+
}
98+
8999
public void setDecompilerHideComments(boolean decompilerHideComments) {
90100
this.decompilerHideComments = decompilerHideComments;
91101
Main.getEventBus().post(new EventRefreshDecompilerText(dc -> true));

src/main/java/me/f1nal/trinity/decompiler/output/DecompilerComponentInitializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public void visitVariable(VariableOutputMember variableMember) {
300300
final String varType = variableMember.getType() == null ? "unknown var type!" : variableMember.getType();
301301
final boolean stackVariable = varIndex >= VarExprent.STACK_BASE;
302302
text.text(CodeColorScheme.DISABLED, (stackVariable ? "Stack Variable" : variable == null ? "#" + varIndex : variable.getName()));
303-
text.text(CodeColorScheme.TEXT, String.format(" (%s) ", (stackVariable ? varIndex - VarExprent.STACK_BASE : varIndex)));
303+
text.text(CodeColorScheme.TEXT, String.format(" (%s) ", (stackVariable ? "-" + (varIndex - VarExprent.STACK_BASE) : varIndex)));
304304
text.text(CodeColorScheme.CLASS_REF, varType);
305305

306306
return text.get();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package me.f1nal.trinity.decompiler.output;
2+
3+
import imgui.ImFont;
4+
import me.f1nal.trinity.util.INameable;
5+
6+
public enum DecompilerFontEnum implements INameable {
7+
JETBRAINS_MONO("JetBrains Mono"),
8+
ZED_MONO("Zed Mono"),
9+
INTER("Inter"),
10+
;
11+
12+
private final String name;
13+
private ImFont font;
14+
15+
DecompilerFontEnum(String name) {
16+
this.name = name;
17+
}
18+
19+
public void setFont(ImFont font) {
20+
this.font = font;
21+
}
22+
23+
public ImFont getFont() {
24+
return font;
25+
}
26+
27+
@Override
28+
public String getName() {
29+
return this.name;
30+
}
31+
}

src/main/java/me/f1nal/trinity/gui/viewport/FontManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import imgui.*;
55
import imgui.gl3.ImGuiImplGl3;
66
import me.f1nal.trinity.Main;
7+
import me.f1nal.trinity.decompiler.output.DecompilerFontEnum;
78
import me.f1nal.trinity.gui.components.FontAwesomeIcons;
89

910
import java.io.IOException;
@@ -37,7 +38,7 @@ public float getGlobalScale() {
3738
private void buildFonts(final float size) {
3839
ImGuiIO io = ImGui.getIO();
3940

40-
io.getFonts().addFontFromMemoryTTF(loadFromResources("fonts/inter-regular.ttf"), size);
41+
DecompilerFontEnum.INTER.setFont(io.getFonts().addFontFromMemoryTTF(loadFromResources("fonts/inter-regular.ttf"), size));
4142

4243
final ImFontConfig fontConfig = new ImFontConfig();
4344
fontConfig.setMergeMode(true);
@@ -49,6 +50,8 @@ private void buildFonts(final float size) {
4950
final short[] glyphRanges = rangesBuilder.buildRanges();
5051

5152
io.getFonts().addFontFromMemoryTTF(loadFromResources("fonts/fa-solid-900.ttf"), size, fontConfig, glyphRanges);
53+
DecompilerFontEnum.JETBRAINS_MONO.setFont(io.getFonts().addFontFromMemoryTTF(loadFromResources("fonts/JetBrainsMonoNL-Regular.ttf"), size + 1.F));
54+
DecompilerFontEnum.ZED_MONO.setFont(io.getFonts().addFontFromMemoryTTF(loadFromResources("fonts/zed-mono-regular.ttf"), size + 1.F));
5255
this.currentFontSize = size;
5356
}
5457

src/main/java/me/f1nal/trinity/gui/windows/impl/PreferencesFrame.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import imgui.ImGui;
44
import imgui.flag.ImGuiDataType;
55
import imgui.flag.ImGuiSliderFlags;
6+
import imgui.flag.ImGuiWindowFlags;
67
import imgui.type.ImFloat;
78
import me.f1nal.trinity.Main;
89
import me.f1nal.trinity.Trinity;
910
import me.f1nal.trinity.appdata.PreferencesFile;
11+
import me.f1nal.trinity.decompiler.output.DecompilerFontEnum;
1012
import me.f1nal.trinity.decompiler.output.number.NumberDisplayTypeEnum;
11-
import me.f1nal.trinity.events.EventRefreshDecompilerText;
1213
import me.f1nal.trinity.gui.components.ComponentId;
1314
import me.f1nal.trinity.gui.components.general.EnumComboBox;
14-
import me.f1nal.trinity.gui.windows.api.ClosableWindow;
1515
import me.f1nal.trinity.gui.windows.api.StaticWindow;
1616
import me.f1nal.trinity.gui.windows.impl.xref.SearchMaxDisplay;
1717
import me.f1nal.trinity.keybindings.Bindable;
@@ -21,15 +21,18 @@
2121

2222
public class PreferencesFrame extends StaticWindow {
2323
private final String id = ComponentId.getId(this.getClass());
24+
private final EnumComboBox<DecompilerFontEnum> decompilerFont;
2425
private final EnumComboBox<NumberDisplayTypeEnum> numberDisplayTypeComboBox;
2526
private final EnumComboBox<SearchMaxDisplay> searchMaxDisplayComboBox;
2627
private final PreferencesFile preferencesFile;
2728
private Bindable editingBind;
2829

2930
public PreferencesFrame(Trinity trinity) {
30-
super("Preferences", 500, 310, trinity);
31+
super("Preferences", 450, 250, trinity);
3132
this.preferencesFile = Main.getPreferences();
32-
this.numberDisplayTypeComboBox = new EnumComboBox<>("Default Number Display Type", NumberDisplayTypeEnum.values(), preferencesFile.getDefaultNumberDisplayType());
33+
this.windowFlags |= ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoDocking;
34+
this.decompilerFont = new EnumComboBox<>("Decompiler Font", DecompilerFontEnum.values(), preferencesFile.getDecompilerFontEnum());
35+
this.numberDisplayTypeComboBox = new EnumComboBox<>("Number Display Type", NumberDisplayTypeEnum.values(), preferencesFile.getDefaultNumberDisplayType());
3336
this.searchMaxDisplayComboBox = new EnumComboBox<>("Search Element Limit", SearchMaxDisplay.values(), preferencesFile.getSearchMaxDisplay());
3437
}
3538

@@ -70,6 +73,7 @@ protected void renderFrame() {
7073
}
7174

7275
if (ImGui.beginTabItem("Decompiler")) {
76+
this.preferencesFile.setDecompilerFontEnum(this.decompilerFont.draw());
7377
this.preferencesFile.setDefaultNumberDisplayType(this.numberDisplayTypeComboBox.draw());
7478

7579
if (ImGui.checkbox("Hide comments", preferencesFile.isDecompilerHideComments())) {
@@ -88,7 +92,7 @@ protected void renderFrame() {
8892
ImGui.endTabItem();
8993
}
9094

91-
if (ImGui.beginTabItem("Keybindings")) {
95+
if (false&&ImGui.beginTabItem("Keybindings")) {
9296
for (Bindable bindable : Main.getKeyBindManager().getBindables()) {
9397
ImGui.text(bindable.getDisplayName());
9498
ImGui.sameLine();

src/main/java/me/f1nal/trinity/gui/windows/impl/assembler/args/NumberArgument.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,25 @@ public class NumberArgument extends InstructionOperand {
88

99
public NumberArgument(Number number) {
1010
this.number = number;
11-
this.getDetailsText().add(new ColoredString(number + getPrefix(number), CodeColorScheme.NUMBER));
11+
this.getDetailsText().add(new ColoredString(formatNumber(number), CodeColorScheme.NUMBER));
1212
}
1313

14-
public static String getPrefix(Number number) {
14+
private static String formatNumber(Number number) {
15+
final String suffix = getSuffix(number);
16+
String text = String.valueOf(number);
17+
18+
if (!suffix.isEmpty()) {
19+
if (text.endsWith(".0")) {
20+
text = text.substring(text.length() - 1);
21+
} else if (!(number instanceof Long) && !text.contains(".")) {
22+
text += ".";
23+
}
24+
}
25+
26+
return text + suffix;
27+
}
28+
29+
public static String getSuffix(Number number) {
1530
if (number instanceof Float) {
1631
return "F";
1732
}

src/main/java/me/f1nal/trinity/gui/windows/impl/constant/search/ConstantSearchTypeNumber.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ protected String convertConstantToText(Number value) {
172172
if (value.intValue() != this.value.get()) {
173173
return null;
174174
}
175-
return value.intValue() + NumberArgument.getPrefix(value);
175+
return value.intValue() + NumberArgument.getSuffix(value);
176176
}
177177
}
178178
}

src/main/java/me/f1nal/trinity/gui/windows/impl/constant/search/ConstantSearchTypeString.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@ public boolean draw() {
3535
ImGui.sameLine();
3636
GuiUtil.smallCheckbox("Exact", this.exact);
3737
GuiUtil.tooltip("If set, the string must exactly match the input instead of containing it.");
38-
return !this.searchTerm.get().isEmpty();
38+
return true;
3939
}
4040

4141
private SearchTermMatchable createMatchable() {
4242
String inputSearch = this.searchTerm.get();
4343

44+
if (inputSearch.isEmpty()) {
45+
return searchTerm -> true;
46+
}
47+
4448
// Exact Search
4549
if (this.exact.get()) {
4650
if (this.caseInsensitive.get()) return searchTerm -> searchTerm.equalsIgnoreCase(inputSearch);

0 commit comments

Comments
 (0)