Visual Basic Foro
Programación => Visual Basic 6 => Mensaje iniciado por: Jhonjhon_123 en Febrero 01, 2010, 04:05:11 pm
-
Hola!
Bueno la cosa es:
tengo una archivo .dat, el cual esta en un formato raro, con el winhex he visto que tiene una secuencia logica en su almacenamiento. Mi pregunta es como puedo hacer un split, un instr, y otros manejos en cadenas hexadecimales???
Gracias!
-
Un archivo .dat el cual está en un formato raro? Explicate, eso no lo entendí.
-
bueno, ya le he podido poner a hex:
Private Function HexConverter(Text As String) As String
Dim Letra As String
Dim TextAsc As String
Dim D As Long
For D = 1 To Len(Text)
Letra = Mid(Text, D, 1)
HexConverter = HexConverter & " " & Hex(Asc(Letra))
DoEvents
Next
End Function
Me explico, el .dat es el "sm.dat" del CuteFTP, y bueno lo he mirado, tiene una secuencia logica, pero no he podido separar los datos con el vb, pues los hex camian con la palabra.
-
Bueno, buscando mas alla, encontre un code, pero esta en C o C++ o C#, no se, y no me como traducirlo a vb, si alguien conose cual es y como se traduce se lo agradesco.
Code:
/*
Copyright 2004,2005,2006,2007,2008,2009 Luigi Auriemma
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
http://www.gnu.org/licenses/gpl-2.0.txt
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
#define VER "0.1.2"
#define BUFFSZ 256
void readshow(FILE *fd, u8 *msg, int dec);
void cuteftp_pwd(u8 *pwd, u8 size);
void read_err(void);
void std_err(void);
int main(int argc, char *argv[]) {
FILE *fd;
u32 b4;
int i;
u16 b2,
hosts;
u8 b;
setbuf(stdout, NULL);
fputs("\n"
"CuteFTP data retriever and password decoder "VER"\n"
"by Luigi Auriemma\n"
"e-mail: aluigi@autistici.org\n"
"web: aluigi.org\n"
"\n", stdout);
if(argc < 2) {
printf("\nUsage: %s <SM.DAT>\n"
"\n"
"sm.dat is located in the folders inside %%APPDATA%%\\GlobalSCAPE\n"
"\n", argv[0]);
printf("\n press RETURN to exit\n");
fgetc(stdin);
exit(1);
}
fd = fopen(argv[1], "rb");
if(!fd) std_err();
if(fread(&b, 1, 1, fd) != 1) read_err();
if(fseek(fd, b, SEEK_SET)) std_err();
readshow(fd, "Main Folder", 0);
if(fseek(fd, 14, SEEK_CUR)) std_err();
if(fread(&hosts, 2, 1, fd) != 1) read_err();
if(fseek(fd, 4 + (hosts << 2), SEEK_CUR)) std_err();
if(fread(&b2, 2, 1, fd) != 1) read_err();
if(fseek(fd, b2, SEEK_CUR)) std_err();
for(;;) {
printf("-------------------------------\n");
for(i = 0; i < 3; i++) {
if(fread(&b4, 4, 1, fd) != 1) break;
}
if(feof(fd)) break; // lame but this is only an experiment
if(fseek(fd, 4, SEEK_CUR)) std_err();
if(b4) {
readshow(fd, "Main Folder", 0);
if(fseek(fd, 14, SEEK_CUR)) std_err();
if(fread(&b2, 2, 1, fd) != 1) read_err();
if(fseek(fd, b2 << 2, SEEK_CUR)) std_err();
if(fseek(fd, 2, SEEK_CUR)) std_err();
continue;
}
readshow(fd, "Label", 0);
if(fseek(fd, 32, SEEK_CUR)) std_err();
readshow(fd, "Timezone", 0);
if(fseek(fd, 8, SEEK_CUR)) std_err();
readshow(fd, "Hostname", 0);
if(fread(&b, 1, 1, fd) != 1) read_err();
if(b == 1) {
readshow(fd, "", 0);
readshow(fd, "", 0);
readshow(fd, "", 0);
readshow(fd, "", 0);
readshow(fd, "", 0);
readshow(fd, "Comment", 0);
if(fseek(fd, 20, SEEK_CUR)) std_err();
} else {
readshow(fd, "", 0);
readshow(fd, "", 0);
readshow(fd, "", 0);
readshow(fd, "Username", 0);
readshow(fd, "Password", 1);
readshow(fd, "Comment", 0);
if(fseek(fd, 4, SEEK_CUR)) std_err();
if(fread(&b2, 2, 1, fd) != 1) read_err();
printf("%-30s %hu\n", "Port", b2);
if(fseek(fd, 14, SEEK_CUR)) std_err();
}
readshow(fd, "Remote folder", 0);
readshow(fd, "Local folder", 0);
if(fseek(fd, 20, SEEK_CUR)) std_err();
readshow(fd, "remote filter", 0);
if(fread(&b2, 2, 1, fd) != 1) read_err();
for(i = 0; i < b2; i++) {
readshow(fd, "filter mask", 0);
}
if(fread(&b2, 2, 1, fd) != 1) read_err();
for(i = 0; i < b2; i++) {
readshow(fd, "filter not mask", 0);
}
if(fseek(fd, 14, SEEK_CUR)) std_err();
readshow(fd, "Proxy host", 0);
if(fseek(fd, 4, SEEK_CUR)) std_err();
readshow(fd, "Proxy user", 0);
readshow(fd, "Proxy password", 0);
if(fseek(fd, 14, SEEK_CUR)) std_err();
if(fread(&b2, 2, 1, fd) != 1) read_err();
for(i = 0; i < b2; i++) {
readshow(fd, "Proxy advanced", 0);
}
if(fseek(fd, 2, SEEK_CUR)) std_err();
readshow(fd, "Socks host", 0);
if(fseek(fd, 4, SEEK_CUR)) std_err();
readshow(fd, "Socks user", 0);
readshow(fd, "Socks password", 0);
if(fseek(fd, 22, SEEK_CUR)) std_err();
}
fclose(fd);
printf("\n press RETURN to exit\n");
fgetc(stdin);
return(0);
}
void readshow(FILE *fd, u8 *msg, int dec) {
int len;
u8 buff[BUFFSZ + 1],
b;
if(fread(&b, 1, 1, fd) != 1) read_err();
len = b;
if(b == 0xff) {
if(fread(&b, 1, 1, fd) != 1) read_err();
len = b;
if(fread(&b, 1, 1, fd) != 1) read_err();
len |= (b << 8);
}
if(len <= 0) return;
if(len > BUFFSZ) { // blah, I don't want to waste 64kb of memory
if(fread(buff, 1, BUFFSZ, fd) != BUFFSZ) read_err();
if(fseek(fd, len - BUFFSZ, SEEK_CUR)) std_err();
len = BUFFSZ;
} else {
if(fread(buff, 1, len, fd) != len) read_err();
}
if(dec) cuteftp_pwd(buff, len);
buff[len] = 0;
if(msg[0]) printf("%-30s %s\n", msg, buff);
}
void cuteftp_pwd(u8 *pwd, u8 size) {
int i;
for(i = 0; i < size; i++) {
pwd[i] ^= 0xc8;
}
pwd[i] = 0;
}
void read_err(void) {
printf("\nError: read error, this tool is experimental so probably a needed value has not been found\n");
printf("\n press RETURN to exit\n");
fgetc(stdin);
exit(1);
}
void std_err(void) {
perror("\nError");
printf("\n press RETURN to exit\n");
fgetc(stdin);
exit(1);
}