Main Page


About

India

I am currently a computer science Ph.D. student at University at Buffalo. My main area of focus is cyber-security, malware analysis, blockchain concepts, application development, and computer networking-leading. My long-term goal is to be a good teacher and researcher.


10824367524_04bd7712a4_o

Common Creative License from Flickr by KylaBorg

BARTS Blockchain Documents:


Links to the BARTS Blockchain Simulation:


BARTS Exercise Links:

  • EXERCISE 1 (Generate a nonce that will result in a leading zero for a hash)
  • EXERCISE 2 (A Hashing program that automatically searches for a nonce)
  • EXERCISE 3 (Mining Computation Issues)
  • EXERCISE 4 (Birthday Paradox and cracking secure hash algorithms)

UB Smart Contract Page


HICSS 2020

HICSS 2021 Blockchain Injection Documentation

Compilers Class​

Smart contract Solidity Code

pragma solidity >=0.5.15;

contract ApplicationContract{

	string Name ="";

	function SetName(string memory statedata) public{
		Name = statedata;
	}

	function Hello()public view returns(string memory){
		return Name;
	}
}

Code for pom.xml file

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>Soot</groupId>
  <artifactId>Soot</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
  <dependency>
    <groupId>ca.mcgill.sable</groupId>
    <artifactId>soot</artifactId>
    <version>4.0.0</version>
  </dependency>
  </dependencies>
</project>

Java file (HicssSootAnalysis.java)

import soot.Body;
import soot.BodyTransformer;
import soot.Local;
import soot.PackManager;
import soot.PatchingChain;
import soot.RefType;
import soot.Scene;
import soot.SootClass;
import soot.SootMethodRef;
import soot.SootResolver;
import soot.Transform;
import soot.Type;
import soot.Unit;
import soot.Value;
import soot.VoidType;
import soot.javaToJimple.LocalGenerator;
import soot.jimple.AssignStmt;
import soot.jimple.InvokeStmt;
import soot.jimple.Jimple;
import soot.jimple.StringConstant;
import soot.jimple.VirtualInvokeExpr;

import java.util.*; 

public class HicssSootAnalysis
{
    
    static String EntryPointApp = "com.example.simpleapplication.MainActivity";
    static String EntryPointBlockchain = "com.example.simpleapplication.Hello";
    static String RemoteFunctionCallWeb3J = "org.web3j.protocol.core.RemoteFunctionCall";
    static String SendAsync = "org.web3j.protocol.core.RemoteFunctionCall: java.util.concurrent.CompletableFuture sendAsync()";
    static Local ContractReference = null;
    static Value BlockchainContractStmt = null;
    
    public static void main(String[] args)
    {       
        
         PackManager.v().getPack("jtp").add(new Transform("jtp.myInstrumenter", new BodyTransformer() {   
            @Override
            protected void internalTransform(final Body body, String phaseName, @SuppressWarnings("rawtypes") Map options) {
                final PatchingChain<Unit> units = body.getUnits();                              
                IterateOverAllUnits(units, body);               
            }
        }));        
        soot.Main.main(args);
    }
    
    private static void IterateOverAllUnits(PatchingChain<Unit> units, Body body) {
        String StringLastKnownUnit = "";   
//        int counter = 0;
        for(Iterator<Unit> UnitIterator = units.snapshotIterator(); UnitIterator.hasNext();) { 
            final Unit LastKnownUnit = UnitIterator.next(); 
            StringLastKnownUnit = LastKnownUnit.toString();
            if(Check_If_SetContentView_Exists(StringLastKnownUnit)) { 
            	//ADD LOCALS
                LocalGenerator l = new LocalGenerator(body);               
                l.generateLocal(RefType.v("com.example.simpleapplication.Hello"));    
                l.generateLocal(RefType.v("org.web3j.protocol.core.RemoteFunctionCall"));
                
                // Create $r3 = $r0.<com.example.simpleapplication.MainActivity: com.example.simpleapplication.Hello contract>;
                LinkedList<Value> ContractInitArgs = new LinkedList<>();
                AssignStmt AssignStmtContract = Jimple.v().newAssignStmt(Return_Local(body, "Hello"),Jimple.v().newVirtualInvokeExpr(Return_Local(body,"MainActivity"), Scene.v().getMethod("<"+ EntryPointApp +": "+ EntryPointBlockchain +" ContractInit()>").makeRef(), ContractInitArgs));
                units.insertAfter(AssignStmtContract, LastKnownUnit);
                // Create $r2 = virtualinvoke $r3.<com.example.simpleapplication.Hello: org.web3j.protocol.core.RemoteFunctionCall SetName(java.lang.String)>("John");
                LinkedList<Value> ContractPersonName = new LinkedList<>();
                ContractPersonName.add(StringConstant.v("John"));
                AssignStmt AssignStmtContractFunc = Jimple.v().newAssignStmt(Return_Local(body, "RemoteFunctionCall"),Jimple.v().newVirtualInvokeExpr(Return_Local(body,"Hello"), Scene.v().getMethod("<"+ EntryPointBlockchain +": "+ RemoteFunctionCallWeb3J +" SetName(java.lang.String)>").makeRef(), ContractPersonName));
                units.insertAfter(AssignStmtContractFunc, AssignStmtContract);
                // Create virtualinvoke $r2.<org.web3j.protocol.core.RemoteFunctionCall: java.util.concurrent.CompletableFuture sendAsync()>();
                List<String> BlockchainArgumentsForSendAsync = new LinkedList<>();
                SootMethodRef SendAsyncMethodRef = makeMethodRef("org.web3j.protocol.core.RemoteCall","sendAsync", "java.util.concurrent.CompletableFuture",BlockchainArgumentsForSendAsync, false);
                VirtualInvokeExpr InvokeExprSendAsync = Jimple.v().newVirtualInvokeExpr(Return_Local(body,"RemoteFunctionCall"), SendAsyncMethodRef, Collections.<Value>emptyList());
                InvokeStmt InvokeStatementSendAsync = Jimple.v().newInvokeStmt(InvokeExprSendAsync);
                units.insertAfter(InvokeStatementSendAsync, (Unit) AssignStmtContractFunc);
            }
        }
        
    } 
    public static SootMethodRef makeMethodRef(String cName, String mName, String rType, List<String> pTypes,
            boolean isStatic) {
           SootClass sc = SootResolver.v().makeClassRef(cName);
           Type returnType = null;
           if (rType == "") {
            returnType = VoidType.v();
           } else {
            returnType = RefType.v(rType);
           }
           List<Type> parameterTypes = new ArrayList<Type>();
           for (String p : pTypes) {
            parameterTypes.add(RefType.v(p));
           }
           return Scene.v().makeMethodRef(sc, mName, parameterTypes, returnType, isStatic);
    }
    
    private static Local Return_Local(Body b, String name) {
        for (Local local : b.getLocals()) {
	         if (local.getType().toString().contains(name)) {
	          return local;
	         }
        }
        return null;
   }

    
    private static boolean Check_If_SetContentView_Exists(String StringLastKnownUnit) {
        if(Contains_Match_Case(StringLastKnownUnit, EntryPointApp) && Contains_Match_Case(StringLastKnownUnit, "SetContentView")) {
            return true;
        }else {
            return false;
        }
    }  
    
    
    public static boolean Contains_Match_Case(String str, String subString) {
        return str.toLowerCase().contains(subString.toLowerCase());
    }    
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s