您的位置:首页 > 编程语言 > C#

c#实现的破解程序--针对软件使用时间限制

2011-12-22 22:09 801 查看
自己捣腾了一天,弄了一个修改软件过期的小程序,主要是自己有几款有时间限制的软件,每次改时间很麻烦。有了这个程序就可以一劳永逸了。

前提:只适用于修改操作系统时间后,程序就能够正常使用的那种软件。如Lingoes,reflector,这两款我测试是可以的。

在Win7下必需用管理员的方式启动。

思路很简单:

1,修改操作系统时间到软件过期前。

2,启动软件。

3,改回操作系统时间。

程序类似于网上的一款好像叫RunAsDate的软件,没用过,只大概记得它的界面,决定自己实现类似的功能。

该程序的亮点是

1,可以生成破解程序的快捷方式到桌面上,生成的快捷方式图标和原来的程序一样(有轻度的失真),生成这个快捷方式后,就不用这个破解程序了,这个才是我要的一劳永逸的东西。

2,对原来的程序exe文件做了备份,避免因破解不成功,软件自身因过期启动自我销毁的情况。如:Refletor就是其中一例。

先看一张程序界面图:



基本操作:

破解启动:界面功能很简单,一看就会用。有效时间一般不知道有效时间,不要指定。选中待破解的程序路径,点“破解启动”按钮,就可以启动程序,但是这种方式只能单次启动,也就是每次都要启动这个破解程序。

快捷方式生成:在“破解启动”成功的前提下,生成的快捷方式才可用。这种方式可以一劳永逸的生成桌面图标,下次也不用启动这个破解程序了。

下面这两个是生成的快捷方式图标:



快捷方式名称栏,可以输入名称来生成快捷方式。

如下图:



点快捷方式生成后:



不错,以后我就可以在桌面上直接启动这些过期的软件了。

下面贴出主要的代码程序:

Win32API

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace ApplicationActive
{
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME
{
public ushort wYear;
public ushort wMonth;
public ushort wDayOfWeek;
public ushort wDay;
public ushort wHour;
public ushort wMinute;
public ushort wSecond;
public ushort wMilliseconds;

public void FromDateTime(DateTime dateTime)
{
wYear = (ushort)dateTime.Year;
wMonth = (ushort)dateTime.Month;
wDayOfWeek = (ushort)dateTime.DayOfWeek;
wDay = (ushort)dateTime.Day;
wHour = (ushort)dateTime.Hour;
wMinute = (ushort)dateTime.Minute;
wSecond = (ushort)dateTime.Second;
wMilliseconds = (ushort)dateTime.Millisecond;
}

public DateTime ToDateTime()
{
return new DateTime(wYear, wMonth, wDay, wHour, wMinute, wSecond);
}
}

[Flags]
enum SHGFI : int
{
/// <summary>get icon</summary>
Icon = 0x000000100,
/// <summary>get display name</summary>
DisplayName = 0x000000200,
/// <summary>get type name</summary>
TypeName = 0x000000400,
/// <summary>get attributes</summary>
Attributes = 0x000000800,
/// <summary>get icon location</summary>
IconLocation = 0x000001000,
/// <summary>return exe type</summary>
ExeType = 0x000002000,
/// <summary>get system icon index</summary>
SysIconIndex = 0x000004000,
/// <summary>put a link overlay on icon</summary>
LinkOverlay = 0x000008000,
/// <summary>show icon in selected state</summary>
Selected = 0x000010000,
/// <summary>get only specified attributes</summary>
Attr_Specified = 0x000020000,
/// <summary>get large icon</summary>
LargeIcon = 0x000000000,
/// <summary>get small icon</summary>
SmallIcon = 0x000000001,
/// <summary>get open icon</summary>
OpenIcon = 0x000000002,
/// <summary>get shell size icon</summary>
ShellIconSize = 0x000000004,
/// <summary>pszPath is a pidl</summary>
PIDL = 0x000000008,
/// <summary>use passed dwFileAttribute</summary>
UseFileAttributes = 0x000000010,
/// <summary>apply the appropriate overlays</summary>
AddOverlays = 0x000000020,
/// <summary>Get the index of the overlay in the upper 8 bits of the iIcon</summary>
OverlayIndex = 0x000000040,
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct SHFILEINFO
{
public SHFILEINFO(bool b)
{
hIcon = IntPtr.Zero;
iIcon = 0;
dwAttributes = 0;
szDisplayName = "";
szTypeName = "";
}
public IntPtr hIcon;
public int iIcon;
public uint dwAttributes;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szDisplayName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
public string szTypeName;
};

class Win32API
{
[DllImport("user32.dll", EntryPoint = "FindWindow")]
public static extern IntPtr FindWindows(string lpClassName, string lpWindowName);
[DllImport("kernel32.dll")]
public static extern bool SetLocalTime(ref SYSTEMTIME Time);
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
public static extern int SHGetFileInfo(
string pszPath,
int dwFileAttributes,
out    SHFILEINFO psfi,
uint cbfileInfo,
SHGFI uFlags);

}
}


创建图标,备份,启动用的共通类

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text;
using System.Drawing;
using System.Runtime.InteropServices;
using IWshRuntimeLibrary;
using System.IO;
using System.Diagnostics;

namespace ApplicationActive
{
class CommonFunction
{
public enum StartMode
{
WinForm,
ShortCut
}
public static readonly string CRACK_FOLDER_NAME = "xsw_Crack";
public static readonly string CONFIG_NAME = "xsw_Crack.xml";
public static StartMode Mode = StartMode.WinForm;

private static Icon GetIcon(string strPath, bool bSmall)
{
SHFILEINFO info = new SHFILEINFO(true);
int cbFileInfo = Marshal.SizeOf(info);
SHGFI flags;
if (bSmall)
flags = SHGFI.Icon | SHGFI.SmallIcon | SHGFI.UseFileAttributes;
else
flags = SHGFI.Icon | SHGFI.LargeIcon;

Win32API.SHGetFileInfo(strPath, 256, out info, (uint)cbFileInfo, flags);
return Icon.FromHandle(info.hIcon);
}

public static string GetCrackFolderPath(string strPath)
{
string dirName = Path.GetDirectoryName(strPath);
dirName += "\\" + CRACK_FOLDER_NAME;
if (!Directory.Exists(dirName))
{
Directory.CreateDirectory(dirName);
}
return dirName;
}

public static void CreateShortCut(string strPath, string shortcutName)
{
string shortcutPath;
string shortcutIconLocation;
string crackFolder;

crackFolder = GetCrackFolderPath(strPath);
shortcutPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + shortcutName + ".lnk";
shortcutIconLocation = crackFolder + "\\" + shortcutName + ".ico";

//create Icon
Icon shortcutIcon = GetIcon(strPath, false);
FileStream fs = new FileStream(shortcutIconLocation, FileMode.OpenOrCreate, FileAccess.Write);
shortcutIcon.Save(fs);
fs.Close();

//copy crack program file
string crackFileName = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).Name;
if (!System.IO.File.Exists(crackFolder + "\\" + crackFileName))
{
System.IO.File.Copy(System.Reflection.Assembly.GetExecutingAssembly().Location, crackFolder + "\\" + crackFileName, true);
}
System.IO.File.Copy(Application.StartupPath + "\\" + CommonFunction.CONFIG_NAME, crackFolder + "\\" + CommonFunction.CONFIG_NAME,true);
BackupTargetFile(strPath);

WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutPath);
shortcut.Arguments = "\"" + strPath + "\"";
shortcut.TargetPath = crackFolder + "\\" + crackFileName;
shortcut.WorkingDirectory = crackFolder;
shortcut.WindowStyle = 1; //normal
shortcut.IconLocation = shortcutIconLocation;
shortcut.Save();
}

public static void BackupTargetFile(string strPath)
{
string strFileTo = GetCrackFolderPath(strPath) +"\\" + new FileInfo(strPath).Name;
if (!System.IO.File.Exists(strFileTo))
{
System.IO.File.Copy(strPath, strFileTo);
}
}

public static void StartProgram(string path, DateTime? settingDate)
{
System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
DateTime NowDate = DateTime.Now;
stopWatch.Start();

//back up EXE file
BackupTargetFile(path);
FileInfo fileInfo = new System.IO.FileInfo(path);
DateTime validDateTime = fileInfo.CreationTime > fileInfo.LastWriteTime ? fileInfo.LastWriteTime : fileInfo.CreationTime;

if (settingDate.HasValue)
{
validDateTime = settingDate.Value;
}

//update date
SYSTEMTIME st = new SYSTEMTIME();
st.FromDateTime(validDateTime);
Win32API.SetLocalTime(ref st);
System.Threading.Thread.Sleep(1000);
try
{
//start program
ProcessStartInfo PstartInfoExe = new ProcessStartInfo();
PstartInfoExe.FileName = path;
PstartInfoExe.WindowStyle = ProcessWindowStyle.Minimized;
PstartInfoExe.UseShellExecute = false;
Process p = new Process();
p.StartInfo = PstartInfoExe;
p.Start();
p.WaitForInputIdle(10000);
System.Threading.Thread.Sleep(2000);

if (CommonFunction.Mode == StartMode.WinForm)
{
ConfigManager.GetInstance().FilePath = path;
if (settingDate.HasValue)
{
ConfigManager.GetInstance().ExpireDate = validDateTime;
}
ConfigManager.GetInstance().Save();
}
}
catch
{
}
finally
{
//update to old date
stopWatch.Stop();
NowDate.Add(stopWatch.Elapsed);
st.FromDateTime(NowDate);
Win32API.SetLocalTime(ref st);
}
}
}
}


xml保存用

using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Xml;

namespace ApplicationActive
{
class ConfigManager
{
private static ConfigManager instance = null;

public static ConfigManager GetInstance()
{
if (instance == null)
instance = new ConfigManager();
return instance;
}

private DateTime? _expireDate = null;
public DateTime? ExpireDate
{
get { return _expireDate; }
set { _expireDate = value; }
}

private string _filePath  = string.Empty;
public string FilePath
{
get { return _filePath; }
set { _filePath = value; }
}

private ConfigManager()
{
GetXml();
}

public void Save()
{
string xmlPath = Application.StartupPath + "\\" + CommonFunction.CONFIG_NAME;
if (this._filePath == string.Empty)
{
return;
}

XmlWriter xmlWriter = XmlWriter.Create(xmlPath);
xmlWriter.WriteStartElement("Root");
xmlWriter.WriteElementString("ExePath", _filePath);
if (_expireDate.HasValue)
{
xmlWriter.WriteElementString("ExpireDate", this._expireDate.Value.ToString("yyyy/MM/dd HH:mm:ss"));
}
xmlWriter.WriteEndElement();
xmlWriter.Close();
}

public void GetXml()
{
string xmlPath = Application.StartupPath + "\\" + CommonFunction.CONFIG_NAME; ;
if (!System.IO.File.Exists(xmlPath))
{
return;
}
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlPath);
XmlNode xmlNode = xmlDoc.SelectSingleNode("Root");

for (int i = 0; i < xmlNode.ChildNodes.Count; i++)
{
if (xmlNode.ChildNodes[i].Name == "ExePath")
{
this._filePath = xmlNode.ChildNodes[i].InnerText;
}
if (xmlNode.ChildNodes[i].Name == "ExpireDate")
{
try
{
this._expireDate = Convert.ToDateTime(xmlNode.ChildNodes[i].InnerText);
}
catch
{
}
}
}
}
}
}


Form 类

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Xml;
using System.Runtime.InteropServices;
using IWshRuntimeLibrary;

namespace ApplicationActive
{
public partial class FrmSetting : Form
{
public FrmSetting()
{

InitializeComponent();
}

private void FrmSetting_Load(object sender, EventArgs e)
{
if (ConfigManager.GetInstance().FilePath != string.Empty)
{
this.tbx_pgmPath.Text = ConfigManager.GetInstance().FilePath;
}
if (ConfigManager.GetInstance().ExpireDate.HasValue)
{
this.chkExpire.Checked = true;
this.dtpExpireDate.Value = ConfigManager.GetInstance().ExpireDate.Value;
}
}

private void btnFile_Click(object sender, EventArgs e)
{
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Filter = "file (*.exe)|*.exe";
if (fileDialog.ShowDialog() == DialogResult.OK)
{
this.tbx_pgmPath.Text = fileDialog.FileName;
}
}

private void btn_startPgm_Click(object sender, EventArgs e)
{
if (InputCheck() == false)
return;

if (this.dtpExpireDate.Enabled)
{

CommonFunction.StartProgram(this.tbx_pgmPath.Text, this.dtpExpireDate.Value);
}
else
{
CommonFunction.StartProgram(this.tbx_pgmPath.Text, null);
}
}

private void btn_CreateIcon_Click(object sender, EventArgs e)
{
if (InputCheck() == false)
return;

string shortcutName = "";
if (this.tbx_IconName.Text == string.Empty)
{
shortcutName = new System.IO.FileInfo(this.tbx_pgmPath.Text).Name.Substring(0, new System.IO.FileInfo(this.tbx_pgmPath.Text).Name.Length - 4);
}
else
{
shortcutName = this.tbx_IconName.Text;
}
try
{
CommonFunction.CreateShortCut(this.tbx_pgmPath.Text, shortcutName);
MessageBox.Show("生成成功!",this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch
{
MessageBox.Show("生成失败!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}

}

private void chkExpire_CheckedChanged(object sender, EventArgs e)
{
if (chkExpire.Checked)
{
this.dtpExpireDate.Enabled = true;
}
else
{
this.dtpExpireDate.Enabled = false;
}
}

private void btn_Close_Click(object sender, EventArgs e)
{
this.Close();
}

private bool InputCheck()
{
string filePath = this.tbx_pgmPath.Text;
if (filePath == "")
{
MessageBox.Show("file is not seleted.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false ;
}
if (!System.IO.File.Exists(filePath))
{

string backupFile = System.IO.Path.GetDirectoryName(filePath) + "\\" + CommonFunction.CRACK_FOLDER_NAME + "\\" + filePath.Substring(filePath.LastIndexOf("\\") + 1);
if (System.IO.File.Exists(backupFile))
{
try
{
System.IO.File.Copy(backupFile, filePath);
}
catch
{
MessageBox.Show("file is not found!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
return false ;
}
}
else
{
MessageBox.Show("file is not found!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
return false ;
}

}
return true;
}
}
}


program类

using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace ApplicationActive
{
static class Program
{
/// <summary>
/// アプリケーションのメイン エントリ ポイントです。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

ConfigManager.GetInstance().GetXml();
if (args.Length > 0)
{
CommonFunction.Mode = CommonFunction.StartMode.ShortCut;
string filePath = args[0];
if (!System.IO.File.Exists(filePath))
{
string backupFile = System.IO.Path.GetDirectoryName(filePath) + "\\" + CommonFunction.CRACK_FOLDER_NAME + "\\" + filePath.Substring(filePath.LastIndexOf("\\") + 1);
if (System.IO.File.Exists(backupFile))
{
try
{
System.IO.File.Copy(backupFile, filePath);
}
catch
{
MessageBox.Show("file:<" + filePath + ">" + " not found!", "error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
else
{
MessageBox.Show("file:<" + filePath + ">" + " not found!", "error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
CommonFunction.StartProgram(filePath, ConfigManager.GetInstance().ExpireDate);
}
else
{
CommonFunction.Mode = CommonFunction.StartMode.WinForm;
Application.Run(new FrmSetting());
}
}
}
}


以上程序是用vs2005,在xp环境下编译的,在win7上转化成vs2008后发现不能正常运行,其原因是win7的UAC账户控制,必需要以管理员的方式启动才能运行,于是在vs2008中加入一个app.manifest文件,配置修改如下:

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC 清单选项
如果希望更改 Windows 用户帐户控制级别,请用以下节点之一替换
requestedExecutionLevel 节点。

<requestedExecutionLevel  level="asInvoker" uiAccess="false" />
<requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

如果您希望利用文件和注册表虚拟化提供
向后兼容性,请删除 requestedExecutionLevel 节点。
-->
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
</asmv1:assembly>


关键是这句:<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

重新编译后在Win7下就能正常运行了。

转载请注明出处:http://blog.csdn.net/xiashengwang/article/details/7096715
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: