Commit 2f6d6aeb authored by Mustafa's avatar Mustafa

Removed unused libs

parent e5daa1ca
Pipeline #2539 failed with stage
How to run the DroidSim
1. create a root directory and put the file CBCFG.jar in it.
this is use our tool CBCFG to generate the component-based CFG graph
2. run python getSignature.py file which can parse the dex file and get the CFG
you can modify the path and change into your personal apk path and you can get the CFG signature.
If you want to run the CFG you should modify the file getSignature.py
#****************************************
# Using method :
# java -jar CBCFG.jar
#
# before we run this file we should run the CFGScanDroid
# sudo apt-get install maven
# ./build.sh
# This will create a file:
# target/CFGScanDroid.jar
#***********************************************
3.When you finish get the CFG signature you can use the file parseCFGResult.py to get the CFG graph
#**********************************************************************
# when we use CFGScanDroid scan the dex file we can get the signature
# of each apk (CFG)
# the signature format:
# La.a()Z;8;0:1,2,3,4,5;6:7
# interceptSMS;4;0:1,2;1:3;2:3,0
# the signature name is interceptSMS, there are 4 vertices
# 0:1,2
# 1:3
# 2:3,0
# in this way we can get the edge relation
#
# the edges:
# 0->1
# 0->2
# 1->3
# 2->3
# 2->0
#**********************************************************************
4. if you want to delete the ad libs you can run this file
python deleteAds.py to delete the ad libs
Generally, you should delet the libs first and then you just parse the CFG graph you should run this file first and then run the parseCFGResult.py
5. run python VF2.py you can get the similar Values of each app pairs.
should install the networkx
How to run the DroidSim
1. create a root directory and put the file CBCFG.jar in it.
this is use our tool CBCFG to generate the component-based CFG graph
2. run python getSignature.py file which can parse the dex file and get the CFG
you can modify the path and change into your personal apk path and you can get the CFG signature.'
When you finish get the CFG signature you can use the file parseCFGResult.py to get the CFG graph
#****************************************
# Using method :
# java -jar CBCFG.jar
#
# before we run this file we should run the CFGScanDroid
# sudo apt-get install maven
# ./build.sh
# This will create a file:
# target/CFGScanDroid.jar
#***********************************************
#**********************************************************************
# when we use CFGScanDroid scan the dex file we can get the signature
# of each apk (CFG)
# the signature format:
# La.a()Z;8;0:1,2,3,4,5;6:7
# interceptSMS;4;0:1,2;1:3;2:3,0
# the signature name is interceptSMS, there are 4 vertices
# 0:1,2
# 1:3
# 2:3,0
# in this way we can get the edge relation
#
# the edges:
# 0->1
# 0->2
# 1->3
# 2->3
# 2->0
#**********************************************************************
3. if you want to delete the ad libs you can run this file
python deleteAds.py to delete the ad libs
Generally, you should delet the libs first and then you just parse the CFG graph you should run this file first and then run the parseCFGResult.py
4. run python VF2.py you can get the similar Values of each app pairs.
#!/usr/bin/env python
# coding=utf-8
# Author : Chicho
# filename : Vf2.py
# Function : parse the graph file
# the file format
# t1
# 0 1
# 0 2
# 1 3
# 1 4
# create the graph according to the graph signature file
# compare the similarity and get the result
import os
import networkx as nx
from networkx.algorithms import isomorphism
import time
import sys
oriGPath = "/home/chicho/workspace/repackaged/DroidSIM/graph/original/"
repGpath = "/home/chicho/workspace/repackaged/DroidSIM/graph/repackaged/"
pairPath = "/home/chicho/workspace/repackaged/repackaging_pairs1.txt"
# create the file
def createGraph(lines):
GL = []
i = 0
while(i < len(lines)):
line = lines[i]
if " " not in line: # we find the graph name
Gname = line.replace("\n","")
Gname = nx.Graph() # create a graph
i = i + 1
line = lines[i]
while ((" " in line) and (i < len(lines))):
line = line.replace("\n","")
edge = line.split(" ")
Gname.add_edge(int(edge[0]),int(edge[1]))
i = i + 1
if i < len(lines):
line = lines[i]
if Gname not in GL:
GL.append(Gname)
return GL
'''
def getcomparePair(pairPath):
f=open(pairPath)
for line in f.readlines():
line = line.replace("\n","")
apks = line.split(",")
'''
def VF(oriGPath,repGpath):
f = open(pairPath)
for line in f.readlines():
line = line.replace("\n","")
apks = line.split(",")
oriapk = apks[0] + ".txt"
repapk = apks[1] + ".txt"
tips = "compare the apk pairs {0},{1}".format(apks[0],apks[1])
print tips
oriAPKPath = os.path.join(oriGPath,oriapk)
repAPKPath = os.path.join(repGpath,repapk)
if os.path.exists(oriAPKPath) and os.path.exists(repAPKPath):
orif = open(oriAPKPath)
tarf = open(repAPKPath)
else:
if not os.path.exists(oriAPKPath) and os.path.exists(repAPKPath):
cmd = "echo {0} >> {1}".format(apks[0],"noexists.txt")
os.system(cmd)
if not os.path.exists(repAPKPath) and os.path.exists(oriAPKPath):
cmd = "echo {0} >> {1}".format(apks[1],"noexists.txt")
os.system(cmd)
if not os.path.exists(oriAPKPath) and not os.path.exists(repAPKPath):
cmd = "echo {0},{1}>>{2}".format(apks[0],apks[1],"noexists.txt")
os.system(cmd)
continue
GG = createGraph(orif.readlines()) # which is an original apks and GG is all of CFG
TG = createGraph(tarf.readlines()) # repackaged apks's CFGs
start = time.time()
b = 0
for G in GG:
for T in TG:
GM = isomorphism.GraphMatcher(G,T)
#GM1 = isomorphism.GraphMatcher(T,G)
elapse = time.time() -start
if int(elapse)>600:
break
if GM.subgraph_is_isomorphic():
# tips = "Graph {0} and {1} are isomorphic".format(G,T)
# print tips
b = b + 1
# print GM.mapping
break
else:
pass
# print "There are not match"
elapse = time.time() - start
if int(elapse)>3600:
print "**************************"
print "Time is up!"
print "**************************"
break
nowtime = time.time()
continueTime = nowtime - start
if int(continueTime) >3600:
continue
end = time.time()
time_interval = str(end-start)
cmd = "echo {0} >> {1}".format(time_interval,"runningtime.txt")
os.system(cmd)
if b > min(len(GG),len(TG)):
sim = (b * 1.0)/max(len(GG),len(TG))
else:
sim = (b * 1.0)/min(len(GG),len(TG))
cmd = "echo {0},{1},{2} >>{3}".format(apks[0],apks[1],sim,"similarityResult.txt")
os.system(cmd)
tips = "compare the {0},{1},sim:{2},b:{3},{4},{5}".format(apks[0],apks[1],sim,b,len(GG),len(TG))
print tips
orif.close()
tarf.close()
VF(oriGPath,repGpath)
print "all work is done!\n"
#!/usr/bin/env python
# coding=utf-8
# Author : Chicho
# Date : 2015-05-14
# Running : python calculateCFG.py
# Function : calculate the total number of ground truth Apps
# Draw the Histogram
import os
oriPath = "/home/chicho/workspace/repackaged/DroidSIM/original"
repPath = "/home/chicho/workspace/repackaged/DroidSIM/repackaged"
orioutputPath = "/home/chicho/workspace/repackaged/DroidSIM/ori_nodelete_CFG.txt"
repoutputPath = "/home/chicho/workspace/repackaged/DroidSIM/rep_bodelete_CFG.txt"
def calculateCFG(path,outputPath):
apkList = os.listdir(path)
for apk in apkList:
apkPath = os.path.join(path,apk)
f = open(apkPath)
count = 0
for line in f.readlines():
if ":" and ";" in line:
count +=1
apkname = apk.split(".")[0]
cmd = "echo {0} {1} >> {2}".format(apkname,count,outputPath)
os.system(cmd)
csvname= outputPath.split("/")[-1].split(".")[0] + ".csv"
cmd = "echo {0} >> {1}".format(count,csvname)
os.system(cmd)
print "we are handle with {0}".format(apkname)
calculateCFG(oriPath,orioutputPath)
calculateCFG(repPath,repoutputPath)
#!/usr/bin/env python
# coding=utf-8
# Author : Chicho
# Date : 2017-07-03
# Running : python calculateNodes.py
# Function : parse the cfg/pdg signature and calculate the node of each app
import os
oriPath = "/home/chicho/workspace/repackaged/DroidSIM/delete/original1/"
repPath = "/home/chicho/workspace/repackaged/DroidSIM/delete/repackaged1/"
outputPath = "/home/chicho/workspace/repackaged/DroidSIM/node/"
def calculateNode(path,outputPath):
apkList = os.listdir(path)
i = 0
for apk in apkList:
i = i + 1
if i == 10:
break
print apk
apkPath = os.path.join(path,apk)
f = open(apkPath)
countList = []
eachapkoutPutPath = os.path.join(outputPath,apk)
for line in f.readlines():
if ":" in line and ";" in line:
count = int(line.split(";")[1])
cmd = "echo {0} >> {1}".format(count,eachapkoutPutPath)
os.system(cmd)
countList.append(count)
nodeSum = sum(countList)*1.0
NodeAvg = round(nodeSum/len(countList))
print countList
print nodeSum
print len(countList)
print NodeAvg
f.close()
calculateNode(oriPath,outputPath)
print "all work is done!"
This diff is collapsed.
#!/usr/bin/env python
# coding=utf-8
'''
delete the space line of the file
'''
import os
oriPath = "/home/chicho/workspace/repackaged/DroidSIM/delete/original/"
repPath = "/home/chicho/workspace/repackaged/DroidSIM/delete/repackaged/"
orioutPath = "/home/chicho/workspace/repackaged/DroidSIM/delete/original1/"
repoutPath = "/home/chicho/workspace/repackaged/DroidSIM/delete/repackaged1/"
def deleteSpace(path,outputPath):
fileList = os.listdir(path)
for file in fileList:
filePath = os.path.join(path,file)
outfilePath = os.path.join(outputPath,file)
f = open(filePath)
for line in f.readlines():
if line == "\n":
continue
line = line.replace("\n","")
cmd = "echo '{0}' >> {1}".format(line,outfilePath)
os.system(cmd)
deleteSpace(oriPath,orioutPath)
deleteSpace(repPath,repoutPath)
print "all work is done!"
#!/usr/bin/env python
# coding=utf-8
# Author : Chicho
# Date : 2017-05-12
# running : python getSignature
# function : parse the dex file and get the CFG signature
# we should delete the ad libraries as much as possible
import os
jarPath = "/home/chicho/workspace/repackaged/tools/CBCFG.jar"
oriPath = "/home/chicho/workspace/repackaged/result/original/"
repPath = "/home/chicho/workspace/repackaged/result/repackaged/"
orioutPutPath = "/home/chicho/workspace/repackaged/DroidSIM/original/"
repoutPutPath = "/home/chicho/workspace/repackaged/DroidSIM/repackaged/"
def getCFGsignature(Path,outPutPath):
apkList = os.listdir(Path)
for apk in apkList:
dexPath = os.path.join(Path,apk,"bin/classes/classes.dex")
apkFile = apk + ".txt"
outPutFilePath = os.path.join(outPutPath,apkFile)
cmd = "java -jar {0} -d -f {1} >> {2}".format(jarPath,dexPath,outPutFilePath)
os.system(cmd)
tips = "handle with {0} ...".format(apkFile)
print tips
getCFGsignature(oriPath,orioutPutPath)
getCFGsignature(repPath,repoutPutPath)
print "all work is done!"
#!/usr/bin/env python
# coding=utf-8
# Author : Chicho
# Date : 2017-05-12
# running : python getSignature
# function : parse the dex file and get the CFG signature
# we should delete the ad libraries as much as possible
import os
jarPath = "/home/chicho/workspace/repackaged/tools/CFGScanDroid-master/target/CFGScanDroid.jar"
oriPath = "/home/chicho/workspace/repackaged/result/original/"
repPath = "/home/chicho/workspace/repackaged/result/repackaged/"
orioutPutPath = "/home/chicho/workspace/repackaged/DroidSIM/original/"
repoutPutPath = "/home/chicho/workspace/repackaged/DroidSIM/repackaged/"
def getCFGsignature(Path,outPutPath):
apkList = os.listdir(Path)
for apk in apkList:
dexPath = os.path.join(Path,apk,"bin/classes/classes.dex")
apkFile = apk + ".txt"
outPutFilePath = os.path.join(outPutPath,apkFile)
cmd = "java -jar {0} -d -f {1} >> {2}".format(jarPath,dexPath,outPutFilePath)
os.system(cmd)
tips = "handle with {0} ...".format(apkFile)
print tips
getCFGsignature(oriPath,orioutPutPath)
getCFGsignature(repPath,repoutPutPath)
print "all work is done!"