VFP的代码混淆器,只在VFP9下运行正常
2007-08-03 00:42
435 查看
这是个原型,只能对PRG文件进行混淆,还未完善。
阿明的FOXSHELL看界面有 代码混淆功能,应是很好。
但我的需要,有些不同,要公开部分代码、公开部分二次开发接口,LEONID的混淆器只能
对EXE/APP处理,且BUG不小, 自主的混淆器暂时还是必须的。
1
2*- OBFUSCATOR ----------------------------------------------------------------------------------------------------
3*-
4*- 功能: 针对 PRG代码|代码串的 混淆器,只混淆local定义和lParameters定义。
5*-
6*-
7*- 现行的算法: 只是替换 LOCAL定义和lParameters定义中变量。这两个关键字必须写全,不能缩写。
8*- 替换的必须是 独立的“词”,以cSep来界定。
9*-
10*- 未解决的问题:
11*-
12*- 1. 能会误将 字符串中字符 的与local定义同形的 也混了。算法上应区别 textmerge等
13*- 字符串中,不替换
14*- 除非: (1)在textmerge中 and <>之内;
15*- (2)& 之后
16*- (3)type('')之内
17*- (4)形如: evaluate('oObj.name') 中的oObj
18*- (5)
19*-
20*- 这个算法未做,但影响不大,只是某些情况下有字符串会乱了。
21*-
22*- 2. 个funciton一起时. 应分开FUNCTION、分段处理的,目前是混在一起。有可能出错
23*- 3. 换后,可能做成行长大于255。但vfp9好象没有行长限制了。
24*- 4. 以分号续行的情况,未有考虑。
25*- 5. 生成随机的变量名,除0o之外,应有其他选项。
26*--------------------------------------------------------------------------------------------------------------------
27
28
29Local cFile,cSep,cCode,aXtbl[1,2],i,j,k,cLine,cBin,nIdx,cVarDefKeyWord,cVarName,cVarCnt,nPos,cTmpCodes,cTmpLine
30Local nIdx,cVarDefKeyWord,cVarName,cVarCnt,nPos,cTmpCodes,cTmpLine
31
32
33*cFile = Getfile('prg')
34*cFile = 'D:\02WORKSHOP\YXERP01\01STD\TEST\abc.PRG'
35cFile = 'D:\02WORKSHOP\YXERP01\01STD\source\通用函数.PRG'
36If Empty(cFile)
37 Return .F.
38EndIf
39
40*--
41cCode=Filetostr(cFile)
42cSep = Chr(13)+Chr(10)+Chr(9)+"()=+-*/&@<>.',%[] "+'"'
43
44*-- 1. 去掉注解--------------------------------------------------
45cTmpCodes=''
46For i=1 to GetWordCount(cCode,Chr(13)+Chr(10))
47 cLine = Ltrim(GetWordNum(cCode,i,Chr(13)+Chr(10)) ,1,Chr(9),' ')
48 If Left( cLine,1) = '*'
49 Loop
50 EndIf
51
52 nPos = At('&'+'&',cLine)
53 If nPos > 0
54 cTmp = Substr(cLine,1,nPos-1)
55 If Occurs("'",cTmp)%2=0 and Occurs('"',cTmp)%2=0 &&不在字符串中
56 cLine = cTmp
57 EndIf
58 EndIf
59
60 cTmpCodes = cTmpCodes + Chr(13)+Chr(10) + cLine
61Next
62cCode = cTmpCodes
63
64
65
66*-- 2. 取得local 及 lparameters 定义,生成对照表-------------------------------
67cVarDefKeyWord='local'
68nIdx = 0
69Do While .T.
70 nIdx = nIdx + 1
71 nPos = Atc(cVarDefKeyWord,cCode,nIdx)
72 If nPos = 0
73 If cVarDefKeyWord='local'
74 cVarDefKeyWord='lparameters'
75 nIdx = 0
76 Loop
77 Else
78 Exit
79 EndIf
80 Endif
81
82 cLine = Substr(cCode,nPos-1,500)
83 cLine = Left( cLine, At(Chr(13),cLine))
84 If Not Inlist(Left(cLine,1),Chr(10),Chr(13),' ')
85 Loop
86 EndIf
87
88 cLine = Substr(cLine,Len(cVarDefKeyWord)+2)
89
90 If At('[',cLine)>0 or At('(',cLine)>0 &&array handling
91 cLine = Chrtran( cLine,'[]()', '****' )
92 cTmpLine=''
93 For i=1 to GetWordCount(cLine,'*')
94 cTmp = Alltrim(GetWordNum(cLine,i,'*'),1,Chr(9),' ')
95 If IsDigit(cTmp)
96 Loop
97 EndIf
98 cTmpLine = cTmpLine + cTmp
99 Next
100 cLine = cTmpLine
101 EndIf
102 *---
103
104 For i=1 To Getwordcount(cLine,',')
105 cVarName = Lower( Alltrim(Getwordnum(cLine,i,','),1,Chr(10),Chr(9),Chr(13),' ') )
106 cVarName = GetWordNum(cVarName,1 ,'([')
107 If Ascan(aXTbl,cVarName,1,0,1,2+4)>0
108 Loop
109 EndIf
110
111 If Vartype(aXtbl(1))<>'L'
112 Declare aXtbl( Alen(aXTbl,1)+1, 2)
113 EndIf
114
115 aXTbl(Alen(aXtbl,1),1) = cVarName
116 cBin = ''
117 For j=30 To 0 Step -1
118 cBin = cBin + Iif(Bittest(Rand()*100000000,i),'0','o')
119 Next
120 aXTbl(Alen(aXtbl,1),2) = 'o' + cBin
121
122 wait window nowait '取得变量: ' + padr(cVarName + ' ---> ' + 'o'+cBin,50)
123 Next
124Enddo
125
126
127*--3. 替换变量.o0o0o0o0o0oooo000 --------------------------------------
128For i=1 To Alen(aXTbl,1)
129 If Vartype(aXtbl(i,1))='L'
130 Loop
131 Endif
132
133 nIdx = 1
134 Do While .T.
135 nPos = Atc(aXtbl(i,1),cCode,nIdx)
136 If nPos=0
137 Exit
138 Endif
139
140 nBeforeChar = Substr(cCode,nPos-1,1)
141 nAfterChar = Substr(cCode,nPos+Len(aXtbl(i,1)),1)
142 If Not (nBeforeChar $ cSep Or Empty(nBeforeChar)) or ;
143 Not (nAfterChar $ cSep Or Empty(nAfterChar))
144
145 nIdx = nIdx + 1
146 Loop
147 Endif
148 *-----
149 cCode = Left(cCode, nPos-1) + aXTbl(i,2) + Substr(cCode,nPos + Len(aXTbl(i,1)) )
150 EndDo
151
152 wait window nowait 'obfuscating ' + Str( i / Alen(aXTbl,1)*100,5,2) +' % ' && +cVarName + ' ---> ' + 'o'+cBin
153Next
154
155StrToFile(cCode,'obfuscated.prg')
156Wait clear
157
158Modify Command obfuscated.prg
159
160
161
162
163
164
阿明的FOXSHELL看界面有 代码混淆功能,应是很好。
但我的需要,有些不同,要公开部分代码、公开部分二次开发接口,LEONID的混淆器只能
对EXE/APP处理,且BUG不小, 自主的混淆器暂时还是必须的。
1
2*- OBFUSCATOR ----------------------------------------------------------------------------------------------------
3*-
4*- 功能: 针对 PRG代码|代码串的 混淆器,只混淆local定义和lParameters定义。
5*-
6*-
7*- 现行的算法: 只是替换 LOCAL定义和lParameters定义中变量。这两个关键字必须写全,不能缩写。
8*- 替换的必须是 独立的“词”,以cSep来界定。
9*-
10*- 未解决的问题:
11*-
12*- 1. 能会误将 字符串中字符 的与local定义同形的 也混了。算法上应区别 textmerge等
13*- 字符串中,不替换
14*- 除非: (1)在textmerge中 and <>之内;
15*- (2)& 之后
16*- (3)type('')之内
17*- (4)形如: evaluate('oObj.name') 中的oObj
18*- (5)
19*-
20*- 这个算法未做,但影响不大,只是某些情况下有字符串会乱了。
21*-
22*- 2. 个funciton一起时. 应分开FUNCTION、分段处理的,目前是混在一起。有可能出错
23*- 3. 换后,可能做成行长大于255。但vfp9好象没有行长限制了。
24*- 4. 以分号续行的情况,未有考虑。
25*- 5. 生成随机的变量名,除0o之外,应有其他选项。
26*--------------------------------------------------------------------------------------------------------------------
27
28
29Local cFile,cSep,cCode,aXtbl[1,2],i,j,k,cLine,cBin,nIdx,cVarDefKeyWord,cVarName,cVarCnt,nPos,cTmpCodes,cTmpLine
30Local nIdx,cVarDefKeyWord,cVarName,cVarCnt,nPos,cTmpCodes,cTmpLine
31
32
33*cFile = Getfile('prg')
34*cFile = 'D:\02WORKSHOP\YXERP01\01STD\TEST\abc.PRG'
35cFile = 'D:\02WORKSHOP\YXERP01\01STD\source\通用函数.PRG'
36If Empty(cFile)
37 Return .F.
38EndIf
39
40*--
41cCode=Filetostr(cFile)
42cSep = Chr(13)+Chr(10)+Chr(9)+"()=+-*/&@<>.',%[] "+'"'
43
44*-- 1. 去掉注解--------------------------------------------------
45cTmpCodes=''
46For i=1 to GetWordCount(cCode,Chr(13)+Chr(10))
47 cLine = Ltrim(GetWordNum(cCode,i,Chr(13)+Chr(10)) ,1,Chr(9),' ')
48 If Left( cLine,1) = '*'
49 Loop
50 EndIf
51
52 nPos = At('&'+'&',cLine)
53 If nPos > 0
54 cTmp = Substr(cLine,1,nPos-1)
55 If Occurs("'",cTmp)%2=0 and Occurs('"',cTmp)%2=0 &&不在字符串中
56 cLine = cTmp
57 EndIf
58 EndIf
59
60 cTmpCodes = cTmpCodes + Chr(13)+Chr(10) + cLine
61Next
62cCode = cTmpCodes
63
64
65
66*-- 2. 取得local 及 lparameters 定义,生成对照表-------------------------------
67cVarDefKeyWord='local'
68nIdx = 0
69Do While .T.
70 nIdx = nIdx + 1
71 nPos = Atc(cVarDefKeyWord,cCode,nIdx)
72 If nPos = 0
73 If cVarDefKeyWord='local'
74 cVarDefKeyWord='lparameters'
75 nIdx = 0
76 Loop
77 Else
78 Exit
79 EndIf
80 Endif
81
82 cLine = Substr(cCode,nPos-1,500)
83 cLine = Left( cLine, At(Chr(13),cLine))
84 If Not Inlist(Left(cLine,1),Chr(10),Chr(13),' ')
85 Loop
86 EndIf
87
88 cLine = Substr(cLine,Len(cVarDefKeyWord)+2)
89
90 If At('[',cLine)>0 or At('(',cLine)>0 &&array handling
91 cLine = Chrtran( cLine,'[]()', '****' )
92 cTmpLine=''
93 For i=1 to GetWordCount(cLine,'*')
94 cTmp = Alltrim(GetWordNum(cLine,i,'*'),1,Chr(9),' ')
95 If IsDigit(cTmp)
96 Loop
97 EndIf
98 cTmpLine = cTmpLine + cTmp
99 Next
100 cLine = cTmpLine
101 EndIf
102 *---
103
104 For i=1 To Getwordcount(cLine,',')
105 cVarName = Lower( Alltrim(Getwordnum(cLine,i,','),1,Chr(10),Chr(9),Chr(13),' ') )
106 cVarName = GetWordNum(cVarName,1 ,'([')
107 If Ascan(aXTbl,cVarName,1,0,1,2+4)>0
108 Loop
109 EndIf
110
111 If Vartype(aXtbl(1))<>'L'
112 Declare aXtbl( Alen(aXTbl,1)+1, 2)
113 EndIf
114
115 aXTbl(Alen(aXtbl,1),1) = cVarName
116 cBin = ''
117 For j=30 To 0 Step -1
118 cBin = cBin + Iif(Bittest(Rand()*100000000,i),'0','o')
119 Next
120 aXTbl(Alen(aXtbl,1),2) = 'o' + cBin
121
122 wait window nowait '取得变量: ' + padr(cVarName + ' ---> ' + 'o'+cBin,50)
123 Next
124Enddo
125
126
127*--3. 替换变量.o0o0o0o0o0oooo000 --------------------------------------
128For i=1 To Alen(aXTbl,1)
129 If Vartype(aXtbl(i,1))='L'
130 Loop
131 Endif
132
133 nIdx = 1
134 Do While .T.
135 nPos = Atc(aXtbl(i,1),cCode,nIdx)
136 If nPos=0
137 Exit
138 Endif
139
140 nBeforeChar = Substr(cCode,nPos-1,1)
141 nAfterChar = Substr(cCode,nPos+Len(aXtbl(i,1)),1)
142 If Not (nBeforeChar $ cSep Or Empty(nBeforeChar)) or ;
143 Not (nAfterChar $ cSep Or Empty(nAfterChar))
144
145 nIdx = nIdx + 1
146 Loop
147 Endif
148 *-----
149 cCode = Left(cCode, nPos-1) + aXTbl(i,2) + Substr(cCode,nPos + Len(aXTbl(i,1)) )
150 EndDo
151
152 wait window nowait 'obfuscating ' + Str( i / Alen(aXTbl,1)*100,5,2) +' % ' && +cVarName + ' ---> ' + 'o'+cBin
153Next
154
155StrToFile(cCode,'obfuscated.prg')
156Wait clear
157
158Modify Command obfuscated.prg
159
160
161
162
163
164
相关文章推荐
- vfp 的主文件MAIN.PRG编译成.EXE可执行文件后,开始运行正常,几天后,不能运行?
- gma950 调试 xna4.0代码 编译正常 运行出错
- 代码没问题一运行就说与偶个问题导致程序停止正常工作了
- AS项目运行正常,但查看代码飘红the file size exceeds configured limit.
- 在VC运行正常在ADS异常的代码
- 关于可运行代码无法正常执行的使用说明
- extjs中的JS代码在firefox可以正常运行,在IE中无法运行的方法。
- Proguard混淆后无法正常运行的问题
- 这段代码居然运行正常
- SnmpTrap 线程 内附代码,eclipse可正常运行测试!
- 在OD中修改代码可以正常运行,尝试各种补丁却不行
- 调试经验 | Visual Studio中代码正常运行,但运行生成的exe报错“0xc000007b无法正常启动”
- eclipse+cdt 代码编译通过 正常运行 编辑器却报错
- 加密后的php代码需要ZendGuardLoader模块才能正常运行
- 迈普-MP2600企业路由器简单配置可正常运行实例代码
- opencv 1.0下运行正常的代码,后续版本不能正常运行
- android 混淆代码后 app 运行报错时, 如何精准定位报错位置
- 使用Progurad工具混淆代码 保留内部类并正常调用
- android studio环境下代码混淆(混淆完了直接打包就可以运行)
- 很奇怪,下面这段代码在VC6.0里面运行正常,但在VS2010面确有错误提示,求高手解释!