Skip to content

Commit

Permalink
Improve filter logic
Browse files Browse the repository at this point in the history
  • Loading branch information
qtc-de committed Jul 25, 2024
1 parent ded128d commit 820f5c5
Show file tree
Hide file tree
Showing 2 changed files with 184 additions and 91 deletions.
113 changes: 97 additions & 16 deletions frontend/src/components/InterfacePane.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,112 @@
this.selectedInterface = intf;
},
applyFilter(filter, intf)
casualFilter(intf, filter)
{
if (!filter)
let inverse = false;
if (filter.startsWith('!'))
{
return true;
filter = filter.substring(1);
inverse = true;
}
filter = filter.toLowerCase();
return (intf.id.toLowerCase().includes(filter) || intf.location.toLowerCase().includes(filter) ||
intf.description.toLowerCase().includes(filter) || intf.name.toLowerCase().includes(filter) ||
intf.annotation.toLowerCase().includes(filter)) != inverse;
},
if (!filter.includes(':'))
getInterfaces: function*(filter)
{
for (const intf of this.selectedProcess.rpc_info.interface_infos)
{
let inverse = false;
if (filter.startsWith('!'))
if (filter)
{
filter = filter.substring(1);
inverse = true;
let match = true;
filter = filter.toLowerCase();
if (!filter.includes(':') && !this.casualFilter(intf, filter))
{
match = false;
}
else
{
const filterArray = filter.split(/\s*\|\s*/);
for (const entry of filterArray)
{
let key, value;
let inverse = false;
[key, value] = entry.split(':', 2);
if (key === 'uuid')
{
key = 'id';
}
if (value === undefined)
{
if (!this.casualFilter(intf, key))
{
match = false;
break;
}
continue;
}
if (value.startsWith('!'))
{
value = value.substring(1);
inverse = true;
}
if (Object.hasOwn(intf, key))
{
const propValue = intf[key];
if (Array.isArray(propValue))
{
let found = false;
for (const item of propValue)
{
if (String(item).toLowerCase().includes(value))
{
found = true;
break;
}
}
if (!found != inverse)
{
match = false;
break;
}
}
else
{
if (String(propValue).toLowerCase().includes(value) == inverse)
{
match = false;
break;
}
}
}
}
}
if (!match)
{
continue;
}
}
return (intf.uuid.toLowerCase().includes(filter) || intf.location.toLowerCase().includes(filter) ||
intf.decs.toLowerCase().includes(filter) || intf.name.toLowerCase().includes(filter) ||
intf.annotation.toLowerCase().includes(filter)) != inverse;
yield intf;
}
return true;
},
interfaceClick(e, item)
Expand Down Expand Up @@ -106,7 +187,7 @@
<th class="InterfaceColumn">Annotation</th>
<th class="InterfaceColumn">EpRegistred</th>
</tr>
<tr v-if="selectedProcess && applyFilter(interfaceFilter, intf)" v-for="intf in selectedProcess.rpc_info.interface_infos" @contextmenu.prevent.stop="interfaceClick($event, intf)"
<tr v-if="selectedProcess" v-for="intf in getInterfaces(interfaceFilter)" @contextmenu.prevent.stop="interfaceClick($event, intf)"
:class="{ Selected: (selectedInterface && selectedInterface.id == intf.id), Rpc: intf.typ == 'rpc',
Dcom: intf.typ == 'dcom', Hybrid: intf.typ == 'hybrid' }" @click='selectRow(intf)'>
<td class="InterfaceColumn">{{ intf.typ.toUpperCase() }}</td>
Expand Down
162 changes: 87 additions & 75 deletions frontend/src/components/ProcessTableRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,115 +27,127 @@
this.selectedInterface = null;
},
applyFilter(filter, process)
casualFilter(process, filter)
{
if (!filter)
{
return true;
}
filter = filter.toLowerCase();
let inverse = false;
if (!filter.includes(':'))
if (filter.startsWith('!'))
{
let inverse = false;
if (filter.startsWith('!'))
{
filter = filter.substring(1);
inverse = true;
}
return (process.path.toLowerCase().includes(filter) || process.cmdline.toLowerCase().includes(filter) ||
process.user.toLowerCase().includes(filter) || process.pid == filter) != inverse;
filter = filter.substring(1);
inverse = true;
}
let result = true;
const filterArray = filter.split(/\s*\|\s*/);
return (process.path.toLowerCase().includes(filter) || process.cmdline.toLowerCase().includes(filter) ||
process.user.toLowerCase().includes(filter) || process.pid == filter) != inverse;
},
for (const entry of filterArray)
applyFilter(filter, process)
{
if (filter)
{
let key, value;
let inverse = false;
[key, value] = entry.split(':', 2);
if (value === undefined)
{
key = key.toLowerCase();
result = result && (process.path.toLowerCase().includes(key) || process.cmdline.toLowerCase().includes(key) ||
process.user.toLowerCase().includes(key) || process.pid == key);
continue;
}
filter = filter.toLowerCase();
if (value.startsWith('!'))
if (!filter.includes(':') && !this.casualFilter(process, filter))
{
value = value.substring(1);
inverse = true;
return false;
}
if (key === 'uuid' || key === 'id' || key == 'location')
else
{
let found = false;
const filterArray = filter.split(/\s*\|\s*/);
if (key === 'uuid')
for (const entry of filterArray)
{
key = 'id';
}
let key, value;
let inverse = false;
for (const intf of process.rpc_info.interface_infos)
{
if (String(intf[key]).toLowerCase().includes(value) != inverse)
[key, value] = entry.split(':', 2);
if (key === 'uuid')
{
found = true
key = 'id';
}
}
result = result && found;
}
else if (key === 'endpoint')
{
let found = false;
if (value === undefined)
{
if (!this.casualFilter(process, key))
{
return false;
}
for (const endpoint of process.rpc_info.server_info.endpoints)
{
const mergedEndpoint = `${endpoint.protocol}:${endpoint.name}`;
continue;
}
if (mergedEndpoint.toLowerCase().includes(value) != inverse)
if (value.startsWith('!'))
{
found = true
value = value.substring(1);
inverse = true;
}
}
result = result && found;
}
let propValue = null;
else if (key === 'flags')
{
let found = false;
if (Object.hasOwn(process, key))
{
propValue = process[key];
}
for (const intf of process.rpc_info.interface_infos)
{
for (const flag of intf.flags)
else if (Object.hasOwn(process.rpc_info.server_info, key))
{
if (flag.toLowerCase().includes(value) != inverse)
propValue = process.server_info[key];
}
else if (process.rpc_info.interface_infos.length > 0)
{
if (Object.hasOwn(process.rpc_info.interface_infos[0], key))
{
found = true
propValue = [];
for (const intf of process.rpc_info.interface_infos)
{
propValue.push(intf[key]);
}
}
}
}
result = result && found;
}
else
{
return false;
}
else
{
result = result && (Object.hasOwn(process, key) && String(process[key]).toLowerCase().includes(value) != inverse);
if (propValue !== null)
{
if (Array.isArray(propValue))
{
let found = false;
for (const item of propValue)
{
if (String(item).toLowerCase().includes(value))
{
found = true;
break;
}
}
if (!found != inverse)
{
return false;
}
}
else
{
if (String(propValue).toLowerCase().includes(value) == inverse)
{
return false;
}
}
}
}
}
}
return result;
return true;
}
},
}
Expand Down

0 comments on commit 820f5c5

Please sign in to comment.