Created
November 19, 2020 07:54
-
-
Save tpmccallum/7e27290da4a5cb3769cba75bb583ac16 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var buffer_1 = new ArrayBuffer(1000000); | |
var buffer_2 = new ArrayBuffer(1000000); | |
var needle = new Uint8Array(buffer_1); | |
var haystack = new Uint8Array(buffer_2); | |
needle.fill(111) | |
haystack.fill(222) | |
needle_length = needle.length; | |
haystack_length = haystack.length; | |
needle_length_string = needle_length.toString(); | |
for (i = needle_length_string.length; i < 10; i++) { | |
needle_length_string = "0" + needle_length_string; | |
} | |
if (needle_length < 1 || needle_length > 9999999999 || needle_length > haystack_length) { | |
alert("The needle's length is not correct, must be between 1 and 9999999999"); | |
} else { | |
var base_array = needle_length_string.split(''); | |
for (i = 0; i < base_array.length; i++) base_array[i] = +base_array[i] | 0; | |
console.log(base_array); | |
} | |
var buffer_to_go = new ArrayBuffer(10 + needle_length + haystack_length); | |
var array_to_go = new Uint8Array(buffer_to_go); | |
array_to_go.set(base_array); | |
array_to_go.set(needle, 10); | |
array_to_go.set(haystack, 10 + needle_length); | |
var url = "https://rpc.ssvm.secondstate.io:8081/api/run/226/search_bytes_single_input"; | |
var xhr = new XMLHttpRequest(); | |
xhr.onreadystatechange = function() { | |
if (xhr.readyState === 4) { | |
console.log(xhr.response); | |
$('#resultII').html(xhr.response); | |
} | |
} | |
xhr.open('POST', url, true); | |
xhr.setRequestHeader("Content-Type", "application/octet-stream"); | |
xhr.send(buffer_to_go); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment