/** Parse a color for a component. */ int ParseColor(const char *value, XColor *c) { unsigned long rgb; if(JUNLIKELY(!value)) { return 0; } if(value[0] == '#' && strlen(value) == 7) { rgb = ReadHex(value + 1); c->red = ((rgb >> 16) & 0xFF) * 257; c->green = ((rgb >> 8) & 0xFF) * 257; c->blue = (rgb & 0xFF) * 257; c->flags = DoRed | DoGreen | DoBlue; GetColor(c); } else {
int main( void ) { unsigned long long inlen; int result = 0; FILE *fp_in; char marker[20]; int refLen; #ifdef cKeccakFixedOutputLengthInBytes refLen = cKeccakFixedOutputLengthInBytes; #else refLen = cKeccakR_SizeInBytes; #endif printf( "Testing Keccak[r=%u, c=%u] against %s over %d squeezed bytes\n", cKeccakR, cKeccakB - cKeccakR, testVectorFile, refLen ); if ( (fp_in = fopen(testVectorFile, "r")) == NULL ) { printf("Couldn't open <%s> for read\n", testVectorFile); return 1; } for ( inlen = 0; inlen <= cKeccakMaxMessageSizeInBytes; ++inlen ) { sprintf( marker, "Len = %u", inlen * 8 ); if ( !FindMarker(fp_in, marker) ) { printf("ERROR: no test vector found (%u bytes)\n", inlen ); result = 1; break; } if ( !ReadHex(fp_in, input, (int)inlen, "Msg = ") ) { printf("ERROR: unable to read 'Msg' (%u bytes)\n", inlen ); result = 1; break; } result = crypto_hash( output, input, inlen ); if ( result != 0 ) { printf("ERROR: crypto_hash() (%u bytes)\n", inlen); result = 1; break; } #ifdef cKeccakFixedOutputLengthInBytes if ( !ReadHex(fp_in, input, refLen, "MD = ") ) #else if ( !ReadHex(fp_in, input, refLen, "Squeezed = ") ) #endif { printf("ERROR: unable to read 'Squeezed/MD' (%u bytes)\n", inlen ); result = 1; break; } if ( memcmp( output, input, refLen ) != 0) { printf("ERROR: hash verification (%u bytes)\n", inlen ); for(result=0; result<refLen; result++) printf("%02X ", output[result]); printf("\n"); result = 1; break; } } fclose( fp_in ); if ( !result ) printf( "\nSuccess!\n"); //printf( "\nPress a key ..."); //getchar(); //printf( "\n"); return ( result ); }
int main(int argc, char **argv) { BEGIN_TEST(); EXPECT_SUCCESS(setenv("S2N_ENABLE_CLIENT_MODE", "1", 0)); /* Part 1 setup a client and server connection with everything they need for a key exchange */ struct s2n_connection *client_conn, *server_conn; EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT)); EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER)); struct s2n_config *server_config, *client_config; client_config = s2n_fetch_unsafe_client_testing_config(); GUARD(s2n_connection_set_config(client_conn, client_config)); /* Part 1.1 setup server's keypair and the give the client the certificate */ char *cert_chain; char *private_key; char *client_chain; EXPECT_NOT_NULL(cert_chain = malloc(S2N_MAX_TEST_PEM_SIZE)); EXPECT_NOT_NULL(private_key = malloc(S2N_MAX_TEST_PEM_SIZE)); EXPECT_NOT_NULL(client_chain = malloc(S2N_MAX_TEST_PEM_SIZE)); EXPECT_NOT_NULL(server_config = s2n_config_new()); EXPECT_SUCCESS(s2n_read_test_pem(S2N_RSA_2048_PKCS1_CERT_CHAIN, cert_chain, S2N_MAX_TEST_PEM_SIZE)); EXPECT_SUCCESS(s2n_read_test_pem(S2N_RSA_2048_PKCS1_KEY, private_key, S2N_MAX_TEST_PEM_SIZE)); EXPECT_SUCCESS(s2n_read_test_pem(S2N_RSA_2048_PKCS1_LEAF_CERT, client_chain, S2N_MAX_TEST_PEM_SIZE)); struct s2n_cert_chain_and_key *chain_and_key; EXPECT_NOT_NULL(chain_and_key = s2n_cert_chain_and_key_new()); EXPECT_SUCCESS(s2n_cert_chain_and_key_load_pem(chain_and_key, cert_chain, private_key)); EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, chain_and_key)); EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config)); GUARD(s2n_set_signature_hash_pair_from_preference_list(server_conn, &server_conn->handshake_params.client_sig_hash_algs, &server_conn->secure.conn_hash_alg, &server_conn->secure.conn_sig_alg)); DEFER_CLEANUP(struct s2n_stuffer certificate_in = {{0}}, s2n_stuffer_free); EXPECT_SUCCESS(s2n_stuffer_alloc(&certificate_in, S2N_MAX_TEST_PEM_SIZE)); DEFER_CLEANUP(struct s2n_stuffer certificate_out = {{0}}, s2n_stuffer_free); EXPECT_SUCCESS(s2n_stuffer_alloc(&certificate_out, S2N_MAX_TEST_PEM_SIZE)); struct s2n_blob temp_blob; temp_blob.data = (uint8_t *) client_chain; temp_blob.size = strlen(client_chain) + 1; EXPECT_SUCCESS(s2n_stuffer_write(&certificate_in, &temp_blob)); EXPECT_SUCCESS(s2n_stuffer_certificate_from_pem(&certificate_in, &certificate_out)); temp_blob.size = s2n_stuffer_data_available(&certificate_out); temp_blob.data = s2n_stuffer_raw_read(&certificate_out, temp_blob.size); s2n_cert_type cert_type; EXPECT_SUCCESS(s2n_asn1der_to_public_key_and_type(&client_conn->secure.server_public_key, &cert_type, &temp_blob)); server_conn->handshake_params.our_chain_and_key = chain_and_key; EXPECT_SUCCESS(setup_connection(server_conn)); EXPECT_SUCCESS(setup_connection(client_conn)); #if S2N_LIBCRYPTO_SUPPORTS_CUSTOM_RAND /* Read the seed from the RSP_FILE and create the DRBG for the test. Since the seed is the same (and prediction * resistance is off) all calls to generate random data will return the same sequence. Thus the server always * generates the same ECDHE point and KEM public key, the client does the same. */ FILE *kat_file = fopen(RSP_FILE_NAME, "r"); EXPECT_NOT_NULL(kat_file); EXPECT_SUCCESS(s2n_alloc(&kat_entropy_blob, 48)); EXPECT_SUCCESS(ReadHex(kat_file, kat_entropy_blob.data, 48, "seed = ")); struct s2n_drbg drbg = {.entropy_generator = &s2n_entropy_generator}; s2n_stack_blob(personalization_string, 32, 32); EXPECT_SUCCESS(s2n_drbg_instantiate(&drbg, &personalization_string, S2N_DANGEROUS_AES_256_CTR_NO_DF_NO_PR)); EXPECT_SUCCESS(s2n_set_private_drbg_for_test(drbg)); #endif /* Part 2 server sends key first */ EXPECT_SUCCESS(s2n_server_key_send(server_conn)); /* Part 2.1 verify the results as best we can */ EXPECT_EQUAL(server_conn->handshake.io.write_cursor, SERVER_KEY_MESSAGE_LENGTH); struct s2n_blob server_key_message = {.size = SERVER_KEY_MESSAGE_LENGTH, .data = s2n_stuffer_raw_read(&server_conn->handshake.io, SERVER_KEY_MESSAGE_LENGTH)}; #if S2N_LIBCRYPTO_SUPPORTS_CUSTOM_RAND /* Part 2.1.1 if we're running in known answer mode check the server's key exchange message matches the expected value */ uint8_t expected_server_key_message[SERVER_KEY_MESSAGE_LENGTH]; EXPECT_SUCCESS(ReadHex(kat_file, expected_server_key_message, SERVER_KEY_MESSAGE_LENGTH, "expected_server_key_exchange = ")); EXPECT_BYTEARRAY_EQUAL(expected_server_key_message, server_key_message.data, SERVER_KEY_MESSAGE_LENGTH); #endif /* Part 2.2 copy server's message to the client's stuffer */ s2n_stuffer_write(&client_conn->handshake.io, &server_key_message); /* Part 3 client recvs the server's key and sends the client key exchange message */ EXPECT_SUCCESS(s2n_server_key_recv(client_conn)); EXPECT_SUCCESS(s2n_client_key_send(client_conn)); /* Part 3.1 verify the results as best we can */ EXPECT_EQUAL(client_conn->handshake.io.write_cursor - client_conn->handshake.io.read_cursor, CLIENT_KEY_MESSAGE_LENGTH); struct s2n_blob client_key_message = {.size = CLIENT_KEY_MESSAGE_LENGTH, .data = s2n_stuffer_raw_read(&client_conn->handshake.io, CLIENT_KEY_MESSAGE_LENGTH)}; #if S2N_LIBCRYPTO_SUPPORTS_CUSTOM_RAND /* Part 3.1.1 if we're running in known answer mode check the client's key exchange message matches the expected value */ uint8_t expected_client_key_message[CLIENT_KEY_MESSAGE_LENGTH]; EXPECT_SUCCESS(ReadHex(kat_file, expected_client_key_message, CLIENT_KEY_MESSAGE_LENGTH, "expected_client_key_exchange = ")); EXPECT_BYTEARRAY_EQUAL(expected_client_key_message, client_key_message.data, CLIENT_KEY_MESSAGE_LENGTH); #endif /* Part 3.2 copy the client's message back to the server's stuffer */ s2n_stuffer_write(&server_conn->handshake.io, &client_key_message); /* Part 4 server receives the client's message */ EXPECT_SUCCESS(s2n_client_key_recv(server_conn)); /* Part 4.1 verify results as best we can, the client and server should at least have the same master secret */ EXPECT_BYTEARRAY_EQUAL(server_conn->secure.master_secret, client_conn->secure.master_secret, S2N_TLS_SECRET_LEN); #if S2N_LIBCRYPTO_SUPPORTS_CUSTOM_RAND /* Part 4.1.1 if we're running in known answer mode check that both the client and server got the expected master secret * from the RSP_FILE */ uint8_t expected_master_secret[S2N_TLS_SECRET_LEN]; EXPECT_SUCCESS(ReadHex(kat_file, expected_master_secret, S2N_TLS_SECRET_LEN, "expected_master_secret = ")); EXPECT_BYTEARRAY_EQUAL(expected_master_secret, client_conn->secure.master_secret, S2N_TLS_SECRET_LEN); EXPECT_BYTEARRAY_EQUAL(expected_master_secret, server_conn->secure.master_secret, S2N_TLS_SECRET_LEN); #endif EXPECT_SUCCESS(s2n_cert_chain_and_key_free(chain_and_key)); EXPECT_SUCCESS(s2n_connection_free(client_conn)); EXPECT_SUCCESS(s2n_connection_free(server_conn)); EXPECT_SUCCESS(s2n_config_free(server_config)); free(cert_chain); free(client_chain); free(private_key); #if S2N_LIBCRYPTO_SUPPORTS_CUSTOM_RAND /* Extra cleanup needed for the known answer test */ fclose(kat_file); #endif END_TEST(); }
int main( void ) { unsigned long long inlen; unsigned long long offset; unsigned long long size; int result = 0; FILE *fp_in; char marker[20]; int refLen; hashState state; #ifdef cKeccakFixedOutputLengthInBytes refLen = cKeccakFixedOutputLengthInBytes; #else refLen = cKeccakR_SizeInBytes; #endif printf( "Testing Keccak[r=%u, c=%u] using crypto_hash() against %s over %d squeezed bytes\n", cKeccakR, cKeccakB - cKeccakR, testVectorFile, refLen ); if ( (fp_in = fopen(testVectorFile, "r")) == NULL ) { printf("Couldn't open <%s> for read\n", testVectorFile); return 1; } for ( inlen = 0; inlen <= cKeccakMaxMessageSizeInBytes; ++inlen ) { sprintf( marker, "Len = %u", inlen * 8 ); if ( !FindMarker(fp_in, marker) ) { printf("ERROR: no test vector found (%u bytes)\n", inlen ); result = 1; break; } if ( !ReadHex(fp_in, input, (int)inlen, "Msg = ") ) { printf("ERROR: unable to read 'Msg' (%u bytes)\n", inlen ); result = 1; break; } result = crypto_hash( output, input, inlen ); if ( result != 0 ) { printf("ERROR: crypto_hash() (%u bytes)\n", inlen); result = 1; break; } #ifdef cKeccakFixedOutputLengthInBytes if ( !ReadHex(fp_in, input, refLen, "MD = ") ) #else if ( !ReadHex(fp_in, input, refLen, "Squeezed = ") ) #endif { printf("ERROR: unable to read 'Squeezed/MD' (%u bytes)\n", inlen ); result = 1; break; } if ( memcmp( output, input, refLen ) != 0) { printf("ERROR: hash verification (%u bytes)\n", inlen ); for(result=0; result<refLen; result++) printf("%02X ", output[result]); printf("\n"); result = 1; break; } } if ( !result ) printf( "\nSuccess!\n"); result = 0; refLen = cKeccakHashRefSizeInBytes; printf( "\nTesting Keccak[r=%u, c=%u] using Init/Update/Final() against %s over %d squeezed bytes\n", cKeccakR, cKeccakB - cKeccakR, testVectorFile, refLen ); fseek( fp_in, 0, SEEK_SET ); for ( inlen = 0; inlen <= cKeccakMaxMessageSizeInBits; ++inlen ) { sprintf( marker, "Len = %u", inlen ); if ( !FindMarker(fp_in, marker) ) { printf("ERROR: no test vector found (%u bits)\n", inlen ); result = 1; break; } if ( !ReadHex(fp_in, input, (int)inlen, "Msg = ") ) { printf("ERROR: unable to read 'Msg' (%u bits)\n", inlen ); result = 1; break; } result = Init( &state ); if ( result != 0 ) { printf("ERROR: Init() (%u bits)\n", inlen); result = 1; break; } for ( offset = 0; offset < inlen; offset += size ) { // vary sizes for Update() if ( (inlen %8) < 2 ) { // byte per byte size = 8; } else if ( (inlen %8) < 4 ) { // incremental size = offset + 8; } else { // random size = ((rand() % ((inlen + 8) / 8)) + 1) * 8; } if ( size > (inlen - offset) ) { size = inlen - offset; } //printf("Update() inlen %u, size %u, offset %u\n", (unsigned int)inlen, (unsigned int)size, (unsigned int)offset ); result = Update( &state, input + offset / 8, size ); if ( result != 0 ) { printf("ERROR: Update() (%u bits)\n", inlen); result = 1; break; } } result = Final( &state, output, refLen ); if ( result != 0 ) { printf("ERROR: Final() (%u bits)\n", inlen); result = 1; break; } #ifdef cKeccakFixedOutputLengthInBytes if ( !ReadHex(fp_in, input, refLen, "MD = ") ) #else if ( !ReadHex(fp_in, input, refLen, "Squeezed = ") ) #endif { printf("ERROR: unable to read 'Squeezed/MD' (%u bits)\n", inlen ); result = 1; break; } if ( memcmp( output, input, refLen ) != 0) { printf("ERROR: hash verification (%u bits)\n", inlen ); for(result=0; result<refLen; result++) printf("%02X ", output[result]); printf("\n"); result = 1; break; } } fclose( fp_in ); if ( !result ) printf( "\nSuccess!\n"); //printf( "\nPress a key ..."); //getchar(); //printf( "\n"); return ( result ); }
int ParseLine(unsigned long pid, char * lines, int start, int linesLen, int * skip, int doForceWrite) { if (pid == NULL || pid == 0) return start; char cType = lines[start]; int lineLen = 0, arg2Len = 0, arg1Off = 0, totalLenRead = 0, arg0 = 0; int arg0_2 = 0; for (lineLen = start; lineLen < linesLen; lineLen++) { if (lines[lineLen] == '\n' || lines[lineLen] == '\r') break; } lineLen -= start; int arg3Off = start + lineLen, arg4Off = arg3Off + 1, arg4Len = arg4Off; totalLenRead = lineLen; if (skip[0] <= 0) { skip[0] = 0; //Parse first line while (lines[(start + lineLen) - arg2Len] != ' ') arg2Len++; while (lines[start + arg1Off] != ' ') arg1Off++; char addrBuf[4]; memset(addrBuf, 0, 4); ReadHexPartial(lines, start + 1, (arg1Off - 1), addrBuf, (arg1Off - 1)/2); arg0 = (int)(((unsigned char)addrBuf[0] << 24) | ((unsigned char)addrBuf[1] << 16) | ((unsigned char)addrBuf[2] << 8) | ((unsigned char)addrBuf[3])); ReadHex(lines, start + arg1Off + 1, 8, addrBuf, 4); uint64_t addr = (uint64_t)(((unsigned char)addrBuf[0] << 24) | ((unsigned char)addrBuf[1] << 16) | ((unsigned char)addrBuf[2] << 8) | ((unsigned char)addrBuf[3])); if (ptrAddr != 0) { addr = ptrAddr; ptrAddr = 0; } char buf0[arg2Len/2]; char arg2Temp[arg2Len - 1]; if (arg0 < 0) arg0 = 0; char buf1[arg0]; //Check if theres a second line if ((start + lineLen + 1) < linesLen) { //Parse second line vars (for codes that need the second line //Get next code arguments while (arg3Off < linesLen && lines[arg3Off] != ' ') arg3Off++; arg4Off = arg3Off + 1; while (arg4Off < linesLen && lines[arg4Off] != ' ') arg4Off++; arg4Len = arg4Off + 1; while (arg4Len < linesLen && lines[arg4Len] != '\r' && lines[arg4Len] != '\n') arg4Len++; arg4Len -= arg4Off; } else arg4Len = 0; char buf0_2[arg4Len/2]; char buf1_2[(arg4Off - arg3Off)/2]; if (arg4Len == 0) goto skipSecondLine; //Get args for second line ReadHexPartial(lines, start + lineLen + 2, (arg3Off) - (start + lineLen + 2), addrBuf, ((arg3Off) - (start + lineLen + 2))/2); arg0_2 = (uint)(((unsigned char)addrBuf[0] << 24) | ((unsigned char)addrBuf[1] << 16) | ((unsigned char)addrBuf[2] << 8) | ((unsigned char)addrBuf[3])); //Get address for second line ReadHexPartial(lines, arg3Off + 1, arg4Off - arg3Off - 1, buf0_2, (arg4Off - arg3Off - 1)/2); //Get value for second line ReadHexPartial(lines, arg4Off + 1, arg4Len - 1, buf1_2, (arg4Len - 1)/2); skipSecondLine: ; switch (cType) { case '0': ; //Write bytes (1=OR,2=AND,3=XOR,rest=write) switch (arg0) { case 1: //OR ReadHex(lines, (start + lineLen) - arg2Len + 1, arg2Len - 1, buf0, 4); //Get source bytes get_process_mem(pid, addr, buf1, (arg2Len/2), isDEX, isCCAPI); //Or each byte for (uint cnt0 = 0; cnt0 < (uint)(arg2Len/2); cnt0++) buf1[cnt0] |= buf0[cnt0]; //Write bytes to dest WriteMem(pid, addr, buf1, (arg2Len/2)); break; case 2: //AND ReadHex(lines, (start + lineLen) - arg2Len + 1, arg2Len - 1, buf0, 4); //Get source bytes get_process_mem(pid, addr, buf1, (arg2Len/2), isDEX, isCCAPI); //And each byte for (uint cnt0 = 0; cnt0 < (uint)(arg2Len/2); cnt0++) buf1[cnt0] &= buf0[cnt0]; //Write bytes to dest WriteMem(pid, addr, buf1, (arg2Len/2)); break; case 3: //XOR ReadHex(lines, (start + lineLen) - arg2Len + 1, arg2Len - 1, buf0, 4); //Get source bytes get_process_mem(pid, addr, buf1, (arg2Len/2), isDEX, isCCAPI); //Xor each byte for (uint cnt0 = 0; cnt0 < (uint)(arg2Len/2); cnt0++) buf1[cnt0] ^= buf0[cnt0]; //Write bytes to dest WriteMem(pid, addr, buf1, (arg2Len/2)); break; default: ReadHex(lines, (start + lineLen) - arg2Len + 1, arg2Len - 1, buf0, 4); WriteMem(pid, addr, buf0, (arg2Len/2)); break; } break; case '1': //Write text //Get total text write size arg1Off++; while (lines[start + arg1Off] != ' ') arg1Off++; arg2Len = lineLen - arg1Off; strncpy(buf0, lines + (start + lineLen) - arg2Len + 1, arg2Len - 1); buf0[arg2Len-1] = '\0'; WriteMem(pid, addr, buf0, arg2Len - 1); break; case '2': //Write float strncpy(buf0, lines + (start + lineLen) - arg2Len + 1, arg2Len - 1); float buf2Flt = (float)___atof(buf0); //atof(buf2); WriteMem(pid, addr, (char*)&buf2Flt, arg2Len - 1); totalLenRead = lineLen; break; case '4': ; //Write condensed //Get count uint count = (uint)(((unsigned char)buf1_2[0] << 24) | ((unsigned char)buf1_2[1] << 16) | ((unsigned char)buf1_2[2] << 8) | ((unsigned char)buf1_2[3])); //Get increment uint64_t inc = (uint64_t)(((unsigned char)buf0_2[0] << 24) | ((unsigned char)buf0_2[1] << 16) | ((unsigned char)buf0_2[2] << 8) | ((unsigned char)buf0_2[3])); //Get write ReadHex(lines, (start + lineLen) - arg2Len + 1, arg2Len - 1, buf0, arg2Len / 2); for (uint cnt4 = 0; cnt4 < count; cnt4++) { WriteMem(pid, addr + (uint64_t)(cnt4 * inc), buf0, (arg2Len/2)); if (arg0_2 != 0) *(uint*)buf0 += (arg0_2 << (((arg2Len/2) % 4) * 8)); } skip[0]++; break; case '6': //Write pointer //Get offset ReadHexPartial(lines, (start + lineLen) - arg2Len + 1, arg2Len - 1, buf0, (arg2Len - 1)/2); uint64_t offset = (uint64_t)(((unsigned char)buf0[0] << 24) | ((unsigned char)buf0[1] << 16) | ((unsigned char)buf0[2] << 8) | ((unsigned char)buf0[3])); //Get address at pointer get_process_mem(pid, addr, buf0, 4, isDEX, isCCAPI); ptrAddr = (uint64_t)(((unsigned char)buf0[0] << 24) | ((unsigned char)buf0[1] << 16) | ((unsigned char)buf0[2] << 8) | ((unsigned char)buf0[3])); ptrAddr += offset; break; case 'A': //Copy paste switch (arg0) { case 1: //if (typeA_Copy) // _free(typeA_Copy); //Get count ReadHexPartial(lines, (start + lineLen) - arg2Len + 1, arg2Len - 1, buf0, (arg2Len - 1)/2); uint count = (uint)(((unsigned char)buf0[0] << 24) | ((unsigned char)buf0[1] << 16) | ((unsigned char)buf0[2] << 8) | ((unsigned char)buf0[3])); typeA_Size = count; //typeA_Copy = (char *)_malloc(count); typeA_Copy = (char *)mem_alloc(0); get_process_mem(pid, addr, typeA_Copy, 4, isDEX, isCCAPI); memcpy(arg2Temp, lines + ((start + lineLen) - arg2Len + 1), arg2Len - 1); break; case 2: if (!typeA_Copy || typeA_Size <= 0) break; WriteMem(pid, addr, typeA_Copy, typeA_Size); break; } break; case 'B': //Find Replace //Only work when doForceWrite is true (1) which means everytime the user activates Artemis from the in game XMB //Don't want to waste time constantly searching if (!doForceWrite) break; //Get end addr ReadHex(lines, (start + lineLen) - arg2Len + 1, arg2Len - 1, addrBuf, 4); uint64_t endAddr = (uint64_t)(((unsigned char)addrBuf[0] << 24) | ((unsigned char)addrBuf[1] << 16) | ((unsigned char)addrBuf[2] << 8) | ((unsigned char)addrBuf[3])); //new (COP) length uint binc = arg4Len/2; //original (OGP) length uint cmpSize = (arg4Off - arg3Off)/2; //Flip addresses uint64_t temp = 0; if (endAddr < addr) { temp = addr; addr = endAddr; endAddr = temp; } for (uint64_t curAddr = addr; curAddr < endAddr; curAddr += (scanInc - cmpSize)) { if (get_process_mem(pid, curAddr, (char *)memBuf, scanInc, isDEX, isCCAPI) >= 0) { //So we stop it each loop before (scanInc - cmpSize) in the instance that //the result is the last 2 bytes, for instance, and the compare is actually 4 bytes (so it won't result even though it should) //This fixes that for (uint64_t boff = 0; boff < (scanInc - cmpSize); boff++) { //Break if count reached if (arg0 > 0 && temp >= (uint64_t)arg0) break; if ((curAddr + boff) >= endAddr) break; if (CompareMemoryBuffered((char *)memBuf, boff, buf0_2, cmpSize)) { //printf ("Instance found at 0x%08x, writing 0x%x (%d)\n", curAddr + boff, *(uint*)buf1_2, binc); WriteMem(pid, curAddr + boff, buf1_2, binc); //Just skip in case the replacement has, within itself, the ogp //We subtract one because it gets added back at the top of the loop boff += binc - 1; temp++; } } } } skip[0]++; totalLenRead = lineLen; break; case 'D': //Write conditional ReadHex(lines, (start + lineLen) - arg2Len + 1, arg2Len - 1, buf0, 4); int DisCond = CompareMemory(pid, addr, buf0, arg2Len / 2); if (!DisCond) { skip[0] += arg0; } break; case 'E': //Write conditional (bitwise) ReadHex(lines, (start + lineLen) - arg2Len + 1, arg2Len - 1, buf0, 4); int EisCond = CompareMemoryAnd(pid, addr, buf0, arg2Len / 2); if (!EisCond) { skip[0] += arg0; } break; case 'F': //Copy bytes //Get destination ReadHex(lines, (start + lineLen) - arg2Len + 1, arg2Len - 1, buf0, 4); uint64_t dest = (uint64_t)(((unsigned char)buf0[0] << 24) | ((unsigned char)buf0[1] << 16) | ((unsigned char)buf0[2] << 8) | ((unsigned char)buf0[3])); //Get source bytes get_process_mem(pid, addr, buf1, arg0, isDEX, isCCAPI); //Write bytes to dest WriteMem(pid, dest, buf1, arg0); break; } } else skip[0]--; return start + totalLenRead; }
void ReadUserData() { *priorMessage = 0; tokenControl = 0; // change nothing of the data chatbotFacts = factFree; sprintf(readBuffer,"USERS/topic_%s_%s%s.txt",loginID,computerID,fileID); FILE* in = fopen(readBuffer,"rb"); *fileID = 0; if ( in) // check validity stamp { ReadALine(readBuffer,in); if (stricmp(readBuffer,saveVersion)) // obsolete format { fclose(in); in = 0; } } if (!in) // this is a new user { ReadNewUser(); start_rejoinder_Topic = rejoinder_Topic; start_Rejoinder_at = rejoinder_at; char* value = GetUserVariable("$token"); tokenControl = (*value) ? atoi(value) : (DO_INTERJECTION_SPLITTING|DO_SUBSTITUTES|DO_NUMBER_MERGE|DO_PROPERNAME_MERGE|DO_SPELLCHECK|DO_UTF8_CONVERT); return; } ReadTopicData(in); // ready in recently used messages for (humanSaidIndex = 0; humanSaidIndex < MAX_USED; ++humanSaidIndex) { ReadALine(humanSaid[humanSaidIndex], in); if (humanSaid[humanSaidIndex][0] == '#') break; // #end } for (chatbotSaidIndex = 0; chatbotSaidIndex < MAX_USED; ++chatbotSaidIndex) { ReadALine(chatbotSaid[chatbotSaidIndex], in); if (chatbotSaid[chatbotSaidIndex][0] == '#') break; // #end } // read in fact sets char word[MAX_WORD_SIZE]; *word = 0; ReadALine(readBuffer, in); // setControl ReadHex(readBuffer,setControl); while (ReadALine(readBuffer, in)) { char* ptr = ReadCompiledWord(readBuffer,word); unsigned int setid; unsigned int count; ptr = ReadInt(ptr,setid); ptr = ReadInt(ptr,count); factSet[setid][0] = (FACT*) count; for (unsigned int i = 1; i <= count; ++i) { if (!ReadALine(readBuffer, in)) break; ptr = readBuffer; factSet[setid][i] = ReadFact(ptr); } } fclose(in); start_rejoinder_Topic = rejoinder_Topic; start_Rejoinder_at = rejoinder_at; // read user facts char name[MAX_WORD_SIZE]; sprintf(name,"USERS/fact_%s.txt",loginID); ReadFacts(name,0); userFactBase = factFree; // note waterline of facts, to see if more are added.. // BUG -- need delete of facts to alter userFactBase also. char* value = GetUserVariable("$token"); tokenControl = (*value) ? atoi(value) : (DO_INTERJECTION_SPLITTING|DO_SUBSTITUTES|DO_NUMBER_MERGE|DO_PROPERNAME_MERGE|DO_SPELLCHECK|DO_UTF8_CONVERT); // for server logging char* prior = (chatbotSaidIndex < 1) ? ((char*)"") : chatbotSaid[chatbotSaidIndex-1]; strcpy(priorMessage,prior); }