Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - 0poitr

Pages: [1] 2 3 ... 6
1
C - C++ / Re: [C] Making A Website Blocker With Manifest
« on: April 14, 2014, 06:50:23 am »
Suit yourself with what you think is necessary or even better. :)



I sense a hint of troll.

2
Very nice write up. A cookie for you!

3
C - C++ / Re: [C] Making A Website Blocker With Manifest
« on: April 13, 2014, 03:34:58 pm »
Quote
The value for str is always "127.0.0.1              " I'm not changing it in the code, so I'm using char *str="something" so, whether I do char *str="something" or char str[100] = "something" it wont make a difference.
As far as I know, fgets() is for input from file right(I may be wrong)? I'm using gets() as I'm taking input from keyboard.
If you're not going to change *str then why 'd you do this:
Code: [Select]
fputs(str, handler);When you do
*str = "something";
"something" is put into the string table of the executable which is read-only. Trying to write something to a r/o region is going to fail. Allocating it the other way around reserves memory from the stack which is r/w.
Use fgets with the default input stream i.e. stdin.
fgets(site, size, stdin);

Hope this helps.

4
aaand something interesting here as well
http://blog.cloudflare.com/answering-the-critical-question-can-you-get-private-ssl-keys-using-heartbleed

They put up a open challenge to exploit and get the private keys off a vulnerable server.

5
C - C++ / Re: [C] Making A Website Blocker With Manifest
« on: April 12, 2014, 05:28:41 pm »
I'm trying to make a website blocker that runs with administrator privileges.
Here is my C code : http://www.scriptings.tk/paste/5348fab7a1ee5
Or view it here :
Code: (c) [Select]
#include<stdio.h>
#include<conio.h>
void main()
{
   
    char* str = "127.0.0.1       ";
   
        fputs(str, handler);
     
}
The memory for str is allocated statically off the stack. It's read-only. You can't re-assign a value to it. Instead, declare it as
Code: [Select]
char str[size]  = "whatever"; and it should run.
Also, always use fgets instead of gets. gets does no boundary check.

6
Operating System / Re: [linux] Bashrc awesomeness thread.
« on: April 10, 2014, 03:38:12 pm »
Code: [Select]
alias bftp="obexftp -b 20:D6:07:03:43:82 -c $1 -p $2"
alias bpush="ussp-push 20:D6:07:03:43:82@9"    # bluetooth push device id@channel number
alias samp='/usr/bin/time -f "Time: %E | Max.Mem: %M K | PF: %F Major %R Minor | Context Swtches: %c"'
alias gdb="gdb -silent"
alias cpu="cpupower -c all frequency-info"
alias mods="lspci -mvk | grep '^Module' | awk '{print $2}' | uniq"  #show currently loaded modules
alias init_dm="stest -flx $PATH|sort -u|tee .cache/dmenu_run|dmenu "$@""

The last one regenerates dmenu cache if it does not pick up new installs, which is rare but happened sometime back, I remember.

7
Tutorials / Re: [Article] Designing an interface
« on: April 09, 2014, 04:15:35 pm »
Very neat write up Kulver. Was a great read. It always appears somewhat as a disagreement to me when developing UI whether I should make it more verbose or more simple. Developers always tend to prefer verbosity, like an urge to let know what's going on under the hood. But the regulars don't want it, I suppose. So, that at times makes it hard for me to balance and then I ask somebody else (when available & applicable) to take a look and tell me what they think of it. That really helps.
And, Thank you for taking time sharing your thoughts.

8
Found it on the Webs / Re: Malware bytes PRO
« on: March 28, 2014, 02:32:48 pm »
Thanks!  Just worked.

9
C - C++ / Re: [C++] Code for Some Sorting Algorithms
« on: March 27, 2014, 04:53:10 am »
These can be optimized quite a bit with things like range-for loops and more of some niceties from C++11.  Also it looks like you reimplemented std::stack? Why?
My excuse would be, I'm just learning C++. Coming from the lands of bare bones C unaware of most of the facilities it's younger sibling provides. Can you demonstrate some language optimizations you are talking about ?

10
C - C++ / [C++] Code for Some Sorting Algorithms
« on: March 25, 2014, 04:23:12 pm »
My implementations of some sorting algorithms. You can use them in your code or for educational purposes. The code is mostly uncommented except for the radix sort, so I guess it could be a bit tricky to understand the workings; the variables themselves are descriptive of what they are used for, though.

Code: (c++) [Select]
// ==================================================================//
//
//   Sorting algorithms:
//   O(n2) Bubble, Selection, Insertion
//   O(nlogn) Quick, Merge (both iterative & recursive), Heap
//
//   Radix Sort (LSD)
//   http://en.wikipedia.org/wiki/Radix_sort#Efficiency
//
//   Author: 0poitr @ evilzone.org, 2014
//   Permission for use and modification of the code.
//
//   For knowledge and some interestng discussion on the algorithms,
//   you can consider their wikipedia pages and references.
//
// ==================================================================//

#include <iostream>

#define ULONG unsigned long
#define MIN(a, b) (a) < (b) ? (a) : (b)
#define mergeSortRecursive(x, y, len) mergeSortRecursive_(x, y, len-1);

using namespace std;

// prototype declarations

template <class T> void selectSort(T *a, int size);
template <class T> void bubbleSort(T *a, int size);
template <class T> void insSort(T *a, int size);
template <class T> int partition(T *a, int lb, int ub);
template <class T> void quickSort(T *a, int size);
template <class T> void quickSortRecursive(T *a, int lb, int ub);
template <class T> void reHeap(T *a, int start, int end);
template <class T> void heapSort(T *a, int size);
template <class T> void mergeParts(T *a, int lb, int mid, int ub);
template <class T> void mergeSort(T *a, int size);
template <class T> void mergeSortRecursive_(T *a, int lb, int ub);
template <class T> void display(T *a, int size);
template <class T> void radixSort(T *a, int size);

template <class T> void reNew(T **ptr, int *size);
template <class T> void push(T *a, T data);
template <class T> int pop(T *a);
int stackEmpty();
template <class T> void swap(T *a, int h, int l);
void freeMem(int **b);

// =====================

// auxiliary functions
int stack_top=0;

template <class T> void push(T *a, T data)
{
    a[stack_top++] = data;
}

template <class T> int pop(T *a)
{
    return a[--stack_top];
}

int stackEmpty()
{
    if (!stack_top) return 1;
    return 0;
}

template <class T> void swap(T *a, int h, int l)
{
    int tmp = a[l];
    a[l] = a[h];
    a[h] = tmp;
}
// ==================

// selection sort
template <class T> void selectSort(T *a, int size)
{
    int i, lowest;
    for (i=0; i<size-1; i++) {
        lowest = i;
        for (int j=i+1; j<size; j++)
            if (a[j] < a[lowest]) lowest = j;
        if (i!=lowest) swap(a, i, lowest);
    }
}
// ==================

// bubble sort
template <class T> void bubbleSort(T *a, int size)
{
    for (int i=0; i<size; i++) {
        bool work = false;
        for (int j=0; j<size-i-1; j++) {
            if (a[j] > a[j+1]) {
                swap(a, j, j+1);
                work = true;
            }
        }
        if (!work) break;
    }
}
// ==================

// insertion sort
template <class T> void insSort(T *a, int size)
{
    int j, i;
    for (i=1; i<size; i++) {
        int tmp = a[i];
        for (j=i-1; j>=0 && tmp < a[j]; j--)
            a[j+1] = a[j];
        a[j+1] = tmp;
    }
}
// ===================

// quick sort
template <class T> int partition(T *a, int lb, int ub)
{
    // considering the middle element as pivot avoids unnecessary
    // passes in case array is already sorted. Never suffer O(n2).
    swap(a, lb, (lb+ub)/2);

    int small_end = lb;
    for (int large_end=lb; large_end<ub; large_end++) {
        if (a[large_end+1] < a[lb])
            swap(a, ++small_end, large_end+1);
    }

    swap(a, lb, small_end);
    return small_end;
}

template <class T> void quickSort(T *a, int size)
{
    int lb=0, ub=size, pivot;
    int stack[size*2];
    push(stack, lb);
    push(stack, ub);

    while (!stackEmpty()) {
        ub = pop(stack);
        lb = pop(stack);

        if (lb >= ub) continue;
        pivot = partition(a, lb, ub);
       
        push(stack, lb);
        push(stack, pivot-1);
        push(stack, pivot+1);
        push(stack, ub);
    }
}

template <class T> void quickSortRecursive(T *a, int lb, int ub)
{
    if (lb >= ub) return;

    int p_end = partition(a, lb, ub);

    quickSortRecursive(a, lb, p_end-1);
    quickSortRecursive(a, p_end+1, ub);
}
// =================

// heap sort
template <class T> void reHeap(T *a, int start, int end)
{
    while (start*2+1 <= end) {
        int ch_indx = start*2 +1;
        int sw_indx = start;
       
        if (a[sw_indx] < a[ch_indx])
            sw_indx = ch_indx;
        if (ch_indx+1 <= end && a[sw_indx] < a[ch_indx+1])
            sw_indx = ++ch_indx;
        if (sw_indx != start)
            swap(a, sw_indx, start);
        else
            return;

        start = sw_indx;
    }
}

template <class T> void heapSort(T *a, int size)
{
    int last_root = (size-2)/2;
    while (last_root >= 0) {
        reHeap(a, last_root, size-1);
        last_root--;
    }

    int last = size-1;
    while (last > 0) {
        swap(a, 0, last);
        reHeap(a, 0, --last);
    }
}
// =================

// mergesort
template <class T> void mergeParts(T *a, int lb, int mid, int ub)
{
    T storage[ub-lb+1];
    int i, j, k;
    //cout<<"lb: "<<lb<<" ub: "<<ub<<endl;

    for (i=lb, k=0, j=mid+1; i<=mid && j<=ub; k++)
        storage[k] = a[i] < a[j] ? a[i++] : a[j++];

    while (i <= mid)
        storage[k++] = a[i++];
    while (j <= ub)
        storage[k++] = a[j++];

    j=lb;
    for (i=0; i<=ub-lb; i++)
        a[j++] = storage[i];
}

template <class T> void mergeSort(T *a, int size)
{
    int i,j;

    for (i=1; i<=size; i=i*2) {
        for (j=0; j<size-i; j=j+i*2)
            // mid = (j + j+2*i)/2 = i+j
            mergeParts(a, j, j+i-1, MIN(j+2*i-1, size-1));
    }
}

template <class T> void mergeSortRecursive_(T *a, int lb, int ub)
{
    if (lb >= ub) return;

    int mid = (ub+lb)/2;

    mergeSortRecursive_(a, lb, mid);
    mergeSortRecursive_(a, mid+1, ub);

    mergeParts(a, lb, mid, ub);
}
// ===================

// radix sort

#define BASE 10
#define MAX 32

template <class T> void reNew(T **ptr, int *size)
{
    T *tmp = new T [*size+MAX];
    for (int i=0; i<*size; i++)
        tmp[i] = *((*ptr)+i);
    delete *ptr;
    *ptr = tmp;
    (*size) += MAX;
}

void freeMem(int **b)
{
    for (int i=0; i<BASE; i++)
        delete b[i];
}

template <class T> void radixSort(T *a, int size)
{
    int *buckets[BASE];              // BASE number of buckets
    int indx_t[BASE][BASE] = { 0 };  // tracks current index for each bucket and bucket size
    int i;                           // indx on row [0], bucket size on [1]
    long highest = a[0];

    for (i=0; i<BASE; i++) {         // initially fixed amount of mem for each bucket
        buckets[i] = new T [MAX];
        indx_t[1][i] = MAX;
    }

    for (i=0; i<size; i++)
        if (a[i] > highest) highest=a[i];
   
    ULONG m=10, n=1;
    ULONG indx;

    while (highest*10 >= m) {
       
       // put numbers into buckets
       for (i=0; i<size; i++) {
           indx = (a[i] % m) / n;
           buckets[indx][indx_t[0][indx]++] = a[i];

       // if next indx > current size, reallocate mem for bucket
           if ( !(indx_t[0][indx] % indx_t[1][indx]) )
               reNew(&buckets[indx], &indx_t[1][indx]);
       }
       
       // copy back and reset index counters
       indx=0;
       for (i=0; i<BASE; i++) {
           int j = 0;

           while (j < indx_t[0][i])
               a[indx++] = buckets[i][j++];
           indx_t[0][i] = 0;
       }

       m *= BASE;
       n *= BASE;
    }

    freeMem(buckets);
}
// ===================

// display
template <class T> void display(T *a, int size)
{
    for (int i=0; i<size; i++) {
        cout<<a[i]<<" ";
    }
    cout<<endl;
}
// ==================

int main()
{
    int data[] = {5,382,132,22,702,52,62,102,52,26};
    int len = sizeof(data)/sizeof(data[0]);
    display(data, len);
    mergeSort(data, len);
    //mergeSortRecursive(data, 0, len);
    //quickSortRecursive(data, 0, len);
    //radixSort(data, len);
    display(data, len);
}


11
C - C++ / Back to C after a while. Got an lvalue problem :/
« on: December 31, 2013, 02:04:43 pm »
Code: [Select]
struct split *stringSplit (char *str, char *delim)
{               
    char **token_array;
    *token_array = NULL;
    allocPtrs (token_array);
       
    char *token = str, *saveptr;
    unsigned int bulk = 1, j;

    for (j=0; ; token=NULL) {
        token = strtok_r (token, delim, &saveptr);
        if (token) {
            if (j == bulk*CHAR_PTRS) {
                allocPtrs (token_array);
                bulk++;
            }
            *token_array+j = calloc (1, strlen (token)+1);
            if (! *token_array+j )
                error ("calloc");
            strcpy (*token_array+j, token);
            j++;
        }
        else break;
    }

    struct split *s_arr = calloc (sizeof(struct split), 1);
    s_arr->num = j;
    s_arr->token_array = token_array;

    return s_arr;
}

Code: [Select]
stringlib.c: In function ‘stringSplit’:
stringlib.c:50:28: error: lvalue required as left operand of assignment
             *token_array+j = calloc (1, strlen (token)+1);
                            ^

The function is meant to split the string by the delimiters and return an array of substring tokens.
What's going wrong? GCC's considering *token_array+j as a constant. WHY! I'm starting to loose mental sanity  >:(

12
...
btw it's D0xBase :D
My bad :D
Only thing i remember is, it was quite a lot of python code.

13
Tutorials / Re: METHODS OF DETECTION OF MALWARE [RESUME]
« on: November 25, 2013, 07:16:09 pm »
Quote
the antimalware laboratories
almost read it animalware :P

14
Nice to see you back again :)

This is some cool stuff :D I guess it only works on Linux as it uses curses? meh... curses are damn hard to understand heh :P
+cookie to you, sir.

Btw there are too many blocks.

Thanks mate !
Yes I wrote it for linux, dunno if n/curses is available for cygwin.
And no, curses isn't that hard to understand. It's quite easy. I guess you also have used curses in your DoxBox project?  :)

Blocks are the fun!  :D

15
C - C++ / [C] le Snake Mod [A mod of the classic snake game for *nix terms]
« on: November 22, 2013, 07:16:32 pm »
Hi guys!

This is a small mod of the classic snake game. But it's a bit more difficult than just finding way eating your food. You gotta avoid the falling blocks as well! Give it a try B)

Source and a demo video is attached. Run make and execute le_snake_mod to play game.
Cheers!

Pages: [1] 2 3 ... 6