This commit is contained in:
xethyrion 2016-11-08 13:02:45 +02:00 committed by GitHub
parent 7b1ed7a4a4
commit 483957077e
4 changed files with 296 additions and 222 deletions

View file

@ -20,27 +20,36 @@ int strpos(char *haystack, char *needle)
} }
struct maddr struct maddr
{ {
char string[100]; char string[200];
uint8_t bytes[100]; uint8_t bytes[100];
int bsize[1];
}; };
struct maddr new_maddr_fb(uint8_t * byteaddress,int size)//Construct new address from bytes struct maddr new_maddr_fb(uint8_t * byteaddress,int size)//Construct new address from bytes
{ {
struct maddr anewaddr; struct maddr anewaddr2;
if(byteaddress!=NULL) if(byteaddress!=NULL)
{ {
memcpy(anewaddr.bytes, byteaddress,size); memcpy(anewaddr2.bytes, byteaddress,size);
if(bytes_to_string(anewaddr.string,byteaddress,size)==1) if(bytes_to_string(anewaddr2.string,byteaddress,size)==1)
{ {
return anewaddr; return anewaddr2;
} }
} }
} }
struct maddr new_maddr_fs(char * straddress)//Construct new address from string struct maddr new_maddr_fs(char * straddress)//Construct new address from string
{ {
struct maddr anewaddr; struct maddr anewaddr;
bzero(anewaddr.string, 100);
strcpy(anewaddr.string, straddress); strcpy(anewaddr.string, straddress);
if(string_to_bytes(anewaddr.bytes,anewaddr.string,sizeof(anewaddr.string))==1) anewaddr.bsize[0] = 0;
if(string_to_bytes(anewaddr.bytes,anewaddr.bsize,anewaddr.string,sizeof(anewaddr.string))==1)
{ {
int betta;
//printf("BSIZE: %u\n", anewaddr.bsize[0]);
for(betta=anewaddr.bsize[0];betta<100;betta++)
{
anewaddr.bytes[betta] = '\0';
}
return anewaddr; return anewaddr;
} }
} }
@ -49,13 +58,11 @@ int m_encapsulate(struct maddr * result, char * string)
if(result!=NULL&&string!=NULL) if(result!=NULL&&string!=NULL)
{ {
int success = 0; int success = 0;
char pstr[50]; char pstr[100];
bzero(pstr,50);
strcpy(pstr,result->string); strcpy(pstr,result->string);
strcat(pstr,string+1); strcat(pstr,string+1);
if(string_to_bytes(result->bytes,pstr,sizeof(pstr))) if(string_to_bytes(result->bytes,result->bsize,pstr,sizeof(pstr)))
{ {
printf("RESULT WOULD BE: %s\n", pstr);
strcpy(result->string,pstr); strcpy(result->string,pstr);
return 1; return 1;
} }
@ -101,7 +108,6 @@ int m_decapsulate(struct maddr * result, char * srci)
procstr[i] = '/'; procstr[i] = '/';
} }
} }
strcpy(result->string,procstr);
return 1; return 1;
} }
else else
@ -115,4 +121,5 @@ int m_decapsulate(struct maddr * result, char * srci)
return 0; return 0;
} }
} }
#endif #endif

50
protocols.c Normal file
View file

@ -0,0 +1,50 @@
#include "protocols.h"
#include "codecs.h"
int main() //This won't exist, it's here for my own testing purposes.
{
load_protocols();
pp();
printf("The returned protocol is: %s\nSIZE: %d\n", proto_with_name("onion")->name, proto_with_name("onion")->size);
printf("The returned protocol is: %s\nSIZE: %d\n", proto_with_deccode(444)->name, proto_with_deccode(444)->size);
for(int i=0; i<14; i++)
{
uint64_t extract = (protocol_P+i)->deccode;
char exhexco[20] = "\0";
strcpy(exhexco, Num_To_HexVar_64(extract));
uint64_t decimalval = HexVar_To_Num_64(exhexco);
if(i<9){printf("PROTOCOL 0%d HAS HEXCODE: %s DECIMAL: %"PRIu64" \n", i+1, exhexco, decimalval);}
else{printf("PROTOCOL %d HAS HEXCODE: %s DECIMAL: %"PRIu64" \n", i+1, exhexco, decimalval);};
}
free(protocol_P);
printf("1337 in Hexvar_64: %s\n", Num_To_HexVar_64(1337));
char HEXSTR[20] = "B90A0000000000000000"; //\0 since it's not defined in a source string
uint64_t result = HexVar_To_Num_64(HEXSTR);
result = HexVar_To_Num_64(HEXSTR);
printf("Hexvar_To_Num_64: %"PRIu64"\n", result);
uint8_t Numinvar[10] = {0};
memcpy(Numinvar, Num_To_Varint_64(1337), 10);
printf("Binary form unreadable obviously : %s\n", Numinvar);
uint64_t Varinnum = 0;
memcpy(&Varinnum, Varint_To_Num_64(Numinvar), sizeof(Varint_To_Num_64(Numinvar)));
printf("Number form now readable again:%"PRIu64"\n", Varinnum);
char converted2hex[20] = "\0";
strcpy(converted2hex, Var_To_Hex(Numinvar));
uint8_t converted2bin[10] = {0};
memcpy(converted2bin, Hex_To_Var(converted2hex), 10);
printf("Encoding previous binary to hex now: %s\n", converted2hex);
printf("Encoding previous hex to binary now: %s\n", converted2bin);
//Series of bytes test
int8_t bcounter = 0;
bcounter = Var_Bytes_Count(Numinvar);
printf("Bytes_Count of Numinvar(1337): %d\n", bcounter);
char int2hex[20] = "\0";
strcat(int2hex, Int_To_Hex(1337));
printf("INT2HEX: %s\n", int2hex);
/*TESTING ENDIAN // Aparently won't be needed.
printf("Testing Endian:\n");
uint32_t val32 = 1337;
printf("val32 = %d swapped val32 = %d\n",val32, htole32(val32));
printf("val32 = 0x%08x swapped val32 = 0x%08x\n\n",val32, htole32(val32));
*/
return 0;
}

View file

@ -247,6 +247,7 @@ char * int2ip(int inputintip)
{ {
uint32_t ipint = inputintip; uint32_t ipint = inputintip;
static char xxx_int2ip_result[16] = "\0"; static char xxx_int2ip_result[16] = "\0";
bzero(xxx_int2ip_result,16);
uint32_t ipint0 = (ipint >> 8*3) % 256; uint32_t ipint0 = (ipint >> 8*3) % 256;
uint32_t ipint1 = (ipint >> 8*2) % 256; uint32_t ipint1 = (ipint >> 8*2) % 256;
uint32_t ipint2 = (ipint >> 8*1) % 256; uint32_t ipint2 = (ipint >> 8*1) % 256;
@ -255,112 +256,100 @@ char * int2ip(int inputintip)
return xxx_int2ip_result; return xxx_int2ip_result;
} }
//I didn't feel another address_bytes_to_string was necesarry sry guys //I didn't feel another address_bytes_to_string was necesarry sry guys
int bytes_to_string(char * result, uint8_t * frombuf, size_t weesize) int bytes_to_string(char * resultzx, uint8_t * catx,int xbsize)
{ {
char removedlines[weesize*2]; bzero(resultzx,200);
bzero(removedlines,sizeof(removedlines)); uint8_t * bytes = NULL;
strcpy(removedlines, Var_To_Hex(frombuf)); int size = 0;
//printf("Bytes to Hex: %s\n",removedlines); size = xbsize;
load_protocols(); load_protocols();
int thelastpos=0; char hex[xbsize*2];
for(int i=0;i<sizeof(removedlines);i++) bzero(hex,xbsize*2);
strcat(hex,Var_To_Hex(size, catx));
//Positioning for memory jump:
int lastpos = 0;
char pid[3];
//Process Hex String
NAX:
//Stage 1 ID:
if(lastpos!=0)
{ {
if(thelastpos!=0) lastpos+1;
{
i = thelastpos;
thelastpos=0;
}
char protocol[2];
bzero(protocol,2);
protocol[0] = removedlines[i];
protocol[1] = removedlines[i+1];
if(proto_with_deccode(Hex_To_Int(protocol))!=NULL)
{
//printf("Cproto: %s - %lu\n",protocol,Hex_To_Int(protocol));
struct protocol * bprotox;
bprotox = proto_with_deccode(Hex_To_Int(protocol));
//Getting the address!
char the_wanted_address[50];
int ffpos=0;
int zxp=0;
int addrsizesofar=0;
bzero(the_wanted_address,50);
char isitp[2] = "\0";
bzero(isitp,2);
for(int zx=i+2;zx<sizeof(removedlines);zx++)
{
//printf("ZX: %d\n",zx);
if(zx%2==0)
{
isitp[0] = removedlines[zx];
isitp[1] = removedlines[zx+1];
struct protocol * izp;
izp=proto_with_deccode(Hex_To_Int(isitp));
if(izp)
{
if(addrsizesofar == (bprotox->size/4))
{
printf("%d -- %d\n", addrsizesofar, (bprotox->size/4));
the_wanted_address[zxp]='\0';
thelastpos=zx;
printf("THELASTPOS: %d ",thelastpos);
break;
}
else if(addrsizesofar>(bprotox->size/4))
{
printf("MALFORMED STRING!!!\n");
return 0;
}
}
//printf("RL[%d]: %c\n",zx,removedlines[zx]);
//printf("RL[%d]: %c\n",zx,removedlines[zx+1]);
}
addrsizesofar++;
the_wanted_address[zxp] = removedlines[zx];
zxp++;
}
printf("And the address:%s\n", the_wanted_address);
printf("With size: %d\n", addrsizesofar);
//printf("%d < %lu\n", i,sizeof(removedlines));
strcat(result, "/");
strcat(result,bprotox->name);
strcat(result, "/");
if(strcmp(bprotox->name,"ip4")==0)
{
strcat(result,int2ip(Hex_To_Int(the_wanted_address)));
}
else if(strcmp(bprotox->name,"tcp")==0)
{
char a[5];
sprintf(a,"%lu",Hex_To_Int(the_wanted_address));
strcat(result,a);
}
else if(strcmp(bprotox->name,"udp")==0)
{
char a[5];
sprintf(a,"%lu",Hex_To_Int(the_wanted_address));
strcat(result,a);
}
else
{
return 0;
}
}
i++;
} }
pid[0] = hex[lastpos];
pid[1] = hex[lastpos+1];
pid[2] = '\0';
if(lastpos == 0)
{
load_protocols();
}
if(proto_with_deccode(Hex_To_Int(pid)))
{
//////////Stage 2: Address
struct protocol * PID;
PID = NULL;
PID = proto_with_deccode(Hex_To_Int(pid));
lastpos = lastpos+2;
char address[(PID->size/4)+1];
bzero(address,(PID->size/4)+1);
address[(PID->size/4)]='\0';
int x=0;
//printf("\nHEX TO DECODE: %s\n",hex);
for(int i = lastpos;i<(PID->size/4)+lastpos;i++)
{
address[x] = hex[i];
//printf("HEX[%d]=%c\n",i,hex[i]);
x++;
}
//////////Stage 3 Process it back to string
//printf("Protocol: %s\n", PID->name);
//printf("Address : %s\n", address);
lastpos= lastpos+(PID->size/4);
//printf("lastpos: %d",lastpos);
//////////Address:
//Keeping Valgrind happy
char name[30];
bzero(name,30);
strcpy(name, PID->name);
//
strcat(resultzx, "/");
strcat(resultzx, name);
strcat(resultzx, "/");
if(strcmp(name, "ip4")==0)
{
strcat(resultzx,int2ip(Hex_To_Int(address)));
}
else if(strcmp(name, "tcp")==0)
{
char a[5];
sprintf(a,"%lu",Hex_To_Int(address));
strcat(resultzx,a);
}
else if(strcmp(name, "udp")==0)
{
char a[5];
sprintf(a,"%lu",Hex_To_Int(address));
strcat(resultzx,a);
}
//printf("Address(hex):%s\n",address);
//printf("TESTING: %s\n",resultzx);
/////////////Done processing this, move to next if there is more.
if(lastpos<size*2)
{
goto NAX;
}
}
strcat(resultzx, "/");
unload_protocols(); unload_protocols();
strcat(result,"/");
return 1;
} }
//
char * address_string_to_bytes(struct protocol * xx, char * abc,size_t getsznow) char * address_string_to_bytes(struct protocol * xx, char * abc,size_t getsznow)
{ {
static char astb__stringy[10] = "\0"; static char astb__stringy[200] = "\0";
bzero(astb__stringy,200);
int code = 0; int code = 0;
code = xx->deccode; code = xx->deccode;
switch(code) switch(code)
@ -368,6 +357,7 @@ char * address_string_to_bytes(struct protocol * xx, char * abc,size_t getsznow)
case 4://IPv4 case 4://IPv4
{ {
char testip[16] = "\0"; char testip[16] = "\0";
bzero(testip,16);
strcpy(testip,abc); strcpy(testip,abc);
if(is_valid_ipv4(testip)==1) if(is_valid_ipv4(testip)==1)
{ {
@ -483,7 +473,7 @@ char * address_string_to_bytes(struct protocol * xx, char * abc,size_t getsznow)
} }
case 42://IPFS - !!! case 42://IPFS - !!!
{ {
//abc=address
break; break;
} }
case 480://http case 480://http
@ -519,14 +509,15 @@ char * address_string_to_bytes(struct protocol * xx, char * abc,size_t getsznow)
} }
} }
} }
int string_to_bytes(uint8_t * finalbytes,char * strx, size_t strsize) int string_to_bytes(uint8_t * finalbytes,int * realbbsize,char * strx, size_t strsize)
{ {
static char xxx[40] = "\0"; static char xxx[200] = "\0";
bzero(xxx,40); bzero(xxx,200);
int sigmalf = 0; int sigmalf = 0;
char * totpch; char * totpch;
char totalwordstest[strsize]; char totalwordstest[strsize];
strcpy(totalwordstest, strx); bzero(totalwordstest,strsize);
strcat(totalwordstest, strx);
int totalwords = 0; int totalwords = 0;
totpch = strtok(totalwordstest, "/"); totpch = strtok(totalwordstest, "/");
while(totpch != NULL) while(totpch != NULL)
@ -535,8 +526,10 @@ int string_to_bytes(uint8_t * finalbytes,char * strx, size_t strsize)
totalwords++; totalwords++;
} }
int processedwords = 0; int processedwords = 0;
char processedsofar[500] = "\0"; char processedsofar[100];
bzero(processedsofar,100);
char str[strsize]; //This string will be bad later. char str[strsize]; //This string will be bad later.
bzero(str,strsize);
nextproc: nextproc:
strcpy(str,strx); strcpy(str,strx);
if(str[0] == '/') if(str[0] == '/')
@ -557,10 +550,12 @@ int string_to_bytes(uint8_t * finalbytes,char * strx, size_t strsize)
struct protocol * protx; struct protocol * protx;
//printf("PCH-P:%s\n",pch); //printf("PCH-P:%s\n",pch);
protx = proto_with_name(pch); protx = proto_with_name(pch);
char cut[30]="\0"; char cut[3]="\0";
bzero(cut,3);
strcat(cut,Int_To_Hex(protx->deccode)); strcat(cut,Int_To_Hex(protx->deccode));
cut[2] = '\0'; cut[2] = '\0';
char finipbit[2] = "\0"; char finipbit[3] = "\0";
bzero(finipbit,3);
finipbit[0] = cut[0]; finipbit[0] = cut[0];
finipbit[1] = cut[1]; finipbit[1] = cut[1];
finipbit[2] = '\0'; finipbit[2] = '\0';
@ -570,7 +565,8 @@ int string_to_bytes(uint8_t * finalbytes,char * strx, size_t strsize)
strcat(processedsofar, pch); strcat(processedsofar, pch);
//printf("PCH-A:%s\n",pch); //printf("PCH-A:%s\n",pch);
char addr[60] = "\0"; char addr[60] = "\0";
strcpy(addr, pch); bzero(addr,60);
strcat(addr, pch);
//If both are ok: //If both are ok:
strcat(xxx,finipbit); strcat(xxx,finipbit);
if(address_string_to_bytes(protx, addr,sizeof(addr))) if(address_string_to_bytes(protx, addr,sizeof(addr)))
@ -610,30 +606,20 @@ int string_to_bytes(uint8_t * finalbytes,char * strx, size_t strsize)
{ {
//printf("S2B_RESULT: %s\n", xxx); //printf("S2B_RESULT: %s\n", xxx);
//static uint8_t finalbytes[100] = {0}; //static uint8_t finalbytes[100] = {0};
for(int i=0; i<100; i++) bzero(finalbytes,100);
{ //printf("XXX: %s\n",xxx);
finalbytes[i] = 0;
}
memcpy(finalbytes, Hex_To_Var(xxx), 100); memcpy(finalbytes, Hex_To_Var(xxx), 100);
int xtotbytes = 0; realbbsize[0] = 0;
for(int i=0; i<100; i++) for(int i=0;i<100;i++)
{ {
if(finalbytes[i] != 0) if(finalbytes[i])
{ {
xtotbytes++; realbbsize[0]++;
} }
} }
//printf("TOT BYTES: %d\n", xtotbytes); //printf("FB2XXX: %s\nWith size: %u\n",Var_To_Hex(finalbytes), realbbsize[0]);
uint8_t finalproc[sizeof(finalbytes)/sizeof(finalbytes)[0]]; //realbsize = realsize;
for(int i=0;i<sizeof(finalproc); i++) //printf("REALbBSZIE: %d", realbbsize[0]);
{
if(finalbytes[i] != 0)
{
finalproc[i] = '\0';
}
}
//printf("FinalBytes: %s\n",finalbytes);
//printf("Finaltest: %s",Var_To_Hex(finalbytes));
return 1;//success return 1;//success
} }
else else

View file

@ -13,7 +13,7 @@
memcpy(encbe, htobe32(ebex32)); memcpy(encbe, htobe32(ebex32));
return encbe; return encbe;
}*/ }*/
int8_t Var_Bytes_Count(uint8_t countbytesofthis[10]) int8_t Var_Bytes_Count(uint8_t * countbytesofthis)
{ {
static int8_t xrzk_bytescnt = 0; static int8_t xrzk_bytescnt = 0;
for(int8_t i=0; i<10; i++) for(int8_t i=0; i<10; i++)
@ -27,95 +27,112 @@ int8_t Var_Bytes_Count(uint8_t countbytesofthis[10])
} }
uint8_t * Num_To_Varint_64(uint64_t TOV64INPUT) //UINT64_T TO VARINT uint8_t * Num_To_Varint_64(uint64_t TOV64INPUT) //UINT64_T TO VARINT
{ {
static uint8_t buffy_001[10] = {0}; static uint8_t buffy_001[60] = {0};
uvarint_encode64(TOV64INPUT, buffy_001, 10); uvarint_encode64(TOV64INPUT, buffy_001, 60);
return buffy_001; return buffy_001;
} }
uint8_t * Num_To_Varint_32(uint32_t TOV32INPUT) // UINT32_T TO VARINT uint8_t * Num_To_Varint_32(uint32_t TOV32INPUT) // UINT32_T TO VARINT
{ {
static uint8_t buffy_032[10] = {0}; static uint8_t buffy_032[60] = {0};
uvarint_encode32(TOV32INPUT, buffy_032, 10); uvarint_encode32(TOV32INPUT, buffy_032, 60);
return buffy_032; return buffy_032;
} }
uint64_t * Varint_To_Num_64(uint8_t TON64INPUT[10]) //VARINT TO UINT64_t uint64_t * Varint_To_Num_64(uint8_t TON64INPUT[60]) //VARINT TO UINT64_t
{ {
static uint64_t varintdecode_001 = 0; static uint64_t varintdecode_001 = 0;
uvarint_decode64(TON64INPUT, 10, &varintdecode_001); uvarint_decode64(TON64INPUT, 60, &varintdecode_001);
return &varintdecode_001; return &varintdecode_001;
} }
uint32_t * Varint_To_Num_32(uint8_t TON32INPUT[10]) //VARINT TO UINT32_t uint32_t * Varint_To_Num_32(uint8_t TON32INPUT[60]) //VARINT TO UINT32_t
{ {
static uint32_t varintdecode_032 = 0; static uint32_t varintdecode_032 = 0;
uvarint_decode32(TON32INPUT, 10, &varintdecode_032); uvarint_decode32(TON32INPUT, 60, &varintdecode_032);
return &varintdecode_032; return &varintdecode_032;
} }
// //
char * Int_To_Hex(uint64_t int2hex) //VAR[binformat] TO HEX char * Int_To_Hex(uint64_t int2hex) //VAR[binformat] TO HEX
{ {
static char int2hex_result[20]="\0"; static char int2hex_result[200]="\0";
memset(int2hex_result,0,sizeof(int2hex_result)); memset(int2hex_result,0,sizeof(int2hex_result));
sprintf (int2hex_result, "%02lX", int2hex); sprintf (int2hex_result, "%02lX", int2hex);
return int2hex_result; return int2hex_result;
} }
uint64_t Hex_To_Int(char *hex) uint64_t Hex_To_Int(char * hax)
{ {
char * hex = NULL;
hex=hax;
uint64_t val = 0; uint64_t val = 0;
while (*hex) while (*hex)
{ {
// get current character then increment // get current character then increment
uint8_t byte = *hex++; uint8_t byte = *hex++;
// transform hex character to the 4bit equivalent number, using the ascii table indexes // transform hex character to the 4bit equivalent number, using the ascii table indexes
if (byte >= '0' && byte <= '9') byte = byte - '0'; if (byte >= '0' && byte <= '9') byte = byte - '0';
else if (byte >= 'a' && byte <='f') byte = byte - 'a' + 10; else if (byte >= 'a' && byte <='f') byte = byte - 'a' + 10;
else if (byte >= 'A' && byte <='F') byte = byte - 'A' + 10; else if (byte >= 'A' && byte <='F') byte = byte - 'A' + 10;
// shift 4 to make space for new digit, and add the 4 bits of the new digit // shift 4 to make space for new digit, and add the 4 bits of the new digit
val = (val << 4) | (byte & 0xF); val = (val << 4) | (byte & 0xF);
} }
return val; return val;
} }
// //
char * Var_To_Hex(uint8_t * TOHEXINPUT) //VAR[binformat] TO HEX void vthconvert(int size, char * crrz01, uint8_t * xbuf)
{ {
if(TOHEXINPUT != NULL) uint8_t buf[100];
bzero(buf,100);
//fixing the buf
for(int cz=0; cz<size;cz++)
{ {
static char convert_resultz1[105]="\0"; buf[cz] = xbuf[cz];
memset(convert_resultz1,0,sizeof(convert_resultz1)); }
void convert(uint8_t * buf) //
if(crrz01!=NULL)
{ {
char conv_proc[100]="\0"; char * crrz1 = NULL;
for(int i=0; i < 100; i++) crrz1 = crrz01;
char conv_proc[200]="\0";
int i;
for(i=0; i < (size*2); i++)
{ {
if(buf[i]!=0) if(buf[i]!='\0')
{ {
sprintf (conv_proc, "%02X", buf[i]); sprintf (conv_proc, "%02X", buf[i]);
//printf("%d:%d\n",i, buf[i]); //printf("%d:%d\n",i, buf[i]);
strcat(convert_resultz1, conv_proc); strcat(crrz1, conv_proc);
}
if(buf[i]==0 && buf[i+1]!=0)
{
sprintf (conv_proc, "%02X", buf[i]);
//printf("%d:%d\n",i, buf[i]);
strcat(convert_resultz1, conv_proc);
} }
} }
crrz1 = NULL;
} }
convert(TOHEXINPUT); }
return convert_resultz1; char * Var_To_Hex(int realsize, uint8_t * TOHEXINPUT) //VAR[binformat] TO HEX
{
for(int ix=realsize;ix<100;ix++)
{
TOHEXINPUT[ix] = '\0';
}
if(TOHEXINPUT != NULL)
{
static char convert_resultz1[200]="\0";
bzero(convert_resultz1,200);
vthconvert(realsize, convert_resultz1, TOHEXINPUT);
return convert_resultz1;
} }
} }
uint8_t * Hex_To_Var(char * Hexstr) //HEX TO VAR[BINFORMAT] uint8_t * Hex_To_Var(char * Hexstr) //HEX TO VAR[BINFORMAT]
{ {
static uint8_t buffy_HEX[105] = {0}; static uint8_t buffy_HEX[100] = {0};
for(int i=0;i<105;i++) bzero(buffy_HEX,100);
{ int i;
buffy_HEX[i] = 0; char codo[200] = "\0";
} bzero(codo,200);
char codo[105] = "\0";
strcpy(codo, Hexstr); strcpy(codo, Hexstr);
char code[3] = "\0"; char code[3];
bzero(code,3);
code[3]='\0';
int x = 0; int x = 0;
int fori001=0; int fori001=0;
for(fori001=0;fori001<105;fori001++) for(fori001=0;fori001<200;fori001++)
{ {
strncpy(&code[0],&codo[fori001],1); strncpy(&code[0],&codo[fori001],1);
strncpy(&code[1],&codo[fori001+1],1); strncpy(&code[1],&codo[fori001+1],1);
@ -130,57 +147,67 @@ uint8_t * Hex_To_Var(char * Hexstr) //HEX TO VAR[BINFORMAT]
return buffy_HEX; return buffy_HEX;
} }
// //
void convert(char * convert_result, uint8_t * buf) //Both of them read them properly.
{
char conv_proc[200]="\0";
bzero(conv_proc,200);
int i;
for(i=0; i < 10; i++)
{
sprintf (conv_proc, "%02X", buf[i]);
//printf("%d:%d\n",i, buf[i]);
strcat(convert_result, conv_proc);
}
}
char * Num_To_HexVar_64(uint64_t TOHVINPUT) //UINT64 TO HEXIFIED VAR char * Num_To_HexVar_64(uint64_t TOHVINPUT) //UINT64 TO HEXIFIED VAR
{ //Code to varint - py { //Code to varint - py
static char convert_result[10]="\0";//Note that the hex resulted from this will differ from py static char convert_result[200]="\0";//Note that the hex resulted from this will differ from py
bzero(convert_result,200);
memset(convert_result,0,sizeof(convert_result));//But if you make sure the string is always 20 chars in size memset(convert_result,0,sizeof(convert_result));//But if you make sure the string is always 20 chars in size
void convert(uint8_t buf[10]) //Both of them read them properly. uint8_t buf[100] = {0};
{ bzero(buf,100);
char conv_proc[10]="\0"; uvarint_encode64(TOHVINPUT, buf, 200);
int i=0; convert(convert_result,buf);
for(; i < 10; i++)
{
sprintf (conv_proc, "%02X", buf[i]);
//printf("%d:%d\n",i, buf[i]);
strcat(convert_result, conv_proc);
}
}
uint8_t buf[10] = {0};
uvarint_encode64(TOHVINPUT, buf, 10);
convert(buf);
return convert_result; return convert_result;
} }
void convert2(char * convert_result2, uint8_t * bufhx)
{
uint8_t * buf = NULL;
buf = bufhx;
char conv_proc[3]="\0";
conv_proc[3] = '\0';
bzero(conv_proc, 3);
int i;
for(i=0; i == 0; i++)
{
sprintf (conv_proc, "%02X", buf[i]);
//printf("aaaaaaaaaaah%d:%d\n",i, buf[i]);
strcat(convert_result2, conv_proc);
}
buf = NULL;
}
char * Num_To_HexVar_32(uint32_t TOHVINPUT) //UINT32 TO HEXIFIED VAR char * Num_To_HexVar_32(uint32_t TOHVINPUT) //UINT32 TO HEXIFIED VAR
{ //Code to varint - py { //Code to varint - py
static char convert_result2[20]="\0"; static char convert_result2[3]="\0";
bzero(convert_result2,3);
convert_result2[2] = '\0';
memset(convert_result2,0,sizeof(convert_result2)); memset(convert_result2,0,sizeof(convert_result2));
void convert(uint8_t buf[10]) uint8_t buf[1] = {0};
{ bzero(buf,1);
char conv_proc[10]="\0"; uvarint_encode32(TOHVINPUT, buf, 1);
int i=0; convert2(convert_result2,buf);
for(; i < 10; i++)
{
sprintf (conv_proc, "%02X", buf[i]);
printf("%d:%d\n",i, buf[i]);
strcat(convert_result2, conv_proc);
}
}
uint8_t buf[10] = {0};
uvarint_encode32(TOHVINPUT, buf, 10);
convert(buf);
return convert_result2; return convert_result2;
} }
uint64_t HexVar_To_Num_64(char * theHEXstring) //HEXIFIED VAR TO UINT64_T uint64_t HexVar_To_Num_64(char * theHEXstring) //HEXIFIED VAR TO UINT64_T
{ //Varint to code - py { //Varint to code - py
uint8_t buffy[10] = {0}; uint8_t buffy[100] = {0};
char codo[20] = "\0"; char codo[200] = "\0";
bzero(codo,200);
strcpy(codo, theHEXstring); strcpy(codo, theHEXstring);
char code[3] = "\0"; char code[3] = "\0";
int x = 0; int x = 0;
for(int i= 0;i<20;i++) for(int i= 0;i<199;i++)
{ {
strncpy(&code[0],&codo[i],1); strncpy(&code[0],&codo[i],1);
strncpy(&code[1],&codo[i+1],1); strncpy(&code[1],&codo[i+1],1);
@ -192,17 +219,21 @@ uint64_t HexVar_To_Num_64(char * theHEXstring) //HEXIFIED VAR TO UINT64_T
x++; x++;
} }
static uint64_t decoded; static uint64_t decoded;
uvarint_decode64 (buffy, 10, &decoded); uvarint_decode64 (buffy, 100, &decoded);
return decoded; return decoded;
} }
uint32_t HexVar_To_Num_32(char theHEXstring[]) //HEXIFIED VAR TO UINT32_T uint32_t HexVar_To_Num_32(char theHEXstring[]) //HEXIFIED VAR TO UINT32_T
{ //Varint to code py { //Varint to code py
uint8_t buffy[10] = {0}; uint8_t buffy[100] = {0};
char codo[20] = "\0"; bzero(buffy,100);
char codo[200] = "\0";
bzero(codo,200);
strcpy(codo, theHEXstring); strcpy(codo, theHEXstring);
char code[2] = "\0"; char code[3] = "\0";
bzero(code,3);
code[3] = '\0';
int x = 0; int x = 0;
for(int i= 0;i<20;i++) for(int i= 0;i<199;i++)
{ {
strncpy(&code[0],&codo[i],1); strncpy(&code[0],&codo[i],1);
strncpy(&code[1],&codo[i+1],1); strncpy(&code[1],&codo[i+1],1);