Skip to content

Instantly share code, notes, and snippets.

@mbtools
Created December 5, 2022 14:08
Show Gist options
  • Save mbtools/a0faf51bd990f2102014f5653d8572c4 to your computer and use it in GitHub Desktop.
Save mbtools/a0faf51bd990f2102014f5653d8572c4 to your computer and use it in GitHub Desktop.
Test of the ABAP Virus Scan Interface (EICAR.EXE)
*----------------------------------------------------------------------*
* Test of the ABAP Virus Scan Interface *
*----------------------------------------------------------------------*
REPORT zvsi_test.
TYPE-POOLS:
abap.
DATA:
gf_rc TYPE i,
gf_msg_buf TYPE string,
gf_data TYPE xstring,
gf_blob TYPE xstring,
gf_data_clean TYPE xstring,
gs_vscan_server TYPE vscan_server,
go_vsa TYPE REF TO cl_vscan_adapter,
gs_vsa_info TYPE vscan_rfc_vsa_info,
gt_parameter TYPE vscan_rfc_param_t,
gs_engine_info TYPE vscan_rfc_engine_info,
gt_driver_info TYPE vscan_rfc_driver_info_t,
gf_from_buffer TYPE abap_bool,
gf_scanrc TYPE vscan_scanrc,
gt_bapiret TYPE vscan_bapiret2_t,
gs_scanerror TYPE vscan_rfc_scanerror,
gt_scanerror TYPE vscan_scanerror_t,
gt_infection TYPE vscan_infection_t.
START-OF-SELECTION.
****************************************
*
* get server
*
*****************************************
SELECT SINGLE * FROM vscan_server INTO gs_vscan_server.
IF sy-subrc <> 0.
WRITE: 'Missing configuration' COLOR COL_TOTAL.
EXIT.
ENDIF.
****************************************
*
* start test
*
*****************************************
CALL METHOD cl_vscan_adapter=>start_local_adapter
EXPORTING
name = gs_vscan_server-name
vsa_lib = gs_vscan_server-vsa_lib
IMPORTING
eo_adapter = go_vsa
error_msg = gf_msg_buf
return_code = gf_rc
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0 OR gf_rc <> 0.
IF gf_msg_buf IS INITIAL.
WRITE: 'No instance available' COLOR COL_TOTAL.
ELSE.
WRITE: gf_msg_buf COLOR COL_TOTAL.
ENDIF.
EXIT.
ENDIF.
IF go_vsa->is_alive( ) = abap_false.
CALL METHOD go_vsa->start_on_appserver
EXPORTING
if_reinit = abap_false
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
CONCATENATE 'This server: ' sy-host ' cannot start the VSA. '
'Check trace in SM50' INTO gf_msg_buf RESPECTING BLANKS.
WRITE: gf_msg_buf COLOR COL_NEGATIVE.
EXIT.
ENDIF.
ENDIF.
CALL METHOD go_vsa->get_engine_info
IMPORTING
es_engine_info = gs_engine_info
et_driver_info = gt_driver_info
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
WRITE: 'Vsa engine failed' COLOR COL_NEGATIVE.
EXIT.
ENDIF.
CALL METHOD go_vsa->get_vsa_info
IMPORTING
es_vsa_info = gs_vsa_info
et_parameters = gt_parameter
ef_from_buffer = gf_from_buffer
EXCEPTIONS
not_available = 1
OTHERS = 2.
IF sy-subrc <> 0.
WRITE: 'Vsa info failed' COLOR COL_NEGATIVE.
EXIT.
ENDIF.
DEFINE def_add_blob.
gf_blob = &1.
CONCATENATE
gf_data
gf_blob
INTO
gf_data
IN BYTE MODE.
END-OF-DEFINITION.
CLEAR gf_data.
def_add_blob '58354F2150254041505B345C505A58353428505E'.
def_add_blob '2937434329377D2445494341522D5354414E4441'.
def_add_blob '52442D414E544956495255532D544553542D4649'.
def_add_blob '4C452124482B482A'.
CALL METHOD go_vsa->if_vscan_instance~scan_bytes
EXPORTING
if_job_id = 'EICAR.EXE'
if_data = gf_data
if_do_clean = abap_false
if_active_content = abap_false
if_no_details = abap_false
IMPORTING
ef_scanrc = gf_scanrc
ef_data = gf_data_clean
et_bapiret = gt_bapiret
et_scanerror = gt_scanerror
et_infection = gt_infection
EXCEPTIONS
not_available = 1
configuration_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
WRITE: 'Scan failed' COLOR COL_NEGATIVE.
EXIT.
ENDIF.
IF gf_scanrc <> -2.
WRITE: 'EICAR test virus not found' COLOR COL_NEGATIVE.
SKIP.
LOOP AT gt_scanerror INTO gs_scanerror.
WRITE: / gs_scanerror-error_rc, / gs_scanerror-error_text, / gs_scanerror-object_name.
ENDLOOP.
ELSE.
WRITE: 'EICAR test virus found' COLOR COL_POSITIVE.
ENDIF.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment