www.gusucode.com > 一些VC++加密算法+实例源码源码程序 > 一些VC++加密算法+实例源码/优化后的加密注册模块/优化后的加密注册模块/Inv(optimized)/AccessDB.cpp
//AccessDB.cpp #include "StdAfx.h" #include "AccessDB.h" #include "am_lv1.h" //*********************************************************** char * get_time(char * stat_time) { char * time = new char[9]; int j = 0; for(int i=0;i<8;i++) { if(i==2 || i==5) { j++; time[i] = ':'; } else { time[i] = stat_time[8+i-j]; } } time[8] = 0; return time; } //************************************************************ int gen_dbsql(db_ltable *in_table,char *db_name) { CDaoDatabase * batabase; //use DAO batabase = new CDaoDatabase; batabase->Open(db_name); //open a table if(batabase) { if(!batabase->IsOpen()) { AfxDaoTerm(); //release DAO Engine delete batabase; return E_DB_USE; } } batabase->Execute(_T((char *)in_table->sql_statement),dbFailOnError); //execute sql sentence batabase->Close(); //close the opened table AfxDaoTerm(); //release DAO Engine delete batabase; return DB_SUCCEED; } //*********************************************************** int insert(int id,void * stru) { const char subkey[]="SOFTWARE\\ARKO\\ARKOMASTER\\CONSOLE"; const char valuename[]="Confpath"; char db_fullname[260]; unsigned int cbsize=260; if(am_LocaConfFile(subkey, valuename, db_fullname, &cbsize)) return E_DB_REGPATH; strcat(db_fullname,"\\INVDB.mdb"); //get the path of Access db //insert manipulation distinguish from variant table id if(id == TABLE_INV_CPU) { insert_cpu((inv_cpu_ltab *)stru,db_fullname); return 0; } if(id == TABLE_INV_MEM) { insert_mem((inv_mem_ltab *)stru,db_fullname); return 0; } if(id == TABLE_INV_FS) { insert_fs((inv_fs_ltab *)stru,db_fullname); return 0; } if(id == TABLE_INV_OS) { insert_os((inv_os_ltab *)stru,db_fullname); return 0; } if(id == TABLE_INV_DEV) { insert_dev((inv_dev_ltab *)stru,db_fullname); return 0; } if(id == TABLE_INV_NET) { insert_net((inv_net_ltab *)stru,db_fullname); return 0; } if(id == TABLE_INV_STAT) { insert_stat((inv_stat_ltab *)stru,db_fullname); return 0; } if(id == TABLE_INV_NETSTAT) { insert_netstat((inv_netstat_ltab *)stru,db_fullname); return 0; } if(id == TABLE_INV_MAP) { insert_map((inv_map_ltab *)stru,db_fullname); return 0; } return E_DB_TABID; } //*********************************************************************** int insert_cpu(inv_cpu_ltab * result,char *db_name) { db_ltable in_table; in_table.db_table_id = DB_INV | TABLE_INV_CPU; in_table.encrypt_id = 0; in_table.db_operation = INSERT; sprintf((char *)in_table.sql_statement,"insert into INV_CPUTAB values (%ld,\"%s\",%d,\"%s\",%d)",result->endsystem_id,result->cpu_type,result->cpu_speed,result->cpu_manufacture,result->cpu_mmx_flag); int hRes = gen_dbsql(&in_table,db_name); return hRes; } int insert_mem(inv_mem_ltab * result,char *db_name) { db_ltable in_table; in_table.db_table_id = DB_INV | TABLE_INV_MEM; in_table.encrypt_id = 0; in_table.db_operation = INSERT; sprintf((char *)in_table.sql_statement,"insert into INV_MEMORYTAB values (%ld,%d,%d,%d)",result->endsystem_id,result->mem_physical_size,result->mem_virtual_size,result->mem_page_size); int hRes = gen_dbsql(&in_table,db_name); return hRes; } int insert_fs(inv_fs_ltab * result,char *db_name) { db_ltable in_table; in_table.db_table_id = DB_INV | TABLE_INV_FS; in_table.encrypt_id = 0; in_table.db_operation = INSERT; sprintf((char *)in_table.sql_statement,"insert into INV_FILETAB values (%ld,\"%s\",%d,%d,\"%s\",\"%s\")",result->endsystem_id,result->fs_type,result->fs_size,result->fs_surplus,result->fs_dev_name,result->fs_desc); int hRes = gen_dbsql(&in_table,db_name); return hRes; } int insert_os(inv_os_ltab * result,char *db_name) { db_ltable in_table; in_table.db_table_id = DB_INV | TABLE_INV_OS; in_table.encrypt_id = 0; in_table.db_operation = INSERT; sprintf((char *)in_table.sql_statement,"insert into INV_OSTAB values (%ld,\"%s\",\"%s\",\"%s\",\"%s\",\"%s\")",result->endsystem_id,result->os_type,result->os_ver,result->os_install_time,result->os_desc,result->os_install_path); int hRes = gen_dbsql(&in_table,db_name); return hRes; } int insert_dev(inv_dev_ltab * result,char *db_name) { db_ltable in_table; in_table.db_table_id = DB_INV | TABLE_INV_DEV; in_table.encrypt_id = 0; in_table.db_operation = INSERT; sprintf((char *)in_table.sql_statement,"insert into INV_DEVICETAB values (%ld,\"%s\",\"%s\",\"%s\",\"%s\",%d,%d,%d)",result->endsystem_id,result->dev_name,result->dev_manufacture,result->dev_model,result->dev_install_time,result->dev_status,result->dev_pnp_flag,result->dev_irq_no); int hRes = gen_dbsql(&in_table,db_name); return hRes; } int insert_net(inv_net_ltab * result,char *db_name) { db_ltable in_table; in_table.db_table_id = DB_INV | TABLE_INV_NET; in_table.encrypt_id = 0; in_table.db_operation = INSERT; sprintf((char *)in_table.sql_statement,"insert into INV_NETWORKTAB values (%ld,\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\")",result->endsystem_id,result->net_hostname,result->net_ip_addr,result->net_mask,result->net_cur_user,result->net_work_grp,result->net_domain ,result->net_mac_addr); int hRes = gen_dbsql(&in_table,db_name); return hRes; } int insert_stat(inv_stat_ltab * result,char *db_name) { db_ltable in_table; in_table.db_table_id = DB_INV | TABLE_INV_STAT; in_table.encrypt_id = 0; in_table.db_operation = INSERT; char * time; time = get_time(result->stat_time); sprintf((char *)in_table.sql_statement,"insert into INV_STATISTICSTAB values (%ld,\"%s\",\"%s\",%d,%f,%f,%f)",result->endsystem_id,result->stat_time,time,result->stat_proc_num,result->stat_cpu_rate,result->stat_mem_rate,result->stat_fs_rate); delete time; int hRes = gen_dbsql(&in_table,db_name); return hRes; } int insert_netstat(inv_netstat_ltab * result,char *db_name) { db_ltable in_table; in_table.db_table_id = DB_INV | TABLE_INV_NETSTAT; in_table.encrypt_id = 0; in_table.db_operation = INSERT; char * time; time = get_time(result->netstat_time); sprintf((char *)in_table.sql_statement,"insert into INV_NETSTATAB values (%ld,\"%s\",\"%s\",\"%s\",%u,%u,%u,%u,%u,%u,%u,\"%s\",\"%s\")",result->endsystem_id,result->netstat_ip_addr,result->netstat_mask,result->netstat_mac_addr,result->netstat_rcv_byte,result->netstat_send_byte,result->netstat_rcv_packet,result->netstat_send_packet,result->netstat_discard_packet,result->netstat_unknown_protocol,result->netstat_error_packet,result->netstat_time,time); delete time; int hRes = gen_dbsql(&in_table,db_name); return hRes; } int insert_map(inv_map_ltab * result,char *db_name) { db_ltable in_table; in_table.db_table_id = DB_INV | TABLE_INV_MAP; in_table.encrypt_id = 0; in_table.db_operation = INSERT; sprintf((char *)in_table.sql_statement,"insert into INV_MAPTAB values (%d,\"%s\",\"%s\",%d)",result->endsystem_id,result->map_ip_addr,result->map_hostname,result->map_available_flag); int hRes = gen_dbsql(&in_table,db_name); return hRes; } //***************************************************************************** int dele(int id) { const char subkey[]="SOFTWARE\\ARKO\\ARKOMASTER\\CONSOLE"; const char valuename[]="Confpath"; char db_fullname[260]; unsigned int cbsize=260; if(am_LocaConfFile(subkey, valuename, db_fullname, &cbsize)) return E_DB_REGPATH; strcat(db_fullname,"\\INVDB.mdb"); //get the path of Access db //delete manipulation, distinguish from variant table id if(id == TABLE_INV_CPU) { delete_cpu(db_fullname); return 0; } if(id == TABLE_INV_MEM) { delete_mem(db_fullname); return 0; } if(id == TABLE_INV_FS) { delete_fs(db_fullname); return 0; } if(id == TABLE_INV_OS) { delete_os(db_fullname); return 0; } if(id == TABLE_INV_DEV) { delete_dev(db_fullname); return 0; } if(id == TABLE_INV_NET) { delete_net(db_fullname); return 0; } if(id == TABLE_INV_STAT) { delete_stat(db_fullname); return 0; } if(id == TABLE_INV_NETSTAT) { delete_netstat(db_fullname); return 0; } if(id == TABLE_INV_MAP) { delete_map(db_fullname); return 0; } return E_DB_TABID; } //***************************************************************************** int delete_cpu(char *db_name) { db_ltable in_table; in_table.db_table_id = DB_INV | TABLE_INV_CPU; in_table.encrypt_id = 0; in_table.db_operation = DELET; sprintf((char *)in_table.sql_statement,"delete from INV_CPUTAB"); int hRes = gen_dbsql(&in_table,db_name); return hRes; } int delete_mem(char *db_name) { db_ltable in_table; in_table.db_table_id = DB_INV | TABLE_INV_MEM; in_table.encrypt_id = 0; in_table.db_operation = DELET; sprintf((char *)in_table.sql_statement,"delete from INV_MEMORYTAB"); int hRes = gen_dbsql(&in_table,db_name); return hRes; } int delete_fs(char *db_name) { db_ltable in_table; in_table.db_table_id = DB_INV | TABLE_INV_FS; in_table.encrypt_id = 0; in_table.db_operation = DELET; sprintf((char *)in_table.sql_statement,"delete from INV_FILETAB"); int hRes = gen_dbsql(&in_table,db_name); return hRes; } int delete_os(char *db_name) { db_ltable in_table; in_table.db_table_id = DB_INV | TABLE_INV_OS; in_table.encrypt_id = 0; in_table.db_operation = DELET; sprintf((char *)in_table.sql_statement,"delete from INV_OSTAB"); int hRes = gen_dbsql(&in_table,db_name); return hRes; } int delete_dev(char *db_name) { db_ltable in_table; in_table.db_table_id = DB_INV | TABLE_INV_DEV; in_table.encrypt_id = 0; in_table.db_operation = DELET; sprintf((char *)in_table.sql_statement,"delete from INV_DEVICETAB"); int hRes = gen_dbsql(&in_table,db_name); return hRes; } int delete_net(char *db_name) { db_ltable in_table; in_table.db_table_id = DB_INV | TABLE_INV_NET; in_table.encrypt_id = 0; in_table.db_operation = DELET; sprintf((char *)in_table.sql_statement,"delete from INV_NETWORKTAB"); int hRes = gen_dbsql(&in_table,db_name); return hRes; } int delete_stat(char *db_name) { db_ltable in_table; in_table.db_table_id = DB_INV | TABLE_INV_STAT; in_table.encrypt_id = 0; in_table.db_operation = DELET; sprintf((char *)in_table.sql_statement,"delete from INV_STATISTICSTAB"); int hRes = gen_dbsql(&in_table,db_name); return hRes; } int delete_netstat(char *db_name) { db_ltable in_table; in_table.db_table_id = DB_INV | TABLE_INV_NETSTAT; in_table.encrypt_id = 0; in_table.db_operation = DELET; sprintf((char *)in_table.sql_statement,"delete from INV_NETSTATAB"); int hRes = gen_dbsql(&in_table,db_name); return hRes; } int delete_map(char *db_name) { db_ltable in_table; in_table.db_table_id = DB_INV | TABLE_INV_MAP; in_table.encrypt_id = 0; in_table.db_operation = DELET; sprintf((char *)in_table.sql_statement,"delete from INV_MAPTAB"); int hRes = gen_dbsql(&in_table,db_name); return hRes; }