Пример #1
0
        public static void VmDecrypt(Byte[] buffer, String password)
        {
            DropSacaraVm();

            // prepare variables in order to be passed to the VM code
            var key            = Encoding.Default.GetBytes(password);
            var passwordBuffer = Encoding.Default.GetBytes(password);
            var bufferPtr      = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            var keyPtr         = GCHandle.Alloc(key, GCHandleType.Pinned);

            // execute the encryption routine
            using (var vm = new SacaraVm())
            {
                var index = 0;
                vm.LocalVarSet(index++, bufferPtr.AddrOfPinnedObject().ToInt32());
                vm.LocalVarSet(index++, buffer.Length);
                vm.LocalVarSet(index++, keyPtr.AddrOfPinnedObject().ToInt32());
                vm.LocalVarSet(index++, key.Length);
                vm.Run(_deEncryptionCode);
            }
        }
Пример #2
0
        public static void Main(string[] args)
        {
            var code      = @"
proc main
    inc some_variable 
    byte 0x41, 0x41 /* this will generates an invalid instruction, raising an error */
    halt
endp
";
            var assembler = new SacaraAssembler();
            var vmCode    = assembler.Assemble(code);

            Console.WriteLine(vmCode);

            // run the buggy code
            using (var vm = new SacaraVm())
            {
                vm.SetErrorHandler(HandleError);
                vm.Run(vmCode);
            }

            Debug.Assert(_errorRaised);
        }