Code: Select all
uint8_t descramble(uint8_t s) {
uint8_t a = (s + 0xFF) & 0xFF;
uint8_t b = a ^ MAGIC;
uint8_t p := b & 0x7E | b >> 7 & 0x01 | b << 7 & 0x80;
return p; }
Can I do this on QuickBMS for a entire file (byte by byte)?
Code: Select all
uint8_t descramble(uint8_t s) {
uint8_t a = (s + 0xFF) & 0xFF;
uint8_t b = a ^ MAGIC;
uint8_t p := b & 0x7E | b >> 7 & 0x01 | b << 7 & 0x80;
return p; }
Code: Select all
xmath a "(s + 0xFF) & 0xFF"
xmath b "a ^ MAGIC"
xmath p "(b & 0x7E) | (b >> 7 & 0x01) | ((b << 7) & 0x80)"
Code: Select all
math s = 0x11223344
callfunction descramble 1
print "%p|x%"
startfunction descramble
xmath a "(s + 0xFF) & 0xFF"
xmath b "a ^ MAGIC"
xmath p "(b & 0x7E) | (b >> 7 & 0x01) | ((b << 7) & 0x80)"
endfunction
Code: Select all
for
get s BYTE
xmath a "(s + 0xFF) & 0xFF"
xmath b "a ^ MAGIC"
xmath p "(b & 0x7E) | (b >> 7 & 0x01) | ((b << 7) & 0x80)"
print "%p%"
next I
Code: Select all
## Descramble:
for
get s BYTE
xmath a "(s + 0xFF) & 0xFF"
xmath b "a ^ MAGIC"
xmath p "(b & 0x7E) | (b >> 7 & 0x01) | ((b << 7) & 0x80)"
DoSomeMagicToAppend %p% ContentsIntoATemporalMemoryToReprocessAgain
next I
## Now parse the descrambled data:
for
get TMP BYTE
print "Value: %TMP%"
next I
Code: Select all
get SIZE asize # size of the file
putvarchr MEMORY_FILE SIZE 0 # pre-allocation (unnecessary but it's faster)
log MEMORY_FILE 0 0 # reset the memory file
for OFFSET = 0 < SIZE
get s byte # read the byte
xmath b "(s + 0xFF) ^ MAGIC"
xmath p "(b & 0x7E) | (b >> 7 & 0x01) | ((b << 7) & 0x80)"
put p byte MEMORY_FILE # write the byte in the memory file
next OFFSET
log "dump.dat" 0 SIZE MEMORY_FILE # dump the memory file in dump.dat