1#!/usr/bin/env node 2 3/* 4 * Copyright (c) 2023 Huawei Device Co., Ltd. 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18import {program} from 'commander'; 19import * as path from 'path'; 20 21import {ArkObfuscator} from '../ArkObfuscator'; 22 23/** 24 * Main Entry of Obfuscation in 25 */ 26const minParametersNum: number = 3; 27(function (): void { 28 if (process.argv.length < minParametersNum) { 29 console.error('Too few input parameters.'); 30 console.error('Usage: SecHarmony [input files] [options]'); 31 return; 32 } 33 34 initOptionsSetting(); 35 36 let configPath: string = program.opts()?.configPath; 37 configPath = path.resolve(configPath); 38 let fileList: Array<string> = []; 39 program.args.forEach((value) => { 40 const resolved: string = path.resolve(value); 41 fileList.push(resolved); 42 }); 43 44 let obfuscator: ArkObfuscator = new ArkObfuscator(fileList, configPath); 45 const initSuccess: boolean = obfuscator.init(); 46 if (!initSuccess) { 47 console.error('init from config file error.'); 48 return; 49 } 50 51 obfuscator.obfuscateFiles(); 52})(); 53 54function initOptionsSetting(): void { 55 program.name('SecHarmony') 56 .version('1.0.0') 57 .description('A tool to obfuscate open harmony application written by Javascript or Typescript.') 58 .usage('Usage: SecHarmony [input files] [options]') 59 .option('-v, --version', 'show version information.') 60 .option('-cp, --config-path <dir>', 'obfuscation configuration for open harmony application.') 61 .parse(); 62} 63