# Requirements
## 1
有个软件想找同学修改

我需要破解一个C# 编写的软件

有偿调试  需求：
1.由原始exe文件逆向成功工程文件

2. 在工程文件的基础上可以二次开发，例如修改界面文字，颜色，增减功能等。 费用你报个数。  另外，可以与我的2个学生一起做省级优秀毕业论文设计团队，你负责这个软件开发，另外2个负责下位机硬件部分设计。 你们系里及指导老师那边我来沟通协调。


## 2
一般情况是这样 在同一台电脑上 先打开教师端
设置题库和比赛时间
然后再打开学生端 开始答题
串口用来向单片机发送数据 控制99个继电器
每次一个继电器断开
学生判断出来那个继电器断开 然后在图上的红色圆圈上面点击一下
再点击修复  
最后点击提交  计算机比较学生找的故障 和 原来设置的是否一致

另外学生可以自己设置故障  然后自己训练
我们需要做的就是在同一台计算机上完成这些工作
电脑主要是和下位机连接控制继电器的
所以每台电脑需要开教师端和学生端
如果学生自己出题自己做 就不要打开教师端
一般情况下 教师端都会打开 学生自己在教师端设置  因为那里面可以设置判断故障的时间

需要修改的是  界面颜色 界面上的一些字  ，风格上最好能修改一下 ，最终看上去是个新的软件，把目前不合理的地方修改了 ，用不到的修改掉
例如s700k 和zyj7   和zd6  这三套软件


## 3
里面的图纸我重新绘制一下  例如背景颜色用黑色  电路图也适当修改了

打开时开始是登陆界面 包括加密功能  
教师端和学生端整合起来 点击整个的界面选择
改名为：故障设置 和  训练考核  分别对应教师端  和 学生端

加密如果可能的话用专门的加密狗
通信协议部分不修改  
以保证新软件和被破解的软件之间的兼容性

大致要求就这些，你看看多少钱可以开发
代码可以随便改 界面与现有的一样稍有差异  只要能保证通信协议不变 能控制下位机设备  新老软件均可以跑即可。如果通信协议上有难度 直接推翻 重新设计也行  下位机反正是需要全新开发的


## 4
理论题库可以不做  因为不是做比赛设备  仅仅是为了训练学生的电路故障分析能力  以及配线导通速度  题库有很多软件  采用通用的题库软件 在新开发的里面加载估计就可以   价格你说吧 毕竟是脑力和体力劳动  


## ???
老师需要打开教师端设置故障点与答题时间出试卷
学生端打开领取试卷就可以处理故障点

如果是一个教室里很多台设备，就可以连接一台电脑，电脑打开教师端，设置题库，然后点开始比赛   连接的学生端设备打开学生端 就可以答题


# Complished
1.由原始exe文件逆向成功工程文件
2.项目合并


# Tech issues with solution
## All in all
If you feel confused when you read following content, read a book which named `Pro WPF 4.5 in C# Windows Presentation Foundation in .NET 4.5, 4 edition-APRESS (2013)`. It'll do you good.

## Decompile
1. use dnSpy
2. export VS2019 c# solution

## `Double defination for a class or xaml` error
```
Error	CS0260	Missing partial modifier on declaration of type 'theroyExamScoreMessageUC'; another partial declaration of this type exists	
```

When you go to `theroyExamScoreMessageUC.cs`, you'll see the whole class defination of `theroyExamScoreMessageUC` shouln't exist, because you already have `theroyExamScoreMessageUC.xaml` existed.

Every `**.xaml` file has a corresponding file which names `**.xaml.cs`. The `**.xaml` is the User Interface, the `**.xaml.cs` is the logic code or code-behind, code-behind controls the User Interface. That's basic idea of WPF.

So here, as I said, you should simply remove the extra useless `theroyExamScoreMessageUC.cs` file, because it's not binded with `theroyExamScoreMessageUC.xaml`. You can see that from its name `theroyExamScoreMessageUC.cs`, the right name should be `theroyExamScoreMessageUC.xaml.cs`.

After the deletion, you got two option: leave it alone or create a `theroyExamScoreMessageUC.xaml.cs` for him.

If you want to create a new file for him, the following code is useful:
```
using System.Windows.Controls;

namespace student_exam_client.MessageReminder.theroyExamScoreMessageUC
{
	public partial class theroyExamScoreMessageUC : UserControl
	{
		public theroyExamScoreMessageUC()
		{
			this.InitializeComponent();
		}
	}
}
```

## Missing a UI component when trying to use it in code or code-behind
```
Error	CS1061	'ComprehensiveKnowledgePg' does not contain a definition for 'theroyScoreBnt' and no accessible extension method 'theroyScoreBnt' accepting a first argument of type 'ComprehensiveKnowledgePg' could be found (are you missing a using directive or an assembly reference?)
```

Just go to the corrsponding UI xaml file, here, it is `ComprehensiveKnowledgePg.xaml`.

Then if you see anything similar with `scoreMessage:theroyExamScoreMessageUC`, I mean `*:*`, you do some changes for its propertys.

Here, it is to change it `Name=""` to `x:Name=""`.

We do this is because `*:*` is speicial. You can google `WPF xaml Using Types from Other Namespaces` to get more information.

Now, close your sulotion, then open it again. You should see those errors are gone.


## `double defination for a class or xaml` error, but `**.cs` have a lot of codes which is very important

As I said, thoese codes are important, you shouldn't delete it directly. What should you do?

1. Looking for code like follows, delte that part of codes:
```
		// Token: 0x0600017C RID: 380 RVA: 0x00015F18 File Offset: 0x00014118
		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Uri resourceLocater = new Uri("/teacher_exam_server;component/basicinformation/teacherbasicinfmanagementuc.xaml", UriKind.Relative);
			Application.LoadComponent(this, resourceLocater);
		}

		// Token: 0x0600017D RID: 381 RVA: 0x00015F48 File Offset: 0x00014148
		[DebuggerNonUserCode]
		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		[EditorBrowsable(EditorBrowsableState.Never)]
		void IComponentConnector.Connect(int connectionId, object target)
		{
			switch (connectionId)
			{
			case 1:
				this.groupBox1 = (GroupBox)target;
				return;
			case 2:
				this.passwordlabel = (Label)target;
				return;
			case 3:
				this.loginNamelabel = (Label)target;
				return;
			case 4:
				this.loginNametextBox = (TextBox)target;
				return;
			case 5:
				this.passwordBox = (PasswordBox)target;
				return;
			case 6:
				this.studentInflistView = (ListView)target;
				this.studentInflistView.SelectionChanged += this.studentInflistView_SelectionChanged;
				return;
			case 7:
				this.loginNameGridView = (GridViewColumn)target;
				return;
			case 8:
				this.passwordGridView = (GridViewColumn)target;
				return;
			case 9:
				this.loginTimeGridView = (GridViewColumn)target;
				return;
			case 10:
				this.groupBox = (GroupBox)target;
				return;
			case 11:
				this.AddBnt = (Button)target;
				this.AddBnt.Click += this.AddBnt_Click;
				return;
			case 12:
				this.DelBnt = (Button)target;
				this.DelBnt.Click += this.DelBnt_Click;
				return;
			default:
				this._contentLoaded = true;
				return;
			}
		}
``` 
Yous should notice that it is `[generated code]`, it wasn't suppose to exist in source code. The VS2019 will generate it automatically when you compile your project.

2. Looking for code like follows, delte that part of codes:
```
		// Token: 0x040002FD RID: 765
		internal GroupBox groupBox1;

		// Token: 0x040002FE RID: 766
		internal Label passwordlabel;

		// Token: 0x040002FF RID: 767
		internal Label loginNamelabel;

		// Token: 0x04000300 RID: 768
		internal TextBox loginNametextBox;

		// Token: 0x04000301 RID: 769
		internal PasswordBox passwordBox;

		// Token: 0x04000302 RID: 770
		internal ListView studentInflistView;

		// Token: 0x04000303 RID: 771
		internal GridViewColumn loginNameGridView;

		// Token: 0x04000304 RID: 772
		internal GridViewColumn passwordGridView;

		// Token: 0x04000305 RID: 773
		internal GridViewColumn loginTimeGridView;

		// Token: 0x04000306 RID: 774
		internal GroupBox groupBox;

		// Token: 0x04000307 RID: 775
		internal Button AddBnt;

		// Token: 0x04000308 RID: 776
		internal Button DelBnt;

		// Token: 0x04000309 RID: 777
		private bool _contentLoaded;
```
Why would we do this? It's because the xaml file already defined those UI component for you, and when you run your program, that UI component will be dumpped to your c# class automatically, you don't have to define it by yourself.

## Add all projects into one solution
1. Right click your solution -> Add -> Existing Project
2. Select your project `*.csproj` file
3. Right click other projects -> Change `Output type` to `Class Library` -> remember its `Assembly name` and `Default namespace`, you'll use it later if you want to use that project from your main project
4. Add reference to other projects: Right click the main project -> Add -> Reference -> Select All -> Click OK
5. Exclude other project's `App.xaml` file
6. Merge different project's `app.config` file togather at main project
7. Merge different project's `app.manifest` file togather at main project

## Use other project `xaml` or window from your main project in one solution
1. I supporse you got a main project, it has a basic `MainWindow.xaml` and `MainWindow.xaml.cs`. `cs` means `c sharp` by the way.
2. Call a windown from another project is simple, you just have to use `new assemblyName.MainWindow()`, like following:
```
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            student_exam_client.MainWindow mw = new student_exam_client.MainWindow();
            mw.Show(); //Not necessary, because the window will show up autmatically sometimes
        }
    }
```
`student_exam_client` is an Assembly Name or Namespace.
3. Get an `xaml` is much complex:
```
            Uri uri = new Uri("pack://application:,,,/student_exam_client;component/MainWindow.xaml", UriKind.Absolute);
            Application.LoadComponent(this, uri);
```
`student_exam_client` is an Assembly Name here. The common rule is `pack://application:,,,/assemblyname;component/foldername_if_you_have/*.xaml`

## Image won't load when using that window from another project
Check the `*.xaml` file, see a property of `Source` under a tag of `Image`?
Change the source from `/pic/s700k_c.jpg` to `/student_exam_client;component/pic/s700k_c.jpg`, where `student_exam_client` is the `Assembly Name`.
Now it should be able to load that image without any problem.

## Missing .dll file
Right click your project -> Add reference -> Brower(select your *.dll file) -> OK


## Make the window to be in the center of our screen
```
public MainWindow()
{
    this.InitializeComponent();
    base.WindowStartupLocation = WindowStartupLocation.CenterScreen;
}
```
