start	end	text
8040	16080	Hello, everyone. Good afternoon. I hope you're enjoying Devcon as well as I am. So my talk
16080	22820	is about Androzia, which is a tool for securing data in process for your Android applications.
23140	30540	So if I had to explain what Androzia is doing in a couple of lines, it's basically providing
30540	39580	you the features of a proactive garbage collector. And garbage collectors inherently are lazy.
39580	45480	So they only kick in when your application is memory constrained. And they will reclaim
45480	52440	memory from objects which are unreferenced. But with Androzia, you will be able to reclaim
52440	61300	memory from objects immediately after their last use. So this is helpful because if you
61300	66320	have a lot of sensitive information lying around in your heap memory, as soon as it
66320	72500	is last used, Androzia is going to kick in and collect all that sensitive information
72500	78160	from your application and replace the memory contents with the default values. So your
78160	83380	sensitive data will not remain on the memory anymore. So before we begin, a little bit
83380	89080	about myself. I'm Samit. I work for the product security team at Citrix. I'm a web and mobile
89080	93280	application security enthusiast. Spoken at a bunch of conferences, including Black Hat
93280	103060	Asia, AppSec USA, Cocon, CodeBlue, IEEE Services, MobileSoft, and CloudCom. So, yeah, a little
103060	111660	bit of contact information in case you want to contact me. So starting off, the first
111660	118820	question for you is, which one of these is the most difficult to protect? Number one
118820	125800	data at rest, number two data in process, or number three data in motion? So arguably,
125800	133000	I would say that it's number two. Why? Because the least number of solutions in the market
133000	139900	are for number two. Because this is a very gray area. You know, EMM providers do not
139900	147540	really understand how to protect data in process. Data at rest is very simple. You use any ciphers
147540	152680	and then protect your data. Data in motion can be protected using TLS. However, data
152680	162980	in process is still a mystery for most of us. So this tool targets number two. And we'll
162980	173060	see how, yeah. So, going ahead. So Java creates a lot of objects, or Android itself creates
173240	177900	a lot of objects on the heap, right? And the objects may contain a lot of sensitive information
177900	183820	which may include your authentication credentials, authorisation tokens, and encryption decryption
183820	191560	keys, bins, ODPs, and personally identifiable information. So, as in when the application
191560	197760	is executing, all of these will be on your heap memory. So the developers want to ensure
197760	203260	that they get rid of all the sensitive information as soon as it is last used in the programme.
204400	209760	So the myth is that the garbage collector will eventually collect it. But, you know,
209760	214460	the garbage collector is very lazy, as I said. It will not come into the picture, or it will
214460	221140	not collect all your data until it is essential for it. Because unless your application is
221140	226540	memory-constrained, it will not come into the picture. And even if it does, right, its
226540	233320	scope is very limited. So this is something which is called as an object tree on the heap.
233540	240200	And how garbage collectors actually does a collection is using mark-and-sweep algorithm.
240380	248000	So it will start off from the root nodes which are called GC root. And from the GC root,
248000	253540	it traverses the object tree using depth-first search and keeps on marking all the objects
253540	258760	that are reachable. In the sweep phase of the direct garbage collector's collection
258760	264520	process, it is going to find out all the objects on the heap which are unreachable, and it
264520	271800	is going to collect only those objects. So when a developer is, you know, writing code,
271800	281420	he may forget to unreference some objects which may be these ones which are in the circle.
282220	288060	And garbage collector will not collect these set of objects just because they are reachable
288060	293500	from the GC roots. And these objects may contain sensitive information and they're going to
293500	299260	lie around in your application throughout the lifetime of your application until the
299260	307140	application is terminated. So this is where Androsia kicks in. It will clean off all the
307140	313660	unused but reachable objects in your memory. So to summarize what I've been talking about
313660	319000	until now, reachable and unused string builder objects may contain sensitive information.
319000	322880	So throughout the course of this presentation, I'm going to specifically talk about string
322880	328040	builder objects as an example. But this framework is, you know, extendable to any other kind
328040	334100	of objects as well. So reachable and unused string builder objects may contain sensitive
334100	339200	information and a heap dump or an application compromise will help an attacker to reveal
339200	343880	that sensitive information easily. So don't just rely on the garbage collector to collect
343880	348520	all that information, but instead destroy by overwriting all the critical data that
348520	357080	you have in the application. So with that in mind, we do have some solutions provided
357080	363480	by Java libraries which allow you to destroy objects that are created on the heap. One
363480	369980	of them is the keystore.password protection class. And this class provides a destroy method
369980	377420	which can be used to destroy the object's content. But again, you know, it's the developers,
377940	382720	you know, it's upon the developer to use this API. He may use it at a very late stage in
382720	388220	the program, or he may not even use it at all. So, ideally, we want to automate this
388220	392540	process. We don't want to rely on the developer to destroy our data. Our data should be in
392540	398140	our hands, not the developer's hands. So, you know, this is where Androsia will again
398140	404020	automate that process and instrument code to remove or destroy any object that has critical
404020	416770	information. So how does Androsia help? So Androsia uses static code analysis, and it
416770	423530	determines the last use of objects at a whole program level. If I had to be specific, it
423530	428730	uses a summary-based interprocedural data flow analysis. So there are three terms here,
428730	433390	three key terms. One is summary-based, second is interprocedural, and the third one is data
433390	440830	flow analysis. So static code analysis power is just not grabbing data and giving you information
440830	445410	about what the Android applications permissions are or whatever stuff. It comes from data
445410	452410	flow analysis. So every statement in your program has some data to contribute. And that
452410	457870	data needs to be propagated across all the statements in your application, and every
457870	463190	statement could probably add or remove some data from the data flow sets that are going
463190	470630	on. So that's how powerful data flow analysis is. It will help you perform any sort of data
470630	481170	related analysis, which may include even taint analysis. So that's where the power of static
481170	488710	code analysis is better used. What I mean by summary-based interprocedural analysis
488710	493950	is that this is a whole program analysis. This is not just analyzing a specific method.
493970	499390	And every method, when it is analyzed, the analysis results can be maintained or cached
499390	506110	in a summary. The reason for that is that a particular method, let's say foo, can be
506110	510770	called from multiple locations. And if you have already computed the summary for foo,
510770	516090	you may want to reuse that computed summary instead of computing it again and again whenever
516090	522150	the method is called. So that's why we use summary as a cache for storing our analysis
522150	527590	results for a specific method. And after we have determined the last usage point of a
527590	534790	particular object, we are going to instrument byte code to clear its memory content. So
534790	540510	to give you a very simple example, I have statements numbered 1 to 10 here, and there
540510	546230	is a definition of variable x at statement number 3. And then there is a use of variable
546230	552950	x at statement number 5. So between statement number 3 and 5, since the variable is defined
552950	559930	and used, I can say that the variable is live. But before statement number 3, the variable
559930	566430	x wasn't even defined and neither was it used. So it is said to be dead between 1 and 3.
566430	575610	And now at 7, the variable x gets redefined and then reused at 8. So between 7 and 8,
575610	581270	the variable is again live. However, between 5 and 7, the variable won't be live. It has
581270	587510	been defined, but it is not being used. So this is just to give you an idea about how
587510	592770	liveness of a variable looks like. And we are going to use it further ahead when we
592770	598270	are seeing how Androsia really works and how it computes the liveness sets and how
598270	608100	it then infers the last usage point. So basically, if you have a span of definition and usage,
608100	611040	between that span, a variable is going to be live.
613540	618640	So this is a snapshot of the heap dump taken using Eclipse Memory Analyzer Toolkit. So
618640	624740	I had this sample code which contained a static field which is called static secret
624740	630380	and it contained a password. And it shows up in the heap dump. And after the optimization
630380	636300	or after the instrumentation, the static secret does not contain any password at all because
636300	640220	Androsia has successfully removed the password from the heap memory.
640220	648420	So, in order to give you an overview where Androsia would fit in is that a user could
648420	655620	provide an application or source code to Androsia server. And Androsia server can then unpack
655620	663500	the application to Dalvik byte code. And the Dalvik byte code gets converted into
663500	670160	Gimple code. Now, Gimple is an intermediate representation. Just like Smiley, it is an
670160	675500	intermediate representation which takes good from both the worlds. It takes good from the
675500	681400	Dalvik byte code as well as good from the Java high-level language as well. So Gimple
681400	687320	is basically a mixture of Java and it is simple so they call it Gimple. So Gimple has only
687320	692200	15 different kind of statements. Unlike Java which has a lot of complicated structures
692200	697380	and different kind of statements, even Dalvik byte code has like 200 different opcodes.
697620	704400	So Gimple has only a precise number of statements which is 15 and, you know, it is easier to
704400	708960	analyze when you have just 15 odd statements to play around with. And this Gimple code
708960	716380	is then analyzed by the analysis that we have embedded into Androsia and then the code instrumentation
716380	721280	happens and then we convert the Gimple code back to Dalvik byte code and then the Dalvik
721280	727260	byte code is packaged again and signed or we could just provide the analysis results
727260	737960	to the user. So this is the entire flow of how will you eventually use Androsia. So an
737960	743080	important fact that I should also mention here is that the framework which is called
743080	748840	suit which is the backbone of Androsia can be used to perform any sort of data flow analysis.
748840	755120	It's not just the analysis that I have done. So I'm going to talk about suit next and it
755120	760880	can be used, you know, you can build your own data flow analysis over suit. So suit
760880	767100	is basically static, so it's a framework for Java byte code analysis and it can be used
767100	772660	to implement your own analysis as well. It provides this three address code representation
772660	778500	called Gimple and it looks something like this. So for example, I have an if statement
778500	785520	here and in any line of Gimple code, you will not see more than three operands in one line.
785520	792740	So you have R1, null and label zero here. So it is very simple to view, you know. It's
792740	800800	not like Java that you can have a lot of complicated structures in one statement itself. And this
800800	806800	diagram shows you that the suit framework itself takes in the Java source code or the
806800	812340	class files and converts it into Gimple three address intermediate representation. And
812340	816960	then you can perform your analysis optimization and then again convert it back to the class
816960	822680	files. So until recently, actually, you know, as I talked about that we are going to do
822680	827920	an inter-procedural analysis, so suit also provides you the ability to perform an intra-procedural
827920	836480	analysis. So until now, until recently, suit was missing a Dalvik to Gimple transformation
836480	846020	module. And now that void has been fulfilled. And that void has been fulfilled by a plugin
846020	853100	called Dexplore which allows you to transform Dalvik to Gimple code. So it makes it easier
853100	858680	for you to analyse any Android application. Okay. So there's one more tool that I want
858680	863940	to, you know, talk about here which is called FlowDroid. Now, FlowDroid allows you to generate
864020	869900	a dummy main method because unlike Java, Android does not have, Android applications do not
869900	875520	have a main method. And to start your data flow analysis, you need a starting point.
875600	884110	And this dummy main method acts like a starting point for your data flow analysis. The dummy
884110	891250	main method actually connects all the Android life cycle callbacks. So it gives you, you
904630	916630	know, a dummy main method. So that way, you can start your data flow analysis from a single
916630	925650	point. Okay. So objects can, you know, exist in various scopes. They can either exist as
925870	933170	a local variable inside a method. For example, I have XYZ variables here which contain eventually
933170	938910	the string builder objects. And their scope is limited to this method foo only. They're
938910	946010	not used outside this method anywhere. So this is one simple example which I'm going
946010	950710	to take or, you know, it will be a walk-through example throughout the course of this presentation.
950830	958390	So this example will be recurring. And I have a variable X here which I'm instantiating
958390	963210	with a string builder object. So basically X will be referring to the string builder
963210	967490	which contains the value secret. Y will be referring to the string builder which contains
967490	972210	the value password. And there's some logic here which I'm going to, you know, I'll just
972210	978290	add it for the sake of explaining things. So the scope could be either as a local variable
978290	985890	or your objects could even exist as static fields of a class. And this is completely
985890	990450	different because, you know, the scope of a static field is the entire program. It's
990450	999070	not just a specific method. So X, the value X, can be invoked from anywhere else using
999070	1008450	the class name which is my class. So this is how you will invoke variable, sorry, this
1008450	1017000	is how you will invoke variable X. And this invocation can happen in any other method
1017000	1024720	which is bar in my case. So the scope, you know, becomes the entire program. Or you can
1024720	1030920	have objects as instance field. Here you can see that I have a private access modifier
1030920	1037640	specified for instance field X inside the my instance field string builder class. So
1038340	1045780	the scope of this variable X will now be limited to the scope of the object of this class,
1045780	1056830	my instance field SB. Okay. So coming to the demo, I have three classes here. So I have
1056850	1061770	three classes here. And one of them is the main activity where my control will begin.
1061950	1068290	And this is where the secret has been defined. And then I'm calling the useStaticField method.
1069150	1075770	And the useStaticField method uses the static secret and then calls bar method. And inside
1075770	1082310	the bar method, I'm again using the static secret. So if I had to, you know, just ask
1082310	1087270	you guys to point out the last usage of the static secret, it would be like inside the
1087270	1092770	bar method, right? Here. So the instrumentation should happen immediately after the system.out.println
1092770	1099710	statement of static secret. That's correct. But, you know, there can be loops as well.
1100370	1104590	Like this statement could be inside a for loop. And then the instrumentation point will
1104590	1108610	not be immediately after static secret. It will be right before the return statement
1108610	1114910	of bar method. If there's a loop outside the call to the bar method, then your instrumentation
1114910	1121190	will happen here. Why is that? Because if you instrument it within the loop, then your
1121190	1128670	logic of the application will break. And you don't want that to happen. So we'll see an
1128670	1135230	example, actually a demo on it, which is on the next slide. So this is the same code which
1135230	1141810	I showed you on the last slide. I have a password string builder object being created
1141810	1146390	which contains the value password. And then I'm calling the useStaticField method here.
1147270	1153250	Now we'll see the definition of the useStaticField. The useStaticField is using the static secret
1153250	1159270	and calling bar method. And inside the bar method, we have again useStaticSecret. And
1159270	1166130	then we have two print statements which are printing hello and bye. So if you see, the
1166130	1172450	instrumentation point should be right now just after the last use of static secret,
1172450	1183690	which is on line 20. So let's run the tool on this. So this is how the dummy main method
1183690	1192570	looks like. You'll see it in the stack trace that gets printed out. And right now, the
1192570	1196750	output format is set to jimple so that we can see where the instrumentation is happening.
1196750	1203510	You can even set it to Dalvik bytecode so you'll get a dex format as an output. Alright.
1203510	1207650	We're in the onCreate method, but we need to go to the bar method, right? So inside
1207650	1222170	the bar method... so can we pause the video, please? So you'll see that right here, you
1222170	1228170	have the print line statement for static secret. This is the static secret reference variable,
1228170	1238670	which is an R2. And you're printing the value of R2. And from line number 30 to 34 is where
1238670	1244090	the code from Androsia that has been instrumented. So what I'm doing here is that I'm getting
1244290	1249550	a reference to the static secret field. I'm calculating the length of the static secret
1249550	1255870	field. And I'm using the delete API from zero to the length of the static secret to
1255870	1262870	remove or clear its memory content. So the instrumentation point right now is right after
1262870	1266770	the print line statement for static secret, which is the correct instrumentation point.
1266870	1276190	So can we resume the video, please? Alright. Now what we're going to do is that we're going
1276190	1281930	to remove the for loop here. We're going to uncomment the for loop here. And now the
1281930	1287910	instrumentation point will not be between, will not be actually right after the static
1287910	1294570	secret statement, but it will be right before the by statement here. The system.out.print
1294570	1300810	line for the by statement, by keyword. So yeah. That's because you don't want to instrument
1300810	1305650	within the loop, because in the next iteration of the loop, your resetted value will be used,
1305650	1311550	which will break the logic of the code. Yeah. So this time the instrumentation, which is
1311550	1320170	from 31 to 34, 33, is happening right before the print statement for by, which is the right
1320170	1325790	instrumentation point. And Androzia is smart enough to figure out if there is a loop, it
1325790	1331430	can hoist the instrumentation point outside the loop. So that's the main idea that I want
1331430	1337310	to convey here. And that goes on for any level of nested for loops. You know, you can
1337310	1341670	have the bar method being called from a for loop like this, and then the instrumentation
1341670	1347350	point will change to somewhere in between, somewhere just before returning the use static
1347350	1352850	field method. So the return statement would be somewhere here in the Gimple code, and
1352850	1358270	the instrumentation point will be right before the return statement. This is the use static
1358270	1363290	field, and right before the return statement of the use static field, you'll find the instrumented
1363290	1371210	code from line number 73 to 74, 75, actually. Even 77. So this is the part which gets
1371210	1376650	instrumented, just before the return statement. So you see that the instrumentation points
1376650	1382590	are changing according to the loops that you have inside the code, which is, you know,
1383150	1388030	which may not be because of nested loops, it may be even because of recursion of a
1388030	1393450	specific method. So Androsia will be smartly identifying if there is recursion or loops,
1393450	1400210	and changing the instrumentation points accordingly. So we've seen how Androsia is doing or performing
1400210	1406550	the instrumentation, but we really don't know what is the logic behind that, what is the
1406550	1413710	algorithm that is running behind Androsia. So to come to that, first let's identify what
1413710	1419130	information can a single statement provide us. So there is, every line of statement has
1419130	1424030	some or the other data to add, right? And the data that we are concerned about here
1424030	1435280	is called liveness data. So the next few slides are going to talk about the live variable
1435280	1443060	analysis definition, and how we compute the summary for every method, which is going to
1443060	1448820	look something like this. It will be a two-tuple combination. Basically, the first tuple will
1448820	1456180	be the variable. So the summary of foo method will tell you that the variable x was last
1456180	1461280	used in the statement if y.length is less than x.length. It will be something like this.
1461400	1467240	So for every variable, you will have, you know, a two-tuple element, and the summary
1467240	1472500	will tell you how many variables are there, and what is the last usage point of every
1472500	1479260	variable inside it. So to compute the summary, we have a two-step process. One is to use
1479260	1486280	of, one is to compute the definition and use sets for every statement. Then using the definition
1486900	1492640	and use sets, we are going to compute live variable sets for every statement. LVENTRY
1492640	1499820	and LVEXIT. And using the live variable entry and exit sets, we're going to infer the last
1499820	1506120	usage point for a local or static field reference within that method. And we're going to store
1506120	1513850	that as a summary. And now, once we have the summaries for every method that is analyzed
1513850	1520390	by Androsia, we're going to compute the last usage point of a static field reference, considering
1520390	1525170	the whole program, not just within a method. Because we know that the summary will tell
1525170	1529590	us that within a method, this is the last usage point of a particular local variable.
1529590	1534490	But it will not tell us across the entire program where is the last usage actually happening.
1534490	1541030	So the summaries need to be combined and propagated across your program to infer that knowledge.
1544400	1550180	So to start off with the definition of live variable analysis, live variable analysis
1550180	1555820	determines for each statement, which variables must have a subsequent use prior to the next
1555820	1560180	definition, which is what we learned from the diagram we saw earlier, right? We had
1560180	1565500	a definition and use of variable X. And between that span, the variable was live. And after
1565500	1570600	that, it was dead. So this is exactly what the statement is telling us. So in this particular
1570600	1578340	code, the last usage point of variable X is this blue statement, which is number 4. And
1578340	1588240	the last usage point of Y is statement number 5 and 6. Because they are two different statements
1588240	1592760	within the if clause. So either this one could execute or this one could execute based on
1592760	1599540	the result from the if clause. And the last use of Z is statement number 7. So this is
1599540	1606020	very intuitive, right? We can see it. But how do you determine this using an automated
1606020	1612500	way? That's the question. And it's not as easy as it seems like. So we're going to run
1612500	1617400	through this same example in the next few slides and figure out how we determine the
1617400	1623540	last usage points of X, Y, and Z. So the last usage point of a variable is also the
1623540	1630300	last statement where that variable was live. So X is last live here. And it is also the
1630300	1635840	last usage point of that variable X. So we're going to use this fact to determine the last
1635840	1644260	usage point of every variable. So talking about the def use sets, the definition of
1644300	1650340	a definition set is that it will contain all the variables defined in a particular statement.
1650460	1657420	So in statement number 1, X is being defined. So for statement 1, you'll have an entry X.
1657980	1664720	So the use set are the set of variables that are used in a statement. So if we run through
1664720	1669900	this example and compute the def use set, they will look something like this. So we
1669900	1676360	start from the bottom. Z is being used here. So it will go in the use column for statement
1676360	1682320	number 7. And X is being defined here. So it will go in the definition column for statement
1682320	1689400	number 7. And similarly, if we keep going, it will eventually populate the entire table.
1690420	1698520	So the direction of propagating that data or propagating the data flow facts is from
1698520	1704900	bottom to top. It is the reverse order of execution of the program. So if I compute
1704900	1712620	the live variable of exit of 6th statement, which is the last statement in my code, then
1712620	1718920	it is going to be 5. Because there is no other variable which is being used after statement
1718920	1724920	number 6. So this is a must. Like this has to be 5 because there cannot be any other
1724920	1730440	variable which is used after the last statement in the code. So this will be an initial point
1730440	1736620	for the algorithm to run. And once you compute LVExit of 6, you are going to use the def
1736620	1744560	use set of 6 to compute LVEntry of 6. And then you will compute LVExit of 5, then you
1744560	1751400	will compute LVEntry of 5, then LVExit of 4, LVEntry of 4. Similarly, once you reach
1751400	1758660	at a point where there is two branches, you are going to merge the results from LVEntry
1758660	1769640	3 and LVEntry 4 using a union operator. And that result will go into LVExit of 2. And
1769640	1776500	using LVExit of 2, we are going to compute LVEntry of 2 and so on. So that's up next.
1776500	1781320	We are going to use the same example, the one we discussed for the def use set and we
1781320	1785600	are going to compute these things. So if I had to give you a mathematical representation,
1785600	1790980	I mean, there's nothing possible without math here because data flow analysis needs to have
1790980	1796560	math backing it up for proof of correctness. And without any algorithm or without some
1796560	1803280	math, there's no way you can perform a data flow analysis. So the LVExit of a statement
1803280	1809600	L will be 5 if L is the last statement of the body, which is what we discussed on the
1809600	1820460	last slide. And it will be the union over the LVEntry set of the successors of L. Otherwise,
1820460	1826720	so if you have a merge point, we'll have to take this LVEntry sets and do a union over
1826720	1833840	all the entry sets to compute LVExit of L. Now once we have the LVExit of L, we are going
1833840	1840920	to plug that value here and we already computed LVEfinition and use it for a statement L.
1841660	1849320	And that's going to give us LVEntry of L. Let's see this in action. So we have the def
1849320	1857100	use columns populated. We know that the LVExit of 7 statement will be 5 because this is the
1857100	1863820	last statement. And now we are going to use this formula to compute LVEntry of 7. So LVExit
1863820	1877720	of 7 will be 5 minus x union z, which will give you z. And then LVEntry of 7 will form
1877720	1887620	the LVExit of 6. So LVExit of 6 will be z. And now z minus z union y will give you y.
1887620	1893800	So you get the LVEntry of statement number 6 as well. And so on, you can populate this
1893800	1902700	table iteratively and you get the entire table. Now, the interesting part to note
1902700	1910440	here is that if a variable disappears from the entry set to the exit set in the live
1910440	1916920	variable table, like in the fourth statement, we have x disappearing from the entry set
1916920	1923560	to the exit set. In the fifth and sixth statement, y disappears from entry set to the exit set.
1923560	1929680	And in the seventh statement, we see that z disappears from the entry set to the exit
1929680	1935540	set. So those will be, the corresponding numbers will be the last usage point of those variables.
1936060	1943380	And that's what we were after. We've got that now. So now we're going to store all these
1943380	1950240	results, the last usage point results, as the summary of foo method. And we're going
1950240	1955280	to use this summary in other parts of the program when the foo method gets invoked from
1955280	1961520	there. We don't want to compute this again and again and again. So let's just say that
1961520	1967740	foo was, there was a method foo which calls bar and bar called baz. Okay? So, and just,
1968440	1972920	we've already computed, let's just assume that we've already computed summaries for each
1972920	1978640	of these individual methods. Foo, bar, as well as baz. And baz will tell me that, the
1978640	1984700	summary of baz is going to tell me that static field reference was last used at C4. The
1984700	1990320	summary for bar is telling me that the static field reference was used at B5. And there
1990320	1997460	was no use of SFR in foo. Now what I'm going to do is, I'm going to propagate the summaries
1997460	2005600	across these methods in a reverse topological order. So, this is how the analysis will run.
2005600	2011480	And when you read statement C4, you see that SFR is being used. What I'm going to do is
2011480	2019500	create a data structure with the value baz, SFR, C4, which is going to tell me that the
2019500	2028680	last use of SFR is happening at C4 statement in baz method. Okay? And once I reach, I've
2028680	2034220	already analyzed, I've completed the analysis for baz method, I'm going to analyze the bar
2034220	2040660	method. So, the analysis happens in a reverse topological order. So, if baz is the last
2040660	2045080	method that is called, it will be analyzed first. If bar is the second last method that
2045080	2049640	is analyzed, it will be, you know, if bar is the second last method that is called,
2049640	2055360	it will be analyzed second last. And if the first, sorry, so basically foo is calling
2055360	2059480	bar, bar is calling baz, baz will be analyzed first, bar will be analyzed second, and then
2059480	2067100	you'll analyze foo. So, here, we see that SFR is being used at B5. So, the LV entry
2067100	2074120	will contain B5 SFR. And once we reach the call statement for baz, we're going to pull
2074120	2080760	in the summary of baz method from here. And now we're going to see whether the LV entries,
2080760	2086740	LV exit set of B3 already contains an SFR's use, and it does in our case. So, we're going
2086740	2093280	to replace the value of this little red data structure with the new entry, which will
2093280	2099760	be bar SFR B5, which would mean that SFR is last used at B5 statement inside bar method.
2100060	2106460	So, this is how you'll keep on going and updating the red data structure. And once the analysis
2106460	2112220	is complete over all these methods, you'll realize that the red data structure will complete
2112220	2119440	the last usage point of the SFR variable across the entire program. So, similarly,
2119440	2124000	if you go ahead and see that there's a bar method invocation here, you're going to pull
2124000	2131360	in the summary for bar method, but the exit set of A3 contains 5, because SFR is not being
2131360	2137900	used ahead in the program inside the foo method. So, this summary will not be over, this particular
2137900	2143040	value will not be overwritten by anything, because it's just 5 that is being coming from
2143040	2148100	the exit set of A3. We just completed our analysis, and the results tell us that SFR
2148100	2155100	was last being used at B5 statement inside the bar method. So, this is how, you know,
2155100	2160260	algorithmically, Androsia will run on your code and figure out what is the last usage
2160260	2168500	point of any object in that application. Just to summarize, we went through this definition
2168500	2175700	of live variable analysis. We computed summaries for individual methods using a two-step process.
2175700	2180580	One of the steps is to compute the defuse set for every statement, and using the defuse
2181840	2187980	sets, we computed the LV entry and exit sets, and using the LV entry and exit sets, we figured
2187980	2193380	out the last usage point of every static field reference or local method, and put it
2193380	2197660	in a summary, and eventually, we used the summary to compute the last usage point for
2197800	2204800	a static field reference at a whole program level. Phew! So, that was too much. I mean,
2204800	2208260	just intuitively, you can see what is the last use point, but to automate that, you
2208260	2217900	require a lot of algorithm and math. So, yeah, I mean, things are not easy always. So, for
2217900	2223020	instance field approach, the approach, you know, for instance fields is a little different.
2223020	2227900	What we do is we mark all the classes which are string builder instance fields. We find
2227900	2233420	their object instances. We track the last usage of object instances and their aliases
2233420	2239400	instead of the string builder fields themselves. We will actually see a demo of this again,
2239400	2245380	and I think that would explain this even better. So, just let's see, we have three classes
2245380	2249440	here, which one of them is main activity. This is where my control is going to start.
2249480	2255580	I have a secret defined here, which is a variable, which is going into a variable my secret,
2256320	2263320	and then I'm instantiating the my class, which is here, and the variable that is referring
2263320	2269300	to the object of my class is mc. Then we have a wrapper class whom I'm instantiating, and
2269300	2278740	the reference variable for that is w. And then I have a call to call w method, which
2278740	2285080	is defined inside the wrapper method. Wrapper class, sorry. And I'm passing the mc object
2285080	2291620	instance to this call w method, which is invoking set a to pass on the secret value here, and
2291620	2295920	this is just a setter method, which is setting the value of a. So, basically, the secret
2295920	2301900	is here, then it goes here, and then it gets defined in this, and then it gets set in the
2301900	2308940	setter method to the instance field a, which is a private instance field. So, in order
2308940	2314340	to reset, if we had to reset this private instance field, we cannot just do it outside
2315080	2320580	from within the on create method. We need to invoke a method within the class to reset
2320580	2327520	the value of a, because it has been privately, the access modifier is private, so we can't,
2327520	2339600	you know, access it outside its class. So, let's just quickly jump on to the demo. So,
2339600	2344180	the steps that I had explained on the previous slides were we mark all classes which are
2344180	2351060	string builder instance fields, which will be my class. We find the object instances,
2351060	2358100	which is MC. Then we track the last uses of object instances, which is here in the call
2358100	2365620	W statement. And then we instrument the code right after the call W statement. And here,
2365620	2372280	you can see that I'm invoking a method, which is reset SBA. And this reset SBA is being
2372280	2378040	defined in the class right here. That's because I cannot access the private instance field
2378040	2386620	small a within the on create method. So, I have to invoke this reset method. All right.
2386620	2393180	So, let's have a look at the demo. Pretty same code. Pretty much the same code. I have
2393180	2399760	the call W statement here where I'm passing MC and my secret. And I also have the wrapper
2399760	2407280	class here instantiated. And the reference variable is W. And I'm printing the W.SB field.
2407280	2414280	So, SBField is another string builder instance field of wrapper class. And A and B, we can
2414280	2422020	see that. So, A and B will be instance fields of my class. And SB will be an instance field
2422020	2433260	in the wrapper class. We'll see that just in a while. So, you can see that we have an
2433260	2440140	instance field SB here in the wrapper class. And I'm calling set A and passing on the secrets
2440140	2446220	value to the set A method. And my class has A and B as its instance fields. And inside
2446220	2453380	the set A method, I'm setting the value of the secret to A. B is nowhere used right now.
2460820	2465640	So, inside the wrapper class, you see that the method call W also has a secret defined
2465640	2479650	called password. And its last use is inside the call W method. So, B is used here. MC
2479650	2486250	is last used here. And W is last used here. So, the instrumentation point for A and B
2486250	2491730	should be right after the call W statement here. And the instrumentation point for the
2491730	2500950	string build SB should be right after the WSB statement here. So, you see here that
2500950	2507010	there's a call W method being invoked. And I have the reset methods being injected or
2507010	2512830	instrumented right after the call W method. Because we were tracking MC. And MC's last
2512830	2519030	use was in the call W method call. And after that, we have reset both the instance fields.
2519030	2526570	And similarly, for the wrapper class, we had an instance field SB which is being reset right
2526570	2542630	here in statement number 58. So, these reset methods are defined in the respective classes
2542630	2551430	which have those instance fields. So, if we go to the respective classes, this is the wrapper
2551430	2556310	class and the reset method has been defined here. What it's doing is the same thing. It's
2556310	2560690	calling the length function on the string builder. And then it's calling the delete
2560690	2571380	API to remove the content of the string builder. And similarly, we have reset methods for variable
2571380	2579800	A and B, which were the instance field in my class. Here we have reset SBB, which is
2579800	2588360	the reset method for variable B. So, you know, we've tackled all the three scopes now. We
2588360	2593820	know how to deal with instance fields. We know how to deal with static fields. We also
2593820	2599120	know how to deal with local variables. So, I mean, we did not need to see all of this
2599120	2602940	because this is too much in depth. But if you want to go ahead and implement your own
2602940	2608000	static code analysis, this is important stuff for you. So, I mean, I thought it appropriate
2608000	2615900	to be, you know, displayed here. So, the work in progress is basically we're working on
2615900	2621080	a test development so that we can, you know, get rid of the remaining bugs that we have.
2621080	2627020	And we're also planning to include this into the CICD pipeline, which should be straightforward.
2627280	2632680	And that way, a lot of big companies could, you know, just plug in their APKs and just
2632680	2637480	push it across to us. And then we can just analyze those APKs and instrument the code
2637480	2646320	that Androsia, you know, instruments to clear the memory contents of the APK. So, that way,
2646320	2651920	it will be helpful for big corporates and especially the enterprise mobility management
2651920	2658360	companies. So, if you want to use Androsia or you want to contribute or get in touch,
2658360	2662980	this is the URL you should take a note of. And the tool and documentation will be available
2662980	2669100	here. And if you want to contribute to the tool, here's my Twitter account or email.
2669100	2682120	You can just shoot out an email to me. All right. So, these are some good references.
2682160	2687200	The first three ones will get you started when it comes to creating your own data flow
2687200	2694300	analysis. And the last two ones are a little bit more in-depth. If you want to, you know,
2694300	2699320	see how things are actually working in the background. I'll anyways post these slides
2699320	2709660	on the website of DEF CON. So, you can have a look at these references. Cool. So, that
2709660	2715500	brings me to the end of my talk. Thank you for your time. I'm really happy to speak over
2715500	2719160	here on this podium. I hope you enjoyed it. Thank you very much.
