Skip to content

Commit

Permalink
Find a way to propogate models
Browse files Browse the repository at this point in the history
  • Loading branch information
jawline committed Apr 22, 2018
1 parent f937bbc commit a2c538e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 43 deletions.
23 changes: 17 additions & 6 deletions Analyser/src/FunctionModels.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,11 @@ function BuildModels(state) {
}

model.add(Array.prototype.push, function(base, args) {

const is_symbolic = state.isSymbolic(base);
const args_well_formed = state.getConcrete(base) instanceof Array;
Log.logMid('TODO: Push prototype is not smart enough to decide array type');
const args_well_formed = state.getConcrete(base) instanceof Array
&& state.arrayType(base) == typeof(state.getConcrete(args[0]));

if (is_symbolic) {
Log.log('Push symbolic prototype');
const array = state.asSymbolic(base);
Expand All @@ -182,8 +184,11 @@ function BuildModels(state) {
});

model.add(Array.prototype.pop, function(base, args) {

const is_symbolic = state.isSymbolic(base);
const args_well_formed = state.getConcrete(base) instanceof Array;
const args_well_formed = state.getConcrete(base) instanceof Array
&& state.arrayType(base) == typeof(state.getConcrete(args[0]));

Log.log('TODO: Push prototype is not smart enough to decide array type');
if (is_symbolic && args_well_formed) {
Log.log('Push symbolic prototype');
Expand All @@ -208,7 +213,12 @@ function BuildModels(state) {

model.add(Array.prototype.indexOf, symbolicHook(
Array.prototype.indexOf,
(base, args) => state.isSymbolic(base) && state.getConcrete(base) instanceof Array && typeof(args[0]) === typeof(base[0]) /* TODO: Give arrays a type on the concolic object rather than this */,
(base, args) => {
const is_symbolic = state.isSymbolic(base) && state.getConcrete(base) instanceof Array;
const is_same_type = state.arrayType(base) == typeof(state.getConcrete(args[0]));
console.log(state.arrayType(base) + ' vs ' + typeof(args[0]));
return is_symbolic; //&& is_same_type;
},
(base, args, result) => {

const searchTarget = state.asSymbolic(args[0]);
Expand Down Expand Up @@ -267,8 +277,9 @@ function BuildModels(state) {
Array.prototype.includes,
(base, args) => {
const is_symbolic = state.isSymbolic(base);
const is_well_formed = state.getConcrete(base) instanceof Array;
return is_symbolic && is_well_formed;
const args_well_formed = state.getConcrete(base) instanceof Array
&& state.arrayType(base) == typeof(state.getConcrete(args[0]));
return is_symbolic && args_well_formed;
},
(base, args, result) => {

Expand Down
2 changes: 1 addition & 1 deletion Analyser/src/SymbolicExecution.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class SymbolicExecution {

//TODO: Enumerate if symbolic offset and concrete input

if (this.state.isSymbolic(base) && this.state.getConcrete(base) instanceof Array) {
if (this.state.isSymbolic(base) && this.state.getConcrete(base) instanceof Array && this.state.arrayType(base) == typeof(val)) {
Log.log(`TODO: Check that setField is homogonous`);

//SetField produce a new array
Expand Down
8 changes: 7 additions & 1 deletion Analyser/src/SymbolicState.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,13 @@ class SymbolicState {
}

let symbolic;
let arrayType;

if (concrete instanceof Array) {
this.stats.seen('Symbolic Arrays');
symbolic = this.ctx.mkArray(name, this._getSort(concrete[0]));
this.pushCondition(this.ctx.mkGe(symbolic.getLength(), this.ctx.mkIntVal(0)), true);
arrayType = typeof(concrete[0]);
} else {
this.stats.seen('Symbolic Primitives');
const sort = this._getSort(concrete);
Expand All @@ -305,7 +307,7 @@ class SymbolicState {
this.inputSymbols[name] = symbolic;

Log.logMid(`Initializing fresh symbolic variable ${symbolic} using concrete value ${concrete}`);
return new ConcolicValue(concrete, symbolic);
return new ConcolicValue(concrete, symbolic, arrayType);
}

getSolution(model) {
Expand Down Expand Up @@ -366,6 +368,10 @@ class SymbolicState {
return val instanceof WrappedValue ? val.getConcrete() : val;
}

arrayType(val) {
return val instanceof WrappedValue ? val.getArrayType() : undefined;
}

getSymbolic(val) {
return ConcolicValue.getSymbolic(val);
}
Expand Down
41 changes: 10 additions & 31 deletions Analyser/src/Values/WrappedValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,37 +45,15 @@ class WrappedValue {
}
}

class Types {

constructor(initial) {
this._types = initial;
}

add(type) {
this._types.push(type);
return this;
}

remove(type) {
const typeIdx = this._types.indexOf(type);

if (typeIdx != -1) {
this._types.splice(typeIdx, 1);
}

return this;
}

serialize() {
return JSON.stringify(this._types);
}
}

class ConcolicValue extends WrappedValue {

constructor(concrete, symbolic) {

/**
* TODO: I'm not sure I like passing array type with concolic values to sanity check comparisons
*/
constructor(concrete, symbolic, arrayType = undefined) {
super(concrete);
this.symbolic = symbolic;
this._arrayType = arrayType;
}

toString() {
Expand All @@ -94,9 +72,10 @@ class ConcolicValue extends WrappedValue {
return this.symbolic;
}

getType() {
return typeof this.getConcrete();
getArrayType() {
return this._arrayType;
}

}

ConcolicValue.getSymbolic = function(val) {
Expand All @@ -109,4 +88,4 @@ ConcolicValue.setSymbolic = function(val, val_s) {
}
};

export {WrappedValue, Types, ConcolicValue};
export {WrappedValue, ConcolicValue};
2 changes: 1 addition & 1 deletion Tester/src/TestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if (process.argv.length >= 3) {

console.log('Test runner searching ' + target);

let numConcurrent = 2;
let numConcurrent = 6;

let concurrent = getArgument('--concurrent', numConcurrent);

Expand Down
10 changes: 7 additions & 3 deletions tests/test_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,13 @@ function buildTestList() {
buildTest('regex/core/literals/non_alpha.js', 2, 2);
buildTest('regex/core/literals/multiple.js', 6, 6);

buildTest('regex/core/escaping/hex.js', 5, 4);
buildTest('regex/core/escaping/unicode.js', 6, 5);
buildTest('regex/core/escaping/unicode_mode.js', 6, 5);
/**
* TODO: Find out of unicode support is possible through some screwing with Z3 strings
* buildTest('regex/core/escaping/hex.js', 5, 4);
* buildTest('regex/core/escaping/unicode.js', 6, 5);
* buildTest('regex/core/escaping/unicode_mode.js', 6, 5);
*/

buildTest('regex/core/escaping/ranges.js', 8, 8);
buildTest('regex/core/escaping/negative_ranges.js', 3, 2);
buildTest('regex/core/escaping/space_class.js', 8, 7);
Expand Down

0 comments on commit a2c538e

Please sign in to comment.