8000 ByReferenceWrapperGenerator: Add class to scene by MarcMil · Pull Request #2160 · soot-oss/soot · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ByReferenceWrapperGenerator: Add class to scene #2160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,15 @@
import soot.jimple.JimpleBody;

/**
* Array elements in .NET can be loaded by reference.
* Since Jimple does not support this semantic, we generate Wrapper classes.
* Array elements in .NET can be loaded by reference. Since Jimple does not support this semantic, we generate Wrapper
* classes.
*
* Note that in .NET, array covariance is allowed for reference types:
* <code>
* Note that in .NET, array covariance is allowed for reference types: <code>
string[] strings = new string[10];
object[] objects = strings;
</code>
* However, for value types, this is not the case.
* So all the reference types may share one object[] wrapper, but value types need their own.
</code> However, for value types, this is not the case. So all the reference types may share one object[] wrapper, but
* value types need their own.
*
* @author Marc Miltenberger
*/
public class ArrayByReferenceWrapperGenerator {
Expand All @@ -77,6 +76,7 @@ public synchronized static SootClass getWrapperClass(Type elementType) {
Type arrType = elementType.makeArrayType();

SootClass sc = scene.makeSootClass(name, Modifier.FINAL | Modifier.STATIC);
Scene.v().addClass(sc);
sc.setApplicationClass();
SootField arrayField = scene.makeSootField("array", arrType);
arrayField.setModifiers(Modifier.PUBLIC | Modifier.FINAL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public synchronized static SootClass getWrapperClass(Type t) {
return rt.getSootClass();
}
SootClass sc = scene.makeSootClass(name, Modifier.FINAL | Modifier.STATIC);
scene.addClass(sc);
sc.setApplicationClass();
SootField r = scene.makeSootField(WRAPPER_FIELD_NAME, RefType.v("System.Object"));
r.setModifiers(Modifier.PUBLIC);
Expand Down
40 changes: 5 additions & 35 deletions src/main/java/soot/dotnet/members/method/DelegateHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,38 +199,6 @@ private void createDelegateMethods(Scene sc, SootClass actualDelegateClass, List

}
{
//public static List<Delegate> remove(List<Delegate> my, List<Delegate> other)
//{
// List<Delegate> list = new List<Delegate>(my);
//
// int idx = list.Count;
// idx -= other.Count;
// if (other.Count == 0)
// return list;
// Delegate firstOtherElem = other[0];
//next:
// while (idx >= 0)
// {
// idx = list.LastIndexOf(firstOtherElem, idx);
// if (idx == -1)
// break;
// int i = idx;
// int x = 0;
// while (i < idx + other.Count)
// {
// if (list[i] != other[x])
// {
// idx--;
// goto next;
// }
// x++;
// i++;
// }
// list.RemoveRange(idx, other.Count);
// break;
// }
// return list;
//}

SootMethod removeFrom = sc.makeSootMethod(REMOVE_METHOD_NAME, Arrays.asList(delegateInterface.getType()),
delegateInterface.getType(), Modifier.PUBLIC);
Expand Down Expand Up @@ -379,7 +347,7 @@ private void createDelegateMethods(Scene sc, SootClass actualDelegateClass, List

Stmt backedge = j.newIfStmt(j.newEqExpr(lclIndex, lclCount), retS);
bodyInvoke.getUnits().add(backedge);
//loop
// loop
List<Value> parameters = new ArrayList<>();
Local objFromDelegate = j.newLocal("objFromDelegate", sc.getObjectType());
bodyInvoke.getLocals().add(objFromDelegate);
Expand Down Expand Up @@ -428,7 +396,7 @@ private void createDelegateMethods(Scene sc, SootClass actualDelegateClass, List

protected void createSingleConstructor(Scene sc, SootClass actualDelegateClass) {
Jimple j = Jimple.v();
//we use a long type as a parameter to distinguish it from the one generate by the .NET compiler
// we use a long type as a parameter to distinguish it from the one generate by the .NET compiler
mCtorSingle
= sc.makeSootMethod("<init>", Arrays.asList(sc.getObjectType(), LongType.v()), VoidType.v(), Modifier.PUBLIC);

Expand Down Expand Up @@ -485,6 +453,7 @@ public static synchronized SootClass createDelegateInterface(Scene sc) {
}
delegateInterface
= sc.makeSootClass(DELEGATE_INTERFACE_CLASSNAME, Modifier.PUBLIC | Modifier.INTERFACE | Modifier.ABSTRACT);
Scene.v().addClass(delegateInterface);
delegateInterface.setApplicationClass();

SootMethod combineWith = sc.makeSootMethod(COMBINE_WITH_METHOD_NAME, Arrays.asList(delegateInterface.getType()),
Expand Down Expand Up @@ -513,7 +482,7 @@ public static synchronized SootClass createDelegateInterface(Scene sc) {
Unit retTwo = j.newReturnStmt(bd.getParameterLocal(0));
uc.add(j.newIfStmt(j.newEqExpr(bd.getParameterLocal(0), NullConstant.v()), retOne));
uc.add(j.newIfStmt(j.newEqExpr(bd.getParameterLocal(1), NullConstant.v()), retTwo));
// assign.setRightOp(j.newInterfaceInvokeExpr((Local) inv.getArg(0), combineMRef, inv.getArg(1)));
// assign.setRightOp(j.newInterfaceInvokeExpr((Local) inv.getArg(0), combineMRef, inv.getArg(1)));
uc.add(j.newAssignStmt(l,
j.newInterfaceInvokeExpr(bd.getParameterLocal(0), combineWith.makeRef(), bd.getParameterLocal(1))));
uc.add(j.newReturnStmt(l));
Expand All @@ -529,6 +498,7 @@ protected static synchronized SootClass createDelegateHolder(Scene sc) {
return dh;
}
SootClass delegateHolder = sc.makeSootClass(DELEGATE_HOLDER_CLASSNAME, Modifier.PUBLIC);
Scene.v().addClass(delegateHolder);
delegateHolder.setApplicationClass();

SootField instanceField = sc.makeSootField(INSTANCE_FIELDNAME, sc.getObjectType(), Modifier.PUBLIC);
Expand Down
Loading
0