예제 #1
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);
        }
예제 #2
0
        private static Byte[] CreateScript()
        {
            var assembler     = new SacaraAssembler();
            var code          = @"
proc main
    push buffer     
    push buffer_length
    push key        
    push key_length
    push 4          
    push de_encrypt 
    call
    halt
endp

/*
This method accept: 
1 - the length of the password
2 - a pointer to the password to use
3 - the lengh of the buffer
4 - a pointer to the buffer
*/
proc de_encrypt
    pop key_length
    pop key
    pop buffer_length
    pop buffer
    push 0
    pop buffer_index
    push 0
    pop key_index
    push 0
    pop buffer_char
    push 0
    pop key_char

encryption_loop:
    /* read the character from the buffer */
    push buffer_index
    push buffer
    add
    nread
    pop buffer_char

    /* read the character from the key buffer */
    push key_index
    push key
    add
    nread
    pop key_char

    /* do XOR and save the result on the stack */
    push key_char
    push buffer_char
    xor

    /* write back the result */
    push buffer_index
    push buffer
    add
    nwrite

    /* increase counter */
    push 1
    push key_index
    add
    pop key_index

    push 1
    push buffer_index
    add
    pop buffer_index

    /* check if I have to round the password index */    
    push key_length
    push key_index
    cmp
    push check_for_completation
    jumpifl

round_key:
    push 0
    pop key_index
    
check_for_completation: 
    push buffer_length 
    push buffer_index   
    cmp
    push encryption_loop
    jumpifl

    ret
endp
            ";
            var assembledCode = assembler.Assemble(code);

            return(assembledCode.GetBuffer());
        }