Skip to content

Commit

Permalink
Allow specifying expected type.
Browse files Browse the repository at this point in the history
  • Loading branch information
lapo-luchini committed Apr 19, 2024
1 parent 3f5e5fa commit 8400fa7
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions dumpASN1.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,26 @@ try { // try PEM first
let result = ASN1.decode(content);
content = null;
const t0 = performance.now();
const types = Defs.commonTypes
.map(type => {
const stats = Defs.match(result, type);
return { type, match: stats.recognized / stats.total };
})
.sort((a, b) => b.match - a.match);
const t1 = performance.now();
console.log('Parsed in ' + (t1 - t0).toFixed(2) + ' ms; possible types:');
for (const t of types)
console.log((t.match * 100).toFixed(2).padStart(6) + '% ' + t.type.description);
Defs.match(result, types[0].type);
// const stats = Defs.match(result, types[0].type);
// console.log('Stats:', stats);
console.log('Parsed as:', result.def);
// const type = searchType(process.argv[2]);
// const stats = applyDef(result, type);
if (process.argv.length == 5) {
Defs.match(result, Defs.moduleAndType(Defs.RFC[process.argv[3]], process.argv[4]));
} else {
const types = Defs.commonTypes
.map(type => {
const stats = Defs.match(result, type);
return { type, match: stats.recognized / stats.total };
})
.sort((a, b) => b.match - a.match);
const t1 = performance.now();
console.log('Parsed in ' + (t1 - t0).toFixed(2) + ' ms; possible types:');
for (const t of types)
console.log((t.match * 100).toFixed(2).padStart(6) + '% ' + t.type.description);
Defs.match(result, types[0].type);
// const stats = Defs.match(result, types[0].type);
// console.log('Stats:', stats);
console.log('Parsed as:', result.def);
// const type = searchType(process.argv[2]);
// const stats = applyDef(result, type);
}
console.log(print(result));
// console.log('Stats:', (stats.recognized * 100 / stats.total).toFixed(2) + '%');
// // print(result, searchType(process.argv[2]), stats);
Expand Down

0 comments on commit 8400fa7

Please sign in to comment.