def test_dynamic_varnode_pickle(self): # shift B by a temporary varnode with a value set in the root context temp_varnode = varnode(default="temp_varnode_default") shifted_ctx = self.ctx.shift({B : temp_varnode}) self.ctx[temp_varnode] = "temp_varnode" self.assertEquals(shifted_ctx[B], "temp_varnode") # pickle the context, unregister the node and recreate the context x = pickle.dumps(self.ctx) MDFContext.unregister_node(temp_varnode) new_ctx = pickle.loads(x) # find the shifted context (can't reshift as temp_varnode was unregistered) self.assertEquals(len(new_ctx.get_shifted_contexts()), 1) shifted_ctx = new_ctx.get_shifted_contexts()[0] # check that B in the shifted context is still set self.assertEquals(shifted_ctx[B], "temp_varnode") # check that temp_varnode refers to the original node, not the new one # that had to be recreated when un-pickled. self.assertEquals(shifted_ctx[temp_varnode], "temp_varnode_default")
def test_dynamic_varnode_pickle(self): # shift B by a temporary varnode with a value set in the root context temp_varnode = varnode(default="temp_varnode_default") shifted_ctx = self.ctx.shift({B: temp_varnode}) self.ctx[temp_varnode] = "temp_varnode" self.assertEquals(shifted_ctx[B], "temp_varnode") # pickle the context, unregister the node and recreate the context x = pickle.dumps(self.ctx) MDFContext.unregister_node(temp_varnode) new_ctx = pickle.loads(x) # find the shifted context (can't reshift as temp_varnode was unregistered) self.assertEquals(len(new_ctx.get_shifted_contexts()), 1) shifted_ctx = new_ctx.get_shifted_contexts()[0] # check that B in the shifted context is still set self.assertEquals(shifted_ctx[B], "temp_varnode") # check that temp_varnode refers to the original node, not the new one # that had to be recreated when un-pickled. self.assertEquals(shifted_ctx[temp_varnode], "temp_varnode_default")