-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Id and signature in scan log #99
Open
peter-volkov
wants to merge
3
commits into
master
Choose a base branch
from
id_and_signature_in_scan_log
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
ob_start(); | ||
require_once('Tskv.inc.php'); | ||
ob_end_clean(); | ||
|
||
|
||
class SignatureDetect | ||
{ | ||
function __construct($filePath, $isDetected, $id, $severity, $signature, $position, $detectedContent) | ||
{ | ||
|
||
$this->filePath = $filePath; | ||
$this->isDetected = $isDetected; | ||
$this->id = $id; | ||
$this->severity = $severity; | ||
$this->signature = $signature; | ||
$this->position = $position; | ||
$this->detectedContent = $detectedContent; | ||
} | ||
|
||
function toString() | ||
{ | ||
$elements = array('filePath' => $this->filePath, | ||
'isDetected' => $this->isDetected, | ||
); | ||
if ($this->isDetected == 1) { | ||
$elements['id'] = $this->id; | ||
$elements['severity'] = $this->severity; | ||
$elements['signature'] = base64_encode($this->signature); | ||
$elements['position'] = $this->position; | ||
$elements['detectedContent'] = $this->detectedContent; | ||
} | ||
return toTskv($elements); | ||
} | ||
|
||
function fromString($tskvString) | ||
{ | ||
$keyValuePairs = fromTskv($tskvString); | ||
$this->filePath = $keyValuePairs['filePath']; | ||
$this->isDetected = $keyValuePairs['isDetected']; | ||
if ($this->isDetected == 1) { | ||
$this->id = $keyValuePairs['id']; | ||
$this->severity = $keyValuePairs['severity']; | ||
$this->signature = base64_decode($keyValuePairs['signature']); | ||
$this->position = $keyValuePairs['position']; | ||
$this->detectedContent = $keyValuePairs['detectedContent']; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
//dump assisiative array to tab separated key-value string | ||
function toTskv($dict) | ||
{ | ||
$keyValuePairs = array(); | ||
foreach($dict as $key => $value) { | ||
array_push($keyValuePairs, "$key=$value"); | ||
} | ||
return join("\t", $keyValuePairs); | ||
} | ||
|
||
//parse tab separated key-value string to assisiative array | ||
function fromTskv($tskvString) | ||
{ | ||
$dict = array(); | ||
foreach(explode("\t", $tskvString) as $keyValuePair) { | ||
$keyValue = explode("=", $keyValuePair, 2); | ||
$dict[$keyValue[0]] = $keyValue[1]; | ||
} | ||
return $dict; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я в предыдущем коммите делал конвертацию в массив. При поиске по массиву будет работать быстрее, требует меньше памяти, решение получается более гибкое (можно, например, кэшировать его сериализацией на момент сканирования). Может стоит сюда это перенести?
Еще был фикс ошибки с конструктором Auth - я переименовывал метод auth(), чтобы не было Constructor is already defined на некоторых версиях PHP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Фикс перенесем обязательно. Про массив - надо померить, кажется. Если действительно с классом будет значительное увеличение накладных ресурсов, то да, надо сделать массив.
Дай день-другой на сравнение.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Есть подозрение, что если и есть увеличение, то незначительное, а часть с формированием очереди так удобно вынести, как мне кажется.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
http://stackoverflow.com/questions/2193049/php-objects-vs-arrays
arrays: 1.8451430797577
memory: 460416
Array
(
[aaa] => aaa
[bbb] => bbb
[ccc] => aaabbb
)
arrays: 1.8294548988342
memory: 275696
SomeClass Object
(
[aaa] => aaa
[bbb] => bbb
[ccc] => aaabbb
)