/** * call-seq: * RIS.decode_raw(img_path) => str * * decodes str from the image at img_path * * call-seq: * RIS.decode_raw(img_path1, img_path2) => str * * decodes str from the image at img_path1 using xor * with the image at img_path2 * * * decodes the whole image data without hiding extra data */ static VALUE ris_decode_raw(VALUE self, VALUE args) { if(RARRAY_LEN(args) > 2) rb_raise(rb_eArgError, "to many argumens: expected 1..2"); if(RARRAY_LEN(args) < 1) rb_raise(rb_eArgError, "to few argumens: expected 1..2"); VALUE path1 = rb_ary_entry(args, 0); if(TYPE(path1) != T_STRING) rb_raise(rb_eTypeError, "wrong Parameters: expected String"); const char *c_path1 = rb_string_value_ptr(&path1); Byte *str; u_int64_t len; if (RARRAY_LEN(args) == 1) { int errcode = decode_str_in_img(c_path1, &str, &len); if (errcode != 1) raise_ris_error(errcode); } else { VALUE path2 = rb_ary_entry(args, 2); if(TYPE(path2) != T_STRING) rb_raise(rb_eTypeError, "wrong Parameters: expected String"); const char *c_path2 = rb_string_value_ptr(&path2); int errcode = decode_xor_str_in_img(c_path1, c_path2, &str, &len); if (errcode != 1) raise_ris_error(errcode); } return rb_str_new((const char *) str, len); }
/* * Initializes a LanguageBreakdown. * * call-seq: * new<em>(language_name, code_string, comment_string, blank_counts)</em> * */ static VALUE _language_breakdown_initialize(int argc, VALUE* argv, VALUE self) { VALUE name; VALUE code; VALUE comment; VALUE blanks; rb_scan_args(argc, argv, "13", &name, &code, &comment, &blanks); /* validation */ Check_Type(name, T_STRING); if (!NIL_P(code)) { Check_Type(code, T_STRING); } if (!NIL_P(comment)) { Check_Type(comment, T_STRING); } if (!NIL_P(blanks)) { Check_Type(blanks, T_FIXNUM); } LanguageBreakdown *lb; Data_Get_Struct (self, LanguageBreakdown, lb); /* name */ strncpy(lb->name, rb_string_value_ptr(&name), MAX_LANGUAGE_NAME); /* code */ if (!NIL_P(code)) { if (lb->code != NULL) { free(lb->code); } lb->code = (char*)malloc(RSTRING(code)->len + 1); strcpy(lb->code, rb_string_value_ptr(&code)); } /* comment */ if (!NIL_P(comment)) { if (lb->comment != NULL) { free(lb->comment); } lb->comment = (char*)malloc(RSTRING(comment)->len + 1); strcpy(lb->comment, rb_string_value_ptr(&comment)); } /* blanks */ if (!NIL_P(blanks)) { lb->blank_count = NUM2INT(blanks); } return self; }
/** * call-seq: * RIS.encode_raw(img_path, str, xor) * * hides str in the image at img_path. * uses xor if xor == true * * hides onely the given string in the image without extra infomrtaion */ static VALUE ris_encode_raw(VALUE self, VALUE img_path, VALUE str, VALUE xor) { if(TYPE(img_path) != T_STRING || TYPE(str) != T_STRING || !(TYPE(xor) == T_TRUE || TYPE(xor) == T_FALSE)) rb_raise(rb_eTypeError, "wrong Parameters: expected String, String, true / false"); u_int32_t str_len = RSTRING_LEN(str); const char *c_img_path = rb_string_value_ptr(&img_path); Byte *c_str = (Byte *) rb_string_value_ptr(&str); if (TYPE(xor) == T_TRUE) { int errcode = encode_xor_str_in_img(c_img_path, c_str, str_len); if (errcode != 1) raise_ris_error(errcode); } else { int errcode = encode_str_in_img(c_img_path, c_str, str_len); if (errcode != 1) raise_ris_error(errcode); } return Qtrue; }
static char *rb_obj_as_string_protected(VALUE objval) { VALUE rval; int state = 0; rval = rb_protect( (VALUE (*)(VALUE))rb_obj_as_string, objval, &state); if (state != 0) { iroffer_ruby_errro(state); return NULL; } return rb_string_value_ptr(&rval); }
// ---------------------------------------------------------------------------- VALUE RubyClassHandler::Logit(VALUE self, VALUE stringToLog) // ---------------------------------------------------------------------------- {//Static called from Ruby // Called from Ruby // write a Ruby string to our testing log #if defined(LOGGING) //LOGIT( _T("RbuyClassHandler::logit called from Ruby") ); #endif #if defined(LOGGING) char* logStr = rb_string_value_ptr(&stringToLog); LOGIT( _T("%s"), logStr); #endif return true; }
struct fuse_args * rarray2fuseargs(VALUE rarray){ Check_Type(rarray, T_ARRAY); struct fuse_args *args = malloc(sizeof(struct fuse_args)); args->argc = RARRAY_LEN(rarray); args->argv = malloc((args->argc + 1) * sizeof(char *)); args->allocated = 1; int i; VALUE v; for(i = 0; i < args->argc; i++) { v = RARRAY_PTR(rarray)[i]; Check_Type(v, T_STRING); args->argv[i] = strdup(rb_string_value_ptr(&v)); //STR2CSTR(RSTRING(v)); } args->argv[args->argc] = NULL; return args; }
char *Ruby::Eval(char *value) { //Evaluate Ruby expression (protected) try { VALUE retval; char *c_retval; rb_eval_string("Thread.current[:nwnx_context] = true"); retval = rb_eval_string_protect(value, &nError); rb_eval_string("Thread.current[:nwnx_context] = false"); if(nError) { Log(0, "Error %d while evaluating a Ruby expression: %s\n", nError, value); return NULL; } if(retval!=Qnil) { retval = rb_funcall(retval, rb_intern("to_s"), 0); c_retval = rb_string_value_ptr(&retval); if(c_retval) { char *buf = (char *) malloc(strlen(c_retval)+1); strcpy(buf, c_retval); return buf; } } return NULL; } catch(...) { Log(0, "Caught a C++ exception while evaluating a Ruby expression: %s\n", value); return NULL; } /*else return RSTRING(rb_cvar_get(cNWScript, rb_intern(RUBY_RETVAL)))->ptr;*/ }
VALUE CRbWin32API::call(int argc, VALUE * argv, VALUE obj) { struct { u32 params[16]; } param; VALUE obj_proc = rb_iv_get(obj, "__proc__"); VALUE obj_import = rb_iv_get(obj, "__import__"); VALUE obj_export = rb_iv_get(obj, "__export__"); FARPROC ApiFunction = (FARPROC)rb_num2ulong(obj_proc); VALUE args; int items = rb_scan_args(argc, argv, "0*", &args); int nimport = RARRAY_LEN(obj_import); if (items != nimport) rb_raise(rb_eSinError, "wrong number of parameters: expected %d, got %d", nimport, items); for (int i = 0; i < nimport; ++i) { u32 lParam = 0; switch (FIX2INT(rb_ary_entry(obj_import, i))) { VALUE str; case _T_NUMBER: case _T_INTEGER: default: lParam = rb_num2ulong(rb_ary_entry(args, i)); break; case _T_POINTER: str = rb_ary_entry(args, i); if (NIL_P(str)) { lParam = 0; } else if (FIXNUM_P(str)) { lParam = rb_num2ulong(str); } else { rb_string_value(&str); rb_str_modify(str); lParam = (u32)rb_string_value_ptr(&str); } break; } param.params[i] = lParam; } u32 retval; __try { __asm { mov ebx, esp sub esp, 40h mov ecx, 10h lea esi, [param] mov edi, esp rep movs dword ptr es:[edi], dword ptr [esi] call dword ptr [ApiFunction] mov esp, ebx mov dword ptr [retval], eax } } __except(EXCEPTION_EXECUTE_HANDLER) { rb_raise(rb_eSinError, "Api Crashed..."); } switch (FIX2INT(obj_export)) { case _T_NUMBER: case _T_INTEGER: return rb_int2inum(retval); case _T_POINTER: return (retval ? rb_str_new2((char *)retval) : Qnil); case _T_VOID: default: return INT2FIX(0); } }