Guest User

Untitled

a guest
Jul 14th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. #include "main.h"
  2.  
  3.  
  4. typedef void (*logprintf_t)(char* format, ...);
  5. logprintf_t logprintf;
  6.  
  7.  
  8. unsigned long base = 0x00;
  9.  
  10. bool GetMysqlInfos( char* host, char* username, char* password )
  11. {
  12. FILE* fichier = fopen( "mysql_config.ini", "r" );
  13.  
  14. if( fichier )
  15. {
  16. char buffer[ 2048 ] = "";
  17. int idx = 0, line_idx = 0;
  18. bool eof = false;
  19. while( fread( &buffer[ idx ], 1, 1, fichier ) == 1 || eof == false ) // ( buffer[ idx ] = (char)fgetc( fichier ) ) bug ...
  20. {
  21. if( buffer[ idx ] == '\n' || buffer[ idx ] == 0 )
  22. {
  23. if( buffer[ idx ] == 0 ) eof = true;
  24.  
  25. std::string str( &buffer[ line_idx ], &buffer[ idx ] );
  26. line_idx = idx + 1;
  27. /* traitement des données */
  28.  
  29. if( str.find( "hostname=" ) != -1 )
  30. {
  31. strcpy( host, str.substr( 9 ).c_str( ) );
  32. }
  33. else if( str.find( "username=" ) != -1 )
  34. {
  35. strcpy( username, str.substr( 9 ).c_str( ) );
  36. }
  37. else if( str.find( "password=" ) != -1 )
  38. {
  39. strcpy( password, str.substr( 9 ).c_str( ) );
  40. }
  41. }
  42.  
  43. idx++;
  44. }
  45. fclose( fichier );
  46. return true;
  47. }
  48. return false;
  49. }
  50.  
  51.  
  52. cell amxSampMysqlConnect( AMX* a_AmxInterface, cell a_Params[] )
  53. {
  54.  
  55. char host[ 128 ] = "", username[ 128 ] = "", pass[ 128 ] = "";
  56. if( GetMysqlInfos( host, username, pass ) == true )
  57. {
  58. logprintf( "mysql_config.ini opened." );
  59. logprintf( "hostname=%s\n", host );
  60. logprintf( "username=%s\n", username );
  61. logprintf( "password=%s\n", pass );
  62. }
  63. else
  64. {
  65. logprintf( "Unable to load \"mysql_config.ini" );
  66. return 0;
  67. }
  68.  
  69. if( a_Params[ 0 ] == 3 * 8 )
  70. {
  71.  
  72. amx_SetString( &a_Params[ 1 ], host, 0, 0, strlen( host ) );
  73. amx_SetString( &a_Params[ 2 ], host, 0, 0, strlen( username ) );
  74. amx_SetString( &a_Params[ 3 ], host, 0, 0, strlen( pass ) );
  75.  
  76. unsigned long samp_mysql_connect = base + 0x290A;
  77. cell ret = 0;
  78. __asm_volatile
  79. {
  80. push a_Params
  81. push a_AmxInterface
  82. call samp_mysql_connect
  83. mov ret, eax
  84. }
  85. return ret;
  86. }
  87. return 0;
  88. }
  89.  
  90.  
  91. PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports()
  92. {
  93. return SUPPORTS_VERSION | SUPPORTS_AMX_NATIVES;
  94. }
  95.  
  96. PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData)
  97. {
  98. pAMXFunctions = ppData[PLUGIN_DATA_AMX_EXPORTS];
  99. logprintf = (logprintf_t) ppData[PLUGIN_DATA_LOGPRINTF];
  100.  
  101.  
  102.  
  103. base = ( unsigned long )dlsym( dlopen( "sampmysqlsyg.so", RTLD_NOLOAD ), 0 );
  104. mprotect( (void*)( base + _REGISTER_OFF_SAMP_MYSQL_CONNECT ), 0x04, PROT_READ | PROT_WRITE | PROT_EXEC );
  105. *( unsigned long* )( base + REGISTER_OFF_SAMP_MYSQL_CONNECT ) = ( unsigned long) amxSampMysqlConnect;
  106.  
  107. return true;
  108. }
  109.  
  110. PLUGIN_EXPORT void PLUGIN_CALL Unload()
  111. {
  112.  
  113. }
  114.  
  115. PLUGIN_EXPORT int PLUGIN_CALL AmxLoad( AMX *amx )
  116. {
  117.  
  118. return -1;
  119. }
  120.  
  121.  
  122. PLUGIN_EXPORT int PLUGIN_CALL AmxUnload( AMX *amx )
  123. {
  124.  
  125.  
  126. return AMX_ERR_NONE;
  127. }
Add Comment
Please, Sign In to add comment