32bit-adressing-table-modrm
Version:
Intel- 32-Bit Addressing Forms with the ModR/M Byte converted to an easily searchable Hashmap, also includes a reverse search.
98 lines (97 loc) • 4.22 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Table = void 0;
var createTable_1 = require("./createTable");
var Table = /** @class */ (function () {
function Table() {
var _this = this;
this.set1 = new Set(['al', 'ax', 'eax', '0']);
this.set2 = new Set(['cl', 'cx', 'ecx', '1']);
this.set3 = new Set(['dl', 'dx', 'edx', '2']);
this.set4 = new Set(['bl', 'bx', 'ebx', '3']);
this.set5 = new Set(['ah', 'sp', 'esp', '4']);
this.set6 = new Set(['ch', 'bp', 'ebp', '5']);
this.set7 = new Set(['dh', 'si', 'esi', '6']);
this.set8 = new Set(['bh', 'di', 'edi', '7']);
this.sets = [this.set1, this.set2, this.set3, this.set4, this.set5, this.set6, this.set7, this.set8];
this.table32rm = createTable_1.create32bitModRmTable();
this.table32sib = createTable_1.create32bitSIBtable();
this.table16rm = createTable_1.create16bitRmTable();
this.reversed32rmTable = new Map();
this.reversed32sibTable = new Map();
this.reversed16rmTable = new Map();
this.table32rm.forEach(function (value, key) {
value.forEach(function (value1, key1) {
_this.reversed32rmTable.set(value1, [key, key1]);
});
});
this.table16rm.forEach(function (value, key) {
value.forEach(function (value1, key1) {
_this.reversed16rmTable.set(value1, [key, key1]);
});
});
this.table32sib.forEach(function (value, key) {
value.forEach(function (value1, key1) {
_this.reversed32sibTable.set(value1, [key, key1]);
});
});
}
Table.prototype.getReverseValueFromTable = function (op, type) {
var table = type ? this.getTable(type, true) : this.reversed32rmTable;
var sets = table.get(op);
// @ts-ignore
var secondSet = this[sets[0]];
// @ts-ignore
var firstSet = this[sets[1]];
// @ts-ignore
return [firstSet ? Array.from(firstSet) : [sets[1]], !!secondSet ? Array.from(secondSet) : [sets[0]]];
};
Table.prototype.getTable = function (type, reversed) {
switch (type) {
case '16rm':
return !reversed ? this.table16rm : this.reversed16rmTable;
case '32rm':
return !reversed ? this.table32rm : this.reversed32rmTable;
case '32sib':
return !reversed ? this.table32sib : this.reversed32sibTable;
}
};
Table.prototype.getValueFromTable = function (op1, op2, type) {
var _a, _b, _c, _d;
var table = type ? this.getTable(type) : this.table32rm;
var setNameForOp1 = this.presentInSet(op1);
var setNameForOp2 = this.presentInSet(op2);
if (type === '32sib') {
op1 = op1.includes('[*]') ? op1 : op1.replace('[', '').replace(']', '');
op2 = op2.includes('*1') ? op2.replace('*1', '') : op2;
return table.get(op1).get(op2);
}
//check rm byte
if (op1.length === 1) {
return (_a = table.get(setNameForOp1)) === null || _a === void 0 ? void 0 : _a.get(setNameForOp2 ? setNameForOp2 : op2);
}
//both are sets
if (setNameForOp1 && setNameForOp2) {
return (_b = table.get(setNameForOp2)) === null || _b === void 0 ? void 0 : _b.get(setNameForOp1);
}
//only one is in a set
if (setNameForOp1) {
return (_c = table.get(setNameForOp1)) === null || _c === void 0 ? void 0 : _c.get(op2);
}
if (setNameForOp2) {
return (_d = table.get(setNameForOp2)) === null || _d === void 0 ? void 0 : _d.get(op1);
}
throw new Error('Could not find value');
};
Table.prototype.presentInSet = function (op) {
var setName;
this.sets.some(function (s, index) {
if (s.has(op)) {
setName = "set" + (index + 1);
}
});
return setName;
};
return Table;
}());
exports.Table = Table;