diff --git a/ets2panda/driver/build_system/package.json b/ets2panda/driver/build_system/package.json index 1b1672985c5ee87c3d819fe2b995767e6daef159..f8013b599bea67e4540048d7526fab85e9917de9 100644 --- a/ets2panda/driver/build_system/package.json +++ b/ets2panda/driver/build_system/package.json @@ -51,6 +51,8 @@ "plugin_test": "jest --testMatch='/test/plugin/**/*.test.ts'", "build_system_Utest": "jest --testMatch='**/test/ut/**/*.test.ts' --testPathIgnorePatterns='test/e2e/'", "build_system_Etest": "TEST=demo_entry1.2_hsp1.1:gen_abc jest --testMatch='**/test/e2e/*.test.ts' --testPathIgnorePatterns='test/ut/'", + "run-obfuscation": "node ./test/e2e/obfuscation/process-obfuscation.js", + "obfuscation-all": "npm run build && npm run run-obfuscation", "IncrementCompileTest1": "npm run build && node ./dist/entry.js test/e2e/IncrementDemo/build_config.json && sed -i 's/hello world from harA!/hello world from harA! (modified)/' \"$(pwd)/test/e2e/IncrementDemo/harB/index.ets\" && TEST=IncrementDemo:gen_abc jest --testMatch='**/test/e2e/*.test.ts' --testPathIgnorePatterns='test/ut/'", "IncrementCompileTest2": "npm run build && node ./dist/entry.js test/e2e/IncrementDemo/build_config.json && sed -i 's/console.log(strA)/console.log(strA + \"modified\")/' \"$(pwd)/test/e2e/IncrementDemo/entry/index.ets\" && TEST=IncrementDemo:gen_abc jest --testMatch='**/test/e2e/*.test.ts' --testPathIgnorePatterns='test/ut/'", diff --git a/ets2panda/driver/build_system/src/build/base_mode.ts b/ets2panda/driver/build_system/src/build/base_mode.ts index 231eaa73492433aa195173e9d409202725f39fc8..1c1da90a51d77ec239f7d2009ccc2b443a14fff0 100644 --- a/ets2panda/driver/build_system/src/build/base_mode.ts +++ b/ets2panda/driver/build_system/src/build/base_mode.ts @@ -33,7 +33,8 @@ import { MERGED_INTERMEDIATE_FILE, STATIC_RECORD_FILE, STATIC_RECORD_FILE_CONTENT, - TS_SUFFIX + TS_SUFFIX, + OBFUSCATION_RULE_FILE, } from '../pre_define'; import { changeDeclgenFileExtension, @@ -88,6 +89,7 @@ import { handleDeclgenWorkerExit } from '../util/worker_exit_handler'; import { initKoalaModules } from '../init/init_koala_modules'; +import { ObfuscationConfigParse } from '../obfuscation_config_parse'; export abstract class BaseMode { public buildConfig: BuildConfig; @@ -126,6 +128,11 @@ export abstract class BaseMode { public es2pandaMode: number; public skipDeclCheck: boolean; public genDeclAnnotations: boolean; + public obfPath: string; + public obfAbcFile: string; + public obfRulesJsonPath: string; + public obfuscationRulesPaths: string[]; + public obfuscationRulesFiles: Set; constructor(buildConfig: BuildConfig) { this.buildConfig = buildConfig; @@ -168,6 +175,12 @@ export abstract class BaseMode { ); this.skipDeclCheck = buildConfig?.skipDeclCheck as boolean ?? true; this.genDeclAnnotations = buildConfig?.genDeclAnnotations as boolean ?? true; + this.obfPath = buildConfig.obfuscationPath ?? ''; + this.obfAbcFile = buildConfig.obfuscationPath ? + path.resolve(buildConfig.obfuscationPath, 'obf', MERGED_ABC_FILE) : ''; + this.obfuscationRulesPaths = buildConfig.obfuscationRulesPaths ?? []; + this.obfuscationRulesFiles = new Set(); + this.obfRulesJsonPath = path.resolve(this.obfPath, OBFUSCATION_RULE_FILE); } public declgen(fileInfo: CompileFileInfo): void { @@ -480,6 +493,18 @@ export abstract class BaseMode { } } + private mergeObfuscationRules(): void { + if (this.obfuscationRulesFiles.size == 0) { + return; + } + + ObfuscationConfigParse.getInstance().init(this.mergedAbcFile, this.obfAbcFile, this.obfPath); + this.obfuscationRulesFiles.forEach((file: string) => { + ObfuscationConfigParse.getInstance().readObfuscationRules(file); + }); + ObfuscationConfigParse.getInstance().writeObfuscationRulesInJson(this.obfRulesJsonPath); + } + private getDependentModules(moduleInfo: ModuleInfo): Map[] { const dynamicDepModules: Map = new Map(); const staticDepModules: Map = new Map(); @@ -606,6 +631,7 @@ export abstract class BaseMode { abcPath: module.abcPath, dependenciesSet: new Set(module?.dependencies), dependentSet: new Set(), + obfuscationRulesPaths: module.obfuscationRulesPaths ?? [] }; this.moduleInfos.set(module.packageName, moduleInfo); }); @@ -633,7 +659,8 @@ export abstract class BaseMode { declFilesPath: mainModuleInfo?.declFilesPath, dependentSet: new Set(), dependenciesSet: new Set(mainModuleInfo?.dependencies), - dependencies: mainModuleInfo?.dependencies ?? [] + dependencies: mainModuleInfo?.dependencies ?? [], + obfuscationRulesPaths: this.obfuscationRulesPaths }; } @@ -835,6 +862,16 @@ export abstract class BaseMode { }); } + protected collectObfuscationRulesFiles(): void { + for (const [packageName, moduleInfo] of this.moduleInfos) { + let length = moduleInfo.obfuscationRulesPaths?.length ?? 0; + for (let i = 0; i < length; i++) { + this.obfuscationRulesFiles.add(moduleInfo.obfuscationRulesPaths![i]); + } + } + this.mergeObfuscationRules(); + } + protected collectAbcFileFromByteCodeHar(): void { // the abc of the dependent bytecode har needs to be included When compiling hsp/hap // but it's not required when compiling har @@ -872,6 +909,7 @@ export abstract class BaseMode { compileSingleData.record(RECORDE_MODULE_NODE.COLLECT_INFO); this.collectModuleInfos(); compileSingleData.record(RECORDE_MODULE_NODE.GEN_CONFIG, RECORDE_MODULE_NODE.COLLECT_INFO); + this.collectObfuscationRulesFiles(); this.generateArkTSConfigForModules(); compileSingleData.record(RECORDE_MODULE_NODE.CLT_FILES, RECORDE_MODULE_NODE.GEN_CONFIG); this.collectCompileFiles(); diff --git a/ets2panda/driver/build_system/src/obfuscation_config_parse.ts b/ets2panda/driver/build_system/src/obfuscation_config_parse.ts new file mode 100755 index 0000000000000000000000000000000000000000..5c42af210ec69fef31192727926e45f2b61d578b --- /dev/null +++ b/ets2panda/driver/build_system/src/obfuscation_config_parse.ts @@ -0,0 +1,448 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import fs from 'fs'; +import { ensurePathExists } from './util/utils'; + +export interface KeepOption { + reservedPaths?: string[]; + universalReservedPaths?: string[]; +} + +export interface KeepOptions { + keepPath?: KeepOption; + keeps?: string[]; + keepclassmembers?: string[]; + keepclasswithmembers?: string[]; +} + +export interface FileNameObfuscation { + enable?: boolean; + reservedFileNames?: string[]; + universalReservedFileNames?: string[]; +} + +export interface PrintSeedsOption { + enable?: boolean; + filePath?: string; +} + +export interface ObfuscationRules { + disableObfuscation?: boolean; + printNameCache?: string; + applyNameCache?: string; + removeLog?: boolean; + printSeedsOption?: PrintSeedsOption; + fileNameObfuscation?: FileNameObfuscation; + keepOptions?: KeepOptions; +} + +export interface ObfuscationConfig { + abcPath: string; + obfAbcPath: string; + defaultNameCachePath: string; + obfuscationRules?: ObfuscationRules; +} + +export enum OBFUSCATION_TYPE { + DISABLE_OBFUSCATION = '-disable-obfuscation', + KEEP = '-keep', + KEEP_CLASS_WITH_MEMBERS = '-keepclasswithmembers', + KEEP_CLASS_MEMBERS = '-keepclassmembers', + PRINT_SEEDS = '-printseeds', + PRINT_CONFIGURATION = '-printconfiguration', + PRINT_NAMECACHE = '-print-namecache', + APPLY_NAMECACHE = '-apply-namecache', + REMOVE_LOG = '-remove-log', + KEEP_FILE_NAME = '-keep-file-name' +} + +export class ObfuscationConfigParse { + private static instance: ObfuscationConfigParse | undefined; + private obfuscationConfig: ObfuscationConfig; + private printConfigurationPath: string; + + private constructor() { + this.obfuscationConfig = this.getInitObfuscationConfig(); + this.printConfigurationPath = ''; + } + + public static getInstance(): ObfuscationConfigParse { + if (!this.instance) { + this.instance = new ObfuscationConfigParse(); + } + return this.instance; + } + + public init(abcPath: string, obfAbcPath: string, defaultNameCachePath: string) { + this.obfuscationConfig.abcPath = abcPath; + this.obfuscationConfig.obfAbcPath = obfAbcPath; + this.obfuscationConfig.defaultNameCachePath = defaultNameCachePath; + } + + private getInitObfuscationConfig(): ObfuscationConfig { + let obfuscationConfig = { + abcPath: '', + obfAbcPath: '', + defaultNameCachePath: '' + } + return obfuscationConfig; + } + + public writeObfuscationRulesInJson(filePath: string) { + ensurePathExists(filePath); + const jsonString = JSON.stringify(this.obfuscationConfig, null, 2); + console.log(jsonString); + fs.writeFile(filePath, jsonString, 'utf8', (err) => { + if (err) { + console.error(err); + return; + } + }); + } + + public writeMergeObfuscationRulesResult() { + if (this.printConfigurationPath.length > 0) { + this.writeObfuscationRulesInTxt(this.printConfigurationPath); + } + } + + public writeObfuscationRulesInTxt(filePath: string) { + if (!this.obfuscationConfig.obfuscationRules) { + return; + } + const obfuscationRules = this.obfuscationConfig.obfuscationRules!; + ensurePathExists(filePath); + fs.writeFileSync(filePath, ''); + if (obfuscationRules.disableObfuscation) { + fs.appendFileSync(filePath, OBFUSCATION_TYPE.DISABLE_OBFUSCATION + '\r\n', { encoding: 'utf-8' }); + } + if (obfuscationRules.printNameCache && obfuscationRules.printNameCache !== '') { + fs.appendFileSync(filePath, OBFUSCATION_TYPE.PRINT_NAMECACHE + '\r\n', { encoding: 'utf-8' }); + fs.appendFileSync(filePath, obfuscationRules.printNameCache + '\r\n', { encoding: 'utf-8' }); + } + if (obfuscationRules.applyNameCache && obfuscationRules.applyNameCache !== '') { + fs.appendFileSync(filePath, OBFUSCATION_TYPE.APPLY_NAMECACHE + '\r\n', { encoding: 'utf-8' }); + fs.appendFileSync(filePath, obfuscationRules.applyNameCache + '\r\n', { encoding: 'utf-8' }); + } + if (obfuscationRules.removeLog) { + fs.appendFileSync(filePath, OBFUSCATION_TYPE.REMOVE_LOG + '\r\n', { encoding: 'utf-8' }); + } + if (this.printConfigurationPath.length > 0) { + fs.appendFileSync(filePath, OBFUSCATION_TYPE.PRINT_CONFIGURATION + '\r\n', { encoding: 'utf-8' }); + fs.appendFileSync(filePath, this.printConfigurationPath + '\r\n', { encoding: 'utf-8' }); + } + if (obfuscationRules.printSeedsOption && obfuscationRules.printSeedsOption!.enable) { + fs.appendFileSync(filePath, OBFUSCATION_TYPE.PRINT_SEEDS + '\r\n', { encoding: 'utf-8' }); + if (obfuscationRules.printSeedsOption!.filePath) { + fs.appendFileSync(filePath, obfuscationRules.printSeedsOption!.filePath + '\r\n', { encoding: 'utf-8' }); + } + + } + if (obfuscationRules.fileNameObfuscation && obfuscationRules.fileNameObfuscation!.enable) { + fs.appendFileSync(filePath, OBFUSCATION_TYPE.KEEP_FILE_NAME + '\r\n', { encoding: 'utf-8' }); + obfuscationRules.fileNameObfuscation!.reservedFileNames?.forEach((data: string) => { + fs.appendFileSync(filePath, data + '\r\n', { encoding: 'utf-8' }); + }); + obfuscationRules.fileNameObfuscation!.universalReservedFileNames?.forEach((data: string) => { + fs.appendFileSync(filePath, data + '\r\n', { encoding: 'utf-8' }); + }); + } + this.writeKeepOptionsInTxt(filePath, obfuscationRules); + } + + public readObfuscationRules(filePath: string) { + const data = fs.readFileSync(filePath, 'utf8'); + const lines = data.split(/\r?\n/).filter(line => line.trim() !== ''); + const filteredLines = lines.filter(line => !line.startsWith('#')); + let length = filteredLines.length; + for (let i = 0; i < length; i++) { + let options = filteredLines[i].split(' '); + console.log("options[0]: " + options[0]); + if (!this.obfuscationConfig.obfuscationRules) { + this.obfuscationConfig.obfuscationRules = {}; + } + if (this.isBoolOption(options[0])) { + this.saveBoolOption(options[0]); + } else if (this.isNameCacheOption(options[0])) { + if (options.length > 1) { + this.saveNameCache(options[0], options[1]); + } else { + let extraLists = this.getListData(filteredLines, i + 1); + this.saveNameCache(options[0], extraLists[0]); + i = i + extraLists.length; + } + } else if (options[0] === OBFUSCATION_TYPE.PRINT_SEEDS) { + let num = this.savePrintSeedsOption(options, filteredLines, i + 1); + i = i + num; + } else if (options[0] === OBFUSCATION_TYPE.KEEP_FILE_NAME) { + let num = this.saveFileName(options, filteredLines, i); + i = i + num; + } else if (this.isKeepOption(options[0])) { + let num = this.saveKeepOption(options, filteredLines, i); + i = i + num; + } else if (options[0] === OBFUSCATION_TYPE.PRINT_CONFIGURATION) { + if (options.length > 1) { + this.printConfigurationPath = options[1]; + } else { + let extraLists = this.getListData(filteredLines, i + 1); + this.printConfigurationPath = extraLists[0]; + i = i + extraLists.length; + } + } else { + let extraLists = this.getListData(filteredLines, i + 1); + i = i + extraLists.length; + } + } + this.writeMergeObfuscationRulesResult(); + } + + private writeKeepOptionsInTxt(filePath: string, obfuscationRules: ObfuscationRules) { + if (obfuscationRules.keepOptions) { + if (obfuscationRules.keepOptions!.keepPath) { + fs.appendFileSync(filePath, OBFUSCATION_TYPE.KEEP + '\r\n', { encoding: 'utf-8' }); + } + obfuscationRules.keepOptions!.keepPath?.reservedPaths?.forEach((data: string) => { + fs.appendFileSync(filePath, data + '\r\n', { encoding: 'utf-8' }); + }); + obfuscationRules.keepOptions!.keepPath?.universalReservedPaths?.forEach((data: string) => { + fs.appendFileSync(filePath, data + '\r\n', { encoding: 'utf-8' }); + }); + obfuscationRules.keepOptions!.keeps?.forEach((data: string) => { + fs.appendFileSync(filePath, data + '\r\n', { encoding: 'utf-8' }); + }); + obfuscationRules.keepOptions!.keepclassmembers?.forEach((data: string) => { + fs.appendFileSync(filePath, data + '\r\n', { encoding: 'utf-8' }); + }); + obfuscationRules.keepOptions!.keepclasswithmembers?.forEach((data: string) => { + fs.appendFileSync(filePath, data + '\r\n', { encoding: 'utf-8' }); + }); + } + } + + private saveBoolOption(option: string) { + if (option === OBFUSCATION_TYPE.DISABLE_OBFUSCATION) { + this.obfuscationConfig.obfuscationRules!.disableObfuscation = true; + } + if (option === OBFUSCATION_TYPE.REMOVE_LOG) { + this.obfuscationConfig.obfuscationRules!.removeLog = true; + } + } + + private saveNameCache(option: string, filePath: string) { + if (option === OBFUSCATION_TYPE.APPLY_NAMECACHE) { + this.obfuscationConfig.obfuscationRules!.applyNameCache = filePath; + } + if (option === OBFUSCATION_TYPE.PRINT_NAMECACHE) { + this.obfuscationConfig.obfuscationRules!.printNameCache = filePath; + } + } + + private savePrintSeedsOption(options: string[], lines: string[], index: number): number { + let lineNum = 0; + if (options.length > 1) { + this.obfuscationConfig.obfuscationRules!.printSeedsOption = { + enable: true, + filePath: options[1] + } + } else { + let extraLists = this.getListData(lines, index); + this.obfuscationConfig.obfuscationRules!.printSeedsOption = { + enable: true, + filePath: extraLists[0] + } + lineNum = extraLists.length; + } + return lineNum; + } + + private isUniversal(str: string): boolean { + return (str.includes('.') || str.includes('^') || str.includes('$') || str.includes('*') || str.includes('+') || + str.includes('?') || str.includes('{') || str.includes('}') || str.includes('[') || str.includes(']') || + str.includes('\\') || str.includes('|') || str.includes('(') || str.includes(')')) ? true : false; + } + + private saveFileName(options: string[], lines: string[], index: number): number { + if (!this.obfuscationConfig.obfuscationRules!.fileNameObfuscation) { + this.obfuscationConfig.obfuscationRules!.fileNameObfuscation = {}; + } + let lineNum = 0; + this.obfuscationConfig.obfuscationRules!.fileNameObfuscation!.enable = true; + for (let i = index + 1; i < lines.length; i++) { + if (lines[i].startsWith('-')) { + break; + } + let trimLine = lines[i].trim(); + let fileNameObfuscation = this.obfuscationConfig.obfuscationRules!.fileNameObfuscation!; + if (this.isUniversal(trimLine)) { + if (!fileNameObfuscation.universalReservedFileNames) { + fileNameObfuscation.universalReservedFileNames = []; + } + if (!fileNameObfuscation.universalReservedFileNames!.includes(trimLine)) { + fileNameObfuscation.universalReservedFileNames!.push(trimLine); + } + } else { + if (!fileNameObfuscation.reservedFileNames) { + fileNameObfuscation.reservedFileNames = []; + } + if (!fileNameObfuscation.reservedFileNames!.includes(trimLine)) { + fileNameObfuscation.reservedFileNames!.push(trimLine); + } + } + lineNum++; + } + return lineNum; + } + + private saveKeepOption(options: string[], lines: string[], index: number): number { + if (options[0] === OBFUSCATION_TYPE.KEEP_CLASS_MEMBERS || + options[0] === OBFUSCATION_TYPE.KEEP_CLASS_WITH_MEMBERS) { + return this.saveKeepClass(options[0], lines, index); + } else { + return this.saveKeep(options, lines, index); + } + } + + private getRegexAndNum(lines: string[], index: number): [string, number] { + let regex = ''; + let lineNum = 0; + for (let i = index; i < lines.length; i++) { + lineNum++; + let line = lines[i].trim(); + if (i == index) { + if (line.endsWith('}')) { + regex += line; + break; + } + if (line.endsWith('{')) { + regex += line + ' '; + } else { + regex += line; + } + } else { + if (line.startsWith('-')) { + break; + } + if (line.endsWith('}')) { + regex += ' ' + line; + break; + } + regex += line; + } + } + return [regex, lineNum]; + } + + private saveKeep(options: string[], lines: string[], index: number): number { + if (!this.obfuscationConfig.obfuscationRules!.keepOptions) { + this.obfuscationConfig.obfuscationRules!.keepOptions = {}; + } + let lineNum = 0; + if (options.length > 1) { + let regexAndNum = this.getRegexAndNum(lines, index); + if (!this.obfuscationConfig.obfuscationRules!.keepOptions!.keeps) { + this.obfuscationConfig.obfuscationRules!.keepOptions!.keeps = []; + } + if (!this.obfuscationConfig.obfuscationRules!.keepOptions!.keeps!.includes(regexAndNum[0])) { + this.obfuscationConfig.obfuscationRules!.keepOptions!.keeps!.push(regexAndNum[0]); + } + lineNum = regexAndNum[1]; + lineNum = lineNum > 0 ? lineNum - 1 : lineNum; + } else { + if (!this.obfuscationConfig.obfuscationRules!.keepOptions!.keepPath) { + this.obfuscationConfig.obfuscationRules!.keepOptions!.keepPath = {}; + } + for (let i = index + 1; i < lines.length; i++) { + if (lines[i].startsWith('-')) { + break; + } + let trimLine = lines[i].trim(); + this.saveKeepPath(trimLine); + lineNum++; + } + } + return lineNum; + } + + private saveKeepPath(trimLine: string): void { + if (this.isUniversal(trimLine)) { + let universalReservedPaths = this.obfuscationConfig.obfuscationRules!.keepOptions!.keepPath!; + if (!universalReservedPaths.universalReservedPaths) { + this.obfuscationConfig.obfuscationRules!.keepOptions!.keepPath!.universalReservedPaths = []; + } + if (!universalReservedPaths.universalReservedPaths!.includes(trimLine)) { + this.obfuscationConfig.obfuscationRules!.keepOptions!.keepPath!.universalReservedPaths!.push(trimLine); + } + } else { + if (!this.obfuscationConfig.obfuscationRules!.keepOptions!.keepPath!.reservedPaths) { + this.obfuscationConfig.obfuscationRules!.keepOptions!.keepPath!.reservedPaths = []; + } + if (!this.obfuscationConfig.obfuscationRules!.keepOptions!.keepPath!.reservedPaths!.includes(trimLine)) { + this.obfuscationConfig.obfuscationRules!.keepOptions!.keepPath!.reservedPaths!.push(trimLine); + } + } + } + + private saveKeepClass(option: string, lines: string[], index: number): number { + if (!this.obfuscationConfig.obfuscationRules!.keepOptions) { + this.obfuscationConfig.obfuscationRules!.keepOptions = {}; + } + let [regex, lineNum] = this.getRegexAndNum(lines, index); + if (option === OBFUSCATION_TYPE.KEEP_CLASS_MEMBERS) { + if (!this.obfuscationConfig.obfuscationRules!.keepOptions!.keepclassmembers) { + this.obfuscationConfig.obfuscationRules!.keepOptions!.keepclassmembers = []; + } + if (!this.obfuscationConfig.obfuscationRules!.keepOptions!.keepclassmembers!.includes(regex)) { + this.obfuscationConfig.obfuscationRules!.keepOptions!.keepclassmembers.push(regex); + } + } else { + if (!this.obfuscationConfig.obfuscationRules!.keepOptions!.keepclasswithmembers) { + this.obfuscationConfig.obfuscationRules!.keepOptions!.keepclasswithmembers = []; + } + if (!this.obfuscationConfig.obfuscationRules!.keepOptions!.keepclasswithmembers!.includes(regex)) { + this.obfuscationConfig.obfuscationRules!.keepOptions!.keepclasswithmembers!.push(regex); + } + } + lineNum = lineNum > 0 ? lineNum - 1 : lineNum; + return lineNum; + } + + private getListData(lists: string[], index: number): string[] { + let length = lists.length; + let endIndex: number = length; + for (let i = index; i < length; i++) { + if (lists[i].startsWith('-')) { + endIndex = i; + break; + } + } + if (index == endIndex) { + return []; + } + return lists.slice(index, endIndex); + } + + private isBoolOption(option: string): boolean { + return (option === OBFUSCATION_TYPE.DISABLE_OBFUSCATION || option === OBFUSCATION_TYPE.REMOVE_LOG) ? true : false; + } + + private isNameCacheOption(option: string): boolean { + return (option === OBFUSCATION_TYPE.APPLY_NAMECACHE || option === OBFUSCATION_TYPE.PRINT_NAMECACHE) ? true : false; + } + + private isKeepOption(option: string): boolean { + return (option === OBFUSCATION_TYPE.KEEP || option === OBFUSCATION_TYPE.KEEP_CLASS_MEMBERS || + option === OBFUSCATION_TYPE.KEEP_CLASS_WITH_MEMBERS) ? true : false; + } +} diff --git a/ets2panda/driver/build_system/src/pre_define.ts b/ets2panda/driver/build_system/src/pre_define.ts index a434824c5a61c1d7ed9b0320931b98245b884c97..1c12e95435b4823de0d241f98adf4d89132619b9 100644 --- a/ets2panda/driver/build_system/src/pre_define.ts +++ b/ets2panda/driver/build_system/src/pre_define.ts @@ -21,6 +21,7 @@ export const DEPENDENCY_INPUT_FILE: string = 'dependencyFileInfo.txt'; export const DEPENDENCY_JSON_FILE: string = 'dependency.json'; export const PROJECT_BUILD_CONFIG_FILE: string = 'projectionConfig.json'; export const STATIC_RECORD_FILE: string = 'static.Record.d.ts'; +export const OBFUSCATION_RULE_FILE: string = 'obfuscation-rules.json'; export const DECL_ETS_SUFFIX: string = '.d.ets'; export const DECL_TS_SUFFIX: string = '.d.ts'; diff --git a/ets2panda/driver/build_system/src/types.ts b/ets2panda/driver/build_system/src/types.ts index 73d44ab46babdc6333e1cc25fdeb60a58dbc73f6..2228f814ec1bd651d4cab7bcc3dee33eab836a8d 100644 --- a/ets2panda/driver/build_system/src/types.ts +++ b/ets2panda/driver/build_system/src/types.ts @@ -143,6 +143,8 @@ export interface PathConfig { interopSDKPaths: Set; interopApiPaths:string[]; projectRootPath: string; + obfuscationPath?: string; + obfuscationRulesPaths?:string[]; } /** @@ -195,6 +197,7 @@ export interface DependentModuleConfig { declgenV2OutPath?: string; declgenBridgeCodePath?: string; byteCodeHar: boolean; + obfuscationRulesPaths?: string[]; } export interface BuildConfig extends BuildBaseConfig, DeclgenConfig, LoggerConfig, ModuleConfig, PathConfig, FrameworkConfig { @@ -239,6 +242,7 @@ export interface ModuleInfo { //for topological order merging dependenciesSet:Set; dependentSet:Set; + obfuscationRulesPaths?: string[]; } export type SetupClusterOptions = { diff --git a/ets2panda/driver/build_system/test/e2e/externalProject/containsHar/index.ets b/ets2panda/driver/build_system/test/e2e/externalProject/containsHar/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6b439a23e34aecf851f90d2d2f77c51377aad123 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/containsHar/index.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export { sub } from './sub' + +class HarClassA { + private static alias: string = 'testA'; +} diff --git a/ets2panda/driver/build_system/test/e2e/externalProject/containsHar/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/externalProject/containsHar/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..e7dd764bf8cd126d2e6eab4caa5f5307d3c1e7d6 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/containsHar/obfuscation.txt @@ -0,0 +1,16 @@ +-print-namecache +./customCache/nameCache.json +-apply-namecache +./customCache/nameCache.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_externalHar_harContainsEntry/entry/obfuscation.txt +-printseeds +./customCache/nameCache.json +-keep-file-name +index +-keep +a/b/index +-keep class HarClassA { + private static alias: string = 'testA'; +} diff --git a/ets2panda/driver/build_system/test/e2e/externalProject/containsHar/sub.ets b/ets2panda/driver/build_system/test/e2e/externalProject/containsHar/sub.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ef62e9c7d9b78c6e87dbd8327366dc7db800d5c --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/containsHar/sub.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export function sub(a: number, b: number) { + return a - b +} diff --git a/ets2panda/driver/build_system/test/e2e/externalProject/includedHar/index.ets b/ets2panda/driver/build_system/test/e2e/externalProject/includedHar/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6b439a23e34aecf851f90d2d2f77c51377aad123 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/includedHar/index.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export { sub } from './sub' + +class HarClassA { + private static alias: string = 'testA'; +} diff --git a/ets2panda/driver/build_system/test/e2e/externalProject/includedHar/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/externalProject/includedHar/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..547e2f4545ad98ee1aefbfe105e0ccb683754269 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/includedHar/obfuscation.txt @@ -0,0 +1,16 @@ +-print-namecache +./customCache/nameCache.json +-apply-namecache +./customCache/nameCache.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_externalHar_entryContainsHar/entry/obfuscation.txt +-printseeds +./customCache/nameCache.json +-keep-file-name +index +-keep +a/b/index +-keep class HarClassA { + private static alias: string = 'testA'; +} diff --git a/ets2panda/driver/build_system/test/e2e/externalProject/includedHar/sub.ets b/ets2panda/driver/build_system/test/e2e/externalProject/includedHar/sub.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ef62e9c7d9b78c6e87dbd8327366dc7db800d5c --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/includedHar/sub.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export function sub(a: number, b: number) { + return a - b +} diff --git a/ets2panda/driver/build_system/test/e2e/externalProject/intersectionHar/index.ets b/ets2panda/driver/build_system/test/e2e/externalProject/intersectionHar/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..bf97b3e2d4f22e73cb24e18fd5236cee5abf0604 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/intersectionHar/index.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export { sub } from './sub' + +class HarClassA { + private static alias: string = 'testA'; +} + +class MyclassA { + private static alias: string = 'testA'; + + public static printAlias(): void { + console.log(`Alias: ${MyclassA.alias}`); + } +} diff --git a/ets2panda/driver/build_system/test/e2e/externalProject/intersectionHar/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/externalProject/intersectionHar/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..8bbba94e3026d0f2d625d705bb5916c09e86b314 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/intersectionHar/obfuscation.txt @@ -0,0 +1,15 @@ +-apply-namecache +./customCache/nameCache.json +-print-namecache +./customCache/nameCache.json +-printseeds +./customCache/nameCache.json +-keep class HarClassA { + private static alias: string = 'testA'; +} +-keepclassmembers class MyclassA { + private static alias: string = 'testA'; + public static printAlias(): void; +} +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_externalHar_intersection/entry/obfuscation.txt diff --git a/ets2panda/driver/build_system/test/e2e/externalProject/intersectionHar/sub.ets b/ets2panda/driver/build_system/test/e2e/externalProject/intersectionHar/sub.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ef62e9c7d9b78c6e87dbd8327366dc7db800d5c --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/intersectionHar/sub.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export function sub(a: number, b: number) { + return a - b +} diff --git a/ets2panda/driver/build_system/test/e2e/externalProject/noIntersectionHar/index.ets b/ets2panda/driver/build_system/test/e2e/externalProject/noIntersectionHar/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6b439a23e34aecf851f90d2d2f77c51377aad123 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/noIntersectionHar/index.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export { sub } from './sub' + +class HarClassA { + private static alias: string = 'testA'; +} diff --git a/ets2panda/driver/build_system/test/e2e/externalProject/noIntersectionHar/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/externalProject/noIntersectionHar/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..3f13cec6c8b5a31acb577ee78359750959ee7c52 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/noIntersectionHar/obfuscation.txt @@ -0,0 +1,11 @@ +-apply-namecache +./customCache/harNameCache.json +-print-namecache +./customCache/harNameCache.json +-printseeds +./customCache/harNameCache.json +-keep class HarClassA { + private static alias: string = 'testA'; +} +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_externalHar_noIntersection/entry/obfuscation.txt diff --git a/ets2panda/driver/build_system/test/e2e/externalProject/noIntersectionHar/sub.ets b/ets2panda/driver/build_system/test/e2e/externalProject/noIntersectionHar/sub.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ef62e9c7d9b78c6e87dbd8327366dc7db800d5c --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/noIntersectionHar/sub.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export function sub(a: number, b: number) { + return a - b +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demoObf/build_config_abc.json b/ets2panda/driver/build_system/test/e2e/obfuscation/demoObf/build_config_abc.json new file mode 100644 index 0000000000000000000000000000000000000000..07fc736db2925cf6e405bd60abd9c52ebdc6dfad --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demoObf/build_config_abc.json @@ -0,0 +1,24 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demoObf/entry/index.ets" + ], + "packageName": "entry", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demoObf/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist/out/", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets1", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [], + "hasMainModule": true, + "interopApiPaths": [], + "sdkAliasMap": {} +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demoObf/build_config_decl.json b/ets2panda/driver/build_system/test/e2e/obfuscation/demoObf/build_config_decl.json new file mode 100644 index 0000000000000000000000000000000000000000..6ded960837a2990ad6a7e49b6bef676523f40ba9 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demoObf/build_config_decl.json @@ -0,0 +1,23 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demoObf/entry/index.ets" + ], + "packageName": "entry", + "byteCodeHar": true, + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demoObf/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist/out/", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": true, + "declgenV1OutPath": "./dist/declgen/decl_ets1", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [], + "hasMainModule": true +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demoObf/entry/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demoObf/entry/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..286e098e994b67453f8c94e622d8b3eee7139f94 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demoObf/entry/index.ets @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export enum e_Obf{ + e1_Obf = 1, + e2_Obf = 2, + e3_Obf = 3 +} +export enum e{ + e1 = 1, + e2 = 2, + e3 = 3 +} +export function f_Obs(arg_Obf:number): number{ + return arg_Obf; +} +export function f(arg:number): number{ + return arg; +} +export const num_Obf: number = 1234567890; +export const num: number = 1234567890; + +export class Animal { + protected name: string + protected age: number + constructor(name: string, age: number) { + this.name = name + this.age = age + } + speak(): void { + console.log(`${this.name} makes a sound`) + } + getInfo(): string { + return `Name: ${this.name}, Age: ${this.age}` + } +} + +export class Dog extends Animal { + private breed: string + constructor(name: string, age: number, breed: string) { + super(name, age) + this.breed = breed + } + speak(): void { + console.log(`${this.name} barks`) + } + getBreed(): string { + return this.breed + } +} + +export abstract class Shape { + abstract calculateArea(): number + displayInfo(): void { + console.log(`Area: ${this.calculateArea()}`) + } +} + +export class Circle extends Shape { + private radius: number + constructor(radius: number) { + super() + this.radius = radius + } + calculateArea(): number { + return Math.PI * this.radius * this.radius + } +} +export function main() { + let string_Obf: string = "hello world" + console.log(string_Obf) +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/build_config.json b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/build_config.json new file mode 100644 index 0000000000000000000000000000000000000000..f61a1761b489299306f8decb2b6be51b77102ecc --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/build_config.json @@ -0,0 +1,40 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/entry/index.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [ + { + "packageName": "harA", + "moduleName": "harA", + "moduleType": "har", + "modulePath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/harA", + "sourceRoots": [ + "./" + ], + "entryFile": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/harA/index.ets", + "language": "1.2" + } + ], + "hasMainModule": true, + "obfuscationPath": "./dist/obfuscationPath", + "obfuscationRulesPaths": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/entry/obfuscation-rules.txt", + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/harA/obfuscation.txt" + ] +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/entry/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/entry/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..07e9ec45c57ce6fa6b380a686038f2c9635175a1 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/entry/index.ets @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main() { + let a: string = "hello world" + console.log(a) +} + +export default class Entry { + onCreate() { + main() + } +} + +class MyclassA { + private static alias: string = 'testA'; + + public static printAlias(): void { + console.log(`Alias: ${MyclassA.alias}`); + } +} + +class MyclassB { + private static alias: string = 'testB'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/entry/obfuscation-rules.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..81ccbe1934af46d62bdb8a9ca7fecda4baf6bfbb --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/entry/obfuscation-rules.txt @@ -0,0 +1,45 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-apply-namecache +./customCache/nameCache.json +-print-namecache +./customCache/nameCache.json +-keep-file-name +index +-remove-log +-keep +a/b/index +-keep class Entry { + *; +} +-keep class HarClassA { + private static alias: string = 'testA'; +} +-keepclassmembers class MyclassA { + private static alias: string = 'testA'; + public static printAlias(): void; +} +-keepclasswithmembers class MyclassB { + private static alias: string = 'testB'; +} +-printseeds +./customCache/nameCache.json +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/entry/obfuscation.txt diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/entry/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/entry/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..1b951aa5e69ea8a05590b0525832c23784e35f6c --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/entry/obfuscation.txt @@ -0,0 +1,17 @@ +-print-namecache +./customCache/nameCache.json +-apply-namecache +./customCache/nameCache.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/entry/obfuscation.txt +-printseeds +./customCache/nameCache.json +-keep-file-name +index +-keep +a/b/index +-keep class Entry { *; } +-keep class HarClassA { private static alias: string = 'testA'; } +-keepclassmembers class MyclassA { private static alias: string = 'testA';public static printAlias(): void; } +-keepclasswithmembers class MyclassB { private static alias: string = 'testB'; } diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/harA/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/harA/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6b439a23e34aecf851f90d2d2f77c51377aad123 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/harA/index.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export { sub } from './sub' + +class HarClassA { + private static alias: string = 'testA'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/harA/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/harA/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..9950e3bd67d587c00df2d81833304d65850c06d7 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/harA/obfuscation.txt @@ -0,0 +1,16 @@ +-print-namecache +./customCache/nameCache.json +-apply-namecache +./customCache/nameCache.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/entry/obfuscation.txt +-printseeds +./customCache/nameCache.json +-keep-file-name +index +-keep +a/b/index +-keep class HarClassA { + private static alias: string = 'testA'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/harA/sub.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/harA/sub.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ef62e9c7d9b78c6e87dbd8327366dc7db800d5c --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/harA/sub.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export function sub(a: number, b: number) { + return a - b +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/build_config.json b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/build_config.json new file mode 100644 index 0000000000000000000000000000000000000000..57443f3688a42e05e7359b73c50ef86956a0f59d --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/build_config.json @@ -0,0 +1,40 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/entry/index.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [ + { + "packageName": "harA", + "moduleName": "harA", + "moduleType": "har", + "modulePath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/harA", + "sourceRoots": [ + "./" + ], + "entryFile": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/harA/index.ets", + "language": "1.2" + } + ], + "hasMainModule": true, + "obfuscationPath": "./dist/obfuscationPath", + "obfuscationRulesPaths": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/entry/obfuscation-rules.txt", + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/harA/obfuscation.txt" + ] +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/entry/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/entry/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..07e9ec45c57ce6fa6b380a686038f2c9635175a1 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/entry/index.ets @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main() { + let a: string = "hello world" + console.log(a) +} + +export default class Entry { + onCreate() { + main() + } +} + +class MyclassA { + private static alias: string = 'testA'; + + public static printAlias(): void { + console.log(`Alias: ${MyclassA.alias}`); + } +} + +class MyclassB { + private static alias: string = 'testB'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/entry/obfuscation-rules.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..69a1e908c94b6c9c86ea1b0badeec98295d62e22 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/entry/obfuscation-rules.txt @@ -0,0 +1,43 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-disable-obfuscation +-apply-namecache +./customCache/nameCache.json +-print-namecache +./customCache/nameCache.json +-keep-file-name +index +-remove-log +-keep +a/b/index +-keep class Entry { + *; +} +-keepclassmembers class MyclassA { + private static alias: string = 'testA'; + public static printAlias(): void; +} +-keepclasswithmembers class MyclassB { + private static alias: string = 'testB'; +} +-printseeds +./customCache/nameCache.json +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/entry/obfuscation.txt diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/entry/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/entry/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..3a2a40845f85d0f7ec97db9047811235477ede1a --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/entry/obfuscation.txt @@ -0,0 +1,18 @@ +-disable-obfuscation +-print-namecache +./customCache/nameCache.json +-apply-namecache +./customCache/nameCache.json +-remove-log +-printconfiguration +/home/caolihan/ets_frontend1/arkcompiler_ets_frontend/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/entry/obfuscation.txt +-printseeds +./customCache/nameCache.json +-keep-file-name +index +-keep +a/b/index +-keep class Entry { *; } +-keep class HarClassA { private static alias: string = 'testA'; } +-keepclassmembers class MyclassA { private static alias: string = 'testA';public static printAlias(): void; } +-keepclasswithmembers class MyclassB { private static alias: string = 'testB'; } diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/harA/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/harA/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6b439a23e34aecf851f90d2d2f77c51377aad123 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/harA/index.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export { sub } from './sub' + +class HarClassA { + private static alias: string = 'testA'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/harA/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/harA/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..96e75fb64528889986d65c97c80dc379d6abb233 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/harA/obfuscation.txt @@ -0,0 +1,16 @@ +-print-namecache +./customCache/nameCache.json +-apply-namecache +./customCache/nameCache.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/entry/obfuscation.txt +-printseeds +./customCache/nameCache.json +-keep-file-name +index +-keep +a/b/index +-keep class HarClassA { + private static alias: string = 'testA'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/harA/sub.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/harA/sub.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ef62e9c7d9b78c6e87dbd8327366dc7db800d5c --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_entryDisable/harA/sub.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export function sub(a: number, b: number) { + return a - b +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_entryContainsHar/build_config.json b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_entryContainsHar/build_config.json new file mode 100644 index 0000000000000000000000000000000000000000..aa8bf2cadc1b95d32d8668dc809c95ef32ae9792 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_entryContainsHar/build_config.json @@ -0,0 +1,40 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/entry/index.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [ + { + "packageName": "harA", + "moduleName": "harA", + "moduleType": "har", + "modulePath": "${absolute_path_to_build_system}/test/e2e/obfuscation/externalProject/includedHar", + "sourceRoots": [ + "./" + ], + "entryFile": "${absolute_path_to_build_system}/test/e2e/obfuscation/externalProject/includedHar/index.ets", + "language": "1.2" + } + ], + "hasMainModule": true, + "obfuscationPath": "./dist/obfuscationPath", + "obfuscationRulesPaths": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_entryContainsHar/entry/obfuscation-rules.txt", + "${absolute_path_to_build_system}/test/e2e/externalProject/includedHar/obfuscation.txt" + ] +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_entryContainsHar/entry/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_entryContainsHar/entry/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..07e9ec45c57ce6fa6b380a686038f2c9635175a1 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_entryContainsHar/entry/index.ets @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main() { + let a: string = "hello world" + console.log(a) +} + +export default class Entry { + onCreate() { + main() + } +} + +class MyclassA { + private static alias: string = 'testA'; + + public static printAlias(): void { + console.log(`Alias: ${MyclassA.alias}`); + } +} + +class MyclassB { + private static alias: string = 'testB'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_entryContainsHar/entry/obfuscation-rules.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_entryContainsHar/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..7b2c0bb5d2394ede4c0a2a13dbfe5e5d8915b105 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_entryContainsHar/entry/obfuscation-rules.txt @@ -0,0 +1,45 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-apply-namecache +./customCache/nameCache.json +-print-namecache +./customCache/nameCache.json +-keep-file-name +index +-remove-log +-keep +a/b/index +-keep class Entry { + *; +} +-keep class HarClassA { + private static alias: string = 'testA'; +} +-keepclassmembers class MyclassA { + private static alias: string = 'testA'; + public static printAlias(): void; +} +-keepclasswithmembers class MyclassB { + private static alias: string = 'testB'; +} +-printseeds +./customCache/nameCache.json +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_externalHar_entryContainsHar/entry/obfuscation.txt diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_entryContainsHar/entry/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_entryContainsHar/entry/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..99e97ed1febaa424a1016903a853fb6bca21acd6 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_entryContainsHar/entry/obfuscation.txt @@ -0,0 +1,17 @@ +-print-namecache +./customCache/nameCache.json +-apply-namecache +./customCache/nameCache.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_externalHar_entryContainsHar/entry/obfuscation.txt +-printseeds +./customCache/nameCache.json +-keep-file-name +index +-keep +a/b/index +-keep class Entry { *; } +-keep class HarClassA { private static alias: string = 'testA'; } +-keepclassmembers class MyclassA { private static alias: string = 'testA';public static printAlias(): void; } +-keepclasswithmembers class MyclassB { private static alias: string = 'testB'; } diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_harContainsEntry/build_config.json b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_harContainsEntry/build_config.json new file mode 100644 index 0000000000000000000000000000000000000000..c99ebfaf1058463270eb71e408e72a5aa7e5e0ea --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_harContainsEntry/build_config.json @@ -0,0 +1,40 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_externalHar_harContainsEntry/entry/index.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_externalHar_harContainsEntry/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [ + { + "packageName": "harA", + "moduleName": "harA", + "moduleType": "har", + "modulePath": "${absolute_path_to_build_system}/test/e2e/obfuscation/externalProject/containsHar", + "sourceRoots": [ + "./" + ], + "entryFile": "${absolute_path_to_build_system}/test/e2e/obfuscation/externalProject/containsHar/index.ets", + "language": "1.2" + } + ], + "hasMainModule": true, + "obfuscationPath": "./dist/obfuscationPath", + "obfuscationRulesPaths": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_externalHar_harContainsEntry/entry/obfuscation-rules.txt", + "${absolute_path_to_build_system}/test/e2e/externalProject/containsHar/obfuscation.txt" + ] +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_harContainsEntry/entry/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_harContainsEntry/entry/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..07e9ec45c57ce6fa6b380a686038f2c9635175a1 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_harContainsEntry/entry/index.ets @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main() { + let a: string = "hello world" + console.log(a) +} + +export default class Entry { + onCreate() { + main() + } +} + +class MyclassA { + private static alias: string = 'testA'; + + public static printAlias(): void { + console.log(`Alias: ${MyclassA.alias}`); + } +} + +class MyclassB { + private static alias: string = 'testB'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_harContainsEntry/entry/obfuscation-rules.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_harContainsEntry/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..41f88339cb4d072fddd797275a3b0f5e3e7f3872 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_harContainsEntry/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-printseeds +./customCache/nameCache.json +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_externalHar_harContainsEntry/entry/obfuscation.txt diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_harContainsEntry/entry/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_harContainsEntry/entry/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..94c73f1d7838ee4b149840b19982e41431dadab1 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_harContainsEntry/entry/obfuscation.txt @@ -0,0 +1,14 @@ +-print-namecache +./customCache/nameCache.json +-apply-namecache +./customCache/nameCache.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_externalHar_harContainsEntry/entry/obfuscation.txt +-printseeds +./customCache/nameCache.json +-keep-file-name +index +-keep +a/b/index +-keep class HarClassA { private static alias: string = 'testA'; } diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_intersection/build_config.json b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_intersection/build_config.json new file mode 100644 index 0000000000000000000000000000000000000000..0ea3c789484130490e0cb451f7bf358da915d59f --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_intersection/build_config.json @@ -0,0 +1,40 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_externalHar_intersection/entry/index.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_externalHar_intersection/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [ + { + "packageName": "harA", + "moduleName": "harA", + "moduleType": "har", + "modulePath": "${absolute_path_to_build_system}/test/e2e/obfuscation/externalProject/intersectionHar", + "sourceRoots": [ + "./" + ], + "entryFile": "${absolute_path_to_build_system}/test/e2e/obfuscation/externalProject/intersectionHar/index.ets", + "language": "1.2" + } + ], + "hasMainModule": true, + "obfuscationPath": "./dist/obfuscationPath", + "obfuscationRulesPaths": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_externalHar_intersection/entry/obfuscation-rules.txt", + "${absolute_path_to_build_system}/test/e2e/externalProject/intersectionHar/obfuscation.txt" + ] +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_intersection/entry/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_intersection/entry/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..77ac40ad51a958210743aff1f4933362acd444f6 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_intersection/entry/index.ets @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main() { + let a: string = "hello world" + console.log(a) +} + +export default class Entry { + onCreate() { + main() + } +} + +class MyclassA { + private static alias: string = 'testA'; + + public static printAlias(): void { + console.log(`Alias: ${MyclassA.alias}`); + } +} + +class MyclassB { + private static alias: string = 'testB'; +} + +class HarClassA { + private static alias: string = 'testA'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_intersection/entry/obfuscation-rules.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_intersection/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..2af7ba811a172a1b36ee391f07037e8f515a4bf5 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_intersection/entry/obfuscation-rules.txt @@ -0,0 +1,45 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-apply-namecache +./customCache/nameCache.json +-print-namecache +./customCache/nameCache.json +-keep-file-name +index +-remove-log +-keep +a/b/index +-keep class Entry { + *; +} +-keepclassmembers class MyclassA { + private static alias: string = 'testA'; + public static printAlias(): void; +} +-keepclasswithmembers class MyclassB { + private static alias: string = 'testB'; +} +-keep class HarClassA { + private static alias: string = 'testA'; +} +-printseeds +./customCache/nameCache.json +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_externalHar_intersection/entry/obfuscation.txt diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_intersection/entry/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_intersection/entry/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..f8ef3a9594d04e132827a1d251f3881bd63501ff --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_intersection/entry/obfuscation.txt @@ -0,0 +1,17 @@ +-print-namecache +./customCache/nameCache.json +-apply-namecache +./customCache/nameCache.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_externalHar_intersection/entry/obfuscation.txt +-printseeds +./customCache/nameCache.json +-keep-file-name +index +-keep +a/b/index +-keep class Entry { *; } +-keep class HarClassA { private static alias: string = 'testA'; } +-keepclassmembers class MyclassA { private static alias: string = 'testA';public static printAlias(): void; } +-keepclasswithmembers class MyclassB { private static alias: string = 'testB'; } diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_noIntersection/build_config.json b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_noIntersection/build_config.json new file mode 100644 index 0000000000000000000000000000000000000000..6129c4f0ace64c088d577567c71ea37059f43312 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_noIntersection/build_config.json @@ -0,0 +1,40 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_externalHar_noIntersection/entry/index.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_externalHar_noIntersection/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [ + { + "packageName": "harA", + "moduleName": "harA", + "moduleType": "har", + "modulePath": "${absolute_path_to_build_system}/test/e2e/obfuscation/externalProject/noIntersectionHar", + "sourceRoots": [ + "./" + ], + "entryFile": "${absolute_path_to_build_system}/test/e2e/obfuscation/externalProject/noIntersectionHar/index.ets", + "language": "1.2" + } + ], + "hasMainModule": true, + "obfuscationPath": "./dist/obfuscationPath", + "obfuscationRulesPaths": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_externalHar_noIntersection/entry/obfuscation-rules.txt", + "${absolute_path_to_build_system}/test/e2e/externalProject/noIntersectionHar/obfuscation.txt" + ] +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_noIntersection/entry/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_noIntersection/entry/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..07e9ec45c57ce6fa6b380a686038f2c9635175a1 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_noIntersection/entry/index.ets @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main() { + let a: string = "hello world" + console.log(a) +} + +export default class Entry { + onCreate() { + main() + } +} + +class MyclassA { + private static alias: string = 'testA'; + + public static printAlias(): void { + console.log(`Alias: ${MyclassA.alias}`); + } +} + +class MyclassB { + private static alias: string = 'testB'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_noIntersection/entry/obfuscation-rules.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_noIntersection/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..a86dcc1d0af2177feee90d93fb8ea9701527e511 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_noIntersection/entry/obfuscation-rules.txt @@ -0,0 +1,42 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-apply-namecache +./customCache/nameCache.json +-print-namecache +./customCache/nameCache.json +-keep-file-name +index +-remove-log +-keep +a/b/index +-keep class Entry { + *; +} +-keepclassmembers class MyclassA { + private static alias: string = 'testA'; + public static printAlias(): void; +} +-keepclasswithmembers class MyclassB { + private static alias: string = 'testB'; +} +-printseeds +./customCache/nameCache.json +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_externalHar_noIntersection/entry/obfuscation.txt diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_noIntersection/entry/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_noIntersection/entry/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..d77901fd01ca6520918b9a057ae837eb3a47c525 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_externalHar_noIntersection/entry/obfuscation.txt @@ -0,0 +1,17 @@ +-print-namecache +./customCache/harNameCache.json +-apply-namecache +./customCache/harNameCache.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_externalHar_noIntersection/entry/obfuscation.txt +-printseeds +./customCache/harNameCache.json +-keep-file-name +index +-keep +a/b/index +-keep class Entry { *; } +-keep class HarClassA { private static alias: string = 'testA'; } +-keepclassmembers class MyclassA { private static alias: string = 'testA';public static printAlias(): void; } +-keepclasswithmembers class MyclassB { private static alias: string = 'testB'; } diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/build_config.json b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/build_config.json new file mode 100644 index 0000000000000000000000000000000000000000..eecc8331f2aea641e0eb7b54f670c2a4f83a264e --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/build_config.json @@ -0,0 +1,40 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/entry/index.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [ + { + "packageName": "harA", + "moduleName": "harA", + "moduleType": "har", + "modulePath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/harA", + "sourceRoots": [ + "./" + ], + "entryFile": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/harA/index.ets", + "language": "1.2" + } + ], + "hasMainModule": true, + "obfuscationPath": "./dist/obfuscationPath", + "obfuscationRulesPaths": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/entry/obfuscation-rules.txt", + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/harA/obfuscation.txt" + ] +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/entry/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/entry/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..07e9ec45c57ce6fa6b380a686038f2c9635175a1 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/entry/index.ets @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main() { + let a: string = "hello world" + console.log(a) +} + +export default class Entry { + onCreate() { + main() + } +} + +class MyclassA { + private static alias: string = 'testA'; + + public static printAlias(): void { + console.log(`Alias: ${MyclassA.alias}`); + } +} + +class MyclassB { + private static alias: string = 'testB'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/entry/obfuscation-rules.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..58b832a1c8f193875e0cc0a7ef150d12430eef80 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-printseeds +./customCache/nameCache.json +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/entry/obfuscation.txt diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/entry/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/entry/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..30889363aee8cef8bbbe80de6f3665cc819223cb --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/entry/obfuscation.txt @@ -0,0 +1,14 @@ +-print-namecache +./customCache/nameCache.json +-apply-namecache +./customCache/nameCache.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/entry/obfuscation.txt +-printseeds +./customCache/nameCache.json +-keep-file-name +index +-keep +a/b/index +-keep class HarClassA { private static alias: string = 'testA'; } diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/harA/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/harA/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6b439a23e34aecf851f90d2d2f77c51377aad123 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/harA/index.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export { sub } from './sub' + +class HarClassA { + private static alias: string = 'testA'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/harA/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/harA/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..a14bf757aebe21ee068da2faa6a7c4c3df34e11a --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/harA/obfuscation.txt @@ -0,0 +1,16 @@ +-print-namecache +./customCache/nameCache.json +-apply-namecache +./customCache/nameCache.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/entry/obfuscation.txt +-printseeds +./customCache/nameCache.json +-keep-file-name +index +-keep +a/b/index +-keep class HarClassA { + private static alias: string = 'testA'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/harA/sub.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/harA/sub.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ef62e9c7d9b78c6e87dbd8327366dc7db800d5c --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harContainsEntry/harA/sub.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export function sub(a: number, b: number) { + return a - b +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harDisable/build_config.json b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harDisable/build_config.json new file mode 100644 index 0000000000000000000000000000000000000000..1f32d0b886a651f7195ce1fc8fd168f3481559e0 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harDisable/build_config.json @@ -0,0 +1,40 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_harDisable/entry/index.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_harDisable/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [ + { + "packageName": "harA", + "moduleName": "harA", + "moduleType": "har", + "modulePath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_harDisable/harA", + "sourceRoots": [ + "./" + ], + "entryFile": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_harDisable/harA/index.ets", + "language": "1.2" + } + ], + "hasMainModule": true, + "obfuscationPath": "./dist/obfuscationPath", + "obfuscationRulesPaths": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_harDisable/entry/obfuscation-rules.txt", + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_harDisable/harA/obfuscation.txt" + ] +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harDisable/entry/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harDisable/entry/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..07e9ec45c57ce6fa6b380a686038f2c9635175a1 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harDisable/entry/index.ets @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main() { + let a: string = "hello world" + console.log(a) +} + +export default class Entry { + onCreate() { + main() + } +} + +class MyclassA { + private static alias: string = 'testA'; + + public static printAlias(): void { + console.log(`Alias: ${MyclassA.alias}`); + } +} + +class MyclassB { + private static alias: string = 'testB'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harDisable/entry/obfuscation-rules.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harDisable/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..887aa48ce173745a676808f5fe78f0a435d49afd --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harDisable/entry/obfuscation-rules.txt @@ -0,0 +1,42 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-apply-namecache +./customCache/nameCache.json +-print-namecache +./customCache/nameCache.json +-keep-file-name +index +-remove-log +-keep +a/b/index +-keep class Entry { + *; +} +-keepclassmembers class MyclassA { + private static alias: string = 'testA'; + public static printAlias(): void; +} +-keepclasswithmembers class MyclassB { + private static alias: string = 'testB'; +} +-printseeds +./customCache/nameCache.json +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_harDisable/entry/obfuscation.txt diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harDisable/entry/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harDisable/entry/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..c1541638c3816c29e4a7a115e85e581ac1515477 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harDisable/entry/obfuscation.txt @@ -0,0 +1,18 @@ +-disable-obfuscation +-print-namecache +./customCache/nameCache.json +-apply-namecache +./customCache/nameCache.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_harDisable/entry/obfuscation.txt +-printseeds +./customCache/nameCache.json +-keep-file-name +index +-keep +a/b/index +-keep class Entry { *; } +-keep class HarClassA { private static alias: string = 'testA'; } +-keepclassmembers class MyclassA { private static alias: string = 'testA';public static printAlias(): void; } +-keepclasswithmembers class MyclassB { private static alias: string = 'testB'; } diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harDisable/harA/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harDisable/harA/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6b439a23e34aecf851f90d2d2f77c51377aad123 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harDisable/harA/index.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export { sub } from './sub' + +class HarClassA { + private static alias: string = 'testA'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harDisable/harA/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harDisable/harA/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..3f3da9e6b488e4f91e62e4c003e2462cbe760fad --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harDisable/harA/obfuscation.txt @@ -0,0 +1,17 @@ +-disable-obfuscation +-print-namecache +./customCache/nameCache.json +-apply-namecache +./customCache/nameCache.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_harDisable/entry/obfuscation.txt +-printseeds +./customCache/nameCache.json +-keep-file-name +index +-keep +a/b/index +-keep class HarClassA { + private static alias: string = 'testA'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harDisable/harA/sub.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harDisable/harA/sub.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ef62e9c7d9b78c6e87dbd8327366dc7db800d5c --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_harDisable/harA/sub.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export function sub(a: number, b: number) { + return a - b +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_intersection/build_config.json b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_intersection/build_config.json new file mode 100644 index 0000000000000000000000000000000000000000..69d976d2157e14bcac34b3ba78d2deb89d9110e0 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_intersection/build_config.json @@ -0,0 +1,40 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_intersection/entry/index.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_intersection/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [ + { + "packageName": "harA", + "moduleName": "harA", + "moduleType": "har", + "modulePath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_intersection/harA", + "sourceRoots": [ + "./" + ], + "entryFile": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_intersection/harA/index.ets", + "language": "1.2" + } + ], + "hasMainModule": true, + "obfuscationPath": "./dist/obfuscationPath", + "obfuscationRulesPaths": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_intersection/entry/obfuscation-rules.txt", + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_intersection/harA/obfuscation.txt" + ] +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_intersection/entry/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_intersection/entry/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..07e9ec45c57ce6fa6b380a686038f2c9635175a1 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_intersection/entry/index.ets @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main() { + let a: string = "hello world" + console.log(a) +} + +export default class Entry { + onCreate() { + main() + } +} + +class MyclassA { + private static alias: string = 'testA'; + + public static printAlias(): void { + console.log(`Alias: ${MyclassA.alias}`); + } +} + +class MyclassB { + private static alias: string = 'testB'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_intersection/entry/obfuscation-rules.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_intersection/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..3ec1b56ab3aed362f883bce1c48f21efb40a0f61 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_intersection/entry/obfuscation-rules.txt @@ -0,0 +1,42 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-apply-namecache +./customCache/nameCache.json +-print-namecache +./customCache/nameCache.json +-keep-file-name +index +-remove-log +-keep +a/b/index +-keep class Entry { + *; +} +-keepclassmembers class MyclassA { + private static alias: string = 'testA'; + public static printAlias(): void; +} +-keepclasswithmembers class MyclassB { + private static alias: string = 'testB'; +} +-printseeds +./customCache/nameCache.json +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_intersection/entry/obfuscation.txt diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_intersection/entry/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_intersection/entry/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..692e2e7b1d5d1c809b477d059a9733d7779dd1af --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_intersection/entry/obfuscation.txt @@ -0,0 +1,17 @@ +-print-namecache +./customCache/nameCache.json +-apply-namecache +./customCache/nameCache.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_intersection/entry/obfuscation.txt +-printseeds +./customCache/nameCache.json +-keep-file-name +index +-keep +a/b/index +-keep class Entry { *; } +-keep class HarClassA { private static alias: string = 'testA'; } +-keepclassmembers class MyclassA { private static alias: string = 'testA';public static printAlias(): void; } +-keepclasswithmembers class MyclassB { private static alias: string = 'testB'; } diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_intersection/harA/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_intersection/harA/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6b439a23e34aecf851f90d2d2f77c51377aad123 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_intersection/harA/index.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export { sub } from './sub' + +class HarClassA { + private static alias: string = 'testA'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_intersection/harA/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_intersection/harA/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..d4c8ef1a6cb3f5cfa3d387c1819e9684bd245fdc --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_intersection/harA/obfuscation.txt @@ -0,0 +1,16 @@ +-print-namecache +./customCache/nameCache.json +-apply-namecache +./customCache/nameCache.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_intersection/entry/obfuscation.txt +-printseeds +./customCache/nameCache.json +-keep-file-name +index +-keep +a/b/index +-keep class HarClassA { + private static alias: string = 'testA'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_intersection/harA/sub.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_intersection/harA/sub.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ef62e9c7d9b78c6e87dbd8327366dc7db800d5c --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_intersection/harA/sub.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export function sub(a: number, b: number) { + return a - b +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/build_config.json b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/build_config.json new file mode 100644 index 0000000000000000000000000000000000000000..91d8c7e934ac74e773e6ce74e45ec22c11fd77bf --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/build_config.json @@ -0,0 +1,40 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/entry/index.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [ + { + "packageName": "harA", + "moduleName": "harA", + "moduleType": "har", + "modulePath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/harA", + "sourceRoots": [ + "./" + ], + "entryFile": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/harA/index.ets", + "language": "1.2" + } + ], + "hasMainModule": true, + "obfuscationPath": "./dist/obfuscationPath", + "obfuscationRulesPaths": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/entry/obfuscation-rules.txt", + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/harA/obfuscation.txt" + ] +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/entry/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/entry/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..07e9ec45c57ce6fa6b380a686038f2c9635175a1 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/entry/index.ets @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main() { + let a: string = "hello world" + console.log(a) +} + +export default class Entry { + onCreate() { + main() + } +} + +class MyclassA { + private static alias: string = 'testA'; + + public static printAlias(): void { + console.log(`Alias: ${MyclassA.alias}`); + } +} + +class MyclassB { + private static alias: string = 'testB'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/entry/obfuscation-rules.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..6052f4b133a13c4e3976b5c92ea4811910110693 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/entry/obfuscation-rules.txt @@ -0,0 +1,42 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-apply-namecache +./customCache/nameCache.json +-print-namecache +./customCache/nameCache.json +-keep-file-name +index +-remove-log +-keep +a/b/index +-keep class Entry { + *; +} +-keepclassmembers class MyclassA { + private static alias: string = 'testA'; + public static printAlias(): void; +} +-keepclasswithmembers class MyclassB { + private static alias: string = 'testB'; +} +-printseeds +./customCache/nameCache.json +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/entry/obfuscation.txt diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/entry/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/entry/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..147a2e8309b3e18442eee39952445fcaeb88b1ed --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/entry/obfuscation.txt @@ -0,0 +1,17 @@ +-print-namecache +./customCache/harNameCache.json +-apply-namecache +./customCache/harNameCache.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/entry/obfuscation.txt +-printseeds +./customCache/harNameCache.json +-keep-file-name +index +-keep +a/b/index +-keep class Entry { *; } +-keep class HarClassA { private static alias: string = 'testA'; } +-keepclassmembers class MyclassA { private static alias: string = 'testA';public static printAlias(): void; } +-keepclasswithmembers class MyclassB { private static alias: string = 'testB'; } diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/harA/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/harA/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6b439a23e34aecf851f90d2d2f77c51377aad123 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/harA/index.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export { sub } from './sub' + +class HarClassA { + private static alias: string = 'testA'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/harA/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/harA/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..6398c6447feb580db0e2ef764ed41024288d577d --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/harA/obfuscation.txt @@ -0,0 +1,11 @@ +-apply-namecache +./customCache/harNameCache.json +-print-namecache +./customCache/harNameCache.json +-printseeds +./customCache/harNameCache.json +-keep class HarClassA { + private static alias: string = 'testA'; +} +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/entry/obfuscation.txt diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/harA/sub.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/harA/sub.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ef62e9c7d9b78c6e87dbd8327366dc7db800d5c --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_mergeObfRules_noIntersection/harA/sub.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export function sub(a: number, b: number) { + return a - b +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_default/build_config.json b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_default/build_config.json new file mode 100644 index 0000000000000000000000000000000000000000..7a2cb6208a6c77632f510059f485fd814a8c82aa --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_default/build_config.json @@ -0,0 +1,27 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_default/entry/index.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_default/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [], + "hasMainModule": true, + "obfuscationPath": "./dist/obfuscationPath", + "obfuscationRulesPaths": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_default/entry/obfuscation-rules.txt" + ] +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_default/entry/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_default/entry/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..76a66d7bbfd24d99a07b0ee71e0e6225ec62d355 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_default/entry/index.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main() { + let a: string = "hello world" + console.log(a) +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_default/entry/obfuscation-rules.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_default/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..eb5c766dfc6374b931f6a57b652b5f7675765da1 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_default/entry/obfuscation-rules.txt @@ -0,0 +1,18 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_disable/build_config.json b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_disable/build_config.json new file mode 100644 index 0000000000000000000000000000000000000000..b867505ec3246e27c1ddc8d62cfc66df75f1cc71 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_disable/build_config.json @@ -0,0 +1,27 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_disable/entry/index.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_disable/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [], + "hasMainModule": true, + "obfuscationPath": "./dist/obfuscationPath", + "obfuscationRulesPaths": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_disable/entry/obfuscation-rules.txt" + ] +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_disable/entry/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_disable/entry/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..07e9ec45c57ce6fa6b380a686038f2c9635175a1 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_disable/entry/index.ets @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main() { + let a: string = "hello world" + console.log(a) +} + +export default class Entry { + onCreate() { + main() + } +} + +class MyclassA { + private static alias: string = 'testA'; + + public static printAlias(): void { + console.log(`Alias: ${MyclassA.alias}`); + } +} + +class MyclassB { + private static alias: string = 'testB'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_disable/entry/obfuscation-rules.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_disable/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..80ba8b39828f493f27c398cc49592ca019340d19 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_disable/entry/obfuscation-rules.txt @@ -0,0 +1,43 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-disable-obfuscation +-apply-namecache +./customCache/nameCache.json +-print-namecache +./customCache/nameCache.json +-keep-file-name +index +-remove-log +-keep +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_disable/entry/test.ets +-keep class Entry { + *; +} +-keepclassmembers class MyclassA { + private static alias: string = 'testA'; + public static printAlias(): void; +} +-keepclasswithmembers class MyclassB { + private static alias: string = 'testB'; +} +-printseeds +./customCache/nameCache.json +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_disable/entry/obfuscation.txt diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_disable/entry/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_disable/entry/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..caf6a5299e13bde291f6864d97205e2b8a09d444 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_disable/entry/obfuscation.txt @@ -0,0 +1,17 @@ +-disable-obfuscation +-print-namecache +./customCache/nameCache.json +-apply-namecache +./customCache/nameCache.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_disable/entry/obfuscation.txt +-printseeds +./customCache/nameCache.json +-keep-file-name +index +-keep +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_disable/entry/test.ets +-keep class Entry { *; } +-keepclassmembers class MyclassA { private static alias: string = 'testA';public static printAlias(): void; } +-keepclasswithmembers class MyclassB { private static alias: string = 'testB'; } diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_disable/entry/test.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_disable/entry/test.ets new file mode 100644 index 0000000000000000000000000000000000000000..eee500b6dc6c680429d9a7c68c1dcdfe312cde08 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_disable/entry/test.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main() { + let a: string = "hello world" + console.log(a) +} + +export default class Entry { + onCreate() { + main() + } +} + +class MyclassA { + private static alias: string = 'testA'; +} + +class MyclassB { + private static alias: string = 'testB'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_double_pass/build_config_first.json b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_double_pass/build_config_first.json new file mode 100644 index 0000000000000000000000000000000000000000..7852ea912c2cd19394f71bc8f8041e89bc1e957b --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_double_pass/build_config_first.json @@ -0,0 +1,27 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/index.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache_first", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [], + "hasMainModule": true, + "obfuscationPath": "./dist/obfuscationPath_first", + "obfuscationRulesPaths": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/obfuscation-rules-first.txt" + ] +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_double_pass/build_config_second.json b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_double_pass/build_config_second.json new file mode 100644 index 0000000000000000000000000000000000000000..18deb89758151fc9a88ec118084672fc67258539 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_double_pass/build_config_second.json @@ -0,0 +1,27 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/index.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache_second", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [], + "hasMainModule": true, + "obfuscationPath": "./dist/obfuscationPath_second", + "obfuscationRulesPaths": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/obfuscation-rules-second.txt" + ] +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..7cd1b149dc8c20a8261a68ffd34c16bdb2642a3f --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/index.ets @@ -0,0 +1,35 @@ +export class DoublePassTestClass { + private memberVariable: string = "original_value"; + public static staticMember: number = 42; + + constructor(param: string) { + this.memberVariable = param; + } + + public testMethod(inputParam: string): string { + console.log("This log should be removed in first pass"); + let localVariable = inputParam + this.memberVariable; + return localVariable; + } + + public anotherMethod(): void { + console.info("This info should be removed in second pass"); + let tempVar = DoublePassTestClass.staticMember * 2; + console.log("Result:", tempVar); + } +} + +export function globalFunction(arg1: string, arg2: number): boolean { + console.warn("Warning message to be removed"); + let result = arg1.length > arg2; + return result; +} + +export class Entry { + public static main(): void { + let testInstance = new DoublePassTestClass("test_param"); + testInstance.testMethod("input_value"); + testInstance.anotherMethod(); + globalFunction("test_string", 10); + } +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/obfuscation-rules-first.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/obfuscation-rules-first.txt new file mode 100644 index 0000000000000000000000000000000000000000..30161a5ad350d544b0eec4993e6df955cdec6b20 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/obfuscation-rules-first.txt @@ -0,0 +1,23 @@ +# First pass obfuscation rules - basic obfuscation +# Focus on removing logs and basic name obfuscation + +-print-namecache +./dist/nameCache_first.json +-apply-namecache +./dist/nameCache_first.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/obfuscation_first.txt +-printseeds +./dist/nameCache_first.json +-keep-file-name +index +-keep +entry/index +-keep class Entry { + *; +} +-keep class DoublePassTestClass { + public static main(): void; + constructor(param: string); +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/obfuscation-rules-second.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/obfuscation-rules-second.txt new file mode 100644 index 0000000000000000000000000000000000000000..cf813f0e3e441eb52a0c062c9bc5ccfe2a03c779 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/obfuscation-rules-second.txt @@ -0,0 +1,23 @@ +# Second pass obfuscation rules - more aggressive obfuscation +# Apply the first pass name cache and add additional obfuscation + +-print-namecache +./dist/nameCache_second.json +-apply-namecache +./dist/nameCache_first.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/obfuscation_second.txt +-printseeds +./dist/nameCache_second.json +-keep-file-name +index +-keep +entry/index +-keep class Entry { + public static main(): void; +} +-keepclassmembers class DoublePassTestClass { + constructor(param: string); +} +# More aggressive in second pass - fewer keeps diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/obfuscation_first.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/obfuscation_first.txt new file mode 100644 index 0000000000000000000000000000000000000000..1d6406f78506e682cab09292b6e974a390838e02 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/obfuscation_first.txt @@ -0,0 +1,15 @@ +-print-namecache +./dist/nameCache_first.json +-apply-namecache +./dist/nameCache_first.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/obfuscation_first.txt +-printseeds +./dist/nameCache_first.json +-keep-file-name +index +-keep +entry/index +-keep class Entry { *; } +-keep class DoublePassTestClass { public static main(): void;constructor(param: string); } diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/obfuscation_second.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/obfuscation_second.txt new file mode 100644 index 0000000000000000000000000000000000000000..49252fc5b02bbe37b43434bd9a3538d2ca61b96e --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/obfuscation_second.txt @@ -0,0 +1,15 @@ +-print-namecache +./dist/nameCache_second.json +-apply-namecache +./dist/nameCache_first.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_double_pass/entry/obfuscation_second.txt +-printseeds +./dist/nameCache_second.json +-keep-file-name +index +-keep +entry/index +-keep class Entry { public static main(): void; } +-keepclassmembers class DoublePassTestClass { constructor(param: string); } diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_errorCase/build_config.json b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_errorCase/build_config.json new file mode 100644 index 0000000000000000000000000000000000000000..b551ef4973aacd31174725497d64d3bfc2859e8f --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_errorCase/build_config.json @@ -0,0 +1,27 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_errorCase/entry/index.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_errorCase/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [], + "hasMainModule": true, + "obfuscationPath": "./dist/obfuscationPath", + "obfuscationRulesPaths": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_errorCase/entry/obfuscation-rules.txt" + ] +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_errorCase/entry/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_errorCase/entry/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..07e9ec45c57ce6fa6b380a686038f2c9635175a1 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_errorCase/entry/index.ets @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main() { + let a: string = "hello world" + console.log(a) +} + +export default class Entry { + onCreate() { + main() + } +} + +class MyclassA { + private static alias: string = 'testA'; + + public static printAlias(): void { + console.log(`Alias: ${MyclassA.alias}`); + } +} + +class MyclassB { + private static alias: string = 'testB'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_errorCase/entry/obfuscation-rules.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_errorCase/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..4387b806b2cada08de093a4522a6ed36ccf64fe1 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_errorCase/entry/obfuscation-rules.txt @@ -0,0 +1,20 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +aaaaa diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_errorCase2/build_config.json b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_errorCase2/build_config.json new file mode 100644 index 0000000000000000000000000000000000000000..d2be24acb13e77cf5dbc1fe3f4d1257af1d9b3ea --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_errorCase2/build_config.json @@ -0,0 +1,27 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_errorCase2/entry/index.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_errorCase2/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [], + "hasMainModule": true, + "obfuscationPath": "./dist/obfuscationPath", + "obfuscationRulesPaths": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_errorCase2/entry/obfuscation-rules.txt" + ] +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_errorCase2/entry/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_errorCase2/entry/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..07e9ec45c57ce6fa6b380a686038f2c9635175a1 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_errorCase2/entry/index.ets @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main() { + let a: string = "hello world" + console.log(a) +} + +export default class Entry { + onCreate() { + main() + } +} + +class MyclassA { + private static alias: string = 'testA'; + + public static printAlias(): void { + console.log(`Alias: ${MyclassA.alias}`); + } +} + +class MyclassB { + private static alias: string = 'testB'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_errorCase2/entry/obfuscation-rules.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_errorCase2/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..5ecf2f05316c7f8cdb1847133223c1d179994ebd --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_errorCase2/entry/obfuscation-rules.txt @@ -0,0 +1,26 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-keepclass Entry { + *; +} +-keepclassmembersclass MyclassA { + private static alias: string = 'testA'; + public static printAlias(): void; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_exclude/build_config.json b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_exclude/build_config.json new file mode 100644 index 0000000000000000000000000000000000000000..2c0738f789372391692d3bdb554adf959264264b --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_exclude/build_config.json @@ -0,0 +1,27 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_keep_exclude/entry/index.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_keep_exclude/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [], + "hasMainModule": true, + "obfuscationPath": "./dist/obfuscationPath", + "obfuscationRulesPaths": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_keep_exclude/entry/obfuscation-rules.txt" + ] +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_exclude/entry/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_exclude/entry/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..07e9ec45c57ce6fa6b380a686038f2c9635175a1 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_exclude/entry/index.ets @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main() { + let a: string = "hello world" + console.log(a) +} + +export default class Entry { + onCreate() { + main() + } +} + +class MyclassA { + private static alias: string = 'testA'; + + public static printAlias(): void { + console.log(`Alias: ${MyclassA.alias}`); + } +} + +class MyclassB { + private static alias: string = 'testB'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_exclude/entry/obfuscation-rules.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_exclude/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..f5cddb57c219ebc5afeaec17f311e8f73d6c5f69 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_exclude/entry/obfuscation-rules.txt @@ -0,0 +1,42 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-apply-namecache +./customCache/nameCache.json +-print-namecache +./customCache/nameCache.json +-keep-file-name +index +-remove-log +-keep +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_keep_exclude/entry/test.ets +-keep class ExcludeEntrty { + *; +} +-keepclassmembers class ExcludeClass { + private static alias: string = 'testA'; + public static printAlias(): void; +} +-keepclasswithmembers class ExcludeClass { + private static alias: string = 'testB'; +} +-printseeds +./customCache/nameCache.json +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_keep_exclude/entry/obfuscation.txt diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_exclude/entry/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_exclude/entry/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..14b5e7267ceb98e49ab53e755deb0c54ee030bbc --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_exclude/entry/obfuscation.txt @@ -0,0 +1,16 @@ +-print-namecache +./customCache/nameCache.json +-apply-namecache +./customCache/nameCache.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_keep_exclude/entry/obfuscation.txt +-printseeds +./customCache/nameCache.json +-keep-file-name +index +-keep +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_keep_exclude/entry/test.ets +-keep class ExcludeEntrty { *; } +-keepclassmembers class ExcludeClass { private static alias: string = 'testA';public static printAlias(): void; } +-keepclasswithmembers class ExcludeClass { private static alias: string = 'testB'; } diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_exclude/entry/test.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_exclude/entry/test.ets new file mode 100644 index 0000000000000000000000000000000000000000..eee500b6dc6c680429d9a7c68c1dcdfe312cde08 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_exclude/entry/test.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main() { + let a: string = "hello world" + console.log(a) +} + +export default class Entry { + onCreate() { + main() + } +} + +class MyclassA { + private static alias: string = 'testA'; +} + +class MyclassB { + private static alias: string = 'testB'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_include/build_config.json b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_include/build_config.json new file mode 100644 index 0000000000000000000000000000000000000000..ac4322eecb0205599222438b49151cccbc5a4b61 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_include/build_config.json @@ -0,0 +1,27 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_keep_include/entry/index.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_keep_include/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [], + "hasMainModule": true, + "obfuscationPath": "./dist/obfuscationPath", + "obfuscationRulesPaths": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_keep_include/entry/obfuscation-rules.txt" + ] +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_include/entry/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_include/entry/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..07e9ec45c57ce6fa6b380a686038f2c9635175a1 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_include/entry/index.ets @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main() { + let a: string = "hello world" + console.log(a) +} + +export default class Entry { + onCreate() { + main() + } +} + +class MyclassA { + private static alias: string = 'testA'; + + public static printAlias(): void { + console.log(`Alias: ${MyclassA.alias}`); + } +} + +class MyclassB { + private static alias: string = 'testB'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_include/entry/obfuscation-rules.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_include/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..b905a7f57aa5b6b96bc1e41ac4d9dca513f04156 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_include/entry/obfuscation-rules.txt @@ -0,0 +1,42 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-apply-namecache +./customCache/nameCache.json +-print-namecache +./customCache/nameCache.json +-keep-file-name +index +-remove-log +-keep +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_keep_include/entry/test.ets +-keep class Entry { + *; +} +-keepclassmembers class MyclassA { + private static alias: string = 'testA'; + public static printAlias(): void; +} +-keepclasswithmembers class MyclassB { + private static alias: string = 'testB'; +} +-printseeds +./customCache/nameCache.json +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_keep_include/entry/obfuscation.txt diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_include/entry/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_include/entry/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..69dadf84892397c2d5c8d645bea29f078240513c --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_include/entry/obfuscation.txt @@ -0,0 +1,16 @@ +-print-namecache +./customCache/nameCache.json +-apply-namecache +./customCache/nameCache.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_keep_include/entry/obfuscation.txt +-printseeds +./customCache/nameCache.json +-keep-file-name +index +-keep +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_keep_include/entry/test.ets +-keep class Entry { *; } +-keepclassmembers class MyclassA { private static alias: string = 'testA';public static printAlias(): void; } +-keepclasswithmembers class MyclassB { private static alias: string = 'testB'; } diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_include/entry/test.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_include/entry/test.ets new file mode 100644 index 0000000000000000000000000000000000000000..eee500b6dc6c680429d9a7c68c1dcdfe312cde08 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_keep_include/entry/test.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main() { + let a: string = "hello world" + console.log(a) +} + +export default class Entry { + onCreate() { + main() + } +} + +class MyclassA { + private static alias: string = 'testA'; +} + +class MyclassB { + private static alias: string = 'testB'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withBlock/build_config.json b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withBlock/build_config.json new file mode 100644 index 0000000000000000000000000000000000000000..a1ba6e2533f9c64b35618dd78defa8750b551b29 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withBlock/build_config.json @@ -0,0 +1,27 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_withBlock/entry/index.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_withBlock/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [], + "hasMainModule": true, + "obfuscationPath": "./dist/obfuscationPath", + "obfuscationRulesPaths": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_withBlock/entry/obfuscation-rules.txt" + ] +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withBlock/entry/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withBlock/entry/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..07e9ec45c57ce6fa6b380a686038f2c9635175a1 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withBlock/entry/index.ets @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main() { + let a: string = "hello world" + console.log(a) +} + +export default class Entry { + onCreate() { + main() + } +} + +class MyclassA { + private static alias: string = 'testA'; + + public static printAlias(): void { + console.log(`Alias: ${MyclassA.alias}`); + } +} + +class MyclassB { + private static alias: string = 'testB'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withBlock/entry/obfuscation-rules.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withBlock/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..6f59b540b23737c01951981cde8101bd58ca3a11 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withBlock/entry/obfuscation-rules.txt @@ -0,0 +1,44 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-apply-namecache + +./customCache/nameCache.json +-print-namecache ./customCache/nameCache.json +-keep-file-name +index +-remove-log +-keep +index + +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_withBlock/entry/test.ets +-keep class Entry { + *; +} +-keepclassmembers class MyclassA { + private static alias: string = 'testA'; + public static printAlias(): void; +} +-keepclasswithmembers class MyclassB { + private static alias: string = 'testB'; +} +-printseeds +./customCache/nameCache.json +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_withBlock/entry/obfuscation.txt diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withBlock/entry/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withBlock/entry/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..4864727da72816383648520b5d0844002403c67f --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withBlock/entry/obfuscation.txt @@ -0,0 +1,15 @@ +-apply-namecache +./customCache/nameCache.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_withBlock/entry/obfuscation.txt +-printseeds +./customCache/nameCache.json +-keep-file-name +index +-keep +index +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_withBlock/entry/test.ets +-keep class Entry { *; } +-keepclassmembers class MyclassA { private static alias: string = 'testA';public static printAlias(): void; } +-keepclasswithmembers class MyclassB { private static alias: string = 'testB'; } diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withBlock/entry/test.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withBlock/entry/test.ets new file mode 100644 index 0000000000000000000000000000000000000000..eee500b6dc6c680429d9a7c68c1dcdfe312cde08 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withBlock/entry/test.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main() { + let a: string = "hello world" + console.log(a) +} + +export default class Entry { + onCreate() { + main() + } +} + +class MyclassA { + private static alias: string = 'testA'; +} + +class MyclassB { + private static alias: string = 'testB'; +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withoutKeep/build_config.json b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withoutKeep/build_config.json new file mode 100644 index 0000000000000000000000000000000000000000..17fd84facc134d854800c559110335588e1795ee --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withoutKeep/build_config.json @@ -0,0 +1,27 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_withoutKeep/entry/index.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_withoutKeep/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [], + "hasMainModule": true, + "obfuscationPath": "./dist/obfuscationPath", + "obfuscationRulesPaths": [ + "${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_withoutKeep/entry/obfuscation-rules.txt" + ] +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withoutKeep/entry/index.ets b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withoutKeep/entry/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..76a66d7bbfd24d99a07b0ee71e0e6225ec62d355 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withoutKeep/entry/index.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main() { + let a: string = "hello world" + console.log(a) +} diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withoutKeep/entry/obfuscation-rules.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withoutKeep/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..1dbb4ff3c4983c59b53fc8d72999c2abc9433494 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withoutKeep/entry/obfuscation-rules.txt @@ -0,0 +1,28 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-apply-namecache +./customCache/nameCache.json +-print-namecache +./customCache/nameCache.json +-remove-log +-printseeds +./customCache/nameCache.json +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_withoutKeep/entry/obfuscation.txt diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withoutKeep/entry/obfuscation.txt b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withoutKeep/entry/obfuscation.txt new file mode 100644 index 0000000000000000000000000000000000000000..3c09683917bfea8d174fbc906b4d24221410b8ee --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/demo_obfuscation_withoutKeep/entry/obfuscation.txt @@ -0,0 +1,9 @@ +-print-namecache +./customCache/nameCache.json +-apply-namecache +./customCache/nameCache.json +-remove-log +-printconfiguration +${absolute_path_to_build_system}/test/e2e/obfuscation/demo_obfuscation_withoutKeep/entry/obfuscation.txt +-printseeds +./customCache/nameCache.json diff --git a/ets2panda/driver/build_system/test/e2e/obfuscation/process-obfuscation.js b/ets2panda/driver/build_system/test/e2e/obfuscation/process-obfuscation.js new file mode 100644 index 0000000000000000000000000000000000000000..d4f9ade93cd83bf079388a52462c278111175f6b --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/obfuscation/process-obfuscation.js @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const { execSync } = require('child_process'); +const fs = require('fs'); +const path = require('path'); + +const buildSystemDir = path.resolve(__dirname, '../../..'); +const obfuscationDir = path.join(buildSystemDir, 'test/e2e/obfuscation'); + +function validateObfuscationResult(testScriptName) { + const e2eDir = path.join(buildSystemDir, 'test/e2e'); + const entryDir = path.join(e2eDir, 'obfuscation', testScriptName, 'entry'); + const distDir = path.join(buildSystemDir, 'dist/obfuscationPath'); + const obfuscationTxtPath = path.join(entryDir, 'obfuscation.txt'); + const obfuscationRulesJsonPath = path.join(distDir, 'obfuscation-rules.json'); + + const modulesStaticAbcPath1 = path.join(buildSystemDir, 'dist/modules_static.abc'); + const modulesStaticAbcPath2 = path.join(buildSystemDir, 'dist/out/modules_static.abc'); + + const obfuscationTxtExists = fs.existsSync(obfuscationTxtPath); + const obfuscationRulesJsonExists = fs.existsSync(obfuscationRulesJsonPath); + const modulesStaticAbcPathExists = fs.existsSync(modulesStaticAbcPath1) || fs.existsSync(modulesStaticAbcPath2); + + console.log(`Validating ${testScriptName}...`); + + if (testScriptName !== 'demo_obfuscation_default' && + testScriptName !== 'demo_obfuscation_errorCase' && + testScriptName !== 'demo_obfuscation_errorCase2' && + testScriptName !== 'demoObf') { + if (!modulesStaticAbcPathExists) { + throw new Error(`modules_static.abc not found for ${testScriptName}`); + } + if (!obfuscationRulesJsonExists) { + throw new Error(`obfuscation-rules.json not found for ${testScriptName}`); + } + if (!obfuscationTxtExists) { + throw new Error(`obfuscation.txt not found for ${testScriptName}`); + } + } else { + if (!modulesStaticAbcPathExists) { + throw new Error(`modules_static.abc not found for ${testScriptName}`); + } + } + + return true; +} + +function getTestCases() { + const testCases = []; + const items = fs.readdirSync(obfuscationDir); + + for (const item of items) { + const itemPath = path.join(obfuscationDir, item); + if (fs.statSync(itemPath).isDirectory() && item !== 'test') { + testCases.push(item); + } + } + + return testCases; +} + +function findConfigFile(testCaseName) { + const testCaseDir = path.join(obfuscationDir, testCaseName); + const configFiles = ['build_config.json', 'build_config_abc.json', 'build_config_decl.json']; + + for (const configFile of configFiles) { + const configPath = path.join(testCaseDir, configFile); + if (fs.existsSync(configPath)) { + return configPath; + } + } + + return null; +} + +function findDoublePassConfigFiles(testCaseName) { + const testCaseDir = path.join(obfuscationDir, testCaseName); + const firstConfigPath = path.join(testCaseDir, 'build_config_first.json'); + const secondConfigPath = path.join(testCaseDir, 'build_config_second.json'); + + if (fs.existsSync(firstConfigPath) && fs.existsSync(secondConfigPath)) { + return [firstConfigPath, secondConfigPath]; + } + + return null; +} + +function validateDoublePassResult(testScriptName) { + const entryDir = path.join(obfuscationDir, testScriptName, 'entry'); + + const firstObfTxtPath = path.join(entryDir, 'obfuscation_first.txt'); + const secondObfTxtPath = path.join(entryDir, 'obfuscation_second.txt'); + + const modulesStaticAbcPath = path.join(buildSystemDir, 'dist/modules_static.abc'); + + const firstRulesJsonPath = path.join(buildSystemDir, 'dist/obfuscationPath_first/obfuscation-rules.json'); + const secondRulesJsonPath = path.join(buildSystemDir, 'dist/obfuscationPath_second/obfuscation-rules.json'); + + console.log(`Validating double pass ${testScriptName}...`); + + if (!fs.existsSync(firstObfTxtPath)) { + throw new Error(`obfuscation_first.txt not found for ${testScriptName}`); + } + + if (!fs.existsSync(secondObfTxtPath)) { + throw new Error(`obfuscation_second.txt not found for ${testScriptName}`); + } + + if (!fs.existsSync(modulesStaticAbcPath)) { + throw new Error(`modules_static.abc not found for ${testScriptName}`); + } + + if (!fs.existsSync(firstRulesJsonPath)) { + throw new Error(`First pass obfuscation-rules.json not found for ${testScriptName}`); + } + + if (!fs.existsSync(secondRulesJsonPath)) { + throw new Error(`Second pass obfuscation-rules.json not found for ${testScriptName}`); + } + + return true; +} + +function runTestCase(testCaseName) { + console.log(`========== Running ${testCaseName} ==========`); + + const doublePassConfigs = findDoublePassConfigFiles(testCaseName); + if (doublePassConfigs) { + return runDoublePassTestCase(testCaseName, doublePassConfigs); + } + + const configPath = findConfigFile(testCaseName); + if (!configPath) { + console.log(`No valid config file found for ${testCaseName}`); + return false; + } + + console.log(`Using config: ${path.basename(configPath)}`); + + try { + console.log('Running npm build...'); + execSync('npm run build', { + cwd: buildSystemDir, + stdio: 'pipe' + }); + + console.log('Running compilation...'); + execSync(`node ./dist/entry.js "${configPath}"`, { + cwd: buildSystemDir, + stdio: 'pipe' + }); + + validateObfuscationResult(testCaseName); + + console.log(`✓ ${testCaseName} passed`); + return true; + } catch (error) { + console.error(`✗ ${testCaseName} failed: ${error.message}`); + return false; + } finally { + console.log('------------------------------------------'); + } +} + +function runDoublePassTestCase(testCaseName, configPaths) { + console.log(`Double pass test case detected`); + + try { + console.log('Running npm build...'); + execSync('npm run build', { + cwd: buildSystemDir, + stdio: 'pipe' + }); + + console.log('Running first pass compilation...'); + console.log(`Using config: ${path.basename(configPaths[0])}`); + execSync(`node ./dist/entry.js "${configPaths[0]}"`, { + cwd: buildSystemDir, + stdio: 'pipe' + }); + + console.log('Running second pass compilation...'); + console.log(`Using config: ${path.basename(configPaths[1])}`); + execSync(`node ./dist/entry.js "${configPaths[1]}"`, { + cwd: buildSystemDir, + stdio: 'pipe' + }); + + validateDoublePassResult(testCaseName); + + console.log(`✓ ${testCaseName} (double pass) passed`); + return true; + } catch (error) { + console.error(`✗ ${testCaseName} (double pass) failed: ${error.message}`); + return false; + } finally { + console.log('------------------------------------------'); + } +} + +function main() { + const testCases = getTestCases(); + const results = { + passed: [], + failed: [] + }; + + console.log(`Found ${testCases.length} test cases\n`); + + for (const testCase of testCases) { + const success = runTestCase(testCase); + if (success) { + results.passed.push(testCase); + } else { + results.failed.push(testCase); + } + } + + console.log('\n================== E2E Test Summary =================='); + console.log(`Total: ${testCases.length}`); + console.log(`Passed: ${results.passed.length}`); + console.log(`Failed: ${results.failed.length}`); + + if (results.passed.length > 0) { + console.log('Passed tests:'); + for (const test of results.passed) { + console.log(` ${test}`); + } + } + + if (results.failed.length > 0) { + console.log('Failed tests:'); + for (const test of results.failed) { + console.log(` ${test}`); + } + } + + console.log('======================================================'); + + if (results.failed.length > 0) { + process.exit(1); + } +} + +if (require.main === module) { + main(); +} + +module.exports = { + main, + runTestCase, + validateObfuscationResult, + validateDoublePassResult, + getTestCases, + findDoublePassConfigFiles, + runDoublePassTestCase +};