mirror of
https://github.com/jakeswenson/BitBetter.git
synced 2023-10-10 13:36:57 +02:00
adding license gen
This commit is contained in:
parent
72b24aeecd
commit
5c58b0d8fd
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@ obj/
|
||||
*.dll
|
||||
*.pem
|
||||
.vscode/
|
||||
*.pfx
|
8
build.sh
8
build.sh
@ -1,5 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
mkdir ./src/bitbetter/.keys
|
||||
|
||||
cp .keys/cert.cert ./src/bitbetter/.keys
|
||||
|
||||
cd ./src/bitbetter
|
||||
|
||||
dotnet restore
|
||||
dotnet publish
|
||||
|
||||
docker build . -t bitbetter/api # --squash
|
||||
|
||||
|
BIN
src/bitBetter/.keys/cert.cert
Normal file
BIN
src/bitBetter/.keys/cert.cert
Normal file
Binary file not shown.
@ -1,7 +1,7 @@
|
||||
FROM bitwarden/api
|
||||
|
||||
COPY bin/Debug/netcoreapp2.0/publish/* /bitBetter/
|
||||
COPY cert.cert /newLicensing.cer
|
||||
COPY ./.keys/cert.cert /newLicensing.cer
|
||||
|
||||
RUN dotnet /bitBetter/bitBetter.dll && \
|
||||
echo "modified dll" && \
|
93
src/licenseGen/Program.cs
Normal file
93
src/licenseGen/Program.cs
Normal file
@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
using Mono.Cecil.Rocks;
|
||||
|
||||
namespace bitwardenSelfLicensor
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static int Main(string[] args)
|
||||
{
|
||||
string cerFile;
|
||||
string corePath;
|
||||
|
||||
if(args.Length >= 2) {
|
||||
cerFile = args[0];
|
||||
corePath = args[1];
|
||||
} else if (args.Length == 1) {
|
||||
cerFile = args[0];
|
||||
corePath = "/app/Core.dll";
|
||||
}
|
||||
else {
|
||||
cerFile = "/newLicensing.cer";
|
||||
corePath = "/app/Core.dll";
|
||||
}
|
||||
|
||||
|
||||
var module = ModuleDefinition.ReadModule(new MemoryStream(File.ReadAllBytes(corePath)));
|
||||
var cert = File.ReadAllBytes(cerFile);
|
||||
|
||||
var x = module.Resources.OfType<EmbeddedResource>()
|
||||
.Where(r => r.Name.Equals("Bit.Core.licensing.cer"))
|
||||
.First();
|
||||
|
||||
Console.WriteLine(x.Name);
|
||||
|
||||
var e = new EmbeddedResource("Bit.Core.licensing.cer", x.Attributes, cert);
|
||||
|
||||
module.Resources.Add(e);
|
||||
module.Resources.Remove(x);
|
||||
|
||||
var services = module.Types.Where(t => t.Namespace == "Bit.Core.Services");
|
||||
|
||||
|
||||
var type = services.First(t => t.Name == "LicensingService");
|
||||
|
||||
var licensingType = type.Resolve();
|
||||
|
||||
var existingCert = new X509Certificate2(x.GetResourceData());
|
||||
|
||||
Console.WriteLine($"Existing Cert Thumbprin: {existingCert.Thumbprint}");
|
||||
X509Certificate2 certificate = new X509Certificate2(cert);
|
||||
|
||||
Console.WriteLine($"New cert Thumbprint: {certificate.Thumbprint}");
|
||||
|
||||
var ctor = licensingType.GetConstructors().Single();
|
||||
|
||||
|
||||
var rewriter = ctor.Body.GetILProcessor();
|
||||
|
||||
var instToReplace =
|
||||
ctor.Body.Instructions.Where(i => i.OpCode == OpCodes.Ldstr
|
||||
&& string.Equals((string)i.Operand, existingCert.Thumbprint, StringComparison.InvariantCultureIgnoreCase))
|
||||
.FirstOrDefault();
|
||||
|
||||
if(instToReplace != null) {
|
||||
rewriter.Replace(instToReplace, Instruction.Create(OpCodes.Ldstr, certificate.Thumbprint));
|
||||
}
|
||||
else {
|
||||
Console.WriteLine("Cant find inst");
|
||||
}
|
||||
|
||||
// foreach (var inst in ctor.Body.Instructions)
|
||||
// {
|
||||
// Console.Write(inst.OpCode.Name + " " + inst.Operand?.GetType() + " = ");
|
||||
// if(inst.OpCode.FlowControl == FlowControl.Call) {
|
||||
// Console.WriteLine(inst.Operand);
|
||||
// }
|
||||
// else if(inst.OpCode == OpCodes.Ldstr) {
|
||||
// Console.WriteLine(inst.Operand);
|
||||
// }
|
||||
// else {Console.WriteLine();}
|
||||
// }
|
||||
|
||||
module.Write("modified.dll");
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
8
src/licenseGen/licenseGen.csproj
Normal file
8
src/licenseGen/licenseGen.csproj
Normal file
@ -0,0 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user