1. 程式人生 > 其它 >SAP ABAP程式碼加密增強

SAP ABAP程式碼加密增強

1.增強使用截圖

 

 

 2.增強具體實施方法:

2.1事務碼:CMOD,建立專案

 

 

 

2.2輸入描述和增強分配:SEUED001

 

 

 

 

 

 

啟用元件:

 

 

 

 

 

 

未完善版本,僅供參考:

  1 *&---------------------------------------------------------------------*
  2 *& 包含               ZXSEUU25
  3 *&---------------------------------------------------------------------*
4 CONSTANTS:remote_dir TYPE string VALUE '/tmp/z3426/'. 5 CONSTANTS:gv_pwd TYPE string VALUE 'chen123'. 6 CONSTANTS:lv_author TYPE cnam VALUE 'CHENHUI'. 7 INCLUDE ole2incl. 8 DATA: ole TYPE ole2_object, 9 voice TYPE ole2_object, 10 text TYPE string. 11 DATA:lv_cnam TYPE reposrc-cnam.
12 DATA:lv_secret TYPE abpauth-secret. 13 DATA:gv_version TYPE r3state VALUE 'A'. 14 DATA:gv_suffix TYPE string VALUE '.chen'. 15 DATA:go_encry TYPE REF TO cl_hard_wired_encryptor, 16 go_zip TYPE REF TO cl_abap_zip. 17 18 DATA:BEGIN OF gt_file OCCURS 0, 19 filename TYPE string,
20 progname TYPE progname, 21 code TYPE TABLE OF line, 22 codestr TYPE string, 23 END OF gt_file. 24 25 DATA:BEGIN OF lt_code OCCURS 0, 26 progname TYPE reposrc-progname, 27 END OF lt_code. 28 29 DATA:lv_filename TYPE string, 30 lv_string TYPE string, 31 lv_xstring TYPE xstring, 32 lv_size TYPE i, 33 lt_bin TYPE STANDARD TABLE OF raw255. 34 35 CREATE OBJECT go_encry. 36 CREATE OBJECT go_zip. 37 38 CALL FUNCTION 'GET_INCLUDETAB' "取包含程式 39 EXPORTING 40 progname = program 41 TABLES 42 incltab = lt_code. 43 APPEND program TO lt_code. 44 DELETE ADJACENT DUPLICATES FROM lt_code. 45 46 LOOP AT lt_code. 47 IF NOT lt_code-progname+0(1) CA 'ZY'. 48 CONTINUE. 49 ENDIF. 50 SELECT SINGLE cnam INTO lv_cnam FROM reposrc WHERE progname = program. 51 IF lv_cnam = lv_author. 52 cl_demo_input=>request( EXPORTING text = '加密陳輝的原始碼,請先驗證金鑰' CHANGING field = lv_secret ). 53 IF to_upper( lv_secret ) NE lv_author. 54 text = '您可以執行但不允許加密陳輝的原始碼,若想修改功能,請聯絡[email protected]!'. 55 CREATE OBJECT voice 'SAPI.SpVoice'. 56 CALL METHOD OF voice 'Speak' = ole 57 EXPORTING #1 = text. 58 ENDIF. 59 ENDIF. 60 gt_file-progname = lt_code-progname. 61 READ REPORT lt_code-progname INTO gt_file-code[] STATE gv_version. 62 CLEAR:lv_string. 63 LOOP AT gt_file-code INTO DATA(ls_line). 64 TRY. 65 DATA(lv_strlen) = strlen( ls_line-line ). 66 DATA(lv_random) = cl_cnv_demo_basic_generator=>random( from = 0 to = lv_strlen ). 67 lv_strlen = lv_strlen - lv_random. 68 DATA(lv_line) = ls_line-line+0(lv_random) && gv_pwd && ls_line-line+lv_random(lv_strlen)."在原有基礎上隨機插入加密混淆字串 69 lv_string = lv_string && go_encry->encrypt_string2string( the_string = lv_line ) && cl_abap_char_utilities=>cr_lf. 70 CATCH cx_root INTO DATA(lo_error). 71 ENDTRY. 72 ENDLOOP. 73 74 CLEAR:lv_xstring. 75 CALL FUNCTION 'SCMS_STRING_TO_XSTRING' 76 EXPORTING 77 text = lv_string 78 mimetype = 'text/html;chartset=gbk' 79 IMPORTING 80 buffer = lv_xstring 81 EXCEPTIONS 82 failed = 1 83 OTHERS = 2. 84 lv_filename = remote_dir && sy-datum && sy-uzeit && '_' && lt_code-progname && gv_suffix. 85 go_zip->add( name = lv_filename content = lv_xstring ). 86 ENDLOOP. 87 lv_xstring = go_zip->save( ). 88 REFRESH:lt_bin. 89 CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' 90 EXPORTING 91 buffer = lv_xstring 92 IMPORTING 93 output_length = lv_size 94 TABLES 95 binary_tab = lt_bin. 96 97 DATA: l_rc TYPE i, 98 l_filetable TYPE filetable. 99 DATA:default_filename TYPE string. 100 default_filename = sy-datum && '.zip'. 101 CALL METHOD cl_gui_frontend_services=>file_open_dialog 102 EXPORTING 103 window_title = '請選擇加密程式碼匯出位置' 104 file_filter = cl_gui_frontend_services=>filetype_all "filetype_excel 105 default_filename = default_filename 106 multiselection = space 107 CHANGING 108 file_table = l_filetable 109 rc = l_rc 110 EXCEPTIONS 111 file_open_dialog_failed = 1 112 cntl_error = 2 113 error_no_gui = 3 114 not_supported_by_gui = 4 115 OTHERS = 5. 116 117 IF sy-subrc = 0 AND l_rc = 1. 118 READ TABLE l_filetable INTO DATA(lv_file) INDEX 1. 119 ENDIF. 120 121 lv_filename = lv_file. 122 CALL METHOD cl_gui_frontend_services=>gui_download 123 EXPORTING 124 bin_filesize = lv_size 125 filename = lv_filename 126 filetype = 'BIN' 127 CHANGING 128 data_tab = lt_bin. 129 130 131 TRY. 132 DATA:lv_str TYPE string, 133 ls_data TYPE REF TO data, 134 lt_data TYPE TABLE OF reposrc, 135 lo_sql TYPE REF TO cl_sql_statement, 136 lx_sql TYPE REF TO cx_sql_exception, 137 lo_result TYPE REF TO cl_sql_result_set, 138 lv_uflag TYPE i VALUE 1, 139 lv_dbname TYPE dbcon_name, 140 lv_dbuser TYPE dbcon_uid, 141 lv_dbtab TYPE tabname. 142 DATA:e TYPE REF TO cx_root, 143 err_text TYPE string. 144 lv_dbname = 'DEFAULT'. 145 SELECT SINGLE schemaname INTO lv_dbuser FROM db6navsyst WHERE sysid = sy-sysid. 146 lv_dbtab = 'REPOSRC'. 147 CREATE OBJECT lo_sql EXPORTING con_ref = cl_sql_connection=>get_connection( lv_dbname ). 148 lv_dbtab = lv_dbuser && `.` && lv_dbtab. 149 DATA:lv_code TYPE reposrc-data. 150 SELECT SINGLE data INTO lv_code FROM reposrc WHERE progname = program. 151 152 lv_str = `UPDATE ` && lv_dbtab && ` SET DATA = '` && lv_code && `' WHERE PROGNAME = '` && program && `'`. 153 lv_uflag = lo_sql->execute_update( lv_str ). 154 IF lv_uflag = 1. 155 156 ENDIF. 157 CATCH cx_root INTO e. 158 err_text = e->get_text( ). 159 ENDTRY. 160 161 162 163 164 165 166 167 168 DATA remote_file LIKE rcgfiletr-ftappl VALUE '/tmp/z3426003aTest.xlsx'.. "遠端檔案型別 169 DATA local_file LIKE rcgfiletr-ftfront VALUE 'C:\Users\3426\Desktop\Z3426aTest.xlsx'. "下載檔案型別 170 171 DATA:line TYPE string. 172 DATA:lv_max TYPE i VALUE '5000'. 173 174 *create file 175 OPEN DATASET remote_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT. 176 DO lv_max TIMES. 177 line = `Line` && sy-index && `Col1` && ' ' && `Line` && sy-index && `Col2`. 178 TRANSFER line TO remote_file. 179 ENDDO. 180 CLOSE DATASET remote_file.
View Code