Compare commits
No commits in common. "696ab2ce279f6d431ee170a1a980eeaa5306231b" and "fd45b5c54fe4cc9f0149fd6a6d020143309414fb" have entirely different histories.
696ab2ce27
...
fd45b5c54f
@ -1,130 +0,0 @@
|
|||||||
def datastrlen:
|
|
||||||
###############
|
|
||||||
# r0 = offset of str in data
|
|
||||||
# retval (r0) = strlen
|
|
||||||
###############
|
|
||||||
push r1
|
|
||||||
push r2
|
|
||||||
push r3
|
|
||||||
movr s2, r0
|
|
||||||
movi s1, 0
|
|
||||||
lodr s0, s2
|
|
||||||
cmpb s0, 0
|
|
||||||
jpei exit
|
|
||||||
loop:
|
|
||||||
movi s2, 0
|
|
||||||
addi s1, 1
|
|
||||||
addr s2, s1
|
|
||||||
lodr s0, s2
|
|
||||||
cmpb s0, 0
|
|
||||||
debg
|
|
||||||
jpni loop
|
|
||||||
exit:
|
|
||||||
movr r0, s1
|
|
||||||
poop r3
|
|
||||||
poop r2
|
|
||||||
poop r1
|
|
||||||
retn
|
|
||||||
|
|
||||||
def round: # round(uint16_t text[2])
|
|
||||||
#################
|
|
||||||
# r0 = offset of text[0] in data
|
|
||||||
# r1 = offset of text[1] in data
|
|
||||||
# r2 = text[0]
|
|
||||||
# r3 = text[1]
|
|
||||||
# retval = void
|
|
||||||
################
|
|
||||||
push r1
|
|
||||||
push r2
|
|
||||||
push r3
|
|
||||||
lodr r2, r0 # text[0]
|
|
||||||
lodr r3, r1 # text[1]
|
|
||||||
movi s0, 0 # i
|
|
||||||
movi s1, 0 # sum
|
|
||||||
loop:
|
|
||||||
push s0 # saving i
|
|
||||||
addi s1, 0x626f # sum += delta
|
|
||||||
push s1 # saving sum
|
|
||||||
# s0 and s1 will be used as tmps
|
|
||||||
#########
|
|
||||||
# calc v0
|
|
||||||
#########
|
|
||||||
movr s0, r3
|
|
||||||
shli s0, 4
|
|
||||||
addi s0, 0x7065 # s0 = (text[1] << 4) + k0
|
|
||||||
movr s1, r3
|
|
||||||
poop s3 # restoring sum in s3
|
|
||||||
addr s1, s3 # s1 = text[1] + sum
|
|
||||||
push s3 # saving sum again
|
|
||||||
xorr s0, s1 # s0 = ((text[1] << 4) + k0) ^ (text[1] + sum)
|
|
||||||
push s0
|
|
||||||
movr s0, r3
|
|
||||||
shri s0, 5
|
|
||||||
addi s0, 0x7065 # s0 = (text[1] >> 5) + k1
|
|
||||||
poop s1
|
|
||||||
xorr s0, s1 # s0 = ((text[1] << 4) + k0) ^ (text[1] + sum) ^ ((text[1] >> 5) + k1)
|
|
||||||
addr r2, s0 # r2 += s0
|
|
||||||
#########
|
|
||||||
# calc v1
|
|
||||||
#########
|
|
||||||
movr s0, r2
|
|
||||||
shli s0, 4
|
|
||||||
addi s0, 0x7275 # s0 = (text[0] << 4) + k2
|
|
||||||
movr s1, r2
|
|
||||||
poop s3 # restoring sum in s3
|
|
||||||
addr s1, s3 # s1 = text[0] + sum
|
|
||||||
push s3 # saving sum again
|
|
||||||
xorr s0, s1 # s0 = ((text[0] << 4) + k2) ^ (text[0] + sum)
|
|
||||||
push s0
|
|
||||||
movr s0, r2
|
|
||||||
shri s0, 5
|
|
||||||
addi s0, 0x6e73 # s0 = (text[0] >> 5) + k3
|
|
||||||
poop s1
|
|
||||||
xorr s0, s1 # s0 = ((text[0] << 4) + k2) ^ (text[0] + sum) ^ ((text[0] >> 5) + k3)
|
|
||||||
addr r3, s0 # r3 += s0
|
|
||||||
######
|
|
||||||
# end loop
|
|
||||||
#####
|
|
||||||
poop s1 # restoring sum
|
|
||||||
poop s0 # restoring i
|
|
||||||
addi s0, 1
|
|
||||||
cmpb s0, 127 # while (i < 128)
|
|
||||||
jpbi loop
|
|
||||||
# saving the values
|
|
||||||
strr r0, r2
|
|
||||||
strr r1, r3
|
|
||||||
poop r3
|
|
||||||
poop r2
|
|
||||||
poop r1
|
|
||||||
retn
|
|
||||||
|
|
||||||
def main:
|
|
||||||
movi r0, 0xadde
|
|
||||||
movi r1, 0x0bb0
|
|
||||||
stri 0, r0
|
|
||||||
stri 2, r1
|
|
||||||
movi r0, 0x0bb0
|
|
||||||
movi r1, 0xcefa
|
|
||||||
stri 0x4, r0
|
|
||||||
stri 0x6, r1
|
|
||||||
movi r0, 0
|
|
||||||
call datastrlen
|
|
||||||
movr r2, r0
|
|
||||||
movi s0, 0
|
|
||||||
encrypt:
|
|
||||||
push s0
|
|
||||||
movi r0, 0
|
|
||||||
movi r1, 2
|
|
||||||
addr r0, s0
|
|
||||||
addr r1, s0
|
|
||||||
call round
|
|
||||||
poop s0
|
|
||||||
addi s0, 1
|
|
||||||
cmpr s0, r2
|
|
||||||
jpbi encrypt
|
|
||||||
lodi r0, 0
|
|
||||||
lodi r1, 2
|
|
||||||
lodi r2, 4
|
|
||||||
lodi r3, 6
|
|
||||||
debg
|
|
||||||
shit
|
|
@ -24,7 +24,6 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
bytecode = new uint8_t[bytecode_size];
|
bytecode = new uint8_t[bytecode_size];
|
||||||
bytecode_if.read((char *)bytecode, bytecode_size);
|
bytecode_if.read((char *)bytecode, bytecode_size);
|
||||||
printf("SIZE READ: %d\n", bytecode_size);
|
|
||||||
VM vm((uint8_t *)argv[1], bytecode, bytecode_size);
|
VM vm((uint8_t *)argv[1], bytecode, bytecode_size);
|
||||||
vm.run();
|
vm.run();
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -54,7 +54,7 @@ bool VMAddrSpace::allocate(void) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VMAddrSpace::insCode(uint8_t *buf, uint32_t size) {
|
bool VMAddrSpace::insCode(uint8_t *buf, uint8_t size) {
|
||||||
if (code) {
|
if (code) {
|
||||||
DBG_INFO(("Copying buffer into code section.\n"));
|
DBG_INFO(("Copying buffer into code section.\n"));
|
||||||
memcpy(code, buf, size);
|
memcpy(code, buf, size);
|
||||||
@ -65,7 +65,7 @@ bool VMAddrSpace::insCode(uint8_t *buf, uint32_t size) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VMAddrSpace::insStack(uint8_t *buf, uint32_t size) {
|
bool VMAddrSpace::insStack(uint8_t *buf, uint8_t size) {
|
||||||
if (stack) {
|
if (stack) {
|
||||||
DBG_INFO(("Copying buffer into stack section.\n"));
|
DBG_INFO(("Copying buffer into stack section.\n"));
|
||||||
memcpy(stack, buf, size);
|
memcpy(stack, buf, size);
|
||||||
@ -76,7 +76,7 @@ bool VMAddrSpace::insStack(uint8_t *buf, uint32_t size) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VMAddrSpace::insData(uint8_t *buf, uint32_t size) {
|
bool VMAddrSpace::insData(uint8_t *buf, uint8_t size) {
|
||||||
if (this->code) {
|
if (this->code) {
|
||||||
DBG_INFO(("Copying buffer into data section.\n"));
|
DBG_INFO(("Copying buffer into data section.\n"));
|
||||||
memcpy(data, buf, size);
|
memcpy(data, buf, size);
|
||||||
|
@ -14,9 +14,9 @@ public:
|
|||||||
VMAddrSpace(uint32_t ss, uint32_t cs, uint32_t ds);
|
VMAddrSpace(uint32_t ss, uint32_t cs, uint32_t ds);
|
||||||
uint8_t *stack, *code, *data;
|
uint8_t *stack, *code, *data;
|
||||||
bool allocate(void);
|
bool allocate(void);
|
||||||
bool insStack(uint8_t *buf, uint32_t size);
|
bool insStack(uint8_t *buf, uint8_t size);
|
||||||
bool insCode(uint8_t *buf, uint32_t size);
|
bool insCode(uint8_t *buf, uint8_t size);
|
||||||
bool insData(uint8_t *buf, uint32_t size);
|
bool insData(uint8_t *buf, uint8_t size);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue
Block a user