Baseline: Ausgangszustand vor Modularisierung

Erster Commit des bestehenden monolithischen WinForms-Copytraders,
inklusive der Alt-Backups (*.bak), damit diese dauerhaft in der
Historie rekonstruierbar bleiben. Threema-Lib unter libs/ wurde
vendored (nested .git entfernt).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
bergm
2026-07-01 13:16:16 +02:00
co-authored by Claude Opus 4.8
commit 475d396f80
147 changed files with 25455 additions and 0 deletions
@@ -0,0 +1,101 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IcgSoftware.Threema.CoreMsgApi.Messages
{
class DeliveryReceipt : ThreemaMessage
{
public const int TYPE_CODE = 0x80;
public enum Type
{
RECEIVED = 1,
READ = 2,
USER_ACK = 3
}
private readonly Type receiptType;
private readonly List<MessageId> ackedMessageIds;
public DeliveryReceipt(Type receiptType, List<MessageId> ackedMessageIds) {
this.receiptType = receiptType;
this.ackedMessageIds = ackedMessageIds;
}
public Type ReceiptType
{
get { return receiptType; }
}
public List<MessageId> AckedMessageIds
{
get { return ackedMessageIds; }
}
public override int GetTypeCode() {
return TYPE_CODE;
}
public override byte[] GetData()
{
//Not implemented yet
return new byte[0];
}
public override string ToString()
{
StringBuilder sb = new StringBuilder("Delivery receipt (");
sb.Append(receiptType);
sb.Append("): ");
int i = 0;
ackedMessageIds.ForEach(messageId =>
{
if (i != 0)
{
sb.Append(", ");
}
sb.Append(messageId);
i++;
});
return sb.ToString();
}
/**
* A delivery receipt type. The following types are defined:
*
* <ul>
* <li>RECEIVED: the message has been received and decrypted on the recipient's device</li>
* <li>READ: the message has been shown to the user in the chat view
* (note that this status can be disabled)</li>
* <li>USER_ACK: the user has explicitly acknowledged the message (usually by
* long-pressing it and choosing the "acknowledge" option)</li>
* </ul>
*/
/*
public enum Type {
RECEIVED(1), READ(2), USER_ACK(3);
private final int code;
Type(int code) {
this.code = code;
}
public int getCode() {
return code;
}
public static Type get(int code) {
for (Type t : values()) {
if (t.code == code)
return t;
}
return null;
}
}
*/
}
}
@@ -0,0 +1,147 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IcgSoftware.Threema.CoreMsgApi.Exceptions;
namespace IcgSoftware.Threema.CoreMsgApi.Messages
{
class FileMessage : ThreemaMessage
{
public const int TYPE_CODE = 0x17;
private const string KEY_BLOB_ID = "b";
private const string KEY_THUMBNAIL_BLOB_ID = "t";
private const string KEY_ENCRYPTION_KEY = "k";
private const string KEY_MIME_TYPE = "m";
private const string KEY_FILE_NAME = "n";
private const string KEY_FILE_SIZE = "s";
private const string KEY_TYPE = "i";
private readonly byte[] blobId;
private readonly byte[] encryptionKey;
private readonly string mimeType;
private readonly string fileName;
private readonly int fileSize;
private readonly byte[] thumbnailBlobId;
public FileMessage(byte[] blobId, byte[] encryptionKey, String mimeType, String fileName, int fileSize, byte[] thumbnailBlobId)
{
this.blobId = blobId;
this.encryptionKey = encryptionKey;
this.mimeType = mimeType;
this.fileName = fileName;
this.fileSize = fileSize;
this.thumbnailBlobId = thumbnailBlobId;
}
public byte[] BlobId
{
get { return this.blobId; }
}
public byte[] EncryptionKey
{
get { return this.encryptionKey; }
}
public string MimeType
{
get { return this.mimeType; }
}
public string FileName
{
get { return this.fileName; }
}
public int FileSize
{
get { return this.fileSize; }
}
public byte[] ThumbnailBlobId
{
get { return this.thumbnailBlobId; }
}
public override int GetTypeCode()
{
return TYPE_CODE;
}
public override string ToString()
{
return string.Format("file message {0}", this.fileName);
}
public override byte[] GetData()
{
JObject jo = new JObject();
try
{
jo.Add(KEY_BLOB_ID, JToken.FromObject(DataUtils.ByteArrayToHexString(this.blobId)));
if (this.thumbnailBlobId != null)
{
jo.Add(KEY_THUMBNAIL_BLOB_ID, JToken.FromObject(DataUtils.ByteArrayToHexString(this.thumbnailBlobId)));
}
jo.Add(KEY_ENCRYPTION_KEY, JToken.FromObject(DataUtils.ByteArrayToHexString(this.encryptionKey)));
jo.Add(KEY_MIME_TYPE, JToken.FromObject(this.mimeType));
jo.Add(KEY_FILE_NAME, JToken.FromObject(this.fileName));
jo.Add(KEY_FILE_SIZE, JToken.FromObject(this.fileSize));
jo.Add(KEY_TYPE, JToken.FromObject(0));
}
catch (Exception)
{
throw new BadMessageException();
}
return Encoding.UTF8.GetBytes(jo.ToString());
}
public static FileMessage FromString(string json)
{
try
{
JObject jo = JObject.Parse(json);
byte[] encryptionKey = DataUtils.HexStringToByteArray(jo[KEY_ENCRYPTION_KEY].Value<string>());
string mimeType = jo[KEY_MIME_TYPE].Value<string>();
int fileSize = jo[KEY_FILE_SIZE].Value<int>();
byte[] blobId = DataUtils.HexStringToByteArray(jo[KEY_BLOB_ID].Value<string>());
string fileName;
byte[] thumbnailBlobId = null;
//optional field
if (jo.Children().Any(e => e.Path.EndsWith(KEY_THUMBNAIL_BLOB_ID)))
{
thumbnailBlobId = DataUtils.HexStringToByteArray(jo[KEY_THUMBNAIL_BLOB_ID].Value<string>());
}
if (jo.Children().Any(e => e.Path.EndsWith(KEY_FILE_NAME)))
{
fileName = jo[KEY_FILE_NAME].Value<string>();
}
else
{
fileName = "unnamed";
}
return new FileMessage(
blobId,
encryptionKey,
mimeType,
fileName,
fileSize,
thumbnailBlobId
);
}
catch
{
throw new BadMessageException();
}
}
}
}
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IcgSoftware.Threema.CoreMsgApi.Messages
{
class ImageMessage : ThreemaMessage
{
public const int TYPE_CODE = 0x02;
private readonly byte[] blobId;
private readonly int size;
private readonly byte[] nonce;
public ImageMessage(byte[] blobId, int size, byte[] nonce)
{
this.blobId = blobId;
this.size = size;
this.nonce = nonce;
}
public byte[] BlobId
{
get { return this.blobId; }
}
public int Size
{
get { return this.size; }
}
public byte[] Nonce
{
get { return this.nonce; }
}
public override int GetTypeCode()
{
return TYPE_CODE;
}
public override byte[] GetData()
{
byte[] data = new byte[BLOB_ID_LEN + 4 + ThreemaMessage.NONCEBYTES];
int pos = 0;
//System.arraycopy(this.blobId, 0, data, pos, BLOB_ID_LEN);
this.blobId.CopyTo(data, 0);
pos += BLOB_ID_LEN;
//EndianUtils.writeSwappedInteger(data, pos, this.size);
byte[] size = BitConverter.GetBytes(this.size);
size.CopyTo(data, pos);
pos += 4;
//System.arraycopy(this.nonce, 0, data, pos, ThreemaMessage.NONCEBYTES);
this.nonce.CopyTo(data, pos);
return data;
}
public override string ToString()
{
return string.Format("blob {0}", DataUtils.ByteArrayToHexString(this.blobId));
}
}
}
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IcgSoftware.Threema.CoreMsgApi.Messages
{
/// <summary>
/// A text message that can be sent/received with end-to-end encryption via Threema.
/// </summary>
public class TextMessage : ThreemaMessage
{
public const int TYPE_CODE = 0x01;
private readonly string text;
public TextMessage(String text)
{
this.text = text;
}
public string Text { get { return text; } }
public override int GetTypeCode() {
return TYPE_CODE;
}
public override byte[] GetData()
{
return Encoding.UTF8.GetBytes(text);
}
public override string ToString()
{
return text;
}
}
}
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IcgSoftware.Threema.CoreMsgApi.Messages
{
/// <summary>
/// Abstract base class of messages that can be sent with end-to-end encryption via Threema.
/// </summary>
public abstract class ThreemaMessage
{
public const int NONCEBYTES = 24;
public const int BLOB_ID_LEN = 16;
/// <summary>
/// Get message's raw content
/// </summary>
/// <returns></returns>
public abstract byte[] GetData();
/// <summary>
/// Get message's type code
/// </summary>
/// <returns></returns>
public abstract int GetTypeCode();
}
}