怎样应用程序加密码控制?

kill 2000-05-11 12:53:00
我是初学者,现在正在练习编写应用程序,我想作一个小软件,在它启动的时候,由管理者输入密码,确认后再进入系统,但不知道我应怎样实现密码的任意变更,如能提供源程
序或实际例子原码,将不胜感激!!
...全文
326 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
xfchai 2000-06-09
  • 打赏
  • 举报
回复
dongcan, 在数据库中存放是不是不太安全呀。用更好的办法吗。
dongcan 2000-06-09
  • 打赏
  • 举报
回复
在你的数据库中,加一个表,一字段,用来放密码?下面的我不说你一定会了!
有问题吗?
wxz 2000-05-18
  • 打赏
  • 举报
回复
简单一点,可以用注册表保存密码
haiyang 2000-05-17
  • 打赏
  • 举报
回复
我记不得是从那弄来的。建议多到一些站点,推荐大富翁论坛,http://www.gislab.ecnu.edu.cn/delphibbs!
//纯粹作弊,敬请原谅!
可执行文件的自修改

The Unofficial Newsletter of Delphi Users - by Robert Vivrette
---------------------------------

Self-Modifying Code With Delphi
by Marcus M?nnig - minibbjd@gmx.de

Preface

Lots of people using high-level languages, like Object Pascal, do not know much about what happens with their code when they click compile in Delphi. If you have a basic knowledge about assembler and about the exe file format, the comments in the source code should make everything pretty clear. For everyone else, I will try to explain what's done in the source code.
My own knowledge about assembler and the exe format is limited and I learned most of it while looking for information about piracy protection and how to implement self-modifying code myself. The reason why I did this article is that I found very little information about this issue, so I put everything I found together to share it. Further, english is not my native language, so excuse any spelling and grammatical mistakes.

Self-modifying code with Delphi

What is it? Normally, we modify our code at design time. This usually happens inside Delphi before the code is compiled. Well, we all know this.
Then, sometimes compiled code gets modified, e.g. a patch might be applied to a (non-running) exe file to do changes to the original exe. This is often used when applications are distributed widely and the users want to update to a newer version. To save download time and to prevent that the user has to reinstall the whole application again, only the differences between two versions of an exe file are distributed in a patch file an applied to the old version of the exe. Another example of patch files are "cracks"... little com or exe files that remove built-in limitations (evaluation time limits, etc.) from applications.
These two kinds of code modifications are obviously done before the exe is executed. When an exe file is executed the file gets loaded into memory. The only way to affect the behavior of the program after this point is to modify the memory where the exe now resides.
A program that modifies itself while it is running by doing changes to the memory uses "self-modifying code".
Why is it bad?
Self-modifying code makes debugging harder, since there is a difference in what is in the memory and what the debugger thinks is in the memory.
Self-modifying code also has a bad reputation, especially because the most prominent use for it are viruses, that do all kinds of hide and seek tricks with it. This also means that if you use self-modifying code it's always possible that a virus checker will complain about your application.

Why is it good?
Self-modifying code makes debugging harder. While this is bad if you want to debug your code, it's good to prevent others from debugging your code or at least make it harder for them. This is the reason why self-modifying code can be an effective part of a piracy protection scheme. It won't prevent that an application can be cracked, however a wise use of this technique can make it very hard.
What functions are needed?

In a Windows environment we can make use the following API calls:

ReadProcessMemory(hProcess,lpBaseAddress,lpBuffer,nSize,lpNumberOfBytesRead);
This function is used, well, to read the memory of a process. Since this article is about _self_-modifying code, we will always use this function on our process only.
WriteProcessMemory(hProcess,lpBaseAddress,lpBuffer,nSize,lpNumberOfBytesWritten);
Used for writing data to a process memory.
VirtualProtect(lpAddress,dwSize,flNewProtect,lpflOldProtect);
Used to change the access protection of a region in memory. To learn more about these functions, refer to the Win32 help file that ships with Delphi and take a look how they are used in the sample code.
What does the example code do?

The code that will be modified is inside the CallModifiedCode procedure:

procedure TForm1.CallModifiedCode(Sender: TObject);
var
b:boolean;
c:TColor;
label 1;
begin
c := clgreen;
b := true;
if b then goto 1;
asm
nop
nop
nop
nop
nop
nop
end;
c := clred;
1:
form1.Color := c;
end;

After studying the code you might be puzzled about some things. Obviously, this code sets the color of Form1, but as it is, the color will always be green, since b is always true, so it will always jump to label 1 and c:=clred before never gets called.
However, there is another function in the program that will change the line if b then goto 1; to if NOT(b) then goto 1; while the program is running, so after this modification in memory is done and this function is called again the form will actually be changed to red. Note that we will not change the boolean value of b, but virtually insert a "NOT" into the if statement.
Surely you noticed the six "nop"'s. "nop" is an assembler instruction and means "no operation", so these 6 lines do just nothing. 6 nop's in a row are quite unusual in a compiled exe, so we will use these nops as a marker for the position of the if statement above inside the compiled exe.
To understand how we will modify the code, we need to take a look at what the compiler will make from our pascal code. You can do this by running the project from Delphi, setting a breakpoint on the line with the if statement and (once you called the CallModifiedCode procedure by clicking the button and the debugger stopped the execution) opening the CPU window from Delphi's debug menu. You will see something like this:

807DFB00 cmp byte ptr [ebp-$05],$00
750D jnz TForm1.CallModifiedCode + $2A
90 nop
90 nop
90 nop
90 nop
90 nop
90 nop
Well, we can clearly see the 6 nops we placed in our code. The two lines above are the assembler code of the if statement. The first line compares a value (as we know from the pascal code this has to be the boolean value of b) with $00, the hexadecimal notation of 0, that in the case of a boolean variable means false.
The second line starts with jnz, what means "jump if not equal" (technically, "jump if not zero") and the address to jump to if the compared values from line one are not equal. So, the first two lines mean: "Compare the value of variable b with 0 (false) and if they are not equal jump away."
Note the hexadecimal values to the left of the asm code above. Each assembler instruction has a unique hexadecimal identifier. Obviously, $90 means "nop". $75 means "jnz", which is followed by the address (relative to the current address) to jump to ($0D in this case). $80 means "cmp" followed by some hexadecimal data specifying what and how it it compared. This hexadecimal representation of the assembler instructions is what makes the exe. If you have a hex editor, load the compiled exe and try to search for "909090909090". You will quickly find it and you will notice that the values before will be identical with the values above.
So, coming back to our task, if we want to insert "NOT" into our if statement, we will need to replace "jnz" with "jz". "jz" means "jump if zero" or "jump if equal". Replacing "jnz" with "jz" will reverse the condition in the original if statement, so once this modification is done the jump will not be done and the line c:=clRed; will be executed and the form will get red. As I said, "jnz" is represented by the hexadecimal value $75. The hexadecimal value for "jz" is $74.
Let's summarize what we have to do to change "if b then goto 1;" to "if NOT(b) then goto 1;": Locate $909090909090 in memory. From this position, go back two bytes and replace $75 with $74. If we want to go back to the original code, we do the same, but replace $74 with $75.
This is what is done in procedure TForm1.ModifyCode. I'll not go into further details here, but the source has lots of comments. You can download the sample code for this article by clicking here. After calling ModifyCode by clicking one of the two buttons on the right, click the "Execute code" button again and open the CPU view in Delphi to see that $75 was actually replaced with $74 or vice versa.
Epilog
There are easier ways to set the color of a form depending on which button was clicked ;-), but of course the purpose here is to demonstrate the concept of self-modifying code. Self-modifying code is a powerful technique and the example code might be very useful to implement a piracy protection scheme.
Finally, a small warning: You should take care when using a series of assembler nop's as a marker in real world applications, as these kind of unused code sections can be a nest for some viruses, e.g. the
W95/CIH1003 virus.
newcsdn 2000-05-17
  • 打赏
  • 举报
回复
把密碼記在在regedit或者放在數据庫里都可以,很簡單的几行代碼,自己先試試!
fyje 2000-05-17
  • 打赏
  • 举报
回复
吧密码放在数据库中,登录是检测一下就行了,我记得好多例子中都有,你可以查查看.
saxash 2000-05-14
  • 打赏
  • 举报
回复
对对,我也是初学者,也想知道。例如说能不能把密码写入可执行文件(写自己)等等。
蝈蝈俊 2000-05-11
  • 打赏
  • 举报
回复
密码的任意变更???,变了你如何知道密码???如何可以进入???
xfchai 2000-05-11
  • 打赏
  • 举报
回复
我现在用是的从另外的文件中读入密码的方法(经过处理后存入此文件),如果变更了新的。也要写入此文件(当然要处理后的)把旧的覆盖掉。

不知道还有什么更好的方法,我这个显的笨了。你知道的话,告诉我。
supershan 2000-05-11
  • 打赏
  • 举报
回复
能说清楚点吗?象这样的程序很简单
国密即国家密码局认定的国产密码算法,即商用密码。国密算法是国家密码局制定标准的一系列算法。其中包括了对称密算法,椭圆曲线非对称密算法,杂凑算法。具体包括SM1,SM2,SM3等,其中:SM2为国家密码管理局公布的公钥算法,其密强度为256位。其它几个重要的商用密码算法包括:SM1,对称密算法,密强度为128位,采用硬件实现;SM3,密码杂凑算法,杂凑值长度为32字节,和SM2算法同期公布,参见《国家密码管理局公告(第 22 号)》;SMS4,对称密算法,随WAPI标准一起公布,可使用软件实现,密强度为128位。商用密码,是指能够实现商用密码算法的密、解密和认证等功能的技术。(包括密码算法编程技术和密码算法芯片、密卡等的实现技术)。商用密码技术是商用密码的核心,国家将商用密码技术列入国家秘密,任何单位和个人都有责任和义务保护商用密码技术的秘密。商用密码的应用领域十分广泛,主要用于对不涉及国家秘密内容但又具有敏感性的内部信息、行政事务信息、经济信息等进行密保护。比如:商用密码可用于企业门禁管理、企业内部的各类敏感信息的传输密、存储密,防止非法第三方获取信息内容;也可用于各种安全认证、网上银行、数字签名等。例如:在门禁应用中,采用SM1算法进行身份鉴别和数据密通讯,实现卡片合法性的验证,保证身份识别的真实性。 安全是关系国家、城市信息、行业用户、百姓利益的关键问题。国家密码管理局针对现有重要门禁系统建设和升级改造应用也提出指导意见,强芯片、卡片、系统的标准化建设。截止目前,国密门禁系统的升级的案例也逐渐增多,基于自主国产知识产权的CPU卡、CPU卡读写设备及密钥管理系统广泛受到关注。一些厂商如同方锐安在2009年推出CPU卡安全门禁系列产品,在2010年北京安博会上,该公司再次向业界展示出“御”系列CPU卡门禁系统、TF-DF6000系列安全门禁读卡器以及基于CPU卡技术的一卡通系统等主流产品和系统。这些厂商是全国推广的国密门禁产品的先驱者,使“御”系列CPU卡门禁系统广泛应用于政府、监狱、司法、军工企业和大型公共智能建筑等高安全领域。以太坊是互联网新时代的基础:内建货币与支付。用户拥有个人数据主权,且不会被各类应用监听或窃取数据。人人都有权使用开放金融系统。基于中立且开源的基础架构,不受任何组织或个人控制。以太坊主网于 2015 年上线,是世界头部的可编程区块链。和其它区块链一样,以太坊也拥有原生密货币,叫作 ether (ETH)。 ETH 是一种数字货币, 和比特币有许多相同的功能。 它是一种纯数字货币,可以即时发送给世界上任何地方的任何人。 ETH 的供应不受任何政府或组织控制,它是去中心化且具稀缺性的。 全世界的人们都在使用 ETH 进行支付,或将其作为价值存储和抵押品。但与其它区块链不同的是,以太坊可以做更多的工作。 以太坊是可编程的,开发者可以用它来构建不同于以往的应用程序。这些去中心化的应用程序(或称“dapps”)基于密货币与区块链技术, 因而值得信任,也就是说 dapps 一旦被“上传”到以太坊,它们将始终按照编好的程序运行。 这些应用程序可以控制数字资产,以便创造新的金融应用; 同时还是去中心化的,这意味着没有任何单一实体或个人可以控制它们。目前,全世界有成千上万名开发者正在以太坊上构建应用程序、发明新的应用程序,其中有许多现在已经可以使用:密货币钱包:让你可以使用 ETH 或其他数字资产进行低成本的即时支付金融应用程序:让你可以借贷、投资数字资产去中心化市场:让你可以交易数字资产,甚至就现实世界事件的“预测”进行交易游戏:你可以拥有游戏内的资产,甚至可以由此获得现实收益以及更多,更多。以太坊社区是世界上最大最活跃的区块链社区。它包括核心协议开发者、密经济研究员、密码朋克、挖矿组织、ETH 持有者、应用开发者、普通用户、无政府主义者、财富 500 强公司,以及现在的你。没有公司或中心化的组织能够控制以太坊。 一直以来,以太坊由多元化的全球性社区贡献者来协同进行维护和改善,社区成员耕耘于以太坊的方方面面,从核心协议到应用程序。 这个网站,就像以太坊的其他部分一样,是由一群人共同构建的,并将持续构建下去。本课程定制符合国家标准的以太坊。

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧