330 lines
12 KiB
Java
330 lines
12 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* com.tridium.sys.Nre
|
|
* com.tridium.sys.module.ModuleClassLoader
|
|
* com.tridium.sys.module.NModule
|
|
* javax.baja.log.Log
|
|
* javax.baja.naming.SlotPath
|
|
* javax.baja.nre.util.Array
|
|
* javax.baja.security.BPermissions
|
|
* javax.baja.sys.BBlob
|
|
* javax.baja.sys.BModule
|
|
* javax.baja.sys.BValue
|
|
* javax.baja.sys.BVector
|
|
* javax.baja.sys.Context
|
|
* javax.baja.sys.Property
|
|
* javax.baja.sys.Sys
|
|
* javax.baja.sys.Type
|
|
* javax.baja.util.BUuid
|
|
*/
|
|
package com.tridium.program;
|
|
|
|
import com.tridium.program.BProgram;
|
|
import com.tridium.program.BProgramService;
|
|
import com.tridium.sys.Nre;
|
|
import com.tridium.sys.module.ModuleClassLoader;
|
|
import com.tridium.sys.module.NModule;
|
|
import java.security.SecureClassLoader;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.StringTokenizer;
|
|
import javax.baja.log.Log;
|
|
import javax.baja.naming.SlotPath;
|
|
import javax.baja.nre.util.Array;
|
|
import javax.baja.security.BPermissions;
|
|
import javax.baja.sys.BBlob;
|
|
import javax.baja.sys.BModule;
|
|
import javax.baja.sys.BValue;
|
|
import javax.baja.sys.BVector;
|
|
import javax.baja.sys.Context;
|
|
import javax.baja.sys.Property;
|
|
import javax.baja.sys.Sys;
|
|
import javax.baja.sys.Type;
|
|
import javax.baja.util.BUuid;
|
|
|
|
/*
|
|
* Illegal identifiers - consider using --renameillegalidents true
|
|
*/
|
|
public class BCode
|
|
extends BVector {
|
|
public static final Property className = BCode.newProperty((int)1, (String)"", null);
|
|
public static final Property classFile = BCode.newProperty((int)1, (BValue)BBlob.DEFAULT, null);
|
|
public static final Property dependencies = BCode.newProperty((int)1, (String)"", null);
|
|
public static final Type TYPE;
|
|
public static final Log log;
|
|
static Object loadLock;
|
|
static ProgramClassLoader classLoader;
|
|
static HashMap loadClassFiles;
|
|
static HashMap loadDependsMap;
|
|
static ModuleClassLoader[] loadDepends;
|
|
static /* synthetic */ Class class$com$tridium$program$BCode;
|
|
static /* synthetic */ Class class$com$tridium$program$BCode$ProgramClassEntry;
|
|
static /* synthetic */ Class class$javax$baja$sys$BBlob;
|
|
|
|
public String getClassName() {
|
|
return this.getString(className);
|
|
}
|
|
|
|
public void setClassName(String string) {
|
|
this.setString(className, string, null);
|
|
}
|
|
|
|
public BBlob getClassFile() {
|
|
return (BBlob)this.get(classFile);
|
|
}
|
|
|
|
public void setClassFile(BBlob bBlob) {
|
|
this.set(classFile, (BValue)bBlob, null);
|
|
}
|
|
|
|
public String getDependencies() {
|
|
return this.getString(dependencies);
|
|
}
|
|
|
|
public void setDependencies(String string) {
|
|
this.setString(dependencies, string, null);
|
|
}
|
|
|
|
public Type getType() {
|
|
return TYPE;
|
|
}
|
|
|
|
/*
|
|
* Unable to fully structure code
|
|
*/
|
|
public Object newInstance() throws Exception {
|
|
var1_1 = this.getClassName();
|
|
if (var1_1.length() == 0) {
|
|
throw new IllegalStateException("Empty className");
|
|
}
|
|
if (var1_1.equals("ProgramImpl") || var1_1.equals("RobotImpl")) {
|
|
throw new IllegalStateException("Must run programs thru program:com.tridium.program.RecompileTool");
|
|
}
|
|
var2_2 = this.getClassFile();
|
|
if (var2_2.length() == 0) {
|
|
throw new IllegalStateException("Empty classFile");
|
|
}
|
|
var3_3 = this.resolveDependencies();
|
|
v0 = BCode.class$com$tridium$program$BCode$ProgramClassEntry;
|
|
if (v0 == null) {
|
|
v0 = BCode.class$com$tridium$program$BCode$ProgramClassEntry = BCode.class("[Lcom.tridium.program.BCode$ProgramClassEntry;", false);
|
|
}
|
|
var4_4 = new Array(v0);
|
|
var5_5 = this.getProperties();
|
|
if (true) ** GOTO lbl20
|
|
do {
|
|
if (var5_5.property().isDynamic()) {
|
|
var4_4.add((Object)new ProgramClassEntry(SlotPath.unescape((String)var5_5.property().getName()), ((BBlob)var5_5.get()).copyBytes()));
|
|
}
|
|
lbl20:
|
|
// 4 sources
|
|
|
|
if ((v1 = BCode.class$javax$baja$sys$BBlob) != null) continue;
|
|
v1 = BCode.class("[Ljavax.baja.sys.BBlob;", false);
|
|
} while (var5_5.next(v1));
|
|
var5_5 = BCode.loadClass(var1_1, var2_2.copyBytes(), (ProgramClassEntry[])var4_4.trim(), var3_3);
|
|
return var5_5.newInstance();
|
|
}
|
|
|
|
public String[] parseDependencies() {
|
|
ArrayList<String> arrayList = new ArrayList<String>();
|
|
StringTokenizer stringTokenizer = new StringTokenizer(this.getDependencies(), ";");
|
|
while (stringTokenizer.hasMoreTokens()) {
|
|
String string = stringTokenizer.nextToken().trim();
|
|
if (string.length() <= 0 || BProgram.isSpecialModule(string)) continue;
|
|
arrayList.add(string);
|
|
}
|
|
return arrayList.toArray(new String[arrayList.size()]);
|
|
}
|
|
|
|
private final ModuleClassLoader[] resolveDependencies() throws Exception {
|
|
ArrayList<ModuleClassLoader> arrayList = new ArrayList<ModuleClassLoader>();
|
|
String[] stringArray = this.parseDependencies();
|
|
int n = 0;
|
|
while (n < stringArray.length) {
|
|
BModule bModule = Sys.loadModule((String)stringArray[n]);
|
|
NModule nModule = Nre.moduleManager.loadModule(bModule.getModuleName());
|
|
ModuleClassLoader moduleClassLoader = nModule.getClassLoader();
|
|
if (moduleClassLoader != null) {
|
|
arrayList.add(moduleClassLoader);
|
|
}
|
|
++n;
|
|
}
|
|
return arrayList.toArray(new ModuleClassLoader[arrayList.size()]);
|
|
}
|
|
|
|
/*
|
|
* Unable to fully structure code
|
|
*/
|
|
public void clearInnerClassFiles() {
|
|
var1_1 = this.getProperties();
|
|
if (true) ** GOTO lbl6
|
|
do {
|
|
if (var1_1.property().isDynamic()) {
|
|
this.remove(var1_1.property());
|
|
}
|
|
lbl6:
|
|
// 4 sources
|
|
|
|
if ((v0 = BCode.class$javax$baja$sys$BBlob) != null) continue;
|
|
v0 = BCode.class("[Ljavax.baja.sys.BBlob;", false);
|
|
} while (var1_1.next(v0));
|
|
}
|
|
|
|
public void addInnerClassFile(String string, BBlob bBlob) throws Exception {
|
|
String string2 = SlotPath.escape((String)string);
|
|
Property property = this.getProperty(string2);
|
|
if (property == null) {
|
|
this.add(string2, (BValue)bBlob, 1);
|
|
} else {
|
|
this.set(string2, (BValue)bBlob);
|
|
}
|
|
}
|
|
|
|
public static String generateClassName() {
|
|
BUuid bUuid = BUuid.make();
|
|
return "Prog_" + Long.toHexString(bUuid.getMostSignificant()) + Long.toHexString(bUuid.getLeastSignificant());
|
|
}
|
|
|
|
static Class loadClass(String string, byte[] byArray, ModuleClassLoader[] moduleClassLoaderArray) throws ClassNotFoundException {
|
|
return BCode.loadClass(string, byArray, null, moduleClassLoaderArray);
|
|
}
|
|
|
|
/*
|
|
* WARNING - Removed try catching itself - possible behaviour change.
|
|
* Unable to fully structure code
|
|
* Enabled aggressive block sorting
|
|
* Enabled unnecessary exception pruning
|
|
* Enabled aggressive exception aggregation
|
|
*/
|
|
static Class loadClass(String var0, byte[] var1_1, ProgramClassEntry[] var2_2, ModuleClassLoader[] var3_3) throws ClassNotFoundException {
|
|
var4_4 = BCode.loadLock;
|
|
synchronized (var4_4) {
|
|
block7: {
|
|
if (BCode.classLoader == null) {
|
|
BCode.classLoader = new ProgramClassLoader();
|
|
BCode.loadDependsMap = new HashMap<K, V>();
|
|
BCode.loadClassFiles = new HashMap<K, V>();
|
|
}
|
|
var7_5 = 0;
|
|
while (true) {
|
|
block8: {
|
|
if (var7_5 < var3_3.length) break block8;
|
|
BCode.loadDepends = BCode.loadDependsMap.values().toArray(new ModuleClassLoader[BCode.loadDependsMap.size()]);
|
|
BCode.loadClassFiles.put(var0, var1_1);
|
|
if (var2_2 == null) break block7;
|
|
var7_5 = 0;
|
|
if (true) ** GOTO lbl32
|
|
}
|
|
var8_6 = var3_3[var7_5];
|
|
var9_7 = var8_6.module.getModuleName();
|
|
if (BCode.loadDependsMap.get(var9_7) == null) {
|
|
BCode.loadDependsMap.put(var9_7, var8_6);
|
|
}
|
|
++var7_5;
|
|
}
|
|
do {
|
|
BCode.loadClassFiles.put(var2_2[var7_5].name, var2_2[var7_5].classFile);
|
|
++var7_5;
|
|
lbl32:
|
|
// 2 sources
|
|
|
|
} while (var7_5 < var2_2.length);
|
|
}
|
|
return BCode.classLoader.loadClass(var0);
|
|
}
|
|
}
|
|
|
|
public final BPermissions getPermissions(Context context) {
|
|
BPermissions bPermissions = super.getPermissions(context);
|
|
if (BProgramService.REQUIRE_SUPER_USER_PERMISSION && context != null && context.getUser() != null && !context.getUser().getPermissions().isSuperUser()) {
|
|
int n = 0;
|
|
if (bPermissions.hasOperatorRead()) {
|
|
n |= 1;
|
|
}
|
|
if (bPermissions.hasAdminRead()) {
|
|
n |= 0x10;
|
|
}
|
|
bPermissions = BPermissions.make((int)n);
|
|
}
|
|
return bPermissions;
|
|
}
|
|
|
|
static /* synthetic */ Class class(String string, boolean bl) {
|
|
try {
|
|
Class<?> clazz = Class.forName(string);
|
|
if (!bl) {
|
|
clazz = clazz.getComponentType();
|
|
}
|
|
return clazz;
|
|
}
|
|
catch (ClassNotFoundException classNotFoundException) {
|
|
throw new NoClassDefFoundError(classNotFoundException.getMessage());
|
|
}
|
|
}
|
|
|
|
static {
|
|
Class clazz = class$com$tridium$program$BCode;
|
|
if (clazz == null) {
|
|
clazz = class$com$tridium$program$BCode = BCode.class("[Lcom.tridium.program.BCode;", false);
|
|
}
|
|
TYPE = Sys.loadType((Class)clazz);
|
|
log = Log.getLog((String)"sys.program");
|
|
loadLock = new Object();
|
|
}
|
|
|
|
static class ProgramClassEntry {
|
|
String name;
|
|
byte[] classFile;
|
|
|
|
public ProgramClassEntry(String string, byte[] byArray) {
|
|
this.name = string;
|
|
this.classFile = byArray;
|
|
}
|
|
}
|
|
|
|
static class ProgramClassLoader
|
|
extends SecureClassLoader {
|
|
/*
|
|
* WARNING - Removed try catching itself - possible behaviour change.
|
|
* Enabled aggressive block sorting
|
|
* Enabled unnecessary exception pruning
|
|
* Enabled aggressive exception aggregation
|
|
*/
|
|
public Class findClass(String string) throws ClassNotFoundException {
|
|
ModuleClassLoader[] moduleClassLoaderArray;
|
|
block7: {
|
|
byte[] byArray = null;
|
|
moduleClassLoaderArray = null;
|
|
Object object = loadLock;
|
|
synchronized (object) {
|
|
byArray = (byte[])loadClassFiles.get(string);
|
|
if (byArray != null) {
|
|
loadClassFiles.remove(string);
|
|
} else {
|
|
moduleClassLoaderArray = (ModuleClassLoader[])loadDepends.clone();
|
|
}
|
|
// MONITOREXIT @DISABLED, blocks:[0, 1] lbl12 : MonitorExitStatement: MONITOREXIT : var4_4
|
|
if (byArray == null) break block7;
|
|
return this.defineClass(string, byArray, 0, byArray.length);
|
|
}
|
|
}
|
|
int n = 0;
|
|
while (n < moduleClassLoaderArray.length) {
|
|
Class clazz = moduleClassLoaderArray[n].nload(string, false);
|
|
if (clazz != null) {
|
|
return clazz;
|
|
}
|
|
++n;
|
|
}
|
|
throw new ClassNotFoundException(string);
|
|
}
|
|
|
|
ProgramClassLoader() {
|
|
}
|
|
}
|
|
}
|
|
|