Sign a .NET Assembly with a Strong Name Without Recompiling

Signing a .NET assembly with a strong name is easy in Visual Studio. However, what if this is a 3rd party assembly and you don't have the source?

For me, I have an application that has a requirement that all assemblies are signed with a strong name. One of the assemblies I am using is RestSharp. I like to contribute to RestSharp and I didn't want to modify the project file to sign the assembly as I didn't want that to go back to the repository when I had some changes to contribute.

Not a problem. What I have is a batch file that disassembles the DLL to IL and then reassembles the IL back into a DLL and includes my key file. This way I get to keep the original DLL for projects that I don't need the assembly to have a strong name and a separate one that is signed with the strong name for the projects where I need that.

Here's what I did:
  1. In the Release build folder I created the following:
    • The key file (create using sn.exe -k MyPublicPrivateKeyFile.snk)
    • A subfolder to contain the signed assembly, mine is named "Signed"
    • A batch file (see below)
  2. Create a batch file in the Release folder named "SignAssembly.bat" with the following contents:
del .\Signed\RestSharp.* /F
"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\ildasm.exe" .\RestSharp.dll /out:.\Signed\RestSharp.il
"C:\Windows\Microsoft.NET\Framework\v2.0.50727\ilasm.exe" .\Signed\RestSharp.il /dll /key=.\RestSharp.snk /output=.\Signed\RestSharp.dll

pause
The first line deletes any previously signed assembly. Second line uses ILDASM to disassemble the DLL to IL in the "Signed" folder as RestSharp.il. The third line reassembles the IL into an assembly using ILASM and tells it to use the IL file and the key file. That's it.

Now, whenever I do a new release build, I just run the batch file and I have a signed copy to use, and I did it without changing the project file to do it.                   
### CH341A DKMS Driver Installation and Configuration For systems requiring the use of USB-to-serial converters, particularly those based on the CH340 or CH341 chipset like the CH341A, installing a compatible driver is essential to ensure proper functionality. The following details cover how one might go about setting up such drivers using DKMS (Dynamic Kernel Module Support), which allows for automatic rebuilding of kernel modules when new kernels are installed. #### Installing Dependencies Before proceeding with the installation of any third-party drivers including those for devices utilizing the CH341A chip, it's important that certain dependencies be present within the system environment. These typically involve development tools as well as headers specific to the Linux distribution being used. ```bash sudo apt-get update && sudo apt-get install -y build-essential linux-headers-$(uname -r) ``` #### Obtaining the CH341A Driver Source Code The source code necessary for building the CH341A driver can often be found through various repositories online; however, an official package from WCH (WinChipHead) may not always exist in all distributions' default software sources. One approach involves downloading precompiled binaries or fetching the latest version directly from GitHub projects dedicated to maintaining these drivers[^1]. Once obtained, extract the archive into a suitable directory before continuing further steps related to compilation and integration via DKMS. #### Setting Up DKMS Environment DKMS facilitates managing out-of-tree kernel modules by automatically recompiling them whenever there’s a change in the running kernel. To set this up specifically for the CH341A device: 1. Install `dkms` if not already available: ```bash sudo apt-get install dkms ``` 2. Copy the extracted folder containing the CH341A driver files into `/usr/src/ch341a-$version`, replacing `$version` appropriately according to what was downloaded earlier. 3. Create a configuration file named after your module inside `/etc/dkms/`. An example entry could look something like below but should match exactly whatever naming convention applies here: ```ini PACKAGE_NAME="ch341a" PACKAGE_VERSION="$version" CLEAN="" BUILT_MODULE_NAME[0]="ch341a" DEST_MODULE_LOCATION[0]="/kernel/drivers/usb/serial/" AUTOINSTALL=yes ``` 4. Add the newly created package information so DKMS recognizes it: ```bash sudo dkms add ch341a/$version ``` 5. Build and install the module against currently loaded kernel versions: ```bash sudo dkms build ch341a/$version sudo dkms install ch341a/$version ``` After completing above procedures successfully, verify whether the driver has been correctly registered under the active kernel space along with checking dmesg logs for confirmation messages regarding detection of connected hardware during boot time or upon plugging/unplugging actions performed later on. --related questions-- 1. What other methods besides DKMS can be utilized for loading custom USB serial converter drivers? 2. How does one troubleshoot issues encountered while trying to load the CH341A driver? 3. Is there support provided officially by manufacturers for newer generations of similar chips beyond CH341 series? 4. Can multiple different types of USB-to-UART bridges coexist without conflicts once their respective drivers have been properly configured?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值