Skip to content

Commit

Permalink
fixed VS10 build
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdavidgraham committed Nov 8, 2023
1 parent cc88226 commit ec509fb
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 69 deletions.
7 changes: 5 additions & 2 deletions src/main-conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

/*
Expand Down
2 changes: 1 addition & 1 deletion src/massip-rangesv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/massip-rangesv4.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define RANGES_H
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include "util-bool.h" /*<stdbool.h>*/

/**
* A range of either IP addresses or ports
Expand Down
2 changes: 1 addition & 1 deletion src/massip-rangesv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ range6list_optimize(struct Range6List *targets)

for (i=0; i<targets->count; 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);
Expand Down
2 changes: 1 addition & 1 deletion src/out-tcp-services.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions src/proto-mc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand All @@ -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] == '}')
Expand Down
4 changes: 4 additions & 0 deletions src/templ-opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
55 changes: 30 additions & 25 deletions src/templ-tcp-hdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <malloc.h> /*fixme: remove this*/

struct tcp_opt_t {
const unsigned char *buf;
Expand Down Expand Up @@ -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(".");
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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}},
Expand Down Expand Up @@ -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);
Expand Down
23 changes: 15 additions & 8 deletions vs10/masscan.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\crypto-base64.c" />
<ClCompile Include="..\src\crypto-blackrock.c" />
<ClCompile Include="..\src\crypto-blackrock2.c" />
<ClCompile Include="..\src\crypto-lcg.c" />
<ClCompile Include="..\src\crypto-primegen.c" />
<ClCompile Include="..\src\crypto-siphash24.c" />
<ClCompile Include="..\src\event-timeout.c" />
<ClCompile Include="..\src\in-filter.c" />
<ClCompile Include="..\src\in-report.c" />
Expand Down Expand Up @@ -59,6 +63,7 @@
<ClCompile Include="..\src\proto-icmp.c" />
<ClCompile Include="..\src\proto-imap4.c" />
<ClCompile Include="..\src\proto-interactive.c" />
<ClCompile Include="..\src\proto-mc.c" />
<ClCompile Include="..\src\proto-memcached.c" />
<ClCompile Include="..\src\proto-netbios.c" />
<ClCompile Include="..\src\proto-ntlmssp.c" />
Expand Down Expand Up @@ -90,9 +95,6 @@
<ClCompile Include="..\src\proto-vnc.c" />
<ClCompile Include="..\src\proto-x509.c" />
<ClCompile Include="..\src\proto-zeroaccess.c" />
<ClCompile Include="..\src\rand-blackrock.c" />
<ClCompile Include="..\src\rand-lcg.c" />
<ClCompile Include="..\src\rand-primegen.c" />
<ClCompile Include="..\src\rawsock-getif.c" />
<ClCompile Include="..\src\rawsock-getip.c" />
<ClCompile Include="..\src\rawsock-getip6.c" />
Expand All @@ -105,7 +107,6 @@
<ClCompile Include="..\src\scripting-banner.c" />
<ClCompile Include="..\src\scripting-masscan.c" />
<ClCompile Include="..\src\scripting.c" />
<ClCompile Include="..\src\siphash24.c" />
<ClCompile Include="..\src\smack1.c" />
<ClCompile Include="..\src\smackqueue.c" />
<ClCompile Include="..\src\stack-arpv4.c" />
Expand All @@ -118,8 +119,10 @@
<ClCompile Include="..\src\stub-pcap.c" />
<ClCompile Include="..\src\stub-pfring.c" />
<ClCompile Include="..\src\syn-cookie.c" />
<ClCompile Include="..\src\templ-nmap-payloads.c" />
<ClCompile Include="..\src\templ-payloads.c" />
<ClCompile Include="..\src\templ-pkt.c" />
<ClCompile Include="..\src\templ-tcp-hdr.c" />
<ClCompile Include="..\src\util-checksum.c" />
<ClCompile Include="..\src\util-malloc.c" />
<ClCompile Include="..\src\versioning.c" />
Expand All @@ -131,6 +134,10 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\crypto-base64.h" />
<ClInclude Include="..\src\crypto-blackrock.h" />
<ClInclude Include="..\src\crypto-lcg.h" />
<ClInclude Include="..\src\crypto-primegen.h" />
<ClInclude Include="..\src\crypto-siphash24.h" />
<ClInclude Include="..\src\in-filter.h" />
<ClInclude Include="..\src\in-report.h" />
<ClInclude Include="..\src\main-globals.h" />
Expand Down Expand Up @@ -171,6 +178,7 @@
<ClInclude Include="..\src\proto-icmp.h" />
<ClInclude Include="..\src\proto-imap4.h" />
<ClInclude Include="..\src\proto-interactive.h" />
<ClInclude Include="..\src\proto-mc.h" />
<ClInclude Include="..\src\proto-memcached.h" />
<ClInclude Include="..\src\proto-netbios.h" />
<ClInclude Include="..\src\proto-ntlmssp.h" />
Expand All @@ -191,16 +199,12 @@
<ClInclude Include="..\src\proto-vnc.h" />
<ClInclude Include="..\src\proto-x509.h" />
<ClInclude Include="..\src\proto-zeroaccess.h" />
<ClInclude Include="..\src\rand-blackrock.h" />
<ClInclude Include="..\src\rand-lcg.h" />
<ClInclude Include="..\src\rand-primegen.h" />
<ClInclude Include="..\src\rawsock-adapter.h" />
<ClInclude Include="..\src\rawsock-pcapfile.h" />
<ClInclude Include="..\src\rawsock.h" />
<ClInclude Include="..\src\read-service-probes.h" />
<ClInclude Include="..\src\rte-ring.h" />
<ClInclude Include="..\src\scripting.h" />
<ClInclude Include="..\src\siphash24.h" />
<ClInclude Include="..\src\smack.h" />
<ClInclude Include="..\src\smackqueue.h" />
<ClInclude Include="..\src\stack-arpv4.h" />
Expand All @@ -212,8 +216,11 @@
<ClInclude Include="..\src\stub-pcap.h" />
<ClInclude Include="..\src\stub-pfring.h" />
<ClInclude Include="..\src\syn-cookie.h" />
<ClInclude Include="..\src\templ-nmap-payloads.h" />
<ClInclude Include="..\src\templ-opts.h" />
<ClInclude Include="..\src\templ-payloads.h" />
<ClInclude Include="..\src\templ-pkt.h" />
<ClInclude Include="..\src\templ-tcp-hdr.h" />
<ClInclude Include="..\src\util-bool.h" />
<ClInclude Include="..\src\util-checksum.h" />
<ClInclude Include="..\src\util-malloc.h" />
Expand Down
Loading

0 comments on commit ec509fb

Please sign in to comment.