diff --git a/src/components/Packet.vue b/src/components/Packet.vue index 23d7b93..de73ce6 100644 --- a/src/components/Packet.vue +++ b/src/components/Packet.vue @@ -5,12 +5,12 @@ - - +

+

@@ -30,7 +30,13 @@ computed: { hexdata() { const dataString = atob(this.packet.content); - return this.hexdump(dataString, this.$store.state.hexdumpBlockSize, this.$store.state.hexdumpLineNumberBase); + const dump = this.hexdump(dataString, this.$store.state.hexdumpBlockSize, this.$store.state.hexdumpLineNumberBase); + return this.escapeHtml(dump) + .split('\n') + .join('
'); + }, + stringdata() { + return this.base64ToHtml(this.packet.content); }, }, methods: { @@ -64,7 +70,7 @@ }); }, escapeHtml(in_) { - return in_.replace(/[&<>"'/]/g, s => { + return in_.replace(/(|<\/span>)|[&<>"'/]/g, ($0, $1) => { const entityMap = { '&': '&', '<': '<', @@ -74,11 +80,36 @@ '/': '/', }; - return entityMap[s]; + return $1 ? $1 : entityMap[$0]; }); }, - base64ToHtml(in_) { - return this.escapeHtml(atob(in_)).split('\n').join('
'); // Replace all \n to
+ base64ToHtml(in_) { // FIXME: Пересекающиеся паттерны приводят к неожиданным результатам + let raw = atob(in_); + const patterns = this.$store.state.patterns.reduce((obj, item) => { + obj[item.id] = item; + return obj; + }, {}); + let offset = 0; + this.packet.matches + .sort((a, b) => a.startPosition - b.startPosition) + .forEach(match => { + const pattern = patterns[match.patternId]; + if (!pattern) { + console.info(`Pattern #${match.patternId} does not exist`); + return; + } + const firstTag = ``; + const secondTag = ''; + + const positionStart = match.startPosition + offset; + raw = raw.substring(0, positionStart) + firstTag + raw.substring(positionStart); + offset += firstTag.length; + + const positionEnd = match.endPosition + offset; + raw = raw.substring(0, positionEnd) + secondTag + raw.substring(positionEnd); + offset += secondTag.length; + }); + return this.escapeHtml(raw).split('\n').join('
'); // Replace all \n to
}, copyPythonBytes() { @@ -122,7 +153,7 @@ box-shadow: 0 0 5px 5px rgba(251, 233, 231, 0.4); } - code { + p { font-family: "Ubuntu Mono", "Lucida Console", monospace; font-size: 100%; color: black; diff --git a/src/components/PatternsDropdown.vue b/src/components/PatternsDropdown.vue index 45f9268..88db3e7 100644 --- a/src/components/PatternsDropdown.vue +++ b/src/components/PatternsDropdown.vue @@ -7,7 +7,7 @@ - {{ pattern.name }}: {{ pattern.regex ? `/${pattern.value}/` : `'${pattern.value}'` }}; @@ -29,7 +29,7 @@ name: 'PatternsDropdown', data() { return { - patterns: Array(), + // patterns: Array(), }; }, mounted() { @@ -41,7 +41,7 @@ }, updatePatterns() { this.$http.get('pattern/') - .then(r => this.patterns = r.data) + .then(r => this.$store.commit('setPatterns', r.data)) .catch(e => { this.$bvToast.toast(`Не удалось загрузить паттерны: ${e}`, { title: 'Сбой', @@ -75,11 +75,11 @@ }, addPatternFromWs(pattern) { - this.patterns.push(pattern); + this.$store.commit('addPattern', pattern); }, deletePatternFromWs(id) { - this.patterns = this.patterns.filter(o => o.id !== id); + this.$store.commit('setPatterns', this.$store.state.patterns.filter(o => o.id !== id)); }, }, }; diff --git a/src/store.js b/src/store.js index 3fdbf11..c422215 100644 --- a/src/store.js +++ b/src/store.js @@ -20,6 +20,8 @@ export default new Vuex.Store({ serviceModalName: '', serviceModalId: 0, + + patterns: [], }, mutations: { setApiLogin: (s, p) => s.apiLogin = p, @@ -36,6 +38,9 @@ export default new Vuex.Store({ setServiceModalName: (s, p) => s.serviceModalName = p, setServiceModalId: (s, p) => s.serviceModalId = p, + + setPatterns: (s, p) => s.patterns = p, + addPattern: (s, p) => s.patterns.push(p), }, actions: {}, plugins: [ @@ -49,7 +54,9 @@ export default new Vuex.Store({ && mName !== 'setServiceModalName' && mName !== 'setServiceModalId' && mName !== 'togglePause' - && mName !== 'toggleHexdumpMode'; + && mName !== 'toggleHexdumpMode' + && mName !== 'setPatterns' + && mName !== 'addPattern'; console.debug('Processing?', process); return process; },