From 9c80ff1c6e050a3ad4204d60d611be405e97cf34 Mon Sep 17 00:00:00 2001 From: Graham Date: Wed, 5 Aug 2020 13:54:28 +0100 Subject: [PATCH] Fix conversion of negative integers to char literals Signed-off-by: Graham --- .../deob/ast/transform/CharLiteralTransformer.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/CharLiteralTransformer.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/CharLiteralTransformer.kt index b1dd6fa8..92d72f44 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/CharLiteralTransformer.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/CharLiteralTransformer.kt @@ -14,9 +14,11 @@ import com.github.javaparser.ast.expr.BinaryExpr.Operator.PLUS import com.github.javaparser.ast.expr.CharLiteralExpr import com.github.javaparser.ast.expr.Expression import com.github.javaparser.ast.expr.IntegerLiteralExpr +import com.github.javaparser.ast.expr.UnaryExpr import com.github.javaparser.resolution.types.ResolvedPrimitiveType import dev.openrs2.deob.ast.Library import dev.openrs2.deob.ast.LibraryGroup +import dev.openrs2.deob.ast.util.checkedAsInt import dev.openrs2.deob.ast.util.walk import java.lang.Character.CONTROL import java.lang.Character.FORMAT @@ -49,7 +51,14 @@ class CharLiteralTransformer : Transformer() { return } - b.replace(CharLiteralExpr(escape(b.asNumber().toChar()))) + val n = b.checkedAsInt() + if (n < 0) { + val char = (-n).toChar() + b.replace(UnaryExpr(CharLiteralExpr(escape(char)), UnaryExpr.Operator.MINUS)) + } else { + val char = n.toChar() + b.replace(CharLiteralExpr(escape(char))) + } } private fun escape(c: Char): String {