Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Николаев Александр Александрович
libakrypt-0.x-parts-implementation
Commits
b63873e6
Commit
b63873e6
authored
9 months ago
by
Нестеренко Алексей Юрьевич
Browse files
Options
Download
Patches
Plain Diff
Промежуточная фиксация. Сделана первая проверка с заданными файлами и каталогами
parent
c7c877fd
master
0.9.14
No related merge requests found
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
CMakeLists.txt
+2
-2
CMakeLists.txt
aktool/aktool.h
+4
-1
aktool/aktool.h
aktool/aktool_icode.c
+2
-3
aktool/aktool_icode.c
aktool/aktool_icode_evaluate.c
+114
-16
aktool/aktool_icode_evaluate.c
source/ak_file.c
+28
-2
source/ak_file.c
source/libakrypt-base.h.in
+5
-1
source/libakrypt-base.h.in
with
155 additions
and
25 deletions
+155
-25
CMakeLists.txt
+
2
−
2
View file @
b63873e6
...
@@ -462,8 +462,8 @@ set( CPACK_SOURCE_IGNORE_FILES
...
@@ -462,8 +462,8 @@ set( CPACK_SOURCE_IGNORE_FILES
# в зависимостях можно указать в явном виде стандартную библиотеку языка Си,
# в зависимостях можно указать в явном виде стандартную библиотеку языка Си,
# но она и так входит в перечень
# но она и так входит в перечень
set
(
CPACK_DEBIAN_PACKAGE_
DEP
ENDS
"libbz2-1.0"
)
set
(
CPACK_DEBIAN_PACKAGE_
RECOMM
ENDS
"libbz2-1.0"
)
set
(
CPACK_DEBIAN_PACKAGE_
DEP
ENDS
"libelf-dev"
)
set
(
CPACK_DEBIAN_PACKAGE_
RECOMM
ENDS
"libelf-dev"
)
set
(
CPACK_PACKAGE_VERSION_MAJOR
${
HEAD_VERSION
}
)
set
(
CPACK_PACKAGE_VERSION_MAJOR
${
HEAD_VERSION
}
)
set
(
CPACK_PACKAGE_VERSION_MINOR
${
MAIN_VERSION
}
)
set
(
CPACK_PACKAGE_VERSION_MINOR
${
MAIN_VERSION
}
)
set
(
CPACK_PACKAGE_VERSION_PATCH
${
MINOR_VERSION
}
)
set
(
CPACK_PACKAGE_VERSION_PATCH
${
MINOR_VERSION
}
)
...
...
This diff is collapsed.
Click to expand it.
aktool/aktool.h
+
4
−
1
View file @
b63873e6
...
@@ -151,7 +151,8 @@
...
@@ -151,7 +151,8 @@
size_t
deleted_files
;
size_t
deleted_files
;
/* количество измененных файлов */
/* количество измененных файлов */
size_t
changed_files
;
size_t
changed_files
;
/* количество новых файлов */
size_t
new_files
;
}
statistical_data
;
}
statistical_data
;
/* при установленном флаге программа не проверяет сегменты, загружаемые в память */
/* при установленном флаге программа не проверяет сегменты, загружаемые в память */
bool_t
ignore_segments
;
bool_t
ignore_segments
;
...
@@ -272,6 +273,8 @@
...
@@ -272,6 +273,8 @@
int
aktool_icode_import_checksum
(
aktool_ki_t
*
);
int
aktool_icode_import_checksum
(
aktool_ki_t
*
);
/* проверка контрольных сумм по заданой базе данных */
/* проверка контрольных сумм по заданой базе данных */
int
aktool_icode_check_from_database
(
aktool_ki_t
*
);
int
aktool_icode_check_from_database
(
aktool_ki_t
*
);
/* проверка контрольных сумм для заданных каталогов и файлов */
int
aktool_icode_check_from_directory
(
aktool_ki_t
*
);
/* ----------------------------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------------------------------- */
typedef
enum
{
do_nothing
,
do_encrypt
,
do_decrypt
}
encrypt_t
;
typedef
enum
{
do_nothing
,
do_encrypt
,
do_decrypt
}
encrypt_t
;
...
...
This diff is collapsed.
Click to expand it.
aktool/aktool_icode.c
+
2
−
3
View file @
b63873e6
...
@@ -301,11 +301,10 @@
...
@@ -301,11 +301,10 @@
- если указаны файлы или каталоги, тогда происходит поиск файлов
- если указаны файлы или каталоги, тогда происходит поиск файлов
и проверка их контрольных сумм на соотвествие значениям из базы данных
и проверка их контрольных сумм на соотвествие значениям из базы данных
- если файлы не определены, то перебираются все файлы из сформированной базы данных */
- если файлы не определены, то перебираются все файлы из сформированной базы данных */
if
((
!
ki
.
include_file
.
count
)
&&
(
!
ki
.
include_path
.
count
))
if
(
!
(
ki
.
include_file
.
count
+
ki
.
include_path
.
count
))
exit_status
=
aktool_icode_check_from_database
(
&
ki
);
exit_status
=
aktool_icode_check_from_database
(
&
ki
);
else
else
exit_status
=
-
13
;
exit_status
=
aktool_icode_check_from_directory
(
&
ki
);
/* уничтожаем контекст алгоритма хеширования или имитозащиты */
/* уничтожаем контекст алгоритма хеширования или имитозащиты */
aktool_icode_destroy_handle
(
&
ki
);
aktool_icode_destroy_handle
(
&
ki
);
break
;
break
;
...
...
This diff is collapsed.
Click to expand it.
aktool/aktool_icode_evaluate.c
+
114
−
16
View file @
b63873e6
...
@@ -207,7 +207,7 @@
...
@@ -207,7 +207,7 @@
ki
->
statistical_data
.
skipped_executables
++
;
ki
->
statistical_data
.
skipped_executables
++
;
goto
labexit
;
goto
labexit
;
}
}
/* формируем
ф
иртуальное имя файла - ключ доступа в виртуальной таблице */
/* формируем
в
иртуальное имя файла - ключ доступа в виртуальной таблице */
ak_snprintf
(
segment_value
,
sizeof
(
segment_value
)
-
1
,
"%s/%08jx"
,
value
,
phdr
.
p_offset
);
ak_snprintf
(
segment_value
,
sizeof
(
segment_value
)
-
1
,
"%s/%08jx"
,
value
,
phdr
.
p_offset
);
/* при необходимости, формируем производный ключ */
/* при необходимости, формируем производный ключ */
if
((
dkey
=
aktool_icode_get_derived_key
(
segment_value
,
ki
,
&
fp
))
==
NULL
)
{
if
((
dkey
=
aktool_icode_get_derived_key
(
segment_value
,
ki
,
&
fp
))
==
NULL
)
{
...
@@ -329,6 +329,14 @@
...
@@ -329,6 +329,14 @@
}
while
(
ak_list_next
(
&
ki
->
include_path
));
}
while
(
ak_list_next
(
&
ki
->
include_path
));
}
}
/* финальное сообщение об ошибках */
if
(
ki
->
statistical_data
.
skiped_files
)
{
exit_status
=
EXIT_FAILURE
;
aktool_error
(
_
(
"aktool found %d error(s), try aktool with
\"
--audit-file stderr --audit 2
\"
"
" options or see syslog messages"
),
ki
->
statistical_data
.
skiped_files
);
}
/* вывод статистики */
if
(
!
ki
->
quiet
)
{
if
(
!
ki
->
quiet
)
{
if
((
!
ki
->
dont_show_icode
)
&&
(
!
ki
->
dont_show_stat
))
printf
(
"
\n
"
);
if
((
!
ki
->
dont_show_icode
)
&&
(
!
ki
->
dont_show_stat
))
printf
(
"
\n
"
);
if
(
!
ki
->
dont_show_stat
)
{
if
(
!
ki
->
dont_show_stat
)
{
...
@@ -339,21 +347,17 @@
...
@@ -339,21 +347,17 @@
printf
(
_
(
" %6llu have been proceed
\n
"
),
printf
(
_
(
" %6llu have been proceed
\n
"
),
(
long
long
unsigned
int
)
ki
->
statistical_data
.
hashed_files
);
(
long
long
unsigned
int
)
ki
->
statistical_data
.
hashed_files
);
#ifdef AK_HAVE_GELF_H
#ifdef AK_HAVE_GELF_H
printf
(
_
(
" %6llu contain downloadable segments
\n
"
),
if
(
!
ki
->
ignore_segments
)
{
printf
(
_
(
" %6llu contain downloadable segments
\n
"
),
(
long
long
unsigned
int
)
ki
->
statistical_data
.
executables
);
(
long
long
unsigned
int
)
ki
->
statistical_data
.
executables
);
if
(
ki
->
statistical_data
.
skipped_executables
)
if
(
ki
->
statistical_data
.
skipped_executables
)
printf
(
_
(
" %6llu downloadable segments discarded
\n
"
),
printf
(
_
(
" %6llu downloadable segments discarded
\n
"
),
(
long
long
unsigned
int
)
ki
->
statistical_data
.
skipped_executables
);
(
long
long
unsigned
int
)
ki
->
statistical_data
.
skipped_executables
);
}
#endif
#endif
}
}
}
}
if
(
ki
->
statistical_data
.
skiped_files
)
{
exit_status
=
EXIT_FAILURE
;
aktool_error
(
_
(
"aktool found %d error(s), try aktool with
\"
--audit-file stderr --audit 2
\"
"
" options or see syslog messages"
),
ki
->
statistical_data
.
skiped_files
);
}
aktool_icode_destroy_handle
(
ki
);
aktool_icode_destroy_handle
(
ki
);
return
exit_status
;
return
exit_status
;
...
@@ -451,16 +455,24 @@
...
@@ -451,16 +455,24 @@
while
(
ak_list_next
(
list
));
while
(
ak_list_next
(
list
));
}
}
/* финальное предупреждение */
if
(
ki
->
statistical_data
.
skiped_files
)
{
aktool_error
(
_
(
"aktool found %d error(s), try aktool with
\"
--audit-file stderr --audit 2
\"
"
" options or see syslog messages"
),
ki
->
statistical_data
.
skiped_files
);
exit_status
=
EXIT_FAILURE
;
}
else
exit_status
=
EXIT_SUCCESS
;
/* вывод статистики о проделанной работе */
/* вывод статистики о проделанной работе */
if
(
!
ki
->
quiet
)
{
if
(
!
ki
->
quiet
)
{
if
(
!
ki
->
dont_show_stat
)
{
if
(
!
ki
->
dont_show_stat
)
{
if
(
!
ki
->
dont_show_icode
)
printf
(
"
\n
"
);
if
(
(
!
ki
->
dont_show_icode
)
||
(
ki
->
statistical_data
.
skiped_files
))
printf
(
"
\n
"
);
printf
(
_
(
"the total number of files checked: %llu, of which:
\n
"
),
printf
(
_
(
"the total number of files checked: %llu, of which:
\n
"
),
(
long
long
unsigned
int
)
ki
->
statistical_data
.
total_files
);
(
long
long
unsigned
int
)
ki
->
statistical_data
.
total_files
);
printf
(
_
(
" %6llu have been discarded
\n
"
),
(
long
long
unsigned
int
)
ki
->
statistical_data
.
skiped_files
);
printf
(
_
(
" %6llu have been proceed
\n
"
),
printf
(
_
(
" %6llu have been proceed
\n
"
),
(
long
long
unsigned
int
)
ki
->
statistical_data
.
hashed_files
);
(
long
long
unsigned
int
)
ki
->
statistical_data
.
hashed_files
);
printf
(
_
(
" %6llu have been discarded
\n
"
),
(
long
long
unsigned
int
)
ki
->
statistical_data
.
skiped_files
);
if
(
ki
->
statistical_data
.
skiped_files
)
{
if
(
ki
->
statistical_data
.
skiped_files
)
{
printf
(
_
(
" %6llu have been deleted
\n
"
),
printf
(
_
(
" %6llu have been deleted
\n
"
),
(
long
long
unsigned
int
)
ki
->
statistical_data
.
deleted_files
);
(
long
long
unsigned
int
)
ki
->
statistical_data
.
deleted_files
);
...
@@ -470,15 +482,101 @@
...
@@ -470,15 +482,101 @@
}
}
}
}
return
exit_status
;
}
/* ----------------------------------------------------------------------------------------------- */
static
int
aktool_icode_check_file_function
(
const
char
*
value
,
ak_pointer
ptr
)
{
ak_keypair
kp
=
NULL
;
aktool_ki_t
*
ki
=
ptr
;
/* проверяем черный список */
if
(
ak_htable_get_str
(
&
ki
->
exclude_file
,
value
,
NULL
)
!=
NULL
)
return
ak_error_ok
;
/* ищем файл в базе */
if
((
kp
=
ak_htable_get_keypair_str
(
&
ki
->
icodes
,
value
))
==
NULL
)
{
ki
->
statistical_data
.
total_files
++
;
ki
->
statistical_data
.
new_files
++
;
if
(
!
ki
->
quiet
)
aktool_error
(
_
(
"the file %s is new and can't be checked"
),
value
);
return
ak_error_message_fmt
(
ak_error_htable_key_not_found
,
__func__
,
_
(
"the file %s is new and can't be checked"
),
value
);
}
/* проверяем, что база корректна */
if
(
kp
->
data
==
NULL
)
return
ak_error_message
(
ak_error_null_pointer
,
__func__
,
_
(
"using null pointer to keypair"
));
/* выполняем проверку конкретного файла */
return
aktool_icode_check_function
(
(
const
char
*
)
kp
->
data
,
kp
->
data
+
kp
->
key_length
);
}
/* ----------------------------------------------------------------------------------------------- */
int
aktool_icode_check_from_directory
(
aktool_ki_t
*
ki
)
{
int
exit_status
=
EXIT_FAILURE
;
/* обнуляем счетчики */
memset
(
&
ki
->
statistical_data
,
0
,
sizeof
(
struct
icode_stat
));
/* создаем контекст алгоритма хеширования или имитозащиты */
if
(
aktool_icode_create_handle
(
ki
)
!=
ak_error_ok
)
return
EXIT_FAILURE
;
/* начинаем с обхода файлов */
if
(
ki
->
include_file
.
count
)
{
ak_list_first
(
&
ki
->
include_file
);
do
{
aktool_icode_check_file_function
(
(
char
*
)
ki
->
include_file
.
current
->
data
,
ki
);
}
while
(
ak_list_next
(
&
ki
->
include_file
));
}
/* теперь продолжаем обходом каталогов */
if
(
ki
->
include_path
.
count
)
{
ak_list_first
(
&
ki
->
include_path
);
do
{
const
char
*
value
=
(
const
char
*
)
ki
->
include_path
.
current
->
data
;
/* проверяем черный список */
if
(
ak_htable_get_str
(
&
ki
->
exclude_path
,
value
,
NULL
)
!=
NULL
)
continue
;
/* запускаем вычисление контрольной суммы */
ak_file_find
(
value
,
ki
->
pattern
,
aktool_icode_check_file_function
,
ki
,
ki
->
tree
);
}
while
(
ak_list_next
(
&
ki
->
include_path
));
}
/* финальное сообщение об ошибках */
if
(
ki
->
statistical_data
.
skiped_files
)
{
if
(
ki
->
statistical_data
.
skiped_files
)
{
exit_status
=
EXIT_FAILURE
;
aktool_error
(
_
(
"aktool found %d error(s), try aktool with
\"
--audit-file stderr --audit 2
\"
"
aktool_error
(
_
(
"aktool found %d error(s), try aktool with
\"
--audit-file stderr --audit 2
\"
"
" options or see syslog messages"
),
ki
->
statistical_data
.
skiped_files
);
" options or see syslog messages"
),
ki
->
statistical_data
.
skiped_files
);
exit_status
=
EXIT_FAILURE
;
}
}
else
exit_status
=
EXIT_SUCCESS
;
return
exit_status
;
/* вывод статистики о проделанной работе */
if
(
!
ki
->
quiet
)
{
if
(
!
ki
->
dont_show_stat
)
{
if
((
!
ki
->
dont_show_icode
)
||
(
ki
->
statistical_data
.
skiped_files
))
printf
(
"
\n
"
);
printf
(
_
(
"the total number of files checked: %llu, of which:
\n
"
),
(
long
long
unsigned
int
)
ki
->
statistical_data
.
total_files
);
printf
(
_
(
" %6llu have been proceed
\n
"
),
(
long
long
unsigned
int
)
ki
->
statistical_data
.
hashed_files
);
printf
(
_
(
" %6llu have been discarded
\n
"
),
(
long
long
unsigned
int
)
ki
->
statistical_data
.
skiped_files
);
if
(
ki
->
statistical_data
.
skiped_files
)
{
printf
(
_
(
" %6llu have been deleted
\n
"
),
(
long
long
unsigned
int
)
ki
->
statistical_data
.
deleted_files
);
printf
(
_
(
" %6llu have been changed
\n
"
),
(
long
long
unsigned
int
)
ki
->
statistical_data
.
changed_files
);
}
if
(
ki
->
statistical_data
.
new_files
)
printf
(
_
(
" %6llu new files found
\n
"
),
(
long
long
unsigned
int
)
ki
->
statistical_data
.
new_files
);
}
}
aktool_icode_destroy_handle
(
ki
);
return
exit_status
;
}
}
/* ----------------------------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------------------------------- */
/* aktool_icode_evaluate.c */
/* aktool_icode_evaluate.c */
/* ----------------------------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------------------------------- */
This diff is collapsed.
Click to expand it.
source/ak_file.c
+
28
−
2
View file @
b63873e6
...
@@ -293,6 +293,12 @@
...
@@ -293,6 +293,12 @@
file
->
blksize
=
(
ak_int64
)
st
.
st_blksize
;
file
->
blksize
=
(
ak_int64
)
st
.
st_blksize
;
#endif
#endif
/* в отладочных целях, сохраняем имя файла */
file
->
name
=
NULL
;
#ifdef AK_HAVE_STRINGS_H
file
->
name
=
strndup
(
filename
,
512
);
#endif
return
ak_error_ok
;
return
ak_error_ok
;
}
}
...
@@ -332,12 +338,20 @@
...
@@ -332,12 +338,20 @@
}
else
file
->
blksize
=
(
ak_int64
)
st
.
st_blksize
;
}
else
file
->
blksize
=
(
ak_int64
)
st
.
st_blksize
;
#endif
#endif
/* в отладочных целях, сохраняем имя файла */
file
->
name
=
NULL
;
#ifdef AK_HAVE_STRINGS_H
file
->
name
=
strndup
(
filename
,
512
);
#endif
return
ak_error_ok
;
return
ak_error_ok
;
}
}
/* ----------------------------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------------------------------- */
int
ak_file_close
(
ak_file
file
)
int
ak_file_close
(
ak_file
file
)
{
{
if
(
file
->
name
!=
NULL
)
free
(
file
->
name
);
file
->
size
=
0
;
file
->
size
=
0
;
file
->
blksize
=
0
;
file
->
blksize
=
0
;
#ifdef AK_HAVE_WINDOWS_H
#ifdef AK_HAVE_WINDOWS_H
...
@@ -441,12 +455,24 @@
...
@@ -441,12 +455,24 @@
отображаемые данные.*/
отображаемые данные.*/
/* ----------------------------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------------------------------- */
ak_pointer
ak_file_mmap
(
ak_file
file
,
ak_pointer
ak_file_mmap
(
ak_file
file
,
void
*
start
,
size_t
length
,
int
prot
,
int
flags
,
size_t
offset
)
void
*
start
,
size_t
length
,
int
prot
,
int
flags
,
size_t
offset
)
{
{
if
(
!
length
)
{
ak_error_message_fmt
(
ak_error_zero_length
,
__func__
,
"mmaping a file %s with zero length segment"
,
file
->
name
);
return
NULL
;
}
#ifdef AK_HAVE_SYSMMAN_H
#ifdef AK_HAVE_SYSMMAN_H
if
((
file
->
addr
=
mmap
(
start
,
file
->
mmaped_size
=
length
,
if
((
file
->
addr
=
mmap
(
start
,
file
->
mmaped_size
=
length
,
prot
,
flags
,
file
->
fd
,
offset
))
==
MAP_FAILED
)
{
prot
,
flags
,
file
->
fd
,
offset
))
==
MAP_FAILED
)
{
ak_error_message_fmt
(
ak_error_mmap_file
,
__func__
,
"mmap error (%s)"
,
strerror
(
errno
));
ak_error_message_fmt
(
ak_error_mmap_file
,
__func__
,
"mmap error (%d, %s) for file %s"
,
errno
,
strerror
(
errno
),
file
->
name
);
if
(
errno
==
EINVAL
)
{
ak_error_message_fmt
(
ak_error_mmap_file
,
__func__
,
"data length: %llx, data offset: %llx"
,
(
long
long
unsigned
int
)
length
,
(
long
long
unsigned
int
)
offset
);
}
return
NULL
;
}
}
return
file
->
addr
;
return
file
->
addr
;
#else
#else
...
...
This diff is collapsed.
Click to expand it.
source/libakrypt-base.h.in
+
5
−
1
View file @
b63873e6
...
@@ -273,8 +273,10 @@ extern "C" {
...
@@ -273,8 +273,10 @@ extern "C" {
/*! \brief Ошибка при добавлении элемента со существующим ключом в хеш-таблицу */
/*! \brief Ошибка при добавлении элемента со существующим ключом в хеш-таблицу */
#define ak_error_htable_key_exist (-34)
#define ak_error_htable_key_exist (-34)
/*! \brief Ошибка при поиске несуществующего элемента */
#define ak_error_htable_key_not_found (-35)
/*! \brief Ошибка, возникающая при появлении в хеш-таблице элемента с null-указателем на данные */
/*! \brief Ошибка, возникающая при появлении в хеш-таблице элемента с null-указателем на данные */
#define ak_error_htable_null_element (-3
5
)
#define ak_error_htable_null_element (-3
6
)
/* ----------------------------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------------------------------- */
#define ak_null_string ("(null)")
#define ak_null_string ("(null)")
...
@@ -553,6 +555,8 @@ extern "C" {
...
@@ -553,6 +555,8 @@ extern "C" {
ak_pointer addr;
ak_pointer addr;
/*! \brief Реальный размер отображенной памяти (после вызова mmap) */
/*! \brief Реальный размер отображенной памяти (после вызова mmap) */
ak_int64 mmaped_size;
ak_int64 mmaped_size;
/*! \brief Имя файла */
tchar *name;
} *ak_file;
} *ak_file;
/* ----------------------------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------------------------------- */
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets