-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
165 lines (148 loc) · 4.79 KB
/
test.cpp
File metadata and controls
165 lines (148 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include <stdio.h>
#include <process.h>
#include "iostream.h"
#pragma comment(lib,"iostream.lib")
typedef struct _STRUCT_TESTX_ {
char buffer[256];
int value;
}RTextX,*pTextX;
int addr_pass_test(void* lpParam);
unsigned __stdcall io_input(LPVOID lParam);
unsigned __stdcall io_output(LPVOID lParam);
unsigned __stdcall io_input(LPVOID lParam)
{
pIOStream io=(pIOStream)lParam;
char message[256]="";
DWORD threadid=0;
int thread_sequence_no=0;
SYSTEMTIME st={0};
if(io==NULL) return -1;
threadid=GetCurrentThreadId();
while(thread_sequence_no<1024*200) {
GetLocalTime(&st);
memset(message,0x00,sizeof(message));
sprintf(message,
"[THREAD ID:0x%08X-%06d][TIME:%02d%02d%02d %02d:%02d:%02d.%03d]\n",
threadid,thread_sequence_no,st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.wSecond,st.wMilliseconds);
{
//printf("%s",message);
}
if(io->push_io(io,message,strlen(message))<0) {
printf("[IO INPUT ERROR/THREAD ID:0x%08X-%06d].\n",threadid,thread_sequence_no);
break;
}
thread_sequence_no++;
Sleep(1);
}
if(thread_sequence_no>=1024*2) {
EnterCriticalSection(&io->io_lock);
if(io->stream_index>0) io->export_mem2file(io,NULL,0);
LeaveCriticalSection(&io->io_lock);
printf("[THREAD ID:0x%08X-%06d]DONE.\n",threadid,thread_sequence_no);
}
return 0;
}
unsigned __stdcall io_output(LPVOID lParam)
{
pIOStream io=(pIOStream)lParam;
//FILE* file=NULL;
char stream_out[256+1]="";
DWORD threadid=0;
int io_count=0;
if(io==NULL) return -1;
threadid=GetCurrentThreadId();
//if(NULL==(file=fopen("output_test.txt","a+"))) return -1;
//Sleep(100);
while(TRUE) {
int result=0;
memset(stream_out,0x00,sizeof(stream_out));
if((result=io->pull_io(io,stream_out,256))<0) {
printf("[IO OUTPUT ERROR/THREAD ID:0x%08X].\n",threadid);
break;
}
else {
//printf("%s",stream_out);
//fwrite(stream_out,sizeof(char),result,file);
//fflush(file);
if(result==0) printf("[IO OUTPUT(%08d) CLEAN/THREAD ID:0x%08X].\n",io_count,threadid);
io_count+=result;
}
}
//if(file) fclose(file);
printf("[IO OUTPUT Bytes:%d]\n",io_count);
return 0;
}
int io_jobschedule()
{
HANDLE io_handle[4]={NULL};
DWORD threadid[4]={0};
int index=0;
pIOStream io=malloc_iostream(NULL);
if(io==NULL) {
printf("Initial iostream failed.\n");
return -1;
}
while(index<sizeof(io_handle)/sizeof(HANDLE)-1){
io_handle[index]=(HANDLE)_beginthreadex(NULL,0,io_input,io,0,(unsigned int*)&threadid[index]);
index++;
}
io_handle[index]=(HANDLE)_beginthreadex(NULL,0,io_output,io,0,(unsigned int*)&threadid[index]);
WaitForMultipleObjects(sizeof(io_handle)/sizeof(HANDLE),io_handle,TRUE,INFINITE);
free_iostream(io);
return 0;
}
int addr_pass_test(void* lpParam)
{
RTextX** p=(pTextX*)lpParam;
pTextX addr=NULL;
printf("inside function-call/param addr:%08X\n",p);
addr=(pTextX)malloc(sizeof(RTextX));
strcpy(addr->buffer,"what a fuck?");
addr->value=42;
//(*lpParam)=addr;
return 0;
}
void main()
{
//pTextX p=NULL;
//pTextX* addr_p=&p;
//
//printf("plt addr:%08X\n",addr_p);
//addr_pass_test(addr_p);
//if(p) printf("struct{%s,%d}\n",p->buffer,p->value);
//
//if(p) free(p);
//
//{
// int listcount=10;
// int filename_itemsize=256;
// char** filenamelist=NULL;
//
// filenamelist=(char**)malloc(sizeof(char*)*listcount);
// for(int index=0;index<listcount;index++) {
// *(filenamelist+index)=(char*)malloc(sizeof(char)*filename_itemsize);
// memset(*(filenamelist+index),0x00,filename_itemsize);
// sprintf(*(filenamelist+index),"file index:%d-(%d.extension.)",index,index);
// }
//
// {
// int count=_msize(filenamelist)/sizeof(char*);
// int file_index=0;
//
// do{
// printf("[%08X]:%s\n",filenamelist+file_index,*(filenamelist+file_index));
//
// free(*(filenamelist+file_index));
// *(filenamelist+file_index)=NULL;
//
// }while(++file_index<count);
//
// printf("[%08X]\n",filenamelist);
//
// free(filenamelist);
// filenamelist=NULL;
// }
//
//}
io_jobschedule();
}