From b4f956b114552913a362ecc7a4113d57b065fe1b Mon Sep 17 00:00:00 2001 From: Demyan Kimitsa Date: Tue, 3 May 2022 17:11:37 +0300 Subject: [PATCH 1/4] * support for JEP 181: Nest-Based Access Control Added parsing for NestMembers and NestHost attributes --- src/soot/coffi/ClassFile.java | 15 +++++- src/soot/coffi/NestHost_attribute.java | 35 ++++++++++++++ src/soot/coffi/NestMembers_attribute.java | 35 ++++++++++++++ src/soot/coffi/Util.java | 12 +++++ src/soot/coffi/attribute_info.java | 12 ++++- src/soot/tagkit/NestHostTag.java | 58 +++++++++++++++++++++++ src/soot/tagkit/NestMembersTag.java | 57 ++++++++++++++++++++++ 7 files changed, 222 insertions(+), 2 deletions(-) create mode 100644 src/soot/coffi/NestHost_attribute.java create mode 100644 src/soot/coffi/NestMembers_attribute.java create mode 100644 src/soot/tagkit/NestHostTag.java create mode 100644 src/soot/tagkit/NestMembersTag.java diff --git a/src/soot/coffi/ClassFile.java b/src/soot/coffi/ClassFile.java index f4d2f1097ed..8ddb347ccbc 100644 --- a/src/soot/coffi/ClassFile.java +++ b/src/soot/coffi/ClassFile.java @@ -705,7 +705,20 @@ else if (s.compareTo(attribute_info.EnclosingMethod)==0){ ea.method_index = d.readUnsignedShort(); a = (attribute_info)ea; } - else if(s.compareTo(attribute_info.InnerClasses)==0) + else if (s.compareTo(attribute_info.NestHost)==0){ + NestHost_attribute ea = new NestHost_attribute(); + ea.class_index = d.readUnsignedShort(); + a = (attribute_info)ea; + } + else if (s.compareTo(attribute_info.NestMembers)==0){ + NestMembers_attribute ea = new NestMembers_attribute(); + int number_of_classes = d.readUnsignedShort(); + ea.classes = new int[number_of_classes]; + for (int idx = 0; idx < number_of_classes; idx++) + ea.classes[idx] = d.readUnsignedShort(); + a = (attribute_info)ea; + } + else if(s.compareTo(attribute_info.InnerClasses)==0) { InnerClasses_attribute ia = new InnerClasses_attribute(); ia.inner_classes_length = d.readUnsignedShort(); diff --git a/src/soot/coffi/NestHost_attribute.java b/src/soot/coffi/NestHost_attribute.java new file mode 100644 index 00000000000..a6e1a1ad0fc --- /dev/null +++ b/src/soot/coffi/NestHost_attribute.java @@ -0,0 +1,35 @@ +/* Soot - a J*va Optimization Framework + * Copyright (C) 2005 Jennifer Lhotak + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* + * Modified by the Sable Research Group and others 1997-1999. + * See the 'credits' file distributed with Soot for the complete list of + * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot) + */ + +package soot.coffi; + +/** Attribute that connects nest member with its host + * @see attribute_info + * @author Demyan Kimitsa + */ +class NestHost_attribute extends attribute_info { + public int class_index; +} + diff --git a/src/soot/coffi/NestMembers_attribute.java b/src/soot/coffi/NestMembers_attribute.java new file mode 100644 index 00000000000..0a7e63c4d36 --- /dev/null +++ b/src/soot/coffi/NestMembers_attribute.java @@ -0,0 +1,35 @@ +/* Soot - a J*va Optimization Framework + * Copyright (C) 2005 Jennifer Lhotak + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* + * Modified by the Sable Research Group and others 1997-1999. + * See the 'credits' file distributed with Soot for the complete list of + * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot) + */ + +package soot.coffi; + +/** Attribute that connects nest host with members + * @see attribute_info + * @author Demyan Kimitsa + */ +class NestMembers_attribute extends attribute_info { + public int[] classes; +} + diff --git a/src/soot/coffi/Util.java b/src/soot/coffi/Util.java index 830031b1852..120a6e8e701 100644 --- a/src/soot/coffi/Util.java +++ b/src/soot/coffi/Util.java @@ -409,6 +409,18 @@ else if (coffiClass.attributes[i] instanceof EnclosingMethod_attribute){ } bclass.addTag(new EnclosingMethodTag(class_name, method_name, method_sig)); } + else if (coffiClass.attributes[i] instanceof NestHost_attribute) { + NestHost_attribute attr = (NestHost_attribute)coffiClass.attributes[i]; + String nest_host_class = ((CONSTANT_Utf8_info)coffiClass.constant_pool[((CONSTANT_Class_info)coffiClass.constant_pool[ attr.class_index]).name_index]).convert(); + bclass.addTag(new NestHostTag(nest_host_class)); + } + else if (coffiClass.attributes[i] instanceof NestMembers_attribute) { + NestMembers_attribute attr = (NestMembers_attribute)coffiClass.attributes[i]; + String[] members = new String[attr.classes.length]; + for (int idx = 0; idx < members.length; idx++) + members[idx] = ((CONSTANT_Utf8_info)coffiClass.constant_pool[((CONSTANT_Class_info)coffiClass.constant_pool[ attr.classes[idx]]).name_index]).convert(); + bclass.addTag(new NestMembersTag(members)); + } else if (coffiClass.attributes[i] instanceof RuntimeVisibleAnnotations_attribute || coffiClass.attributes[i] instanceof RuntimeInvisibleAnnotations_attribute) { addAnnotationVisibilityAttribute(bclass, coffiClass.attributes[i], coffiClass, references); diff --git a/src/soot/coffi/attribute_info.java b/src/soot/coffi/attribute_info.java index f2e0023d105..3e5aac2f146 100644 --- a/src/soot/coffi/attribute_info.java +++ b/src/soot/coffi/attribute_info.java @@ -91,7 +91,17 @@ class attribute_info { * @see EnclosingMethod_attribute */ public static final String EnclosingMethod = "EnclosingMethod"; - + + /** String by which a NestMembers attribute is recognized. + * @see NestMembers_attribute + */ + public static final String NestMembers = "NestMembers"; + + /** String by which a NestHost attribute is recognized. + * @see NestHost_attribute + */ + public static final String NestHost = "NestHost"; + /** String by which a LocalVariableTypeTable attribute is recognized. * @see LocalVariableTypeTable_attribute */ diff --git a/src/soot/tagkit/NestHostTag.java b/src/soot/tagkit/NestHostTag.java new file mode 100644 index 00000000000..d2068b4a215 --- /dev/null +++ b/src/soot/tagkit/NestHostTag.java @@ -0,0 +1,58 @@ +/* Soot - a J*va Optimization Framework + * Copyright (C) 2003 Archie L. Cobbs + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* + * Modified by the Sable Research Group and others 1997-1999. + * See the 'credits' file distributed with Soot for the complete list of + * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot) + */ + + +package soot.tagkit; + +/** + * Tag keeps nest host for class (added in java 11) + * + * @author dkimitsa + */ +public class NestHostTag implements Tag { + private final String nestHostClass; + + public NestHostTag(String nestHostClass) { + this.nestHostClass = nestHostClass; + } + + public String getName() { + return "NestHostTag"; + } + + public byte[] getValue() { + return new byte[0]; + } + + + public String getNestHostClass() { + return nestHostClass; + } + + public String toString() { + return "[host=" + nestHostClass + "]"; + } +} + diff --git a/src/soot/tagkit/NestMembersTag.java b/src/soot/tagkit/NestMembersTag.java new file mode 100644 index 00000000000..9b44663d7c9 --- /dev/null +++ b/src/soot/tagkit/NestMembersTag.java @@ -0,0 +1,57 @@ +/* Soot - a J*va Optimization Framework + * Copyright (C) 2003 Archie L. Cobbs + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* + * Modified by the Sable Research Group and others 1997-1999. + * See the 'credits' file distributed with Soot for the complete list of + * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot) + */ + + +package soot.tagkit; + +/** + * Tag keeps nest members for class (added in java 11) + * + * @author dkimitsa + */ +public class NestMembersTag implements Tag { + private final String[] nestMembers; + + public NestMembersTag(String[] nestMembers) { + this.nestMembers = nestMembers; + } + + public String getName() { + return "NestMembersTag"; + } + + public byte[] getValue() { + return new byte[0]; + } + + public String[] getNestMembers() { + return nestMembers; + } + + public String toString() { + return "[members=" + String.join(",", nestMembers); + } +} + From d89411e4668901acd26151deba4272a5537e095b Mon Sep 17 00:00:00 2001 From: Demyan Kimitsa Date: Tue, 3 May 2022 17:20:53 +0300 Subject: [PATCH 2/4] * fixed: unused import to missing dependency that was breaking compilation --- src/soot/jimple/toolkits/pointer/LocalMustAliasAnalysis.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/soot/jimple/toolkits/pointer/LocalMustAliasAnalysis.java b/src/soot/jimple/toolkits/pointer/LocalMustAliasAnalysis.java index b1fd82e8d2c..fd2cc082998 100644 --- a/src/soot/jimple/toolkits/pointer/LocalMustAliasAnalysis.java +++ b/src/soot/jimple/toolkits/pointer/LocalMustAliasAnalysis.java @@ -27,7 +27,6 @@ import java.util.Map; import java.util.Set; -import org.omg.CORBA.UNKNOWN; import soot.EquivalentValue; import soot.Local; From 4564919902a1ffb5fe59ae5d37935b1336f203c3 Mon Sep 17 00:00:00 2001 From: Demyan Kimitsa Date: Tue, 3 May 2022 17:28:05 +0300 Subject: [PATCH 3/4] * version increased --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 63f2b79cd68..e07e598741e 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ com.mobidevelop.robovm - 2.5.0-7 + 2.5.0-8 robovm-soot Soot jar From 248f603840a5c3449a6eba13a4dfade71fb65714 Mon Sep 17 00:00:00 2001 From: Demyan Kimitsa Date: Fri, 6 May 2022 11:01:15 +0300 Subject: [PATCH 4/4] * version reverted to snapshot --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e07e598741e..c20c1b7a967 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ com.mobidevelop.robovm - 2.5.0-8 + 2.5.0-8-SNAPSHOT robovm-soot Soot jar