From ec509fbcc7a1a2a1d499b937149840110d1d8d65 Mon Sep 17 00:00:00 2001 From: robertdavidgraham Date: Wed, 8 Nov 2023 04:18:51 -0500 Subject: [PATCH] fixed VS10 build --- src/main-conf.c | 7 ++-- src/massip-rangesv4.c | 2 +- src/massip-rangesv4.h | 2 +- src/massip-rangesv6.c | 2 +- src/out-tcp-services.c | 2 +- src/proto-mc.c | 14 ++++---- src/templ-opts.h | 4 +++ src/templ-tcp-hdr.c | 55 +++++++++++++++------------- vs10/masscan.vcxproj | 23 +++++++----- vs10/masscan.vcxproj.filters | 69 +++++++++++++++++++++++------------- 10 files changed, 111 insertions(+), 69 deletions(-) diff --git a/src/main-conf.c b/src/main-conf.c index 14cb7de1..cea527fb 100644 --- a/src/main-conf.c +++ b/src/main-conf.c @@ -235,10 +235,11 @@ print_nmap_help(void) static unsigned count_cidr6_bits(struct Range6 *range, bool *exact) { - /* for the comments of this function, see count_cidr_bits */ - *exact = false; uint64_t i; + /* for the comments of this function, see count_cidr_bits */ + *exact = false; + for (i=0; i<128; i++) { uint64_t mask_hi; uint64_t mask_lo; @@ -3721,6 +3722,8 @@ void masscan_echo_cidr(struct Masscan *masscan, FILE *fp, unsigned is_echo_all) { unsigned i; + UNUSEDPARM(is_echo_all); + masscan->echo = fp; /* diff --git a/src/massip-rangesv4.c b/src/massip-rangesv4.c index 894692fc..c2d0852a 100644 --- a/src/massip-rangesv4.c +++ b/src/massip-rangesv4.c @@ -76,7 +76,7 @@ rangelist_is_contains(const struct RangeList *targets, unsigned addr) ***************************************************************************/ struct Range range_first_cidr(const struct Range range, unsigned *prefix_bits) { - struct Range result = (struct Range){range.begin, range.end}; + struct Range result = {range.begin, range.end}; unsigned zbits = 0; /* Kludge: Special Case: diff --git a/src/massip-rangesv4.h b/src/massip-rangesv4.h index 31305e30..5cad6697 100644 --- a/src/massip-rangesv4.h +++ b/src/massip-rangesv4.h @@ -2,7 +2,7 @@ #define RANGES_H #include #include -#include +#include "util-bool.h" /**/ /** * A range of either IP addresses or ports diff --git a/src/massip-rangesv6.c b/src/massip-rangesv6.c index 3dc11677..ad1dfcfb 100644 --- a/src/massip-rangesv6.c +++ b/src/massip-rangesv6.c @@ -572,7 +572,7 @@ range6list_optimize(struct Range6List *targets) for (i=0; icount; i++) { ipv6address x; - picker[i] = total.lo; + picker[i] = (size_t)total.lo; x = _int128_subtract(targets->list[i].end, targets->list[i].begin); x = _int128_add64(x, 1); total = _int128_add(total, x); diff --git a/src/out-tcp-services.c b/src/out-tcp-services.c index 4f1694da..f34149c3 100644 --- a/src/out-tcp-services.c +++ b/src/out-tcp-services.c @@ -18,7 +18,7 @@ */ static unsigned short my_htons(unsigned port) { - static const char test[2] = "\x11\x22"; + static const char test[3] = "\x11\x22"; if (*(unsigned short*)test == 0x1122) return (unsigned short)(0xFFFF & port); else diff --git a/src/proto-mc.c b/src/proto-mc.c index f25ddecb..2a0ba702 100644 --- a/src/proto-mc.c +++ b/src/proto-mc.c @@ -15,10 +15,10 @@ hand_shake(uint16_t port, const char* ip, size_t ip_len) { size_t tlen = 10+ip_len; unsigned char * ret = (unsigned char *)calloc(1,tlen); - ret[0] = 7+ip_len; + ret[0] = (unsigned char)(7+ip_len); ret[2] = 0xf7; ret[3] = 5; - ret[4] = ip_len; + ret[4] = (unsigned char)ip_len; memcpy(ret+5,ip,ip_len); ret[tlen-5] = (unsigned char)(port>>8); ret[tlen-4] = (unsigned char)(port&0xff); @@ -31,12 +31,13 @@ hand_shake(uint16_t port, const char* ip, size_t ip_len) static void * memstr(void * mem, size_t len, char * str) { + size_t i; size_t stlen = strlen(str); if(len < stlen) return 0; - for(size_t i = 0; i < len-stlen; i++) { - if(!memcmp(mem+i,str,stlen)) - return mem+i; + for(i = 0; i < len-stlen; i++) { + if(!memcmp((char*)mem+i,str,stlen)) + return (char*)mem+i; } return 0; } @@ -51,9 +52,10 @@ mc_parse( const struct Banner1 *banner1, struct BannerOutput *banout, struct InteractiveData *more) { + size_t i; struct MCSTUFF *mc = &pstate->sub.mc; - for(size_t i = 0; i < length; i++) { + for(i = 0; i < length; i++) { if(px[i] == '{') mc->brackcount++; if(px[i] == '}') diff --git a/src/templ-opts.h b/src/templ-opts.h index 9b3ac1d2..32dff3cb 100644 --- a/src/templ-opts.h +++ b/src/templ-opts.h @@ -2,6 +2,10 @@ #define TEMPL_OPTS_H #include "massip-addr.h" +#ifdef _MSC_VER +#pragma warning(disable:4214) +#endif + /** * This tells us whether we should add, remove, or leave default * a field in the packet headers. diff --git a/src/templ-tcp-hdr.c b/src/templ-tcp-hdr.c index 1db56011..5721dfa8 100644 --- a/src/templ-tcp-hdr.c +++ b/src/templ-tcp-hdr.c @@ -73,6 +73,7 @@ #include #include #include +#include /*fixme: remove this*/ struct tcp_opt_t { const unsigned char *buf; @@ -126,7 +127,7 @@ _HEXDUMP(const void *v, struct tcp_hdr_t hdr, size_t offset, const char *name) if (j == offset) c = '#'; - if (isprint(c) && !isspace(c)) + if (isprint(c&0xff) && !isspace(c&0xff)) printf("%c", c); else printf("."); @@ -269,7 +270,7 @@ _find_tcp_header(const unsigned char *buf, size_t length) { hdr.begin = parsed.transport_offset; hdr.max = hdr.begin + _tcp_header_length(buf, hdr.begin); hdr.ip_offset = parsed.ip_offset; - hdr.ip_version = parsed.ip_version; + hdr.ip_version = (unsigned char)parsed.ip_version; hdr.is_found = true; return hdr; @@ -455,7 +456,7 @@ _adjust_length(unsigned char *buf, size_t length, int adjustment, struct tcp_hdr fprintf(stderr, "[-] templ.tcp corruptoin\n"); } - buf[offset] = (buf[offset] & 0x0F) | ((hdr_length/4) << 4); + buf[offset] = (unsigned char)((buf[offset] & 0x0F) | ((hdr_length/4) << 4)); hdr_length = (buf[offset] >> 4) * 4; if (hdr.begin + hdr_length > length) { @@ -474,13 +475,13 @@ _add_padding(unsigned char **inout_buf, size_t *inout_length, size_t offset, uns unsigned char *buf = *inout_buf; size_t length = *inout_length; - buf = realloc(buf, length + pad_count); length += pad_count; + buf = realloc(buf, length); /* open space between headers and payload */ memmove(buf + offset + pad_count, buf + offset, - length - offset); + (length - pad_count) - offset); /* set padding to zero */ memset(buf + offset, 0, pad_count); @@ -659,21 +660,17 @@ _insert_field(unsigned char **inout_buf, /* can theoreitcally be negative, but that's ok */ adjust = (int)new_length - ((int)offset_end - (int)offset_begin); - if (adjust > 0) { - /* lengthen buffer before */ length += adjust; buf = realloc(buf, length); + memmove(buf + offset_begin + new_length, + buf + offset_end, + (length - adjust) - offset_end); } - - /* move data second */ - memmove(buf + offset_begin + new_length, - buf + offset_end, - length - offset_end); - - if (adjust < 0) { - /* shorten buffer after */ + memmove(buf + offset_begin + new_length, + buf + offset_end, + length - offset_end); length += adjust; buf = realloc(buf, length); } @@ -850,8 +847,8 @@ tcp_add_opt(unsigned char **inout_buf, /* Create a well-formatted field that will be inserted */ new_length = 1 + 1 + opt_length; - new_field[0] = opt_kind; - new_field[1] = new_length; + new_field[0] = (unsigned char)opt_kind; + new_field[1] = (unsigned char)new_length; memcpy(new_field + 2, opt_data, opt_length); /* Calculate the begin/end of the existing field in the packet */ @@ -1124,22 +1121,27 @@ _replace_options(unsigned char **inout_buf, size_t *inout_length, old_length = hdr.max - offset; /* Either increase or decrease the old length appropriately */ - //_HEXDUMPopt(buf, length, "resize before"); + _HEXDUMPopt(buf, length, "resize before"); adjust = (int)(new_length - old_length); - if (old_length < new_length) { - buf = realloc(buf, length + adjust); + if (adjust > 0) { length += adjust; + buf = realloc(buf, length); memmove(buf + hdr.max + adjust, buf + hdr.max, - length - hdr.max); - } else { + (length - adjust) - hdr.max); + } + if (adjust < 0) { memmove(buf + hdr.max + adjust, buf + hdr.max, length - hdr.max); - buf = realloc(buf, length + adjust); length += adjust; + buf = realloc(buf, length); } + _adjust_length(buf, length, adjust, hdr); + _normalize_padding(&buf, &length); + _HEXDUMPopt(buf, length, "resize after"); + /* Now that we've resized the options field, overright * it with then new field */ memcpy(buf + offset, newnew_options, new_length); @@ -1205,18 +1207,20 @@ tests[] = { /* Attempt removal of an option that doesn't exist. This is not * a failure, but a success, though nothing is changed*/ + { {"\3\3\3\0", 4}, {TST_REMOVE, "\x08", 1}, {"\3\3\3\0", 4} }, + /* Test removal of an option. This will also involve removing the now unnecessary padding */ { {"\3\3\3\1\1\1\x08\x0a\x1d\xe9\xb2\x98\x00\x00\x00\x00", 16}, {TST_REMOVE, "\x08", 1}, {"\3\3\3\0", 4} }, -#if 0 + /* Test when trying to add a big option that won't fit unless we get * rid of all the padding */ { { "\x02\x04\x05\xb4" @@ -1259,7 +1263,6 @@ tests[] = { 40 } }, -#endif /* Add a new value to full packet */ {{"\3\3\3", 3}, {TST_ADD, "\4\2", 2}, {"\3\3\3\4\2\0\0\0", 8}}, @@ -1362,6 +1365,8 @@ _selftests_run(void) { size_t field_length; + LOG(1, "[+] templ-tcp-hdr: run #%u\n", (unsigned)i); + /* Each tests creates its own copy of the test packet, which it * will then alter according to the pre-conditions. */ buf = malloc(length); diff --git a/vs10/masscan.vcxproj b/vs10/masscan.vcxproj index 1efa9e02..982d1ff4 100644 --- a/vs10/masscan.vcxproj +++ b/vs10/masscan.vcxproj @@ -20,7 +20,11 @@ + + + + @@ -59,6 +63,7 @@ + @@ -90,9 +95,6 @@ - - - @@ -105,7 +107,6 @@ - @@ -118,8 +119,10 @@ + + @@ -131,6 +134,10 @@ + + + + @@ -171,6 +178,7 @@ + @@ -191,16 +199,12 @@ - - - - @@ -212,8 +216,11 @@ + + + diff --git a/vs10/masscan.vcxproj.filters b/vs10/masscan.vcxproj.filters index bf747f57..02b508dd 100644 --- a/vs10/masscan.vcxproj.filters +++ b/vs10/masscan.vcxproj.filters @@ -162,15 +162,6 @@ Source Files\proto - - Source Files\crypto - - - Source Files\crypto - - - Source Files\crypto - Source Files\proto @@ -180,9 +171,6 @@ Source Files\crypto - - Source Files\crypto - Source Files\output @@ -381,6 +369,27 @@ Source Files\stack + + Source Files\crypto + + + Source Files\crypto + + + Source Files\crypto + + + Source Files\crypto + + + Source Files\proto + + + Source Files\proto + + + Source Files\proto + @@ -470,15 +479,6 @@ Source Files - - Source Files\crypto - - - Source Files\crypto - - - Source Files\crypto - Source Files\proto @@ -488,9 +488,6 @@ Source Files\crypto - - Source Files\crypto - Source Files\output @@ -653,6 +650,30 @@ Source Files\rawsock + + Source Files\crypto + + + Source Files\crypto + + + Source Files\crypto + + + Source Files\crypto + + + Source Files\proto + + + Source Files\proto + + + Source Files\proto + + + Source Files\proto +