Skip to content

Commit

Permalink
chore(all): virtualise invoke construction
Browse files Browse the repository at this point in the history
  • Loading branch information
terminalsin committed Sep 19, 2022
1 parent 9550089 commit 9e6b1eb
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 9 deletions.
4 changes: 2 additions & 2 deletions dev.skidfuscator.gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ plugins {
}

group = 'dev.skidfuscator'
version = '0.1'
version = '1.0.0'

gradlePlugin {
plugins {
skidfuscator {
id = 'dev.skidfuscator'
id = 'io.github.terminalsin'
implementationClass = 'dev.skidfuscator.gradle.SkidfuscatorGradlePlugin'
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,16 @@ private Object buildSkidfuscatorSession(Class<?> aClass) throws NoSuchMethodExce
boolean.class // analytics
);
return constructor.newInstance(
spec.getInput(), spec.getOutput(), spec.getLibs(), spec.getMappings(), spec.getExempt(), spec.getRuntime(),
spec.isPhantom(), spec.isJmod(), spec.isFuckit(), spec.isAnalytics());
spec.getInput(),
spec.getOutput(),
spec.getLibs(),
spec.getMappings(),
spec.getExempt(),
spec.getRuntime(),
spec.isPhantom(),
spec.isJmod(),
spec.isFuckit(),
spec.isAnalytics()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import org.mapleir.ir.cfg.builder.ssa.CfgBuilder;
import org.mapleir.ir.cfg.builder.ssa.expr.*;
import org.mapleir.ir.cfg.builder.ssa.expr.invoke.StaticInvocationExprBuilder;
import org.mapleir.ir.cfg.builder.ssa.expr.invoke.VirtualInvocationExprBuilder;
import org.mapleir.ir.cfg.builder.ssa.stmt.*;
import org.mapleir.ir.cfg.builder.ssa.stmt.copy.CopyPhiStmtBuilder;
import org.mapleir.ir.cfg.builder.ssa.stmt.copy.CopyVarStmtBuilder;
import org.mapleir.ir.code.Expr;
import org.mapleir.ir.code.expr.*;
import org.mapleir.ir.code.expr.invoke.InvocationExpr;
import org.mapleir.ir.code.expr.invoke.StaticInvocationExpr;
import org.mapleir.ir.code.expr.invoke.VirtualInvocationExpr;
import org.mapleir.ir.code.stmt.*;
import org.mapleir.ir.code.stmt.copy.CopyPhiStmt;
import org.mapleir.ir.code.stmt.copy.CopyVarStmt;
Expand Down Expand Up @@ -307,6 +309,63 @@ public ConstantExpr build() {
};
}

@Override
public VirtualInvocationExprBuilder virtual_invoke_expr() {
return new VirtualInvocationExprBuilder() {
private InvocationExpr.CallType callType = InvocationExpr.CallType.VIRTUAL;
private Expr[] args;
private String owner;
private String name;
private String desc;

@Override
public VirtualInvocationExprBuilder callType(InvocationExpr.CallType callType) {
this.callType = callType;
return this;
}

@Override
public VirtualInvocationExprBuilder args(Expr[] args) {
this.args = args;
return this;
}

@Override
public VirtualInvocationExprBuilder owner(String owner) {
this.owner = owner;
return this;
}

@Override
public VirtualInvocationExprBuilder name(String name) {
this.name = name;
return this;
}

@Override
public VirtualInvocationExprBuilder desc(String desc) {
this.desc = desc;
return this;
}

@Override
public VirtualInvocationExpr build() {
assert owner != null : "Owner name cannot be null";
assert name != null : "Name cannot be null";
assert desc != null : "Description cannot be null";


return new VirtualInvocationExpr(
callType,
args,
owner,
name,
desc
);
}
};
}

@Override
public StaticInvocationExprBuilder static_invoke_expr() {
return new StaticInvocationExprBuilder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.mapleir.ir.cfg.builder.ssa.CfgBuilder;
import org.mapleir.ir.cfg.builder.ssa.expr.*;
import org.mapleir.ir.cfg.builder.ssa.expr.invoke.StaticInvocationExprBuilder;
import org.mapleir.ir.cfg.builder.ssa.expr.invoke.VirtualInvocationExprBuilder;
import org.mapleir.ir.cfg.builder.ssa.stmt.*;
import org.mapleir.ir.cfg.builder.ssa.stmt.copy.CopyPhiStmtBuilder;
import org.mapleir.ir.cfg.builder.ssa.stmt.copy.CopyVarStmtBuilder;
Expand Down Expand Up @@ -46,6 +47,8 @@ public interface SSAFactory {

StaticInvocationExprBuilder static_invoke_expr();

VirtualInvocationExprBuilder virtual_invoke_expr();

CopyPhiStmtBuilder copy_phi_stmt();

CopyVarStmtBuilder copy_var_stmt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,14 @@ protected void _call(int op, String owner, String name, String desc) {
case Opcodes.INVOKEVIRTUAL:
case Opcodes.INVOKEINTERFACE:
case Opcodes.INVOKESPECIAL:
callExpr = new VirtualInvocationExpr(VirtualInvocationExpr.resolveCallType(op), args, owner, name, desc);
callExpr = builder.factory
.virtual_invoke_expr()
.callType(VirtualInvocationExpr.resolveCallType(op))
.args(args)
.owner(owner)
.name(name)
.desc(desc)
.build();
break;
case Opcodes.INVOKESTATIC:
callExpr = builder.factory
Expand Down Expand Up @@ -1732,10 +1739,8 @@ private void makeRanges(List<BasicBlock> order) {
* if the given descriptor isn't intended for getType
* (getObjectType instead), shouldn't have this problem now.*/
erange.addType(tc.type != null ? Type.getType("L" + tc.type + ";") : TypeUtils.THROWABLE);

ListIterator<BasicBlock> lit = range.listIterator();
while(lit.hasNext()) {
BasicBlock block = lit.next();

for (BasicBlock block : range) {
builder.graph.addEdge(new TryCatchEdge<>(block, erange));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.mapleir.ir.cfg.builder.ssa.expr.invoke;

import org.mapleir.app.factory.Builder;
import org.mapleir.ir.code.Expr;
import org.mapleir.ir.code.expr.invoke.InvocationExpr;
import org.mapleir.ir.code.expr.invoke.StaticInvocationExpr;
import org.mapleir.ir.code.expr.invoke.VirtualInvocationExpr;

public interface VirtualInvocationExprBuilder extends Builder<VirtualInvocationExpr> {
VirtualInvocationExprBuilder callType(InvocationExpr.CallType callType);
VirtualInvocationExprBuilder args(Expr[] args);
VirtualInvocationExprBuilder owner(String owner);
VirtualInvocationExprBuilder name(String name);
VirtualInvocationExprBuilder desc(String desc);
}

0 comments on commit 9e6b1eb

Please sign in to comment.