Skip to content

Commit

Permalink
(29.02.2020): Changes and additions.
Browse files Browse the repository at this point in the history
(29.02.2019)  82 files is different. Changed 45 files, added 37 files, 3 files was been deleted - in 14 folders.
See all changes in changes of Changes.txt
  • Loading branch information
username1565 authored Feb 29, 2020
1 parent a09383d commit 8f0edd8
Show file tree
Hide file tree
Showing 81 changed files with 23,471 additions and 1,130 deletions.
926 changes: 926 additions & 0 deletions Changes.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions download/created/temp_file_to_create_directory.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This temp file just need to create this empty directory. You can delete this file, if this will not be automatically deleted, in future.
1 change: 1 addition & 0 deletions download/generated/temp_file_to_create_directory.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This temp file just need to create this empty directory. You can delete this file, if this will not be automatically deleted, in future.
16 changes: 13 additions & 3 deletions nanodb.exe-source/Captcha/ByteStringExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,21 @@ public static string Stringify(this byte[] bytes)

public static byte[] Bytify(this string @string)
{
var bytes = new byte[@string.Length / 2];
//when database is corrupted and damaged,
//or when some text contains in the end of the post, after [sign=blahblah]some_text
string sign_value = @string.Split(']')[0]; //just cut signature [sign=blahblah], and working with signature only.
var bytes = new byte[sign_value.Length / 2];

for (int i = 0; i < @string.Length / 2; i++)
for (int i = 0; i < sign_value.Length / 2; i++)
{
bytes[i] = byte.Parse(@string[i * 2] + "" + @string[i * 2 + 1], System.Globalization.NumberStyles.HexNumber);
try{ //try
bytes[i] = byte.Parse(sign_value[i * 2] + "" + sign_value[i * 2 + 1], System.Globalization.NumberStyles.HexNumber);
//Sometimes System.Byte.Parse return incorrect value, when @string contains some text, after signature.
}
catch (Exception ex){ //or return some shit, as bytes.
Console.WriteLine(ex);
bytes[i] = 0; //add null byte, just to skip this step.
}
}

return bytes;
Expand Down
5 changes: 3 additions & 2 deletions nanodb.exe-source/Captcha/Captcha.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Captcha
public static string original_captcha_file_sha256_hash = "0732888283037E2B17FFF361EAB73BEC26F7D2505CDB98C83C80EC14B9680413";
public static string captcha_downloading_url = "http://some_url_to_download_captcha/"; //This value can be customized in config-3.json, without hardcoding this.

public static bool captcha_checked = false;
public static bool captcha_checked = false; public static bool bypassValidation = false;
public static bool IsCaptchaValid = false;
public static bool captcha_found = false;

Expand Down Expand Up @@ -194,7 +194,7 @@ private static string ToHex(byte[] bytes, bool upperCase)

public static bool verify_captcha_hash(){
_packFile = Configurator.Instance.GetValue("captcha_pack_file", captcha_file);
captcha_downloading_url = Configurator.Instance.GetValue("captcha_url", captcha_downloading_url);
captcha_downloading_url = Uri.UnescapeDataString(Configurator.Instance.GetValue("captcha_url", captcha_downloading_url));

string captcha_file_hash = "";
if(!File.Exists(_packFile)){
Expand Down Expand Up @@ -362,6 +362,7 @@ public static string AddPow(string post)
hash = ComputeHash(xpost + trash);
}

// Console.WriteLine("Catcha.cs. AddPow. trash: "+trash+", hash: "+BitConverter.ToString(hash).Replace("-", ""));
return post + trash;
}
}
Expand Down
4 changes: 2 additions & 2 deletions nanodb.exe-source/Captcha/PostSignatureExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public static string ExceptSignature(this string post)
public static byte[] Signature(this string post)
{
if (post.IndexOf("["+Captcha.SignatureTag+"=") == -1) return new byte[64];
var offset = post.LastIndexOf("["+Captcha.SignatureTag+"=") + ("["+Captcha.SignatureTag+"=").Length;
return post.Substring(offset).TrimEnd(']').Bytify();
int offset = post.LastIndexOf("["+Captcha.SignatureTag+"=") + ("["+Captcha.SignatureTag+"=").Length;
return ((byte[])((string)(post.Substring(offset).TrimEnd(']'))).Bytify());
}
}

Expand Down
5 changes: 4 additions & 1 deletion nanodb.exe-source/Database/FileUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ static class FileUtil
/* Appends bytes to the end of file */
public static int Append(string path, string @string)
{
return Append(path, System.Text.Encoding.UTF8.GetBytes(@string));
lock (_lock) //sometimes .db3 file busy by another process, when program try to append string there. lock it.
{
return Append(path, System.Text.Encoding.UTF8.GetBytes(@string));
}
}

/* Appends bytes to the end of file */
Expand Down
73 changes: 59 additions & 14 deletions nanodb.exe-source/Database/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ namespace NDB
/*
Post entity used by DB class and API handlers for read/write.
*/
public class Post
[System.Runtime.InteropServices.ComVisible(true)]
public interface ICloneable
{
object Clone(); //Need to Clone Ndb.Post (Post). See comment at line 95.
}

public class Post : ICloneable
{
#pragma warning disable 0649
[JsonProperty("hash")]
Expand All @@ -21,23 +27,51 @@ public class Post
public string replyto; //here //this
#pragma warning restore 0649

object _lock = new object(); //lock datetime_result
//from client 3.1
public DateTime date
{
get
get //get date and time from [g][/g] tag in the message of the post.
{
DateTime res;
try
{
res = Convert.ToDateTime(message.FromB64().Split(new string[] { "[g]" }, StringSplitOptions.None)[1].
Split(new string[] { ", client:" }, StringSplitOptions.None)[0]);

}
catch//(Exception e) //fix compile warning
{
res = new DateTime();
}
return res;
lock(_lock){ //_lock datetime_result value
DateTime datetime_result = new DateTime(); //new DateTime() == DateTime.Parse("01.01.0001 0:00:00")

string[] splitted =
message //get post message
.Replace("post_was_deleted", "") //remove "post_was_deleted", if this was been "deleted_once"
// .Replace("post_is_reported", "") //remove "post_is_reported", if this was been "reported"
.FromB64() //decode base64-encoded post-message to string
.Split( //split this string
new string[] { "[g]" }, //by "[g]"
StringSplitOptions.None
);
;

if(splitted.Length>1){ //if "[g]" was been found and splitted-array length > 1
splitted = splitted[1] //continue to split the second part splitted[1]
.Split( //split it
new string[] { ", client:" }, //by ", client: "
StringSplitOptions.None
);
}else{ //else if "[g]" not found
return datetime_result; //return default date-time
}

//[g]Mon, 11/Feb/2019, 20:35:20.535 (Europe/Helsinki), client: karasiq-nanoboard v1.3.2[/g]
if(splitted[0].Contains("(")){ //DateTime.TryParse("Mon, 11/Feb/2019, 20:35:20.535 (Europe/Helsinki)", out datetime_result); //not working
splitted = splitted[0].Split('('); //DateTime.TryParse("Mon, 11/Feb/2019, 20:35:20.535", out datetime_result); // return 11.02.2019 20:35:20 - working
}

try{
DateTime.TryParse(splitted[0], out datetime_result); //after all, in splitted[0] must to be DateTime.
//Try to parse this and save DateTime in datetime_result.
}
catch(Exception ex){
Console.WriteLine("Post.cs. date. Post hash: "+hash+", post message: "+message.Substring(0, 100)+", Exception: "+ex);
}

return datetime_result; //return parsed DateTime or just return default.
}
}
}

Expand All @@ -56,5 +90,16 @@ public Post(string r, string m)
message = m;
hash = HashCalculator.Calculate(r + m.FromB64());
}

/**
Need to clone Post,
because when
Post newPost = Post oldPost;
newPost.message += "post was deleted"+newPost.message; //oldPost.message changing too.
*/
public object Clone()
{
return this.MemberwiseClone(); //now, clonning is available by command: Post newPost = (NDB.Post)oldPost.Clone();
}
}
}
Loading

0 comments on commit 8f0edd8

Please sign in to comment.